@vcp-dev/site-edit-engine 0.11.48 → 0.11.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=require("@babel/generator"),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;
|
|
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:r.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;
|
|
@@ -12,7 +12,11 @@ declare function siteEditInstrumentationLoader(
|
|
|
12
12
|
inputSourceMap?: unknown,
|
|
13
13
|
) => void;
|
|
14
14
|
resourcePath?: string;
|
|
15
|
-
getOptions?: () => {
|
|
15
|
+
getOptions?: () => {
|
|
16
|
+
projectRoot?: string;
|
|
17
|
+
sourceLocations?: boolean;
|
|
18
|
+
cmsPreviewModulePath?: string;
|
|
19
|
+
};
|
|
16
20
|
},
|
|
17
21
|
source: string,
|
|
18
22
|
inputSourceMap?: unknown,
|
package/dist/webpack-loader.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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();
|
|
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:r.cmsPreviewModulePath??ve(r.projectRoot)});i(null,s.code,s.code===e?t:null)}catch(r){i(r)}}function ve(e){try{let t=require.resolve("@vcp-dev/site-edit-bridge/auto-bootstrap",{paths:[e||process.cwd()]});for(let i of[b.dirname(t),b.resolve(b.dirname(t),"../dist")]){let r=b.join(i,"cms-preview-record.js");if(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.49",
|
|
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.49",
|
|
61
61
|
"postcss": "8.5.23",
|
|
62
62
|
"rollup": "npm:@rollup/wasm-node@4.60.4",
|
|
63
63
|
"typescript": "5.9.3",
|