@uniformdev/canvas
Advanced tools
Comparing version 12.2.1-alpha.39 to 12.2.1-alpha.43
@@ -94,2 +94,3 @@ import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIPutRequest, f as CompositionAPIDeleteRequest, g as ComponentDefinitionListAPIOptions, h as ComponentDefinitionAPIResponse, i as ComponentDefinitionAPIPutRequest, j as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-ada6f4ff'; | ||
removeComponent: () => void; | ||
insertAfter: (components: ComponentInstance | ComponentInstance[]) => void; | ||
}; | ||
@@ -346,3 +347,3 @@ /** Walks a composition's component tree, visiting each component instance depth-first, in order. */ | ||
component: ComponentInstance; | ||
}): Record<string, ComponentInstance>; | ||
}): Record<string, ComponentInstance[]>; | ||
declare function localize({ composition, locale, }: { | ||
@@ -352,3 +353,3 @@ composition: ComponentInstance; | ||
component: Readonly<ComponentInstance>; | ||
locales: Readonly<Record<string, ComponentInstance>>; | ||
locales: Readonly<Record<string, ComponentInstance[]>>; | ||
}) => string | undefined); | ||
@@ -355,0 +356,0 @@ }): void; |
@@ -1,4 +0,4 @@ | ||
import{a as L,b as l,c as k,d as M,e as j,f as F,g as P,h as v,i as g,j as $,k as N,l as A,m as U,n as z}from"./chunk-Y7BBT5AF.mjs";function u(o,e){let n=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let r=t.ancestorsAndSelf[0];e(r.component,t.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=t.ancestorsAndSelf[0],s=t.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],m=a[s];for(let p=m.length-1;p>=0;p--)n.push({ancestorsAndSelf:[{component:m[p],parentSlot:s,parentSlotIndex:p},...t.ancestorsAndSelf]})}}}while(n.length>0)}function y(o){let e=[];for(let n=o.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:r}=o[n];t&&r!==void 0&&e.push(`${t}[${r}]`)}return`.${e.join(".")}`}var b=class{constructor(e,n){this.groups=e.reduce((t,r)=>{var i;let a=n(r.args);return t[a]=(i=t[a])!=null?i:[],t[a].push(r),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var f=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new f}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new f,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,t){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(n,t);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[r,a]of t.resolveComponentEnhancers())n.set(r,a)}return n}};var w=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function Q({handleBatch:o,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{t.push(new w(c,s,i))})},completeAll:async()=>{if(t.length>0){try{await o(t)}catch(c){t.forEach(s=>s.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=t.length;return t=[],i},limitPolicy:n}}async function Z({composition:o,enhancers:e,context:n,onErrors:t=r=>{throw new Error(r.map(a=>`${a.message} | ||
import{a as L,b as l,c as k,d as M,e as j,f as F,g as P,h as v,i as g,j as $,k as N,l as A,m as U,n as z}from"./chunk-Y7BBT5AF.mjs";function u(o,e){let n=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let r=t.ancestorsAndSelf[0];e(r.component,t.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=t.ancestorsAndSelf[0],s=t.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function f(o){let e=[];for(let n=o.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:r}=o[n];t&&r!==void 0&&e.push(`${t}[${r}]`)}return`.${e.join(".")}`}var b=class{constructor(e,n){this.groups=e.reduce((t,r)=>{var i;let a=n(r.args);return t[a]=(i=t[a])!=null?i:[],t[a].push(r),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var y=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new y}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new y,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,t){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(n,t);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[r,a]of t.resolveComponentEnhancers())n.set(r,a)}return n}};var w=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function Q({handleBatch:o,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{t.push(new w(c,s,i))})},completeAll:async()=>{if(t.length>0){try{await o(t)}catch(c){t.forEach(s=>s.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=t.length;return t=[],i},limitPolicy:n}}async function Z({composition:o,enhancers:e,context:n,onErrors:t=r=>{throw new Error(r.map(a=>`${a.message} | ||
${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(` | ||
`))}}){let r=[],a=new Set,i=new Set;u(o,(s,m)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([C,E])=>{let d=e.resolveParameterEnhancer(s,C,E);d&&(i.add(d),r.push(R(s,m,C,E,d,n)))});let p=e.resolveComponentEnhancers(s);r.push(I(s,m,p,n)),a.add(p)}),r.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,m])=>{var p;try{m.completeAll&&await((p=m.limitPolicy)!=null?p:l)(()=>m.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async s=>{var m;try{s.completeAll&&await((m=s.limitPolicy)!=null?m:l)(()=>s.completeAll())}catch(p){return{error:p,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&t(c)}async function I(o,e,n,t){return n.size&&(o.data={}),await Promise.all(Array.from(n).map(async([r,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:o,context:t}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${y(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function R(o,e,n,t,r,a){var i;try{let s=await(r.completeAll?l:(i=r.limitPolicy)!=null?i:l)(async()=>r.enhanceOne({parameter:t,parameterName:n,component:o,context:a}));s===null?delete o.parameters[n]:typeof s=="undefined"?o.parameters[n]={...t,value:t.value}:o.parameters[n]={...t,value:s}}catch(c){let s=`Component ${y(e)} (type: ${o.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete o.parameters[n],{message:s,error:c}}}var J=(o,...e)=>({enhanceOne:t=>{let r=o.enhanceOne(t);for(let a of e){let i=B(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...t,parameter:{type:t.parameter.type,value:s}}))}return r},completeAll:()=>{var t,r;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r=(t=o.completeAll)==null?void 0:t.call(o))!=null?r:Promise.resolve(0)}});function B(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var ee=o=>o.startsWith("$");function re(o){return o?o.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[v])==null?void 0:t.value}}):[]}var T="https://js.pusher.com/7.0.3/pusher.min.js";async function S(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let n=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${T}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=T,t.addEventListener("load",()=>{clearTimeout(n),o(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let o=await S();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let r=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function x(o,e,n){return`${o}.${e}@${n}`}function pe({projectId:o,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:r,event:a="updated"}){let i=x(o,e,n),c=t(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function O({component:o}){var t;let e={},n=(t=o.slots)==null?void 0:t[A];return n==null||n.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[g];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=r)}),e}function ue({composition:o,locale:e}){u(o,(n,t,r)=>{if(n.type===P){let a=O({component:n}),i=typeof e=="string"?e:e({component:n,locales:a}),c;i&&(c=a[i]),c?r.replaceComponent(c):r.removeComponent()}})}export{w as BatchEntry,U as CANVAS_DRAFT_STATE,v as CANVAS_INTENT_TAG_PARAM,g as CANVAS_LOCALE_TAG_PARAM,A as CANVAS_LOCALIZATION_SLOT,P as CANVAS_LOCALIZATION_TYPE,$ as CANVAS_PERSONALIZE_SLOT,j as CANVAS_PERSONALIZE_TYPE,z as CANVAS_PUBLISHED_STATE,N as CANVAS_TEST_SLOT,F as CANVAS_TEST_TYPE,M as CanvasClient,k as CanvasClientError,f as ChildEnhancerBuilder,_ as EnhancerBuilder,b as UniqueBatchEntries,J as compose,Q as createBatchEnhancer,ae as createEventBus,L as createLimitPolicy,Z as enhance,O as extractLocales,x as getChannelName,y as getComponentPath,ee as isSystemComponentDefinition,ue as localize,re as mapSlotToPersonalizedVariations,l as nullLimitPolicy,pe as subscribeToComposition,u as walkComponentTree}; | ||
`))}}){let r=[],a=new Set,i=new Set;u(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([C,E])=>{let d=e.resolveParameterEnhancer(s,C,E);d&&(i.add(d),r.push(R(s,p,C,E,d,n)))});let m=e.resolveComponentEnhancers(s);r.push(I(s,p,m,n)),a.add(m)}),r.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:l)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async s=>{var p;try{s.completeAll&&await((p=s.limitPolicy)!=null?p:l)(()=>s.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&t(c)}async function I(o,e,n,t){return n.size&&(o.data={}),await Promise.all(Array.from(n).map(async([r,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:o,context:t}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${f(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function R(o,e,n,t,r,a){var i;try{let s=await(r.completeAll?l:(i=r.limitPolicy)!=null?i:l)(async()=>r.enhanceOne({parameter:t,parameterName:n,component:o,context:a}));s===null?delete o.parameters[n]:typeof s=="undefined"?o.parameters[n]={...t,value:t.value}:o.parameters[n]={...t,value:s}}catch(c){let s=`Component ${f(e)} (type: ${o.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete o.parameters[n],{message:s,error:c}}}var J=(o,...e)=>({enhanceOne:t=>{let r=o.enhanceOne(t);for(let a of e){let i=S(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...t,parameter:{type:t.parameter.type,value:s}}))}return r},completeAll:()=>{var t,r;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r=(t=o.completeAll)==null?void 0:t.call(o))!=null?r:Promise.resolve(0)}});function S(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var ee=o=>o.startsWith("$");function re(o){return o?o.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[v])==null?void 0:t.value}}):[]}var T="https://js.pusher.com/7.0.3/pusher.min.js";async function B(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let n=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${T}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=T,t.addEventListener("load",()=>{clearTimeout(n),o(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let o=await B();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let r=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function x(o,e,n){return`${o}.${e}@${n}`}function pe({projectId:o,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:r,event:a="updated"}){let i=x(o,e,n),c=t(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function O({component:o}){var t;let e={},n=(t=o.slots)==null?void 0:t[A];return n==null||n.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[g];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function ue({composition:o,locale:e}){u(o,(n,t,r)=>{if(n.type===P){let a=O({component:n}),i=typeof e=="string"?e:e({component:n,locales:a}),c;if(i&&(c=a[i]),c==null?void 0:c.length){let[s,...p]=c;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{w as BatchEntry,U as CANVAS_DRAFT_STATE,v as CANVAS_INTENT_TAG_PARAM,g as CANVAS_LOCALE_TAG_PARAM,A as CANVAS_LOCALIZATION_SLOT,P as CANVAS_LOCALIZATION_TYPE,$ as CANVAS_PERSONALIZE_SLOT,j as CANVAS_PERSONALIZE_TYPE,z as CANVAS_PUBLISHED_STATE,N as CANVAS_TEST_SLOT,F as CANVAS_TEST_TYPE,M as CanvasClient,k as CanvasClientError,y as ChildEnhancerBuilder,_ as EnhancerBuilder,b as UniqueBatchEntries,J as compose,Q as createBatchEnhancer,ae as createEventBus,L as createLimitPolicy,Z as enhance,O as extractLocales,x as getChannelName,f as getComponentPath,ee as isSystemComponentDefinition,ue as localize,re as mapSlotToPersonalizedVariations,l as nullLimitPolicy,pe as subscribeToComposition,u as walkComponentTree}; |
@@ -1,5 +0,5 @@ | ||
var $=Object.create;var f=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var _=r=>f(r,"__esModule",{value:!0});var z=(r,e)=>{_(r);for(var n in e)f(r,n,{get:e[n],enumerable:!0})},H=(r,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of V(e))!F.call(r,t)&&t!=="default"&&f(r,t,{get:()=>e[t],enumerable:!(n=M(e,t))||n.enumerable});return r},O=r=>H(_(f(r!=null?$(D(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);z(exports,{BatchEntry:()=>A,CANVAS_DRAFT_STATE:()=>ne,CANVAS_INTENT_TAG_PARAM:()=>I,CANVAS_LOCALE_TAG_PARAM:()=>T,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZE_SLOT:()=>X,CANVAS_PERSONALIZE_TYPE:()=>Y,CANVAS_PUBLISHED_STATE:()=>te,CANVAS_TEST_SLOT:()=>ee,CANVAS_TEST_TYPE:()=>Q,CanvasClient:()=>N,CanvasClientError:()=>y,ChildEnhancerBuilder:()=>E,EnhancerBuilder:()=>L,UniqueBatchEntries:()=>S,compose:()=>J,createBatchEnhancer:()=>q,createEventBus:()=>se,createLimitPolicy:()=>g,enhance:()=>K,extractLocales:()=>U,getChannelName:()=>w,getComponentPath:()=>C,isSystemComponentDefinition:()=>oe,localize:()=>ce,mapSlotToPersonalizedVariations:()=>re,nullLimitPolicy:()=>h,subscribeToComposition:()=>ae,walkComponentTree:()=>d});function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],l=i[a];for(let m=l.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:l[m],parentSlot:a,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function C(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var S=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var E=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},L=class{constructor(){this._componentIndex={};this._rootBuilder=new E}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new E,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var A=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new A(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=O(require("p-throttle")),B=O(require("p-retry"));function g({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,B.default)(s,e)}return i()}}var h=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message} | ||
var $=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var _=r=>y(r,"__esModule",{value:!0});var z=(r,e)=>{_(r);for(var n in e)y(r,n,{get:e[n],enumerable:!0})},H=(r,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of V(e))!F.call(r,t)&&t!=="default"&&y(r,t,{get:()=>e[t],enumerable:!(n=M(e,t))||n.enumerable});return r},S=r=>H(_(y(r!=null?$(D(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);z(exports,{BatchEntry:()=>A,CANVAS_DRAFT_STATE:()=>ne,CANVAS_INTENT_TAG_PARAM:()=>I,CANVAS_LOCALE_TAG_PARAM:()=>T,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZE_SLOT:()=>X,CANVAS_PERSONALIZE_TYPE:()=>Y,CANVAS_PUBLISHED_STATE:()=>te,CANVAS_TEST_SLOT:()=>ee,CANVAS_TEST_TYPE:()=>Q,CanvasClient:()=>N,CanvasClientError:()=>f,ChildEnhancerBuilder:()=>E,EnhancerBuilder:()=>L,UniqueBatchEntries:()=>O,compose:()=>J,createBatchEnhancer:()=>q,createEventBus:()=>se,createLimitPolicy:()=>g,enhance:()=>K,extractLocales:()=>U,getChannelName:()=>w,getComponentPath:()=>C,isSystemComponentDefinition:()=>oe,localize:()=>ce,mapSlotToPersonalizedVariations:()=>re,nullLimitPolicy:()=>h,subscribeToComposition:()=>ae,walkComponentTree:()=>d});function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")m.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:a,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function C(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var O=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var E=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},L=class{constructor(){this._componentIndex={};this._rootBuilder=new E}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new E,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var A=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new A(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=S(require("p-throttle")),B=S(require("p-retry"));function g({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,B.default)(s,e)}return i()}}var h=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message} | ||
${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(` | ||
`))}}){let o=[],i=new Set,s=new Set;d(r,(a,l)=>{var u;Object.entries((u=a.parameters)!=null?u:{}).forEach(([R,b])=>{let P=e.resolveParameterEnhancer(a,R,b);P&&(s.add(P),o.push(Z(a,l,R,b,P,n)))});let m=e.resolveComponentEnhancers(a);o.push(G(a,l,m,n)),i.add(m)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,l])=>{var m;try{l.completeAll&&await((m=l.limitPolicy)!=null?m:h)(()=>l.completeAll())}catch(u){return{error:u,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var l;try{a.completeAll&&await((l=a.limitPolicy)!=null?l:h)(()=>a.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function G(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?h:(s=i.limitPolicy)!=null?s:h)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${C(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function Z(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?h:(s=o.limitPolicy)!=null?s:h)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${C(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var J=(r,...e)=>({enhanceOne:t=>{let o=r.enhanceOne(t);for(let i of e){let s=W(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o=(t=r.completeAll)==null?void 0:t.call(r))!=null?o:Promise.resolve(0)}});function W(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var y=class extends Error{constructor(e,n,t,o,i){super(`${e} | ||
${o}${i?" "+i:""} (${n} ${t})`);this.errorMessage=e;this.fetchMethod=n;this.fetchUri=t;this.statusCode=o;this.statusText=i;Object.setPrototypeOf(this,y.prototype)}},N=class{constructor(e){var n,t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...e,fetch:(n=e.fetch)!=null?n:fetch,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:g({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new y(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status)}return(n==null?void 0:n.expectNoContent)?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}};var Y="$personalization",Q="$test",v="$localization",I="intentTag",T="locale",X="pz",ee="test",x="localized",ne=0,te=64;var oe=r=>r.startsWith("$");function re(r){return r?r.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[I])==null?void 0:t.value}}):[]}var k="https://js.pusher.com/7.0.3/pusher.min.js";async function ie(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${k}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=k,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function se(){let r=await ie();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function w(r,e,n){return`${r}.${e}@${n}`}function ae({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=w(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function U({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[T];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=o)}),e}function ce({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=U({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;s&&(c=i[s]),c?o.replaceComponent(c):o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree}); | ||
`))}}){let o=[],i=new Set,s=new Set;d(r,(a,p)=>{var u;Object.entries((u=a.parameters)!=null?u:{}).forEach(([R,b])=>{let P=e.resolveParameterEnhancer(a,R,b);P&&(s.add(P),o.push(Z(a,p,R,b,P,n)))});let m=e.resolveComponentEnhancers(a);o.push(G(a,p,m,n)),i.add(m)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:h)(()=>p.completeAll())}catch(u){return{error:u,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:h)(()=>a.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function G(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?h:(s=i.limitPolicy)!=null?s:h)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${C(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function Z(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?h:(s=o.limitPolicy)!=null?s:h)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${C(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var J=(r,...e)=>({enhanceOne:t=>{let o=r.enhanceOne(t);for(let i of e){let s=W(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o=(t=r.completeAll)==null?void 0:t.call(r))!=null?o:Promise.resolve(0)}});function W(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var f=class extends Error{constructor(e,n,t,o,i){super(`${e} | ||
${o}${i?" "+i:""} (${n} ${t})`);this.errorMessage=e;this.fetchMethod=n;this.fetchUri=t;this.statusCode=o;this.statusText=i;Object.setPrototypeOf(this,f.prototype)}},N=class{constructor(e){var n,t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...e,fetch:(n=e.fetch)!=null?n:fetch,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:g({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new f(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status)}return(n==null?void 0:n.expectNoContent)?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}};var Y="$personalization",Q="$test",v="$localization",I="intentTag",T="locale",X="pz",ee="test",x="localized",ne=0,te=64;var oe=r=>r.startsWith("$");function re(r){return r?r.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[I])==null?void 0:t.value}}):[]}var k="https://js.pusher.com/7.0.3/pusher.min.js";async function ie(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${k}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=k,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function se(){let r=await ie();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function w(r,e,n){return`${r}.${e}@${n}`}function ae({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=w(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function U({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[T];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function ce({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=U({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c==null?void 0:c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree}); |
{ | ||
"name": "@uniformdev/canvas", | ||
"version": "12.2.1-alpha.39+d7525732", | ||
"version": "12.2.1-alpha.43+0071e168", | ||
"description": "Common functionality and types for Uniform Canvas", | ||
@@ -50,3 +50,3 @@ "license": "SEE LICENSE IN LICENSE.txt", | ||
"@types/yargs": "17.0.5", | ||
"@uniformdev/cli": "^12.2.1-alpha.39+d7525732", | ||
"@uniformdev/cli": "^12.2.1-alpha.43+0071e168", | ||
"eslint": "7.32.0", | ||
@@ -67,4 +67,4 @@ "eslint-plugin-react": "7.26.1", | ||
"dependencies": { | ||
"@uniformdev/optimize-common": "^12.2.1-alpha.39+d7525732", | ||
"@uniformdev/optimize-tracker-common": "^12.2.1-alpha.39+d7525732", | ||
"@uniformdev/optimize-common": "^12.2.1-alpha.43+0071e168", | ||
"@uniformdev/optimize-tracker-common": "^12.2.1-alpha.43+0071e168", | ||
"chalk": "^4.1.2", | ||
@@ -85,3 +85,3 @@ "diff": "^5.0.0", | ||
}, | ||
"gitHead": "d752573207ec468ccf0479f90e06cc252a74c84e" | ||
"gitHead": "0071e168f8a5e5f5cecd3ce908383dc690d3fd3c" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
108373
865