@spiffcommerce/core 21.9.0-alpha.10 → 21.9.0-alpha.11
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/index.js +4 -4
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8204,13 +8204,13 @@ class Xn extends gt {
|
|
|
8204
8204
|
async applyGlobalState(e) {
|
|
8205
8205
|
const t = this.getStateValue();
|
|
8206
8206
|
if (!t)
|
|
8207
|
-
return
|
|
8207
|
+
return;
|
|
8208
8208
|
const A = await v.getLocalOrFromServer(t);
|
|
8209
8209
|
if (!A)
|
|
8210
|
-
return
|
|
8211
|
-
await this.applyImageSelection(A, e);
|
|
8210
|
+
return;
|
|
8211
|
+
await this.applyImageSelection(A, e, !1);
|
|
8212
8212
|
const a = this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);
|
|
8213
|
-
a
|
|
8213
|
+
a ? (console.log({ aspect: t, storage: a }), this.updateSharedStepStorage({ ...a })) : (this.updateSharedStepStorage({ originalAssetKey: t }), await this.bundle.getGlobalPropertyStateManager().setAspectStorage(this.property.name, { originalAssetKey: t }));
|
|
8214
8214
|
}
|
|
8215
8215
|
async applyImageSelection(e, t, A = !0) {
|
|
8216
8216
|
const n = this.getSharedSteps(t).map((i) => i.selectImage(e, A));
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2320,7 +2320,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2320
2320
|
id
|
|
2321
2321
|
}
|
|
2322
2322
|
}
|
|
2323
|
-
`;class ea{constructor(e){this.handleCache={},this.bundle=e}async getHandle(e){if(this.handleCache[e.name])return this.handleCache[e.name];const t=await this.createHandle(e);return this.handleCache[e.name]=t,t}async getHandles(){var t;if(!((t=this.bundle.getProductCollection())!=null&&t.getResource().globalPropertyConfiguration))return[];const e=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(e.aspects.map(A=>this.getHandle(A)))}applyConditionsFromState(e,t){return t?e.filter(A=>this.aspectConditionsSatisfied(A.getRawProperty(),t)):e}aspectConditionsSatisfied(e,t){return!e.conditions||e.conditions.length===0?!0:e.conditions.some(A=>{const n=t.aspects.find(a=>a.name===A.targetAspectName);return n?A.requiredVariantSelections.some(a=>a===n.value):!1})}async createHandle(e){switch(e.type){case l.AspectType.FileUpload:return new Zt(this.bundle,e);case l.AspectType.Option:{const t=e.entityId?await O.getOption(e.entityId):void 0;return(t==null?void 0:t.type)==="Color"?new _t(this.bundle,e,t):new Ke(this.bundle,e,t)}case l.AspectType.Text:return new $t(this.bundle,e)}}}class Se{constructor(e,t){this.bundle=e,this.property=t}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(e){return(e??this.bundle.getWorkflowExperiences()).flatMap(n=>n.getSteps().filter(a=>{var i;return a.getOverrideGlobalPropertyConfiguration(this.property.type)?!1:(i=a.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name})}))}getStateValue(){return this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name)}}class Zt extends Se{constructor(e,t){super(e,t)}async selectImage(e){const t=this.bundle.getGlobalPropertyStateManager();await Promise.all([t.setAspect(this.property.name,e.key,{...t.getAspectStorage(this.property.name)||{},originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}),this.applyImageSelection(e)])}async removeBackgroundFromImage(e=!0){const t=await this.getOriginalImage();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=this.bundle.getGlobalPropertyStateManager(),n=await v.removeBackgroundFromAsset(t),i={...A.getAspectStorage(this.property.name),backgroundRemovedAssetKey:n.key,useOriginalAsset:!e},s=[e?A.setAspect(this.property.name,n.key,i):A.setAspectStorage(this.property.name,i)];return e&&s.push(this.applyImageSelection(n,void 0,!1)),await Promise.all(s),this.updateSharedStepStorage(i),n}hasImage(){return!!this.getStateValue()}async getImage(){const e=this.getStateValue();if(e)return v.getLocalOrFromServer(e)}async getOriginalImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.originalAssetKey)return v.getLocalOrFromServer(e.originalAssetKey)}async getBackgroundRemovedImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.backgroundRemovedAssetKey)return v.getLocalOrFromServer(e.backgroundRemovedAssetKey)}getUseOriginalImage(){var e;return((e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name))==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImage(e){const t=await this.getOriginalImage();if(!t)throw new Error("You must select an image before calling setUseOriginalImage");const A=this.bundle.getGlobalPropertyStateManager(),n=A.getAspectStorage(this.property.name);if((n==null?void 0:n.useOriginalAsset)===e)return;const a={...n,useOriginalAsset:e},i=[A.setAspectStorage(this.property.name,a)];if(e)i.push(this.applyImageSelection(t,void 0,!1));else{const o=async()=>{const s=await this.getBackgroundRemovedImage();if(!s)throw new Error("You must call removeBackgroundFromImage before attempting to use that version of the image.");this.applyImageSelection(s,void 0,!1)};i.push(o())}this.updateSharedStepStorage(a)}async applyGlobalState(e){const t=this.getStateValue();if(!t)return
|
|
2323
|
+
`;class ea{constructor(e){this.handleCache={},this.bundle=e}async getHandle(e){if(this.handleCache[e.name])return this.handleCache[e.name];const t=await this.createHandle(e);return this.handleCache[e.name]=t,t}async getHandles(){var t;if(!((t=this.bundle.getProductCollection())!=null&&t.getResource().globalPropertyConfiguration))return[];const e=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(e.aspects.map(A=>this.getHandle(A)))}applyConditionsFromState(e,t){return t?e.filter(A=>this.aspectConditionsSatisfied(A.getRawProperty(),t)):e}aspectConditionsSatisfied(e,t){return!e.conditions||e.conditions.length===0?!0:e.conditions.some(A=>{const n=t.aspects.find(a=>a.name===A.targetAspectName);return n?A.requiredVariantSelections.some(a=>a===n.value):!1})}async createHandle(e){switch(e.type){case l.AspectType.FileUpload:return new Zt(this.bundle,e);case l.AspectType.Option:{const t=e.entityId?await O.getOption(e.entityId):void 0;return(t==null?void 0:t.type)==="Color"?new _t(this.bundle,e,t):new Ke(this.bundle,e,t)}case l.AspectType.Text:return new $t(this.bundle,e)}}}class Se{constructor(e,t){this.bundle=e,this.property=t}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(e){return(e??this.bundle.getWorkflowExperiences()).flatMap(n=>n.getSteps().filter(a=>{var i;return a.getOverrideGlobalPropertyConfiguration(this.property.type)?!1:(i=a.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name})}))}getStateValue(){return this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name)}}class Zt extends Se{constructor(e,t){super(e,t)}async selectImage(e){const t=this.bundle.getGlobalPropertyStateManager();await Promise.all([t.setAspect(this.property.name,e.key,{...t.getAspectStorage(this.property.name)||{},originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}),this.applyImageSelection(e)])}async removeBackgroundFromImage(e=!0){const t=await this.getOriginalImage();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=this.bundle.getGlobalPropertyStateManager(),n=await v.removeBackgroundFromAsset(t),i={...A.getAspectStorage(this.property.name),backgroundRemovedAssetKey:n.key,useOriginalAsset:!e},s=[e?A.setAspect(this.property.name,n.key,i):A.setAspectStorage(this.property.name,i)];return e&&s.push(this.applyImageSelection(n,void 0,!1)),await Promise.all(s),this.updateSharedStepStorage(i),n}hasImage(){return!!this.getStateValue()}async getImage(){const e=this.getStateValue();if(e)return v.getLocalOrFromServer(e)}async getOriginalImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.originalAssetKey)return v.getLocalOrFromServer(e.originalAssetKey)}async getBackgroundRemovedImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.backgroundRemovedAssetKey)return v.getLocalOrFromServer(e.backgroundRemovedAssetKey)}getUseOriginalImage(){var e;return((e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name))==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImage(e){const t=await this.getOriginalImage();if(!t)throw new Error("You must select an image before calling setUseOriginalImage");const A=this.bundle.getGlobalPropertyStateManager(),n=A.getAspectStorage(this.property.name);if((n==null?void 0:n.useOriginalAsset)===e)return;const a={...n,useOriginalAsset:e},i=[A.setAspectStorage(this.property.name,a)];if(e)i.push(this.applyImageSelection(t,void 0,!1));else{const o=async()=>{const s=await this.getBackgroundRemovedImage();if(!s)throw new Error("You must call removeBackgroundFromImage before attempting to use that version of the image.");this.applyImageSelection(s,void 0,!1)};i.push(o())}this.updateSharedStepStorage(a)}async applyGlobalState(e){const t=this.getStateValue();if(!t)return;const A=await v.getLocalOrFromServer(t);if(!A)return;await this.applyImageSelection(A,e,!1);const n=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);n?(console.log({aspect:t,storage:n}),this.updateSharedStepStorage({...n})):(this.updateSharedStepStorage({originalAssetKey:t}),await this.bundle.getGlobalPropertyStateManager().setAspectStorage(this.property.name,{originalAssetKey:t}))}async applyImageSelection(e,t,A=!0){const a=this.getSharedSteps(t).map(i=>i.selectImage(e,A));await Promise.all(a)}updateSharedStepStorage(e){this.bundle.getWorkflowExperiences().forEach(A=>A.getSteps().forEach(n=>{var i;if(n.getOverrideGlobalPropertyConfiguration(this.property.type))return;((i=n.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name}))&&A.getWorkflowManager().updateStorage(n.getId(),{framePatternData:e})}))}}class $t extends Se{constructor(e,t){super(e,t)}getText(){const e=this.getStateValue();return e||""}async setText(e){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,e),this.applyTextSelection(e)])}async applyGlobalState(e){const t=this.getStateValue();if(!t)return Promise.resolve();await this.applyTextSelection(t,e)}async applyTextSelection(e,t){const n=this.getSharedSteps(t).map(a=>{a.setText(e)});await Promise.all(n)}}class Ke extends Se{constructor(e,t,A){super(e,t),this.optionResource=A}getCurrentVariant(){var t,A;if(!this.optionResource)return;const e=this.getStateValue();if(e){const n=(A=this.optionResource.variants)==null?void 0:A.find(a=>a.id===e);return n?new K(n):void 0}else{const n=(t=this.optionResource.variants)==null?void 0:t.find(a=>{var i,o;return a.id===((o=(i=this.optionResource)==null?void 0:i.defaultVariant)==null?void 0:o.id)});return n?new K(n):void 0}}getAvailableVariants(){var t,A;return(((A=(t=this.optionResource)==null?void 0:t.variants)==null?void 0:A.filter(n=>n.enabled))||[]).map(n=>new K(n))}getAllVariants(){var t;return(((t=this.optionResource)==null?void 0:t.variants)||[]).map(A=>new K(A))}async selectVariant(e){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,e.getId()),this.applyVariantSelection(e)])}async applyGlobalState(e){var n,a;const t=this.getStateValue();if(!t)return Promise.resolve();const A=(a=(n=this.optionResource)==null?void 0:n.variants)==null?void 0:a.find(i=>i.id===t);return A?this.applyVariantSelection(new K(A),e):Promise.resolve()}async applyVariantSelection(e,t){const n=this.getSharedSteps(t).map(a=>a.selectVariant(e));await Promise.all(n)}}class _t extends Ke{constructor(e,t,A){super(e,t,A)}setCustomColor(e){this.getSharedSteps().forEach(A=>A.setCustomColor(e))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Ve=M.gql`
|
|
2324
2324
|
fragment GlobalPropertyStateAspectFields on GlobalPropertyStateAspect {
|
|
2325
2325
|
name
|
|
2326
2326
|
value
|
package/package.json
CHANGED