@vcp-dev/site-edit-engine 0.10.19 → 0.10.20

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.
@@ -1 +1 @@
1
- "use strict";var S=require("@babel/generator"),v=require("@babel/parser"),h=require("@babel/traverse"),s=require("@babel/types"),j=typeof S=="function"?S:S.default,k=typeof h=="function"?h:h.default,O={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},F=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var M="suppressHydrationWarning",$=new Set(["SiteEditBootstrap"]),L="data-vcp-ui-component",f="components/ui";function W(e,t){this.cacheable?.();let n=this.async();try{if(!U(this.resourcePath)){n(null,e,t);return}let r=this.getOptions?.()??{},i=J({source:e,file:this.resourcePath,projectRoot:r.projectRoot});n(null,i.code,i.code===e?t:null)}catch(r){n(r)}}function U(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function J(e){let t=q(e.file,e.projectRoot);if(!z(e.source)||d(t))return{code:e.source,elements:[]};let n=e.attributes??O,r=v.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),i=[],u=V(r,t);return k(r,{JSXElement(o){let c=o.node.openingElement,l=c.name;if(!G(l)||A(c,n.key))return;let y=ee(o)??"default",R=ne(o),P=B(t,y,R),g=m(l)??"unknown",E=K(l)?"jsx":"component-call";if(E==="component-call"&&!te(o.node.children)&&$.has(g))return;let _=E==="component-call"&&H(g,u);Y(c,n.key,P),_&&C(c,L),D(o)&&C(c,M),i.push({key:P,tag:g,component_name:y,source_file:t,source_kind:E})}}),i.length===0?{code:e.source,elements:i}:{code:j(r,{jsescOption:{minimal:!0}}).code,elements:i}}function D(e){return!e.findParent(t=>t.isJSXElement())}function z(e){if(typeof e!="string")throw new TypeError("site edit instrumentation source must be a string");return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function B(e,t,n){return`${e}::${t}::${n}`}function q(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[u,o]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=n.indexOf(u);if(c>=0)return n.slice(c+o)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function K(e){return s.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function m(e){return s.isJSXIdentifier(e)?e.name:s.isJSXMemberExpression(e)?w(e):null}function V(e,t){let n=new Set;for(let r of e.program.body)if(!(!s.isImportDeclaration(r)||!Q(r.source.value,t)))for(let i of r.specifiers)n.add(i.local.name);return n}function H(e,t){let n=e.split(".")[0]??e;return t.has(n)}function d(e){if(!e)return!1;let t=x(e);return t===f||t.startsWith(`${f}/`)||t.includes(`/${f}/`)||t.endsWith(`/${f}`)}function Q(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?d(e.slice(2)):e.startsWith("./")||e.startsWith("../")?d(x(`${Z(t)}/${e}`)):d(e):!1}function x(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i===".."){r.pop();continue}r.push(i)}return r.join("/")}function Z(e){let t=x(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function G(e){let t=m(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!F.has(t)}function A(e,t){return e.attributes.some(n=>s.isJSXAttribute(n)&&s.isJSXIdentifier(n.name,{name:t}))}function Y(e,t,n){X(e,s.jsxAttribute(s.jsxIdentifier(t),s.stringLiteral(n)))}function C(e,t){A(e,t)||X(e,s.jsxAttribute(s.jsxIdentifier(t),null))}function X(e,t){let n=e.attributes.findIndex(r=>s.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function w(e){return`${s.isJSXIdentifier(e.object)?e.object.name:w(e.object)}.${e.property.name}`}function ee(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&s.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function te(e){return e.some(t=>s.isJSXElement(t)||s.isJSXFragment(t))}var I=new WeakMap,T=new WeakMap,b=new WeakMap;function ne(e){let t=I.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let u=re(r);u&&n.unshift(u)}r=r.parentPath}let i=n.join("/");return I.set(e.node,i),i}function re(e){let t=m(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${N(e,t)}`:`${t}#${N(e,t)}`}function N(e,t){let n=ie(e);if(!n)return 0;let r=b.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let i=b.get(n.node);i||(i=new Map,b.set(n.node,i));let u=i.get(t);u||(u=new WeakMap,i.set(t,u));let o=0;for(let c of p(n))if(m(c.node.openingElement.name)===t){if(u.set(c.node,o),c.node===e.node)return o;o+=1}return u.get(e.node)??0}function ie(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function p(e){let t=T.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let i of r)if(!Array.isArray(i)){if(i.isJSXElement()){n.push(i);continue}if(i.isJSXFragment()){n.push(...p(i));continue}i.isJSXExpressionContainer()&&n.push(...a(i.get("expression")))}return T.set(e.node,n),n}function a(e){return e.isJSXElement()?[e]:e.isJSXFragment()?p(e):e.isParenthesizedExpression()?a(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?a(e.get("right")):e.isConditionalExpression()?[...a(e.get("consequent")),...a(e.get("alternate"))]:e.isCallExpression()&&oe(e.node)?se(e.get("arguments")[0]):[]}function se(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return p(t);if(t.isParenthesizedExpression())return a(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let u of r.get("declarations")){let o=u.get("init");(o.isJSXElement()||o.isJSXFragment())&&n.push(...a(o))}if(!r.isReturnStatement())continue;let i=r.get("argument");return i.node&&n.push(...a(i)),n}return n}function oe(e){return s.isMemberExpression(e.callee)&&s.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=W;module.exports.instrumentSiteEditRuntimeAttributes=J;
1
+ "use strict";var b=require("@babel/generator"),F=require("@babel/parser"),x=require("@babel/traverse"),s=require("@babel/types"),j=typeof b=="function"?b:b.default,k=typeof x=="function"?x:x.default,O={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},M=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var $="suppressHydrationWarning",L=new Set(["SiteEditBootstrap"]),W="data-vcp-ui-component",f="components/ui";function U(e,t){this.cacheable?.();let n=this.async();try{if(!D(this.resourcePath)){n(null,e,t);return}let r=this.getOptions?.()??{},i=N({source:e,file:this.resourcePath,projectRoot:r.projectRoot});n(null,i.code,i.code===e?t:null)}catch(r){n(r)}}function D(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function N(e){let t=K(e.file,e.projectRoot);if(!B(e.source)||d(t))return{code:e.source,elements:[]};let n=e.attributes??O,r=F.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),i=[],u=H(r,t);return k(r,{JSXElement(o){let c=o.node.openingElement,l=c.name;if(!Y(l)||A(c,n.key))return;let E=te(o)??"default",w=re(o),C=q(t,E,w),S=p(l)??"unknown",h=V(l)?"jsx":"component-call";if(h==="component-call"&&!ne(o.node.children)&&L.has(S))return;let _=h==="component-call"&&Q(S,u);ee(c,n.key,C),_&&I(c,W),z(o)&&I(c,$),i.push({key:C,tag:S,component_name:E,source_file:t,source_kind:h})}}),i.length===0?{code:e.source,elements:i}:{code:j(r,{jsescOption:{minimal:!0}}).code,elements:i}}function z(e){return!e.findParent(t=>t.isJSXElement())}function B(e){if(typeof e!="string")throw new TypeError("site edit instrumentation source must be a string");return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function q(e,t,n){return`${e}::${t}::${n}`}function K(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[u,o]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=n.indexOf(u);if(c>=0)return n.slice(c+o)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function V(e){return s.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function p(e){return s.isJSXIdentifier(e)?e.name:s.isJSXMemberExpression(e)?R(e):null}function H(e,t){let n=new Set;for(let r of e.program.body)if(!(!s.isImportDeclaration(r)||!Z(r.source.value,t)))for(let i of r.specifiers)n.add(i.local.name);return n}function Q(e,t){let n=e.split(".")[0]??e;return t.has(n)}function d(e){if(!e)return!1;let t=y(e);return t===f||t.startsWith(`${f}/`)||t.includes(`/${f}/`)||t.endsWith(`/${f}`)}function Z(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?d(e.slice(2)):e.startsWith("./")||e.startsWith("../")?d(y(`${G(t)}/${e}`)):d(e):!1}function y(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i===".."){r.pop();continue}r.push(i)}return r.join("/")}function G(e){let t=y(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function Y(e){let t=p(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!M.has(t)}function A(e,t){return e.attributes.some(n=>s.isJSXAttribute(n)&&s.isJSXIdentifier(n.name,{name:t}))}function ee(e,t,n){X(e,s.jsxAttribute(s.jsxIdentifier(t),s.stringLiteral(n)))}function I(e,t){A(e,t)||X(e,s.jsxAttribute(s.jsxIdentifier(t),null))}function X(e,t){let n=e.attributes.findIndex(r=>s.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function R(e){return`${s.isJSXIdentifier(e.object)?e.object.name:R(e.object)}.${e.property.name}`}function te(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&s.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function ne(e){return e.some(t=>s.isJSXElement(t)||s.isJSXFragment(t))}var J=new WeakMap,m=new WeakMap,P=new WeakMap;function re(e){let t=J.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let u=ie(r);u&&n.unshift(u)}r=r.parentPath}let i=n.join("/");return J.set(e.node,i),i}function ie(e){let t=p(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${T(e,t)}`:`${t}#${T(e,t)}`}function T(e,t){let n=v(e)??e.getFunctionParent();if(!n)return 0;let r=P.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let i=P.get(n.node);i||(i=new Map,P.set(n.node,i));let u=i.get(t);u||(u=new WeakMap,i.set(t,u));let o=0,c=n.isJSXElement()||n.isJSXFragment()?g(n):se(n);for(let l of c)if(p(l.node.openingElement.name)===t){if(u.set(l.node,o),l.node===e.node)return o;o+=1}return u.get(e.node)??0}function se(e){let t=m.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!v(r)&&n.push(r)}}),m.set(e.node,n),n}function v(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function g(e){let t=m.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let i of r)if(!Array.isArray(i)){if(i.isJSXElement()){n.push(i);continue}if(i.isJSXFragment()){n.push(...g(i));continue}i.isJSXExpressionContainer()&&n.push(...a(i.get("expression")))}return m.set(e.node,n),n}function a(e){return e.isJSXElement()?[e]:e.isJSXFragment()?g(e):e.isParenthesizedExpression()?a(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?a(e.get("right")):e.isConditionalExpression()?[...a(e.get("consequent")),...a(e.get("alternate"))]:e.isCallExpression()&&ue(e.node)?oe(e.get("arguments")[0]):[]}function oe(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return g(t);if(t.isParenthesizedExpression())return a(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let u of r.get("declarations")){let o=u.get("init");(o.isJSXElement()||o.isJSXFragment())&&n.push(...a(o))}if(!r.isReturnStatement())continue;let i=r.get("argument");return i.node&&n.push(...a(i)),n}return n}function ue(e){return s.isMemberExpression(e.callee)&&s.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=U;module.exports.instrumentSiteEditRuntimeAttributes=N;
@@ -1 +1 @@
1
- "use strict";var k=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var _=k((fe,y)=>{"use strict";var S=require("@babel/generator"),O=require("@babel/parser"),h=require("@babel/traverse"),s=require("@babel/types"),F=typeof S=="function"?S:S.default,M=typeof h=="function"?h:h.default,$={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},L=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),W="suppressHydrationWarning",U=new Set(["SiteEditBootstrap"]),D="data-vcp-ui-component",f="components/ui";function z(e,t){this.cacheable?.();let n=this.async();try{if(!B(this.resourcePath)){n(null,e,t);return}let r=this.getOptions?.()??{},i=A({source:e,file:this.resourcePath,projectRoot:r.projectRoot});n(null,i.code,i.code===e?t:null)}catch(r){n(r)}}function B(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function A(e){let t=H(e.file,e.projectRoot);if(!K(e.source)||d(t))return{code:e.source,elements:[]};let n=e.attributes??$,r=O.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),i=[],u=Z(r,t);return M(r,{JSXElement(o){let c=o.node.openingElement,l=c.name;if(!te(l)||X(c,n.key))return;let P=re(o)??"default",v=se(o),C=V(t,P,v),g=m(l)??"unknown",E=Q(l)?"jsx":"component-call";if(E==="component-call"&&!ie(o.node.children)&&U.has(g))return;let j=E==="component-call"&&G(g,u);ne(c,n.key,C),j&&I(c,D),q(o)&&I(c,W),i.push({key:C,tag:g,component_name:P,source_file:t,source_kind:E})}}),i.length===0?{code:e.source,elements:i}:{code:F(r,{jsescOption:{minimal:!0}}).code,elements:i}}function q(e){return!e.findParent(t=>t.isJSXElement())}function K(e){if(typeof e!="string")throw new TypeError("site edit instrumentation source must be a string");return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function V(e,t,n){return`${e}::${t}::${n}`}function H(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[u,o]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=n.indexOf(u);if(c>=0)return n.slice(c+o)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function Q(e){return s.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function m(e){return s.isJSXIdentifier(e)?e.name:s.isJSXMemberExpression(e)?R(e):null}function Z(e,t){let n=new Set;for(let r of e.program.body)if(!(!s.isImportDeclaration(r)||!Y(r.source.value,t)))for(let i of r.specifiers)n.add(i.local.name);return n}function G(e,t){let n=e.split(".")[0]??e;return t.has(n)}function d(e){if(!e)return!1;let t=x(e);return t===f||t.startsWith(`${f}/`)||t.includes(`/${f}/`)||t.endsWith(`/${f}`)}function Y(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?d(e.slice(2)):e.startsWith("./")||e.startsWith("../")?d(x(`${ee(t)}/${e}`)):d(e):!1}function x(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i===".."){r.pop();continue}r.push(i)}return r.join("/")}function ee(e){let t=x(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function te(e){let t=m(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!L.has(t)}function X(e,t){return e.attributes.some(n=>s.isJSXAttribute(n)&&s.isJSXIdentifier(n.name,{name:t}))}function ne(e,t,n){w(e,s.jsxAttribute(s.jsxIdentifier(t),s.stringLiteral(n)))}function I(e,t){X(e,t)||w(e,s.jsxAttribute(s.jsxIdentifier(t),null))}function w(e,t){let n=e.attributes.findIndex(r=>s.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function R(e){return`${s.isJSXIdentifier(e.object)?e.object.name:R(e.object)}.${e.property.name}`}function re(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&s.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function ie(e){return e.some(t=>s.isJSXElement(t)||s.isJSXFragment(t))}var T=new WeakMap,N=new WeakMap,b=new WeakMap;function se(e){let t=T.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let u=oe(r);u&&n.unshift(u)}r=r.parentPath}let i=n.join("/");return T.set(e.node,i),i}function oe(e){let t=m(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${J(e,t)}`:`${t}#${J(e,t)}`}function J(e,t){let n=ue(e);if(!n)return 0;let r=b.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let i=b.get(n.node);i||(i=new Map,b.set(n.node,i));let u=i.get(t);u||(u=new WeakMap,i.set(t,u));let o=0;for(let c of p(n))if(m(c.node.openingElement.name)===t){if(u.set(c.node,o),c.node===e.node)return o;o+=1}return u.get(e.node)??0}function ue(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function p(e){let t=N.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let i of r)if(!Array.isArray(i)){if(i.isJSXElement()){n.push(i);continue}if(i.isJSXFragment()){n.push(...p(i));continue}i.isJSXExpressionContainer()&&n.push(...a(i.get("expression")))}return N.set(e.node,n),n}function a(e){return e.isJSXElement()?[e]:e.isJSXFragment()?p(e):e.isParenthesizedExpression()?a(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?a(e.get("right")):e.isConditionalExpression()?[...a(e.get("consequent")),...a(e.get("alternate"))]:e.isCallExpression()&&ae(e.node)?ce(e.get("arguments")[0]):[]}function ce(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return p(t);if(t.isParenthesizedExpression())return a(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let u of r.get("declarations")){let o=u.get("init");(o.isJSXElement()||o.isJSXFragment())&&n.push(...a(o))}if(!r.isReturnStatement())continue;let i=r.get("argument");return i.node&&n.push(...a(i)),n}return n}function ae(e){return s.isMemberExpression(e.callee)&&s.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}y.exports=z;y.exports.instrumentSiteEditRuntimeAttributes=A});module.exports=_();
1
+ "use strict";var k=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var _=k((de,C)=>{"use strict";var b=require("@babel/generator"),O=require("@babel/parser"),x=require("@babel/traverse"),s=require("@babel/types"),M=typeof b=="function"?b:b.default,$=typeof x=="function"?x:x.default,L={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},W=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),U="suppressHydrationWarning",D=new Set(["SiteEditBootstrap"]),z="data-vcp-ui-component",f="components/ui";function B(e,t){this.cacheable?.();let n=this.async();try{if(!q(this.resourcePath)){n(null,e,t);return}let r=this.getOptions?.()??{},i=A({source:e,file:this.resourcePath,projectRoot:r.projectRoot});n(null,i.code,i.code===e?t:null)}catch(r){n(r)}}function q(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function A(e){let t=Q(e.file,e.projectRoot);if(!V(e.source)||d(t))return{code:e.source,elements:[]};let n=e.attributes??L,r=O.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),i=[],u=G(r,t);return $(r,{JSXElement(o){let c=o.node.openingElement,l=c.name;if(!ne(l)||X(c,n.key))return;let E=ie(o)??"default",F=oe(o),I=H(t,E,F),S=p(l)??"unknown",h=Z(l)?"jsx":"component-call";if(h==="component-call"&&!se(o.node.children)&&D.has(S))return;let j=h==="component-call"&&Y(S,u);re(c,n.key,I),j&&J(c,z),K(o)&&J(c,U),i.push({key:I,tag:S,component_name:E,source_file:t,source_kind:h})}}),i.length===0?{code:e.source,elements:i}:{code:M(r,{jsescOption:{minimal:!0}}).code,elements:i}}function K(e){return!e.findParent(t=>t.isJSXElement())}function V(e){if(typeof e!="string")throw new TypeError("site edit instrumentation source must be a string");return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function H(e,t,n){return`${e}::${t}::${n}`}function Q(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[u,o]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=n.indexOf(u);if(c>=0)return n.slice(c+o)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function Z(e){return s.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function p(e){return s.isJSXIdentifier(e)?e.name:s.isJSXMemberExpression(e)?v(e):null}function G(e,t){let n=new Set;for(let r of e.program.body)if(!(!s.isImportDeclaration(r)||!ee(r.source.value,t)))for(let i of r.specifiers)n.add(i.local.name);return n}function Y(e,t){let n=e.split(".")[0]??e;return t.has(n)}function d(e){if(!e)return!1;let t=y(e);return t===f||t.startsWith(`${f}/`)||t.includes(`/${f}/`)||t.endsWith(`/${f}`)}function ee(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?d(e.slice(2)):e.startsWith("./")||e.startsWith("../")?d(y(`${te(t)}/${e}`)):d(e):!1}function y(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let i of n.split("/"))if(!(!i||i===".")){if(i===".."){r.pop();continue}r.push(i)}return r.join("/")}function te(e){let t=y(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function ne(e){let t=p(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!W.has(t)}function X(e,t){return e.attributes.some(n=>s.isJSXAttribute(n)&&s.isJSXIdentifier(n.name,{name:t}))}function re(e,t,n){R(e,s.jsxAttribute(s.jsxIdentifier(t),s.stringLiteral(n)))}function J(e,t){X(e,t)||R(e,s.jsxAttribute(s.jsxIdentifier(t),null))}function R(e,t){let n=e.attributes.findIndex(r=>s.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function v(e){return`${s.isJSXIdentifier(e.object)?e.object.name:v(e.object)}.${e.property.name}`}function ie(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&s.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function se(e){return e.some(t=>s.isJSXElement(t)||s.isJSXFragment(t))}var T=new WeakMap,m=new WeakMap,P=new WeakMap;function oe(e){let t=T.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let u=ue(r);u&&n.unshift(u)}r=r.parentPath}let i=n.join("/");return T.set(e.node,i),i}function ue(e){let t=p(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${N(e,t)}`:`${t}#${N(e,t)}`}function N(e,t){let n=w(e)??e.getFunctionParent();if(!n)return 0;let r=P.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let i=P.get(n.node);i||(i=new Map,P.set(n.node,i));let u=i.get(t);u||(u=new WeakMap,i.set(t,u));let o=0,c=n.isJSXElement()||n.isJSXFragment()?g(n):ce(n);for(let l of c)if(p(l.node.openingElement.name)===t){if(u.set(l.node,o),l.node===e.node)return o;o+=1}return u.get(e.node)??0}function ce(e){let t=m.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!w(r)&&n.push(r)}}),m.set(e.node,n),n}function w(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function g(e){let t=m.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let i of r)if(!Array.isArray(i)){if(i.isJSXElement()){n.push(i);continue}if(i.isJSXFragment()){n.push(...g(i));continue}i.isJSXExpressionContainer()&&n.push(...a(i.get("expression")))}return m.set(e.node,n),n}function a(e){return e.isJSXElement()?[e]:e.isJSXFragment()?g(e):e.isParenthesizedExpression()?a(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?a(e.get("right")):e.isConditionalExpression()?[...a(e.get("consequent")),...a(e.get("alternate"))]:e.isCallExpression()&&le(e.node)?ae(e.get("arguments")[0]):[]}function ae(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return g(t);if(t.isParenthesizedExpression())return a(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let u of r.get("declarations")){let o=u.get("init");(o.isJSXElement()||o.isJSXFragment())&&n.push(...a(o))}if(!r.isReturnStatement())continue;let i=r.get("argument");return i.node&&n.push(...a(i)),n}return n}function le(e){return s.isMemberExpression(e.callee)&&s.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}C.exports=B;C.exports.instrumentSiteEditRuntimeAttributes=A});module.exports=_();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcp-dev/site-edit-engine",
3
- "version": "0.10.19",
3
+ "version": "0.10.20",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -60,7 +60,7 @@
60
60
  "@babel/parser": "^7.29.3",
61
61
  "@babel/traverse": "^7.29.0",
62
62
  "@babel/types": "^7.29.0",
63
- "@vcp-dev/contracts": "0.10.19",
63
+ "@vcp-dev/contracts": "0.10.20",
64
64
  "yaml": "^2.9.0"
65
65
  },
66
66
  "devDependencies": {