generated from hellofranklin/helixboilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
universal-editor-overlays-0.0.60.js
2 lines (2 loc) · 6.29 KB
/
universal-editor-overlays-0.0.60.js
1
2
var e=require("debounce"),t=require("uuid"),n=require("@aem-sites/universal-editor-commons");function o(e,t){return Object.keys(t).forEach((function(n){"default"===n||"__esModule"===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e}function r(e,t,n,o){Object.defineProperty(e,t,{get:n,set:o,enumerable:!0,configurable:!0})}var i={};r(i,"routines",(()=>b));const s={element:window.document},a=150,d="Component";var l={};r(l,"getEditableContent",(()=>u)),r(l,"handleEventListener",(()=>m)),r(l,"handleEventListenerAdapter",(()=>E)),r(l,"setupOverlayBlockingElement",(()=>p));const c=e=>{const t=window.getComputedStyle(e).backgroundColor,o=e.parentElement;return t===n.Constants.TRANSPARENT_BACKGROUND&&o?c(o):t},u=e=>{if(!(e&&e instanceof HTMLElement))return;const t=window.getComputedStyle(e);return{content:e.innerText,htmlContent:e.innerHTML,style:{font:t.getPropertyValue("font"),visibility:e.style.visibility,color:t.getPropertyValue("color"),textAlign:t.getPropertyValue("text-align"),textTransform:t.getPropertyValue("text-transform"),border:t.getPropertyValue("border"),padding:t.getPropertyValue("padding"),backgroundColor:c(e),width:t.getPropertyValue("width"),height:t.getPropertyValue("height")}}},m=e=>{e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();const t={pageHeight:document.documentElement.scrollHeight,pageYOffset:window.pageYOffset,type:e.type,x:null,y:null,keyModifiers:{advancedSelect:e.ctrlKey,multiSelect:e.shiftKey,metaKey:e.metaKey},editables:[]};"scroll"!==e.type&&(t.x=e.x,t.y=e.y,t.editables=document.elementsFromPoint(e.x,e.y).filter((e=>e.matches(n.Constants.EDITABLE_SELECTOR))).map((e=>{const t=u(e),n=v(e);return{content:(null==t?void 0:t.content)||"",htmlContent:(null==t?void 0:t.htmlContent)||"",style:(null==t?void 0:t.style)||{},id:n.id,rect:n.rect,label:n.label,itemprop:n.itemprop,itemid:n.itemid,itemtype:n.itemtype,parentid:n.parentid,containerid:n.containerid,selector:n.selector,pageYOffset:n.pageYOffset}}))),parent.postMessage({type:n.Constants.OVERLAY_INPUT_MESSAGE,payload:t},n.Constants.TARGET_ORIGIN)},E=e=>m(e),p=()=>{const e=document.createElement("div");e.id="OverlayBlockingElement",e.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 2147483647;",document.body.appendChild(e)},g=e=>{const t=e.closest(n.Constants.PARENT_SELECTOR);return(null==t?void 0:t.getAttribute(n.EDITABLE_ATTRS.ID))||""},v=e=>{const o=e.getAttribute(n.EDITABLE_ATTRS.TYPE)||"",r=e.getAttribute(n.EDITABLE_ATTRS.ID)||void 0,i=e.getAttribute(n.EDITABLE_ATTRS.PROP)||void 0,s=o===n.Constants.COMPONENT_ITEM_TYPE||e.getAttribute(n.EDITABLE_ATTRS.EDITOR_BEHAVIOR)===n.Constants.COMPONENT_ITEM_TYPE,a=!r&&i?g(e):"",l=s&&r?(e=>{const o=e.closest(n.Constants.CONTAINER_SELECTOR),r=null==o?void 0:o.getAttribute(n.EDITABLE_ATTRS.ID);if(r)return(0,t.v5)(`${r}`,t.v5.URL);const i=null==o?void 0:o.getAttribute(n.EDITABLE_ATTRS.PROP),s=o&&g(o);return i&&s?(0,t.v5)(`${s}_${i}`,t.v5.URL):""})(e):"",c=u(e);let m;r?m=`[${n.EDITABLE_ATTRS.ID}="${r}"]`:(m=`[${n.EDITABLE_ATTRS.ID}="${a}"] ${e.tagName.toLocaleLowerCase()}[${n.EDITABLE_ATTRS.TYPE}="${o}"]`,i&&(m+=`[${n.EDITABLE_ATTRS.PROP}="${i}"]`));const E=(0,t.v5)(`${r||a}${i?`_${i}`:""}`,t.v5.URL),p=o||d;let v={rect:e.getBoundingClientRect(),itemtype:o,label:p,id:E,itemid:r,itemprop:i,containerid:l,parentid:a,selector:m,pageYOffset:window.pageYOffset};return["text","richtext"].includes(o)&&(v={...v,...c}),v},h={viewport:{width:0,height:0},frame:{width:0,height:0},scroll:{x:0,y:0}},y=({editor:e})=>{null==e||e.updateFrameDetails({details:h})},T=({target:e})=>{const t=e.documentElement;h.scroll.x=t.scrollLeft,h.scroll.y=t.scrollTop},f=({target:e})=>{const t=Math.max(e.document.documentElement.clientWidth||0,e.innerWidth||0),n=Math.max(e.document.documentElement.clientHeight||0,e.innerHeight||0),{width:o,height:r}=e.document.documentElement.getBoundingClientRect();h.viewport={width:t,height:n},h.frame={width:Math.ceil(o),height:Math.ceil(r)}},b={discoverFonts:({editor:e})=>{const t=[];[...document.styleSheets].forEach((e=>{try{const{cssRules:n}=e;[...n].find((e=>e instanceof CSSFontFaceRule))&&e.href&&t.push(e.href)}catch(n){e.href&&t.push(e.href)}})),e.addCustomFonts(t)},observeEditables:({editor:t})=>{const o=s.element,r=(0,e.debounce)((()=>{const e=(e=>{const{scrollLeft:t,scrollTop:o}=e.documentElement,r=e.querySelectorAll(n.Constants.EDITABLE_SELECTOR)||[],i={editables:[],offset:{x:t,y:o},selected:{}};return r.forEach((e=>{const t=v(e);i.editables.push(t)})),i})(o);t.repaintEditables({editables:e})}),a);r(),window.removeEventListener("resize",r),window.addEventListener("resize",r),(({element:e,callback:t})=>{const n=new MutationObserver(t);n.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),n.disconnect})({element:o,callback:r})},observeFrame:({editor:t})=>{const n=window;n.document.addEventListener("scroll",(0,e.debounce)((({target:e})=>{T({target:e}),y({editor:t})}),a)),n.addEventListener("resize",(0,e.debounce)((({target:e})=>{f({target:e}),y({editor:t})}),a)),n.addEventListener("orientationchange",(0,e.debounce)((({target:e})=>{T({target:n.document}),f({target:e}),y({editor:t})}),a));const o=(0,e.debounce)((()=>{f({target:n}),y({editor:t})}),a);new ResizeObserver(o).observe(n.document.body),requestAnimationFrame((()=>{T({target:n.document}),f({target:n}),y({editor:t})}))},relayNavigation:({editor:e})=>{document.addEventListener("click",(t=>(({event:e,editor:t})=>{const n=e.target.closest("A");n&&(e.preventDefault(),t.navigateTo({href:n.href}))})({event:t,editor:e})),{capture:!0})},relayUserInputs:()=>{window.addEventListener("keydown",(({type:e,key:t,altKey:o,metaKey:r,shiftKey:i,ctrlKey:s})=>{const a={type:e,key:t,altKey:o,metaKey:r,shiftKey:i,ctrlKey:s};parent.postMessage({type:n.Constants.USER_INPUT_RELAY_MESSAGE,value:a},"*")})),p(),document.removeEventListener("scroll",E),document.removeEventListener("mousemove",m),document.removeEventListener("mousedown",m),document.removeEventListener("mouseup",m),document.removeEventListener("click",m),document.addEventListener("scroll",E),document.addEventListener("mousemove",m),document.addEventListener("mousedown",m),document.addEventListener("mouseup",m),document.addEventListener("click",m)}};o(module.exports,i),o(module.exports,l);
//# sourceMappingURL=index.js.map