@base44/vite-plugin 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/injections/canvas-wheel-zoom-bridge.d.ts +1 -1
- package/dist/injections/canvas-wheel-zoom-bridge.d.ts.map +1 -1
- package/dist/injections/canvas-wheel-zoom-bridge.js +53 -16
- package/dist/injections/canvas-wheel-zoom-bridge.js.map +1 -1
- package/dist/injections/page-height-bridge.d.ts.map +1 -1
- package/dist/injections/page-height-bridge.js +215 -27
- package/dist/injections/page-height-bridge.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +1 -0
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/statics/index.mjs +7 -7
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/injections/canvas-wheel-zoom-bridge.ts +67 -16
- package/src/injections/page-height-bridge.ts +229 -29
- package/src/injections/visual-edit-agent.ts +1 -0
package/dist/statics/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
function
|
|
2
|
-
[data-visual-edit-active] *:not([${
|
|
3
|
-
[data-visual-edit-active] *:not([${
|
|
4
|
-
[data-visual-edit-active] *:not([${
|
|
1
|
+
function ce(e,t){let n=t.top<27,i=t.height>=54,l=t.width>=window.innerWidth-4,c=l?"8px":"-2px",u=l?"8px":"4px";n&&i?(e.style.top="2px",e.style.left=u):n?(e.style.top=`${t.height+2}px`,e.style.left=c):(e.style.top="-27px",e.style.left=c)}function z(e){let t=e;return!!(t.dataset?.sourceLocation||t.dataset?.visualSelectorId)}function D(e){let t=e;return t.dataset?.sourceLocation||t.dataset?.visualSelectorId||null}var K=["src"],I="data-vite-plugin-element";function H(e){if(!e)return[];let t=Array.from(document.querySelectorAll(`[data-source-location="${e}"]`));return t.length>0?t:Array.from(document.querySelectorAll(`[data-visual-selector-id="${e}"]`))}function ue(e,t){e.forEach(n=>{n.setAttribute("class",t)})}function me(e,t,n){K.includes(t)&&e.forEach(i=>{i.setAttribute(t,n)})}function fe(e,t){let n={};for(let i of t){let l=e.getAttribute(i);l!==null&&(n[i]=l)}return n}function pe(){if(document.getElementById("freeze-animations"))return;document.documentElement.setAttribute("data-visual-edit-active","");let e=document.createElement("style");e.id="freeze-animations",e.textContent=`
|
|
2
|
+
[data-visual-edit-active] *:not([${I}]):not([${I}] *),
|
|
3
|
+
[data-visual-edit-active] *:not([${I}]):not([${I}] *)::before,
|
|
4
|
+
[data-visual-edit-active] *:not([${I}]):not([${I}] *)::after {
|
|
5
5
|
animation-play-state: paused !important;
|
|
6
6
|
transition: none !important;
|
|
7
7
|
}
|
|
8
8
|
`;let t=document.createElement("style");t.id="freeze-pointer-events",t.textContent=`
|
|
9
9
|
[data-visual-edit-active] * { pointer-events: none !important; }
|
|
10
|
-
[${
|
|
11
|
-
`;let n=document.head||document.documentElement;n.appendChild(e),n.appendChild(t),document.getAnimations().forEach(i=>{let l=i.effect?.target;if(!(l instanceof Element&&l.closest(`[${
|
|
10
|
+
[${I}], [${I}] * { pointer-events: auto !important; }
|
|
11
|
+
`;let n=document.head||document.documentElement;n.appendChild(e),n.appendChild(t),document.getAnimations().forEach(i=>{let l=i.effect?.target;if(!(l instanceof Element&&l.closest(`[${I}]`)))try{i.finish()}catch{i.pause()}})}function Ee(){let e=document.getElementById("freeze-animations");e&&(e.remove(),document.getElementById("freeze-pointer-events")?.remove(),document.documentElement.removeAttribute("data-visual-edit-active"),document.getAnimations().forEach(t=>{if(t.playState==="paused")try{t.play()}catch{}}))}function G(e,t){let n=document.getElementById("freeze-pointer-events");n&&(n.disabled=!0);let i=document.elementFromPoint(e,t);return n&&(n.disabled=!1),i?.closest("[data-source-location], [data-visual-selector-id]")??null}function ge(e,t,n){let i=G(e,t);if(!i)return null;let l=D(i);return l===n?null:l}var he={position:"absolute",backgroundColor:"#ffffff",border:"1px solid #e2e8f0",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",fontSize:"12px",minWidth:"120px",maxHeight:"200px",overflowY:"auto",zIndex:"10001",padding:"4px 0",pointerEvents:"auto"},ve={padding:"4px 12px",cursor:"pointer",color:"#334155",backgroundColor:"transparent",whiteSpace:"nowrap",lineHeight:"1.5",fontWeight:"400"},Y="#526cff",ye="#DBEAFE",be="600",q="#f1f5f9",Le=10,j='<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="2" fill="none"/></svg>',Te='<svg width="12" height="12" viewBox="0 0 24 24" style="vertical-align:middle;margin-left:4px"><path d="M18 15l-6-6-6 6" stroke="currentColor" stroke-width="2" fill="none"/></svg>',k="data-chevron",Se=12,V="data-layer-dropdown",we=2,Ie=2;function Z(e,t){for(let n of Object.keys(t))e.style.setProperty(n.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`),t[n])}function Me(e){return e.tagName}function J(e,t){let n={element:e,tagName:e.tagName.toLowerCase(),selectorId:D(e)};return t!==void 0&&(n.depth=t),n}function Ce(e,t,n){let i=[];function l(c,u){if(!(u>t))for(let d=0;d<c.children.length;d++){let p=c.children[d];if(z(p)){let h={element:p,tagName:p.tagName.toLowerCase(),selectorId:D(p)};n!==void 0&&(h.depth=n+u-1),i.push(h),l(p,u+1)}else l(p,u)}}return l(e,1),i}function et(e){let t=[],n=e.parentElement;for(;n&&n!==document.documentElement&&n!==document.body&&t.length<we;)z(n)&&t.push(J(n)),n=n.parentElement;return t.reverse(),t}function tt(e,t){return t.forEach((n,i)=>{e.push({...n,depth:i})}),t.length}function Ae(e,t,n){e.push(J(t,n));let i=Ce(t,Ie,n+1);e.push(...i)}function nt(e){return e.at(-1)?.element??null}function ot(e,t){let n=Ce(e,1);return n.some(i=>i.element===t)||n.push(J(t)),n}function rt(e,t,n,i){let l=D(n),c=new Set;for(let u of t)if(u.element===n)Ae(e,n,i),l&&c.add(l);else{let d=u.selectorId;if(d!=null){if(d===l||c.has(d))continue;c.add(d)}e.push({...u,depth:i})}}function De(e){let t=et(e),n=[],i=tt(n,t),l=nt(t);if(l){let c=ot(l,e);rt(n,c,e,i)}else Ae(n,e,i);return n}var P=null,Q=null,W=null,$=null,F=null;function it(e,t,{onSelect:n,onHover:i,onHoverEnd:l}){let c=document.createElement("div");c.textContent=Me(e),Z(c,ve);let u=e.depth??0;return u>0&&(c.style.paddingLeft=`${Se+u*Le}px`),t&&(c.style.color=Y,c.style.backgroundColor=ye,c.style.fontWeight=be),c.addEventListener("mouseenter",()=>{t||(c.style.backgroundColor=q),i&&i(e)}),c.addEventListener("mouseleave",()=>{t||(c.style.backgroundColor="transparent"),l&&l()}),c.addEventListener("click",d=>{d.stopPropagation(),d.preventDefault(),n(e)}),c}function lt(e,t,n){let i=document.createElement("div");return i.setAttribute(V,"true"),i.setAttribute(I,"true"),Z(i,he),e.forEach(l=>{let c=l.element===t;i.appendChild(it(l,c,n))}),i}function xe(e){if(e.querySelector(`[${k}]`))return;let t=document.createElement("span");t.setAttribute(k,"true"),t.style.display="inline-flex",t.innerHTML=j,e.appendChild(t),e.style.display="inline-flex",e.style.alignItems="center",e.style.cursor="pointer",e.style.userSelect="none",e.style.whiteSpace="nowrap",e.style.pointerEvents="auto",e.setAttribute(V,"true"),e.setAttribute(I,"true")}function st(e,t,n,{onSelect:i,onHover:l,onHoverEnd:c}){let u=Array.from(e.children),d=t.findIndex(h=>h.element===n),p=h=>{if(d>=0&&d<u.length){let S=u[d];S.style.color!==Y&&(S.style.backgroundColor="transparent")}if(d=h,d>=0&&d<u.length){let S=u[d];S.style.color!==Y&&(S.style.backgroundColor=q),S.scrollIntoView({block:"nearest"}),l&&d>=0&&d<t.length&&l(t[d])}};F=h=>{h.key==="ArrowDown"?(h.preventDefault(),h.stopPropagation(),p(d<u.length-1?d+1:0)):h.key==="ArrowUp"?(h.preventDefault(),h.stopPropagation(),p(d>0?d-1:u.length-1)):h.key==="Enter"&&d>=0&&d<t.length&&(h.preventDefault(),h.stopPropagation(),c&&c(),i(t[d]),_())},document.addEventListener("keydown",F,!0)}function at(e,t){let n=!0;W=i=>{if(n){n=!1;return}let l=i.target;!e.contains(l)&&l!==t&&_()},document.addEventListener("mousedown",W,!0)}function He(e,t,n,i){_();let l=lt(t,n,{...i,onSelect:d=>{i.onHoverEnd&&i.onHoverEnd(),i.onSelect(d),_()}}),c=e.parentElement;if(!c)return;l.style.top=`${e.offsetTop+e.offsetHeight+2}px`,l.style.left=`${e.offsetLeft}px`,c.appendChild(l),P=l,Q=e;let u=e.querySelector(`[${k}]`);u&&(u.innerHTML=Te),$=i.onHoverEnd??null,st(l,t,n,i),at(l,e)}function _(){let e=Q?.querySelector(`[${k}]`);e&&(e.innerHTML=j),Q=null,$&&($(),$=null),P&&P.parentNode&&P.remove(),P=null,W&&(document.removeEventListener("mousedown",W,!0),W=null),F&&(document.removeEventListener("keydown",F,!0),F=null)}function _e(){return P!==null}function Oe(e){let t=null,n=null,i=null,l=()=>{t&&t.parentNode&&t.remove(),t=null},c=b=>{l(),D(b.element)!==e.getSelectedElementId()&&(t=e.createPreviewOverlay(b.element))},u=b=>{l(),_(),n&&(document.removeEventListener("keydown",n,!0),n=null),i=null;let r=e.selectElement(b.element);h(r,b.element)},d=()=>{n&&(document.removeEventListener("keydown",n,!0),n=null),i&&(u(i),i=null)},p=(b,r,m,w,C)=>{b.stopPropagation(),b.preventDefault(),_e()?(_(),d()):(i={element:m,tagName:m.tagName.toLowerCase(),selectorId:C},e.onDeselect(),n=T=>{T.key==="Escape"&&(T.stopPropagation(),_(),d())},document.addEventListener("keydown",n,!0),He(r,w,m,{onSelect:u,onHover:c,onHoverEnd:l}))},h=(b,r)=>{if(!b)return;let m=b.querySelector("div");if(!m)return;let w=De(r);if(w.length<=1)return;let C=D(r);xe(m),m.addEventListener("click",T=>{p(T,m,r,w,C)})};return{attachToOverlay:h,cleanup:()=>{l(),_()}}}var ee="visual-edit-focus-styles",dt=["div","p","h1","h2","h3","h4","h5","h6","span","li","td","a","button","label"],te=e=>!!e.dataset.arrField,ct=e=>!(!dt.includes(e.tagName.toLowerCase())||!e.textContent?.trim()||e.querySelector("img, video, canvas, svg")||e.children?.length>0),Ne=()=>{if(document.getElementById(ee))return;let e=document.createElement("style");e.id=ee,e.textContent=`
|
|
12
12
|
[data-selected="true"][contenteditable="true"]:focus {
|
|
13
13
|
outline: none !important;
|
|
14
14
|
}
|
|
15
|
-
`,document.head.appendChild(e)},Oe=()=>{document.getElementById(Z)?.remove()},Ne=e=>{let t=document.createRange();t.selectNodeContents(e);let n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)},ct=e=>!(e instanceof HTMLElement)||!dt(e)?!1:J(e)?!0:e.dataset.dynamicContent!=="true",Q=e=>!(e instanceof HTMLElement)||e.dataset.selected!=="true"?!1:ct(e);var ut=500;function ee(e){let t=null,n=null,i=!1,l=new WeakMap,d=()=>{let r=e.getSelectedElementId();if(!r)return;let u=e.findElementsById(r);e.getSelectedOverlays().forEach((b,L)=>{L<u.length&&u[L]&&e.positionOverlay(b,u[L])})},m=r=>{let u=r.dataset.originalTextContent,v=r.textContent,b=r,L=r.getBoundingClientRect(),D={type:"inline-edit",elementInfo:{tagName:r.tagName,classes:b.className?.baseVal||r.className||"",visualSelectorId:e.getSelectedElementId(),content:v,dataSourceLocation:r.dataset.sourceLocation,isDynamicContent:r.dataset.dynamicContent==="true",linenumber:r.dataset.linenumber,filename:r.dataset.filename,position:{top:L.top,left:L.left,right:L.right,bottom:L.bottom,width:L.width,height:L.height,centerX:L.left+L.width/2,centerY:L.top+L.height/2}},originalContent:u,newContent:v};J(r)&&(D.arrIndex=r.dataset.arrIndex,D.arrVariableName=r.dataset.arrVariableName,D.arrField=r.dataset.arrField),window.parent.postMessage(D,"*"),r.dataset.originalTextContent=v||""},c=r=>{n&&clearTimeout(n),n=setTimeout(()=>m(r),ut)},f=r=>{d(),c(r)},h=function(){f(this)},w=r=>{_e(),r.dataset.originalTextContent=r.textContent||"",r.dataset.originalCursor=r.style.cursor,r.contentEditable="true",r.setAttribute(T,"true");let u=new AbortController;l.set(r,u),r.addEventListener("input",h,{signal:u.signal}),r.style.cursor="text",Ne(r),setTimeout(()=>{r.isConnected&&r.focus()},0)},y=r=>{let u=l.get(r);u&&(u.abort(),l.delete(r)),r.isConnected&&(Oe(),r.contentEditable="false",r.removeAttribute(T),delete r.dataset.originalTextContent,r.dataset.originalCursor!==void 0&&(r.style.cursor=r.dataset.originalCursor,delete r.dataset.originalCursor))};return{get enabled(){return i},set enabled(r){i=r},isEditing(){return t!==null},getCurrentElement(){return t},canEdit(r){return Q(r)},startEditing(r){t=r,e.getSelectedOverlays().forEach(u=>{u.style.display="none"}),w(r),window.parent.postMessage({type:"content-editing-started",visualSelectorId:e.getSelectedElementId()},"*")},stopEditing(){if(!t)return;n&&(clearTimeout(n),n=null),y(t),e.getSelectedOverlays().forEach(u=>{u.style.display=""}),d(),window.parent.postMessage({type:"content-editing-ended",visualSelectorId:e.getSelectedElementId()},"*"),t=null},markElementsSelected(r){r.forEach(u=>{u instanceof HTMLElement&&(u.dataset.selected="true")})},clearSelectedMarks(r){r&&e.findElementsById(r).forEach(u=>{u instanceof HTMLElement&&delete u.dataset.selected})},handleToggleMessage(r){if(!i)return;let u=e.findElementsById(r.dataSourceLocation);if(u.length===0||!(u[0]instanceof HTMLElement))return;let v=u[0];if(r.inlineEditingMode){if(!Q(v))return;e.getSelectedElementId()!==r.dataSourceLocation&&(this.stopEditing(),e.clearSelection(),this.markElementsSelected(u),e.createSelectionOverlays(u,r.dataSourceLocation)),this.startEditing(v)}else t===v&&this.stopEditing()},cleanup(){this.stopEditing()}}}var te="__theme-font-preview";function Re(){let e=t=>{!t.ctrlKey&&!t.metaKey||(t.preventDefault(),window.parent.postMessage({type:"canvas-wheel-zoom",data:{deltaY:t.deltaY,deltaMode:t.deltaMode,clientX:t.clientX,clientY:t.clientY,ctrlKey:t.ctrlKey,metaKey:t.metaKey}},"*"))};return{enable:()=>{window.addEventListener("wheel",e,{capture:!0,passive:!1})},teardown:()=>{window.removeEventListener("wheel",e,!0)}}}var ne="--base44-reference-vh-base";function Be(){let e=null,t=null,n,i="*";return{freezeVhUnits:l=>{let d=mt(l);if(ft(d),e){t?.();return}e=[],t=pt(e)},measurePageHeight:(l,d=2e3)=>{i=l,n!==void 0&&window.clearTimeout(n),n=window.setTimeout(()=>{requestAnimationFrame(()=>{let m=gt();window.parent.postMessage({type:"page-height-measured",height:m},i)})},d)},teardown:()=>{if(e){for(let l of e)l();e=null,t=null}n!==void 0&&window.clearTimeout(n)}}}function mt(e){if(e!==void 0)return e;let t=window.innerHeight||0;return t>=400?t:900}function ft(e){document.documentElement.style.setProperty(ne,`${e}px`)}function pt(e){let t=/(\d+(?:\.\d+)?)vh\b/g,n=new WeakSet,i=new WeakMap,l=new WeakSet,d=new Set,c=It(()=>{let r=u=>u.replace(t,(v,b)=>`calc(var(${ne}) * ${Et(b)})`);document.querySelectorAll("style").forEach(u=>{if(h(u),n.has(u))return;n.add(u);let v=u.textContent;if(!v||v.indexOf("vh")===-1)return;let b=r(v);b!==v&&(u.textContent=b)});for(let u=0;u<document.styleSheets.length;u++){let v=document.styleSheets[u];if(!v)continue;let b;try{b=v.cssRules}catch{continue}i.get(v)!==b.length&&(ke(b,r),i.set(v,b.length))}},16),f=c.trigger;e.push(c.cancel);let h=r=>{if(l.has(r))return;l.add(r);let u=new MutationObserver(()=>{n.delete(r),f()});u.observe(r,{characterData:!0,childList:!0,subtree:!0}),d.add(u)};e.push(()=>{for(let r of d)r.disconnect();d.clear()}),f(),document.readyState==="loading"&&(document.addEventListener("DOMContentLoaded",f),e.push(()=>document.removeEventListener("DOMContentLoaded",f))),window.addEventListener("load",f),e.push(()=>window.removeEventListener("load",f));let w=new MutationObserver(r=>{for(let u of r)if(Pe(u.addedNodes)||Pe(u.removedNodes)){f();return}});e.push(()=>w.disconnect());let y=()=>{document.head&&w.observe(document.head,{childList:!0,subtree:!1})};return document.head?y():(document.addEventListener("DOMContentLoaded",y),e.push(()=>document.removeEventListener("DOMContentLoaded",y))),f}function Et(e){return String(Number((parseFloat(e)/100).toFixed(6)))}function ke(e,t){for(let n=0;n<e.length;n++){let i=e[n];if(!i)continue;i.cssRules&&ke(i.cssRules,t);let l=i.style;if(l)for(let d=0;d<l.length;d++){let m=l[d];if(!m)continue;let c=l.getPropertyValue(m);if(!c||c.indexOf("vh")===-1)continue;let f=t(c);f!==c&&l.setProperty(m,f,l.getPropertyPriority(m))}}}function Pe(e){for(let t=0;t<e.length;t++){let n=e[t];if(n instanceof HTMLStyleElement||n instanceof HTMLLinkElement)return!0}return!1}function gt(){let e=Math.max(document.documentElement.scrollHeight,document.body?.scrollHeight??0),t=Math.max(window.innerHeight||0,document.documentElement.clientHeight,document.body?.clientHeight??0),n=vt(t),i=ht();return n>0?Math.ceil(Math.max(n,i)):Math.ceil(Math.max(e,i))}function ht(){let e=document.documentElement.style.getPropertyValue(ne),t=parseFloat(e);return Number.isFinite(t)?t:0}function vt(e){if(!document.body)return 0;let t=[document.body,...Array.from(document.body.querySelectorAll("*"))],n=new WeakMap,i=window.scrollY+e;for(let l=t.length-1;l>=0;l--){let d=t[l];if(!d)continue;let m=yt(d,n),c=bt(d),f=Tt(c,m,i)?0:c;n.set(d,Math.max(m,f))}return n.get(document.body)??0}function yt(e,t){let n=0;for(let i=0;i<e.children.length;i++){let l=e.children[i];l&&(n=Math.max(n,t.get(l)??0))}return n}function bt(e){let t=window.getComputedStyle(e);if(wt(t))return 0;let n=e.getBoundingClientRect();return n.width===0&&n.height===0?0:n.bottom+window.scrollY+Lt(t)}function Lt(e){let t=parseFloat(e.marginBottom);return Number.isFinite(t)?t:0}function wt(e){return e.position==="fixed"?!0:e.position==="absolute"&&e.pointerEvents==="none"}function Tt(e,t,n){return t>0&&Math.abs(e-n)<=1&&e-t>8}function It(e,t){let n;return{trigger:()=>{n!==void 0&&window.clearTimeout(n),n=window.setTimeout(e,t)},cancel:()=>{n!==void 0&&(window.clearTimeout(n),n=void 0)}}}var k=50;function St(){let e=Re(),t=Be(),n=!1,i=!1,l=!1,d=[],m=[],c=[],f=null,h=null,w=(s=!1)=>{let o=document.createElement("div");return o.style.position="absolute",o.style.pointerEvents="none",o.style.transition="all 0.1s ease-in-out",o.style.zIndex="9999",s?o.style.border="2px solid #2563EB":(o.style.border="2px solid #95a5fc",o.style.backgroundColor="rgba(99, 102, 241, 0.05)"),o},y=(s,o,a=!1)=>{if(!o||!n)return;o.offsetWidth;let E=o.getBoundingClientRect();s.style.top=`${E.top+window.scrollY}px`,s.style.left=`${E.left+window.scrollX}px`,s.style.width=`${E.width}px`,s.style.height=`${E.height}px`;let g=s.querySelector("div");g||(g=document.createElement("div"),g.textContent=o.tagName.toLowerCase(),g.style.position="absolute",g.style.left="-2px",g.style.padding="2px 8px",g.style.fontSize="11px",g.style.fontWeight=a?"500":"400",g.style.color=a?"#ffffff":"#526cff",g.style.backgroundColor=a?"#2563EB":"#DBEAFE",g.style.borderRadius="3px",g.style.minWidth="24px",g.style.textAlign="center",s.appendChild(g)),ae(g,E)},r=ee({findElementsById:C,getSelectedElementId:()=>f,getSelectedOverlays:()=>m,positionOverlay:y,clearSelection:()=>{r.clearSelectedMarks(f),b(),f=null,h=null},createSelectionOverlays:(s,o)=>{s.forEach(a=>{let p=w(!0);document.body.appendChild(p),m.push(p),y(p,a,!0)}),f=o}}),u=()=>{r.clearSelectedMarks(f),b(),f=null,h=null},v=()=>{d.forEach(s=>{s&&s.parentNode&&s.remove()}),d=[],c=[]},b=()=>{m.forEach(s=>{s&&s.parentNode&&s.remove()}),m=[]},L=["p","h1","h2","h3","h4","h5","h6","span","a","label"],D=s=>{let o=s,a=s.getBoundingClientRect(),p=s,E=L.includes(s.tagName?.toLowerCase()),g=o.closest("[data-arr-variable-name]"),I=g?.dataset?.arrVariableName||null,A=g?.dataset?.arrIndex,qe=A!=null?parseInt(A,10):null,Ke=o.dataset?.arrField||null,je=o.closest("[data-collection-id]"),Ze=o.closest("[data-collection-item-field]"),Je=o.closest("[data-collection-item-id]");window.parent.postMessage({type:"element-selected",tagName:s.tagName,classes:p.className?.baseVal||s.className||"",visualSelectorId:S(s),content:E?o.innerText:void 0,dataSourceLocation:o.dataset.sourceLocation,isDynamicContent:o.dataset.dynamicContent==="true",linenumber:o.dataset.linenumber,filename:o.dataset.filename,position:{top:a.top,left:a.left,right:a.right,bottom:a.bottom,width:a.width,height:a.height,centerX:a.left+a.width/2,centerY:a.top+a.height/2},attributes:ue(s,U),isTextElement:E,staticArrayName:I,staticArrayIndex:qe,staticArrayField:Ke,collectionId:je?.dataset?.collectionId||null,collectionItemField:Ze?.dataset?.collectionItemField||null,collectionItemId:Je?.dataset?.collectionItemId||null},"*")},oe=s=>{let o=S(s);return b(),C(o||null).forEach(p=>{let E=w(!0);document.body.appendChild(E),m.push(E),y(E,p,!0)}),f=o||null,h=s,v(),D(s),m[0]},Ve=()=>{f=null,window.parent.postMessage({type:"unselect-element"},"*")},V=null,x=null,W=()=>{v(),V=null},We=s=>{let o=C(s);v(),o.forEach(a=>{let p=w(!1);document.body.appendChild(p),d.push(p),y(p,a)}),c=o,V=s},re=s=>{!n||i||r.isEditing()||x===null&&(x=requestAnimationFrame(()=>{if(x=null,l){W();return}let o=pe(s.clientX,s.clientY,f);if(!o){W();return}V!==o&&We(o)}))},F=()=>{x!==null&&(cancelAnimationFrame(x),x=null),W()},ie=s=>{if(!n)return;let o=s.target;if(o.closest(`[${O}]`)||r.enabled&&o instanceof HTMLElement&&o.contentEditable==="true")return;if(r.isEditing()){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),r.stopEditing();return}if(l){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation();let a=X(s.clientX,s.clientY);if(!a)return;let p=a,E=S(a);if(f===E&&p.dataset.selected==="true"&&r.enabled&&r.canEdit(p)){r.startEditing(p);return}r.stopEditing(),r.enabled&&r.markElementsSelected(C(E));let I=oe(a);se.attachToOverlay(I,a)},Fe=()=>{r.stopEditing(),u()},$e=(s,o)=>{let a=C(s);a.length!==0&&(de(a,o),setTimeout(()=>{f===s&&m.forEach((p,E)=>{E<a.length&&y(p,a[E])}),c.length>0&&c[0]?.dataset?.visualSelectorId===s&&d.forEach((g,I)=>{I<c.length&&y(g,c[I])})},k))},ze=(s,o,a)=>{let p=C(s);p.length!==0&&(ce(p,o,a),setTimeout(()=>{f===s&&m.forEach((E,g)=>{g<p.length&&y(E,p[g])})},k))},Ue=(s,o,a)=>{let p=C(s);p.length!==0&&(a!=null&&(p=p.filter(E=>E.dataset.arrIndex===String(a))),p.forEach(E=>{E.innerText=o}),setTimeout(()=>{f===s&&m.forEach((E,g)=>{g<p.length&&y(E,p[g])})},k))},se=He({createPreviewOverlay:s=>{let o=w(!1);return o.style.zIndex="9998",document.body.appendChild(o),y(o,s),o},getSelectedElementId:()=>f,selectElement:oe,onDeselect:Ve}),Xe=s=>{n=s,s?(document.body.style.cursor="crosshair",me(),document.addEventListener("mousemove",re),document.addEventListener("mouseleave",F),document.addEventListener("click",ie,!0)):(fe(),r.stopEditing(),u(),se.cleanup(),F(),document.body.style.cursor="default",document.removeEventListener("mousemove",re),document.removeEventListener("mouseleave",F),document.removeEventListener("click",ie,!0))},le=()=>{if(f){let s=h;if(s&&s.isConnected){let o=s.getBoundingClientRect(),a=window.innerHeight,p=window.innerWidth,E=o.top<a&&o.bottom>0&&o.left<p&&o.right>0,g={top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2};window.parent.postMessage({type:"element-position-update",position:g,isInViewport:E,visualSelectorId:f},"*")}}},Ye=s=>{let o=s.data;switch(o.type){case"toggle-visual-edit-mode":Xe(o.data.enabled),o.data.specs?.newInlineEditEnabled!==void 0&&(r.enabled=o.data.specs.newInlineEditEnabled);break;case"update-classes":o.data&&o.data.classes!==void 0?$e(o.data.visualSelectorId,o.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",o);break;case"update-attribute":o.data&&o.data.visualSelectorId&&o.data.attribute!==void 0&&o.data.value!==void 0?ze(o.data.visualSelectorId,o.data.attribute,o.data.value):console.warn("[VisualEditAgent] Invalid update-attribute message:",o);break;case"unselect-element":Fe();break;case"refresh-page":window.location.reload();break;case"update-content":o.data&&o.data.content!==void 0?Ue(o.data.visualSelectorId,o.data.content,o.data.arrIndex):console.warn("[VisualEditAgent] Invalid update-content message:",o);break;case"request-element-position":if(f&&h&&h.isConnected){let a=h.getBoundingClientRect(),p=window.innerHeight,E=window.innerWidth,g=a.top<p&&a.bottom>0&&a.left<E&&a.right>0,I={top:a.top,left:a.left,right:a.right,bottom:a.bottom,width:a.width,height:a.height,centerX:a.left+a.width/2,centerY:a.top+a.height/2};window.parent.postMessage({type:"element-position-update",position:I,isInViewport:g,visualSelectorId:f},"*")}break;case"popover-drag-state":o.data&&o.data.isDragging!==void 0&&(i=o.data.isDragging,o.data.isDragging&&v());break;case"dropdown-state":o.data&&o.data.isOpen!==void 0&&(l=o.data.isOpen,o.data.isOpen&&v());break;case"update-theme-variables":if(o.data?.variables){let a=o.data.mode==="dark"?document.querySelector(".dark"):document.documentElement;if(a)for(let[p,E]of Object.entries(o.data.variables))a.style.setProperty(p,E)}break;case"inject-font-import":if(o.data?.fontUrl){let a=document.getElementById(te);a||(a=document.createElement("style"),a.id=te,document.head.appendChild(a)),a.textContent=`@import url('${o.data.fontUrl}');`}break;case"toggle-inline-edit-mode":o.data&&r.handleToggleMessage(o.data);break;case"freeze-vh-units":t.freezeVhUnits(typeof o.referenceVhBase=="number"?o.referenceVhBase:void 0);break;case"measure-page-height":t.measurePageHeight(s.origin&&s.origin!=="null"?s.origin:"*",typeof o.settleMs=="number"?o.settleMs:void 0);break;case"toggle-canvas-wheel-zoom-bridge":e.enable();break;default:break}},$=()=>{if(f){let s=C(f);m.forEach((o,a)=>{a<s.length&&y(o,s[a])})}c.length>0&&d.forEach((s,o)=>{o<c.length&&y(s,c[o])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((s,o)=>{let a=s,p=`visual-id-${a.dataset.filename}-${a.dataset.linenumber}-${o}`;a.dataset.visualSelectorId=p});let Ge=new MutationObserver(s=>{s.some(a=>{let p=g=>{if(g.nodeType===Node.ELEMENT_NODE){let I=g;if(I.dataset&&I.dataset.visualSelectorId)return!0;for(let A=0;A<I.children.length;A++)if(p(I.children[A]))return!0}return!1};return a.type==="attributes"&&(a.attributeName==="style"||a.attributeName==="class"||a.attributeName==="width"||a.attributeName==="height")&&p(a.target)})&&setTimeout($,k)});window.addEventListener("message",Ye),window.addEventListener("scroll",le,!0),document.addEventListener("scroll",le,!0),window.addEventListener("resize",$),window.addEventListener("scroll",$),Ge.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{St as setupVisualEditAgent};
|
|
15
|
+
`,document.head.appendChild(e)},Re=()=>{document.getElementById(ee)?.remove()},Pe=e=>{let t=document.createRange();t.selectNodeContents(e);let n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)},ut=e=>!(e instanceof HTMLElement)||!ct(e)?!1:te(e)?!0:e.dataset.dynamicContent!=="true",ne=e=>!(e instanceof HTMLElement)||e.dataset.selected!=="true"?!1:ut(e);var mt=500;function oe(e){let t=null,n=null,i=!1,l=new WeakMap,c=()=>{let r=e.getSelectedElementId();if(!r)return;let m=e.findElementsById(r);e.getSelectedOverlays().forEach((C,T)=>{T<m.length&&m[T]&&e.positionOverlay(C,m[T])})},u=r=>{let m=r.dataset.originalTextContent,w=r.textContent,C=r,T=r.getBoundingClientRect(),O={type:"inline-edit",elementInfo:{tagName:r.tagName,classes:C.className?.baseVal||r.className||"",visualSelectorId:e.getSelectedElementId(),content:w,dataSourceLocation:r.dataset.sourceLocation,isDynamicContent:r.dataset.dynamicContent==="true",linenumber:r.dataset.linenumber,filename:r.dataset.filename,position:{top:T.top,left:T.left,right:T.right,bottom:T.bottom,width:T.width,height:T.height,centerX:T.left+T.width/2,centerY:T.top+T.height/2}},originalContent:m,newContent:w};te(r)&&(O.arrIndex=r.dataset.arrIndex,O.arrVariableName=r.dataset.arrVariableName,O.arrField=r.dataset.arrField),window.parent.postMessage(O,"*"),r.dataset.originalTextContent=w||""},d=r=>{n&&clearTimeout(n),n=setTimeout(()=>u(r),mt)},p=r=>{c(),d(r)},h=function(){p(this)},S=r=>{Ne(),r.dataset.originalTextContent=r.textContent||"",r.dataset.originalCursor=r.style.cursor,r.contentEditable="true",r.setAttribute(I,"true");let m=new AbortController;l.set(r,m),r.addEventListener("input",h,{signal:m.signal}),r.style.cursor="text",Pe(r),setTimeout(()=>{r.isConnected&&r.focus()},0)},b=r=>{let m=l.get(r);m&&(m.abort(),l.delete(r)),r.isConnected&&(Re(),r.contentEditable="false",r.removeAttribute(I),delete r.dataset.originalTextContent,r.dataset.originalCursor!==void 0&&(r.style.cursor=r.dataset.originalCursor,delete r.dataset.originalCursor))};return{get enabled(){return i},set enabled(r){i=r},isEditing(){return t!==null},getCurrentElement(){return t},canEdit(r){return ne(r)},startEditing(r){t=r,e.getSelectedOverlays().forEach(m=>{m.style.display="none"}),S(r),window.parent.postMessage({type:"content-editing-started",visualSelectorId:e.getSelectedElementId()},"*")},stopEditing(){if(!t)return;n&&(clearTimeout(n),n=null),b(t),e.getSelectedOverlays().forEach(m=>{m.style.display=""}),c(),window.parent.postMessage({type:"content-editing-ended",visualSelectorId:e.getSelectedElementId()},"*"),t=null},markElementsSelected(r){r.forEach(m=>{m instanceof HTMLElement&&(m.dataset.selected="true")})},clearSelectedMarks(r){r&&e.findElementsById(r).forEach(m=>{m instanceof HTMLElement&&delete m.dataset.selected})},handleToggleMessage(r){if(!i)return;let m=e.findElementsById(r.dataSourceLocation);if(m.length===0||!(m[0]instanceof HTMLElement))return;let w=m[0];if(r.inlineEditingMode){if(!ne(w))return;e.getSelectedElementId()!==r.dataSourceLocation&&(this.stopEditing(),e.clearSelection(),this.markElementsSelected(m),e.createSelectionOverlays(m,r.dataSourceLocation)),this.startEditing(w)}else t===w&&this.stopEditing()},cleanup(){this.stopEditing()}}}var re="__theme-font-preview";function ft(e){return e instanceof Element?e:e instanceof Node?e.parentElement:null}function pt(e){return ft(e)?.closest(`[${I}]`)!=null}function Be(){let e=!1,t=l=>{if(pt(l.target))return;if(l.preventDefault(),l.ctrlKey||l.metaKey){window.parent.postMessage({type:"canvas-wheel-zoom",data:{deltaY:l.deltaY,deltaMode:l.deltaMode,clientX:l.clientX,clientY:l.clientY,ctrlKey:l.ctrlKey,metaKey:l.metaKey}},"*");return}let c={deltaX:l.deltaX,deltaY:l.deltaY,deltaMode:l.deltaMode,clientX:l.clientX,clientY:l.clientY,shiftKey:l.shiftKey,ctrlKey:!1,metaKey:!1};window.parent.postMessage({type:"canvas-wheel-pan",data:c},"*")};return{enable:()=>{e||(e=!0,window.addEventListener("wheel",t,{capture:!0,passive:!1}))},disable:()=>{e&&(e=!1,window.removeEventListener("wheel",t,!0))}}}var ie="--base44-reference-vh-base";function We(){let e=null,t=null,n,i,l="*",c=()=>{n!==void 0&&(window.clearTimeout(n),n=void 0),i!==void 0&&(window.clearTimeout(i),i=void 0)};return{freezeVhUnits:u=>{let d=Et(u);if(gt(d),e){t?.();return}e=[],t=ht(e)},measurePageHeight:(u,d=2e3)=>{l=u,c(),n=window.setTimeout(()=>{n=void 0,t?.();let p=ke()+1500,h=-1,S=0,b=m=>{i=void 0,window.parent.postMessage({type:"page-height-measured",height:m},l)},r=()=>{i=void 0;let m=yt();if(m===h?S++:(S=1,h=m),S>=3||ke()>=p){b(m);return}i=window.setTimeout(r,16)};r()},d)},teardown:()=>{if(e){for(let u of e)u();e=null,t=null}c()}}}function ke(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Et(e){if(e!==void 0)return e;let t=window.innerHeight||0;return t>=400?t:900}function gt(e){document.documentElement.style.setProperty(ie,`${e}px`)}function ht(e){let t=/(\d+(?:\.\d+)?)(?:d|s|l)?vh\b/g,n=new WeakSet,i=new WeakMap,l=new WeakSet,c=new Set,u=new WeakSet,d=f=>f.replace(t,(g,L)=>`calc(var(${ie}) * ${vt(L)})`),p=f=>{if(u.has(f))return;let L=window.getComputedStyle(f).overflowY;L!=="auto"&&L!=="scroll"||(u.add(f),f.style.setProperty("overflow-y","visible","important"))},h=f=>{p(f),f.querySelectorAll("*").forEach(p)},S=f=>{let g=f.style;if(!g||g.length===0)return;let L=[];for(let M=0;M<g.length;M++){let x=g[M];x&&L.push(x)}for(let M of L){let x=g.getPropertyValue(M);if(!x||x.indexOf("vh")===-1)continue;let N=d(x);N!==x&&g.setProperty(M,N,g.getPropertyPriority(M))}},r=Ct(()=>{document.querySelectorAll("style").forEach(f=>{if(w(f),n.has(f))return;n.add(f);let g=f.textContent;if(!g||g.indexOf("vh")===-1)return;let L=d(g);L!==g&&(f.textContent=L)});for(let f=0;f<document.styleSheets.length;f++){let g=document.styleSheets[f];if(!g)continue;let L;try{L=g.cssRules}catch{continue}i.get(g)!==L.length&&(Fe(L,d),i.set(g,L.length))}document.querySelectorAll('[style*="vh"]').forEach(S),document.body&&h(document.body)},16),m=r.trigger;e.push(r.cancel);let w=f=>{if(l.has(f))return;l.add(f);let g=new MutationObserver(()=>{n.delete(f),m()});g.observe(f,{characterData:!0,childList:!0,subtree:!0}),c.add(g)};e.push(()=>{for(let f of c)f.disconnect();c.clear()}),m(),document.readyState==="loading"&&(document.addEventListener("DOMContentLoaded",m),e.push(()=>document.removeEventListener("DOMContentLoaded",m))),window.addEventListener("load",m),e.push(()=>window.removeEventListener("load",m));let C=new MutationObserver(f=>{for(let g of f)if(Ve(g.addedNodes)||Ve(g.removedNodes)){m();return}});e.push(()=>C.disconnect());let T=()=>{document.head&&C.observe(document.head,{childList:!0,subtree:!1})};document.head?T():(document.addEventListener("DOMContentLoaded",T),e.push(()=>document.removeEventListener("DOMContentLoaded",T)));let O=f=>{if(!(f instanceof Element))return;let g=f.getAttribute("style");g&&g.indexOf("vh")!==-1&&S(f),f.querySelectorAll('[style*="vh"]').forEach(S),h(f)},B=new MutationObserver(f=>{for(let g of f)if(g.type==="attributes"){let L=g.target;if(!(L instanceof Element))continue;let M=L.getAttribute("style");if(!M||M.indexOf("vh")===-1)continue;S(L)}else if(g.type==="childList")for(let L=0;L<g.addedNodes.length;L++){let M=g.addedNodes[L];M&&O(M)}});return e.push(()=>B.disconnect()),(()=>{let f=document.documentElement;f&&B.observe(f,{attributes:!0,attributeFilter:["style"],childList:!0,subtree:!0})})(),m}function vt(e){return String(Number((parseFloat(e)/100).toFixed(6)))}function Fe(e,t){for(let n=0;n<e.length;n++){let i=e[n];if(!i)continue;i.cssRules&&Fe(i.cssRules,t);let l=i.style;if(l)for(let c=0;c<l.length;c++){let u=l[c];if(!u)continue;let d=l.getPropertyValue(u);if(!d||d.indexOf("vh")===-1)continue;let p=t(d);p!==d&&l.setProperty(u,p,l.getPropertyPriority(u))}}}function Ve(e){for(let t=0;t<e.length;t++){let n=e[t];if(n instanceof HTMLStyleElement||n instanceof HTMLLinkElement)return!0}return!1}function yt(){let e=Math.max(document.documentElement.scrollHeight,document.body?.scrollHeight??0),t=bt(),n=Math.max(window.innerHeight||0,document.documentElement.clientHeight,t),i=Lt(n);return i>0?Math.ceil(Math.max(i,t)):Math.ceil(Math.max(e,t))}function bt(){let e=document.documentElement.style.getPropertyValue(ie),t=parseFloat(e);return Number.isFinite(t)?t:0}function Lt(e){if(!document.body)return 0;let t=[document.body,...Array.from(document.body.querySelectorAll("*"))],n=new WeakMap,i=window.scrollY+e;for(let l=t.length-1;l>=0;l--){let c=t[l];if(!c)continue;let u=Tt(c,n),d=St(c),p=Mt(d,u,e,i)?0:d.bottom;n.set(c,Math.max(u,p))}return n.get(document.body)??0}function Tt(e,t){let n=0;for(let i=0;i<e.children.length;i++){let l=e.children[i];l&&(n=Math.max(n,t.get(l)??0))}return n}function St(e){let t=window.getComputedStyle(e);if(It(t))return{bottom:0,height:0};let n=e.getBoundingClientRect();return n.width===0&&n.height===0?{bottom:0,height:0}:{bottom:n.bottom+window.scrollY+wt(t),height:n.height}}function wt(e){let t=parseFloat(e.marginBottom);return Number.isFinite(t)?t:0}function It(e){return e.position==="fixed"?!0:e.position==="absolute"&&e.pointerEvents==="none"}function Mt(e,t,n,i){return t>0&&Math.abs(e.bottom-i)<=1&&Math.abs(e.height-n)<=1&&e.bottom-t>8}function Ct(e,t){let n;return{trigger:()=>{n!==void 0&&window.clearTimeout(n),n=window.setTimeout(e,t)},cancel:()=>{n!==void 0&&(window.clearTimeout(n),n=void 0)}}}var X=50;function At(){let e=Be(),t=We(),n=!1,i=!1,l=!1,c=[],u=[],d=[],p=null,h=null,S=(s=!1)=>{let o=document.createElement("div");return o.style.position="absolute",o.style.pointerEvents="none",o.style.transition="all 0.1s ease-in-out",o.style.zIndex="9999",s?o.style.border="2px solid #2563EB":(o.style.border="2px solid #95a5fc",o.style.backgroundColor="rgba(99, 102, 241, 0.05)"),o},b=(s,o,a=!1)=>{if(!o||!n)return;o.offsetWidth;let v=o.getBoundingClientRect();s.style.top=`${v.top+window.scrollY}px`,s.style.left=`${v.left+window.scrollX}px`,s.style.width=`${v.width}px`,s.style.height=`${v.height}px`;let y=s.querySelector("div");y||(y=document.createElement("div"),y.textContent=o.tagName.toLowerCase(),y.style.position="absolute",y.style.left="-2px",y.style.padding="2px 8px",y.style.fontSize="11px",y.style.fontWeight=a?"500":"400",y.style.color=a?"#ffffff":"#526cff",y.style.backgroundColor=a?"#2563EB":"#DBEAFE",y.style.borderRadius="3px",y.style.minWidth="24px",y.style.textAlign="center",s.appendChild(y)),ce(y,v)},r=oe({findElementsById:H,getSelectedElementId:()=>p,getSelectedOverlays:()=>u,positionOverlay:b,clearSelection:()=>{r.clearSelectedMarks(p),C(),p=null,h=null},createSelectionOverlays:(s,o)=>{s.forEach(a=>{let E=S(!0);document.body.appendChild(E),u.push(E),b(E,a,!0)}),p=o}}),m=()=>{r.clearSelectedMarks(p),C(),p=null,h=null},w=()=>{c.forEach(s=>{s&&s.parentNode&&s.remove()}),c=[],d=[]},C=()=>{u.forEach(s=>{s&&s.parentNode&&s.remove()}),u=[]},T=["p","h1","h2","h3","h4","h5","h6","span","a","label"],O=s=>{let o=s,a=s.getBoundingClientRect(),E=s,v=T.includes(s.tagName?.toLowerCase()),y=o.closest("[data-arr-variable-name]"),A=y?.dataset?.arrVariableName||null,R=y?.dataset?.arrIndex,qe=R!=null?parseInt(R,10):null,je=o.dataset?.arrField||null,Ze=o.closest("[data-collection-id]"),Je=o.closest("[data-collection-item-field]"),Qe=o.closest("[data-collection-item-id]");window.parent.postMessage({type:"element-selected",tagName:s.tagName,classes:E.className?.baseVal||s.className||"",visualSelectorId:D(s),content:v?o.innerText:void 0,dataSourceLocation:o.dataset.sourceLocation,isDynamicContent:o.dataset.dynamicContent==="true",linenumber:o.dataset.linenumber,filename:o.dataset.filename,position:{top:a.top,left:a.left,right:a.right,bottom:a.bottom,width:a.width,height:a.height,centerX:a.left+a.width/2,centerY:a.top+a.height/2},attributes:fe(s,K),isTextElement:v,staticArrayName:A,staticArrayIndex:qe,staticArrayField:je,collectionId:Ze?.dataset?.collectionId||null,collectionItemField:Je?.dataset?.collectionItemField||null,collectionItemId:Qe?.dataset?.collectionItemId||null},"*")},B=s=>{let o=D(s);return C(),H(o||null).forEach(E=>{let v=S(!0);document.body.appendChild(v),u.push(v),b(v,E,!0)}),p=o||null,h=s,w(),O(s),u[0]},le=()=>{p=null,window.parent.postMessage({type:"unselect-element"},"*")},f=null,g=null,L=()=>{w(),f=null},M=s=>{let o=H(s);w(),o.forEach(a=>{let E=S(!1);document.body.appendChild(E),c.push(E),b(E,a)}),d=o,f=s},x=s=>{!n||i||r.isEditing()||g===null&&(g=requestAnimationFrame(()=>{if(g=null,l){L();return}let o=ge(s.clientX,s.clientY,p);if(!o){L();return}f!==o&&M(o)}))},N=()=>{g!==null&&(cancelAnimationFrame(g),g=null),L()},se=s=>{if(!n)return;let o=s.target;if(o.closest(`[${V}]`)||r.enabled&&o instanceof HTMLElement&&o.contentEditable==="true")return;if(r.isEditing()){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),r.stopEditing();return}if(l){s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation();let a=G(s.clientX,s.clientY);if(!a)return;let E=a,v=D(a);if(p===v&&E.dataset.selected==="true"&&r.enabled&&r.canEdit(E)){r.startEditing(E);return}r.stopEditing(),r.enabled&&r.markElementsSelected(H(v));let A=B(a);ae.attachToOverlay(A,a)},Ye=()=>{r.stopEditing(),m()},$e=(s,o)=>{let a=H(s);a.length!==0&&(ue(a,o),setTimeout(()=>{p===s&&u.forEach((E,v)=>{v<a.length&&b(E,a[v])}),d.length>0&&d[0]?.dataset?.visualSelectorId===s&&c.forEach((y,A)=>{A<d.length&&b(y,d[A])})},X))},Xe=(s,o,a)=>{let E=H(s);E.length!==0&&(me(E,o,a),setTimeout(()=>{p===s&&u.forEach((v,y)=>{y<E.length&&b(v,E[y])})},X))},Ue=(s,o,a)=>{let E=H(s);E.length!==0&&(a!=null&&(E=E.filter(v=>v.dataset.arrIndex===String(a))),E.forEach(v=>{v.innerText=o}),setTimeout(()=>{p===s&&u.forEach((v,y)=>{y<E.length&&b(v,E[y])})},X))},ae=Oe({createPreviewOverlay:s=>{let o=S(!1);return o.style.zIndex="9998",document.body.appendChild(o),b(o,s),o},getSelectedElementId:()=>p,selectElement:B,onDeselect:le}),ze=s=>{n=s,s?(document.body.style.cursor="crosshair",pe(),document.addEventListener("mousemove",x),document.addEventListener("mouseleave",N),document.addEventListener("click",se,!0)):(e.disable(),Ee(),r.stopEditing(),m(),ae.cleanup(),N(),document.body.style.cursor="default",document.removeEventListener("mousemove",x),document.removeEventListener("mouseleave",N),document.removeEventListener("click",se,!0))},de=()=>{if(p){let s=h;if(s&&s.isConnected){let o=s.getBoundingClientRect(),a=window.innerHeight,E=window.innerWidth,v=o.top<a&&o.bottom>0&&o.left<E&&o.right>0,y={top:o.top,left:o.left,right:o.right,bottom:o.bottom,width:o.width,height:o.height,centerX:o.left+o.width/2,centerY:o.top+o.height/2};window.parent.postMessage({type:"element-position-update",position:y,isInViewport:v,visualSelectorId:p},"*")}}},Ke=s=>{let o=s.data;switch(o.type){case"toggle-visual-edit-mode":ze(o.data.enabled),o.data.specs?.newInlineEditEnabled!==void 0&&(r.enabled=o.data.specs.newInlineEditEnabled);break;case"update-classes":o.data&&o.data.classes!==void 0?$e(o.data.visualSelectorId,o.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",o);break;case"update-attribute":o.data&&o.data.visualSelectorId&&o.data.attribute!==void 0&&o.data.value!==void 0?Xe(o.data.visualSelectorId,o.data.attribute,o.data.value):console.warn("[VisualEditAgent] Invalid update-attribute message:",o);break;case"unselect-element":Ye();break;case"refresh-page":window.location.reload();break;case"update-content":o.data&&o.data.content!==void 0?Ue(o.data.visualSelectorId,o.data.content,o.data.arrIndex):console.warn("[VisualEditAgent] Invalid update-content message:",o);break;case"request-element-position":if(p&&h&&h.isConnected){let a=h.getBoundingClientRect(),E=window.innerHeight,v=window.innerWidth,y=a.top<E&&a.bottom>0&&a.left<v&&a.right>0,A={top:a.top,left:a.left,right:a.right,bottom:a.bottom,width:a.width,height:a.height,centerX:a.left+a.width/2,centerY:a.top+a.height/2};window.parent.postMessage({type:"element-position-update",position:A,isInViewport:y,visualSelectorId:p},"*")}break;case"popover-drag-state":o.data&&o.data.isDragging!==void 0&&(i=o.data.isDragging,o.data.isDragging&&w());break;case"dropdown-state":o.data&&o.data.isOpen!==void 0&&(l=o.data.isOpen,o.data.isOpen&&w());break;case"update-theme-variables":if(o.data?.variables){let a=o.data.mode==="dark"?document.querySelector(".dark"):document.documentElement;if(a)for(let[E,v]of Object.entries(o.data.variables))a.style.setProperty(E,v)}break;case"inject-font-import":if(o.data?.fontUrl){let a=document.getElementById(re);a||(a=document.createElement("style"),a.id=re,document.head.appendChild(a)),a.textContent=`@import url('${o.data.fontUrl}');`}break;case"toggle-inline-edit-mode":o.data&&r.handleToggleMessage(o.data);break;case"freeze-vh-units":t.freezeVhUnits(typeof o.referenceVhBase=="number"?o.referenceVhBase:void 0);break;case"measure-page-height":t.measurePageHeight(s.origin&&s.origin!=="null"?s.origin:"*",typeof o.settleMs=="number"?o.settleMs:void 0);break;case"toggle-canvas-wheel-zoom-bridge":e.enable();break;default:break}},U=()=>{if(p){let s=H(p);u.forEach((o,a)=>{a<s.length&&b(o,s[a])})}d.length>0&&c.forEach((s,o)=>{o<d.length&&b(s,d[o])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((s,o)=>{let a=s,E=`visual-id-${a.dataset.filename}-${a.dataset.linenumber}-${o}`;a.dataset.visualSelectorId=E});let Ge=new MutationObserver(s=>{s.some(a=>{let E=y=>{if(y.nodeType===Node.ELEMENT_NODE){let A=y;if(A.dataset&&A.dataset.visualSelectorId)return!0;for(let R=0;R<A.children.length;R++)if(E(A.children[R]))return!0}return!1};return a.type==="attributes"&&(a.attributeName==="style"||a.attributeName==="class"||a.attributeName==="width"||a.attributeName==="height")&&E(a.target)})&&setTimeout(U,X)});window.addEventListener("message",Ke),window.addEventListener("scroll",de,!0),document.addEventListener("scroll",de,!0),window.addEventListener("resize",U),window.addEventListener("scroll",U),Ge.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{At as setupVisualEditAgent};
|
|
16
16
|
//# sourceMappingURL=index.mjs.map
|