@uniformdev/uniform-mcp 20.25.2-alpha.3 → 20.26.1-alpha.0

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -5174,7 +5174,7 @@ to {
5174
5174
  &:before {
5175
5175
  background: var(--error);
5176
5176
  }
5177
- `;await er();function VSe(t){let e=_le({nodes:[pd,fd,cZ,X1,Q1,Tae,gfe,hfe,vfe,Mf]});return e.update(()=>{Eae("skip-dom-selection"),Sde(t,Nde)},{discrete:!0}),e.getEditorState().toJSON()}function HSe({twee:t,nodeId:e,propertyId:n,propertyType:r,locale:o,propertyEdit:i,conditionIndex:a=-1}){let l=t.getNodeById(e);if(!l)throw new Error(`Node with ID ${e} not found`);if(i.action==="clearValue")t.updateNodeProperty({nodeId:e,property:n,value:null,source:"ai",locale:o,conditionIndex:-1});else if(i.action==="resetOverride")t.resetPatternPropertyOverride(e,n,o);else if(i.action==="setValue"){let c=gnt({twee:t,targetNode:l,propertyId:n,propertyType:r,propertyEdit:i}),d=t.getNodeProperty(e,n);if(!o&&d?.locales)throw new Error(`The ${n} property is localized in ${Object.keys(d.locales).join(", ")}, but no locale was provided when setting its value. Please provide an explicit locale.`);t.updateNodeProperty({nodeId:e,property:n,value:()=>c,source:"ai",locale:o,conditionIndex:a,type:r})}}var gnt=({twee:t,targetNode:e,propertyId:n,propertyType:r,propertyEdit:o})=>{if(r==="richText")return VSe(o.newValue??"");if(r==="number")return Number(o.newValue);if(n===pnt){if(hnt(e.value.type))throw new Error("Enrichment tags are not allowed in system components.");if(t.getParentInfo(e.nodeId)?.parentId===mnt)throw new Error("Enrichment tags are not allowed in personalization variants.")}return o.treatNewValueAsJson?JSON.parse(o.newValue):o.newValue};async function DL({twee:t,slotUpdates:e,propertyUpdates:n,localeUpdates:r,nameUpdate:o,slugUpdate:i,descriptionUpdate:a,currentEditorLocale:l,referenceData:c}){let d=[];o&&(t.updateRootNode({update:{_name:o}}),d.push({summary:"Updated name",success:!0})),i&&(t.updateRootNode({update:{_slug:i}}),d.push({summary:"Updated slug",success:!0})),a&&(t.updateRootMetadata({description:a}),d.push({summary:"Updated description",success:!0}));let f=await c.fetchDefinitions();await ynt({slotUpdates:e,twee:t,definitions:f,referenceData:c,results:d});let m=d.some(h=>!h.success);return e.deletedComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped deleting component ${h} because previous actions failed`,success:!1}):(t.deleteNode(h,!1),d.push({summary:`Deleted component ${h}`,success:!0}))}),m=d.some(h=>!h.success),e.moveComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped moving component ${h.componentId} because previous actions failed`,success:!1}):(t.moveNode({movedNodeId:h.componentId,parentNodeId:h.newParentComponentId,parentSlot:h.newSlotName,targetIndexInSlot:h.newSlotIndex}),d.push({summary:`Moved component ${h.componentId} to ${h.newParentComponentId} in slot ${h.newSlotName} at index ${h.newSlotIndex}`,success:!0}))}),m=d.some(h=>!h.success),e.duplicateComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped duplicating component ${h} because previous actions failed`,success:!1}):(t.duplicateNode(h,c.resolvePatternData),d.push({summary:`Duplicated component ${h}`,success:!0}))}),m=d.some(h=>!h.success),r?.enableLocales?.forEach(h=>{m?d.push({summary:`Skipped enabling locale ${h} because previous actions failed`,success:!1}):(t.enableLocale(h),d.push({summary:`Enabled locale ${h}`,success:!0}))}),m=d.some(h=>!h.success),r?.disableLocales?.forEach(h=>{m?d.push({summary:`Skipped disabling locale ${h} because previous actions failed`,success:!1}):(t.disableLocale(h),d.push({summary:`Disabled locale ${h}`,success:!0}))}),m=d.some(h=>!h.success),m?n.length>0&&d.push({summary:`Skipped ${n.length} property updates because previous actions failed`,success:!1}):(await bnt({propertyUpdates:n,twee:t,currentEditorLocale:l,referenceData:c,definitions:f,results:d})).forEach(v=>{if(!v.result.success)return;let y="componentId"in v.update?v.update.componentId:t.rootNodeId,b=Ute({twee:t,nodeId:y,currentEditorLocale:v.currentLocale,definition:v.propertyDefinition}),w=(t.getNodeById(t.rootNodeId)?.value)._locales??[];if(b&&!w.includes(b)){d.push({summary:`The ${b} locale is not enabled on this entity. Please enable it before setting values in this locale.`,success:!1});return}if(v.result.action!=="nothing")try{HSe({twee:t,nodeId:y,propertyId:v.propertyDefinition.id,propertyType:v.propertyDefinition.type,locale:b,propertyEdit:v.result}),d.push({summary:`Updated value of ${v.propertyDefinition.id} on ${y}${b?` in ${b}`:""}`,success:!0})}catch(C){d.push({summary:`Failed to update value of ${v.propertyDefinition.id} on ${y}${b?` in ${b}`:""}: ${C instanceof Error?C.message:"Unknown error"}`,success:!1})}if("overridable"in v.update&&v.update.overridable!==void 0){let C=v.update.overridable;t.updateNode({nodeId:y,updateComponent:S=>{S._overridability??={},S._overridability.parameters??={},S._overridability.parameters[v.propertyDefinition.id]=C}}),d.push({summary:`Updated overridability for ${y}`,success:!0})}}),d}async function ynt({slotUpdates:t,twee:e,definitions:n,referenceData:r,results:o}){(await Promise.allSettled(t.newComponentsInSlots?.map(async a=>{let l=e.getNodeById(a.parentComponentId);if(!l)throw new Error(`Parent component with ID ${a.parentComponentId} not found`);let c=n[l.value.type];if(!c)throw new Error(`Definition for parent component type ${l.value.type} not found`);let d=c.slots?.find(h=>h.id===a.slotName);if(!d)throw new Error(`Slot ${a.slotName} not found on component type ${l.value.type}`);let f=_k({twee:e,parentSlotDefinition:d,nodeId:a.parentComponentId,componentDefinitionsIndex:n});if(!f)throw new Error(`Can't find allowed components inherited slot for ${a.slotName}`);let m=Hte(f);if(a.instanceType==="component"){if(!a.componentType)throw new Error("componentType is required when inserting a component instance");if(!Tk({type:a.componentType},m,!1))throw new Error(`Component type ${a.componentType} is not allowed in slot ${a.slotName}`);e.insertNode({node:{type:a.componentType},overrideNodeId:a.newComponentInstanceUuid,parentNodeId:a.parentComponentId,parentSlot:a.slotName,targetIndexInSlot:a.slotIndex}),o.push({summary:`Inserted component ${a.componentType} in slot ${a.slotName} ${a.slotIndex!==void 0?`at index ${a.slotIndex}`:""}`,success:!0})}else{if(!a.componentPatternId)throw new Error("componentPatternId is required when inserting a component pattern instance");let h=await r.resolvePatternData(a.componentPatternId);if(!h)throw new Error(`Pattern definition with ID ${a.componentPatternId} not found`);if(!Tk({type:h.type,_pattern:a.componentPatternId},m,!1))throw new Error(`Pattern ${a.componentPatternId} is not allowed in slot ${a.slotName}`);e.insertPattern({pattern:h,patternInstanceId:a.newComponentInstanceUuid,parentNodeId:a.parentComponentId,parentSlot:a.slotName,targetIndexInSlot:a.slotIndex}),o.push({summary:`Inserted pattern ${h._name} in slot ${a.slotName} ${a.slotIndex!==void 0?`at index ${a.slotIndex}`:""}`,success:!0})}})??[])).forEach((a,l)=>{if(a.status==="rejected"){let c=t.newComponentsInSlots?.[l];console.error("Error inserting component",a.reason),o.push({summary:`Failed to insert component ${c?.newComponentInstanceUuid}: ${"message"in a.reason?a.reason.message:"Unknown error"}`,success:!1})}})}async function bnt({propertyUpdates:t,twee:e,currentEditorLocale:n,referenceData:r,definitions:o,results:i}){if(t.length===0)return[];let[a,l]=await Promise.all([r.fetchProjectGuidance(),r.getToolClient()]),c=await Promise.allSettled(t.map(async d=>(async()=>{let f="componentId"in d?d.componentId:e.rootNodeId,m=e.getNodeById(f);if(!m)throw new Error(`Component instance with ID ${f} not found`);let h=o[m.value.type];if(!h)throw new Error(`Definition with ID ${m.value.type} not found`);let v="fieldId"in d?d.fieldId:d.parameterId,y=h.parameters?.find(E=>E.id===v),b=d.locale??n,w=y??{id:v,type:"unknown"};if(d.editInstructions===void 0)return{result:{success:!0,newValue:"",treatNewValueAsJson:!1,action:"nothing"},update:d,propertyDefinition:w};if(d.editInstructions==="")return{result:{success:!0,newValue:"",treatNewValueAsJson:!1,action:"clearValue"},update:d,propertyDefinition:w};if(!y)throw new Error(`Property with ID ${v} not found`);let C=vnt({property:e.getNodeProperty(f,v),locale:b,conditionIndex:-1}),S=await l.invoke("createPropertyEdit",{edit:d.editInstructions,propertyDefinition:{id:v,name:y.name,type:y.type,guidance:y.guidance,typeConfig:y.typeConfig},outputLocale:b,documentContext:void 0,currentValue:C,projectGuidance:a,componentGuidance:h.description});if(!S.success)throw new Error(S.summary??"Failed to edit property");return{result:S,update:d,propertyDefinition:y,currentLocale:b}})()));return c.forEach((d,f)=>{if(d.status==="rejected"){let m=t[f],h="fieldId"in m?m.fieldId:m.parameterId;i.push({summary:`Failed to edit property ${h}: ${"message"in d.reason?d.reason.message:"Unknown error"}`,success:!1})}}),c.filter(d=>d.status==="fulfilled").map(d=>d.value)}import{CANVAS_BLOCK_PARAM_TYPE as Sc,CANVAS_ENRICHMENT_TAG_PARAM as $4e,CANVAS_LOCALE_TAG_PARAM as JE,CANVAS_LOCALIZATION_SLOT as $Z,CANVAS_LOCALIZATION_TYPE as xrt,CANVAS_PERSONALIZATION_PARAM as XE,CANVAS_PERSONALIZE_SLOT as N4e,CANVAS_SLOT_SECTION_SLOT as Crt,CANVAS_SLOT_SECTION_TYPE as NZ,CANVAS_TEST_SLOT as L4e,CANVAS_TEST_VARIANT_PARAM as M4e,CANVAS_VIZ_CONTROL_PARAM as u0,convertToBindExpression as Srt,createVariableReference as wrt,getEffectivePropertyValue as O4e,walkNodeTree as c0}from"@uniformdev/canvas";var jSe=Object.prototype.hasOwnProperty;function YE(t,e){var n,r;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((r=t.length)===e.length)for(;r--&&YE(t[r],e[r]););return r===-1}if(!n||typeof t=="object"){r=0;for(n in t)if(jSe.call(t,n)&&++r&&!jSe.call(e,n)||!(n in e)||!YE(t[n],e[n]))return!1;return Object.keys(e).length===r}}return t!==t&&e!==e}var d0=J(mZ(),1),A4e=J(YSe(),1);import{produce as To}from"immer";import Tnt from"crypto";var NL=new Uint8Array(256),$L=NL.length;function hZ(){return $L>NL.length-16&&(Tnt.randomFillSync(NL),$L=0),NL.slice($L,$L+=16)}var ua=[];for(let t=0;t<256;++t)ua.push((t+256).toString(16).slice(1));function ZSe(t,e=0){return ua[t[e+0]]+ua[t[e+1]]+ua[t[e+2]]+ua[t[e+3]]+"-"+ua[t[e+4]]+ua[t[e+5]]+"-"+ua[t[e+6]]+ua[t[e+7]]+"-"+ua[t[e+8]]+ua[t[e+9]]+"-"+ua[t[e+10]]+ua[t[e+11]]+ua[t[e+12]]+ua[t[e+13]]+ua[t[e+14]]+ua[t[e+15]]}import _nt from"crypto";var gZ={randomUUID:_nt.randomUUID};function Dnt(t,e,n){if(gZ.randomUUID&&!e&&!t)return gZ.randomUUID();t=t||{};let r=t.random||(t.rng||hZ)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){n=n||0;for(let o=0;o<16;++o)e[n+o]=r[o];return e}return ZSe(r)}var Ba=Dnt;import{bindVariablesToObject as Unt}from"@uniformdev/canvas";function Lnt(t){return Array.isArray(t)&&t.length>0}function e4e(t){return!!t&&typeof t=="object"&&"type"in t}function t4e(t){return typeof t=="object"&&t!==null&&"root"in t&&e4e(t.root)}function s0(t){return"children"in t&&Lnt(t.children)}var Mnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Ont=({context:t,renderChildren:e})=>{if(!s0(t.currentNode))return"";let n=e(t.currentNode.children);return n.endsWith(" ")?n:`${n} `};var Rnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Ant=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var knt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Pnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Int=({context:t})=>t.currentNode.text;var Fnt=()=>" ";var Bnt=()=>" ",znt=new Map([["text",Int],["tab",Fnt],["linebreak",Bnt],["paragraph",Rnt],["listitem",Ont],["heading",Mnt],["table",Ant],["tablecell",knt],["tablerow",Pnt]]),Vnt=t=>{let e=znt.get(t.currentNode.type);return e||(({context:n,renderChildren:r})=>s0(n.currentNode)?r(n.currentNode.children):"")};function Hnt(t,e){let n=[];return e?.ancestorNodes&&(n=n.concat(e.ancestorNodes)),e?.currentNode&&n.unshift(e.currentNode),{...e??{},currentNode:t,ancestorNodes:n}}function bZ(t,e){var n;if(!e4e(t))return"";let r=Hnt(t,e),o=(n=r.resolveRenderer)==null?void 0:n.call(r,r);if(typeof o>"u")o=Vnt(r);else if(o===null)return"";let i=a=>jnt(a,r);if(o){let a=o({context:r,renderChildren:i});return r.ancestorNodes.length>0?a:a.trim()}else throw new Error(`There is no renderer for node type: ${r.currentNode.type}`)}function jnt(t,e){return Array.isArray(t)?t.map(n=>bZ(n,e)).join(""):""}var ZE="Untitled",n4e=60;function r4e({value:t,isNew:e,contentType:n}){let{result:r}=Unt({value:t,handleBinding:()=>"{token}",variables:{}}),o=n.entryName??"",i=(n.fields??[]).find(a=>a.id===o);if(typeof r=="string"){if(i?.type==="image")return r.length>0?`Image: ${Wnt(r)}`:`${ZE} image`;if(r.length>0)return i?.type==="date"?Ynt(r)?Znt(r):"Invalid date":l0(r)}else{if(typeof r=="number"||typeof r=="boolean")return r.toString();if(typeof r<"u"&&r!==null){if(i?.type==="link")return Knt(r);if(t4e(r))return l0(bZ(r.root));if(i?.type==="datetime"&&r){let a=r;return a.datetime&&o4e(a.datetime)?qnt(a.datetime):"Invalid datetime"}else return l0(Jnt(r).description)}}return e?`New entry: ${n.name}`:ZE}function Knt(t){return t?t.type==="projectMapNode"?t.path.length>0?`Link to ${l0(t.path)}`:`Link to project map node (${t.nodeId})`:t.path.length>0?`Link to ${l0(t.path)}`:`${ZE} link`:`${ZE} link`}function Wnt(t){try{let{pathname:e,hostname:n}=new URL(t),r=e.split("/").filter(o=>o);return r.length>2?`/${r[0]}/.../${r[r.length-1]} (${l0(n)})`:`${e} (${l0(n)})`}catch{return t}}function l0(t){let e=t.split(" ").filter(i=>i).reverse();if(e.length<1)return ZE;let n="",r=e.pop(),o=()=>n.length+(r?.length??0)+(n.length>0?1:0);for(;r&&o()<n4e;)n+=n.length>0?` ${r}`:r,r=e.pop();return n.length<1?`${t.slice(0,n4e)}...`:e.length>0?`${n}...`:n}var Gnt=/^[1-9][0-9]{3}-[0-1][0-9]-[0-3][0-9]$/;function Ynt(t){return Gnt.test(t)?o4e(t):!1}function o4e(t){let e=new Date(t);return e instanceof Date&&!isNaN(Number(e))}function Znt(t){return new Date(t).toLocaleDateString()}function qnt(t){return new Date(t).toLocaleString()}function Jnt(t){let e=xZ(t);return e?{description:e,named:!0}:{description:Xnt(t).valuePreview,named:!1}}function Xnt(t){if(typeof t>"u")return{valueIcon:"close-o",valuePreview:"undefined"};if(t===null)return{valueIcon:"close-o",valuePreview:"null"};if(Array.isArray(t))return{valuePreview:`array with ${t.length} item${t.length!==1?"s":""}`,valueIcon:"list"};if(typeof t=="boolean")return{valuePreview:t.toString(),valueIcon:t?"check-r":"close-r"};if(typeof t=="number"||typeof t=="bigint")return{valuePreview:t.toString(10),valueIcon:"number-input"};if(typeof t=="object"){let e=Object.keys(t);return{valuePreview:`object with ${e.length} ${e.length!==1?"properties":"property"}`,valueIcon:"shape-hexagon"}}return{valuePreview:t,valueIcon:"text-input"}}var Qnt=["displayName","name","_name","title","heading","label","parameters","fields","properties","entry","slug","_slug","alt","alt_description","description","results","items","entries","hits","value","id","objectID","identifier"];function xZ(t){if(typeof t=="string")return t;if(typeof t=="number")return t.toString(10);if(typeof t=="boolean")return t.toString();if(typeof t!="object"||t===null)return;if(Array.isArray(t)){if(t.length===0)return;let r=xZ(t[0]);return r?t.length===1?r:`${r} and ${t.length-1} other${t.length>2?"s":""}`:void 0}let n=t;for(let r of Qnt)if(r in n){let o=xZ(n[r]);if(o)return o}}import{CANVAS_SLOT_SECTION_SLOT as ert,walkNodeTree as trt}from"@uniformdev/canvas";var qE="|";function LL(t,e){if(!t)return e??Ba();let n=t.split(qE),r=(e??Ba()).split(qE);return n.at(-1)===r[0]&&n.pop(),n.concat(r).join(qE)}function a4e(t){let e=t.indexOf(qE);if(e<0)throw new Error(`Cannot remove pattern instance ID from ${t}`);return t.substring(e+1)}function ML(t,e,n=!1){trt(t,({node:r,actions:{setDescendantsContext:o},context:i})=>{let a=!n&&!i?.currentParentPatternInstanceId,l="_pattern"in r&&!!r._pattern;if(i?.currentParentPatternInstanceId){let d=LL(i.currentParentPatternInstanceId,r._id);r._id=d}let c=i?.currentParentPatternInstanceId;l&&(c=r._id),"_overrides"in r&&r._overrides&&i4e(r._overrides,c,a),"_patternOverrides"in r&&r._patternOverrides&&i4e(r._patternOverrides,c,a),l&&o({currentParentPatternInstanceId:r._id})},{initialContext:{currentParentPatternInstanceId:e}})}var i4e=(t,e,n)=>{Object.entries(t).forEach(([r,o])=>{let i=n?r:LL(e,r);Object.entries(o.slots??{}).forEach(([a,l])=>{l.forEach(c=>{let{partOfNestedPattern:d}=OL(r??"");ML(c,a===ert&&!d?void 0:e,!0)})}),i&&(delete t[r],t[i]=o)})};function OL(t){let e=t.split(qE);return e.length===1?{partOfPattern:void 0,partOfNestedPattern:void 0}:e.length===2?{partOfPattern:e[0],partOfNestedPattern:void 0}:{partOfPattern:e[0],partOfNestedPattern:e[e.length-2]}}import{CANVAS_SLOT_SECTION_SLOT as f4e}from"@uniformdev/canvas";import{CANVAS_VIZ_CONTROL_PARAM as irt}from"@uniformdev/canvas";import{CANVAS_ENRICHMENT_TAG_PARAM as s4e,CANVAS_INTENT_TAG_PARAM as nrt,CANVAS_LOCALE_TAG_PARAM as rrt,CANVAS_PERSONALIZATION_PARAM as l4e,CANVAS_TEST_VARIANT_PARAM as ort,CANVAS_VIZ_CONTROL_PARAM as u4e}from"@uniformdev/canvas";var c4e=[{id:nrt,name:"Intent Tag",type:"intentTag"},{id:rrt,name:"Locale Visibility",type:"localeSelect"},{id:l4e,name:"Personalization Criteria",type:l4e},{id:s4e,name:"Enrichment Tags",type:s4e,helpText:"Seeing this component will increase a visitor's score in these enrichments."},{id:ort,name:"A/B Test",type:"testVariant"},{id:u4e,name:"Visibility Control",type:u4e}];var art=c4e.reduce((t,e)=>(e.id===irt||t.add(e.id),t),new Set);function fC(t,e){return art.has(e)?"yes":t?.parameters?.[e]??"no"}function CZ(t,e){e&&Object.entries(e).forEach(([n,r])=>{let o=t[n];if((r.parameters||o?.parameters)&&(t[n]??={},t[n].parameters={...r?.parameters,...o?.parameters}),(r.dataResources||o?.dataResources)&&(t[n]??={},t[n].dataResources={...r?.dataResources,...o?.dataResources}),r.slots||o?.slots){t[n]??={};let i=Object.entries(o?.slots??{}).reduce((a,[l,c])=>(a[l]&&Array.isArray(a[l])?a[l]=[...c,...a[l]]:a[l]=c,a),r.slots??{});t[n].slots=i}(r.variant!==void 0||o?.variant!==void 0)&&(t[n]=t[n]??{},t[n].variant=o?.variant??r?.variant)})}function d4e({applyOverrideToNode:t}){let e=new Set,n={};return{visitNode(r){e.add(r._id),CZ(n,r._overrides),CZ(n,r._patternOverrides);let o=n[r._id];o&&(o.parameters&&Object.keys(o.parameters).forEach(i=>{fC(r._overridability,i)==="no"&&(console.log(`[Override] Cleaned override from ${r._id} parameter ${i} because it is not overridable`),delete n[r._id].parameters?.[i])}),o.dataResources&&Object.keys(o.dataResources).forEach(i=>{r._patternDataResources?.[i]?.isPatternParameter||(console.log(`[Override] Cleaned override from ${r._id} data resource ${i} because it is not overridable`),delete n[r._id].dataResources?.[i])}),o.variant!==void 0&&(r._overridability?.variants||delete o.variant),t({node:r,overrides:o}))},overrides:n}}function SZ(t){let{beforeApplyParameterOverride:e,beforeApplyDataResourceOverride:n}=t??{};return d4e({applyOverrideToNode({node:r,overrides:o}){if(Object.entries(o.parameters??{}).map(([i,a])=>{r.parameters=r.parameters??{},e?.(r,i,a,r.parameters[i]);let l=r.parameters[i]??={type:a.type};a.locales||a.localesConditions?(l.locales??={},delete l.value,delete l.conditions,new Set([...Object.keys(a.locales??{}),...Object.keys(a.localesConditions??{})]).forEach(f=>{delete l.locales?.[f],delete l.localesConditions?.[f];let m=a.locales?.[f],h=a.localesConditions?.[f];m!=null&&(l.locales??={},l.locales[f]=m),h!=null&&(l.localesConditions??={},l.localesConditions[f]=h)}),l.locales&&Object.keys(l.locales).length===0&&delete l.locales,l.localesConditions&&Object.keys(l.localesConditions).length===0&&delete l.localesConditions):(delete l.locales,delete l.localesConditions,delete l.conditions,delete l.value,a.value!==null&&a.value!==void 0&&(l.value=a.value,l.connectedData=a.connectedData),a.conditions!==null&&a.conditions!==void 0&&(l.conditions=a.conditions)),!l.locales&&!l.localesConditions&&!l.conditions&&l.value===void 0&&delete r.parameters[i]}),Object.entries(o.dataResources??{}).forEach(([i,a])=>{n?.(r,i,a,r._dataResources?.[i]),r._dataResources??={},r._dataResources[i]=a}),o.variant!==void 0&&(r.variant=o.variant),o.slots){r.slots??={};let i=Object.keys(o.slots)[0];r.slots[f4e]??=[],r.slots[f4e]=[...o.slots[i]??[]]}}})}import{CANVAS_SLOT_SECTION_SLOT as srt,CANVAS_SLOT_SECTION_TYPE as lrt}from"@uniformdev/canvas";var p4e=({preserveOwnSlotSections:t=!1,preserveChildrenSlotSections:e=!1}={})=>n=>{if(n.node.type!==lrt)return;let{partOfPattern:r,partOfNestedPattern:o}=OL(n.node._id??"");!r&&!o&&t||r&&!o&&e||urt(n)},urt=({node:t,type:e,actions:n})=>{e!=="entry"&&(n.insertAfter(t.slots?.[srt]??[]),n.remove())};import{walkNodeTree as frt}from"@uniformdev/canvas";import{produce as prt}from"immer";import{CANVAS_SLOT_SECTION_SLOT as m4e,walkNodeTree as crt}from"@uniformdev/canvas";import{produce as drt}from"immer";function h4e(t,e,n,r=Ba()){if(!t._pattern)throw new Error("Not a pattern");let o={};return crt(t,({node:i,ancestorsAndSelf:a,actions:l})=>{let c=i._id,d=e[c];if(a.length===1)i._id=r;else{let m=a[0];m.type!=="slot"||m.parentSlot!==m4e?(i._id=a4e(c),i._id=LL(r,i._id)):(l.replace({...o[c],_id:o[c]._id}),l.stopProcessingDescendants())}if(d){let m=drt(d,h=>{h.slots&&Object.entries(h.slots).forEach(([v,y])=>{if(v!==m4e)throw new Error("Only slot section items are supported for duplication");y.forEach((b,w)=>{if(!b._id)return;let C=RL(b,e,n);o[b._id]=C,y[w]=C})})});n?.(i._id,m,c)}}),r}function RL(t,e,n){return prt(t,r=>{frt(r,({type:o,node:i,actions:{stopProcessingDescendants:a}})=>{o==="component"&&i._pattern?(h4e(i,e,n),a()):i._id=Ba()})})}function AL({locale:t,conditionIndex:e,property:n}){if(t===void 0)if(e<0){if(delete n.value,!n.conditions?.length)return!1}else n.conditions?.splice(e,1);else e<0?delete n.locales?.[t]:n.localesConditions?.[t]?.splice(e,1);if(n.localesConditions){for(let[r,o]of Object.entries(n.localesConditions))if(o.length===0){delete n.localesConditions[r];break}Object.keys(n.localesConditions).length===0&&delete n.localesConditions}return n.locales&&Object.keys(n.locales).length===0&&delete n.locales,n.conditions&&n.conditions.length===0&&delete n.conditions,!!(n.value!==void 0||n.locales||n.conditions||n.localesConditions)}function wZ({locale:t,conditionIndex:e,conditionDefinition:n,property:r,newPropertyValue:o}){t===void 0?e<0?r.value=o:(r.conditions??=[],g4e(r.conditions,e,n,o)):e<0?(r.locales??={},r.locales[t]=o):(r.localesConditions??={},r.localesConditions[t]??=[],g4e(r.localesConditions[t],e,n,o))}function g4e(t,e,n,r){if(e<0)throw new Error("Condition index must be greater than or equal to 0");let o=t[e];t[e]={when:n??o?.when??{clauses:[]},value:r===void 0?null:r,id:o?.id??mrt(t)}}function mrt(t){let e=new Set(t.map(r=>r.id)),n=0;for(;e.has(n);)n++;return n}function v4e(t){let e=!1,n={};return"_pattern"in t&&t._patternDataResources&&Object.entries(t._patternDataResources).forEach(([r,o])=>{e=!0,n[r]={...o,source:"patternDataResource"}}),t._dataResources&&Object.entries(t._dataResources).forEach(([r,o])=>{n[r]?n[r].isPatternParameter&&(e=!0,n[r]={...o,source:"dataResource"}):(e=!0,n[r]={...o,source:"dataResource"})}),e?n:void 0}import{CANVAS_DRAFT_STATE as hrt,convertEntryToPutEntry as uVt,getPropertiesValue as fVt}from"@uniformdev/canvas";function y4e(t){let{fields:e,entryName:n,type:r="contentType",thumbnailField:o,...i}=t;return{...i,titleParameter:n,thumbnailParameter:o,parameters:e,canBeComposition:r==="block",permissions:t.permissions,useTeamPermissions:t.useTeamPermissions??!0,workflowId:t.workflowId}}function b4e(t){return{id:t.id,name:t.name,entryName:t.titleParameter,thumbnailField:t.thumbnailParameter,fields:t.parameters,icon:t.icon,description:t.description,slugSettings:t.slugSettings,type:t.canBeComposition?"block":"contentType",created:t.created,updated:t.updated,permissions:t.permissions,useTeamPermissions:t.useTeamPermissions,workflowId:t.workflowId||void 0}}function kL(t){let{entry:{fields:e,...n},...r}=t;return{created:"",modified:"",composition:{_id:"",...n,_name:t.entry._name??"Untitled",parameters:e,_overridability:t.entry._overridability,_overrides:t.entry._overrides,_pattern:t.entry._pattern,_patternError:t.entry._patternError},pattern:!!t.pattern,previewImageUrl:t.entry._thumbnail,...r}}function x4e(t,e,n,r,o,i,a){let l=a??e.projectId;if(!l)throw new Error("projectId is required in currentEntry or explicitly");return{created:e.created??"",modified:e.modified??"",projectId:l,state:r??e.state??hrt,releaseId:o??e.releaseId,workflowId:n?.workflowId??e.workflowId,workflowStageId:n?.workflowStageId??e.workflowStageId,editionId:i,editionName:n?.editionName??e.editionName,editionPriority:n?.editionPriority??e.editionPriority,pattern:e.pattern,entry:{type:t.type,_id:t._id,_name:t._name,_slug:t._slug??"",fields:t.parameters,_thumbnail:n?.previewImageUrl??void 0,_dataResources:t._dataResources,_pattern:t._pattern,_patternError:t._patternError,_overridability:t._overridability,_overrides:t._overrides,_locales:t._locales,_author:t._author,_authorSubject:t._authorSubject,_creator:t._creator,_creatorSubject:t._creatorSubject,_patternDataResources:t._patternDataResources}}}function EZ(t,e){let{parameters:n,...r}=t;return{...r,_id:e??r._id??"unknown",fields:n}}function TZ(t){let{fields:e,...n}=t;return{...n,parameters:e}}import{CANVAS_VIZ_LOCALE_RULE as grt}from"@uniformdev/canvas";import{produce as vrt}from"immer";function C4e(t,e,n){let r=vrt(t.criteria,o=>S4e(o,e,n));return r&&{...t,criteria:r}}function S4e(t,e,n){if(!t)return t;let r=!1;for(let o of t.clauses)if("clauses"in o){let i=S4e(o,e,n);if(i===null){if(t.op!=="|")return null;t.clauses.splice(t.clauses.indexOf(o),1),r=!0}else i!==void 0&&(t.clauses[t.clauses.indexOf(o)]=i,r=!0)}else if(o.rule===grt){let i=Array.isArray(o.value)?o.value:[o.value],a=i.includes(e),l=i.includes(n);if(!a&&!l||a&&l)continue;if(i.length===1&&l&&!a)return null;a&&!l&&(o.value=i.concat(n),r=!0)}return r?t:void 0}var w4e=J(mZ(),1);function _Z(t,e){try{return(0,w4e.get)(t,e)}catch{return}}function DZ(t,e,n=0){let r=t.slice(n*4,n*4+4);if(!r)throw new Error("Failed to generate a default variation name");return`${e.startsWith("$")?e.slice(1):e}-${r}`}import{CANVAS_VIZ_LOCALE_RULE as yrt}from"@uniformdev/canvas";import{produce as brt}from"immer";function E4e(t,e){let n=brt(t.criteria,r=>T4e(r,e));return n&&{...t,criteria:n}}function T4e(t,e){if(!t)return t;for(let n=t.clauses.length-1;n>=0;n--){let r=t.clauses[n];if("clauses"in r){let o=T4e(r,e);if(o)t.clauses[n]=o;else if(t.clauses.splice(n,1),o===null&&t.op!=="|")return null}else if(r.rule===yrt){let o=Array.isArray(r.value)?r.value:[r.value],i=o.indexOf(e);if(i!==-1)if(Array.isArray(r.value)&&r.value.length>1)o.splice(i,1);else if(r.op.startsWith("!"))t.clauses.splice(n,1);else return null}}if(t.clauses.length!==0)return t}function _4e(t){return{all:t=t||new Map,on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(o){o(n)}),(r=t.get("*"))&&r.slice().map(function(o){o(e,n)})}}}function D4e(t,e){let n=_4e();if(process.env.NODE_ENV==="development"&&!e){let r=new Error().stack?.split(`
5177
+ `;await er();function VSe(t){let e=_le({nodes:[pd,fd,cZ,X1,Q1,Tae,gfe,hfe,vfe,Mf]});return e.update(()=>{Eae("skip-dom-selection"),Sde(t,Nde)},{discrete:!0}),e.getEditorState().toJSON()}function HSe({twee:t,nodeId:e,propertyId:n,propertyType:r,locale:o,propertyEdit:i,conditionIndex:a=-1}){let l=t.getNodeById(e);if(!l)throw new Error(`Node with ID ${e} not found`);if(i.action==="clearValue")t.updateNodeProperty({nodeId:e,property:n,value:null,source:"ai",locale:o,conditionIndex:-1});else if(i.action==="resetOverride")t.resetPatternPropertyOverride(e,n,o);else if(i.action==="setValue"){let c=gnt({twee:t,targetNode:l,propertyId:n,propertyType:r,propertyEdit:i}),d=t.getNodeProperty(e,n);if(!o&&d?.locales)throw new Error(`The ${n} property is localized in ${Object.keys(d.locales).join(", ")}, but no locale was provided when setting its value. Please provide an explicit locale.`);t.updateNodeProperty({nodeId:e,property:n,value:()=>c,source:"ai",locale:o,conditionIndex:a,type:r})}}var gnt=({twee:t,targetNode:e,propertyId:n,propertyType:r,propertyEdit:o})=>{if(r==="richText")return VSe(o.newValue??"");if(r==="number")return Number(o.newValue);if(n===pnt){if(hnt(e.value.type))throw new Error("Enrichment tags are not allowed in system components.");if(t.getParentInfo(e.nodeId)?.parentId===mnt)throw new Error("Enrichment tags are not allowed in personalization variants.")}return o.treatNewValueAsJson?JSON.parse(o.newValue):o.newValue};async function DL({twee:t,slotUpdates:e,propertyUpdates:n,localeUpdates:r,nameUpdate:o,slugUpdate:i,descriptionUpdate:a,currentEditorLocale:l,referenceData:c}){let d=[];o&&(t.updateRootNode({update:{_name:o}}),d.push({summary:"Updated name",success:!0})),i&&(t.updateRootNode({update:{_slug:i}}),d.push({summary:"Updated slug",success:!0})),a&&(t.updateRootMetadata({description:a}),d.push({summary:"Updated description",success:!0}));let f=await c.fetchDefinitions();await ynt({slotUpdates:e,twee:t,definitions:f,referenceData:c,results:d});let m=d.some(h=>!h.success);return e.deletedComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped deleting component ${h} because previous actions failed`,success:!1}):(t.deleteNode(h,!1),d.push({summary:`Deleted component ${h}`,success:!0}))}),m=d.some(h=>!h.success),e.moveComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped moving component ${h.componentId} because previous actions failed`,success:!1}):(t.moveNode({movedNodeId:h.componentId,parentNodeId:h.newParentComponentId,parentSlot:h.newSlotName,targetIndexInSlot:h.newSlotIndex}),d.push({summary:`Moved component ${h.componentId} to ${h.newParentComponentId} in slot ${h.newSlotName} at index ${h.newSlotIndex}`,success:!0}))}),m=d.some(h=>!h.success),e.duplicateComponentsInSlots?.forEach(h=>{m?d.push({summary:`Skipped duplicating component ${h} because previous actions failed`,success:!1}):(t.duplicateNode(h,c.resolvePatternData),d.push({summary:`Duplicated component ${h}`,success:!0}))}),m=d.some(h=>!h.success),r?.enableLocales?.forEach(h=>{m?d.push({summary:`Skipped enabling locale ${h} because previous actions failed`,success:!1}):(t.enableLocale(h),d.push({summary:`Enabled locale ${h}`,success:!0}))}),m=d.some(h=>!h.success),r?.disableLocales?.forEach(h=>{m?d.push({summary:`Skipped disabling locale ${h} because previous actions failed`,success:!1}):(t.disableLocale(h),d.push({summary:`Disabled locale ${h}`,success:!0}))}),m=d.some(h=>!h.success),m?n.length>0&&d.push({summary:`Skipped ${n.length} property updates because previous actions failed`,success:!1}):(await bnt({propertyUpdates:n,twee:t,currentEditorLocale:l,referenceData:c,definitions:f,results:d})).forEach(v=>{if(!v.result.success)return;let y="componentId"in v.update?v.update.componentId:t.rootNodeId,b=Ute({twee:t,nodeId:y,currentEditorLocale:v.currentLocale,definition:v.propertyDefinition}),w=(t.getNodeById(t.rootNodeId)?.value)._locales??[];if(b&&!w.includes(b)){d.push({summary:`The ${b} locale is not enabled on this entity. Please enable it before setting values in this locale.`,success:!1});return}if(v.result.action!=="nothing")try{HSe({twee:t,nodeId:y,propertyId:v.propertyDefinition.id,propertyType:v.propertyDefinition.type,locale:b,propertyEdit:v.result}),d.push({summary:`Updated value of ${v.propertyDefinition.id} on ${y}${b?` in ${b}`:""}`,success:!0})}catch(C){d.push({summary:`Failed to update value of ${v.propertyDefinition.id} on ${y}${b?` in ${b}`:""}: ${C instanceof Error?C.message:"Unknown error"}`,success:!1})}if("overridable"in v.update&&v.update.overridable!==void 0){let C=v.update.overridable;t.updateNode({nodeId:y,updateComponent:S=>{S._overridability??={},S._overridability.parameters??={},S._overridability.parameters[v.propertyDefinition.id]=C}}),d.push({summary:`Updated overridability for ${y}`,success:!0})}}),d}async function ynt({slotUpdates:t,twee:e,definitions:n,referenceData:r,results:o}){(await Promise.allSettled(t.newComponentsInSlots?.map(async a=>{let l=e.getNodeById(a.parentComponentId);if(!l)throw new Error(`Parent component with ID ${a.parentComponentId} not found`);let c=n[l.value.type];if(!c)throw new Error(`Definition for parent component type ${l.value.type} not found`);let d=c.slots?.find(h=>h.id===a.slotName);if(!d)throw new Error(`Slot ${a.slotName} not found on component type ${l.value.type}`);let f=_k({twee:e,parentSlotDefinition:d,nodeId:a.parentComponentId,componentDefinitionsIndex:n});if(!f)throw new Error(`Can't find allowed components inherited slot for ${a.slotName}`);let m=Hte(f);if(a.instanceType==="component"){if(!a.componentType)throw new Error("componentType is required when inserting a component instance");if(!Tk({type:a.componentType},m,!1))throw new Error(`Component type ${a.componentType} is not allowed in slot ${a.slotName}`);e.insertNode({node:{type:a.componentType},overrideNodeId:a.newComponentInstanceUuid,parentNodeId:a.parentComponentId,parentSlot:a.slotName,targetIndexInSlot:a.slotIndex}),o.push({summary:`Inserted component ${a.componentType} in slot ${a.slotName} ${a.slotIndex!==void 0?`at index ${a.slotIndex}`:""}`,success:!0})}else{if(!a.componentPatternId)throw new Error("componentPatternId is required when inserting a component pattern instance");let h=await r.resolvePatternData(a.componentPatternId);if(!h)throw new Error(`Pattern definition with ID ${a.componentPatternId} not found`);if(!Tk({type:h.type,_pattern:a.componentPatternId},m,!1))throw new Error(`Pattern ${a.componentPatternId} is not allowed in slot ${a.slotName}`);e.insertPattern({pattern:h,patternInstanceId:a.newComponentInstanceUuid,parentNodeId:a.parentComponentId,parentSlot:a.slotName,targetIndexInSlot:a.slotIndex}),o.push({summary:`Inserted pattern ${h._name} in slot ${a.slotName} ${a.slotIndex!==void 0?`at index ${a.slotIndex}`:""}`,success:!0})}})??[])).forEach((a,l)=>{if(a.status==="rejected"){let c=t.newComponentsInSlots?.[l];console.error("Error inserting component",a.reason),o.push({summary:`Failed to insert component ${c?.newComponentInstanceUuid}: ${"message"in a.reason?a.reason.message:"Unknown error"}`,success:!1})}})}async function bnt({propertyUpdates:t,twee:e,currentEditorLocale:n,referenceData:r,definitions:o,results:i}){if(t.length===0)return[];let[a,l]=await Promise.all([r.fetchProjectGuidance(),r.getToolClient()]),c=await Promise.allSettled(t.map(async d=>(async()=>{let f="componentId"in d?d.componentId:e.rootNodeId,m=e.getNodeById(f);if(!m)throw new Error(`Component instance with ID ${f} not found`);let h=o[m.value.type];if(!h)throw new Error(`Definition with ID ${m.value.type} not found`);let v="fieldId"in d?d.fieldId:d.parameterId,y=h.parameters?.find(E=>E.id===v),b=d.locale??n,w=y??{id:v,type:"unknown"};if(d.editInstructions===void 0)return{result:{success:!0,newValue:"",treatNewValueAsJson:!1,action:"nothing"},update:d,propertyDefinition:w};if(d.editInstructions==="")return{result:{success:!0,newValue:"",treatNewValueAsJson:!1,action:"clearValue"},update:d,propertyDefinition:w};if(!y)throw new Error(`Property with ID ${v} not found`);let C=vnt({property:e.getNodeProperty(f,v),locale:b,conditionIndex:-1}),S=await l.invoke("createPropertyEdit",{edit:d.editInstructions,propertyDefinition:{id:v,name:y.name,type:y.type,guidance:y.guidance,typeConfig:y.typeConfig},outputLocale:b,documentContext:void 0,currentValue:C,projectGuidance:a,componentGuidance:h.description});if(!S.success)throw new Error(S.summary??"Failed to edit property");return{result:S,update:d,propertyDefinition:y,currentLocale:b}})()));return c.forEach((d,f)=>{if(d.status==="rejected"){let m=t[f],h="fieldId"in m?m.fieldId:m.parameterId;i.push({summary:`Failed to edit property ${h}: ${"message"in d.reason?d.reason.message:"Unknown error"}`,success:!1})}}),c.filter(d=>d.status==="fulfilled").map(d=>d.value)}import{CANVAS_BLOCK_PARAM_TYPE as Sc,CANVAS_ENRICHMENT_TAG_PARAM as $4e,CANVAS_LOCALE_TAG_PARAM as JE,CANVAS_LOCALIZATION_SLOT as $Z,CANVAS_LOCALIZATION_TYPE as xrt,CANVAS_PERSONALIZATION_PARAM as XE,CANVAS_PERSONALIZE_SLOT as N4e,CANVAS_SLOT_SECTION_SLOT as Crt,CANVAS_SLOT_SECTION_TYPE as NZ,CANVAS_TEST_SLOT as L4e,CANVAS_TEST_VARIANT_PARAM as M4e,CANVAS_VIZ_CONTROL_PARAM as u0,convertToBindExpression as Srt,createVariableReference as wrt,getEffectivePropertyValue as O4e,walkNodeTree as c0}from"@uniformdev/canvas";var jSe=Object.prototype.hasOwnProperty;function YE(t,e){var n,r;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((r=t.length)===e.length)for(;r--&&YE(t[r],e[r]););return r===-1}if(!n||typeof t=="object"){r=0;for(n in t)if(jSe.call(t,n)&&++r&&!jSe.call(e,n)||!(n in e)||!YE(t[n],e[n]))return!1;return Object.keys(e).length===r}}return t!==t&&e!==e}var d0=J(mZ(),1),A4e=J(YSe(),1);import{produce as To}from"immer";import Tnt from"crypto";var NL=new Uint8Array(256),$L=NL.length;function hZ(){return $L>NL.length-16&&(Tnt.randomFillSync(NL),$L=0),NL.slice($L,$L+=16)}var ua=[];for(let t=0;t<256;++t)ua.push((t+256).toString(16).slice(1));function ZSe(t,e=0){return ua[t[e+0]]+ua[t[e+1]]+ua[t[e+2]]+ua[t[e+3]]+"-"+ua[t[e+4]]+ua[t[e+5]]+"-"+ua[t[e+6]]+ua[t[e+7]]+"-"+ua[t[e+8]]+ua[t[e+9]]+"-"+ua[t[e+10]]+ua[t[e+11]]+ua[t[e+12]]+ua[t[e+13]]+ua[t[e+14]]+ua[t[e+15]]}import _nt from"crypto";var gZ={randomUUID:_nt.randomUUID};function Dnt(t,e,n){if(gZ.randomUUID&&!e&&!t)return gZ.randomUUID();t=t||{};let r=t.random||(t.rng||hZ)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){n=n||0;for(let o=0;o<16;++o)e[n+o]=r[o];return e}return ZSe(r)}var Ba=Dnt;import{bindVariablesToObject as Unt}from"@uniformdev/canvas";function Lnt(t){return Array.isArray(t)&&t.length>0}function e4e(t){return!!t&&typeof t=="object"&&"type"in t}function t4e(t){return typeof t=="object"&&t!==null&&"root"in t&&e4e(t.root)}function s0(t){return"children"in t&&Lnt(t.children)}var Mnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Ont=({context:t,renderChildren:e})=>{if(!s0(t.currentNode))return"";let n=e(t.currentNode.children);return n.endsWith(" ")?n:`${n} `};var Rnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Ant=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var knt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Pnt=({context:t,renderChildren:e})=>s0(t.currentNode)?`${e(t.currentNode.children)} `:"";var Int=({context:t})=>t.currentNode.text;var Fnt=()=>" ";var Bnt=()=>" ",znt=new Map([["text",Int],["tab",Fnt],["linebreak",Bnt],["paragraph",Rnt],["listitem",Ont],["heading",Mnt],["table",Ant],["tablecell",knt],["tablerow",Pnt]]),Vnt=t=>{let e=znt.get(t.currentNode.type);return e||(({context:n,renderChildren:r})=>s0(n.currentNode)?r(n.currentNode.children):"")};function Hnt(t,e){let n=[];return e?.ancestorNodes&&(n=n.concat(e.ancestorNodes)),e?.currentNode&&n.unshift(e.currentNode),{...e??{},currentNode:t,ancestorNodes:n}}function bZ(t,e){var n;if(!e4e(t))return"";let r=Hnt(t,e),o=(n=r.resolveRenderer)==null?void 0:n.call(r,r);if(typeof o>"u")o=Vnt(r);else if(o===null)return"";let i=a=>jnt(a,r);if(o){let a=o({context:r,renderChildren:i});return r.ancestorNodes.length>0?a:a.trim()}else throw new Error(`There is no renderer for node type: ${r.currentNode.type}`)}function jnt(t,e){return Array.isArray(t)?t.map(n=>bZ(n,e)).join(""):""}var ZE="Untitled",n4e=60;function r4e({value:t,isNew:e,contentType:n}){let{result:r}=Unt({value:t,handleBinding:()=>"{token}",variables:{}}),o=n.entryName??"",i=(n.fields??[]).find(a=>a.id===o);if(typeof r=="string"){if(i?.type==="image")return r.length>0?`Image: ${Wnt(r)}`:`${ZE} image`;if(r.length>0)return i?.type==="date"?Ynt(r)?Znt(r):"Invalid date":l0(r)}else{if(typeof r=="number"||typeof r=="boolean")return r.toString();if(typeof r<"u"&&r!==null){if(i?.type==="link")return Knt(r);if(t4e(r))return l0(bZ(r.root));if(i?.type==="datetime"&&r){let a=r;return a.datetime&&o4e(a.datetime)?qnt(a.datetime):"Invalid datetime"}else return l0(Jnt(r).description)}}return e?`New entry: ${n.name}`:ZE}function Knt(t){return t?t.type==="projectMapNode"?t.path.length>0?`Link to ${l0(t.path)}`:`Link to project map node (${t.nodeId})`:t.path.length>0?`Link to ${l0(t.path)}`:`${ZE} link`:`${ZE} link`}function Wnt(t){try{let{pathname:e,hostname:n}=new URL(t),r=e.split("/").filter(o=>o);return r.length>2?`/${r[0]}/.../${r[r.length-1]} (${l0(n)})`:`${e} (${l0(n)})`}catch{return t}}function l0(t){let e=t.split(" ").filter(i=>i).reverse();if(e.length<1)return ZE;let n="",r=e.pop(),o=()=>n.length+(r?.length??0)+(n.length>0?1:0);for(;r&&o()<n4e;)n+=n.length>0?` ${r}`:r,r=e.pop();return n.length<1?`${t.slice(0,n4e)}...`:e.length>0?`${n}...`:n}var Gnt=/^[1-9][0-9]{3}-[0-1][0-9]-[0-3][0-9]$/;function Ynt(t){return Gnt.test(t)?o4e(t):!1}function o4e(t){let e=new Date(t);return e instanceof Date&&!isNaN(Number(e))}function Znt(t){return new Date(t).toLocaleDateString()}function qnt(t){return new Date(t).toLocaleString()}function Jnt(t){let e=xZ(t);return e?{description:e,named:!0}:{description:Xnt(t).valuePreview,named:!1}}function Xnt(t){if(typeof t>"u")return{valueIcon:"close-o",valuePreview:"undefined"};if(t===null)return{valueIcon:"close-o",valuePreview:"null"};if(Array.isArray(t))return{valuePreview:`array with ${t.length} item${t.length!==1?"s":""}`,valueIcon:"list"};if(typeof t=="boolean")return{valuePreview:t.toString(),valueIcon:t?"check-r":"close-r"};if(typeof t=="number"||typeof t=="bigint")return{valuePreview:t.toString(10),valueIcon:"number-input"};if(typeof t=="object"){let e=Object.keys(t);return{valuePreview:`object with ${e.length} ${e.length!==1?"properties":"property"}`,valueIcon:"shape-hexagon"}}return{valuePreview:t,valueIcon:"text-input"}}var Qnt=["displayName","name","_name","title","heading","label","parameters","fields","properties","entry","slug","_slug","alt","alt_description","description","results","items","entries","hits","value","id","objectID","identifier"];function xZ(t){if(typeof t=="string")return t;if(typeof t=="number")return t.toString(10);if(typeof t=="boolean")return t.toString();if(typeof t!="object"||t===null)return;if(Array.isArray(t)){if(t.length===0)return;let r=xZ(t[0]);return r?t.length===1?r:`${r} and ${t.length-1} other${t.length>2?"s":""}`:void 0}let n=t;for(let r of Qnt)if(r in n){let o=xZ(n[r]);if(o)return o}}import{CANVAS_SLOT_SECTION_SLOT as ert,walkNodeTree as trt}from"@uniformdev/canvas";var qE="|";function LL(t,e){if(!t)return e??Ba();let n=t.split(qE),r=(e??Ba()).split(qE);return n.at(-1)===r[0]&&n.pop(),n.concat(r).join(qE)}function a4e(t){let e=t.indexOf(qE);if(e<0)throw new Error(`Cannot remove pattern instance ID from ${t}`);return t.substring(e+1)}function ML(t,e,n=!1){trt(t,({node:r,actions:{setDescendantsContext:o},context:i})=>{let a=!n&&!i?.currentParentPatternInstanceId,l="_pattern"in r&&!!r._pattern;if(i?.currentParentPatternInstanceId){let d=LL(i.currentParentPatternInstanceId,r._id);r._id=d}let c=i?.currentParentPatternInstanceId;l&&(c=r._id),"_overrides"in r&&r._overrides&&i4e(r._overrides,c,a),"_patternOverrides"in r&&r._patternOverrides&&i4e(r._patternOverrides,c,a),l&&o({currentParentPatternInstanceId:r._id})},{initialContext:{currentParentPatternInstanceId:e}})}var i4e=(t,e,n)=>{Object.entries(t).forEach(([r,o])=>{let i=n?r:LL(e,r);Object.entries(o.slots??{}).forEach(([a,l])=>{l.forEach(c=>{let{partOfNestedPattern:d}=OL(r??"");ML(c,a===ert&&!d?void 0:e,!0)})}),i&&(delete t[r],t[i]=o)})};function OL(t){let e=t.split(qE);return e.length===1?{partOfPattern:void 0,partOfNestedPattern:void 0}:e.length===2?{partOfPattern:e[0],partOfNestedPattern:void 0}:{partOfPattern:e[0],partOfNestedPattern:e[e.length-2]}}import{CANVAS_SLOT_SECTION_SLOT as f4e}from"@uniformdev/canvas";import{CANVAS_VIZ_CONTROL_PARAM as irt}from"@uniformdev/canvas";import{CANVAS_ENRICHMENT_TAG_PARAM as s4e,CANVAS_INTENT_TAG_PARAM as nrt,CANVAS_LOCALE_TAG_PARAM as rrt,CANVAS_PERSONALIZATION_PARAM as l4e,CANVAS_TEST_VARIANT_PARAM as ort,CANVAS_VIZ_CONTROL_PARAM as u4e}from"@uniformdev/canvas";var c4e=[{id:nrt,name:"Intent Tag",type:"intentTag"},{id:rrt,name:"Locale Visibility",type:"localeSelect"},{id:l4e,name:"Personalization Criteria",type:l4e},{id:s4e,name:"Enrichment Tags",type:s4e,helpText:"Seeing this component will increase a visitor's score in these enrichments."},{id:ort,name:"A/B Test",type:"testVariant"},{id:u4e,name:"Visibility Control",type:u4e}];var art=c4e.reduce((t,e)=>(e.id===irt||t.add(e.id),t),new Set);function fC(t,e){return art.has(e)?"yes":t?.parameters?.[e]??"no"}function CZ(t,e){e&&Object.entries(e).forEach(([n,r])=>{let o=t[n];if((r.parameters||o?.parameters)&&(t[n]??={},t[n].parameters={...r?.parameters,...o?.parameters}),(r.dataResources||o?.dataResources)&&(t[n]??={},t[n].dataResources={...r?.dataResources,...o?.dataResources}),r.slots||o?.slots){t[n]??={};let i=Object.entries(o?.slots??{}).reduce((a,[l,c])=>(a[l]&&Array.isArray(a[l])?a[l]=[...c,...a[l]]:a[l]=c,a),r.slots??{});t[n].slots=i}(r.variant!==void 0||o?.variant!==void 0)&&(t[n]=t[n]??{},t[n].variant=o?.variant??r?.variant)})}function d4e({applyOverrideToNode:t}){let e=new Set,n={};return{visitNode(r){e.add(r._id),CZ(n,r._overrides),CZ(n,r._patternOverrides);let o=n[r._id];o&&(o.parameters&&Object.keys(o.parameters).forEach(i=>{fC(r._overridability,i)==="no"&&(console.log(`[Override] Cleaned override from ${r._id} parameter ${i} because it is not overridable`),delete n[r._id].parameters?.[i])}),o.dataResources&&Object.keys(o.dataResources).forEach(i=>{r._patternDataResources?.[i]?.isPatternParameter||(console.log(`[Override] Cleaned override from ${r._id} data resource ${i} because it is not overridable`),delete n[r._id].dataResources?.[i])}),o.variant!==void 0&&(r._overridability?.variants||delete o.variant),t({node:r,overrides:o}))},overrides:n}}function SZ(t){let{beforeApplyParameterOverride:e,beforeApplyDataResourceOverride:n}=t??{};return d4e({applyOverrideToNode({node:r,overrides:o}){if(Object.entries(o.parameters??{}).map(([i,a])=>{r.parameters=r.parameters??{},e?.(r,i,a,r.parameters[i]);let l=r.parameters[i]??={type:a.type};a.locales||a.localesConditions?(l.locales??={},delete l.value,delete l.conditions,new Set([...Object.keys(a.locales??{}),...Object.keys(a.localesConditions??{})]).forEach(f=>{delete l.locales?.[f],delete l.localesConditions?.[f];let m=a.locales?.[f],h=a.localesConditions?.[f];m!=null&&(l.locales??={},l.locales[f]=m),h!=null&&(l.localesConditions??={},l.localesConditions[f]=h)}),l.locales&&Object.keys(l.locales).length===0&&delete l.locales,l.localesConditions&&Object.keys(l.localesConditions).length===0&&delete l.localesConditions):(delete l.locales,delete l.localesConditions,delete l.conditions,delete l.value,a.value!==null&&a.value!==void 0&&(l.value=a.value,l.connectedData=a.connectedData),a.conditions!==null&&a.conditions!==void 0&&(l.conditions=a.conditions)),!l.locales&&!l.localesConditions&&!l.conditions&&l.value===void 0&&delete r.parameters[i]}),Object.entries(o.dataResources??{}).forEach(([i,a])=>{n?.(r,i,a,r._dataResources?.[i]),r._dataResources??={},r._dataResources[i]=a}),o.variant!==void 0&&(r.variant=o.variant),o.slots){r.slots??={};let i=Object.keys(o.slots)[0];r.slots[f4e]??=[],r.slots[f4e]=[...o.slots[i]??[]]}}})}import{CANVAS_SLOT_SECTION_SLOT as srt,CANVAS_SLOT_SECTION_TYPE as lrt}from"@uniformdev/canvas";var p4e=({preserveOwnSlotSections:t=!1,preserveChildrenSlotSections:e=!1}={})=>n=>{if(n.node.type!==lrt)return;let{partOfPattern:r,partOfNestedPattern:o}=OL(n.node._id??"");!r&&!o&&t||r&&!o&&e||urt(n)},urt=({node:t,type:e,actions:n})=>{e!=="entry"&&(n.insertAfter(t.slots?.[srt]??[]),n.remove())};import{walkNodeTree as frt}from"@uniformdev/canvas";import{produce as prt}from"immer";import{CANVAS_SLOT_SECTION_SLOT as m4e,walkNodeTree as crt}from"@uniformdev/canvas";import{produce as drt}from"immer";function h4e(t,e,n,r=Ba()){if(!t._pattern)throw new Error("Not a pattern");let o={};return crt(t,({node:i,ancestorsAndSelf:a,actions:l})=>{let c=i._id,d=e[c];if(a.length===1)i._id=r;else{let m=a[0];m.type!=="slot"||m.parentSlot!==m4e?(i._id=a4e(c),i._id=LL(r,i._id)):(l.replace({...o[c],_id:o[c]._id}),l.stopProcessingDescendants())}if(d){let m=drt(d,h=>{h.slots&&Object.entries(h.slots).forEach(([v,y])=>{if(v!==m4e)throw new Error("Only slot section items are supported for duplication");y.forEach((b,w)=>{if(!b._id)return;let C=RL(b,e,n);o[b._id]=C,y[w]=C})})});n?.(i._id,m,c)}}),r}function RL(t,e,n){return prt(t,r=>{frt(r,({type:o,node:i,actions:{stopProcessingDescendants:a}})=>{o==="component"&&i._pattern?(h4e(i,e,n),a()):i._id=Ba()})})}function AL({locale:t,conditionIndex:e,property:n}){if(t===void 0)if(e<0){if(delete n.value,!n.conditions?.length)return!1}else n.conditions?.splice(e,1);else e<0?delete n.locales?.[t]:n.localesConditions?.[t]?.splice(e,1);if(n.localesConditions){for(let[r,o]of Object.entries(n.localesConditions))if(o.length===0){delete n.localesConditions[r];break}Object.keys(n.localesConditions).length===0&&delete n.localesConditions}return n.locales&&Object.keys(n.locales).length===0&&delete n.locales,n.conditions&&n.conditions.length===0&&delete n.conditions,!!(n.value!==void 0||n.locales||n.conditions||n.localesConditions)}function wZ({locale:t,conditionIndex:e,conditionDefinition:n,property:r,newPropertyValue:o}){t===void 0?e<0?r.value=o:(r.conditions??=[],g4e(r.conditions,e,n,o)):e<0?(r.locales??={},r.locales[t]=o):(r.localesConditions??={},r.localesConditions[t]??=[],g4e(r.localesConditions[t],e,n,o))}function g4e(t,e,n,r){if(e<0)throw new Error("Condition index must be greater than or equal to 0");let o=t[e];t[e]={when:n??o?.when??{clauses:[]},value:r===void 0?null:r,id:o?.id??mrt(t)}}function mrt(t){let e=new Set(t.map(r=>r.id)),n=0;for(;e.has(n);)n++;return n}function v4e(t){let e=!1,n={};return"_pattern"in t&&t._patternDataResources&&Object.entries(t._patternDataResources).forEach(([r,o])=>{e=!0,n[r]={...o,source:"patternDataResource"}}),t._dataResources&&Object.entries(t._dataResources).forEach(([r,o])=>{n[r]?n[r].isPatternParameter&&(e=!0,n[r]={...o,source:"dataResource"}):(e=!0,n[r]={...o,source:"dataResource"})}),e?n:void 0}import{CANVAS_DRAFT_STATE as hrt,convertEntryToPutEntry as uVt,getPropertiesValue as fVt}from"@uniformdev/canvas";function y4e(t){let{fields:e,entryName:n,type:r="contentType",thumbnailField:o,...i}=t;return{...i,titleParameter:n,thumbnailParameter:o,parameters:e,canBeComposition:r==="block",permissions:t.permissions,useTeamPermissions:t.useTeamPermissions??!0,workflowId:t.workflowId}}function b4e(t){return{id:t.id,name:t.name,entryName:t.titleParameter,thumbnailField:t.thumbnailParameter,fields:t.parameters,icon:t.icon,description:t.description,slugSettings:t.slugSettings,type:t.canBeComposition?"block":"contentType",created:t.created,updated:t.updated,permissions:t.permissions,useTeamPermissions:t.useTeamPermissions,workflowId:t.workflowId||void 0}}function kL(t){let{entry:{fields:e,...n},...r}=t;return{created:"",modified:"",composition:{_id:"",...n,_name:t.entry._name??"Untitled",parameters:e,_overridability:t.entry._overridability,_overrides:t.entry._overrides,_pattern:t.entry._pattern,_patternError:t.entry._patternError},pattern:!!t.pattern,previewImageUrl:t.entry._thumbnail,...r}}function x4e(t,e,n,r,o,i,a){let l=a??e.projectId;if(!l)throw new Error("projectId is required in currentEntry or explicitly");return{created:"",modified:"",...e,projectId:l,state:r??e.state??hrt,releaseId:o??e.releaseId,workflowId:n?.workflowId??e.workflowId,workflowStageId:n?.workflowStageId??e.workflowStageId,editionId:i,editionName:n?.editionName??e.editionName,editionPriority:n?.editionPriority??e.editionPriority,entry:{type:t.type,_id:t._id,...e.entry,_thumbnail:n?.previewImageUrl??void 0,_name:t._name,_slug:t._slug??"",fields:t.parameters,_dataResources:t._dataResources,_pattern:t._pattern,_patternError:t._patternError,_overridability:t._overridability,_overrides:t._overrides,_locales:t._locales,_author:t._author,_authorSubject:t._authorSubject,_creator:t._creator,_creatorSubject:t._creatorSubject,_patternDataResources:t._patternDataResources}}}function EZ(t,e){let{parameters:n,...r}=t;return{...r,_id:e??r._id??"unknown",fields:n}}function TZ(t){let{fields:e,...n}=t;return{...n,parameters:e}}import{CANVAS_VIZ_LOCALE_RULE as grt}from"@uniformdev/canvas";import{produce as vrt}from"immer";function C4e(t,e,n){let r=vrt(t.criteria,o=>S4e(o,e,n));return r&&{...t,criteria:r}}function S4e(t,e,n){if(!t)return t;let r=!1;for(let o of t.clauses)if("clauses"in o){let i=S4e(o,e,n);if(i===null){if(t.op!=="|")return null;t.clauses.splice(t.clauses.indexOf(o),1),r=!0}else i!==void 0&&(t.clauses[t.clauses.indexOf(o)]=i,r=!0)}else if(o.rule===grt){let i=Array.isArray(o.value)?o.value:[o.value],a=i.includes(e),l=i.includes(n);if(!a&&!l||a&&l)continue;if(i.length===1&&l&&!a)return null;a&&!l&&(o.value=i.concat(n),r=!0)}return r?t:void 0}var w4e=J(mZ(),1);function _Z(t,e){try{return(0,w4e.get)(t,e)}catch{return}}function DZ(t,e,n=0){let r=t.slice(n*4,n*4+4);if(!r)throw new Error("Failed to generate a default variation name");return`${e.startsWith("$")?e.slice(1):e}-${r}`}import{CANVAS_VIZ_LOCALE_RULE as yrt}from"@uniformdev/canvas";import{produce as brt}from"immer";function E4e(t,e){let n=brt(t.criteria,r=>T4e(r,e));return n&&{...t,criteria:n}}function T4e(t,e){if(!t)return t;for(let n=t.clauses.length-1;n>=0;n--){let r=t.clauses[n];if("clauses"in r){let o=T4e(r,e);if(o)t.clauses[n]=o;else if(t.clauses.splice(n,1),o===null&&t.op!=="|")return null}else if(r.rule===yrt){let o=Array.isArray(r.value)?r.value:[r.value],i=o.indexOf(e);if(i!==-1)if(Array.isArray(r.value)&&r.value.length>1)o.splice(i,1);else if(r.op.startsWith("!"))t.clauses.splice(n,1);else return null}}if(t.clauses.length!==0)return t}function _4e(t){return{all:t=t||new Map,on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(o){o(n)}),(r=t.get("*"))&&r.slice().map(function(o){o(e,n)})}}}function D4e(t,e){let n=_4e();if(process.env.NODE_ENV==="development"&&!e){let r=new Error().stack?.split(`
5178
5178
  `).slice(2).join(`
5179
5179
  `).trimStart();n.on("*",(o,i)=>{console.debug(`\u26A1\uFE0F ${t}:${String(o)}`,{args:i,stack:r,subs:n.all.get(String(o))?.length??0})})}return n}var wu=(0,A4e.default)(),Ert=!0,Trt="Twee",Vh=class t{#e={};rootNodeId;#r={};#o={};#n;#i={};#t=D4e(Trt,Ert);#u;#c;#h;#d;#s;#a;#y;constructor(e,n){let{metadata:r,startDirty:o}=n||{};this.#s=r??{},this.#a={_name:e?._name??"",_slug:e?._slug??null},this.#d=!o,this.#y=n?.temp_disableDataResourceOverrideCreation??!1;let i=To(e,a=>{this.#v({composition:a,ignoreRootOverrides:!0,preserveChildrenSlotSections:!0}),delete a._author,delete a._authorSubject,delete a._creator,delete a._creatorSubject});this.rootNodeId=i._id??Ba(),this.#u=this.rootNodeId,this.#l({componentTree:i,nodeId:this.rootNodeId}),this.#n=i._overrides??{}}events=this.#t;exportTree(e){return this.exportSubtree(this.rootNodeId,e)}exportMetadata(){return this.#s}exportRootNodeMetadata(){return this.#a}get pristine(){return this.#d}set pristine(e){this.#d!==e&&(this.#d=e,this.#t.emit("pristineChanged",{pristine:e}))}get selectedBlockIdStack(){return this.#c}set selectedBlockIdStack(e){this.#c=e,this.#t.emit("selectedBlockChanged",{selectedBlockIds:this.#c})}get selectedNodeId(){return this.#u}set selectedNodeId(e){this.#u!==e&&(this.#u=e,this.selectedParameterId=void 0,this.#t.emit("selectedNodeChanged",{selectedNodeId:e}))}get selectedParameterId(){return this.#h}set selectedParameterId(e){this.#h!==e&&(this.#h=e,this.#t.emit("selectedParameterChanged",{selectedParameterId:e}))}pushSelectedBlockId(e){this.selectedBlockIdStack=this.selectedBlockIdStack??[],this.selectedBlockIdStack?.push(e),this.#t.emit("selectedBlockChanged",{selectedBlockIds:this.selectedBlockIdStack})}popSelectedBlockId(){this.#c?.pop(),this.#t.emit("selectedBlockChanged",{selectedBlockIds:this.selectedBlockIdStack})}getNodeById(e){return this.#e[e]}getNodesIndex(){return this.#e}getBlockNodeValueById(e){return EZ(this.exportSubtree(e),e)}getNodeChildren(e){let n=this.#r[e];if(n)return n}getNodeProperty(e,n){return _Z(this.#o,[e,n])}getNodeProperties(e){return this.#o[e]??{}}insertNode({node:e,parentNodeId:n,parentSlot:r,targetIndexInSlot:o,overrideNodeId:i}){let a=i??Ba(),l={nodeId:a,parentId:n,value:t.#T(e),isExpandedInUI:!0,propertyValueLocalizability:{}};return this.#w({node:l,parentNodeId:n,parentSlot:r,targetIndexInSlot:o}),this.#m({nodeId:a,destinationParentId:n,destinationSlotName:r}),this.pristine=!1,this.#t.emit("nodeChanged",{changedNode:l,oldValue:void 0,type:"new"}),this.#t.emit("childrenChanged",{parentId:n,slotOrBlockName:r,newChildIds:this.#r[n][r],type:"slot"}),a}upsertBlockNode({nodeId:e,property:n,index:r,entry:o}){let i=this.#E({nodeId:e,property:n,index:r,entry:o});return this.pristine=!1,this.#t.emit("childrenChanged",{parentId:e,slotOrBlockName:n,newChildIds:this.#o[e]?.[n]?.value,type:"block"}),i}updateRootMetadata(e){let n={...this.#s};this.#s={...this.#s,...e},this.pristine=!1,this.#t.emit("metadataChanged",{metadata:this.#s,oldValue:n})}updateRootNode({update:e,doNotSetDirty:n}){let r={...this.#a};this.#a={...this.#a,...e},n||(this.pristine=!1),this.#t.emit("rootNodeMetadataChanged",{metadata:this.#a,oldValue:r})}insertPattern({parentNodeId:e,parentSlot:n,pattern:r,targetIndexInSlot:o,patternInstanceId:i}){let a=this.#x(r,i??Ba());return this.#f({nodeId:a,parentNodeId:e,parentSlot:n,targetIndexInSlot:o}),this.#m({nodeId:a,destinationParentId:e,destinationSlotName:n}),this.pristine=!1,this.visitNodeAndDescendants(a,l=>{this.#t.emit("nodeChanged",{changedNode:l,oldValue:void 0,type:"new"})}),this.#t.emit("childrenChanged",{parentId:e,slotOrBlockName:n,newChildIds:this.#r[e][n],type:"slot"}),a}unlinkPattern(e){let n=this.#e[e];if(!n)throw new Error(`Node ${e} does not exist`);if(!n.value._pattern)throw new Error(`Node ${e} is not a pattern`);let r=n.value._patternDataResources||n.value._dataResources,o=v4e(n.value),i=l=>{l.partOfNestedPattern||(this.updateNode({nodeId:l.nodeId,updateComponent:c=>{delete c._pattern,delete c._patternError,delete c._overrides},updateMetadata:c=>{delete c.partOfPattern,delete c.partOfNestedPattern},doNotSetDirty:!0,ignoreOverrides:!0}),this.#n[l.nodeId]&&(this.#n=To(this.#n,c=>{delete c[l.nodeId]})))};this.visitNodeAndDescendants(e,i);let a=l=>{l.partOfNestedPattern&&this.updateNode({nodeId:l.nodeId,updateMetadata:c=>{c.partOfPattern=c.partOfNestedPattern,delete c.partOfNestedPattern},doNotSetDirty:!0,ignoreOverrides:!0})};this.visitNodeAndDescendants(e,a),r&&(this.updateNode({nodeId:this.rootNodeId,updateDataResources:l=>Object.entries(o??{}).filter(([c])=>!(c in(l??{}))).map(([c,d])=>{let{source:f,...m}=d;return{type:"set",name:c,value:m}})}),this.updateNode({nodeId:n.nodeId,updateComponent:l=>{delete l._patternDataResources},updateDataResources:"removeAll",doNotSetDirty:!0,ignoreOverrides:!0})),this.pristine=!1}convertToPattern({existingNodeId:e,pattern:n}){let r=this.#e[e],o=r?.parentId;if(!r)throw new Error(`Node ${e} does not exist`);let i=this.#x(n,e);this.#e[i]=To(this.#e[i],l=>{l.parentId=o}),this.pristine=!1;let a=this.#e[i];this.#t.emit("nodeChanged",{changedNode:a,oldValue:r,type:"new"}),Object.entries(this.#r[i]??{}).forEach(([l,c])=>{this.#t.emit("childrenChanged",{newChildIds:c,parentId:i,slotOrBlockName:l,type:"slot"})})}copyNodeToClipboard(e){let n=this.exportSubtree(e,{keepPatternData:!1}),r=this.exportSubtree(e,{keepPatternData:!0}),o=[];c0(r,({node:l})=>{l._id&&o.push(l._id)}),c0(n,({node:l})=>{l._id&&(l._overrides&&delete l._overrides,"_name"in l&&delete l._name,"_slug"in l&&delete l._slug)});let i=this.#g(),a=Object.entries(i??{}).reduce((l,[c,d])=>(o.some(f=>c.includes(f))&&(l[c]=d),l),{});return{format:"uniform/copied-component-subtree-1.0",componentData:n,overrides:Object.keys(a).length?a:void 0,pasteAs:this.getNodeById(e)?.isBlock?"block":void 0}}async pasteNodeFromClipboard({parentNodeId:e,parentSlot:n,targetIndexInParent:r,clipboard:o,resolvePattern:i}){let a=wu(o),l=async d=>{d._pattern&&c.push((async()=>{let f=await i(d._pattern);if(!f){console.debug(`Pasted pattern ${d._pattern} not found, skipping`);return}let m=this.#C(f,d._id);Object.assign(d,m)})())},c=[];return c0(a.componentData,({node:d})=>{l(d)}),a.overrides&&Object.values(a.overrides).forEach(d=>{d.slots&&Object.values(d.slots).forEach(f=>{f.forEach(m=>{c0(m,({node:h})=>{l(h)})})})}),await Promise.all(c),this.#_(a.componentData,{parentId:e,parentName:n,parentType:o.pasteAs==="block"?"block":"slot",targetIndexInParent:r},a.overrides)}enableLocale(e){this.updateNode({nodeId:this.rootNodeId,updateComponent:n=>{let r=n;r._locales??=[];let o=[...new Set([...r._locales,...Array.isArray(e)?e:[e]])];r._locales=o}})}disableLocale(e){this.updateNode({nodeId:this.rootNodeId,updateComponent:o=>{let i=o;i._locales=i._locales?.filter(a=>a!==e)}});let n=[],r=o=>{this.getNodeProperty(o.nodeId,JE)?.value===e&&!o.partOfPattern&&n.push(o.nodeId);let a=this.getNodeProperties(o.nodeId);Object.entries(a).forEach(([c,d])=>{let f=d;c!==u0&&(o.partOfPattern?this.isPatternPropertyOverridden(o.nodeId,c,e)&&this.resetPatternPropertyOverride(o.nodeId,c,e):(f?.localesConditions?.[e]?.forEach((m,h)=>{this.updateNodeProperty({nodeId:o.nodeId,property:c,value:void 0,source:"other",locale:e,conditionIndex:h,conditionDefinition:null})}),f?.locales?.[e]!==void 0&&this.updateNodeProperty({nodeId:o.nodeId,property:c,value:void 0,source:"other",locale:e,conditionIndex:-1})))});let l=this.getNodeProperty(o.nodeId,u0);if(l?.value){let c=E4e(l.value,e);c===null?n.push(o.nodeId):this.updateNodeProperty({nodeId:o.nodeId,property:u0,value:c?()=>c:void 0,source:"other",locale:void 0,conditionIndex:-1})}};this.visitNodeAndDescendants(this.rootNodeId,r),n.forEach(o=>{this.deleteNode(o)})}copyValuesToLocalePlan({sourceLocale:e,destinationLocale:n,doNotCopyDescendants:r=!1,startingNodeId:o=this.rootNodeId,specificPropertyId:i}){let a=new Map,l=d=>{if(d.value.type===xrt&&!d.partOfPattern){let m=this.getNodeChildren(d.nodeId)?.[$Z]??[],h=m.map(b=>this.getNodeProperty(b,JE)),v=h.findIndex(b=>b?.value===n);if(v>=0){let b=m[v];zh(a,b).actions.push({type:"deleteLocalizedNode"})}let y=h.findIndex(b=>b?.value===e);if(y>=0){let b=m[y];zh(a,b).actions.push({type:"duplicateLocalizedNode",targetIndexInSlot:v})}}if(a.get(d.nodeId)?.actions.some(m=>m.type==="deleteLocalizedNode"))return;let f=i?{[i]:this.getNodeProperty(d.nodeId,i)}:this.getNodeProperties(d.nodeId);Object.entries(f).forEach(([m,h])=>{if(h===void 0)return;let v=!d.partOfPattern,y=fC(d.value._overridability,m)==="yes";if(!(v||y))return;if(m===u0){let $=C4e(h.value,e,n);$===null?zh(a,d.nodeId).actions.push({type:"deleteLocalizedNode"}):$&&zh(a,d.nodeId).actions.push({type:"updateVisibilityCriteria",targetValue:$})}let w=h.locales?.[e],C=h.locales?.[n];(!w||!C||!YE(w,C))&&(w!==void 0?zh(a,d.nodeId).actions.push({type:"copyPropertyValue",propertyId:m,sourceValue:w,targetValue:C,conditionIndex:-1}):C!==void 0&&zh(a,d.nodeId).actions.push({type:"deletePropertyValue",propertyId:m,sourceValue:w,targetValue:C,conditionIndex:-1}));let S=h.localesConditions?.[e],E=h.localesConditions?.[n];S?.forEach(($,O)=>{let M=h.localesConditions?.[n]?.[O];(!$||!M||!YE($,M))&&zh(a,d.nodeId).actions.push({type:"copyPropertyValue",propertyId:m,sourceValue:$.value,targetValue:M,conditionIndex:O,conditionDefinition:$.when})});let _=S?.length??0,N=E?.length??0;if(_<N){let $=zh(a,d.nodeId);for(let O=_;O<N;O++)$.actions.push({type:"deletePropertyValue",propertyId:m,sourceValue:S?.[O],targetValue:E?.[O],conditionIndex:O})}})},c=this.#e[o];if(!c)throw new Error(`Node ${o} does not exist`);return l(c),!i&&!r&&this.visitDescendants(c.nodeId,l),{nodePlans:Array.from(a.values()),sourceLocale:e,destinationLocale:n}}async copyValuesToLocaleExecute({resolvePattern:e,plan:{sourceLocale:n,destinationLocale:r,nodePlans:o}}){let i=`copyLocaleExecute: ${r}`;console.time(i);for(let{nodeId:a,actions:l}of o)for(let c of l)switch(c.type){case"copyPropertyValue":{this.updateNodeProperty({nodeId:a,property:c.propertyId,source:"other",locale:r,value:()=>c.sourceValue,type:this.getNodeProperty(a,c.propertyId)?.type,conditionIndex:c.conditionIndex,conditionDefinition:c.conditionDefinition});break}case"deletePropertyValue":{this.updateNodeProperty({nodeId:a,property:c.propertyId,source:"other",locale:r,value:void 0,conditionIndex:c.conditionIndex,conditionDefinition:null});break}case"deleteLocalizedNode":{this.deleteNode(a);break}case"duplicateLocalizedNode":{let d=await this.duplicateNode(a,e);this.updateNodeProperty({nodeId:d,locale:void 0,conditionIndex:-1,type:"localeSelect",property:JE,source:"other",value:()=>r});let f=this.copyValuesToLocalePlan({sourceLocale:n,destinationLocale:r,startingNodeId:d});this.copyValuesToLocaleExecute({plan:f,resolvePattern:e}),c.targetIndexInSlot!==void 0&&this.moveNode({movedNodeId:d,parentNodeId:this.#e[a].parentId,parentSlot:$Z,targetIndexInSlot:c.targetIndexInSlot});break}case"updateVisibilityCriteria":{this.updateNodeProperty({nodeId:a,property:u0,source:"other",locale:void 0,conditionIndex:-1,value:()=>c.targetValue});break}default:throw new Error(`Unhandled action type ${c.type}`)}console.timeEnd(i)}updateNode({nodeId:e,updateComponent:n,updateDataResources:r,updateMetadata:o,doNotSetDirty:i,ignoreOverrides:a}){let l=this.#e[e];if(!l)throw new Error(`Update target node ID ${e} did not exist!`);let c=To(l,h=>{if(o&&(o(h),h.nodeId=e,h.value=l.value,h.parentId=l.parentId),n){if(n(h.value),"slots"in h.value)throw new Error("Do not set `slots` on a Twee node, insert child nodes instead.");if("parameters"in h.value)throw new Error("Do not set `parameters` on a Twee node, use updateProperties option instead.")}if(r){let v=typeof r=="function"?r(h.value._dataResources):r;if(v==="removeAll")delete h.value._dataResources;else for(let y of v){let b=this.#y||a?!1:h.nodeId!==this.rootNodeId&&h.value._pattern;switch(y.type){case"set":b&&(this.#n=To(this.#n,w=>{w[e]??={},w[e].dataResources??={},w[e].dataResources[y.name]=y.value})),h.value._dataResources??={},h.value._dataResources[y.name]=y.value;break;case"remove":b&&(this.#n=To(this.#n,w=>{delete w[e]?.dataResources?.[y.name]})),delete h.value._dataResources?.[y.name];break;case"reset":{let w=this.#i[e]?.dataResources?.[y.name];h.value._dataResources&&(w&&Object.keys(w).length>0?h.value._dataResources[y.name]=w:delete h.value._dataResources[y.name]),this.#n=To(this.#n,C=>{delete C[e]?.dataResources?.[y.name]})}break;default:throw new Error(`Unhandled data resource action ${y?.type}`)}}}}),d=!!(l.partOfPattern&&!l.value._patternError),f=l.value.variant!==c.value.variant,m=l.value._overridability?.variants??!1;!a&&d&&f&&m&&(this.#n=To(this.#n,h=>{h[e]??={},h[e].variant=c.value.variant})),this.#e[e]=c,i||(this.pristine=!1),this.#t.emit("nodeChanged",{changedNode:c,type:"update",oldValue:l})}updateNodeProperty({nodeId:e,property:n,value:r,source:o,locale:i,type:a,doNotSetDirty:l=!1,ignoreOverrides:c=!1,conditionIndex:d,conditionDefinition:f}){let m=this.#e[e];if(!m)throw new Error(`Update target node ID ${e} did not exist!`);if(d<0&&f)throw new Error("Condition definition provided for non-conditional value");let h=!!(m.partOfPattern&&!m.value._patternError),v=[e,n],y=_Z(this.#o,v);if(!y&&r==null)return;let b=O4e({locale:i,property:y,conditionIndex:d}),w=i?y?.localesConditions?.[i]?.[d]:y?.conditions?.[d],C=typeof r=="function"?To(b,$=>r($)):r,S=a??y?.type;if(!S)throw new Error(`Cannot add parameter ${n} to node ${e} without specifying a type`);let E={...y,type:S},_=!1;E=To(E,$=>{C===void 0&&d<0?_=!AL({locale:i,property:$,conditionIndex:d}):f===null&&d>=0?_=!AL({locale:i,property:$,conditionIndex:d}):wZ({locale:i,property:$,newPropertyValue:C,conditionIndex:d,conditionDefinition:f??w?.when??{clauses:[]}})}),_&&(E=void 0);let N=h&&fC(m.value._overridability,n)==="yes";if(h&&!N&&!c)throw new Error(`Cannot override parameter ${n} on node ${e} because it is not marked as overridable on the pattern (${m.partOfPattern})`);if(N&&(this.#i[e]?.parameters?.[n]||(this.#i=To(this.#i,O=>{O[e]??={parameters:{},dataResources:{}},O[e].parameters[n]=y??null}))),!c&&N){let $=this.#n[e]?.parameters?.[n];this.#n=To(this.#n,O=>{let k=C==null||E===void 0?null:C,A=$??{type:E?.type??y?.type??"unknown",value:y?.value,conditions:y?.conditions,locales:i&&y?.locales?.[i]?{[i]:y.locales[i]}:void 0,localesConditions:i&&y?.localesConditions?.[i]?{[i]:y.localesConditions[i]}:void 0},F=To(A,U=>{f===null&&d>=0?AL({locale:i,property:U,conditionIndex:d}):wZ({locale:i,property:U,newPropertyValue:k,conditionIndex:d,conditionDefinition:f??w?.when??{clauses:[]}})});(0,d0.set)(O,`/${e}/parameters/${n}`,F)}),$||this.#t.emit("propertyOverrideCreated",{nodeId:e,property:n})}C===null?(0,d0.remove)(this.#o,v):(this.#o[e]??={},(0,d0.set)(this.#o,v,E)),l||(this.pristine=!1),this.#t.emit("nodeParameterChanged",{nodeId:e,parameter:n,locale:i,conditionIndex:d,value:E,previousValue:y,type:r?y?"update":"new":"delete",conditionDefinition:f,source:o})}isPatternPropertyOverridden(e,n,r,o){let i=this.getNodeById(e);if(!i||fC(i.value._overridability,n)==="no")return!1;let a=this.#n[e]?.parameters?.[n];return a?r?(o===void 0||o===!0)&&a.localesConditions?.[r]!==void 0||(o===void 0||o===!1)&&a.locales?.[r]!==void 0:(o===void 0||o===!0)&&a.conditions!==void 0||(o===void 0||o===!1)&&a.value!==void 0:!1}getPatternPropertyOverrideDefaultValue(e,n,r){let o=this.#i[e]?.parameters?.[n];if(!o)return{exists:!1};if(r&&o.locales?.[r])return{exists:!0,value:o,sourceLocale:r};if(o.value)return{exists:!0,value:o,sourceLocale:void 0};let i=Object.keys(o.locales??{})[0];return i?{exists:!0,value:o,sourceLocale:i}:{exists:!1}}resetPatternPropertyOverride(e,n,r){let o=[-1];this.#n=To(this.#n,a=>{let l=a[e]?.parameters?.[n];if(l)if(r){delete l.locales?.[r];let c=l.localesConditions?.[r];c&&(c.forEach((d,f)=>{o.push(f)}),delete l.localesConditions?.[r]),l.locales&&Object.keys(l.locales).length===0&&delete l.locales,l.localesConditions&&Object.keys(l.localesConditions).length===0&&delete l.localesConditions,Object.keys(l.locales??{}).length===0&&Object.keys(l.localesConditions??{}).length===0&&delete a[e]?.parameters?.[n]}else{let c=l.conditions;c&&c.forEach((d,f)=>{o.push(f)}),delete a[e].parameters?.[n]}});let i=this.getPatternPropertyOverrideDefaultValue(e,n,r);!i.exists||i.value===null?this.updateNodeProperty({nodeId:e,property:n,value:void 0,source:"reset",locale:r,ignoreOverrides:!0,doNotSetDirty:!1,conditionIndex:-1}):o.forEach(a=>{let l=O4e({locale:i.sourceLocale,property:i.value,conditionIndex:a,strict:!0});this.updateNodeProperty({nodeId:e,property:n,value:l===void 0?void 0:()=>l,source:"reset",locale:r,type:i.value?.type,ignoreOverrides:!0,doNotSetDirty:!1,conditionIndex:a,conditionDefinition:(r?i.value?.localesConditions?.[r]?.[a]?.when:i.value?.conditions?.[a]?.when)??null})}),this.#t.emit("propertyOverrideReset",{nodeId:e,property:n,usedPatternDefault:i!==void 0})}async duplicateNode(e,n){let r=this.getParentInfo(e);if(!r)throw new Error("Cannot duplicate root node or parentless block");let o=this.copyNodeToClipboard(e);return await this.pasteNodeFromClipboard({parentNodeId:r.parentId,parentSlot:r.parentName,resolvePattern:n,targetIndexInParent:r.targetIndexInParent+1,clipboard:o})}moveNode({movedNodeId:e,parentNodeId:n,parentSlot:r,targetIndexInSlot:o}){if(!this.#e[e])throw new Error(`Cannot move node ${e} - it does not exist`);let a=this.getParentInfo(e);if(!a)throw new Error("Cannot move root node");this.#r[a.parentId][a.parentName].splice(a.targetIndexInParent,1),this.#b(a.parentId,e),this.#f({nodeId:e,parentNodeId:n,parentSlot:r,targetIndexInSlot:o}),this.#m({nodeId:e,destinationParentId:n,destinationSlotName:r,sourceSlotName:a.parentName}),this.pristine=!1,this.#t.emit("childrenChanged",{parentId:n,slotOrBlockName:r,newChildIds:this.#r[n][r],type:"slot"}),this.#t.emit("childrenChanged",{parentId:a.parentId,slotOrBlockName:a.parentName,newChildIds:this.#r[a.parentId][a.parentName],type:"slot"})}deleteNode(e,n){let r=this.getParentInfo(e);if(!r&&!n)throw new Error("Cannot delete root node");r&&!n&&(this.#r[r.parentId][r.parentName].splice(r.targetIndexInParent,1),this.#r[r.parentId][r.parentName].length===0&&delete this.#r[r.parentId][r.parentName],this.selectedNodeId===e&&(this.selectedNodeId=r.parentId),this.#b(r.parentId,e),this.#t.emit("childrenChanged",{parentId:r.parentId,slotOrBlockName:r.parentName,newChildIds:this.#r[r.parentId][r.parentName]??[],type:"slot"})),delete this.#e[e],this.#t.emit("nodeDeleted",{deletedNodeId:e}),this.pristine=!1}#b(e,n){this.#n=To(this.#n,r=>{let o=r[e]?.slots;o&&Object.keys(o).forEach(i=>{o[i]=o[i].filter(({_id:a})=>a!==n),o[i].length===0&&delete o[i]})})}#g(){if(Object.keys(this.#n).length>0){let e=wu(this.#n);return Object.entries(e).forEach(([r,o])=>{let i=!0;if(!this.#e[r]){delete e[r];return}if(o.parameters){let a=Object.entries(o.parameters);a.forEach(([l,c])=>{let d=R4e(c);d?(o.parameters[l]=d,i=!1):delete o.parameters[l]}),a.length===0&&delete o.parameters}o.slots&&Object.entries(o.slots).forEach(([l,c])=>{if(c.length){let d=c.filter(f=>f._id).map(f=>this.exportSubtree(f._id));d?(o.slots[l]=d,i=!1):delete o.slots[l]}else delete o.slots[l]}),o.variant!==void 0&&(i=!1),o.dataResources&&Object.keys(o.dataResources).length>0&&(i=!1),i&&delete e[r]}),Object.keys(e).length===0&&(e=void 0),e}}exportSubtree(e,n){let{keepPatternData:r=!1}=n??{},o=this.#e[e];if(!o)throw new Error(`Node ${e} to export is not found`);let i=wu(o);if(e===this.rootNodeId){let c=this.#g();c?i.value._overrides=c:delete i.value._overrides;let d=i.value;d._name=this.#a._name,this.#a._slug&&(d._slug=this.#a._slug)}let a=[i],l=new Set;for(;a.length>0;){let c=a.pop();if(l.has(c.nodeId))throw new Error("Circular reference detected in the composition tree with node ID "+c.nodeId);if(l.add(c.nodeId),c.value._id=c.nodeId,!r&&(delete c.value._patternDataResources,delete c.value._patternOverrides,c.value._pattern&&c.value._dataResources)){let m=!1;Object.keys(c.value._dataResources).forEach(h=>{i.value._overrides?.[c.nodeId]?.dataResources?.[h]?delete c.value._dataResources[h]:m=!0}),m||delete c.value._dataResources}let d=this.#o[c.nodeId];if(d&&(r||!c.partOfPattern)){let m={},h=!1;Object.entries(d).forEach(([v,y])=>{if(y?.type===Sc&&Array.isArray(y.value)){let b=y.value,w=[];b.forEach(C=>{let S=this.exportSubtree(C,n);w.push(EZ(S,C))}),m[v]={value:w,type:Sc},h=!0}else{let b=R4e(y);b&&(m[v]=b,h=!0)}}),h&&(c.value.parameters=m)}let f=this.#r[c.nodeId];!f||c.partOfPattern&&!r||Object.entries(f).forEach(([m,h])=>{h.forEach((v,y)=>{let b=this.#e[v];if(!b)throw new Error("Insanity detected.");let w=wu(b),C=c.value;C.slots=C.slots||{},(0,d0.set)(c,["value","slots",m,y.toString(10)],w.value),a.push(w)})})}return i.value}#w({parentNodeId:e,parentSlot:n,targetIndexInSlot:r,node:o}){if(!this.#e[e])throw new Error("Parent ID to insert under did not exist!");this.#e[o.nodeId]=o,this.#f({nodeId:o.nodeId,parentNodeId:e,parentSlot:n,targetIndexInSlot:r})}#f({nodeId:e,parentNodeId:n,parentSlot:r,targetIndexInSlot:o}){let i=this.#e[n],a=this.#r[n]??={},l=a[r]??=[];typeof o<"u"?l.splice(o,0,e):l.push(e),i?.value.type===NZ&&(this.#n=To(this.#n,c=>{c[n]=c[n]??{},c[n].slots={[Crt]:l.map(d=>({_id:d,type:this.#e[d].value.type}))}})),this.#e[e]=To(this.#e[e],c=>{c.parentId=n})}#E({nodeId:e,property:n,index:r,entry:o}){let i=this.getNodeById(e);if(!i)throw new Error("Node doesn't exist");let l={nodeId:o._id??Ba(),value:{type:o.type,_dataResources:o._dataResources},isBlock:!0,parentId:e,propertyValueLocalizability:{}},c=this.getNodeProperty(i.nodeId,n);if(c&&c.type!==Sc)throw new Error("Parameter already exists and isn't a block parameter");let d=this.#e[l.nodeId];this.#e[l.nodeId]=l;let f=wu(this.getNodeProperty(i.nodeId,n)?.value?.filter(m=>this.getNodeById(m))??[]);if(typeof r<"u"){if(r<0)throw new Error("parameter index cannot be less than 0");let m=-1;if(f.forEach((h,v)=>{h===l.nodeId&&(m=v)}),r>f.length+(m===-1?1:0))throw new Error(`Parameter index ${r} outside current index bounds.`);m>-1&&m!==r&&(f=f.filter(h=>h!==l.nodeId),f.splice(r,0,l.nodeId))}else f.push(l.nodeId);return Object.entries(o?.fields??{}).forEach(([m,h])=>{if(h.type===Sc&&Array.isArray(h.value)){let v=h.value,y=[];v.forEach(b=>{this.#l({nodeId:l.nodeId,componentTree:TZ(b)}),y.push(b._id)}),this.updateNodeProperty({nodeId:l.nodeId,property:m,type:h.type,value:()=>y,source:"other",locale:void 0,conditionIndex:-1})}else this.updateNodeProperty({nodeId:l.nodeId,property:m,type:h.type,value:()=>h.value,source:"other",locale:void 0,conditionIndex:-1})}),this.updateNodeProperty({nodeId:i.nodeId,property:n,type:Sc,value:()=>f,source:"other",locale:void 0,conditionIndex:-1}),this.#t.emit("nodeChanged",{changedNode:i,oldValue:void 0,type:d?"update":"new"}),this.#t.emit("nodeParameterChanged",{nodeId:i.nodeId,parameter:n,previousValue:c,source:"other",type:d?"update":"new",locale:void 0,conditionIndex:-1,conditionDefinition:void 0,value:{type:Sc,value:f}}),{blockIds:f}}#l({componentTree:e,nodeId:n,partOfPattern:r,partOfNestedPattern:o,resetUids:i,isBlock:a}){let{slots:l,parameters:c,_id:d,_overrides:f,...m}=e,h=r??m._pattern,v=m._pattern&&m._pattern!==h?m._pattern:o,y={nodeId:n??(i?void 0:d)??Ba(),value:m,partOfPattern:h,partOfNestedPattern:v,isBlock:a,propertyValueLocalizability:Object.entries(c??{}).reduce((b,[w,C])=>(b[w]=Y_({definition:void 0,currentValue:C,lastUserChoice:void 0}),b),{})};return h&&(y.partOfPattern=h),this.#e[y.nodeId]=y,c&&Object.entries(c).forEach(([b,w])=>{let{connectedData:C,...S}=w,E=C?wrt(Srt(C)):w.value;if(w?.type===Sc&&Array.isArray(E)){let _=E,N=[];_?.forEach($=>{let O={...$,_id:i?Ba():$._id??Ba()};return N.push(O._id),this.#e[O._id]={nodeId:O._id,value:{type:Sc},propertyValueLocalizability:{}},this.#l({componentTree:TZ(O),nodeId:O._id}),this.#e[O._id].isBlock=!0,this.#e[O._id].parentId=y.nodeId,this.#e[O._id]}),E=N}this.#o[y.nodeId]=this.#o[y.nodeId]??{},(0,d0.set)(this.#o,[y.nodeId,b],{...S,value:E})}),l&&Object.entries(l).forEach(([b,w])=>{let C=w.map(S=>{if(this.#e[S._id??""]?.isBlock)return;let E=this.#l({componentTree:S,partOfPattern:m.type===NZ?void 0:h,partOfNestedPattern:m.type===NZ?void 0:v,resetUids:i});return this.#e[E].parentId=y.nodeId,E});this.#r[y.nodeId]=this.#r[y.nodeId]??{},this.#r[y.nodeId][b]=C.filter(S=>S)}),y.nodeId}#x(e,n){let r=this.#C(e,n);return this.#l({componentTree:r,nodeId:n})}#C(e,n){let r=wu(e);return this.#v({composition:r}),ML(r,n),r._pattern=e._id,delete r._id,delete r._name,delete r._slug,delete r._overrides,delete r._locales,delete r._author,delete r._authorSubject,delete r._creator,delete r._creatorSubject,r._dataResources&&(r._patternDataResources=wu(r._dataResources),delete r._dataResources),r}getParentInfo(e){let{parentId:n,isBlock:r}=this.#e[e]??{};if(!n)return;let o=this.#e[n];if(o)if(r)for(let[i,a]of Object.entries(this.#o[n]??{})){if(a?.type!==Sc)continue;let l=Array.isArray(a.value)?a.value:[],c=l.indexOf(e);if(c>=0)return{value:o.value,parentId:n,parentName:i,targetIndexInParent:c,parentChildIds:l,parentType:"block"}}else{let i=this.#r[n];if(!i&&!r)throw new Error("Sanity failed; parent had no children!");for(let[a,l]of Object.entries(i??{})){let c=l.indexOf(e);if(c>=0)return{value:o.value,parentId:n,parentName:a,targetIndexInParent:c,parentChildIds:l,parentType:"slot"}}return}}static#T(e){return To(e,r=>{delete r.slots,delete r.parameters})}#_(e,n,r){let i={...this.#g(),...r},a;if(this.#n=To(this.#n,c=>{this.#i=To(this.#i,d=>{a=RL(e,i,(f,m,h)=>{c[f]=m,d[f]=this.#i[h]})})}),!a)throw new Error("Failed to duplicate component");a=To(a,c=>{c._overrides=wu(this.#n),this.#v({composition:c,preserveChildrenSlotSections:!0})});let l=this.#l({componentTree:a,isBlock:n.parentType==="block"});if(n.parentType==="block"){let c=this.getNodeProperty(n.parentId,n.parentName)?.value??[],d=[...c.slice(0,n.targetIndexInParent),l,...c.slice(n.targetIndexInParent)];this.updateNodeProperty({nodeId:n.parentId,property:n.parentName,type:Sc,value:()=>d,locale:void 0,conditionIndex:-1,source:"other"}),this.#e[l].parentId=n.parentId,this.#t.emit("nodeChanged",{changedNode:this.getNodeById(l),type:"new",oldValue:void 0}),this.#t.emit("childrenChanged",{parentId:n.parentId,slotOrBlockName:n.parentName,newChildIds:d,type:"block"})}else{this.#f({nodeId:l,parentNodeId:n.parentId,parentSlot:n.parentName,targetIndexInSlot:n.targetIndexInParent}),this.#m({nodeId:l,destinationParentId:n.parentId,destinationSlotName:n.parentName}),this.#t.emit("childrenChanged",{parentId:n.parentId,slotOrBlockName:n.parentName,newChildIds:this.#r[n.parentId][n.parentName],type:"slot"});let c=d=>{this.#t.emit("nodeChanged",{changedNode:d,type:"new",oldValue:void 0})};this.visitNodeAndDescendants(l,c)}return this.pristine=!1,l}#v({composition:e,ignoreRootOverrides:n,preserveChildrenSlotSections:r}){this.#i=To(this.#i,i=>{let a=SZ({beforeApplyParameterOverride(d,f,m){i[d._id]??={parameters:{},dataResources:{}},i[d._id].parameters[f]=wu(m)},beforeApplyDataResourceOverride(d,f,m){d._dataResources?.[f]?.ignorePatternParameterDefault||(i[d._id]??={parameters:{},dataResources:{}},i[d._id].dataResources[f]=wu(m))}}),l=SZ({beforeApplyParameterOverride(d,f,m,h){i[d._id]?.parameters[f]||(i[d._id]??={parameters:{},dataResources:{}},i[d._id].parameters[f]=wu(h??null))},beforeApplyDataResourceOverride(d,f,m,h){d._dataResources?.[f]?.ignorePatternParameterDefault||i[d._id]?.dataResources[f]||(i[d._id]??={parameters:{},dataResources:{}},i[d._id].dataResources[f]=wu(h))}});if(n){let{_overrides:d,...f}=e;c0(f,({node:m})=>{a.visitNode(m)})}let c=n?l:a;c0(e,({node:d})=>{c.visitNode(d)})});let o=p4e({preserveOwnSlotSections:!0,preserveChildrenSlotSections:r});c0(e,i=>{o(i)})}visitNodeAndDescendants(e,n){let r=this.getNodeById(e);if(!r)throw new Error("Insanity detected.");n(r),this.visitDescendants(e,n)}visitDescendants(e,n){let r=this.#p(e,new Set);for(let o of r)n(...o)}async visitDescendantsAsync(e,n){let r=this.#p(e,new Set);for(let o of r)await n(...o)}*#p(e,n){let r=this.#e[e],o=this.#r[e]??{},i=Object.entries(this.#o[e]??{}).filter(([,a])=>a?.type===Sc)??[];if(!r)throw new Error("Insanity detected.");n.add(e);for(let[a,l]of i){let c=l.value??[];for(let d=0;d<c.length;d++){let f=c[d],m=this.#e[f];if(m){if(n.has(f)){console.error(`Detected parent/child cycle in composition, ID ${f} exists more than once. The traversal of descendants will be aborted for the cycle subtree.`);continue}yield[m,r,a,d];for(let h of this.#p(f,n))yield h}}}for(let[a,l]of Object.entries(o))for(let c=0;c<l.length;c++){let d=l[c],f=this.#e[d];if(f){if(n.has(d)){console.error(`Detected parent/child cycle in composition, ID ${d} exists more than once. The traversal of descendants will be aborted for the cycle subtree.`);continue}yield[f,r,a,c];for(let m of this.#p(d,n))yield m}}}#m({nodeId:e,destinationParentId:n,destinationSlotName:r,sourceSlotName:o}){let i=r,a=o===N4e,l=i===N4e,c=o===L4e,d=i===L4e,f=i===$Z,m=this.getNodeProperty(e,$4e);l&&m&&this.updateNodeProperty({nodeId:e,property:$4e,value:void 0,source:"other",locale:void 0,conditionIndex:-1});let h=this.getNodeProperty(e,XE);!l&&h&&this.updateNodeProperty({nodeId:e,property:XE,value:void 0,source:"other",locale:void 0,conditionIndex:-1}),l&&!a&&this.#S({nodeId:e,siblingIds:this.getNodeChildren(n)?.[r]??[],selectExistingName:b=>this.getNodeProperty(b,XE)?.value?.name,setName:b=>this.updateNodeProperty({nodeId:e,property:XE,value:w=>w&&typeof w=="object"&&w!==null?{...w,name:b}:{name:b,crit:[]},source:"other",locale:void 0,conditionIndex:-1,type:XE})}),d&&!c&&this.#S({nodeId:e,siblingIds:this.getNodeChildren(n)?.[r]??[],selectExistingName:b=>this.getNodeProperty(b,M4e)?.value?.id,setName:b=>this.updateNodeProperty({nodeId:e,property:M4e,value:w=>w&&typeof w=="object"&&w!==null?{...w,id:b}:{id:b},source:"other",locale:void 0,conditionIndex:-1,type:"testVariant"})});let v=this.getNodeProperty(e,JE);!f&&v&&this.updateNodeProperty({nodeId:e,property:JE,value:void 0,source:"other",locale:void 0,conditionIndex:-1});let y=this.getNodeProperty(e,u0);(l||f||d)&&y&&this.updateNodeProperty({nodeId:e,property:u0,value:void 0,source:"other",locale:void 0,conditionIndex:-1})}#S({nodeId:e,siblingIds:n,selectExistingName:r,setName:o}){let i=r(e),a=m=>n.some(h=>h===e?!1:r(h)===m),l=i&&a(i);if(i&&!l)return;let c=this.getNodeById(e)?.value.type;if(!c)throw new Error("Insanity detected.");let d=0,f=DZ(e,c,d);do f=DZ(e,c,d),d++;while(a(f));o(f)}};function R4e(t){return t?.value===void 0&&!t?.conditions&&!t?.locales&&!t?.localesConditions?null:t}function zh(t,e){return _rt(t,e,()=>({nodeId:e,actions:[]}))}function _rt(t,e,n){return t.has(e)||t.set(e,n()),t.get(e)}import{CANVAS_DRAFT_STATE as MZ,CanvasClient as Nrt}from"@uniformdev/canvas";var k4e=J(QSe());var P4e=(0,k4e.default)(6),PL=class t extends Error{constructor(n,r,o,i,a,l){super(`${n}
5180
5180
  ${i}${a?" "+a:""} (${r} ${o}${l?` Request ID: ${l}`:""})`);this.errorMessage=n;this.fetchMethod=r;this.fetchUri=o;this.statusCode=i;this.statusText=a;this.requestId=l;Object.setPrototypeOf(this,t.prototype)}};var IL=class t{options;constructor(e){if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let n=e.fetch;if(!n)if(typeof window<"u")n=window.fetch.bind(window);else if(typeof fetch<"u")n=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:n,apiHost:this.ensureApiHost(e.apiHost),apiKey:e.apiKey??null,projectId:e.projectId??null,bearerToken:e.bearerToken??null,limitPolicy:e.limitPolicy??P4e,bypassCache:e.bypassCache??!1}}async apiClient(e,n){return(await this.apiClientWithResponse(e,n)).body}async apiClientWithResponse(e,n){return this.options.limitPolicy(async()=>{let r=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(r["x-bypass-cache"]="true");let{fetch:o,signal:i}=this.options,l=await Drt(()=>o(e.toString(),{...n,signal:i,headers:{...n?.headers,...r}}));if(!l.ok){let c="";try{let d=await l.text();try{let f=JSON.parse(d);f.errorMessage?c=Array.isArray(f.errorMessage)?f.errorMessage.join(", "):f.errorMessage:c=d}catch{c=d}}catch{c="General error"}throw new PL(c,n?.method??"GET",e.toString(),l.status,l.statusText,t.getRequestId(l))}return n?.expectNoContent?{response:l,body:null}:{response:l,body:await l.json()}})}createUrl(e,n,r){let o=new URL(`${r??this.options.apiHost}${e}`);return Object.entries(n??{}).forEach(([i,a])=>{typeof a<"u"&&a!==null&&o.searchParams.append(i,Array.isArray(a)?a.join(","):a?.toString()??"")}),o}ensureApiHost(e){if(!e)return"https://uniform.app";if(!e?.startsWith("http"))throw new Error('Your apiHost must start with "http"');if(e.indexOf("/",8)>-1)throw new Error("Your apiHost must not contain a path element after the domain");if(e.indexOf("?")>-1)throw new Error("Your apiHost must not contain a query string");return e?.endsWith("/")&&(e=e.substring(0,e.length-1)),e}static getRequestId(e){let n=e.headers.get("apigw-requestid");if(n)return n}};async function Drt(t){let n=5,r;for(;n>0&&(r=await t(),r.status===429);){let o=0;try{let l=r.clone(),c=l.headers.get("date"),d=c?new Date(c).getTime():void 0,m=(await l.json())?.info?.reset;typeof d=="number"&&typeof m=="number"&&(o=Math.max(0,Math.min(Math.round(1.1*(m-d)),1e4)))}catch{}let i=Math.pow(2,5-n)*333,a=i+Math.round(Math.random()*(i/2))*(Math.random()>.5?1:-1);await new Promise(l=>setTimeout(l,o+a)),n-=1}return r}var f0=class extends IL{constructor(e){e.apiHost||(e.apiHost="https://ai.uniform.global"),super(e)}async invoke(e,n){return(await this.apiClientWithResponse(new URL(`/projects/${this.options.projectId}/tools/${e}`,this.options.apiHost),{method:"POST",body:n?JSON.stringify(n):void 0})).body}};function I4e(t){return t.reduce((e,n)=>(e[n._id]={id:n._id,type:n.type,name:n._name},e),{})}import{CANVAS_DRAFT_STATE as F4e,CanvasClient as LZ,ContentClient as B4e,ProjectClient as z4e}from"@uniformdev/canvas";function V4e(){let t,e,n;return{fetchProjectGuidance:async()=>(t!==void 0||(t=(await new z4e(lt).get({projectId:lt.projectId}))?.guidance),t),fetchDefinitions:async()=>{if(e!==void 0)return e;let o=await new LZ(lt).getComponentDefinitions({limit:1e3,includeSystem:!0});return e=Object.fromEntries(o.componentDefinitions.map(i=>[i.id,i])),e},fetchPatterns:async()=>{if(n!==void 0)return n;let o=await new LZ(lt).getCompositionList({limit:1e3,pattern:!0,patternType:"component",resolveData:!1,skipPatternResolution:!0,skipOverridesResolution:!0,state:F4e});return n=I4e(o.compositions.map(i=>i.composition)),n},resolvePatternData:async r=>(await new LZ(lt).getCompositionById({compositionId:r,state:F4e,skipPatternResolution:!1,skipOverridesResolution:!0,withComponentIDs:!0,skipDataResolution:!0,withWorkflowDefinition:!0,releaseId:void 0}))?.composition,getToolClient:async()=>new f0({...lt,apiHost:lt.aiApiHost})}}function H4e(){let t,e;return{fetchProjectGuidance:async()=>(t!==void 0||(t=(await new z4e(lt).get({projectId:lt.projectId}))?.guidance),t),fetchDefinitions:async()=>{if(e!==void 0)return e;let r=await new B4e(lt).getContentTypes({limit:1e3});return e=Object.fromEntries(r.contentTypes.map(o=>[o.id,y4e(o)])),e},fetchPatterns:async()=>({}),resolvePatternData:async n=>{let o=(await new B4e(lt).getEntries({entryIDs:[n],skipPatternResolution:!1,skipOverridesResolution:!0,withComponentIDs:!0,skipDataResolution:!0,withWorkflowDefinition:!0,releaseId:void 0}))?.entries[0];return kL(o).composition},getToolClient:async()=>new f0({...lt,apiHost:lt.aiApiHost})}}import{LocaleClient as $rt}from"@uniformdev/canvas";async function FL(t){if(!t||t.length===0)return;let r=(await new $rt(lt).get()).results.map(i=>i.locale),o=t.filter(i=>!r.includes(i));if(o.length>0)throw new Error(`The following locales are not registered in your project: ${o.join(", ")}`)}async function BL({action:t,id:e,instructions:n,isPattern:r,patternId:o,getEditUrl:i}){let a=new Nrt(lt),l,c,d=t==="update"?e:void 0,f=[];if(t==="create"){if(!n)throw new Error("Instructions are required for create");if(!n.name)throw new Error("Name is required for create");if(!n.type)throw new Error("Type is required for create");if(!o)l=new Vh({_id:e,_name:n.name,type:n.type,_overridability:{hideLockedParameters:!0}});else{let m={composition:{_id:e,_name:n.name,type:n.type,_pattern:o},projectId:lt.projectId,state:MZ,pattern:!1};await a.updateComposition(m),d=e}}if(d){if(c=await a.getCompositionById({compositionId:e,state:MZ,skipDataResolution:!0,skipPatternResolution:!1,withComponentIDs:!0,skipOverridesResolution:!0}),!c)throw new Error("Composition not found");l=new Vh(c.composition)}if(t==="delete"&&await a.removeComposition({compositionId:e}),l){await FL(n?.localeUpdates?.enableLocales),f=await DL({twee:l,descriptionUpdate:void 0,slugUpdate:void 0,nameUpdate:n?.name,propertyUpdates:n?.parameterUpdates??[],localeUpdates:n?.localeUpdates,slotUpdates:n??{newComponentsInSlots:[],deletedComponentsInSlots:[]},currentEditorLocale:void 0,referenceData:V4e()});let m=l.exportTree(),h=l.exportMetadata(),v={composition:m,projectId:lt.projectId,state:MZ,pattern:r,releaseId:c?.releaseId,editionId:c?.editionId,...h};await a.updateComposition(v)}return{content:[{type:"text",text:JSON.stringify({results:f,editUrl:i(e)},null,2)}]}}function zL(t){return`${lt.baseWebUrl}/dashboards/canvas/edit/${t}`}async function VL(t,e){return await new f0({...lt,apiHost:lt.aiApiHost}).invoke("createFilterExpression",{...t,entityType:e})}var Lrt={action:OZ.enum(["create","update","delete"]).describe("The action to perform"),id:OZ.string().uuid().describe("UUID of the composition instance to create, update, or delete"),patternId:OZ.string().uuid().describe("Composition pattern ID to create the composition from. Omit when not creating, or when creating a composition without a composition pattern.").optional(),instructions:Fte.describe("Modification instructions for the composition. Omit for delete.").optional()};function j4e(t){t.tool("compositionAction","Creates, updates, or deletes a Uniform Composition",Lrt,async e=>await BL({...e,isPattern:!1,getEditUrl:zL,patternId:e.patternId}))}import{z as Uo}from"zod";var Mrt=Uo.object({field:Uo.string(),operator:Uo.string(),value:Uo.string().or(Uo.array(Uo.string()))}),Ort=Uo.object({filter:Uo.array(Mrt),error:Uo.string().describe("An error message if the filter expression could not be created, otherwise an empty string"),sort:Uo.array(Uo.enum(["created_at_ASC","created_at_DESC","updated_at_ASC","updated_at_DESC","author_ASC","author_DESC","creator_ASC","creator_DESC","name_ASC","name_DESC","slug_ASC","slug_DESC"])),limit:Uo.number().min(1).max(100),offset:Uo.number().min(0),keyword:Uo.string(),locale:Uo.string().optional()}),vp=Uo.object({searchExpressionPrompt:Uo.string().describe(`Describe what you are looking for, for example "created by me in the last week" or "type is article and headline contains breaking news" or "keyword search for breaking news".
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/uniform-mcp",
3
- "version": "20.25.2-alpha.3+fac462fd6d",
3
+ "version": "20.26.1-alpha.0+ff834f63d0",
4
4
  "description": "Uniform MCP Server",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@modelcontextprotocol/sdk": "^1.12.0",
25
- "@uniformdev/canvas": "20.25.2-alpha.3+fac462fd6d",
25
+ "@uniformdev/canvas": "20.26.1-alpha.0+ff834f63d0",
26
26
  "fast-json-patch": "^3.1.1",
27
27
  "immer": "10.1.1",
28
28
  "zod": "3.23.8"
@@ -34,10 +34,10 @@
34
34
  "access": "public"
35
35
  },
36
36
  "devDependencies": {
37
- "@uniformdev/design-system": "20.25.2-alpha.3+fac462fd6d",
38
- "@uniformdev/files": "20.25.2-alpha.3+fac462fd6d",
39
- "@uniformdev/mesh-edgehancer-sdk": "20.25.2-alpha.3+fac462fd6d",
37
+ "@uniformdev/design-system": "20.26.1-alpha.0+ff834f63d0",
38
+ "@uniformdev/files": "20.26.1-alpha.0+ff834f63d0",
39
+ "@uniformdev/mesh-edgehancer-sdk": "20.26.1-alpha.0+ff834f63d0",
40
40
  "vitest": "^3.1.4"
41
41
  },
42
- "gitHead": "fac462fd6dd8d6d51a6d37d5ed321ed058e23d00"
42
+ "gitHead": "ff834f63d07f7f709e42f69705b93ae20f6b7ddf"
43
43
  }