Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup protectEditing and ignore shadow roots. Fixes #17 #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simpla-admin.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<link rel="import" href="../polymer/polymer.html"> <dom-module id="simpla-admin"> <template> <style>:host{position:absolute}:host([hidden]),[hidden]{display:none!important}</style> <simpla-admin-controls editable="[[_editable]]" authenticated="[[_authenticated]]" busy="{{busy}}" on-login="login" on-save="save" hidden$="[[_loginOpen]]"> </simpla-admin-controls> <simpla-login id="login" active="{{_loginOpen}}"> </simpla-login> <simpla-notify></simpla-notify> </template> <script>!function(){"use strict";function e(e){var t=Simpla.getState("buffer"),n=void 0;if(n=t&&Object.keys(t).some(function(e){return t[e].modified}))return e.returnValue=k,k}function t(e){e.keyCode===O.edit&&e[E]&&(e.preventDefault(),Simpla.editable(!Simpla.getState("editable")))}function n(e){e.keyCode===O.save&&e[E]&&(e.preventDefault(),document.querySelector("simpla-admin").save())}function i(e){var t=function t(){return!!document.body&&(document.body.appendChild(e),document.removeEventListener("readystatechange",t),!0)};t()||document.addEventListener("readystatechange",t)}function o(e){var t=document.querySelector("simpla-admin"),n=void 0;e&&!t&&(n=document.createElement("simpla-admin"),i(n))}function a(){var e=window.location.hash===P;Simpla.editable(e)}function r(e){window.location.hash=e?P:""}function s(e){e.path[0].localName&&"input"===e.path[0].localName||e.preventDefault(),e.stopPropagation()}function u(e){var t=function(e){return 0===e.indexOf("simpla-")};return e&&t(e)}function c(e){return!!u(e.localName)||e.getAttribute&&u(e.getAttribute("is"))}function l(e){var t=function(e){return j.includes(e)},n=function(e){return u(e)&&!t(e)};return!!n(e.localName)||n(e.getAttribute&&e.getAttribute("is"))}function d(e){return Array.prototype.filter.call(e,l)}function f(e){return Array.prototype.filter.call(e,c)}function p(e){return Array.prototype.filter.call(e,function(e){return q.has(e)})}function v(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.style.pointerEvents=t}function m(e){v(e,"auto")}function h(e){v(e,"none")}function b(e){v(e,"")}function y(e){q.set(e,0),m(e),H.forEach(function(t){e.addEventListener(t,s)})}function g(e){q.delete(e),b(e),H.forEach(function(t){e.removeEventListener(t,s)})}var _=(e,t)=>new Promise((n,i)=>{t="number"==typeof t?t:20;const o=()=>{Promise.resolve().then(e).then(e=>{if("boolean"!=typeof e)throw new TypeError("Expected condition to return a boolean");e===!0?n():setTimeout(o,t)}).catch(i)};o()}),S={properties:{loginPrompt:{type:Boolean,observer:"_toggleLoginPromptObserver"}},_toggleLoginPromptObserver:function(e){var t=this,n=this._simplaObservers,i=function(e){var n=t.$.login,i=function(){return"function"==typeof n.prompt};_(i,1).then(function(){e&&!t._authenticated&&n.prompt().then(function(e){Simpla.editable(e)})})};e?(i(Simpla.getState("editable")),n.login=Simpla.observeState("editable",i)):n.login&&n.login.unobserve()}},k="You have unsaved changes, are you sure you want to leave?",w={attached:function(){window.addEventListener("beforeunload",e)},detached:function(){window.removeEventListener("beforeunload",e)}},E="metaKey",O={edit:69,save:83},L={properties:{hotkeys:Boolean},observers:["_updateEditableListener(_authenticated, hotkeys)","_updateSaveListener(_editable, hotkeys)"],_updateEditableListener:function(e,n){e&&n?document.addEventListener("keydown",t):document.removeEventListener("keydown",t)},_updateSaveListener:function(e,t){e&&t?document.addEventListener("keydown",n):document.removeEventListener("keydown",n)},detached:function(){document.removeEventListener("keydown",t),document.removeEventListener("keydown",n)}},A={_simplaObservers:[],observe:function(){var e=this;_(function(){return!!window.Simpla},1).then(function(){var t=Simpla.getState(),n=t.editable,i=t.authenticated,a=n||i;o(a),e._simplaObservers=[Simpla.observeState("authenticated",o),Simpla.observeState("editable",o)]})},unobserve:function(){this._simplaObservers.forEach(function(e){return e.unobserve()}),this._simplaObservers=[]}},P="#edit",B={_simplaObserver:null,_tracking:!1,track:function(){var e=this;_(function(){return!!window.Simpla},1).then(function(){a(),e._tracking||(window.addEventListener("hashchange",a),r(Simpla.getState("editable")),e._simplaObserver=Simpla.observeState("editable",r),e._tracking=!0)})},untrack:function(){this._tracking&&(window.removeEventListener("hashchange",a),this._simplaObserver&&this._simplaObserver.unobserve(),this._simplaObserver=null,this._tracking=!1)}},T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},x=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),N=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},j=["simpla-admin","simpla-login","simpla-admin-controls","simpla-notify"],H=["click","ontouchend"],C=void 0,q=void 0;q=function(){var e=void 0;return void 0!==T(window.Map)?new Map:(e=[],{has:function(t){return e.indexOf(t)!==-1},set:function(t,n){var i=e.indexOf(t);i===-1&&e.push(t)},delete:function(t){var n=e.indexOf(t);n!==-1&&e.splice(n,1)},forEach:function(t){e.forEach(function(e,n,i){return t.call(i,0,e,n)})}})}(),C=new MutationObserver(function(e){e.forEach(function(e){d(e.addedNodes).forEach(y),f(e.addedNodes).forEach(m),p(e.removedNodes).forEach(g)})});var M={enable:function(){q.forEach(function(e,t){return g(t)}),C.disconnect(),b(document.body)},disable:function(){var e=document.querySelectorAll("*");d(e).forEach(y),f(e).forEach(m),h(document.body),C.observe(document.body,{childList:!0,subtree:!0})}},F=["../simpla-login/simpla-login.html","../simpla-notify/simpla-notify.html","simpla-admin-controls.html"],$={saved:"changes saved",saveFailed:"something went wrong, try again?"},I={hashTracking:!0,loginPrompt:!0,hotkeys:!0,protectEditing:!0};window.SimplaAdmin=N({},I,window.SimplaAdmin),A.observe(),window.SimplaAdmin.hashTracking&&B.track();var K=function(){function e(){D(this,e)}return x(e,[{key:"beforeRegister",value:function(){this.is="simpla-admin",this.properties={hashTracking:{type:Boolean,observer:"_updateHashTracking"},protectEditing:Boolean,hidden:{type:Boolean,reflectToAttribute:!0},busy:{type:Boolean,value:!1},_editable:Boolean,_authenticated:Boolean,_dependenciesImported:Boolean,_loginOpen:Boolean,_simplaObservers:{type:Object,value:{}}},this.observers=["_toggleHidden(_editable, _authenticated)","_disableEditable(busy)","_updatePointerEvents(protectEditing, _editable)"]}},{key:"ready",value:function(){N(this,window.SimplaAdmin),window.SimplaAdmin=this}},{key:"attached",value:function(){this._importDependencies(),this._syncEditableAndAuthenticated()}},{key:"detached",value:function(){var e=this;Object.keys(this._simplaObservers).forEach(function(t){e._simplaObservers[t].unobserve()}),this._simplaObservers={},B.untrack(),A.unobserve()}},{key:"_disableEditable",value:function(e){e&&Simpla.getState("editable")?(B.untrack(),Simpla.editable(!1),this.__busyDisabled=!0):!e&&this.__busyDisabled&&(Simpla.editable(!0),B.track(),this.__busyDisabled=!1)}},{key:"login",value:function(){this.$.login.open()}},{key:"save",value:function(){var e=this,t=function(){e.busy=!1,e.fire("simpla-notification",{text:$.saved})},n=function(){e.busy=!1,e.fire("simpla-notification",{text:$.saveFailed})};this.busy=!0,Simpla.save().then(t).catch(n)}},{key:"_toggleHidden",value:function(e,t){this.hidden=!e&&!t}},{key:"_updateHashTracking",value:function(e){e?B.track():B.untrack()}},{key:"_updatePointerEvents",value:function(e,t){e&&t?M.disable():M.enable()}},{key:"_syncEditableAndAuthenticated",value:function(){var e=this,t=Simpla.getState(),n=t.editable,i=t.authenticated,o=function(t){return e._editable=t},a=function(t){return e._authenticated=t};o(n),a(i),this._simplaObservers.editable=Simpla.observeState("editable",o),this._simplaObservers.authenticated=Simpla.observeState("authenticated",a)}},{key:"_importDependencies",value:function(){var e=this;F.forEach(function(t){e.importHref(e.resolveUrl(t))})}},{key:"behaviors",get:function(){return[S,L,w]}}]),e}();Polymer(K)}(); </script> </dom-module>
<link rel="import" href="../polymer/polymer.html"> <dom-module id="simpla-admin"> <template> <style>:host{position:absolute}:host([hidden]),[hidden]{display:none!important}</style> <simpla-admin-controls editable="[[_editable]]" authenticated="[[_authenticated]]" busy="{{busy}}" on-login="login" on-save="save" hidden$="[[_loginOpen]]"> </simpla-admin-controls> <simpla-login id="login" active="{{_loginOpen}}"> </simpla-login> <simpla-notify></simpla-notify> </template> <script>!function(){"use strict";function e(e){var t=Simpla.getState("buffer"),n=void 0;if(n=t&&Object.keys(t).some(function(e){return t[e].modified}))return e.returnValue=k,k}function t(e){e.keyCode===O.edit&&e[E]&&(e.preventDefault(),Simpla.editable(!Simpla.getState("editable")))}function n(e){e.keyCode===O.save&&e[E]&&(e.preventDefault(),document.querySelector("simpla-admin").save())}function i(e){var t=function t(){return!!document.body&&(document.body.appendChild(e),document.removeEventListener("readystatechange",t),!0)};t()||document.addEventListener("readystatechange",t)}function o(e){var t=document.querySelector("simpla-admin"),n=void 0;e&&!t&&(n=document.createElement("simpla-admin"),i(n))}function a(){var e=window.location.hash===P;Simpla.editable(e)}function r(e){window.location.hash=e?P:""}function u(e){e.path[0].localName&&"input"===e.path[0].localName||e.preventDefault(),e.stopPropagation()}function s(e){var t=function(e){return 0===e.indexOf("simpla-")};return e&&t(e)}function c(e){return Array.prototype.filter.call(e,function(e){return 1===e.nodeType})}function l(e){return!!s(e.localName)||s(e.getAttribute("is"))}function d(e){var t=function(e){return l(e)||!document.querySelector("simpla-admin").contains(e)||!e.shadowRoot===root};return e.filter(t)}function f(e){return e.filter(l)}function v(e){return e.filter(function(e){return q.has(e)})}function p(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.style.pointerEvents=t}function m(e){p(e,"auto")}function h(e){p(e,"none")}function b(e){p(e,"")}function y(e){q.set(e,0),m(e),H.forEach(function(t){e.addEventListener(t,u)})}function g(e){q.delete(e),b(e),H.forEach(function(t){e.removeEventListener(t,u)})}var _=(e,t)=>new Promise((n,i)=>{t="number"==typeof t?t:20;const o=()=>{Promise.resolve().then(e).then(e=>{if("boolean"!=typeof e)throw new TypeError("Expected condition to return a boolean");e===!0?n():setTimeout(o,t)}).catch(i)};o()}),S={properties:{loginPrompt:{type:Boolean,observer:"_toggleLoginPromptObserver"}},_toggleLoginPromptObserver:function(e){var t=this,n=this._simplaObservers,i=function(e){var n=t.$.login,i=function(){return"function"==typeof n.prompt};_(i,1).then(function(){e&&!t._authenticated&&n.prompt().then(function(e){Simpla.editable(e)})})};e?(i(Simpla.getState("editable")),n.login=Simpla.observeState("editable",i)):n.login&&n.login.unobserve()}},k="You have unsaved changes, are you sure you want to leave?",w={attached:function(){window.addEventListener("beforeunload",e)},detached:function(){window.removeEventListener("beforeunload",e)}},E="metaKey",O={edit:69,save:83},L={properties:{hotkeys:Boolean},observers:["_updateEditableListener(_authenticated, hotkeys)","_updateSaveListener(_editable, hotkeys)"],_updateEditableListener:function(e,n){e&&n?document.addEventListener("keydown",t):document.removeEventListener("keydown",t)},_updateSaveListener:function(e,t){e&&t?document.addEventListener("keydown",n):document.removeEventListener("keydown",n)},detached:function(){document.removeEventListener("keydown",t),document.removeEventListener("keydown",n)}},A={_simplaObservers:[],observe:function(){var e=this;_(function(){return!!window.Simpla},1).then(function(){var t=Simpla.getState(),n=t.editable,i=t.authenticated,a=n||i;o(a),e._simplaObservers=[Simpla.observeState("authenticated",o),Simpla.observeState("editable",o)]})},unobserve:function(){this._simplaObservers.forEach(function(e){return e.unobserve()}),this._simplaObservers=[]}},P="#edit",B={_simplaObserver:null,_tracking:!1,track:function(){var e=this;_(function(){return!!window.Simpla},1).then(function(){a(),e._tracking||(window.addEventListener("hashchange",a),r(Simpla.getState("editable")),e._simplaObserver=Simpla.observeState("editable",r),e._tracking=!0)})},untrack:function(){this._tracking&&(window.removeEventListener("hashchange",a),this._simplaObserver&&this._simplaObserver.unobserve(),this._simplaObserver=null,this._tracking=!1)}},T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},x=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),j=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},H=["click","ontouchend"],N=void 0,q=void 0;q=function(){var e=void 0;return void 0!==T(window.Map)?new Map:(e=[],{has:function(t){return e.indexOf(t)!==-1},set:function(t,n){var i=e.indexOf(t);i===-1&&e.push(t)},delete:function(t){var n=e.indexOf(t);n!==-1&&e.splice(n,1)},forEach:function(t){e.forEach(function(e,n,i){return t.call(i,0,e,n)})}})}(),N=new MutationObserver(function(e){e.forEach(function(e){var t=c(e.addedNodes),n=c(e.removedNodes);d(t).forEach(y),f(t).forEach(m),v(n).forEach(g)})});var C={enable:function(){q.forEach(function(e,t){return g(t)}),N.disconnect(),b(document.body)},disable:function(){var e=c(document.querySelectorAll("*"));d(e).forEach(y),f(e).forEach(m),h(document.body),N.observe(document.body,{childList:!0,subtree:!0})}},M=["../simpla-login/simpla-login.html","../simpla-notify/simpla-notify.html","simpla-admin-controls.html"],F={saved:"changes saved",saveFailed:"something went wrong, try again?"},R={hashTracking:!0,loginPrompt:!0,hotkeys:!0,protectEditing:!0};window.SimplaAdmin=j({},R,window.SimplaAdmin),A.observe(),window.SimplaAdmin.hashTracking&&B.track();var $=function(){function e(){D(this,e)}return x(e,[{key:"beforeRegister",value:function(){this.is="simpla-admin",this.properties={hashTracking:{type:Boolean,observer:"_updateHashTracking"},protectEditing:Boolean,hidden:{type:Boolean,reflectToAttribute:!0},busy:{type:Boolean,value:!1},_editable:Boolean,_authenticated:Boolean,_dependenciesImported:Boolean,_loginOpen:Boolean,_simplaObservers:{type:Object,value:{}}},this.observers=["_toggleHidden(_editable, _authenticated)","_disableEditable(busy)","_updatePointerEvents(protectEditing, _editable)"]}},{key:"ready",value:function(){j(this,window.SimplaAdmin),window.SimplaAdmin=this}},{key:"attached",value:function(){this._importDependencies(),this._syncEditableAndAuthenticated()}},{key:"detached",value:function(){var e=this;Object.keys(this._simplaObservers).forEach(function(t){e._simplaObservers[t].unobserve()}),this._simplaObservers={},B.untrack(),A.unobserve()}},{key:"_disableEditable",value:function(e){e&&Simpla.getState("editable")?(B.untrack(),Simpla.editable(!1),this.__busyDisabled=!0):!e&&this.__busyDisabled&&(Simpla.editable(!0),B.track(),this.__busyDisabled=!1)}},{key:"login",value:function(){this.$.login.open()}},{key:"save",value:function(){var e=this,t=function(){e.busy=!1,e.fire("simpla-notification",{text:F.saved})},n=function(){e.busy=!1,e.fire("simpla-notification",{text:F.saveFailed})};this.busy=!0,Simpla.save().then(t).catch(n)}},{key:"_toggleHidden",value:function(e,t){this.hidden=!e&&!t}},{key:"_updateHashTracking",value:function(e){e?B.track():B.untrack()}},{key:"_updatePointerEvents",value:function(e,t){e&&t?C.disable():C.enable()}},{key:"_syncEditableAndAuthenticated",value:function(){var e=this,t=Simpla.getState(),n=t.editable,i=t.authenticated,o=function(t){return e._editable=t},a=function(t){return e._authenticated=t};o(n),a(i),this._simplaObservers.editable=Simpla.observeState("editable",o),this._simplaObservers.authenticated=Simpla.observeState("authenticated",a)}},{key:"_importDependencies",value:function(){var e=this;M.forEach(function(t){e.importHref(e.resolveUrl(t))})}},{key:"behaviors",get:function(){return[S,L,w]}}]),e}();Polymer($)}(); </script> </dom-module>
Loading