@uniformdev/canvas 17.1.1-alpha.152 → 17.2.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.
- package/dist/chunk-IQWDQAHE.mjs +4 -0
- package/dist/cli/cli.d.ts +1 -1
- package/dist/cli/cli.js +1 -1
- package/dist/cli/cli.mjs +1 -1
- package/dist/{createEventBus-b9cdb6ff.d.ts → createEventBus-3f3f7633.d.ts} +52 -49
- package/dist/index.d.ts +209 -65
- package/dist/index.esm.js +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
- package/dist/chunk-PFL3XEAQ.mjs +0 -4
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";var se=Object.create;var _=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var R=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),ue=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},J=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pe(e))!le.call(n,o)&&o!==t&&_(n,o,{get:()=>e[o],enumerable:!(r=ce(e,o))||r.enumerable});return n};var he=(n,e,t)=>(t=n!=null?se(me(n)):{},J(e||!n||!n.__esModule?_(t,"default",{value:n,enumerable:!0}):t,n)),fe=n=>J(_({},"__esModule",{value:!0}),n);var de=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var v=(n,e,t)=>(de(n,e,"read from private field"),t?t.call(n):e.get(n)),Z=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var q=R((He,H)=>{function u(n,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(n)),this._timeouts=n,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}H.exports=u;u.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};u.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};u.prototype.retry=function(n){if(this._timeout&&clearTimeout(this._timeout),!n)return!1;var e=new Date().getTime();if(n&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(n),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(n);var t=this._timeouts.shift();if(t===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),t=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},t),this._options.unref&&this._timer.unref(),!0};u.prototype.attempt=function(n,e){this._fn=n,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var t=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){t._operationTimeoutCb()},t._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};u.prototype.try=function(n){console.log("Using RetryOperation.try() is deprecated"),this.attempt(n)};u.prototype.start=function(n){console.log("Using RetryOperation.start() is deprecated"),this.attempt(n)};u.prototype.start=u.prototype.try;u.prototype.errors=function(){return this._errors};u.prototype.attempts=function(){return this._attempts};u.prototype.mainError=function(){if(this._errors.length===0)return null;for(var n={},e=null,t=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(n[i]||0)+1;n[i]=a,a>=t&&(e=o,t=a)}return e}});var Y=R(d=>{var Ce=q();d.operation=function(n){var e=d.timeouts(n);return new Ce(e,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})};d.timeouts=function(n){if(n instanceof Array)return[].concat(n);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var t in n)e[t]=n[t];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<e.retries;o++)r.push(this.createTimeout(o,e));return n&&n.forever&&!r.length&&r.push(this.createTimeout(o,e)),r.sort(function(i,a){return i-a}),r};d.createTimeout=function(n,e){var t=e.randomize?Math.random()+1:1,r=Math.round(t*Math.max(e.minTimeout,1)*Math.pow(e.factor,n));return r=Math.min(r,e.maxTimeout),r};d.wrap=function(n,e,t){if(e instanceof Array&&(t=e,e=null),!t){t=[];for(var r in n)typeof n[r]=="function"&&t.push(r)}for(var o=0;o<t.length;o++){var i=t[o],a=n[i];n[i]=function(c){var p=d.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(h){p.retry(h)||(h&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){c.apply(n,m)})}.bind(n,a),n[i].options=e}}});var K=R((Ye,Q)=>{Q.exports=Y()});var ke={};ue(ke,{BatchEntry:()=>g,CANVAS_DRAFT_STATE:()=>Ct,CANVAS_ENRICHMENT_TAG_PARAM:()=>Ne,CANVAS_INTENT_TAG_PARAM:()=>be,CANVAS_LOCALE_TAG_PARAM:()=>k,CANVAS_LOCALIZATION_SLOT:()=>G,CANVAS_LOCALIZATION_TYPE:()=>B,CANVAS_PERSONALIZATION_PARAM:()=>F,CANVAS_PERSONALIZE_SLOT:()=>Se,CANVAS_PERSONALIZE_TYPE:()=>Ie,CANVAS_PUBLISHED_STATE:()=>Et,CANVAS_TEST_SLOT:()=>Oe,CANVAS_TEST_TYPE:()=>Re,CANVAS_TEST_VARIANT_PARAM:()=>$,CanvasClient:()=>w,CanvasDataConnectionClient:()=>V,CanvasDataTypeClient:()=>I,ChildEnhancerBuilder:()=>T,EnhancerBuilder:()=>S,UncachedCanvasClient:()=>j,UniqueBatchEntries:()=>b,compose:()=>xe,createBatchEnhancer:()=>ye,createEventBus:()=>Me,createLimitPolicy:()=>L,enhance:()=>Ae,extractLocales:()=>ie,getChannelName:()=>z,getComponentPath:()=>x,isSystemComponentDefinition:()=>De,localize:()=>Be,mapSlotToPersonalizedVariations:()=>Ue,mapSlotToTestVariations:()=>Le,nullLimitPolicy:()=>f,subscribeToComposition:()=>Ve,walkComponentTree:()=>P});module.exports=fe(ke);function P(n,e){let t=[{ancestorsAndSelf:[{component:n,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let r=t.pop();if(!r)continue;let o=r.ancestorsAndSelf[0],i=!0;e(o.component,r.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{s[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:s,parentComponent:c,correctedParentSlotIndex:p}=W(r,o.component);if(s&&typeof p!="undefined")c.component.slots[s].splice(p,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:p,parentComponent:m,correctedParentSlotIndex:l}=W(r,o.component);if(p&&typeof l!="undefined")m.component.slots[p].splice(l+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){i=!1}});let a=o.component.slots;if(i&&a){let s=Object.keys(a);for(let c=s.length-1;c>=0;c--){let p=s[c],m=a[p];for(let l=m.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...r.ancestorsAndSelf]})}}}while(t.length>0)}function x(n){let e=[];for(let t=n.length-1;t>=0;t--){let{parentSlot:r,parentSlotIndex:o}=n[t];r&&o!==void 0&&e.push(`${r}[${o}]`)}return`.${e.join(".")}`}function W(n,e){let{parentSlot:t,parentSlotIndex:r}=n.ancestorsAndSelf[0],o=n.ancestorsAndSelf[1],i=r;return t&&r!==void 0&&o.component.slots&&o.component.slots[t][r]!==e&&(i=o.component.slots[t].findIndex(a=>a===e)),{parentSlot:t,parentComponent:o,correctedParentSlotIndex:i}}var b=class{constructor(e,t){this.groups=e.reduce((r,o)=>{var a;let i=t(o.args);return r[i]=(a=r[i])!=null?a:[],r[i].push(o),r},{})}resolveKey(e,t){this.groups[e].forEach(r=>r.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(r=>{r.isCompleted||r.resolve(e)})})}};var T=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){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 t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var r;return(r=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:r.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},S=class{constructor(){this._componentIndex={};this._rootBuilder=new T}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new T,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,r){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(t,r);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(t,r)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),r=this._componentIndex[e.type];if(r){t=new Map(t);for(let[o,i]of r.resolveComponentEnhancers())t.set(o,i)}return t}};var g=class{constructor(e,t,r){this._resolve=e;this._reject=t;this.args=r;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 ye({handleBatch:n,shouldQueue:e,limitPolicy:t}){let r=[];return{enhanceOne:async a=>{if(!e||e(a))return new Promise((s,c)=>{r.push(new g(s,c,a))})},completeAll:async()=>{if(r.length>0){try{await n(r)}catch(s){r.forEach(c=>c.reject(s))}if(r.some(s=>!s.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let a=r.length;return r=[],a},limitPolicy:t}}var O=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function N({limit:n,interval:e,strict:t}){if(!Number.isFinite(n))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let r=new Map,o=0,i=0;function a(){let m=Date.now();return m-o>e?(i=1,o=m,0):(i<n?i++:(o+=e,i=1),o-m)}let s=[];function c(){let m=Date.now();if(s.length<n)return s.push(m),0;let l=s.shift()+e;return m>=l?(s.push(m),0):(s.push(l),l-m)}let p=t?c:a;return m=>{let l=function(...h){if(!l.isEnabled)return(async()=>m.apply(this,h))();let y;return new Promise((E,ae)=>{y=setTimeout(()=>{E(m.apply(this,h)),r.delete(y)},p()),r.set(y,ae)})};return l.abort=()=>{for(let h of r.keys())clearTimeout(h),r.get(h)(new O);r.clear(),s.splice(0,s.length)},l.isEnabled=!0,l}}var ee=he(K(),1),Ee=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),D=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},Pe=(n,e,t)=>{let r=t.retries-(e-1);return n.attemptNumber=e,n.retriesLeft=r,n},Te=n=>Ee.has(n),X=n=>globalThis.DOMException===void 0?new Error(n):new DOMException(n);async function U(n,e){return new Promise((t,r)=>{e={onFailedAttempt(){},retries:10,...e};let o=ee.default.operation(e);o.attempt(async i=>{try{t(await n(i))}catch(a){if(!(a instanceof Error)){r(new TypeError(`Non-error was thrown: "${a}". You should only throw errors.`));return}if(a instanceof D)o.stop(),r(a.originalError);else if(a instanceof TypeError&&!Te(a.message))o.stop(),r(a);else{Pe(a,i,e);try{await e.onFailedAttempt(a)}catch(s){r(s);return}o.retry(a)||r(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?X("The operation was aborted."):e.signal.reason;r(i instanceof Error?i:X(i))},{once:!0})})}function L({throttle:n={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=n?N(n):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let a=i;i=()=>U(a,e)}return i()}}var f=async n=>await n();async function Ae({composition:n,enhancers:e,context:t,onErrors:r=o=>{throw new Error(o.map(i=>`${i.message}
|
2
|
-
${typeof
|
1
|
+
"use strict";var ue=Object.create;var _=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var M=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ce=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of de(e))!ye.call(t,r)&&r!==n&&_(t,r,{get:()=>e[r],enumerable:!(o=he(e,r))||o.enumerable});return t};var ge=(t,e,n)=>(n=t!=null?ue(fe(t)):{},K(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),Ee=t=>K(_({},"__esModule",{value:!0}),t);var Pe=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)};var I=(t,e,n)=>(Pe(t,e,"read from private field"),n?n.call(t):e.get(t)),X=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)};var te=M((it,ee)=>{function C(t,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}ee.exports=C;C.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};C.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};C.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=new Date().getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(t),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1);else return!1;var o=this;return this._timer=setTimeout(function(){o._attempts++,o._operationTimeoutCb&&(o._timeout=setTimeout(function(){o._operationTimeoutCb(o._attempts)},o._operationTimeout),o._options.unref&&o._timeout.unref()),o._fn(o._attempts)},n),this._options.unref&&this._timer.unref(),!0};C.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};C.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)};C.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)};C.prototype.start=C.prototype.try;C.prototype.errors=function(){return this._errors};C.prototype.attempts=function(){return this._attempts};C.prototype.mainError=function(){if(this._errors.length===0)return null;for(var t={},e=null,n=0,o=0;o<this._errors.length;o++){var r=this._errors[o],s=r.message,i=(t[s]||0)+1;t[s]=i,i>=n&&(e=r,n=i)}return e}});var ne=M(P=>{var Te=te();P.operation=function(t){var e=P.timeouts(t);return new Te(e,{forever:t&&(t.forever||t.retries===1/0),unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})};P.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in t)e[n]=t[n];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],r=0;r<e.retries;r++)o.push(this.createTimeout(r,e));return t&&t.forever&&!o.length&&o.push(this.createTimeout(r,e)),o.sort(function(s,i){return s-i}),o};P.createTimeout=function(t,e){var n=e.randomize?Math.random()+1:1,o=Math.round(n*Math.max(e.minTimeout,1)*Math.pow(e.factor,t));return o=Math.min(o,e.maxTimeout),o};P.wrap=function(t,e,n){if(e instanceof Array&&(n=e,e=null),!n){n=[];for(var o in t)typeof t[o]=="function"&&n.push(o)}for(var r=0;r<n.length;r++){var s=n[r],i=t[s];t[s]=function(c){var h=P.operation(e),l=Array.prototype.slice.call(arguments,1),m=l.pop();l.push(function(u){h.retry(u)||(u&&(arguments[0]=h.mainError()),m.apply(this,arguments))}),h.attempt(function(){c.apply(t,l)})}.bind(t,i),t[s].options=e}}});var re=M((ct,oe)=>{oe.exports=ne()});var Xe={};Ce(Xe,{ApiClientError:()=>Q.ApiClientError,BatchEntry:()=>R,CANVAS_DRAFT_STATE:()=>bt,CANVAS_ENRICHMENT_TAG_PARAM:()=>je,CANVAS_INTENT_TAG_PARAM:()=>De,CANVAS_LOCALE_TAG_PARAM:()=>J,CANVAS_LOCALIZATION_SLOT:()=>z,CANVAS_LOCALIZATION_TYPE:()=>F,CANVAS_PERSONALIZATION_PARAM:()=>H,CANVAS_PERSONALIZE_SLOT:()=>Ue,CANVAS_PERSONALIZE_TYPE:()=>Me,CANVAS_PUBLISHED_STATE:()=>St,CANVAS_TEST_SLOT:()=>Le,CANVAS_TEST_TYPE:()=>Ne,CANVAS_TEST_VARIANT_PARAM:()=>W,CanvasClient:()=>b,CanvasClientError:()=>Ke,CanvasDataConnectionClient:()=>$,CanvasDataTypeClient:()=>S,ChildEnhancerBuilder:()=>A,EdgeCanvasClient:()=>Y,EnhancerBuilder:()=>D,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM:()=>Ve,UncachedCanvasClient:()=>k,UniqueBatchEntries:()=>N,compose:()=>be,createBatchEnhancer:()=>xe,createCanvasChannel:()=>Qe,createEventBus:()=>Fe,createLimitPolicy:()=>G,enhance:()=>Ie,extractLocales:()=>le,generateHash:()=>Z,getChannelName:()=>q,getComponentPath:()=>w,isAddComponentMessage:()=>qe,isMovingComponentMessage:()=>Ye,isReadyMessage:()=>We,isSelectComponentMessage:()=>He,isSystemComponentDefinition:()=>Ge,isUpdateCompositionMessage:()=>Ze,localize:()=>ze,mapSlotToPersonalizedVariations:()=>ke,mapSlotToTestVariations:()=>Be,nullLimitPolicy:()=>E,subscribeToComposition:()=>Je,walkComponentTree:()=>T});module.exports=Ee(Xe);function T(t,e,n){var s;let o=[{ancestorsAndSelf:[{component:t,parentSlot:void 0,parentSlotIndex:void 0}],context:n}],r=new Map;do{let i=o.pop();if(!i)continue;let a=i.ancestorsAndSelf[0],c=!0,h=(s=r.get(a.component))!=null?s:i.context;e(a.component,i.ancestorsAndSelf,{replaceComponent:m=>{Object.assign(a.component,m),["parameters","variant","slots","data","_pattern","_patternError"].forEach(f=>{m[f]||delete a.component[f]})},removeComponent:()=>{let{parentSlot:m,parentSlotIndex:u}=i.ancestorsAndSelf[0],f=i.ancestorsAndSelf[1];if(m&&typeof u!="undefined")f.component.slots[m].splice(u,1);else throw new Error("Unable to delete composition.")},insertAfter:m=>{let u=Array.isArray(m)?m:[m],{parentSlot:f,parentSlotIndex:p}=i.ancestorsAndSelf[0],d=i.ancestorsAndSelf[1];if(f&&typeof p!="undefined")d.component.slots[f].splice(p+1,0,...u),o.unshift(...u.map(y=>({ancestorsAndSelf:[{component:y,parentSlot:f,get parentSlotIndex(){return d.component.slots[f].findIndex(g=>g===y)}},...i.ancestorsAndSelf],context:h})));else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){c=!1},setDescendantsContext(m){h=m},setChildContext(m,u){r.set(m,u)}},h);let l=a.component.slots;if(c&&l){let m=Object.keys(l);for(let u=m.length-1;u>=0;u--){let f=m[u],p=l[f];for(let d=p.length-1;d>=0;d--){let y=p[d];o.push({ancestorsAndSelf:[{component:y,parentSlot:f,get parentSlotIndex(){return a.component.slots[f].findIndex(g=>g===y)}},...i.ancestorsAndSelf],context:h})}}}}while(o.length>0)}function w(t){let e=[];for(let n=t.length-1;n>=0;n--){let{parentSlot:o,parentSlotIndex:r}=t[n];o&&r!==void 0&&e.push(`${o}[${r}]`)}return`.${e.join(".")}`}var N=class{constructor(e,n){this.groups=e.reduce((o,r)=>{var i;let s=n(r.args);return o[s]=(i=o[s])!=null?i:[],o[s].push(r),o},{})}resolveKey(e,n){this.groups[e].forEach(o=>o.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(o=>{o.isCompleted||o.resolve(e)})})}};var A=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 o;return(o=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:o.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},D=class{constructor(){this._componentIndex={};this._rootBuilder=new A}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 A,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,o){let r=this._componentIndex[e.type];if(r){let s=r.resolveParameterEnhancer(n,o);if(s)return s}return this._rootBuilder.resolveParameterEnhancer(n,o)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),o=this._componentIndex[e.type];if(o){n=new Map(n);for(let[r,s]of o.resolveComponentEnhancers())n.set(r,s)}return n}};var R=class{constructor(e,n,o){this._resolve=e;this._reject=n;this.args=o;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 xe({handleBatch:t,shouldQueue:e,limitPolicy:n}){let o=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((a,c)=>{o.push(new R(a,c,i))})},completeAll:async()=>{if(o.length>0){try{await t(o)}catch(a){o.forEach(c=>c.reject(a))}if(o.some(a=>!a.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=o.length;return o=[],i},limitPolicy:n}}var U=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function L({limit:t,interval:e,strict:n}){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let o=new Map,r=0,s=0;function i(){let l=Date.now();return l-r>e?(s=1,r=l,0):(s<t?s++:(r+=e,s=1),r-l)}let a=[];function c(){let l=Date.now();if(a.length<t)return a.push(l),0;let m=a.shift()+e;return l>=m?(a.push(l),0):(a.push(m),m-l)}let h=n?c:i;return l=>{let m=function(...u){if(!m.isEnabled)return(async()=>l.apply(this,u))();let f;return new Promise((p,d)=>{f=setTimeout(()=>{p(l.apply(this,u)),o.delete(f)},h()),o.set(f,d)})};return m.abort=()=>{for(let u of o.keys())clearTimeout(u),o.get(u)(new U);o.clear(),a.splice(0,a.length)},m.isEnabled=!0,m}}var ie=ge(re(),1),Ae=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),j=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},ve=(t,e,n)=>{let o=n.retries-(e-1);return t.attemptNumber=e,t.retriesLeft=o,t},_e=t=>Ae.has(t),se=t=>globalThis.DOMException===void 0?new Error(t):new DOMException(t);async function V(t,e){return new Promise((n,o)=>{e={onFailedAttempt(){},retries:10,...e};let r=ie.default.operation(e);r.attempt(async s=>{try{n(await t(s))}catch(i){if(!(i instanceof Error)){o(new TypeError(`Non-error was thrown: "${i}". You should only throw errors.`));return}if(i instanceof j)r.stop(),o(i.originalError);else if(i instanceof TypeError&&!_e(i.message))r.stop(),o(i);else{ve(i,s,e);try{await e.onFailedAttempt(i)}catch(a){o(a);return}r.retry(i)||o(r.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{r.stop();let s=e.signal.reason===void 0?se("The operation was aborted."):e.signal.reason;o(s instanceof Error?s:se(s))},{once:!0})})}function G({throttle:t={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=t?L(t):null;return function(r){let s=async()=>await r();if(n&&(s=n(s)),e){let i=s;s=()=>V(i,e)}return s()}}var E=async t=>await t();async function Ie({composition:t,enhancers:e,context:n,onErrors:o=r=>{throw new Error(r.map(s=>`${s.message}
|
2
|
+
${typeof s.error=="object"&&"stack"in s.error?s.error.stack:s.error}`).join(`
|
3
3
|
|
4
|
-
`))}}){let o=[],i=new Set,a=new Set;P(n,(c,p)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let E=e.resolveParameterEnhancer(c,h,y);E&&(a.add(E),o.push(ve(c,p,h,y,E,t)))});let m=e.resolveComponentEnhancers(c);o.push(_e(c,p,m,t)),i.add(m)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:f)(()=>p.completeAll())}catch(l){return{error:l,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(a).map(async c=>{var p;try{c.completeAll&&await((p=c.limitPolicy)!=null?p:f)(()=>c.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let s=(await Promise.all(o)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);s.length&&r(s)}async function _e(n,e,t,r){return t.size&&(n.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var a;try{let c=await(i.completeAll?f:(a=i.limitPolicy)!=null?a:f)(async()=>i.enhanceOne({component:n,context:r}));c!=null&&(n.data[o]=c)}catch(s){let c=`Component ${x(e)} (type: ${n.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete n.data[o],{message:c,error:s}}}))}async function ve(n,e,t,r,o,i){var a;try{let c=await(o.completeAll?f:(a=o.limitPolicy)!=null?a:f)(async()=>o.enhanceOne({parameter:r,parameterName:t,component:n,context:i}));c===null?delete n.parameters[t]:typeof c=="undefined"?n.parameters[t]={...r,value:r.value}:n.parameters[t]={...r,value:c}}catch(s){let c=`Component ${x(e)} (type: ${n.type}): enhancing parameter ${t} (type: ${r.type}) threw exception. Parameter will be removed.`;return delete n.parameters[t],{message:c,error:s}}}var xe=(n,...e)=>({enhanceOne:r=>{let o="enhanceOne"in n?n.enhanceOne(r):n(r);for(let i of e){let a=ge(o)?o:Promise.resolve(o),s="enhanceOne"in i?i.enhanceOne:i;o=a.then(c=>s({...r,parameter:{type:r.parameter.type,value:c}}))}return o},completeAll:async()=>{var r,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="completeAll"in n?(r=n.completeAll)==null?void 0:r.call(n):0)!=null?o:0}});function ge(n){return!!n&&(typeof n=="object"||typeof n=="function")&&typeof n.then=="function"}var te=require("@uniformdev/context/api"),w=class extends te.ApiClient{constructor(e){e.limitPolicy||(e.limitPolicy=L({})),super(e)}get canvasUrl(){return this.options.experiment14?"/api/edge/v1/composition":"/api/v1/canvas"}async getCompositionList(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async getCompositionBySlug(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async getCompositionById(e){let{projectId:t}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(r)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas"),{projectId:r}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(r)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},j=class extends w{constructor(e){super({...e,bypassCache:!0})}};var ne=require("@uniformdev/context/api"),M="/api/v1/data-connection",we="/api/v1/data-connections",V=class extends ne.ApiClient{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,r=this.createUrl(M,{...e,projectId:t});return await this.apiClient(r)}async getList(e){let{projectId:t}=this.options,r=this.createUrl(we,{...e,projectId:t});return await this.apiClient(r)}async upsert(e){let t=this.createUrl(M);await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(M);await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}};var re=require("@uniformdev/context/api");var C,A=class extends re.ApiClient{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,r=this.createUrl(v(A,C),{...e,projectId:t});return await this.apiClient(r)}async upsert(e){let t=this.createUrl(v(A,C));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(v(A,C));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},I=A;C=new WeakMap,Z(I,C,"/api/v1/data-types");var Ie="$personalization",Re="$test",B="$localization",be="intentTag",k="locale",Se="pz",Oe="test",G="localized",Ct=0,Et=64,F="$pzCrit",$="$tstVrnt",Ne="$enr";var De=n=>n.startsWith("$");function Ue(n){return n?n.map((e,t)=>{var i,a;let r=(a=(i=e.parameters)==null?void 0:i[F])==null?void 0:a.value,o=(r==null?void 0:r.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:r}}):[]}function Le(n){return n?n.map((e,t)=>{var i,a,s;let r=(a=(i=e.parameters)==null?void 0:i[$])==null?void 0:a.value,o=(s=r==null?void 0:r.id)!=null?s:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var oe="https://js.pusher.com/7.0.3/pusher.min.js";async function je(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((n,e)=>{let t=setTimeout(()=>{window.Pusher&&n(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${oe}"><\/script> manually.`)},5e3),r=document.createElement("script");r.src=oe,r.addEventListener("load",()=>{clearTimeout(t),n(window.Pusher)}),document.head.appendChild(r)})}async function Me(){let n=await je();if(!n)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new n("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:r=>{let o=t.subscribe(r);return{unsubscribe:()=>t.unsubscribe(r),addEventHandler:(i,a)=>(o.bind(i,a),()=>o.unbind(i,a))}}}}return e}function z(n,e,t){return`${n}.${e}@${t}`}function Ve({projectId:n,compositionId:e,compositionState:t=0,eventBus:{subscribe:r},callback:o,event:i="updated"}){let a=z(n,e,t),s=r(a),c=s.addEventHandler(i,o);return()=>{c(),s.unsubscribe()}}function ie({component:n}){var r;let e={},t=(r=n.slots)==null?void 0:r[G];return t==null||t.forEach(o=>{var a;let i=(a=o.parameters)==null?void 0:a[k];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Be({composition:n,locale:e}){P(n,(t,r,o)=>{if(t.type===B){let i=ie({component:t}),a=typeof e=="string"?e:e({component:t,locales:i}),s;if(a&&(s=i[a]),s!=null&&s.length){let[c,...p]=s;o.replaceComponent(c),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasDataConnectionClient,CanvasDataTypeClient,ChildEnhancerBuilder,EnhancerBuilder,UncachedCanvasClient,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
|
4
|
+
`))}}){let r=[],s=new Set,i=new Set;T(t,(c,h)=>{var m;Object.entries((m=c.parameters)!=null?m:{}).forEach(([u,f])=>{let p=e.resolveParameterEnhancer(c,u,f);p&&(i.add(p),r.push(Re(c,h,u,f,p,n)))});let l=e.resolveComponentEnhancers(c);r.push(we(c,h,l,n)),s.add(l)}),r.push(...Array.from(s).flatMap(c=>Array.from(c).map(async([,h])=>{var l;try{h.completeAll&&await((l=h.limitPolicy)!=null?l:E)(()=>h.completeAll())}catch(m){return{error:m,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async c=>{var h;try{c.completeAll&&await((h=c.limitPolicy)!=null?h:E)(()=>c.completeAll())}catch(l){return{error:l,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let a=(await Promise.all(r)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);a.length&&o(a)}async function we(t,e,n,o){return n.size&&(t.data={}),await Promise.all(Array.from(n).map(async([r,s])=>{var i;try{let c=await(s.completeAll?E:(i=s.limitPolicy)!=null?i:E)(async()=>s.enhanceOne({component:t,context:o}));c!=null&&(t.data[r]=c)}catch(a){let c=`Component ${w(e)} (type: ${t.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete t.data[r],{message:c,error:a}}}))}async function Re(t,e,n,o,r,s){var i;try{let c=await(r.completeAll?E:(i=r.limitPolicy)!=null?i:E)(async()=>r.enhanceOne({parameter:o,parameterName:n,component:t,context:s}));c===null?delete t.parameters[n]:typeof c=="undefined"?t.parameters[n]={...o,value:o.value}:t.parameters[n]={...o,value:c}}catch(a){let c=`Component ${w(e)} (type: ${t.type}): enhancing parameter ${n} (type: ${o.type}) threw exception. Parameter will be removed.`;return delete t.parameters[n],{message:c,error:a}}}var be=(t,...e)=>({enhanceOne:o=>{let r="enhanceOne"in t?t.enhanceOne(o):t(o);for(let s of e){let i=Se(r)?r:Promise.resolve(r),a="enhanceOne"in s?s.enhanceOne:s;r=i.then(c=>a({...o,parameter:{type:o.parameter.type,value:c}}))}return r},completeAll:async()=>{var o,r;for(let s of e)if("completeAll"in s)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r="completeAll"in t?(o=t.completeAll)==null?void 0:o.call(t):0)!=null?r:0}});function Se(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"}var ae=require("@uniformdev/context/api"),b=class extends ae.ApiClient{constructor(n){n.limitPolicy||(n.limitPolicy=G({}));super(n);this.canvasUrl="/api/v1/canvas"}async getCompositionList(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async getCompositionBySlug(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async getCompositionById(n){let{projectId:o}=this.options,r=this.createUrl(this.canvasUrl,{...n,projectId:o});return await this.apiClient(r)}async updateComposition(n){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(n){let o=this.createUrl("/api/v1/canvas"),{projectId:r}=this.options;await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...n,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(n){let{projectId:o}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...n,projectId:o});return await this.apiClient(r)}async updateComponentDefinition(n){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(n){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...n,projectId:this.options.projectId}),expectNoContent:!0})}},k=class extends b{constructor(e){super({...e,bypassCache:!0})}};var ce=require("@uniformdev/context/api"),B="/api/v1/data-connection",Oe="/api/v1/data-connections",$=class extends ce.ApiClient{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,o=this.createUrl(B,{...e,projectId:n});return await this.apiClient(o)}async getList(e){let{projectId:n}=this.options,o=this.createUrl(Oe,{...e,projectId:n});return await this.apiClient(o)}async upsert(e){let n=this.createUrl(B);await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(B);await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}};var pe=require("@uniformdev/context/api");var x,v=class extends pe.ApiClient{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,o=this.createUrl(I(v,x),{...e,projectId:n});return await this.apiClient(o)}async upsert(e){let n=this.createUrl(I(v,x));await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(I(v,x));await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},S=v;x=new WeakMap,X(S,x,"/api/v1/data-types");var Me="$personalization",Ne="$test",F="$localization",De="intentTag",J="locale",Ue="pz",Le="test",z="localized",bt=0,St=64,H="$pzCrit",W="$tstVrnt",je="$enr",Ve="is_incontext_editing_mode";var Ge=t=>t.startsWith("$");function ke(t){return t?t.map((e,n)=>{var s,i;let o=(i=(s=e.parameters)==null?void 0:s[H])==null?void 0:i.value,r=(o==null?void 0:o.name)||`pz-${n}-${e.type}`;return{...e,id:r,pz:o}}):[]}function Be(t){return t?t.map((e,n)=>{var s,i,a;let o=(i=(s=e.parameters)==null?void 0:s[W])==null?void 0:i.value,r=(a=o==null?void 0:o.id)!=null?a:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:r}}):[]}var Z=({composition:t,secret:e})=>{if(!e)return;let n=`${JSON.stringify(t)}-${e}`,o=0;for(let r=0;r<n.length;r++){let s=n.charCodeAt(r);o=(o<<5)-o+s,o|=0}return o};var me="https://js.pusher.com/7.0.3/pusher.min.js";async function $e(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((t,e)=>{let n=setTimeout(()=>{window.Pusher&&t(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${me}"><\/script> manually.`)},5e3),o=document.createElement("script");o.src=me,o.addEventListener("load",()=>{clearTimeout(n),t(window.Pusher)}),document.head.appendChild(o)})}async function Fe(){let t=await $e();if(!t)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new t("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:o=>{let r=n.subscribe(o);return{unsubscribe:()=>n.unsubscribe(o),addEventHandler:(s,i)=>(r.bind(s,i),()=>r.unbind(s,i))}}}}return e}function q(t,e,n){return`${t}.${e}@${n}`}function Je({projectId:t,compositionId:e,compositionState:n=0,eventBus:{subscribe:o},callback:r,event:s="updated"}){let i=q(t,e,n),a=o(i),c=a.addEventHandler(s,r);return()=>{c(),a.unsubscribe()}}function le({component:t}){var o;let e={},n=(o=t.slots)==null?void 0:o[z];return n==null||n.forEach(r=>{var i;let s=(i=r.parameters)==null?void 0:i[J];(s==null?void 0:s.value)&&typeof s.value=="string"&&(e[s.value]=e[s.value]||[],e[s.value].push(r))}),e}function ze({composition:t,locale:e}){T(t,(n,o,r)=>{if(n.type===F){let s=le({component:n}),i=typeof e=="string"?e:e({component:n,locales:s}),a;if(i&&(a=s[i]),a!=null&&a.length){let[c,...h]=a;r.replaceComponent(c),h.length&&r.insertAfter(h)}else r.removeComponent()}})}var He=t=>t.type==="select-component"&&t.id!==void 0,We=t=>t.type==="ready",Ze=t=>t.type==="update-composition",qe=t=>t.type==="add-component",Ye=t=>t.type==="move-component",Qe=({listenTo:t,broadcastTo:e})=>{let n=0,o={},r=[...e],s=p=>{r.forEach(d=>d.postMessage(JSON.stringify(p),"*"))},i=p=>{s({type:"select-component",id:p})},a=()=>{s({type:"ready"})},c=(p,d)=>{let y=++n;return o[y]={types:Array.isArray(p)?p:[p],handler:d},()=>{delete o[y]}},h=(p,d)=>{let y={type:"update-composition",composition:p,hash:Z({composition:p,secret:d})};s(y)},l=({componentId:p,index:d,slotName:y})=>{s({type:"add-component",componentId:p,slotName:y,index:d})},m=({componentId:p,index:d,slotName:y})=>{s({type:"move-component",componentId:p,slotName:y,index:d})},u=p=>{if(typeof p.data!="string"||p.source===window)return;let d=null;try{let y=JSON.parse(p.data);Object.hasOwn(y,"type")&&(d=y)}catch(y){}if(!!d)for(let y in o){let g=o[y];g.types.includes(d.type)&&g.handler(d,p)}};return t.forEach(p=>p.addEventListener("message",u)),{ready:a,destroy:()=>{t.forEach(p=>p.removeEventListener("message",u))},selectComponent:i,updateComposition:h,on:c,addComponent:l,moveComponent:m}};var O=require("@uniformdev/context/api"),Y=class extends O.ApiClient{constructor(n){n.limitPolicy||(n.limitPolicy=O.nullLimitPolicy);super(n);this.canvasUrl="/api/edge/v1/composition"}async getCompositionBySlug(n){let{projectId:o}=this.options,{dynamicVariables:r,...s}=n,i=this.createUrl(this.canvasUrl,{...s,projectId:o,dynamicVariables:JSON.stringify(r)});return await this.apiClient(i)}async getCompositionById(n){let{projectId:o}=this.options,{dynamicVariables:r,...s}=n,i=this.createUrl(this.canvasUrl,{...s,projectId:o,dynamicVariables:JSON.stringify(r)});return await this.apiClient(i)}};var Q=require("@uniformdev/context/api"),Ke=Q.ApiClientError;0&&(module.exports={ApiClientError,BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,CanvasDataConnectionClient,CanvasDataTypeClient,ChildEnhancerBuilder,EdgeCanvasClient,EnhancerBuilder,IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,UncachedCanvasClient,UniqueBatchEntries,compose,createBatchEnhancer,createCanvasChannel,createEventBus,createLimitPolicy,enhance,extractLocales,generateHash,getChannelName,getComponentPath,isAddComponentMessage,isMovingComponentMessage,isReadyMessage,isSelectComponentMessage,isSystemComponentDefinition,isUpdateCompositionMessage,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-
|
1
|
+
import{$ as Q,A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,V as K,W as L,X as M,Y as N,Z as O,_ as P,aa as R,ba as S,ca as T,da as U,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-IQWDQAHE.mjs";export{T as ApiClientError,f as BatchEntry,x as CANVAS_DRAFT_STATE,B as CANVAS_ENRICHMENT_TAG_PARAM,s as CANVAS_INTENT_TAG_PARAM,t as CANVAS_LOCALE_TAG_PARAM,w as CANVAS_LOCALIZATION_SLOT,r as CANVAS_LOCALIZATION_TYPE,z as CANVAS_PERSONALIZATION_PARAM,u as CANVAS_PERSONALIZE_SLOT,p as CANVAS_PERSONALIZE_TYPE,y as CANVAS_PUBLISHED_STATE,v as CANVAS_TEST_SLOT,q as CANVAS_TEST_TYPE,A as CANVAS_TEST_VARIANT_PARAM,l as CanvasClient,U as CanvasClientError,n as CanvasDataConnectionClient,o as CanvasDataTypeClient,d as ChildEnhancerBuilder,S as EdgeCanvasClient,e as EnhancerBuilder,C as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,m as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,R as createCanvasChannel,H as createEventBus,h as createLimitPolicy,j as enhance,K as extractLocales,G as generateHash,I as getChannelName,b as getComponentPath,P as isAddComponentMessage,Q as isMovingComponentMessage,N as isReadyMessage,M as isSelectComponentMessage,D as isSystemComponentDefinition,O as isUpdateCompositionMessage,L as localize,E as mapSlotToPersonalizedVariations,F as mapSlotToTestVariations,i as nullLimitPolicy,J as subscribeToComposition,a as walkComponentTree};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "17.
|
3
|
+
"version": "17.2.0",
|
4
4
|
"description": "Common functionality and types for Uniform Canvas",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -49,7 +49,7 @@
|
|
49
49
|
"devDependencies": {
|
50
50
|
"@types/retry": "0.12.1",
|
51
51
|
"@types/yargs": "17.0.12",
|
52
|
-
"@uniformdev/cli": "^17.
|
52
|
+
"@uniformdev/cli": "^17.2.0",
|
53
53
|
"p-limit": "4.0.0",
|
54
54
|
"p-retry": "5.1.1",
|
55
55
|
"p-throttle": "5.0.0",
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"yargs": "17.5.1"
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
-
"@uniformdev/context": "^17.
|
60
|
+
"@uniformdev/context": "^17.2.0"
|
61
61
|
},
|
62
62
|
"files": [
|
63
63
|
"/dist"
|
@@ -65,5 +65,5 @@
|
|
65
65
|
"publishConfig": {
|
66
66
|
"access": "public"
|
67
67
|
},
|
68
|
-
"gitHead": "
|
68
|
+
"gitHead": "18ea48d2d1da97733e9e3935e72bd61c665e180d"
|
69
69
|
}
|
package/dist/chunk-PFL3XEAQ.mjs
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
var oe=Object.create;var P=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var pe=(t,e,n)=>e in t?P(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var we=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(e,n)=>(typeof require!="undefined"?require:e)[n]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var Ie=(t,e)=>()=>(t&&(e=t(t=0)),e);var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Re=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},U=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ae(e))!ce.call(t,o)&&o!==n&&P(t,o,{get:()=>e[o],enumerable:!(r=ie(e,o))||r.enumerable});return t};var me=(t,e,n)=>(n=t!=null?oe(se(t)):{},U(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t)),be=t=>U(P({},"__esModule",{value:!0}),t);var Se=(t,e,n)=>(pe(t,typeof e!="symbol"?e+"":e,n),n),L=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)};var T=(t,e,n)=>(L(t,e,"read from private field"),n?n.call(t):e.get(t)),j=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)},le=(t,e,n,r)=>(L(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),Oe=(t,e,n,r)=>({set _(o){le(t,e,o,n)},get _(){return T(t,e,r)}});var G=x((Be,k)=>{function u(t,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(t)),this._timeouts=t,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}k.exports=u;u.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};u.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};u.prototype.retry=function(t){if(this._timeout&&clearTimeout(this._timeout),!t)return!1;var e=new Date().getTime();if(t&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(t),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(t);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n),this._options.unref&&this._timer.unref(),!0};u.prototype.attempt=function(t,e){this._fn=t,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};u.prototype.try=function(t){console.log("Using RetryOperation.try() is deprecated"),this.attempt(t)};u.prototype.start=function(t){console.log("Using RetryOperation.start() is deprecated"),this.attempt(t)};u.prototype.start=u.prototype.try;u.prototype.errors=function(){return this._errors};u.prototype.attempts=function(){return this._attempts};u.prototype.mainError=function(){if(this._errors.length===0)return null;for(var t={},e=null,n=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(t[i]||0)+1;t[i]=a,a>=n&&(e=o,n=a)}return e}});var F=x(f=>{var ue=G();f.operation=function(t){var e=f.timeouts(t);return new ue(e,{forever:t&&(t.forever||t.retries===1/0),unref:t&&t.unref,maxRetryTime:t&&t.maxRetryTime})};f.timeouts=function(t){if(t instanceof Array)return[].concat(t);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in t)e[n]=t[n];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<e.retries;o++)r.push(this.createTimeout(o,e));return t&&t.forever&&!r.length&&r.push(this.createTimeout(o,e)),r.sort(function(i,a){return i-a}),r};f.createTimeout=function(t,e){var n=e.randomize?Math.random()+1:1,r=Math.round(n*Math.max(e.minTimeout,1)*Math.pow(e.factor,t));return r=Math.min(r,e.maxTimeout),r};f.wrap=function(t,e,n){if(e instanceof Array&&(n=e,e=null),!n){n=[];for(var r in t)typeof t[r]=="function"&&n.push(r)}for(var o=0;o<n.length;o++){var i=n[o],a=t[i];t[i]=function(c){var p=f.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(h){p.retry(h)||(h&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){c.apply(t,m)})}.bind(t,a),t[i].options=e}}});var z=x((Ge,$)=>{$.exports=F()});function _(t,e){let n=[{ancestorsAndSelf:[{component:t,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let r=n.pop();if(!r)continue;let o=r.ancestorsAndSelf[0],i=!0;e(o.component,r.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{s[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:s,parentComponent:c,correctedParentSlotIndex:p}=M(r,o.component);if(s&&typeof p!="undefined")c.component.slots[s].splice(p,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:p,parentComponent:m,correctedParentSlotIndex:l}=M(r,o.component);if(p&&typeof l!="undefined")m.component.slots[p].splice(l+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){i=!1}});let a=o.component.slots;if(i&&a){let s=Object.keys(a);for(let c=s.length-1;c>=0;c--){let p=s[c],m=a[p];for(let l=m.length-1;l>=0;l--)n.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...r.ancestorsAndSelf]})}}}while(n.length>0)}function g(t){let e=[];for(let n=t.length-1;n>=0;n--){let{parentSlot:r,parentSlotIndex:o}=t[n];r&&o!==void 0&&e.push(`${r}[${o}]`)}return`.${e.join(".")}`}function M(t,e){let{parentSlot:n,parentSlotIndex:r}=t.ancestorsAndSelf[0],o=t.ancestorsAndSelf[1],i=r;return n&&r!==void 0&&o.component.slots&&o.component.slots[n][r]!==e&&(i=o.component.slots[n].findIndex(a=>a===e)),{parentSlot:n,parentComponent:o,correctedParentSlotIndex:i}}var V=class{constructor(e,n){this.groups=e.reduce((r,o)=>{var a;let i=n(o.args);return r[i]=(a=r[i])!=null?a:[],r[i].push(o),r},{})}resolveKey(e,n){this.groups[e].forEach(r=>r.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(r=>{r.isCompleted||r.resolve(e)})})}};var v=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 r;return(r=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:r.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},B=class{constructor(){this._componentIndex={};this._rootBuilder=new v}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 v,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,r){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,r);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,r)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),r=this._componentIndex[e.type];if(r){n=new Map(n);for(let[o,i]of r.resolveComponentEnhancers())n.set(o,i)}return n}};var w=class{constructor(e,n,r){this._resolve=e;this._reject=n;this.args=r;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 je({handleBatch:t,shouldQueue:e,limitPolicy:n}){let r=[];return{enhanceOne:async a=>{if(!e||e(a))return new Promise((s,c)=>{r.push(new w(s,c,a))})},completeAll:async()=>{if(r.length>0){try{await t(r)}catch(s){r.forEach(c=>c.reject(s))}if(r.some(s=>!s.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let a=r.length;return r=[],a},limitPolicy:n}}var I=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function R({limit:t,interval:e,strict:n}){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let r=new Map,o=0,i=0;function a(){let m=Date.now();return m-o>e?(i=1,o=m,0):(i<t?i++:(o+=e,i=1),o-m)}let s=[];function c(){let m=Date.now();if(s.length<t)return s.push(m),0;let l=s.shift()+e;return m>=l?(s.push(m),0):(s.push(l),l-m)}let p=n?c:a;return m=>{let l=function(...h){if(!l.isEnabled)return(async()=>m.apply(this,h))();let y;return new Promise((E,re)=>{y=setTimeout(()=>{E(m.apply(this,h)),r.delete(y)},p()),r.set(y,re)})};return l.abort=()=>{for(let h of r.keys())clearTimeout(h),r.get(h)(new I);r.clear(),s.splice(0,s.length)},l.isEnabled=!0,l}}var Z=me(z(),1),he=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),b=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},fe=(t,e,n)=>{let r=n.retries-(e-1);return t.attemptNumber=e,t.retriesLeft=r,t},de=t=>he.has(t),J=t=>globalThis.DOMException===void 0?new Error(t):new DOMException(t);async function S(t,e){return new Promise((n,r)=>{e={onFailedAttempt(){},retries:10,...e};let o=Z.default.operation(e);o.attempt(async i=>{try{n(await t(i))}catch(a){if(!(a instanceof Error)){r(new TypeError(`Non-error was thrown: "${a}". You should only throw errors.`));return}if(a instanceof b)o.stop(),r(a.originalError);else if(a instanceof TypeError&&!de(a.message))o.stop(),r(a);else{fe(a,i,e);try{await e.onFailedAttempt(a)}catch(s){r(s);return}o.retry(a)||r(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?J("The operation was aborted."):e.signal.reason;r(i instanceof Error?i:J(i))},{once:!0})})}function W({throttle:t={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=t?R(t):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let a=i;i=()=>S(a,e)}return i()}}var d=async t=>await t();async function Qe({composition:t,enhancers:e,context:n,onErrors:r=o=>{throw new Error(o.map(i=>`${i.message}
|
2
|
-
${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(`
|
3
|
-
|
4
|
-
`))}}){let o=[],i=new Set,a=new Set;_(t,(c,p)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let E=e.resolveParameterEnhancer(c,h,y);E&&(a.add(E),o.push(Ce(c,p,h,y,E,n)))});let m=e.resolveComponentEnhancers(c);o.push(ye(c,p,m,n)),i.add(m)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:d)(()=>p.completeAll())}catch(l){return{error:l,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(a).map(async c=>{var p;try{c.completeAll&&await((p=c.limitPolicy)!=null?p:d)(()=>c.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let s=(await Promise.all(o)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);s.length&&r(s)}async function ye(t,e,n,r){return n.size&&(t.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var a;try{let c=await(i.completeAll?d:(a=i.limitPolicy)!=null?a:d)(async()=>i.enhanceOne({component:t,context:r}));c!=null&&(t.data[o]=c)}catch(s){let c=`Component ${g(e)} (type: ${t.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete t.data[o],{message:c,error:s}}}))}async function Ce(t,e,n,r,o,i){var a;try{let c=await(o.completeAll?d:(a=o.limitPolicy)!=null?a:d)(async()=>o.enhanceOne({parameter:r,parameterName:n,component:t,context:i}));c===null?delete t.parameters[n]:typeof c=="undefined"?t.parameters[n]={...r,value:r.value}:t.parameters[n]={...r,value:c}}catch(s){let c=`Component ${g(e)} (type: ${t.type}): enhancing parameter ${n} (type: ${r.type}) threw exception. Parameter will be removed.`;return delete t.parameters[n],{message:c,error:s}}}var Xe=(t,...e)=>({enhanceOne:r=>{let o="enhanceOne"in t?t.enhanceOne(r):t(r);for(let i of e){let a=Ee(o)?o:Promise.resolve(o),s="enhanceOne"in i?i.enhanceOne:i;o=a.then(c=>s({...r,parameter:{type:r.parameter.type,value:c}}))}return o},completeAll:async()=>{var r,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="completeAll"in t?(r=t.completeAll)==null?void 0:r.call(t):0)!=null?o:0}});function Ee(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"}import{ApiClient as Pe}from"@uniformdev/context/api";var O=class extends Pe{constructor(e){e.limitPolicy||(e.limitPolicy=W({})),super(e)}get canvasUrl(){return this.options.experiment14?"/api/edge/v1/composition":"/api/v1/canvas"}async getCompositionList(e){let{projectId:n}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:n});return await this.apiClient(r)}async getCompositionBySlug(e){let{projectId:n}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:n});return await this.apiClient(r)}async getCompositionById(e){let{projectId:n}=this.options,r=this.createUrl(this.canvasUrl,{...e,projectId:n});return await this.apiClient(r)}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"),{projectId:r}=this.options;await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(r)}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})}},H=class extends O{constructor(e){super({...e,bypassCache:!0})}};import{ApiClient as Te}from"@uniformdev/context/api";var N="/api/v1/data-connection",Ae="/api/v1/data-connections",q=class extends Te{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,r=this.createUrl(N,{...e,projectId:n});return await this.apiClient(r)}async getList(e){let{projectId:n}=this.options,r=this.createUrl(Ae,{...e,projectId:n});return await this.apiClient(r)}async upsert(e){let n=this.createUrl(N);await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(N);await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}};import{ApiClient as _e}from"@uniformdev/context/api";var C,A=class extends _e{constructor(e){super(e)}async get(e){let{projectId:n}=this.options,r=this.createUrl(T(A,C),{...e,projectId:n});return await this.apiClient(r)}async upsert(e){let n=this.createUrl(T(A,C));await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let n=this.createUrl(T(A,C));await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},D=A;C=new WeakMap,j(D,C,"/api/v1/data-types");var ht="$personalization",ft="$test",Y="$localization",dt="intentTag",Q="locale",yt="pz",Ct="test",K="localized",Et=0,Pt=64,X="$pzCrit",ee="$tstVrnt",Tt="$enr";var _t=t=>t.startsWith("$");function gt(t){return t?t.map((e,n)=>{var i,a;let r=(a=(i=e.parameters)==null?void 0:i[X])==null?void 0:a.value,o=(r==null?void 0:r.name)||`pz-${n}-${e.type}`;return{...e,id:o,pz:r}}):[]}function Rt(t){return t?t.map((e,n)=>{var i,a,s;let r=(a=(i=e.parameters)==null?void 0:i[ee])==null?void 0:a.value,o=(s=r==null?void 0:r.id)!=null?s:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:o}}):[]}var te="https://js.pusher.com/7.0.3/pusher.min.js";async function ve(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((t,e)=>{let n=setTimeout(()=>{window.Pusher&&t(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${te}"><\/script> manually.`)},5e3),r=document.createElement("script");r.src=te,r.addEventListener("load",()=>{clearTimeout(n),t(window.Pusher)}),document.head.appendChild(r)})}async function St(){let t=await ve();if(!t)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new t("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:r=>{let o=n.subscribe(r);return{unsubscribe:()=>n.unsubscribe(r),addEventHandler:(i,a)=>(o.bind(i,a),()=>o.unbind(i,a))}}}}return e}function ne(t,e,n){return`${t}.${e}@${n}`}function Ut({projectId:t,compositionId:e,compositionState:n=0,eventBus:{subscribe:r},callback:o,event:i="updated"}){let a=ne(t,e,n),s=r(a),c=s.addEventHandler(i,o);return()=>{c(),s.unsubscribe()}}function xe({component:t}){var r;let e={},n=(r=t.slots)==null?void 0:r[K];return n==null||n.forEach(o=>{var a;let i=(a=o.parameters)==null?void 0:a[Q];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Vt({composition:t,locale:e}){_(t,(n,r,o)=>{if(n.type===Y){let i=xe({component:n}),a=typeof e=="string"?e:e({component:n,locales:i}),s;if(a&&(s=i[a]),s!=null&&s.length){let[c,...p]=s;o.replaceComponent(c),p.length&&o.insertAfter(p)}else o.removeComponent()}})}export{we as a,Ie as b,x as c,Re as d,me as e,be as f,Se as g,T as h,j as i,le as j,Oe as k,_ as l,g as m,V as n,v as o,B as p,w as q,je as r,W as s,d as t,Qe as u,Xe as v,O as w,H as x,q as y,D as z,ht as A,ft as B,Y as C,dt as D,Q as E,yt as F,Ct as G,K as H,Et as I,Pt as J,X as K,ee as L,Tt as M,_t as N,gt as O,Rt as P,St as Q,ne as R,Ut as S,xe as T,Vt as U};
|