@vcp-dev/site-edit-engine 0.11.50 → 0.11.51

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 $=require("@babel/generator"),pe=require("@babel/parser"),D=require("@babel/traverse"),n=require("@babel/types"),Q=require("node:fs"),E=require("node:path"),me=typeof $=="function"?$:$.default,q=typeof D=="function"?D:D.default,ie={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},ge=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var be="suppressHydrationWarning",Ee=new Set(["SiteEditBootstrap"]),H="data-vcp-source-location",Se="data-vcp-ui-component",M="components/ui";function he(e,t){this.cacheable?.();let i=this.async();try{if(!xe(this.resourcePath)){i(null,e,t);return}let r=this.getOptions?.()??{},s=re({source:e,file:this.resourcePath,projectRoot:r.projectRoot,sourceLocations:r.sourceLocations===!0,cmsPreviewModulePath:r.cmsPreviewModulePath??ye(r.projectRoot)});i(null,s.code,s.code===e?t:null)}catch(r){i(r)}}function ye(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let i of[E.dirname(t),E.resolve(E.dirname(t),"../dist")]){let r=E.join(i,"cms-preview-record.js");if(Q.existsSync(r)&&Q.existsSync(E.join(i,"cms-preview-probe.js")))return r}return}catch{return}}function xe(e){return typeof e=="string"&&/\.[jt]sx?$/.test(e)&&!e.replace(/\\/g,"/").includes("/node_modules/")&&!e.endsWith(".d.ts")}function re(e){let t=Ne(e.file,e.projectRoot),i=Ae(e.source)&&!/\.ts$/.test(t),r=e.cmsPreviewModulePath&&e.source.includes("@/lib/cms");if(!i&&!r||X(t))return{code:e.source,elements:[]};let s=e.attributes??ie,o=pe.parse(e.source,{sourceType:"module",plugins:["typescript",.../\.ts$/.test(t)?[]:["jsx"]]}),u=[],c=je(o,t);q(o,{JSXElement(b){let f=b.node.openingElement,d=f.name;if(!Re(d)||K(f,s.key)&&!e.sourceLocations)return;let y=Xe(b)??"default",A=Be(b),v=Le(t,y,A),P=j(d)??"unknown",x=ce(d)?"jsx":"component-call";if(x==="component-call"&&!ke(b.node.children)&&Ee.has(P))return;let _=x==="component-call"&&Te(P,c);if(e.sourceLocations&&(f.attributes=f.attributes.filter(p=>!(n.isJSXAttribute(p)&&n.isJSXIdentifier(p.name)&&(p.name.name===s.key||p.name.name===H))),f.loc)){let{start:p,end:a}=f.loc;Y(f,H,encodeURIComponent(JSON.stringify({key:v,sourceFile:t,componentName:y,structuralPath:A,openingElementRange:{startLine:p.line,startColumn:p.column,endLine:a.line,endColumn:a.column}})))}Y(f,s.key,v),_&&ee(f,Se),we(b)&&ee(f,be),u.push({key:v,tag:P,component_name:y,source_file:t,source_kind:x})}});let g=e.cmsPreviewModulePath?Ie(o,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return u.length===0&&!g?{code:e.source,elements:u}:{code:me(o,{jsescOption:{minimal:!0}}).code,elements:u}}function Z(e,t,i){if(!E.isAbsolute(e))return e;let r=E.isAbsolute(t)?t:E.resolve(i||process.cwd(),t),s=E.relative(E.dirname(r),e).split(E.sep).join("/");return s.startsWith(".")?s:`./${s}`}function Ie(e,t,i,r,s){let o;if(q(e,{Program(a){o=a,a.stop()}}),!o)return!1;let u=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),c=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListResult"),g=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListView"),b=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),f=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),d=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),y=!1,A=!1,v=[],P=!1,x=!1,_=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(i)||e.program.body.some(a=>n.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));q(e,{CallExpression(a){let l=a.node,m=oe(a,l);if(m?.slug&&v.push({path:a,query:m}),n.isMemberExpression(l.callee)&&!l.callee.computed&&n.isIdentifier(l.callee.property,{name:"map"})&&l.arguments.length===1&&n.isIdentifier(l.arguments[0])){let w=G(a,l.arguments[0].name),J=z(a,l.callee.object);if(w&&(!J||J.operation==="list"&&J.slug===w.slug)){let O=J?.operation==="list",U=a.scope.generateUidIdentifier("vcpCmsRecord");l.arguments[0]=n.arrowFunctionExpression([U],n.callExpression(O?u:g,[n.callExpression(n.cloneNode(l.arguments[0]),[n.cloneNode(U)]),n.cloneNode(U),n.stringLiteral(w.slug),...O?[n.stringLiteral("list")]:[]])),O?y=!0:A=!0,a.skip()}return}if(!n.isIdentifier(l.callee)||l.arguments.length!==1)return;let h=G(a,l.callee.name),C=n.isIdentifier(l.arguments[0]),L=C?l.arguments[0].name:R(l.arguments[0],["data"]),N=L&&se(a,L);if(!h||N?.operation!=="detail"||(C?N.slug!==h.slug:N.slug!==void 0))return;let T=n.cloneNode(l,!0),F=n.cloneNode(l.arguments[0],!0);a.replaceWith(n.callExpression(u,[T,F,n.stringLiteral(h.slug),n.stringLiteral("detail")])),y=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=n.callExpression(b,[a.node.argument]),P=!0},JSXElement:{exit(a){let l=a.node.openingElement;if(!K(l,ie.key))return;let m=ve(a);if(!m||!_&&a.scope.getBinding(m.base)?.kind!=="param")return;let h=l.attributes.findIndex(w=>n.isJSXAttribute(w)&&n.isJSXIdentifier(w.name,{name:"key"})),C=h<0?null:l.attributes.splice(h,1)[0],L=[n.identifier(m.base),n.stringLiteral(m.field)];m.index&&L.push(n.cloneNode(m.index,!0));let N=[...C?[C]:[],...ce(l.name)?[]:[n.jsxAttribute(n.jsxIdentifier("lookupHost"))],n.jsxAttribute(n.jsxIdentifier("candidate"),n.jsxExpressionContainer(n.callExpression(f,L)))],T=n.jsxIdentifier(d.name),F=n.jsxElement(n.jsxOpeningElement(n.cloneNode(T),N,!1),n.jsxClosingElement(n.cloneNode(T)),[a.node]);a.replaceWith(F),x=!0,a.skip()}}});let p=[];v.some(({query:a})=>a.operation==="list")&&p.push(n.importSpecifier(c,n.identifier("attachCmsPreviewListResult")));for(let{path:a,query:l}of v.reverse()){let m=a.scope.generateUidIdentifier("vcpCmsResult"),h=n.stringLiteral(l.slug),C=l.operation==="list"?n.callExpression(c,[m,h,n.booleanLiteral(l.strict)]):n.conditionalExpression(m,n.callExpression(u,[m,m,h,n.stringLiteral("detail")]),m);l.operation==="detail"&&(y=!0),a.replaceWith(n.callExpression(n.memberExpression(n.cloneNode(a.node,!0),n.identifier("then")),[n.arrowFunctionExpression([m],C)]))}return y&&p.push(n.importSpecifier(u,n.identifier("attachCmsPreviewRecord"))),A&&p.push(n.importSpecifier(g,n.identifier("attachCmsPreviewListView"))),P&&p.push(n.importSpecifier(b,n.identifier("stripCmsPreviewMetadata"))),x&&p.push(n.importSpecifier(f,n.identifier("readCmsPreviewCandidate"))),p.length&&e.program.body.unshift(n.importDeclaration(p,n.stringLiteral(Z(t,r,s)))),x&&e.program.body.unshift(n.importDeclaration([n.importSpecifier(d,n.identifier("CmsPreviewProbe"))],n.stringLiteral(Z(E.join(E.dirname(t),"cms-preview-probe.js"),r,s)))),p.length>0||x}function ve(e){let t=e.node,i=t.openingElement.name,r=j(i);if(!r)return null;let s=new Map(t.openingElement.attributes.flatMap(d=>n.isJSXAttribute(d)&&n.isJSXIdentifier(d.name)&&n.isJSXExpressionContainer(d.value)&&n.isExpression(d.value.expression)?[[d.name.name,d.value.expression]]:[])),o=r==="img"||/^[A-Z]/.test(r)&&s.has("src"),u=s.get("dangerouslySetInnerHTML"),c=n.isObjectExpression(u)?u.properties.find(d=>n.isObjectProperty(d)&&!d.computed&&(n.isIdentifier(d.key,{name:"__html"})||n.isStringLiteral(d.key,{value:"__html"})))?.value:u,g=t.children.flatMap(d=>n.isJSXExpressionContainer(d)&&n.isExpression(d.expression)?[d.expression]:[]),b=o?[s.get("src")]:c?[c]:g.length?g:["src","href","alt","poster","content","title","aria-label","value","checked","dateTime"].flatMap(d=>s.has(d)?[s.get(d)]:[]);if(b.length!==1||!b[0])return null;let f=b[0];return S(f,e)??(o&&n.isIdentifier(f)&&e.scope.hasBinding(f.name)?{base:f.name,field:"url"}:g.length?Ce(f,e):null)}function Ce(e,t){if(!n.isIdentifier(e))return null;let i=t.scope.getBinding(e.name);if(i?.kind!=="param"||!i.constant)return null;let r=i.path.parentPath,s=r?.parentPath;if(!(r?.isArrowFunctionExpression()||r?.isFunctionExpression())||r.node.params[0]!==i.path.node||!s?.isCallExpression()||s.node.arguments[0]!==r.node||!fe(s.node)||s.node.callee.computed)return null;let o=S(s.node.callee.object,s);return o&&!o.index&&t.scope.getBinding(o.base)===s.scope.getBinding(o.base)?o:null}function S(e,t,i=0){if(i>=8)return null;if(n.isTemplateLiteral(e)&&e.expressions.length===1)return S(e.expressions[0],t,i+1);if(n.isCallExpression(e)&&n.isMemberExpression(e.callee)&&!e.callee.computed&&n.isMemberExpression(e.callee.object)&&!e.callee.object.computed&&n.isIdentifier(e.callee.object.property,{name:"field"})&&ae(t,e.callee.object.object))return S(e.arguments[0],t,i+1);if(n.isCallExpression(e)&&n.isIdentifier(e.callee)&&e.arguments.length===1){let c=t.scope.getBinding(e.callee.name);if(c?.constant&&(c.path.isFunctionDeclaration()||c.path.isVariableDeclarator()&&n.isFunction(c.path.node.init)))return S(e.arguments[0],t,i+1)}if(n.isConditionalExpression(e)){let c=g=>n.isLiteral(g)&&!n.isTemplateLiteral(g);if(c(e.consequent)&&c(e.alternate))return S(e.test,t,i+1);if(c(e.alternate))return S(e.consequent,t,i+1);if(c(e.consequent))return S(e.alternate,t,i+1)}if(n.isLogicalExpression(e)&&(e.operator==="??"||e.operator==="||")&&n.isLiteral(e.right)&&!n.isTemplateLiteral(e.right))return S(e.left,t,i+1);if(n.isTSAsExpression(e)||n.isTSNonNullExpression(e)||n.isTSSatisfiesExpression(e))return S(e.expression,t,i+1);let r=e,s=[];for(;n.isMemberExpression(r)||n.isOptionalMemberExpression(r);){if(!r.computed&&n.isIdentifier(r.property))s.unshift({property:r.property.name});else if(r.computed&&n.isStringLiteral(r.property))s.unshift({property:r.property.value});else if(r.computed&&n.isNumericLiteral(r.property)&&Number.isSafeInteger(r.property.value)&&r.property.value>=0)s.unshift({index:r.property});else if(r.computed&&n.isIdentifier(r.property)&&t.scope.hasBinding(r.property.name))s.unshift({index:r.property});else return null;r=r.object}if(!n.isIdentifier(r))return null;let o=t.scope.getBinding(r.name);if(!o)return null;if(o.constant&&o.path.isVariableDeclarator()&&n.isIdentifier(o.path.node.id)){let c=S(o.path.node.init,o.path,i+1);if(c&&(s.length===0||c.index&&s[0]?.property==="url")&&t.scope.getBinding(c.base)===o.path.scope.getBinding(c.base)&&(!n.isIdentifier(c.index)||t.scope.getBinding(c.index.name)===o.path.scope.getBinding(c.index.name)))return c}if(s[0]?.property==="fields"&&s.shift(),!s[0]?.property||s.slice(2).some(c=>c.index))return null;let u=s[1];return{base:r.name,field:s[0].property,...u?.index?{index:u.index}:{}}}function G(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isImportSpecifier())return null;let r=i.path.node;if(!n.isIdentifier(r.imported)||!/^to[A-Za-z0-9_$]+View$/.test(r.imported.name))return null;let s=i.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 R(e,t){let i=e;for(let r of[...t].reverse()){if(!n.isMemberExpression(i)||i.computed||!n.isIdentifier(i.property,{name:r}))return null;i=i.object}return n.isIdentifier(i)?i.name:null}function Pe(e){if(n.isConditionalExpression(e)){let t=R(e.consequent,["data","items"]);return!t||!n.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!n.isBinaryExpression(e.test,{operator:"==="})||R(e.test.left,["kind"])!==t||!n.isStringLiteral(e.test.right,{value:"ok"})?null:t}return R(e,["data","items"])}function z(e,t,i=new Set){let r=Pe(t);if(r)return se(e,r);if(i.size>=20)return null;if(n.isIdentifier(t)){let s=e.scope.getBinding(t.name);return!s?.constant||!s.path.isVariableDeclarator()||!s.path.node.init||i.has(s)?null:(i.add(s),z(e,s.path.node.init,i))}return n.isCallExpression(t)&&n.isMemberExpression(t.callee)&&!t.callee.computed&&n.isIdentifier(t.callee.property)&&["filter","slice","sort","toSorted","reverse","toReversed"].includes(t.callee.property.name)?(i.add(t),z(e,t.callee.object,i)):null}function se(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isVariableDeclarator())return null;let r=i.path.node.init,s=n.isAwaitExpression(r)?r.argument:null;return oe(e,s)}function oe(e,t){return!n.isCallExpression(t)||!n.isMemberExpression(t.callee)||t.callee.computed||!n.isIdentifier(t.callee.property)||!n.isMemberExpression(t.callee.object)||t.callee.object.computed||!n.isIdentifier(t.callee.object.property,{name:"collections"})||!n.isIdentifier(t.callee.object.object)||!ae(e,t.callee.object.object)?null:["listStrict","list"].includes(t.callee.property.name)&&n.isStringLiteral(t.arguments[0])?{operation:"list",slug:t.arguments[0].value,strict:t.callee.property.name==="listStrict"}:t.callee.property.name==="getByUrlStrict"?{operation:"detail"}:t.callee.property.name==="get"&&n.isStringLiteral(t.arguments[0])?{operation:"detail",slug:t.arguments[0].value}:null}function ae(e,t){if(!n.isIdentifier(t))return!1;let i=e.scope.getBinding(t.name);return i?.constant&&i.path.isImportSpecifier()&&n.isIdentifier(i.path.node.imported,{name:"cms"})&&i.path.parentPath.node.source.value==="@/lib/cms"}function we(e){return!e.findParent(t=>t.isJSXElement())}function Ae(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 Le(e,t,i){return`${e}::${t}::${i}`}function Ne(e,t){let i=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&i.startsWith(`${r}/`))return i.slice(r.length+1);for(let[o,u]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=i.indexOf(o);if(c>=0)return i.slice(c+u)}return i.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??i}function ce(e){return n.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function j(e){return n.isJSXIdentifier(e)?e.name:n.isJSXMemberExpression(e)?ue(e):null}function je(e,t){let i=new Set;for(let r of e.program.body)if(!(!n.isImportDeclaration(r)||!Je(r.source.value,t)))for(let s of r.specifiers)i.add(s.local.name);return i}function Te(e,t){let i=e.split(".")[0]??e;return t.has(i)}function X(e){if(!e)return!1;let t=V(e);return t===M||t.startsWith(`${M}/`)||t.includes(`/${M}/`)||t.endsWith(`/${M}`)}function Je(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?X(e.slice(2)):e.startsWith("./")||e.startsWith("../")?X(V(`${Me(t)}/${e}`)):X(e):!1}function V(e){let i=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let s of i.split("/"))if(!(!s||s===".")){if(s===".."){r.pop();continue}r.push(s)}return r.join("/")}function Me(e){let t=V(e),i=t.lastIndexOf("/");return i>=0?t.slice(0,i):""}function Re(e){let t=j(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ge.has(t)}function K(e,t){return e.attributes.some(i=>n.isJSXAttribute(i)&&n.isJSXIdentifier(i.name,{name:t}))}function Y(e,t,i){le(e,n.jsxAttribute(n.jsxIdentifier(t),n.stringLiteral(i)))}function ee(e,t){K(e,t)||le(e,n.jsxAttribute(n.jsxIdentifier(t),null))}function le(e,t){let i=e.attributes.findIndex(r=>n.isJSXSpreadAttribute(r));if(i>=0){e.attributes.splice(i,0,t);return}e.attributes.push(t)}function ue(e){return`${n.isJSXIdentifier(e.object)?e.object.name:ue(e.object)}.${e.property.name}`}function Xe(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&n.isIdentifier(t.node.id)){let i=t.get("init");if(!Array.isArray(i)&&(i.isArrowFunctionExpression()||i.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function ke(e){return e.some(t=>n.isJSXElement(t)||n.isJSXFragment(t))}var te=new WeakMap,k=new WeakMap,W=new WeakMap;function Be(e){let t=te.get(e.node);if(t!==void 0)return t;let i=[],r=e;for(;r;){if(r.isJSXElement()){let o=_e(r);o&&i.unshift(o)}r=r.parentPath}let s=i.join("/");return te.set(e.node,s),s}function _e(e){let t=j(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${ne(e,t)}`:`${t}#${ne(e,t)}`}function ne(e,t){let i=de(e)??e.getFunctionParent();if(!i)return 0;let r=W.get(i.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let s=W.get(i.node);s||(s=new Map,W.set(i.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let u=0,c=i.isJSXElement()||i.isJSXFragment()?B(i):Fe(i);for(let g of c)if(j(g.node.openingElement.name)===t){if(o.set(g.node,u),g.node===e.node)return u;u+=1}return o.get(e.node)??0}function Fe(e){let t=k.get(e.node);if(t)return t;let i=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!de(r)&&i.push(r)}}),k.set(e.node,i),i}function de(e){let t=e.parentPath,i=null;for(;t;){if(t.isJSXFragment()){i=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return i}function B(e){let t=k.get(e.node);if(t)return t;let i=[],r=e.get("children");for(let s of r)if(!Array.isArray(s)){if(s.isJSXElement()){i.push(s);continue}if(s.isJSXFragment()){i.push(...B(s));continue}s.isJSXExpressionContainer()&&i.push(...I(s.get("expression")))}return k.set(e.node,i),i}function I(e){return e.isJSXElement()?[e]:e.isJSXFragment()?B(e):e.isParenthesizedExpression()?I(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?I(e.get("right")):e.isConditionalExpression()?[...I(e.get("consequent")),...I(e.get("alternate"))]:e.isCallExpression()&&fe(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 B(t);if(t.isParenthesizedExpression())return I(t.get("expression"));if(!t.isBlockStatement())return[];let i=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let o of r.get("declarations")){let u=o.get("init");(u.isJSXElement()||u.isJSXFragment())&&i.push(...I(u))}if(!r.isReturnStatement())continue;let s=r.get("argument");return s.node&&i.push(...I(s)),i}return i}function fe(e){return n.isMemberExpression(e.callee)&&n.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=he;module.exports.instrumentSiteEditRuntimeAttributes=re;
1
+ "use strict";var $=require("@babel/generator"),ge=require("@babel/parser"),W=require("@babel/traverse"),n=require("@babel/types"),Q=require("node:fs"),b=require("node:path"),Ee=typeof $=="function"?$:$.default,q=typeof W=="function"?W:W.default,re={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},be=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var Se="suppressHydrationWarning",he=new Set(["SiteEditBootstrap"]),H="data-vcp-source-location",ye="data-vcp-ui-component",T="components/ui";function xe(e,t){this.cacheable?.();let i=this.async();try{if(!Ie(this.resourcePath)){i(null,e,t);return}let r=this.getOptions?.()??{},s=se({source:e,file:this.resourcePath,projectRoot:r.projectRoot,sourceLocations:r.sourceLocations===!0,cmsPreviewModulePath:r.cmsPreviewModulePath??ve(r.projectRoot)});i(null,s.code,s.code===e?t:null)}catch(r){i(r)}}function ve(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let i of[b.dirname(t),b.resolve(b.dirname(t),"../dist")]){let r=b.join(i,"cms-preview-record.js");if(Q.existsSync(r)&&Q.existsSync(b.join(i,"cms-preview-probe.js")))return r}return}catch{return}}function Ie(e){return typeof e=="string"&&/\.[jt]sx?$/.test(e)&&!e.replace(/\\/g,"/").includes("/node_modules/")&&!e.endsWith(".d.ts")}function se(e){let t=je(e.file,e.projectRoot),i=Le(e.source)&&!/\.ts$/.test(t),r=e.cmsPreviewModulePath&&e.source.includes("@/lib/cms");if(!i&&!r||R(t))return{code:e.source,elements:[]};let s=e.attributes??re,o=ge.parse(e.source,{sourceType:"module",plugins:["typescript",.../\.ts$/.test(t)?[]:["jsx"]]}),u=[],c=Xe(o,t);q(o,{JSXElement(E){let f=E.node.openingElement,d=f.name;if(!ke(d)||K(f,s.key)&&!e.sourceLocations)return;let y=Oe(E)??"default",J=Be(E),I=Ne(t,y,J),P=N(d)??"unknown",x=le(d)?"jsx":"component-call";if(x==="component-call"&&!Fe(E.node.children)&&he.has(P))return;let F=x==="component-call"&&Te(P,c);if(e.sourceLocations&&(f.attributes=f.attributes.filter(m=>!(n.isJSXAttribute(m)&&n.isJSXIdentifier(m.name)&&(m.name.name===s.key||m.name.name===H))),f.loc)){let{start:m,end:a}=f.loc;Y(f,H,encodeURIComponent(JSON.stringify({key:I,sourceFile:t,componentName:y,structuralPath:J,openingElementRange:{startLine:m.line,startColumn:m.column,endLine:a.line,endColumn:a.column}})))}Y(f,s.key,I),F&&ee(f,ye),Ae(E)&&ee(f,Se),u.push({key:I,tag:P,component_name:y,source_file:t,source_kind:x})}});let g=e.cmsPreviewModulePath?Ce(o,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return u.length===0&&!g?{code:e.source,elements:u}:{code:Ee(o,{jsescOption:{minimal:!0}}).code,elements:u}}function Z(e,t,i){if(!b.isAbsolute(e))return e;let r=b.isAbsolute(t)?t:b.resolve(i||process.cwd(),t),s=b.relative(b.dirname(r),e).split(b.sep).join("/");return s.startsWith(".")?s:`./${s}`}function Ce(e,t,i,r,s){let o;if(q(e,{Program(a){o=a,a.stop()}}),!o)return!1;let u=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),c=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListResult"),g=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListView"),E=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),f=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),d=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),y=!1,J=!1,I=[],P=!1,x=!1,F=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(i)||e.program.body.some(a=>n.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));q(e,{CallExpression(a){let l=a.node,p=ae(a,l);if(p?.slug&&I.push({path:a,query:p}),n.isMemberExpression(l.callee)&&!l.callee.computed&&n.isIdentifier(l.callee.property,{name:"map"})&&l.arguments.length===1&&n.isIdentifier(l.arguments[0])){let w=G(a,l.arguments[0].name),X=z(a,l.callee.object);if(w&&(!X||X.operation==="list"&&X.slug===w.slug)){let _=X?.operation==="list",U=a.scope.generateUidIdentifier("vcpCmsRecord");l.arguments[0]=n.arrowFunctionExpression([U],n.callExpression(_?u:g,[n.callExpression(n.cloneNode(l.arguments[0]),[n.cloneNode(U)]),n.cloneNode(U),n.stringLiteral(w.slug),..._?[n.stringLiteral("list")]:[]])),_?y=!0:J=!0,a.skip()}return}if(!n.isIdentifier(l.callee)||l.arguments.length!==1)return;let h=G(a,l.callee.name),C=n.isIdentifier(l.arguments[0]),A=C?l.arguments[0].name:M(l.arguments[0],["data"]),L=A&&oe(a,A);if(!h||L?.operation!=="detail"||(C?L.slug!==h.slug:L.slug!==void 0))return;let j=n.cloneNode(l,!0),B=n.cloneNode(l.arguments[0],!0);a.replaceWith(n.callExpression(u,[j,B,n.stringLiteral(h.slug),n.stringLiteral("detail")])),y=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=n.callExpression(E,[a.node.argument]),P=!0},JSXElement:{exit(a){let l=a.node.openingElement;if(!K(l,re.key))return;let p=Pe(a);if(!p||!F&&a.scope.getBinding(p.base)?.kind!=="param")return;let h=l.attributes.findIndex(w=>n.isJSXAttribute(w)&&n.isJSXIdentifier(w.name,{name:"key"})),C=h<0?null:l.attributes.splice(h,1)[0],A=[n.identifier(p.base),n.stringLiteral(p.field)];p.index&&A.push(n.cloneNode(p.index,!0));let L=[...C?[C]:[],...le(l.name)?[]:[n.jsxAttribute(n.jsxIdentifier("lookupHost"))],n.jsxAttribute(n.jsxIdentifier("candidate"),n.jsxExpressionContainer(n.callExpression(f,A)))],j=n.jsxIdentifier(d.name),B=n.jsxElement(n.jsxOpeningElement(n.cloneNode(j),L,!1),n.jsxClosingElement(n.cloneNode(j)),[a.node]);a.replaceWith(B),x=!0,a.skip()}}});let m=[];I.some(({query:a})=>a.operation==="list")&&m.push(n.importSpecifier(c,n.identifier("attachCmsPreviewListResult")));for(let{path:a,query:l}of I.reverse()){let p=a.scope.generateUidIdentifier("vcpCmsResult"),h=n.stringLiteral(l.slug),C=l.operation==="list"?n.callExpression(c,[p,h,n.booleanLiteral(l.strict)]):n.conditionalExpression(p,n.callExpression(u,[p,p,h,n.stringLiteral("detail")]),p);l.operation==="detail"&&(y=!0),a.replaceWith(n.callExpression(n.memberExpression(n.cloneNode(a.node,!0),n.identifier("then")),[n.arrowFunctionExpression([p],C)]))}return y&&m.push(n.importSpecifier(u,n.identifier("attachCmsPreviewRecord"))),J&&m.push(n.importSpecifier(g,n.identifier("attachCmsPreviewListView"))),P&&m.push(n.importSpecifier(E,n.identifier("stripCmsPreviewMetadata"))),x&&m.push(n.importSpecifier(f,n.identifier("readCmsPreviewCandidate"))),m.length&&e.program.body.unshift(n.importDeclaration(m,n.stringLiteral(Z(t,r,s)))),x&&e.program.body.unshift(n.importDeclaration([n.importSpecifier(d,n.identifier("CmsPreviewProbe"))],n.stringLiteral(Z(b.join(b.dirname(t),"cms-preview-probe.js"),r,s)))),m.length>0||x}function Pe(e){let t=e.node,i=t.openingElement.name,r=N(i);if(!r)return null;let s=new Map(t.openingElement.attributes.flatMap(d=>n.isJSXAttribute(d)&&n.isJSXIdentifier(d.name)&&n.isJSXExpressionContainer(d.value)&&n.isExpression(d.value.expression)?[[d.name.name,d.value.expression]]:[])),o=r==="img"||/^[A-Z]/.test(r)&&s.has("src"),u=s.get("dangerouslySetInnerHTML"),c=n.isObjectExpression(u)?u.properties.find(d=>n.isObjectProperty(d)&&!d.computed&&(n.isIdentifier(d.key,{name:"__html"})||n.isStringLiteral(d.key,{value:"__html"})))?.value:u,g=t.children.flatMap(d=>n.isJSXExpressionContainer(d)&&n.isExpression(d.expression)?[d.expression]:[]),E=o?[s.get("src")]:c?[c]:g.length?g:["src","href","alt","poster","content","title","aria-label","value","checked","dateTime"].flatMap(d=>s.has(d)?[s.get(d)]:[]);if(E.length!==1||!E[0])return null;let f=E[0];return S(f,e)??(o&&n.isIdentifier(f)&&e.scope.hasBinding(f.name)?{base:f.name,field:"url"}:g.length?we(f,e):null)}function we(e,t){if(!n.isIdentifier(e))return null;let i=t.scope.getBinding(e.name);if(i?.kind!=="param"||!i.constant)return null;let r=i.path.parentPath,s=r?.parentPath;if(!(r?.isArrowFunctionExpression()||r?.isFunctionExpression())||r.node.params[0]!==i.path.node||!s?.isCallExpression()||s.node.arguments[0]!==r.node||!pe(s.node)||s.node.callee.computed)return null;let o=S(s.node.callee.object,s);return o&&!o.index&&t.scope.getBinding(o.base)===s.scope.getBinding(o.base)?o:null}function S(e,t,i=0){if(i>=8)return null;if(n.isTemplateLiteral(e)&&e.expressions.length===1)return S(e.expressions[0],t,i+1);if(n.isCallExpression(e)&&n.isMemberExpression(e.callee)&&!e.callee.computed&&n.isMemberExpression(e.callee.object)&&!e.callee.object.computed&&n.isIdentifier(e.callee.object.property,{name:"field"})&&ce(t,e.callee.object.object))return S(e.arguments[0],t,i+1);if(n.isCallExpression(e)&&n.isIdentifier(e.callee)&&e.arguments.length===1){let c=t.scope.getBinding(e.callee.name);if(c?.constant&&(c.path.isFunctionDeclaration()||c.path.isVariableDeclarator()&&n.isFunction(c.path.node.init)))return S(e.arguments[0],t,i+1)}if(n.isConditionalExpression(e)){let c=g=>n.isLiteral(g)&&!n.isTemplateLiteral(g);if(c(e.consequent)&&c(e.alternate))return S(e.test,t,i+1);if(c(e.alternate))return S(e.consequent,t,i+1);if(c(e.consequent))return S(e.alternate,t,i+1)}if(n.isLogicalExpression(e)&&(e.operator==="??"||e.operator==="||")&&n.isLiteral(e.right)&&!n.isTemplateLiteral(e.right))return S(e.left,t,i+1);if(n.isTSAsExpression(e)||n.isTSNonNullExpression(e)||n.isTSSatisfiesExpression(e))return S(e.expression,t,i+1);let r=e,s=[];for(;n.isMemberExpression(r)||n.isOptionalMemberExpression(r);){if(!r.computed&&n.isIdentifier(r.property))s.unshift({property:r.property.name});else if(r.computed&&n.isStringLiteral(r.property))s.unshift({property:r.property.value});else if(r.computed&&n.isNumericLiteral(r.property)&&Number.isSafeInteger(r.property.value)&&r.property.value>=0)s.unshift({index:r.property});else if(r.computed&&n.isIdentifier(r.property)&&t.scope.hasBinding(r.property.name))s.unshift({index:r.property});else return null;r=r.object}if(!n.isIdentifier(r))return null;let o=t.scope.getBinding(r.name);if(!o)return null;if(o.constant&&o.path.isVariableDeclarator()&&n.isIdentifier(o.path.node.id)){let c=S(o.path.node.init,o.path,i+1);if(c&&(s.length===0||c.index&&s[0]?.property==="url")&&t.scope.getBinding(c.base)===o.path.scope.getBinding(c.base)&&(!n.isIdentifier(c.index)||t.scope.getBinding(c.index.name)===o.path.scope.getBinding(c.index.name)))return c}if(s[0]?.property==="fields"&&s.shift(),!s[0]?.property||s.slice(2).some(c=>c.index))return null;let u=s[1];return{base:r.name,field:s[0].property,...u?.index?{index:u.index}:{}}}function G(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isImportSpecifier())return null;let r=i.path.node;if(!n.isIdentifier(r.imported)||!/^to[A-Za-z0-9_$]+View$/.test(r.imported.name))return null;let s=i.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 M(e,t){let i=e;for(let r of[...t].reverse()){if(!n.isMemberExpression(i)||i.computed||!n.isIdentifier(i.property,{name:r}))return null;i=i.object}return n.isIdentifier(i)?i.name:null}function Je(e){if(n.isConditionalExpression(e)){let t=M(e.consequent,["data","items"]);return!t||!n.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!n.isBinaryExpression(e.test,{operator:"==="})||M(e.test.left,["kind"])!==t||!n.isStringLiteral(e.test.right,{value:"ok"})?null:t}return M(e,["data","items"])}function z(e,t,i=new Set){let r=Je(t);if(r)return oe(e,r);if(i.size>=20)return null;if(n.isIdentifier(t)){let s=e.scope.getBinding(t.name);return!s?.constant||!s.path.isVariableDeclarator()||!s.path.node.init||i.has(s)?null:(i.add(s),z(e,s.path.node.init,i))}return n.isCallExpression(t)&&n.isMemberExpression(t.callee)&&!t.callee.computed&&n.isIdentifier(t.callee.property)&&["filter","slice","sort","toSorted","reverse","toReversed"].includes(t.callee.property.name)?(i.add(t),z(e,t.callee.object,i)):null}function oe(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isVariableDeclarator())return null;let r=i.path.node.init,s=n.isAwaitExpression(r)?r.argument:null;return ae(e,s)}function ae(e,t){return!n.isCallExpression(t)||!n.isMemberExpression(t.callee)||t.callee.computed||!n.isIdentifier(t.callee.property)||!n.isMemberExpression(t.callee.object)||t.callee.object.computed||!n.isIdentifier(t.callee.object.property,{name:"collections"})||!n.isIdentifier(t.callee.object.object)||!ce(e,t.callee.object.object)?null:["listStrict","list"].includes(t.callee.property.name)&&n.isStringLiteral(t.arguments[0])?{operation:"list",slug:t.arguments[0].value,strict:t.callee.property.name==="listStrict"}:t.callee.property.name==="getByUrlStrict"?{operation:"detail"}:t.callee.property.name==="get"&&n.isStringLiteral(t.arguments[0])?{operation:"detail",slug:t.arguments[0].value}:null}function ce(e,t){if(!n.isIdentifier(t))return!1;let i=e.scope.getBinding(t.name);return i?.constant&&i.path.isImportSpecifier()&&n.isIdentifier(i.path.node.imported,{name:"cms"})&&i.path.parentPath.node.source.value==="@/lib/cms"}function Ae(e){return!e.findParent(t=>t.isJSXElement())}function Le(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 Ne(e,t,i){return`${e}::${t}::${i}`}function je(e,t){let i=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&i.startsWith(`${r}/`))return i.slice(r.length+1);for(let[o,u]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=i.indexOf(o);if(c>=0)return i.slice(c+u)}return i.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??i}function le(e){return n.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function N(e){return n.isJSXIdentifier(e)?e.name:n.isJSXMemberExpression(e)?de(e):null}function Xe(e,t){let i=new Set;for(let r of e.program.body)if(!(!n.isImportDeclaration(r)||!Me(r.source.value,t)))for(let s of r.specifiers)i.add(s.local.name);return i}function Te(e,t){let i=e.split(".")[0]??e;return t.has(i)}function R(e){if(!e)return!1;let t=V(e);return t===T||t.startsWith(`${T}/`)||t.includes(`/${T}/`)||t.endsWith(`/${T}`)}function Me(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?R(e.slice(2)):e.startsWith("./")||e.startsWith("../")?R(V(`${Re(t)}/${e}`)):R(e):!1}function V(e){let i=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let s of i.split("/"))if(!(!s||s===".")){if(s===".."){r.pop();continue}r.push(s)}return r.join("/")}function Re(e){let t=V(e),i=t.lastIndexOf("/");return i>=0?t.slice(0,i):""}function ke(e){let t=N(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!be.has(t)}function K(e,t){return e.attributes.some(i=>n.isJSXAttribute(i)&&n.isJSXIdentifier(i.name,{name:t}))}function Y(e,t,i){ue(e,n.jsxAttribute(n.jsxIdentifier(t),n.stringLiteral(i)))}function ee(e,t){K(e,t)||ue(e,n.jsxAttribute(n.jsxIdentifier(t),null))}function ue(e,t){let i=e.attributes.findIndex(r=>n.isJSXSpreadAttribute(r));if(i>=0){e.attributes.splice(i,0,t);return}e.attributes.push(t)}function de(e){return`${n.isJSXIdentifier(e.object)?e.object.name:de(e.object)}.${e.property.name}`}function Oe(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&n.isIdentifier(t.node.id)){let i=t.get("init");if(!Array.isArray(i)&&(i.isArrowFunctionExpression()||i.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function Fe(e){return e.some(t=>n.isJSXElement(t)||n.isJSXFragment(t))}var te=new WeakMap,k=new WeakMap,D=new WeakMap,ne=new WeakMap;function Be(e){let t=te.get(e.node);if(t!==void 0)return t;let i=[],r=e;for(;r;){if(r.isJSXElement()){let o=_e(r);o&&i.unshift(o)}r=r.parentPath}let s=i.join("/");return te.set(e.node,s),s}function _e(e){let t=N(e.node.openingElement.name);if(!t||t==="Fragment"||t.endsWith(".Fragment"))return null;let i=Ue(e),r=i?.prefix??"",s=i?.ordinal??$e(e,t);return`${r}${/^[A-Z]/.test(t)?"component:":""}${t}#${s}`}function Ue(e){let t=e.findParent(i=>i.isJSXOpeningElement()||i.isJSXElement()&&!fe(i.node));if(t?.isJSXOpeningElement()){let i=ie(t.node,e.node);if(i!==void 0)return{prefix:`prop:${i}/`,ordinal:0}}if(t?.isJSXElement()&&t.findParent(i=>i.isJSXOpeningElement())){let i=ie(t.node,e.node);if(i!==void 0)return{prefix:"",ordinal:i}}}function ie(e,t){let i=ne.get(e);if(!i){i=new WeakMap;let r=0;for(let s of n.isJSXOpeningElement(e)?e.attributes:e.children)n.traverseFast(s,o=>{if(n.isJSXElement(o)&&!fe(o))return i.set(o,r++),n.traverseFast.skip});ne.set(e,i)}return i.get(t)}function fe(e){let t=e.openingElement.name;return n.isJSXIdentifier(t,{name:"Fragment"})||n.isJSXMemberExpression(t)&&t.property.name==="Fragment"}function $e(e,t){let i=me(e)??e.getFunctionParent();if(!i)return 0;let r=D.get(i.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let s=D.get(i.node);s||(s=new Map,D.set(i.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let u=0,c=i.isJSXElement()||i.isJSXFragment()?O(i):We(i);for(let g of c)if(N(g.node.openingElement.name)===t){if(o.set(g.node,u),g.node===e.node)return u;u+=1}return o.get(e.node)??0}function We(e){let t=k.get(e.node);if(t)return t;let i=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!me(r)&&i.push(r)}}),k.set(e.node,i),i}function me(e){let t=e.parentPath,i=null;for(;t;){if(t.isJSXFragment()){i=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return i}function O(e){let t=k.get(e.node);if(t)return t;let i=[],r=e.get("children");for(let s of r)if(!Array.isArray(s)){if(s.isJSXElement()){i.push(s);continue}if(s.isJSXFragment()){i.push(...O(s));continue}s.isJSXExpressionContainer()&&i.push(...v(s.get("expression")))}return k.set(e.node,i),i}function v(e){return e.isJSXElement()?[e]:e.isJSXFragment()?O(e):e.isParenthesizedExpression()?v(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?v(e.get("right")):e.isConditionalExpression()?[...v(e.get("consequent")),...v(e.get("alternate"))]:e.isCallExpression()&&pe(e.node)?De(e.get("arguments")[0]):[]}function De(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return O(t);if(t.isParenthesizedExpression())return v(t.get("expression"));if(!t.isBlockStatement())return[];let i=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let o of r.get("declarations")){let u=o.get("init");(u.isJSXElement()||u.isJSXFragment())&&i.push(...v(u))}if(!r.isReturnStatement())continue;let s=r.get("argument");return s.node&&i.push(...v(s)),i}return i}function pe(e){return n.isMemberExpression(e.callee)&&n.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=xe;module.exports.instrumentSiteEditRuntimeAttributes=se;
@@ -1 +1 @@
1
- "use strict";var ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var me=ge((qe,Q)=>{"use strict";var $=require("@babel/generator"),be=require("@babel/parser"),D=require("@babel/traverse"),n=require("@babel/types"),H=require("node:fs"),E=require("node:path"),Ee=typeof $=="function"?$:$.default,q=typeof D=="function"?D:D.default,re={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"]),he="suppressHydrationWarning",ye=new Set(["SiteEditBootstrap"]),Z="data-vcp-source-location",xe="data-vcp-ui-component",M="components/ui";function Ie(e,t){this.cacheable?.();let i=this.async();try{if(!Ce(this.resourcePath)){i(null,e,t);return}let r=this.getOptions?.()??{},s=se({source:e,file:this.resourcePath,projectRoot:r.projectRoot,sourceLocations:r.sourceLocations===!0,cmsPreviewModulePath:r.cmsPreviewModulePath??ve(r.projectRoot)});i(null,s.code,s.code===e?t:null)}catch(r){i(r)}}function ve(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let i of[E.dirname(t),E.resolve(E.dirname(t),"../dist")]){let r=E.join(i,"cms-preview-record.js");if(H.existsSync(r)&&H.existsSync(E.join(i,"cms-preview-probe.js")))return r}return}catch{return}}function Ce(e){return typeof e=="string"&&/\.[jt]sx?$/.test(e)&&!e.replace(/\\/g,"/").includes("/node_modules/")&&!e.endsWith(".d.ts")}function se(e){let t=Je(e.file,e.projectRoot),i=je(e.source)&&!/\.ts$/.test(t),r=e.cmsPreviewModulePath&&e.source.includes("@/lib/cms");if(!i&&!r||X(t))return{code:e.source,elements:[]};let s=e.attributes??re,o=be.parse(e.source,{sourceType:"module",plugins:["typescript",.../\.ts$/.test(t)?[]:["jsx"]]}),u=[],c=Me(o,t);q(o,{JSXElement(b){let f=b.node.openingElement,d=f.name;if(!Be(d)||K(f,s.key)&&!e.sourceLocations)return;let y=_e(b)??"default",A=Oe(b),v=Te(t,y,A),P=j(d)??"unknown",x=le(d)?"jsx":"component-call";if(x==="component-call"&&!Fe(b.node.children)&&ye.has(P))return;let _=x==="component-call"&&Re(P,c);if(e.sourceLocations&&(f.attributes=f.attributes.filter(p=>!(n.isJSXAttribute(p)&&n.isJSXIdentifier(p.name)&&(p.name.name===s.key||p.name.name===Z))),f.loc)){let{start:p,end:a}=f.loc;ee(f,Z,encodeURIComponent(JSON.stringify({key:v,sourceFile:t,componentName:y,structuralPath:A,openingElementRange:{startLine:p.line,startColumn:p.column,endLine:a.line,endColumn:a.column}})))}ee(f,s.key,v),_&&te(f,xe),Ne(b)&&te(f,he),u.push({key:v,tag:P,component_name:y,source_file:t,source_kind:x})}});let g=e.cmsPreviewModulePath?Pe(o,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return u.length===0&&!g?{code:e.source,elements:u}:{code:Ee(o,{jsescOption:{minimal:!0}}).code,elements:u}}function G(e,t,i){if(!E.isAbsolute(e))return e;let r=E.isAbsolute(t)?t:E.resolve(i||process.cwd(),t),s=E.relative(E.dirname(r),e).split(E.sep).join("/");return s.startsWith(".")?s:`./${s}`}function Pe(e,t,i,r,s){let o;if(q(e,{Program(a){o=a,a.stop()}}),!o)return!1;let u=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),c=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListResult"),g=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListView"),b=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),f=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),d=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),y=!1,A=!1,v=[],P=!1,x=!1,_=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(i)||e.program.body.some(a=>n.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));q(e,{CallExpression(a){let l=a.node,m=ae(a,l);if(m?.slug&&v.push({path:a,query:m}),n.isMemberExpression(l.callee)&&!l.callee.computed&&n.isIdentifier(l.callee.property,{name:"map"})&&l.arguments.length===1&&n.isIdentifier(l.arguments[0])){let w=Y(a,l.arguments[0].name),J=z(a,l.callee.object);if(w&&(!J||J.operation==="list"&&J.slug===w.slug)){let O=J?.operation==="list",U=a.scope.generateUidIdentifier("vcpCmsRecord");l.arguments[0]=n.arrowFunctionExpression([U],n.callExpression(O?u:g,[n.callExpression(n.cloneNode(l.arguments[0]),[n.cloneNode(U)]),n.cloneNode(U),n.stringLiteral(w.slug),...O?[n.stringLiteral("list")]:[]])),O?y=!0:A=!0,a.skip()}return}if(!n.isIdentifier(l.callee)||l.arguments.length!==1)return;let h=Y(a,l.callee.name),C=n.isIdentifier(l.arguments[0]),L=C?l.arguments[0].name:R(l.arguments[0],["data"]),N=L&&oe(a,L);if(!h||N?.operation!=="detail"||(C?N.slug!==h.slug:N.slug!==void 0))return;let T=n.cloneNode(l,!0),F=n.cloneNode(l.arguments[0],!0);a.replaceWith(n.callExpression(u,[T,F,n.stringLiteral(h.slug),n.stringLiteral("detail")])),y=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=n.callExpression(b,[a.node.argument]),P=!0},JSXElement:{exit(a){let l=a.node.openingElement;if(!K(l,re.key))return;let m=we(a);if(!m||!_&&a.scope.getBinding(m.base)?.kind!=="param")return;let h=l.attributes.findIndex(w=>n.isJSXAttribute(w)&&n.isJSXIdentifier(w.name,{name:"key"})),C=h<0?null:l.attributes.splice(h,1)[0],L=[n.identifier(m.base),n.stringLiteral(m.field)];m.index&&L.push(n.cloneNode(m.index,!0));let N=[...C?[C]:[],...le(l.name)?[]:[n.jsxAttribute(n.jsxIdentifier("lookupHost"))],n.jsxAttribute(n.jsxIdentifier("candidate"),n.jsxExpressionContainer(n.callExpression(f,L)))],T=n.jsxIdentifier(d.name),F=n.jsxElement(n.jsxOpeningElement(n.cloneNode(T),N,!1),n.jsxClosingElement(n.cloneNode(T)),[a.node]);a.replaceWith(F),x=!0,a.skip()}}});let p=[];v.some(({query:a})=>a.operation==="list")&&p.push(n.importSpecifier(c,n.identifier("attachCmsPreviewListResult")));for(let{path:a,query:l}of v.reverse()){let m=a.scope.generateUidIdentifier("vcpCmsResult"),h=n.stringLiteral(l.slug),C=l.operation==="list"?n.callExpression(c,[m,h,n.booleanLiteral(l.strict)]):n.conditionalExpression(m,n.callExpression(u,[m,m,h,n.stringLiteral("detail")]),m);l.operation==="detail"&&(y=!0),a.replaceWith(n.callExpression(n.memberExpression(n.cloneNode(a.node,!0),n.identifier("then")),[n.arrowFunctionExpression([m],C)]))}return y&&p.push(n.importSpecifier(u,n.identifier("attachCmsPreviewRecord"))),A&&p.push(n.importSpecifier(g,n.identifier("attachCmsPreviewListView"))),P&&p.push(n.importSpecifier(b,n.identifier("stripCmsPreviewMetadata"))),x&&p.push(n.importSpecifier(f,n.identifier("readCmsPreviewCandidate"))),p.length&&e.program.body.unshift(n.importDeclaration(p,n.stringLiteral(G(t,r,s)))),x&&e.program.body.unshift(n.importDeclaration([n.importSpecifier(d,n.identifier("CmsPreviewProbe"))],n.stringLiteral(G(E.join(E.dirname(t),"cms-preview-probe.js"),r,s)))),p.length>0||x}function we(e){let t=e.node,i=t.openingElement.name,r=j(i);if(!r)return null;let s=new Map(t.openingElement.attributes.flatMap(d=>n.isJSXAttribute(d)&&n.isJSXIdentifier(d.name)&&n.isJSXExpressionContainer(d.value)&&n.isExpression(d.value.expression)?[[d.name.name,d.value.expression]]:[])),o=r==="img"||/^[A-Z]/.test(r)&&s.has("src"),u=s.get("dangerouslySetInnerHTML"),c=n.isObjectExpression(u)?u.properties.find(d=>n.isObjectProperty(d)&&!d.computed&&(n.isIdentifier(d.key,{name:"__html"})||n.isStringLiteral(d.key,{value:"__html"})))?.value:u,g=t.children.flatMap(d=>n.isJSXExpressionContainer(d)&&n.isExpression(d.expression)?[d.expression]:[]),b=o?[s.get("src")]:c?[c]:g.length?g:["src","href","alt","poster","content","title","aria-label","value","checked","dateTime"].flatMap(d=>s.has(d)?[s.get(d)]:[]);if(b.length!==1||!b[0])return null;let f=b[0];return S(f,e)??(o&&n.isIdentifier(f)&&e.scope.hasBinding(f.name)?{base:f.name,field:"url"}:g.length?Ae(f,e):null)}function Ae(e,t){if(!n.isIdentifier(e))return null;let i=t.scope.getBinding(e.name);if(i?.kind!=="param"||!i.constant)return null;let r=i.path.parentPath,s=r?.parentPath;if(!(r?.isArrowFunctionExpression()||r?.isFunctionExpression())||r.node.params[0]!==i.path.node||!s?.isCallExpression()||s.node.arguments[0]!==r.node||!pe(s.node)||s.node.callee.computed)return null;let o=S(s.node.callee.object,s);return o&&!o.index&&t.scope.getBinding(o.base)===s.scope.getBinding(o.base)?o:null}function S(e,t,i=0){if(i>=8)return null;if(n.isTemplateLiteral(e)&&e.expressions.length===1)return S(e.expressions[0],t,i+1);if(n.isCallExpression(e)&&n.isMemberExpression(e.callee)&&!e.callee.computed&&n.isMemberExpression(e.callee.object)&&!e.callee.object.computed&&n.isIdentifier(e.callee.object.property,{name:"field"})&&ce(t,e.callee.object.object))return S(e.arguments[0],t,i+1);if(n.isCallExpression(e)&&n.isIdentifier(e.callee)&&e.arguments.length===1){let c=t.scope.getBinding(e.callee.name);if(c?.constant&&(c.path.isFunctionDeclaration()||c.path.isVariableDeclarator()&&n.isFunction(c.path.node.init)))return S(e.arguments[0],t,i+1)}if(n.isConditionalExpression(e)){let c=g=>n.isLiteral(g)&&!n.isTemplateLiteral(g);if(c(e.consequent)&&c(e.alternate))return S(e.test,t,i+1);if(c(e.alternate))return S(e.consequent,t,i+1);if(c(e.consequent))return S(e.alternate,t,i+1)}if(n.isLogicalExpression(e)&&(e.operator==="??"||e.operator==="||")&&n.isLiteral(e.right)&&!n.isTemplateLiteral(e.right))return S(e.left,t,i+1);if(n.isTSAsExpression(e)||n.isTSNonNullExpression(e)||n.isTSSatisfiesExpression(e))return S(e.expression,t,i+1);let r=e,s=[];for(;n.isMemberExpression(r)||n.isOptionalMemberExpression(r);){if(!r.computed&&n.isIdentifier(r.property))s.unshift({property:r.property.name});else if(r.computed&&n.isStringLiteral(r.property))s.unshift({property:r.property.value});else if(r.computed&&n.isNumericLiteral(r.property)&&Number.isSafeInteger(r.property.value)&&r.property.value>=0)s.unshift({index:r.property});else if(r.computed&&n.isIdentifier(r.property)&&t.scope.hasBinding(r.property.name))s.unshift({index:r.property});else return null;r=r.object}if(!n.isIdentifier(r))return null;let o=t.scope.getBinding(r.name);if(!o)return null;if(o.constant&&o.path.isVariableDeclarator()&&n.isIdentifier(o.path.node.id)){let c=S(o.path.node.init,o.path,i+1);if(c&&(s.length===0||c.index&&s[0]?.property==="url")&&t.scope.getBinding(c.base)===o.path.scope.getBinding(c.base)&&(!n.isIdentifier(c.index)||t.scope.getBinding(c.index.name)===o.path.scope.getBinding(c.index.name)))return c}if(s[0]?.property==="fields"&&s.shift(),!s[0]?.property||s.slice(2).some(c=>c.index))return null;let u=s[1];return{base:r.name,field:s[0].property,...u?.index?{index:u.index}:{}}}function Y(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isImportSpecifier())return null;let r=i.path.node;if(!n.isIdentifier(r.imported)||!/^to[A-Za-z0-9_$]+View$/.test(r.imported.name))return null;let s=i.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 R(e,t){let i=e;for(let r of[...t].reverse()){if(!n.isMemberExpression(i)||i.computed||!n.isIdentifier(i.property,{name:r}))return null;i=i.object}return n.isIdentifier(i)?i.name:null}function Le(e){if(n.isConditionalExpression(e)){let t=R(e.consequent,["data","items"]);return!t||!n.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!n.isBinaryExpression(e.test,{operator:"==="})||R(e.test.left,["kind"])!==t||!n.isStringLiteral(e.test.right,{value:"ok"})?null:t}return R(e,["data","items"])}function z(e,t,i=new Set){let r=Le(t);if(r)return oe(e,r);if(i.size>=20)return null;if(n.isIdentifier(t)){let s=e.scope.getBinding(t.name);return!s?.constant||!s.path.isVariableDeclarator()||!s.path.node.init||i.has(s)?null:(i.add(s),z(e,s.path.node.init,i))}return n.isCallExpression(t)&&n.isMemberExpression(t.callee)&&!t.callee.computed&&n.isIdentifier(t.callee.property)&&["filter","slice","sort","toSorted","reverse","toReversed"].includes(t.callee.property.name)?(i.add(t),z(e,t.callee.object,i)):null}function oe(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isVariableDeclarator())return null;let r=i.path.node.init,s=n.isAwaitExpression(r)?r.argument:null;return ae(e,s)}function ae(e,t){return!n.isCallExpression(t)||!n.isMemberExpression(t.callee)||t.callee.computed||!n.isIdentifier(t.callee.property)||!n.isMemberExpression(t.callee.object)||t.callee.object.computed||!n.isIdentifier(t.callee.object.property,{name:"collections"})||!n.isIdentifier(t.callee.object.object)||!ce(e,t.callee.object.object)?null:["listStrict","list"].includes(t.callee.property.name)&&n.isStringLiteral(t.arguments[0])?{operation:"list",slug:t.arguments[0].value,strict:t.callee.property.name==="listStrict"}:t.callee.property.name==="getByUrlStrict"?{operation:"detail"}:t.callee.property.name==="get"&&n.isStringLiteral(t.arguments[0])?{operation:"detail",slug:t.arguments[0].value}:null}function ce(e,t){if(!n.isIdentifier(t))return!1;let i=e.scope.getBinding(t.name);return i?.constant&&i.path.isImportSpecifier()&&n.isIdentifier(i.path.node.imported,{name:"cms"})&&i.path.parentPath.node.source.value==="@/lib/cms"}function Ne(e){return!e.findParent(t=>t.isJSXElement())}function je(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 Te(e,t,i){return`${e}::${t}::${i}`}function Je(e,t){let i=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&i.startsWith(`${r}/`))return i.slice(r.length+1);for(let[o,u]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=i.indexOf(o);if(c>=0)return i.slice(c+u)}return i.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??i}function le(e){return n.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function j(e){return n.isJSXIdentifier(e)?e.name:n.isJSXMemberExpression(e)?de(e):null}function Me(e,t){let i=new Set;for(let r of e.program.body)if(!(!n.isImportDeclaration(r)||!Xe(r.source.value,t)))for(let s of r.specifiers)i.add(s.local.name);return i}function Re(e,t){let i=e.split(".")[0]??e;return t.has(i)}function X(e){if(!e)return!1;let t=V(e);return t===M||t.startsWith(`${M}/`)||t.includes(`/${M}/`)||t.endsWith(`/${M}`)}function Xe(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?X(e.slice(2)):e.startsWith("./")||e.startsWith("../")?X(V(`${ke(t)}/${e}`)):X(e):!1}function V(e){let i=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let s of i.split("/"))if(!(!s||s===".")){if(s===".."){r.pop();continue}r.push(s)}return r.join("/")}function ke(e){let t=V(e),i=t.lastIndexOf("/");return i>=0?t.slice(0,i):""}function Be(e){let t=j(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!Se.has(t)}function K(e,t){return e.attributes.some(i=>n.isJSXAttribute(i)&&n.isJSXIdentifier(i.name,{name:t}))}function ee(e,t,i){ue(e,n.jsxAttribute(n.jsxIdentifier(t),n.stringLiteral(i)))}function te(e,t){K(e,t)||ue(e,n.jsxAttribute(n.jsxIdentifier(t),null))}function ue(e,t){let i=e.attributes.findIndex(r=>n.isJSXSpreadAttribute(r));if(i>=0){e.attributes.splice(i,0,t);return}e.attributes.push(t)}function de(e){return`${n.isJSXIdentifier(e.object)?e.object.name:de(e.object)}.${e.property.name}`}function _e(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&n.isIdentifier(t.node.id)){let i=t.get("init");if(!Array.isArray(i)&&(i.isArrowFunctionExpression()||i.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function Fe(e){return e.some(t=>n.isJSXElement(t)||n.isJSXFragment(t))}var ne=new WeakMap,k=new WeakMap,W=new WeakMap;function Oe(e){let t=ne.get(e.node);if(t!==void 0)return t;let i=[],r=e;for(;r;){if(r.isJSXElement()){let o=Ue(r);o&&i.unshift(o)}r=r.parentPath}let s=i.join("/");return ne.set(e.node,s),s}function Ue(e){let t=j(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${ie(e,t)}`:`${t}#${ie(e,t)}`}function ie(e,t){let i=fe(e)??e.getFunctionParent();if(!i)return 0;let r=W.get(i.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let s=W.get(i.node);s||(s=new Map,W.set(i.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let u=0,c=i.isJSXElement()||i.isJSXFragment()?B(i):$e(i);for(let g of c)if(j(g.node.openingElement.name)===t){if(o.set(g.node,u),g.node===e.node)return u;u+=1}return o.get(e.node)??0}function $e(e){let t=k.get(e.node);if(t)return t;let i=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!fe(r)&&i.push(r)}}),k.set(e.node,i),i}function fe(e){let t=e.parentPath,i=null;for(;t;){if(t.isJSXFragment()){i=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return i}function B(e){let t=k.get(e.node);if(t)return t;let i=[],r=e.get("children");for(let s of r)if(!Array.isArray(s)){if(s.isJSXElement()){i.push(s);continue}if(s.isJSXFragment()){i.push(...B(s));continue}s.isJSXExpressionContainer()&&i.push(...I(s.get("expression")))}return k.set(e.node,i),i}function I(e){return e.isJSXElement()?[e]:e.isJSXFragment()?B(e):e.isParenthesizedExpression()?I(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?I(e.get("right")):e.isConditionalExpression()?[...I(e.get("consequent")),...I(e.get("alternate"))]:e.isCallExpression()&&pe(e.node)?De(e.get("arguments")[0]):[]}function De(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return B(t);if(t.isParenthesizedExpression())return I(t.get("expression"));if(!t.isBlockStatement())return[];let i=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let o of r.get("declarations")){let u=o.get("init");(u.isJSXElement()||u.isJSXFragment())&&i.push(...I(u))}if(!r.isReturnStatement())continue;let s=r.get("argument");return s.node&&i.push(...I(s)),i}return i}function pe(e){return n.isMemberExpression(e.callee)&&n.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}Q.exports=Ie;Q.exports.instrumentSiteEditRuntimeAttributes=se});module.exports=me();
1
+ "use strict";var be=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ee=be((Qe,Q)=>{"use strict";var $=require("@babel/generator"),Se=require("@babel/parser"),W=require("@babel/traverse"),n=require("@babel/types"),H=require("node:fs"),b=require("node:path"),he=typeof $=="function"?$:$.default,q=typeof W=="function"?W:W.default,se={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},ye=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),xe="suppressHydrationWarning",ve=new Set(["SiteEditBootstrap"]),Z="data-vcp-source-location",Ie="data-vcp-ui-component",T="components/ui";function Ce(e,t){this.cacheable?.();let i=this.async();try{if(!we(this.resourcePath)){i(null,e,t);return}let r=this.getOptions?.()??{},s=oe({source:e,file:this.resourcePath,projectRoot:r.projectRoot,sourceLocations:r.sourceLocations===!0,cmsPreviewModulePath:r.cmsPreviewModulePath??Pe(r.projectRoot)});i(null,s.code,s.code===e?t:null)}catch(r){i(r)}}function Pe(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let i of[b.dirname(t),b.resolve(b.dirname(t),"../dist")]){let r=b.join(i,"cms-preview-record.js");if(H.existsSync(r)&&H.existsSync(b.join(i,"cms-preview-probe.js")))return r}return}catch{return}}function we(e){return typeof e=="string"&&/\.[jt]sx?$/.test(e)&&!e.replace(/\\/g,"/").includes("/node_modules/")&&!e.endsWith(".d.ts")}function oe(e){let t=Me(e.file,e.projectRoot),i=Xe(e.source)&&!/\.ts$/.test(t),r=e.cmsPreviewModulePath&&e.source.includes("@/lib/cms");if(!i&&!r||R(t))return{code:e.source,elements:[]};let s=e.attributes??se,o=Se.parse(e.source,{sourceType:"module",plugins:["typescript",.../\.ts$/.test(t)?[]:["jsx"]]}),u=[],c=Re(o,t);q(o,{JSXElement(E){let f=E.node.openingElement,d=f.name;if(!Be(d)||K(f,s.key)&&!e.sourceLocations)return;let y=_e(E)??"default",J=$e(E),I=Te(t,y,J),P=N(d)??"unknown",x=ue(d)?"jsx":"component-call";if(x==="component-call"&&!Ue(E.node.children)&&ve.has(P))return;let F=x==="component-call"&&ke(P,c);if(e.sourceLocations&&(f.attributes=f.attributes.filter(m=>!(n.isJSXAttribute(m)&&n.isJSXIdentifier(m.name)&&(m.name.name===s.key||m.name.name===Z))),f.loc)){let{start:m,end:a}=f.loc;ee(f,Z,encodeURIComponent(JSON.stringify({key:I,sourceFile:t,componentName:y,structuralPath:J,openingElementRange:{startLine:m.line,startColumn:m.column,endLine:a.line,endColumn:a.column}})))}ee(f,s.key,I),F&&te(f,Ie),je(E)&&te(f,xe),u.push({key:I,tag:P,component_name:y,source_file:t,source_kind:x})}});let g=e.cmsPreviewModulePath?Je(o,e.cmsPreviewModulePath,t,e.file,e.projectRoot):!1;return u.length===0&&!g?{code:e.source,elements:u}:{code:he(o,{jsescOption:{minimal:!0}}).code,elements:u}}function G(e,t,i){if(!b.isAbsolute(e))return e;let r=b.isAbsolute(t)?t:b.resolve(i||process.cwd(),t),s=b.relative(b.dirname(r),e).split(b.sep).join("/");return s.startsWith(".")?s:`./${s}`}function Je(e,t,i,r,s){let o;if(q(e,{Program(a){o=a,a.stop()}}),!o)return!1;let u=o.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),c=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListResult"),g=o.scope.generateUidIdentifier("vcpAttachCmsPreviewListView"),E=o.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),f=o.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),d=o.scope.generateUidIdentifier("VcpCmsPreviewProbe"),y=!1,J=!1,I=[],P=!1,x=!1,F=/(?:^|\/)(?:[^/]+-)?(?:list|detail)-view\.[jt]sx$/.test(i)||e.program.body.some(a=>n.isImportDeclaration(a)&&(a.source.value==="@/lib/cms"||/^@\/lib\/cms\/generated\//.test(a.source.value)));q(e,{CallExpression(a){let l=a.node,p=ce(a,l);if(p?.slug&&I.push({path:a,query:p}),n.isMemberExpression(l.callee)&&!l.callee.computed&&n.isIdentifier(l.callee.property,{name:"map"})&&l.arguments.length===1&&n.isIdentifier(l.arguments[0])){let w=Y(a,l.arguments[0].name),X=z(a,l.callee.object);if(w&&(!X||X.operation==="list"&&X.slug===w.slug)){let _=X?.operation==="list",U=a.scope.generateUidIdentifier("vcpCmsRecord");l.arguments[0]=n.arrowFunctionExpression([U],n.callExpression(_?u:g,[n.callExpression(n.cloneNode(l.arguments[0]),[n.cloneNode(U)]),n.cloneNode(U),n.stringLiteral(w.slug),..._?[n.stringLiteral("list")]:[]])),_?y=!0:J=!0,a.skip()}return}if(!n.isIdentifier(l.callee)||l.arguments.length!==1)return;let h=Y(a,l.callee.name),C=n.isIdentifier(l.arguments[0]),A=C?l.arguments[0].name:M(l.arguments[0],["data"]),L=A&&ae(a,A);if(!h||L?.operation!=="detail"||(C?L.slug!==h.slug:L.slug!==void 0))return;let j=n.cloneNode(l,!0),B=n.cloneNode(l.arguments[0],!0);a.replaceWith(n.callExpression(u,[j,B,n.stringLiteral(h.slug),n.stringLiteral("detail")])),y=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=n.callExpression(E,[a.node.argument]),P=!0},JSXElement:{exit(a){let l=a.node.openingElement;if(!K(l,se.key))return;let p=Ae(a);if(!p||!F&&a.scope.getBinding(p.base)?.kind!=="param")return;let h=l.attributes.findIndex(w=>n.isJSXAttribute(w)&&n.isJSXIdentifier(w.name,{name:"key"})),C=h<0?null:l.attributes.splice(h,1)[0],A=[n.identifier(p.base),n.stringLiteral(p.field)];p.index&&A.push(n.cloneNode(p.index,!0));let L=[...C?[C]:[],...ue(l.name)?[]:[n.jsxAttribute(n.jsxIdentifier("lookupHost"))],n.jsxAttribute(n.jsxIdentifier("candidate"),n.jsxExpressionContainer(n.callExpression(f,A)))],j=n.jsxIdentifier(d.name),B=n.jsxElement(n.jsxOpeningElement(n.cloneNode(j),L,!1),n.jsxClosingElement(n.cloneNode(j)),[a.node]);a.replaceWith(B),x=!0,a.skip()}}});let m=[];I.some(({query:a})=>a.operation==="list")&&m.push(n.importSpecifier(c,n.identifier("attachCmsPreviewListResult")));for(let{path:a,query:l}of I.reverse()){let p=a.scope.generateUidIdentifier("vcpCmsResult"),h=n.stringLiteral(l.slug),C=l.operation==="list"?n.callExpression(c,[p,h,n.booleanLiteral(l.strict)]):n.conditionalExpression(p,n.callExpression(u,[p,p,h,n.stringLiteral("detail")]),p);l.operation==="detail"&&(y=!0),a.replaceWith(n.callExpression(n.memberExpression(n.cloneNode(a.node,!0),n.identifier("then")),[n.arrowFunctionExpression([p],C)]))}return y&&m.push(n.importSpecifier(u,n.identifier("attachCmsPreviewRecord"))),J&&m.push(n.importSpecifier(g,n.identifier("attachCmsPreviewListView"))),P&&m.push(n.importSpecifier(E,n.identifier("stripCmsPreviewMetadata"))),x&&m.push(n.importSpecifier(f,n.identifier("readCmsPreviewCandidate"))),m.length&&e.program.body.unshift(n.importDeclaration(m,n.stringLiteral(G(t,r,s)))),x&&e.program.body.unshift(n.importDeclaration([n.importSpecifier(d,n.identifier("CmsPreviewProbe"))],n.stringLiteral(G(b.join(b.dirname(t),"cms-preview-probe.js"),r,s)))),m.length>0||x}function Ae(e){let t=e.node,i=t.openingElement.name,r=N(i);if(!r)return null;let s=new Map(t.openingElement.attributes.flatMap(d=>n.isJSXAttribute(d)&&n.isJSXIdentifier(d.name)&&n.isJSXExpressionContainer(d.value)&&n.isExpression(d.value.expression)?[[d.name.name,d.value.expression]]:[])),o=r==="img"||/^[A-Z]/.test(r)&&s.has("src"),u=s.get("dangerouslySetInnerHTML"),c=n.isObjectExpression(u)?u.properties.find(d=>n.isObjectProperty(d)&&!d.computed&&(n.isIdentifier(d.key,{name:"__html"})||n.isStringLiteral(d.key,{value:"__html"})))?.value:u,g=t.children.flatMap(d=>n.isJSXExpressionContainer(d)&&n.isExpression(d.expression)?[d.expression]:[]),E=o?[s.get("src")]:c?[c]:g.length?g:["src","href","alt","poster","content","title","aria-label","value","checked","dateTime"].flatMap(d=>s.has(d)?[s.get(d)]:[]);if(E.length!==1||!E[0])return null;let f=E[0];return S(f,e)??(o&&n.isIdentifier(f)&&e.scope.hasBinding(f.name)?{base:f.name,field:"url"}:g.length?Le(f,e):null)}function Le(e,t){if(!n.isIdentifier(e))return null;let i=t.scope.getBinding(e.name);if(i?.kind!=="param"||!i.constant)return null;let r=i.path.parentPath,s=r?.parentPath;if(!(r?.isArrowFunctionExpression()||r?.isFunctionExpression())||r.node.params[0]!==i.path.node||!s?.isCallExpression()||s.node.arguments[0]!==r.node||!ge(s.node)||s.node.callee.computed)return null;let o=S(s.node.callee.object,s);return o&&!o.index&&t.scope.getBinding(o.base)===s.scope.getBinding(o.base)?o:null}function S(e,t,i=0){if(i>=8)return null;if(n.isTemplateLiteral(e)&&e.expressions.length===1)return S(e.expressions[0],t,i+1);if(n.isCallExpression(e)&&n.isMemberExpression(e.callee)&&!e.callee.computed&&n.isMemberExpression(e.callee.object)&&!e.callee.object.computed&&n.isIdentifier(e.callee.object.property,{name:"field"})&&le(t,e.callee.object.object))return S(e.arguments[0],t,i+1);if(n.isCallExpression(e)&&n.isIdentifier(e.callee)&&e.arguments.length===1){let c=t.scope.getBinding(e.callee.name);if(c?.constant&&(c.path.isFunctionDeclaration()||c.path.isVariableDeclarator()&&n.isFunction(c.path.node.init)))return S(e.arguments[0],t,i+1)}if(n.isConditionalExpression(e)){let c=g=>n.isLiteral(g)&&!n.isTemplateLiteral(g);if(c(e.consequent)&&c(e.alternate))return S(e.test,t,i+1);if(c(e.alternate))return S(e.consequent,t,i+1);if(c(e.consequent))return S(e.alternate,t,i+1)}if(n.isLogicalExpression(e)&&(e.operator==="??"||e.operator==="||")&&n.isLiteral(e.right)&&!n.isTemplateLiteral(e.right))return S(e.left,t,i+1);if(n.isTSAsExpression(e)||n.isTSNonNullExpression(e)||n.isTSSatisfiesExpression(e))return S(e.expression,t,i+1);let r=e,s=[];for(;n.isMemberExpression(r)||n.isOptionalMemberExpression(r);){if(!r.computed&&n.isIdentifier(r.property))s.unshift({property:r.property.name});else if(r.computed&&n.isStringLiteral(r.property))s.unshift({property:r.property.value});else if(r.computed&&n.isNumericLiteral(r.property)&&Number.isSafeInteger(r.property.value)&&r.property.value>=0)s.unshift({index:r.property});else if(r.computed&&n.isIdentifier(r.property)&&t.scope.hasBinding(r.property.name))s.unshift({index:r.property});else return null;r=r.object}if(!n.isIdentifier(r))return null;let o=t.scope.getBinding(r.name);if(!o)return null;if(o.constant&&o.path.isVariableDeclarator()&&n.isIdentifier(o.path.node.id)){let c=S(o.path.node.init,o.path,i+1);if(c&&(s.length===0||c.index&&s[0]?.property==="url")&&t.scope.getBinding(c.base)===o.path.scope.getBinding(c.base)&&(!n.isIdentifier(c.index)||t.scope.getBinding(c.index.name)===o.path.scope.getBinding(c.index.name)))return c}if(s[0]?.property==="fields"&&s.shift(),!s[0]?.property||s.slice(2).some(c=>c.index))return null;let u=s[1];return{base:r.name,field:s[0].property,...u?.index?{index:u.index}:{}}}function Y(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isImportSpecifier())return null;let r=i.path.node;if(!n.isIdentifier(r.imported)||!/^to[A-Za-z0-9_$]+View$/.test(r.imported.name))return null;let s=i.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 M(e,t){let i=e;for(let r of[...t].reverse()){if(!n.isMemberExpression(i)||i.computed||!n.isIdentifier(i.property,{name:r}))return null;i=i.object}return n.isIdentifier(i)?i.name:null}function Ne(e){if(n.isConditionalExpression(e)){let t=M(e.consequent,["data","items"]);return!t||!n.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!n.isBinaryExpression(e.test,{operator:"==="})||M(e.test.left,["kind"])!==t||!n.isStringLiteral(e.test.right,{value:"ok"})?null:t}return M(e,["data","items"])}function z(e,t,i=new Set){let r=Ne(t);if(r)return ae(e,r);if(i.size>=20)return null;if(n.isIdentifier(t)){let s=e.scope.getBinding(t.name);return!s?.constant||!s.path.isVariableDeclarator()||!s.path.node.init||i.has(s)?null:(i.add(s),z(e,s.path.node.init,i))}return n.isCallExpression(t)&&n.isMemberExpression(t.callee)&&!t.callee.computed&&n.isIdentifier(t.callee.property)&&["filter","slice","sort","toSorted","reverse","toReversed"].includes(t.callee.property.name)?(i.add(t),z(e,t.callee.object,i)):null}function ae(e,t){let i=e.scope.getBinding(t);if(!i?.constant||!i.path.isVariableDeclarator())return null;let r=i.path.node.init,s=n.isAwaitExpression(r)?r.argument:null;return ce(e,s)}function ce(e,t){return!n.isCallExpression(t)||!n.isMemberExpression(t.callee)||t.callee.computed||!n.isIdentifier(t.callee.property)||!n.isMemberExpression(t.callee.object)||t.callee.object.computed||!n.isIdentifier(t.callee.object.property,{name:"collections"})||!n.isIdentifier(t.callee.object.object)||!le(e,t.callee.object.object)?null:["listStrict","list"].includes(t.callee.property.name)&&n.isStringLiteral(t.arguments[0])?{operation:"list",slug:t.arguments[0].value,strict:t.callee.property.name==="listStrict"}:t.callee.property.name==="getByUrlStrict"?{operation:"detail"}:t.callee.property.name==="get"&&n.isStringLiteral(t.arguments[0])?{operation:"detail",slug:t.arguments[0].value}:null}function le(e,t){if(!n.isIdentifier(t))return!1;let i=e.scope.getBinding(t.name);return i?.constant&&i.path.isImportSpecifier()&&n.isIdentifier(i.path.node.imported,{name:"cms"})&&i.path.parentPath.node.source.value==="@/lib/cms"}function je(e){return!e.findParent(t=>t.isJSXElement())}function Xe(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 Te(e,t,i){return`${e}::${t}::${i}`}function Me(e,t){let i=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&i.startsWith(`${r}/`))return i.slice(r.length+1);for(let[o,u]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let c=i.indexOf(o);if(c>=0)return i.slice(c+u)}return i.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??i}function ue(e){return n.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function N(e){return n.isJSXIdentifier(e)?e.name:n.isJSXMemberExpression(e)?fe(e):null}function Re(e,t){let i=new Set;for(let r of e.program.body)if(!(!n.isImportDeclaration(r)||!Oe(r.source.value,t)))for(let s of r.specifiers)i.add(s.local.name);return i}function ke(e,t){let i=e.split(".")[0]??e;return t.has(i)}function R(e){if(!e)return!1;let t=V(e);return t===T||t.startsWith(`${T}/`)||t.includes(`/${T}/`)||t.endsWith(`/${T}`)}function Oe(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?R(e.slice(2)):e.startsWith("./")||e.startsWith("../")?R(V(`${Fe(t)}/${e}`)):R(e):!1}function V(e){let i=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let s of i.split("/"))if(!(!s||s===".")){if(s===".."){r.pop();continue}r.push(s)}return r.join("/")}function Fe(e){let t=V(e),i=t.lastIndexOf("/");return i>=0?t.slice(0,i):""}function Be(e){let t=N(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ye.has(t)}function K(e,t){return e.attributes.some(i=>n.isJSXAttribute(i)&&n.isJSXIdentifier(i.name,{name:t}))}function ee(e,t,i){de(e,n.jsxAttribute(n.jsxIdentifier(t),n.stringLiteral(i)))}function te(e,t){K(e,t)||de(e,n.jsxAttribute(n.jsxIdentifier(t),null))}function de(e,t){let i=e.attributes.findIndex(r=>n.isJSXSpreadAttribute(r));if(i>=0){e.attributes.splice(i,0,t);return}e.attributes.push(t)}function fe(e){return`${n.isJSXIdentifier(e.object)?e.object.name:fe(e.object)}.${e.property.name}`}function _e(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&n.isIdentifier(t.node.id)){let i=t.get("init");if(!Array.isArray(i)&&(i.isArrowFunctionExpression()||i.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function Ue(e){return e.some(t=>n.isJSXElement(t)||n.isJSXFragment(t))}var ne=new WeakMap,k=new WeakMap,D=new WeakMap,ie=new WeakMap;function $e(e){let t=ne.get(e.node);if(t!==void 0)return t;let i=[],r=e;for(;r;){if(r.isJSXElement()){let o=We(r);o&&i.unshift(o)}r=r.parentPath}let s=i.join("/");return ne.set(e.node,s),s}function We(e){let t=N(e.node.openingElement.name);if(!t||t==="Fragment"||t.endsWith(".Fragment"))return null;let i=De(e),r=i?.prefix??"",s=i?.ordinal??qe(e,t);return`${r}${/^[A-Z]/.test(t)?"component:":""}${t}#${s}`}function De(e){let t=e.findParent(i=>i.isJSXOpeningElement()||i.isJSXElement()&&!me(i.node));if(t?.isJSXOpeningElement()){let i=re(t.node,e.node);if(i!==void 0)return{prefix:`prop:${i}/`,ordinal:0}}if(t?.isJSXElement()&&t.findParent(i=>i.isJSXOpeningElement())){let i=re(t.node,e.node);if(i!==void 0)return{prefix:"",ordinal:i}}}function re(e,t){let i=ie.get(e);if(!i){i=new WeakMap;let r=0;for(let s of n.isJSXOpeningElement(e)?e.attributes:e.children)n.traverseFast(s,o=>{if(n.isJSXElement(o)&&!me(o))return i.set(o,r++),n.traverseFast.skip});ie.set(e,i)}return i.get(t)}function me(e){let t=e.openingElement.name;return n.isJSXIdentifier(t,{name:"Fragment"})||n.isJSXMemberExpression(t)&&t.property.name==="Fragment"}function qe(e,t){let i=pe(e)??e.getFunctionParent();if(!i)return 0;let r=D.get(i.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let s=D.get(i.node);s||(s=new Map,D.set(i.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let u=0,c=i.isJSXElement()||i.isJSXFragment()?O(i):ze(i);for(let g of c)if(N(g.node.openingElement.name)===t){if(o.set(g.node,u),g.node===e.node)return u;u+=1}return o.get(e.node)??0}function ze(e){let t=k.get(e.node);if(t)return t;let i=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!pe(r)&&i.push(r)}}),k.set(e.node,i),i}function pe(e){let t=e.parentPath,i=null;for(;t;){if(t.isJSXFragment()){i=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return i}function O(e){let t=k.get(e.node);if(t)return t;let i=[],r=e.get("children");for(let s of r)if(!Array.isArray(s)){if(s.isJSXElement()){i.push(s);continue}if(s.isJSXFragment()){i.push(...O(s));continue}s.isJSXExpressionContainer()&&i.push(...v(s.get("expression")))}return k.set(e.node,i),i}function v(e){return e.isJSXElement()?[e]:e.isJSXFragment()?O(e):e.isParenthesizedExpression()?v(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?v(e.get("right")):e.isConditionalExpression()?[...v(e.get("consequent")),...v(e.get("alternate"))]:e.isCallExpression()&&ge(e.node)?Ve(e.get("arguments")[0]):[]}function Ve(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return O(t);if(t.isParenthesizedExpression())return v(t.get("expression"));if(!t.isBlockStatement())return[];let i=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let o of r.get("declarations")){let u=o.get("init");(u.isJSXElement()||u.isJSXFragment())&&i.push(...v(u))}if(!r.isReturnStatement())continue;let s=r.get("argument");return s.node&&i.push(...v(s)),i}return i}function ge(e){return n.isMemberExpression(e.callee)&&n.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}Q.exports=Ce;Q.exports.instrumentSiteEditRuntimeAttributes=oe});module.exports=Ee();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcp-dev/site-edit-engine",
3
- "version": "0.11.50",
3
+ "version": "0.11.51",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -57,7 +57,7 @@
57
57
  "@babel/types": "^7.29.0",
58
58
  "@csstools/css-tokenizer": "3.0.4",
59
59
  "@jridgewell/sourcemap-codec": "1.5.5",
60
- "@vcp-dev/platform-shared": "0.11.50",
60
+ "@vcp-dev/platform-shared": "0.11.51",
61
61
  "postcss": "8.5.23",
62
62
  "rollup": "npm:@rollup/wasm-node@4.60.4",
63
63
  "typescript": "5.9.3",