@vcp-dev/site-edit-engine 0.11.4 → 0.11.6

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 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
+ "use strict";var k=require("@babel/generator"),ee=require("@babel/parser"),L=require("@babel/traverse"),r=require("@babel/types"),U=require("node:fs"),d=require("node:path"),te=typeof k=="function"?k:k.default,F=typeof L=="function"?L:L.default,Z={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},ne=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var re="suppressHydrationWarning",ie=new Set(["SiteEditBootstrap"]),se="data-vcp-ui-component",J="components/ui";function oe(e,t){this.cacheable?.();let n=this.async();try{if(!ce(this.resourcePath)){n(null,e,t);return}let i=this.getOptions?.()??{},s=H({source:e,file:this.resourcePath,projectRoot:i.projectRoot,cmsPreviewModulePath:ae(i.projectRoot)});n(null,s.code,s.code===e?t:null)}catch(i){n(i)}}function ae(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let n of[d.dirname(t),d.resolve(d.dirname(t),"../dist")]){let i=d.join(n,"cms-preview-record.js");if(U.existsSync(i)&&U.existsSync(d.join(n,"cms-preview-probe.js")))return i}return}catch{return}}function ce(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function H(e){let t=Ee(e.file,e.projectRoot);if(!me(e.source)||X(t))return{code:e.source,elements:[]};let n=e.attributes??Z,i=ee.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),s=[],o=be(i,t);F(i,{JSXElement(l){let c=l.node.openingElement,E=c.name;if(!ve(E)||$(c,n.key))return;let b=Ce(l)??"default",w=we(l),S=ge(t,b,w),x=P(E)??"unknown",f=Se(E)?"jsx":"component-call";if(f==="component-call"&&!Pe(l.node.children)&&ie.has(x))return;let a=f==="component-call"&&he(x,o);Ie(c,n.key,S),a&&q(c,se),fe(l)&&q(c,re),s.push({key:S,tag:x,component_name:b,source_file:t,source_kind:f})}});let p=e.cmsPreviewModulePath?ue(i,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return s.length===0&&!p?{code:e.source,elements:s}:{code:te(i,{jsescOption:{minimal:!0}}).code,elements:s}}function W(e,t,n){if(!d.isAbsolute(e))return e;let i=d.isAbsolute(t)?t:d.resolve(n||process.cwd(),t),s=d.relative(d.dirname(i),e).split(d.sep).join("/");return s.startsWith(".")?s:`./${s}`}function ue(e,t,n,i,s){let o;if(F(e,{Program(a){o=a,a.stop()}}),!o)return!1;let p=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),l=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),c=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),E=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),b=!1,w=!1,S=!1,x=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(n)||e.program.body.some(a=>r.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));F(e,{CallExpression(a){let u=a.node;if(r.isMemberExpression(u.callee)&&!u.callee.computed&&r.isIdentifier(u.callee.property,{name:"map"})&&u.arguments.length===1&&r.isIdentifier(u.arguments[0])){let I=D(a,u.arguments[0].name),C=de(u.callee.object),B=C&&z(a,C);if(I&&B?.operation==="list"&&B.slug===I.slug){let R=a.scope.generateUidIdentifier("vcpCmsRecord");u.arguments[0]=r.arrowFunctionExpression([R],r.callExpression(p,[r.callExpression(r.cloneNode(u.arguments[0]),[r.cloneNode(R)]),r.cloneNode(R),r.stringLiteral(I.slug),r.stringLiteral("list")])),b=!0,a.skip()}return}if(!r.isIdentifier(u.callee)||u.arguments.length!==1)return;let m=D(a,u.callee.name),y=r.isIdentifier(u.arguments[0]),v=y?u.arguments[0].name:N(u.arguments[0],["data"]),h=v&&z(a,v);if(!m||h?.operation!=="detail"||(y?h.slug!==m.slug:h.slug!==void 0))return;let M=r.cloneNode(u,!0),A=r.cloneNode(u.arguments[0],!0);a.replaceWith(r.callExpression(p,[M,A,r.stringLiteral(m.slug),r.stringLiteral("detail")])),b=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=r.callExpression(l,[a.node.argument]),w=!0},JSXElement:{exit(a){if(!x)return;let u=a.node.openingElement;if(!$(u,Z.key))return;let m=le(a);if(!m)return;let y=u.attributes.findIndex(C=>r.isJSXAttribute(C)&&r.isJSXIdentifier(C.name,{name:"key"})),v=y<0?null:u.attributes.splice(y,1)[0],h=[r.identifier(m.base),r.stringLiteral(m.field)];m.index&&h.push(r.cloneNode(m.index,!0));let M=[...v?[v]:[],r.jsxAttribute(r.jsxIdentifier("candidate"),r.jsxExpressionContainer(r.callExpression(c,h)))],A=r.jsxIdentifier(E.name),I=r.jsxElement(r.jsxOpeningElement(r.cloneNode(A),M,!1),r.jsxClosingElement(r.cloneNode(A)),[a.node]);a.replaceWith(I),S=!0,a.skip()}}});let f=[];return b&&f.push(r.importSpecifier(p,r.identifier("attachCmsPreviewRecord"))),w&&f.push(r.importSpecifier(l,r.identifier("stripCmsPreviewMetadata"))),S&&f.push(r.importSpecifier(c,r.identifier("readCmsPreviewCandidate"))),f.length&&e.program.body.unshift(r.importDeclaration(f,r.stringLiteral(W(t,i,s)))),S&&e.program.body.unshift(r.importDeclaration([r.importSpecifier(E,r.identifier("CmsPreviewProbe"))],r.stringLiteral(W(d.join(d.dirname(t),"cms-preview-probe.js"),i,s)))),f.length>0||S}function le(e){let t=e.node,n=t.openingElement.name,i=P(n);if(!i)return null;let s=t.openingElement.attributes.find(c=>r.isJSXAttribute(c)&&r.isJSXIdentifier(c.name,{name:"src"})),o=t.openingElement.attributes.find(c=>r.isJSXAttribute(c)&&r.isJSXIdentifier(c.name,{name:"dangerouslySetInnerHTML"})),p=i==="img"||/^[A-Z]/.test(i)&&s,l=p?r.isJSXAttribute(s)&&r.isJSXExpressionContainer(s.value)&&r.isExpression(s.value.expression)?[s.value.expression]:[]:r.isJSXAttribute(o)&&r.isJSXExpressionContainer(o.value)&&r.isExpression(o.value.expression)?[o.value.expression]:t.children.flatMap(c=>r.isJSXExpressionContainer(c)&&r.isExpression(c.expression)?[c.expression]:[]);return l.length!==1?null:p&&r.isIdentifier(l[0])&&e.scope.hasBinding(l[0].name)?{base:l[0].name,field:"url"}:pe(l[0],e)}function pe(e,t){let n=e,i=[];for(;r.isMemberExpression(n)||r.isOptionalMemberExpression(n);){if(!n.computed&&r.isIdentifier(n.property))i.unshift({property:n.property.name});else if(n.computed&&r.isNumericLiteral(n.property)&&Number.isSafeInteger(n.property.value)&&n.property.value>=0)i.unshift({index:n.property});else if(n.computed&&r.isIdentifier(n.property)&&t.scope.hasBinding(n.property.name))i.unshift({index:n.property});else return null;n=n.object}if(!r.isIdentifier(n)||!t.scope.hasBinding(n.name)||(i[0]?.property==="fields"&&i.shift(),!i[0]?.property||i.slice(2).some(o=>o.index)))return null;let s=i[1];return{base:n.name,field:i[0].property,...s?.index?{index:s.index}:{}}}function D(e,t){let n=e.scope.getBinding(t);if(!n?.constant||!n.path.isImportSpecifier())return null;let i=n.path.node;if(!r.isIdentifier(i.imported)||!/^to[A-Za-z0-9_$]+View$/.test(i.imported.name))return null;let s=n.path.parentPath.node.source.value,o=typeof s=="string"&&s.match(/^@\/lib\/cms\/generated\/([a-z0-9][a-z0-9-]*)$/);return o?{slug:o[1]}:null}function N(e,t){let n=e;for(let i of[...t].reverse()){if(!r.isMemberExpression(n)||n.computed||!r.isIdentifier(n.property,{name:i}))return null;n=n.object}return r.isIdentifier(n)?n.name:null}function de(e){if(r.isConditionalExpression(e)){let t=N(e.consequent,["data","items"]);return!t||!r.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!r.isBinaryExpression(e.test,{operator:"==="})||N(e.test.left,["kind"])!==t||!r.isStringLiteral(e.test.right,{value:"ok"})?null:t}return N(e,["data","items"])}function z(e,t){let n=e.scope.getBinding(t);if(!n?.constant||!n.path.isVariableDeclarator())return null;let i=n.path.node.init,s=r.isAwaitExpression(i)?i.argument:null;if(!r.isCallExpression(s)||!r.isMemberExpression(s.callee)||s.callee.computed||!r.isIdentifier(s.callee.property)||!r.isMemberExpression(s.callee.object)||s.callee.object.computed||!r.isIdentifier(s.callee.object.property,{name:"collections"})||!r.isIdentifier(s.callee.object.object))return null;let o=e.scope.getBinding(s.callee.object.object.name);return!o?.constant||!o.path.isImportSpecifier()||!r.isIdentifier(o.path.node.imported,{name:"cms"})||o.path.parentPath.node.source.value!=="@/lib/cms"?null:s.callee.property.name==="listStrict"&&r.isStringLiteral(s.arguments[0])?{operation:"list",slug:s.arguments[0].value}:s.callee.property.name==="getByUrlStrict"?{operation:"detail"}:s.callee.property.name==="get"&&r.isStringLiteral(s.arguments[0])?{operation:"detail",slug:s.arguments[0].value}:null}function fe(e){return!e.findParent(t=>t.isJSXElement())}function me(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 ge(e,t,n){return`${e}::${t}::${n}`}function Ee(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),i=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(i&&n.startsWith(`${i}/`))return n.slice(i.length+1);for(let[o,p]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let l=n.indexOf(o);if(l>=0)return n.slice(l+p)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function Se(e){return r.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function P(e){return r.isJSXIdentifier(e)?e.name:r.isJSXMemberExpression(e)?G(e):null}function be(e,t){let n=new Set;for(let i of e.program.body)if(!(!r.isImportDeclaration(i)||!xe(i.source.value,t)))for(let s of i.specifiers)n.add(s.local.name);return n}function he(e,t){let n=e.split(".")[0]??e;return t.has(n)}function X(e){if(!e)return!1;let t=O(e);return t===J||t.startsWith(`${J}/`)||t.includes(`/${J}/`)||t.endsWith(`/${J}`)}function xe(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?X(e.slice(2)):e.startsWith("./")||e.startsWith("../")?X(O(`${ye(t)}/${e}`)):X(e):!1}function O(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),i=[];for(let s of n.split("/"))if(!(!s||s===".")){if(s===".."){i.pop();continue}i.push(s)}return i.join("/")}function ye(e){let t=O(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function ve(e){let t=P(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ne.has(t)}function $(e,t){return e.attributes.some(n=>r.isJSXAttribute(n)&&r.isJSXIdentifier(n.name,{name:t}))}function Ie(e,t,n){Q(e,r.jsxAttribute(r.jsxIdentifier(t),r.stringLiteral(n)))}function q(e,t){$(e,t)||Q(e,r.jsxAttribute(r.jsxIdentifier(t),null))}function Q(e,t){let n=e.attributes.findIndex(i=>r.isJSXSpreadAttribute(i));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function G(e){return`${r.isJSXIdentifier(e.object)?e.object.name:G(e.object)}.${e.property.name}`}function Ce(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&r.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 Pe(e){return e.some(t=>r.isJSXElement(t)||r.isJSXFragment(t))}var K=new WeakMap,j=new WeakMap,_=new WeakMap;function we(e){let t=K.get(e.node);if(t!==void 0)return t;let n=[],i=e;for(;i;){if(i.isJSXElement()){let o=Ae(i);o&&n.unshift(o)}i=i.parentPath}let s=n.join("/");return K.set(e.node,s),s}function Ae(e){let t=P(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${V(e,t)}`:`${t}#${V(e,t)}`}function V(e,t){let n=Y(e)??e.getFunctionParent();if(!n)return 0;let i=_.get(n.node)?.get(t)?.get(e.node);if(i!==void 0)return i;let s=_.get(n.node);s||(s=new Map,_.set(n.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let p=0,l=n.isJSXElement()||n.isJSXFragment()?T(n):Je(n);for(let c of l)if(P(c.node.openingElement.name)===t){if(o.set(c.node,p),c.node===e.node)return p;p+=1}return o.get(e.node)??0}function Je(e){let t=j.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(i){i.getFunctionParent()?.node===e.node&&!Y(i)&&n.push(i)}}),j.set(e.node,n),n}function Y(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 T(e){let t=j.get(e.node);if(t)return t;let n=[],i=e.get("children");for(let s of i)if(!Array.isArray(s)){if(s.isJSXElement()){n.push(s);continue}if(s.isJSXFragment()){n.push(...T(s));continue}s.isJSXExpressionContainer()&&n.push(...g(s.get("expression")))}return j.set(e.node,n),n}function g(e){return e.isJSXElement()?[e]:e.isJSXFragment()?T(e):e.isParenthesizedExpression()?g(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?g(e.get("right")):e.isConditionalExpression()?[...g(e.get("consequent")),...g(e.get("alternate"))]:e.isCallExpression()&&Xe(e.node)?Ne(e.get("arguments")[0]):[]}function Ne(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return T(t);if(t.isParenthesizedExpression())return g(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let i of t.get("body")){if(i.isVariableDeclaration())for(let o of i.get("declarations")){let p=o.get("init");(p.isJSXElement()||p.isJSXFragment())&&n.push(...g(p))}if(!i.isReturnStatement())continue;let s=i.get("argument");return s.node&&n.push(...g(s)),n}return n}function Xe(e){return r.isMemberExpression(e.callee)&&r.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=oe;module.exports.instrumentSiteEditRuntimeAttributes=H;
@@ -1 +1 @@
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=_();
1
+ "use strict";var ne=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var te=ne((ke,B)=>{"use strict";var k=require("@babel/generator"),re=require("@babel/parser"),L=require("@babel/traverse"),r=require("@babel/types"),W=require("node:fs"),d=require("node:path"),ie=typeof k=="function"?k:k.default,F=typeof L=="function"?L:L.default,H={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},se=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),oe="suppressHydrationWarning",ae=new Set(["SiteEditBootstrap"]),ce="data-vcp-ui-component",J="components/ui";function ue(e,t){this.cacheable?.();let n=this.async();try{if(!pe(this.resourcePath)){n(null,e,t);return}let i=this.getOptions?.()??{},s=Q({source:e,file:this.resourcePath,projectRoot:i.projectRoot,cmsPreviewModulePath:le(i.projectRoot)});n(null,s.code,s.code===e?t:null)}catch(i){n(i)}}function le(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let n of[d.dirname(t),d.resolve(d.dirname(t),"../dist")]){let i=d.join(n,"cms-preview-record.js");if(W.existsSync(i)&&W.existsSync(d.join(n,"cms-preview-probe.js")))return i}return}catch{return}}function pe(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function Q(e){let t=he(e.file,e.projectRoot);if(!Se(e.source)||X(t))return{code:e.source,elements:[]};let n=e.attributes??H,i=re.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),s=[],o=ye(i,t);F(i,{JSXElement(l){let c=l.node.openingElement,E=c.name;if(!Pe(E)||$(c,n.key))return;let b=Ae(l)??"default",w=Ne(l),S=be(t,b,w),x=P(E)??"unknown",f=xe(E)?"jsx":"component-call";if(f==="component-call"&&!Je(l.node.children)&&ae.has(x))return;let a=f==="component-call"&&ve(x,o);we(c,n.key,S),a&&K(c,ce),Ee(l)&&K(c,oe),s.push({key:S,tag:x,component_name:b,source_file:t,source_kind:f})}});let p=e.cmsPreviewModulePath?de(i,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return s.length===0&&!p?{code:e.source,elements:s}:{code:ie(i,{jsescOption:{minimal:!0}}).code,elements:s}}function D(e,t,n){if(!d.isAbsolute(e))return e;let i=d.isAbsolute(t)?t:d.resolve(n||process.cwd(),t),s=d.relative(d.dirname(i),e).split(d.sep).join("/");return s.startsWith(".")?s:`./${s}`}function de(e,t,n,i,s){let o;if(F(e,{Program(a){o=a,a.stop()}}),!o)return!1;let p=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),l=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),c=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),E=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),b=!1,w=!1,S=!1,x=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(n)||e.program.body.some(a=>r.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));F(e,{CallExpression(a){let u=a.node;if(r.isMemberExpression(u.callee)&&!u.callee.computed&&r.isIdentifier(u.callee.property,{name:"map"})&&u.arguments.length===1&&r.isIdentifier(u.arguments[0])){let I=q(a,u.arguments[0].name),C=ge(u.callee.object),U=C&&z(a,C);if(I&&U?.operation==="list"&&U.slug===I.slug){let R=a.scope.generateUidIdentifier("vcpCmsRecord");u.arguments[0]=r.arrowFunctionExpression([R],r.callExpression(p,[r.callExpression(r.cloneNode(u.arguments[0]),[r.cloneNode(R)]),r.cloneNode(R),r.stringLiteral(I.slug),r.stringLiteral("list")])),b=!0,a.skip()}return}if(!r.isIdentifier(u.callee)||u.arguments.length!==1)return;let m=q(a,u.callee.name),y=r.isIdentifier(u.arguments[0]),v=y?u.arguments[0].name:N(u.arguments[0],["data"]),h=v&&z(a,v);if(!m||h?.operation!=="detail"||(y?h.slug!==m.slug:h.slug!==void 0))return;let M=r.cloneNode(u,!0),A=r.cloneNode(u.arguments[0],!0);a.replaceWith(r.callExpression(p,[M,A,r.stringLiteral(m.slug),r.stringLiteral("detail")])),b=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=r.callExpression(l,[a.node.argument]),w=!0},JSXElement:{exit(a){if(!x)return;let u=a.node.openingElement;if(!$(u,H.key))return;let m=fe(a);if(!m)return;let y=u.attributes.findIndex(C=>r.isJSXAttribute(C)&&r.isJSXIdentifier(C.name,{name:"key"})),v=y<0?null:u.attributes.splice(y,1)[0],h=[r.identifier(m.base),r.stringLiteral(m.field)];m.index&&h.push(r.cloneNode(m.index,!0));let M=[...v?[v]:[],r.jsxAttribute(r.jsxIdentifier("candidate"),r.jsxExpressionContainer(r.callExpression(c,h)))],A=r.jsxIdentifier(E.name),I=r.jsxElement(r.jsxOpeningElement(r.cloneNode(A),M,!1),r.jsxClosingElement(r.cloneNode(A)),[a.node]);a.replaceWith(I),S=!0,a.skip()}}});let f=[];return b&&f.push(r.importSpecifier(p,r.identifier("attachCmsPreviewRecord"))),w&&f.push(r.importSpecifier(l,r.identifier("stripCmsPreviewMetadata"))),S&&f.push(r.importSpecifier(c,r.identifier("readCmsPreviewCandidate"))),f.length&&e.program.body.unshift(r.importDeclaration(f,r.stringLiteral(D(t,i,s)))),S&&e.program.body.unshift(r.importDeclaration([r.importSpecifier(E,r.identifier("CmsPreviewProbe"))],r.stringLiteral(D(d.join(d.dirname(t),"cms-preview-probe.js"),i,s)))),f.length>0||S}function fe(e){let t=e.node,n=t.openingElement.name,i=P(n);if(!i)return null;let s=t.openingElement.attributes.find(c=>r.isJSXAttribute(c)&&r.isJSXIdentifier(c.name,{name:"src"})),o=t.openingElement.attributes.find(c=>r.isJSXAttribute(c)&&r.isJSXIdentifier(c.name,{name:"dangerouslySetInnerHTML"})),p=i==="img"||/^[A-Z]/.test(i)&&s,l=p?r.isJSXAttribute(s)&&r.isJSXExpressionContainer(s.value)&&r.isExpression(s.value.expression)?[s.value.expression]:[]:r.isJSXAttribute(o)&&r.isJSXExpressionContainer(o.value)&&r.isExpression(o.value.expression)?[o.value.expression]:t.children.flatMap(c=>r.isJSXExpressionContainer(c)&&r.isExpression(c.expression)?[c.expression]:[]);return l.length!==1?null:p&&r.isIdentifier(l[0])&&e.scope.hasBinding(l[0].name)?{base:l[0].name,field:"url"}:me(l[0],e)}function me(e,t){let n=e,i=[];for(;r.isMemberExpression(n)||r.isOptionalMemberExpression(n);){if(!n.computed&&r.isIdentifier(n.property))i.unshift({property:n.property.name});else if(n.computed&&r.isNumericLiteral(n.property)&&Number.isSafeInteger(n.property.value)&&n.property.value>=0)i.unshift({index:n.property});else if(n.computed&&r.isIdentifier(n.property)&&t.scope.hasBinding(n.property.name))i.unshift({index:n.property});else return null;n=n.object}if(!r.isIdentifier(n)||!t.scope.hasBinding(n.name)||(i[0]?.property==="fields"&&i.shift(),!i[0]?.property||i.slice(2).some(o=>o.index)))return null;let s=i[1];return{base:n.name,field:i[0].property,...s?.index?{index:s.index}:{}}}function q(e,t){let n=e.scope.getBinding(t);if(!n?.constant||!n.path.isImportSpecifier())return null;let i=n.path.node;if(!r.isIdentifier(i.imported)||!/^to[A-Za-z0-9_$]+View$/.test(i.imported.name))return null;let s=n.path.parentPath.node.source.value,o=typeof s=="string"&&s.match(/^@\/lib\/cms\/generated\/([a-z0-9][a-z0-9-]*)$/);return o?{slug:o[1]}:null}function N(e,t){let n=e;for(let i of[...t].reverse()){if(!r.isMemberExpression(n)||n.computed||!r.isIdentifier(n.property,{name:i}))return null;n=n.object}return r.isIdentifier(n)?n.name:null}function ge(e){if(r.isConditionalExpression(e)){let t=N(e.consequent,["data","items"]);return!t||!r.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!r.isBinaryExpression(e.test,{operator:"==="})||N(e.test.left,["kind"])!==t||!r.isStringLiteral(e.test.right,{value:"ok"})?null:t}return N(e,["data","items"])}function z(e,t){let n=e.scope.getBinding(t);if(!n?.constant||!n.path.isVariableDeclarator())return null;let i=n.path.node.init,s=r.isAwaitExpression(i)?i.argument:null;if(!r.isCallExpression(s)||!r.isMemberExpression(s.callee)||s.callee.computed||!r.isIdentifier(s.callee.property)||!r.isMemberExpression(s.callee.object)||s.callee.object.computed||!r.isIdentifier(s.callee.object.property,{name:"collections"})||!r.isIdentifier(s.callee.object.object))return null;let o=e.scope.getBinding(s.callee.object.object.name);return!o?.constant||!o.path.isImportSpecifier()||!r.isIdentifier(o.path.node.imported,{name:"cms"})||o.path.parentPath.node.source.value!=="@/lib/cms"?null:s.callee.property.name==="listStrict"&&r.isStringLiteral(s.arguments[0])?{operation:"list",slug:s.arguments[0].value}:s.callee.property.name==="getByUrlStrict"?{operation:"detail"}:s.callee.property.name==="get"&&r.isStringLiteral(s.arguments[0])?{operation:"detail",slug:s.arguments[0].value}:null}function Ee(e){return!e.findParent(t=>t.isJSXElement())}function Se(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 be(e,t,n){return`${e}::${t}::${n}`}function he(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),i=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(i&&n.startsWith(`${i}/`))return n.slice(i.length+1);for(let[o,p]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let l=n.indexOf(o);if(l>=0)return n.slice(l+p)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function xe(e){return r.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function P(e){return r.isJSXIdentifier(e)?e.name:r.isJSXMemberExpression(e)?Y(e):null}function ye(e,t){let n=new Set;for(let i of e.program.body)if(!(!r.isImportDeclaration(i)||!Ie(i.source.value,t)))for(let s of i.specifiers)n.add(s.local.name);return n}function ve(e,t){let n=e.split(".")[0]??e;return t.has(n)}function X(e){if(!e)return!1;let t=O(e);return t===J||t.startsWith(`${J}/`)||t.includes(`/${J}/`)||t.endsWith(`/${J}`)}function Ie(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?X(e.slice(2)):e.startsWith("./")||e.startsWith("../")?X(O(`${Ce(t)}/${e}`)):X(e):!1}function O(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),i=[];for(let s of n.split("/"))if(!(!s||s===".")){if(s===".."){i.pop();continue}i.push(s)}return i.join("/")}function Ce(e){let t=O(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function Pe(e){let t=P(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!se.has(t)}function $(e,t){return e.attributes.some(n=>r.isJSXAttribute(n)&&r.isJSXIdentifier(n.name,{name:t}))}function we(e,t,n){G(e,r.jsxAttribute(r.jsxIdentifier(t),r.stringLiteral(n)))}function K(e,t){$(e,t)||G(e,r.jsxAttribute(r.jsxIdentifier(t),null))}function G(e,t){let n=e.attributes.findIndex(i=>r.isJSXSpreadAttribute(i));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function Y(e){return`${r.isJSXIdentifier(e.object)?e.object.name:Y(e.object)}.${e.property.name}`}function Ae(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&r.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 Je(e){return e.some(t=>r.isJSXElement(t)||r.isJSXFragment(t))}var V=new WeakMap,j=new WeakMap,_=new WeakMap;function Ne(e){let t=V.get(e.node);if(t!==void 0)return t;let n=[],i=e;for(;i;){if(i.isJSXElement()){let o=Xe(i);o&&n.unshift(o)}i=i.parentPath}let s=n.join("/");return V.set(e.node,s),s}function Xe(e){let t=P(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${Z(e,t)}`:`${t}#${Z(e,t)}`}function Z(e,t){let n=ee(e)??e.getFunctionParent();if(!n)return 0;let i=_.get(n.node)?.get(t)?.get(e.node);if(i!==void 0)return i;let s=_.get(n.node);s||(s=new Map,_.set(n.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let p=0,l=n.isJSXElement()||n.isJSXFragment()?T(n):je(n);for(let c of l)if(P(c.node.openingElement.name)===t){if(o.set(c.node,p),c.node===e.node)return p;p+=1}return o.get(e.node)??0}function je(e){let t=j.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(i){i.getFunctionParent()?.node===e.node&&!ee(i)&&n.push(i)}}),j.set(e.node,n),n}function ee(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 T(e){let t=j.get(e.node);if(t)return t;let n=[],i=e.get("children");for(let s of i)if(!Array.isArray(s)){if(s.isJSXElement()){n.push(s);continue}if(s.isJSXFragment()){n.push(...T(s));continue}s.isJSXExpressionContainer()&&n.push(...g(s.get("expression")))}return j.set(e.node,n),n}function g(e){return e.isJSXElement()?[e]:e.isJSXFragment()?T(e):e.isParenthesizedExpression()?g(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?g(e.get("right")):e.isConditionalExpression()?[...g(e.get("consequent")),...g(e.get("alternate"))]:e.isCallExpression()&&Me(e.node)?Te(e.get("arguments")[0]):[]}function Te(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return T(t);if(t.isParenthesizedExpression())return g(t.get("expression"));if(!t.isBlockStatement())return[];let n=[];for(let i of t.get("body")){if(i.isVariableDeclaration())for(let o of i.get("declarations")){let p=o.get("init");(p.isJSXElement()||p.isJSXFragment())&&n.push(...g(p))}if(!i.isReturnStatement())continue;let s=i.get("argument");return s.node&&n.push(...g(s)),n}return n}function Me(e){return r.isMemberExpression(e.callee)&&r.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}B.exports=ue;B.exports.instrumentSiteEditRuntimeAttributes=Q});module.exports=te();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcp-dev/site-edit-engine",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
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.11.4",
63
+ "@vcp-dev/contracts": "0.11.6",
64
64
  "yaml": "^2.9.0"
65
65
  },
66
66
  "devDependencies": {