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