@vcp-dev/site-edit-engine 0.11.5 → 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.
package/README.md CHANGED
@@ -86,6 +86,8 @@ Next.js 插件平台,也不承诺覆盖 preview instrumentation 之外的构
86
86
  `site-edit-instrumentation-loader` 的兼容别名,不维护第二套转换逻辑;新接入建议优先使用
87
87
  bundler-neutral 子路径。
88
88
 
89
+ CMS 预览身份 helper 从已安装 Bridge 包中定位,注入的 import 必须相对于当前源文件,不能使用绝对磁盘路径(Turbopack 会将其当作不支持的 server-relative import)。同目录路径也保留 `./`,不能退化为裸模块名;该注入仍仅限开发预览。
90
+
89
91
  ## 内部职责边界
90
92
 
91
93
  内部组织遵循 [Site Edit 核心复杂度合同 #71](https://github.com/trojanbox/project-documents/issues/71),不改变公开入口、Bridge 协议、operation 或 History/Recovery 语义。
@@ -1 +1 @@
1
- "use strict";var M=require("@babel/generator"),Q=require("@babel/parser"),R=require("@babel/traverse"),r=require("@babel/types"),$=require("node:fs"),S=require("node:path"),G=typeof M=="function"?M:M.default,L=typeof R=="function"?R:R.default,q={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags"},Y=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]);var ee="suppressHydrationWarning",te=new Set(["SiteEditBootstrap"]),ne="data-vcp-ui-component",P="components/ui";function re(e,t){this.cacheable?.();let n=this.async();try{if(!se(this.resourcePath)){n(null,e,t);return}let i=this.getOptions?.()??{},s=K({source:e,file:this.resourcePath,projectRoot:i.projectRoot,cmsPreviewModulePath:ie(i.projectRoot)});n(null,s.code,s.code===e?t:null)}catch(i){n(i)}}function ie(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let n of[S.dirname(t),S.resolve(S.dirname(t),"../dist")]){let i=S.join(n,"cms-preview-record.js");if($.existsSync(i)&&$.existsSync(S.join(n,"cms-preview-probe.js")))return i}return}catch{return}}function se(e){return typeof e=="string"&&/\.(jsx|tsx)$/.test(e)&&!e.includes("/node_modules/")&&!e.endsWith(".d.ts")}function K(e){let t=fe(e.file,e.projectRoot);if(!de(e.source)||J(t))return{code:e.source,elements:[]};let n=e.attributes??q,i=Q.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),s=[],o=ge(i,t);L(i,{JSXElement(l){let u=l.node.openingElement,g=u.name;if(!he(g)||F(u,n.key))return;let E=ye(l)??"default",X=ve(l),f=pe(t,E,X),a=v(g)??"unknown",c=me(g)?"jsx":"component-call";if(c==="component-call"&&!Ie(l.node.children)&&te.has(a))return;let p=c==="component-call"&&Ee(a,o);xe(u,n.key,f),p&&W(u,ne),le(l)&&W(u,ee),s.push({key:f,tag:a,component_name:E,source_file:t,source_kind:c})}});let d=e.cmsPreviewModulePath?oe(i,e.cmsPreviewModulePath,t):!1;return s.length===0&&!d?{code:e.source,elements:s}:{code:G(i,{jsescOption:{minimal:!0}}).code,elements:s}}function oe(e,t,n){let i;if(L(e,{Program(a){i=a,a.stop()}}),!i)return!1;let s=i.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),o=i.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),d=i.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),l=i.scope.generateUidIdentifier("VcpCmsPreviewProbe"),u=!1,g=!1,E=!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)));L(e,{CallExpression(a){let c=a.node;if(r.isMemberExpression(c.callee)&&!c.callee.computed&&r.isIdentifier(c.callee.property,{name:"map"})&&c.arguments.length===1&&r.isIdentifier(c.arguments[0])){let y=B(a,c.arguments[0].name),I=ue(c.callee.object),O=I&&U(a,I);if(y&&O?.operation==="list"&&O.slug===y.slug){let T=a.scope.generateUidIdentifier("vcpCmsRecord");c.arguments[0]=r.arrowFunctionExpression([T],r.callExpression(s,[r.callExpression(r.cloneNode(c.arguments[0]),[r.cloneNode(T)]),r.cloneNode(T),r.stringLiteral(y.slug),r.stringLiteral("list")])),u=!0,a.skip()}return}if(!r.isIdentifier(c.callee)||c.arguments.length!==1)return;let p=B(a,c.callee.name),h=r.isIdentifier(c.arguments[0]),x=h?c.arguments[0].name:w(c.arguments[0],["data"]),b=x&&U(a,x);if(!p||b?.operation!=="detail"||(h?b.slug!==p.slug:b.slug!==void 0))return;let j=r.cloneNode(c,!0),C=r.cloneNode(c.arguments[0],!0);a.replaceWith(r.callExpression(s,[j,C,r.stringLiteral(p.slug),r.stringLiteral("detail")])),u=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=r.callExpression(o,[a.node.argument]),g=!0},JSXElement:{exit(a){if(!X)return;let c=a.node.openingElement;if(!F(c,q.key))return;let p=ae(a);if(!p)return;let h=c.attributes.findIndex(I=>r.isJSXAttribute(I)&&r.isJSXIdentifier(I.name,{name:"key"})),x=h<0?null:c.attributes.splice(h,1)[0],b=[r.identifier(p.base),r.stringLiteral(p.field)];p.index&&b.push(r.cloneNode(p.index,!0));let j=[...x?[x]:[],r.jsxAttribute(r.jsxIdentifier("candidate"),r.jsxExpressionContainer(r.callExpression(d,b)))],C=r.jsxIdentifier(l.name),y=r.jsxElement(r.jsxOpeningElement(r.cloneNode(C),j,!1),r.jsxClosingElement(r.cloneNode(C)),[a.node]);a.replaceWith(y),E=!0,a.skip()}}});let f=[];return u&&f.push(r.importSpecifier(s,r.identifier("attachCmsPreviewRecord"))),g&&f.push(r.importSpecifier(o,r.identifier("stripCmsPreviewMetadata"))),E&&f.push(r.importSpecifier(d,r.identifier("readCmsPreviewCandidate"))),f.length&&e.program.body.unshift(r.importDeclaration(f,r.stringLiteral(t))),E&&e.program.body.unshift(r.importDeclaration([r.importSpecifier(l,r.identifier("CmsPreviewProbe"))],r.stringLiteral(S.join(S.dirname(t),"cms-preview-probe.js")))),f.length>0||E}function ae(e){let t=e.node,n=t.openingElement.name,i=v(n);if(!i)return null;let s=t.openingElement.attributes.find(u=>r.isJSXAttribute(u)&&r.isJSXIdentifier(u.name,{name:"src"})),o=t.openingElement.attributes.find(u=>r.isJSXAttribute(u)&&r.isJSXIdentifier(u.name,{name:"dangerouslySetInnerHTML"})),d=i==="img"||/^[A-Z]/.test(i)&&s,l=d?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(u=>r.isJSXExpressionContainer(u)&&r.isExpression(u.expression)?[u.expression]:[]);return l.length!==1?null:d&&r.isIdentifier(l[0])&&e.scope.hasBinding(l[0].name)?{base:l[0].name,field:"url"}:ce(l[0],e)}function ce(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 B(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 w(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 ue(e){if(r.isConditionalExpression(e)){let t=w(e.consequent,["data","items"]);return!t||!r.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!r.isBinaryExpression(e.test,{operator:"==="})||w(e.test.left,["kind"])!==t||!r.isStringLiteral(e.test.right,{value:"ok"})?null:t}return w(e,["data","items"])}function U(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 le(e){return!e.findParent(t=>t.isJSXElement())}function de(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 pe(e,t,n){return`${e}::${t}::${n}`}function fe(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,d]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let l=n.indexOf(o);if(l>=0)return n.slice(l+d)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function me(e){return r.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function v(e){return r.isJSXIdentifier(e)?e.name:r.isJSXMemberExpression(e)?Z(e):null}function ge(e,t){let n=new Set;for(let i of e.program.body)if(!(!r.isImportDeclaration(i)||!Se(i.source.value,t)))for(let s of i.specifiers)n.add(s.local.name);return n}function Ee(e,t){let n=e.split(".")[0]??e;return t.has(n)}function J(e){if(!e)return!1;let t=_(e);return t===P||t.startsWith(`${P}/`)||t.includes(`/${P}/`)||t.endsWith(`/${P}`)}function Se(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?J(e.slice(2)):e.startsWith("./")||e.startsWith("../")?J(_(`${be(t)}/${e}`)):J(e):!1}function _(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 be(e){let t=_(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function he(e){let t=v(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!Y.has(t)}function F(e,t){return e.attributes.some(n=>r.isJSXAttribute(n)&&r.isJSXIdentifier(n.name,{name:t}))}function xe(e,t,n){V(e,r.jsxAttribute(r.jsxIdentifier(t),r.stringLiteral(n)))}function W(e,t){F(e,t)||V(e,r.jsxAttribute(r.jsxIdentifier(t),null))}function V(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 Z(e){return`${r.isJSXIdentifier(e.object)?e.object.name:Z(e.object)}.${e.property.name}`}function ye(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 Ie(e){return e.some(t=>r.isJSXElement(t)||r.isJSXFragment(t))}var D=new WeakMap,A=new WeakMap,k=new WeakMap;function ve(e){let t=D.get(e.node);if(t!==void 0)return t;let n=[],i=e;for(;i;){if(i.isJSXElement()){let o=Ce(i);o&&n.unshift(o)}i=i.parentPath}let s=n.join("/");return D.set(e.node,s),s}function Ce(e){let t=v(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=H(e)??e.getFunctionParent();if(!n)return 0;let i=k.get(n.node)?.get(t)?.get(e.node);if(i!==void 0)return i;let s=k.get(n.node);s||(s=new Map,k.set(n.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let d=0,l=n.isJSXElement()||n.isJSXFragment()?N(n):Pe(n);for(let u of l)if(v(u.node.openingElement.name)===t){if(o.set(u.node,d),u.node===e.node)return d;d+=1}return o.get(e.node)??0}function Pe(e){let t=A.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(i){i.getFunctionParent()?.node===e.node&&!H(i)&&n.push(i)}}),A.set(e.node,n),n}function H(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 N(e){let t=A.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(...N(s));continue}s.isJSXExpressionContainer()&&n.push(...m(s.get("expression")))}return A.set(e.node,n),n}function m(e){return e.isJSXElement()?[e]:e.isJSXFragment()?N(e):e.isParenthesizedExpression()?m(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?m(e.get("right")):e.isConditionalExpression()?[...m(e.get("consequent")),...m(e.get("alternate"))]:e.isCallExpression()&&Je(e.node)?we(e.get("arguments")[0]):[]}function we(e){if(!e?.isArrowFunctionExpression()&&!e?.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return N(t);if(t.isParenthesizedExpression())return m(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 d=o.get("init");(d.isJSXElement()||d.isJSXFragment())&&n.push(...m(d))}if(!i.isReturnStatement())continue;let s=i.get("argument");return s.node&&n.push(...m(s)),n}return n}function Je(e){return r.isMemberExpression(e.callee)&&r.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}module.exports=re;module.exports.instrumentSiteEditRuntimeAttributes=K;
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 Y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var G=Y((Te,O)=>{"use strict";var M=require("@babel/generator"),ee=require("@babel/parser"),R=require("@babel/traverse"),r=require("@babel/types"),B=require("node:fs"),S=require("node:path"),te=typeof M=="function"?M:M.default,L=typeof R=="function"?R:R.default,K={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"]),re="suppressHydrationWarning",ie=new Set(["SiteEditBootstrap"]),se="data-vcp-ui-component",P="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=V({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[S.dirname(t),S.resolve(S.dirname(t),"../dist")]){let i=S.join(n,"cms-preview-record.js");if(B.existsSync(i)&&B.existsSync(S.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 V(e){let t=Ee(e.file,e.projectRoot);if(!me(e.source)||J(t))return{code:e.source,elements:[]};let n=e.attributes??K,i=ee.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),s=[],o=be(i,t);L(i,{JSXElement(l){let u=l.node.openingElement,g=u.name;if(!Ie(g)||F(u,n.key))return;let E=Ce(l)??"default",X=we(l),f=ge(t,E,X),a=v(g)??"unknown",c=Se(g)?"jsx":"component-call";if(c==="component-call"&&!Pe(l.node.children)&&ie.has(a))return;let p=c==="component-call"&&he(a,o);ve(u,n.key,f),p&&D(u,se),fe(l)&&D(u,re),s.push({key:f,tag:a,component_name:E,source_file:t,source_kind:c})}});let d=e.cmsPreviewModulePath?ue(i,e.cmsPreviewModulePath,t):!1;return s.length===0&&!d?{code:e.source,elements:s}:{code:te(i,{jsescOption:{minimal:!0}}).code,elements:s}}function ue(e,t,n){let i;if(L(e,{Program(a){i=a,a.stop()}}),!i)return!1;let s=i.scope.generateUidIdentifier("vcpAttachCmsPreviewRecord"),o=i.scope.generateUidIdentifier("vcpStripCmsPreviewMetadata"),d=i.scope.generateUidIdentifier("vcpReadCmsPreviewCandidate"),l=i.scope.generateUidIdentifier("VcpCmsPreviewProbe"),u=!1,g=!1,E=!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)));L(e,{CallExpression(a){let c=a.node;if(r.isMemberExpression(c.callee)&&!c.callee.computed&&r.isIdentifier(c.callee.property,{name:"map"})&&c.arguments.length===1&&r.isIdentifier(c.arguments[0])){let y=U(a,c.arguments[0].name),I=pe(c.callee.object),$=I&&W(a,I);if(y&&$?.operation==="list"&&$.slug===y.slug){let T=a.scope.generateUidIdentifier("vcpCmsRecord");c.arguments[0]=r.arrowFunctionExpression([T],r.callExpression(s,[r.callExpression(r.cloneNode(c.arguments[0]),[r.cloneNode(T)]),r.cloneNode(T),r.stringLiteral(y.slug),r.stringLiteral("list")])),u=!0,a.skip()}return}if(!r.isIdentifier(c.callee)||c.arguments.length!==1)return;let p=U(a,c.callee.name),h=r.isIdentifier(c.arguments[0]),x=h?c.arguments[0].name:w(c.arguments[0],["data"]),b=x&&W(a,x);if(!p||b?.operation!=="detail"||(h?b.slug!==p.slug:b.slug!==void 0))return;let j=r.cloneNode(c,!0),C=r.cloneNode(c.arguments[0],!0);a.replaceWith(r.callExpression(s,[j,C,r.stringLiteral(p.slug),r.stringLiteral("detail")])),u=!0,a.skip()},JSXSpreadAttribute(a){a.node.argument=r.callExpression(o,[a.node.argument]),g=!0},JSXElement:{exit(a){if(!X)return;let c=a.node.openingElement;if(!F(c,K.key))return;let p=le(a);if(!p)return;let h=c.attributes.findIndex(I=>r.isJSXAttribute(I)&&r.isJSXIdentifier(I.name,{name:"key"})),x=h<0?null:c.attributes.splice(h,1)[0],b=[r.identifier(p.base),r.stringLiteral(p.field)];p.index&&b.push(r.cloneNode(p.index,!0));let j=[...x?[x]:[],r.jsxAttribute(r.jsxIdentifier("candidate"),r.jsxExpressionContainer(r.callExpression(d,b)))],C=r.jsxIdentifier(l.name),y=r.jsxElement(r.jsxOpeningElement(r.cloneNode(C),j,!1),r.jsxClosingElement(r.cloneNode(C)),[a.node]);a.replaceWith(y),E=!0,a.skip()}}});let f=[];return u&&f.push(r.importSpecifier(s,r.identifier("attachCmsPreviewRecord"))),g&&f.push(r.importSpecifier(o,r.identifier("stripCmsPreviewMetadata"))),E&&f.push(r.importSpecifier(d,r.identifier("readCmsPreviewCandidate"))),f.length&&e.program.body.unshift(r.importDeclaration(f,r.stringLiteral(t))),E&&e.program.body.unshift(r.importDeclaration([r.importSpecifier(l,r.identifier("CmsPreviewProbe"))],r.stringLiteral(S.join(S.dirname(t),"cms-preview-probe.js")))),f.length>0||E}function le(e){let t=e.node,n=t.openingElement.name,i=v(n);if(!i)return null;let s=t.openingElement.attributes.find(u=>r.isJSXAttribute(u)&&r.isJSXIdentifier(u.name,{name:"src"})),o=t.openingElement.attributes.find(u=>r.isJSXAttribute(u)&&r.isJSXIdentifier(u.name,{name:"dangerouslySetInnerHTML"})),d=i==="img"||/^[A-Z]/.test(i)&&s,l=d?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(u=>r.isJSXExpressionContainer(u)&&r.isExpression(u.expression)?[u.expression]:[]);return l.length!==1?null:d&&r.isIdentifier(l[0])&&e.scope.hasBinding(l[0].name)?{base:l[0].name,field:"url"}:de(l[0],e)}function de(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 U(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 w(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 pe(e){if(r.isConditionalExpression(e)){let t=w(e.consequent,["data","items"]);return!t||!r.isArrayExpression(e.alternate)||e.alternate.elements.length!==0||!r.isBinaryExpression(e.test,{operator:"==="})||w(e.test.left,["kind"])!==t||!r.isStringLiteral(e.test.right,{value:"ok"})?null:t}return w(e,["data","items"])}function W(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,d]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let l=n.indexOf(o);if(l>=0)return n.slice(l+d)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function Se(e){return r.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function v(e){return r.isJSXIdentifier(e)?e.name:r.isJSXMemberExpression(e)?H(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 J(e){if(!e)return!1;let t=_(e);return t===P||t.startsWith(`${P}/`)||t.includes(`/${P}/`)||t.endsWith(`/${P}`)}function xe(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?J(e.slice(2)):e.startsWith("./")||e.startsWith("../")?J(_(`${ye(t)}/${e}`)):J(e):!1}function _(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=_(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function Ie(e){let t=v(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ne.has(t)}function F(e,t){return e.attributes.some(n=>r.isJSXAttribute(n)&&r.isJSXIdentifier(n.name,{name:t}))}function ve(e,t,n){Z(e,r.jsxAttribute(r.jsxIdentifier(t),r.stringLiteral(n)))}function D(e,t){F(e,t)||Z(e,r.jsxAttribute(r.jsxIdentifier(t),null))}function Z(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 H(e){return`${r.isJSXIdentifier(e.object)?e.object.name:H(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 q=new WeakMap,A=new WeakMap,k=new WeakMap;function we(e){let t=q.get(e.node);if(t!==void 0)return t;let n=[],i=e;for(;i;){if(i.isJSXElement()){let o=Je(i);o&&n.unshift(o)}i=i.parentPath}let s=n.join("/");return q.set(e.node,s),s}function Je(e){let t=v(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=Q(e)??e.getFunctionParent();if(!n)return 0;let i=k.get(n.node)?.get(t)?.get(e.node);if(i!==void 0)return i;let s=k.get(n.node);s||(s=new Map,k.set(n.node,s));let o=s.get(t);o||(o=new WeakMap,s.set(t,o));let d=0,l=n.isJSXElement()||n.isJSXFragment()?N(n):Ae(n);for(let u of l)if(v(u.node.openingElement.name)===t){if(o.set(u.node,d),u.node===e.node)return d;d+=1}return o.get(e.node)??0}function Ae(e){let t=A.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(i){i.getFunctionParent()?.node===e.node&&!Q(i)&&n.push(i)}}),A.set(e.node,n),n}function Q(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 N(e){let t=A.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(...N(s));continue}s.isJSXExpressionContainer()&&n.push(...m(s.get("expression")))}return A.set(e.node,n),n}function m(e){return e.isJSXElement()?[e]:e.isJSXFragment()?N(e):e.isParenthesizedExpression()?m(e.get("expression")):e.isLogicalExpression()&&e.node.operator==="&&"?m(e.get("right")):e.isConditionalExpression()?[...m(e.get("consequent")),...m(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 N(t);if(t.isParenthesizedExpression())return m(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 d=o.get("init");(d.isJSXElement()||d.isJSXFragment())&&n.push(...m(d))}if(!i.isReturnStatement())continue;let s=i.get("argument");return s.node&&n.push(...m(s)),n}return n}function Xe(e){return r.isMemberExpression(e.callee)&&r.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}O.exports=oe;O.exports.instrumentSiteEditRuntimeAttributes=V});module.exports=G();
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.5",
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.5",
63
+ "@vcp-dev/contracts": "0.11.6",
64
64
  "yaml": "^2.9.0"
65
65
  },
66
66
  "devDependencies": {