@spiffcommerce/core 15.0.3 → 15.0.4
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/main.js +33 -2
- package/dist/module.js +46 -15
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -754,6 +754,9 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
754
754
|
firstName
|
|
755
755
|
lastName
|
|
756
756
|
phoneNumber
|
|
757
|
+
partner {
|
|
758
|
+
id
|
|
759
|
+
}
|
|
757
760
|
}
|
|
758
761
|
type
|
|
759
762
|
}
|
|
@@ -851,12 +854,40 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
851
854
|
mutation BundleAddStakeholder($id: String!, $details: CustomerDetailsInput!, $type: String!) {
|
|
852
855
|
bundleAddStakeholder(id: $id, details: $details, type: $type) {
|
|
853
856
|
id
|
|
857
|
+
bundleStakeholders {
|
|
858
|
+
id
|
|
859
|
+
customer {
|
|
860
|
+
id
|
|
861
|
+
emailAddress
|
|
862
|
+
firstName
|
|
863
|
+
lastName
|
|
864
|
+
phoneNumber
|
|
865
|
+
partner {
|
|
866
|
+
id
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
type
|
|
870
|
+
}
|
|
854
871
|
}
|
|
855
872
|
}
|
|
856
873
|
`,mc=v.gql`
|
|
857
874
|
mutation BundleUpdateStakeholders($id: String!, $input: [BundleStakeholderInput!]!) {
|
|
858
875
|
bundleUpdateStakeholders(id: $id, input: $input) {
|
|
859
876
|
id
|
|
877
|
+
bundleStakeholders {
|
|
878
|
+
id
|
|
879
|
+
customer {
|
|
880
|
+
id
|
|
881
|
+
emailAddress
|
|
882
|
+
firstName
|
|
883
|
+
lastName
|
|
884
|
+
phoneNumber
|
|
885
|
+
partner {
|
|
886
|
+
id
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
type
|
|
890
|
+
}
|
|
860
891
|
}
|
|
861
892
|
}
|
|
862
893
|
`,Ec=v.gql`
|
|
@@ -895,7 +926,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
895
926
|
}
|
|
896
927
|
}
|
|
897
928
|
}
|
|
898
|
-
`;function bc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Fc{constructor(t,e){bc(this,"bundleId",void 0),bc(this,"globalPropertyState",void 0),bc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Ia.getShadowGraphqlClient().mutate({mutation:Mc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Ia.getShadowGraphqlClient().query({query:Sc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Ia.getShadowGraphqlClient().mutate({mutation:vc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Pc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Yc{constructor(t){Pc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function Nc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class kc{constructor(t){Nc(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new Rc(t)))}getResource(){return this.collection}}class Rc{constructor(t){Nc(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Hc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Uc{constructor(t,e,i,n){Hc(this,"client",void 0),Hc(this,"id",void 0),Hc(this,"name",void 0),Hc(this,"metadata",void 0),Hc(this,"productCollection",void 0),Hc(this,"bundleStateManager",void 0),Hc(this,"globalConfiguration",void 0),Hc(this,"globalPropertyStateManager",void 0),Hc(this,"globalPropertyHandleService",void 0),Hc(this,"eventListeners",new Map),Hc(this,"initializationPromise",void 0),Hc(this,"workflowExperiences",[]),Hc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Yc(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Fc(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Cc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new kc(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Ia.getShadowGraphqlClient().mutate({mutation:uc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const i=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(da.getMap("transactionOwnerIds")||new Map).get(i);await Ia.getShadowGraphqlClient().mutate({mutation:dc,variables:{id:this.id,transactionId:i},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,i=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Ia.getShadowGraphqlClient().mutate({mutation:wc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),i&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Ia.getShadowGraphqlClient().mutate({mutation:Bc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const i=this.workflowExperiences[t];if(i.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,i.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const i=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=i,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Ia.getShadowGraphqlClient().mutate({mutation:pc,variables:{id:this.id,details:t,type:e||gr.Owner}})}async updateStakeholders(t){await Ia.getShadowGraphqlClient().mutate({mutation:mc,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Ia.getShadowGraphqlClient().query({query:cc,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async finish(t){return await tc(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const i=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=i,this.previewService)for(const t of i)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Ia.getShadowGraphqlClient().mutate({mutation:hc,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Ia.getShadowGraphqlClient().mutate({mutation:Ec,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function Gc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Tc=t.gql`
|
|
929
|
+
`;function bc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Fc{constructor(t,e){bc(this,"bundleId",void 0),bc(this,"globalPropertyState",void 0),bc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Ia.getShadowGraphqlClient().mutate({mutation:Mc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Ia.getShadowGraphqlClient().query({query:Sc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Ia.getShadowGraphqlClient().mutate({mutation:vc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Pc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Yc{constructor(t){Pc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function Nc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class kc{constructor(t){Nc(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new Rc(t)))}getResource(){return this.collection}}class Rc{constructor(t){Nc(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Hc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Uc{constructor(t,e,i,n){Hc(this,"client",void 0),Hc(this,"id",void 0),Hc(this,"name",void 0),Hc(this,"metadata",void 0),Hc(this,"productCollection",void 0),Hc(this,"bundleStateManager",void 0),Hc(this,"globalConfiguration",void 0),Hc(this,"globalPropertyStateManager",void 0),Hc(this,"globalPropertyHandleService",void 0),Hc(this,"eventListeners",new Map),Hc(this,"initializationPromise",void 0),Hc(this,"workflowExperiences",[]),Hc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Yc(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Fc(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Cc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new kc(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Ia.getShadowGraphqlClient().mutate({mutation:uc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const i=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(da.getMap("transactionOwnerIds")||new Map).get(i);await Ia.getShadowGraphqlClient().mutate({mutation:dc,variables:{id:this.id,transactionId:i},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,i=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Ia.getShadowGraphqlClient().mutate({mutation:wc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),i&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Ia.getShadowGraphqlClient().mutate({mutation:Bc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const i=this.workflowExperiences[t];if(i.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,i.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const i=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=i,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){const i=await Ia.getShadowGraphqlClient().mutate({mutation:pc,variables:{id:this.id,details:t,type:e||gr.Owner}});if(!i.data?.bundleAddStakeholder)throw new Error("Bundle not found!");const n=i.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(t){const e=await Ia.getShadowGraphqlClient().mutate({mutation:mc,variables:{id:this.id,input:t}});if(!e.data?.bundleUpdateStakeholders)throw new Error("Bundle not found!");const i=e.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(i)}async getAllStakeholders(){const t=await Ia.getShadowGraphqlClient().query({query:cc,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");const e=t.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(e),e}storeStakeholderCustomers(t){t.forEach((t=>{t.customer&&this.client.storeCustomer(t.customer)}))}async finish(t){return await tc(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const i=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=i,this.previewService)for(const t of i)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Ia.getShadowGraphqlClient().mutate({mutation:hc,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Ia.getShadowGraphqlClient().mutate({mutation:Ec,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function Gc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Tc=t.gql`
|
|
899
930
|
mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
|
|
900
931
|
processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
|
|
901
932
|
id
|
|
@@ -1540,5 +1571,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
1540
1571
|
}
|
|
1541
1572
|
}
|
|
1542
1573
|
}
|
|
1543
|
-
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:e}});var A;const a=n.data.workflows;if(void 0===a||a.length!==e.length)throw new Error(`Unable to read workflows: ${n.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(A,i),r=A.map((t=>Ha.set({id:t,options:i},(async(t,e)=>{const i=(await e).find((e=>e.id===t));if(!i)throw new Error(`Workflow not found: ${t}`);return i})(t,a)))),s=n.filter((t=>void 0!==t));return await Promise.all(s.concat(r))},rl=async(t,e)=>(await al([t],e))[0],sl=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class ol{constructor(t){var e;Kc(this,"options",void 0),Kc(this,"initialized",void 0),Kc(this,"currencyCode",void 0),Kc(this,"customer",void 0),Kc(this,"experienceOptions",void 0),Kc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Os})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),Kc(this,"storeCustomer",(t=>{const e=da.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),da.setMap("partnerCustomerIds",e)})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Oc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:gr.Owner})}const i=da.getMap("bundlePartnerIds")||new Map;if(i.has(t)){const e=i.get(t),n=(da.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Ia.getShadowGraphqlClient(),i=await e.query({query:$c,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:gr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:_c,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Ia.getShadowGraphqlClient(),i=(await e.query({query:tl,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:el,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.storeCustomer(i),this.customer=i,{customer:i,isAuthenticated:!1}}this.storeCustomer(i);const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Ia.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:il,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(this.storeCustomer(A),Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:nl,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:Al,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),this.storeCustomer(i),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:gc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const i=da.getMap("bundlePartnerIds")||new Map;i.set(e.id,e.partner.id),da.setMap("bundlePartnerIds",i),fa(e.bundleOwnerId);const n=da.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",n),new Uc(this,e)}async getExistingBundle(t,e,i){const n=da.getMap("bundleOwnerIds")?.get(t);n&&fa(n);const A=await Ia.getShadowGraphqlClient().query({query:oc,variables:{id:t},fetchPolicy:"no-cache"});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=A.data?.bundles[0],r=da.getMap("bundlePartnerIds")||new Map;r.set(a.id,a.partner.id),da.setMap("bundlePartnerIds",r);const s=new Uc(this,a,e,i);return await s.getInitializationPromise(),s}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:lc,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Ts,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await rl(a.workflowId);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r,readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:Hs,variables:{...e,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=rl(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=sl(o.transaction,o.workflow);if(o.renderableContextService=new Ms(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new ac(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new oa("No options provided!");const i=Ia.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),A=n.filter((t=>"transaction"===t.option.type)),a=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),r=(await Promise.all([(async()=>{if(0===A.length)return[];const t=A.map((t=>t.option.transactionId)),e=await i.query({query:Ts,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==A.length){const t=e.errors?.[0]?.message||"Unknown error";throw new oa(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:A.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:A[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await i.mutate({mutation:Us,variables:{inputs:a.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new oa(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),s=[...new Set(r.map((t=>t.workflowId)))],o=await al(s,e),c=new Map(o.map((t=>[t.id,t]))),l=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},g=da.getMap("transactionOwnerIds")||new Map,h=r.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=c.get(n),s=t[a];!g.get(i.id)&&i.transactionOwnerId&&g.set(i.id,i.transactionOwnerId);const o=g.get(i.id)||void 0,h={product:i.product,transaction:i,layouts:[],stateMutationFunc:A?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:o}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===s.type};if("transaction"===s.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else if(!A&&s.workflowState){const t=JSON.parse(s.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else h.layouts=sl(h.transaction,h.workflow);return h.renderableContextService=new Ms(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:s}}));da.setMap("transactionOwnerIds",g);const d=(await Promise.all(h)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new ac(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:Hs,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Ts,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Ts,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Gs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await rl(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new Ms(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new ac(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Js,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=rl(t);if(await Promise.all([A,a]),this.experienceOptions.workflow=await a,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=sl(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new Ms(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const r=new ac(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function cl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ll{constructor(){cl(this,"getProduct",void 0),cl(this,"getCommandContext",void 0),cl(this,"getAllLayoutData",void 0),cl(this,"getMetadata",void 0),cl(this,"getWorkflowMetadata",void 0),cl(this,"getStepStorage",void 0),cl(this,"setModelContainer",void 0),cl(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function gl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let hl;var dl;(dl=hl||(hl={})).SelectFrame="SelectFrame",dl.SelectImage="SelectImage",dl.Position="Position";class ul extends Po{constructor(t,e){super(t,e),gl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return co.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return co.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?hl.SelectFrame:e||i||this.getImageData()?hl.Position:hl.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const wl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),jr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),jr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
|
|
1574
|
+
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:e}});var A;const a=n.data.workflows;if(void 0===a||a.length!==e.length)throw new Error(`Unable to read workflows: ${n.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(A,i),r=A.map((t=>Ha.set({id:t,options:i},(async(t,e)=>{const i=(await e).find((e=>e.id===t));if(!i)throw new Error(`Workflow not found: ${t}`);return i})(t,a)))),s=n.filter((t=>void 0!==t));return await Promise.all(s.concat(r))},rl=async(t,e)=>(await al([t],e))[0],sl=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class ol{constructor(t){var e;Kc(this,"options",void 0),Kc(this,"initialized",void 0),Kc(this,"currencyCode",void 0),Kc(this,"customer",void 0),Kc(this,"experienceOptions",void 0),Kc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Os})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Oc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:gr.Owner})}const i=da.getMap("bundlePartnerIds")||new Map;if(i.has(t)){const e=i.get(t),n=(da.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Ia.getShadowGraphqlClient(),i=await e.query({query:$c,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:gr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:_c,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Ia.getShadowGraphqlClient(),i=(await e.query({query:tl,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:el,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.storeCustomer(i),this.customer=i,{customer:i,isAuthenticated:!1}}this.storeCustomer(i);const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Ia.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:il,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(this.storeCustomer(A),Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:nl,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:Al,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),this.storeCustomer(i),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:gc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const i=da.getMap("bundlePartnerIds")||new Map;i.set(e.id,e.partner.id),da.setMap("bundlePartnerIds",i),fa(e.bundleOwnerId);const n=da.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",n),new Uc(this,e)}async getExistingBundle(t,e,i){const n=da.getMap("bundleOwnerIds")?.get(t);n&&fa(n);const A=await Ia.getShadowGraphqlClient().query({query:oc,variables:{id:t},fetchPolicy:"no-cache"});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=A.data?.bundles[0],r=da.getMap("bundlePartnerIds")||new Map;r.set(a.id,a.partner.id),da.setMap("bundlePartnerIds",r);const s=new Uc(this,a,e,i);return await s.getInitializationPromise(),s}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:lc,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Ts,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await rl(a.workflowId);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r,readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:Hs,variables:{...e,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=rl(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=sl(o.transaction,o.workflow);if(o.renderableContextService=new Ms(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new ac(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new oa("No options provided!");const i=Ia.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),A=n.filter((t=>"transaction"===t.option.type)),a=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),r=(await Promise.all([(async()=>{if(0===A.length)return[];const t=A.map((t=>t.option.transactionId)),e=await i.query({query:Ts,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==A.length){const t=e.errors?.[0]?.message||"Unknown error";throw new oa(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:A.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:A[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await i.mutate({mutation:Us,variables:{inputs:a.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new oa(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),s=[...new Set(r.map((t=>t.workflowId)))],o=await al(s,e),c=new Map(o.map((t=>[t.id,t]))),l=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},g=da.getMap("transactionOwnerIds")||new Map,h=r.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=c.get(n),s=t[a];!g.get(i.id)&&i.transactionOwnerId&&g.set(i.id,i.transactionOwnerId);const o=g.get(i.id)||void 0,h={product:i.product,transaction:i,layouts:[],stateMutationFunc:A?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:o}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===s.type};if("transaction"===s.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else if(!A&&s.workflowState){const t=JSON.parse(s.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else h.layouts=sl(h.transaction,h.workflow);return h.renderableContextService=new Ms(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:s}}));da.setMap("transactionOwnerIds",g);const d=(await Promise.all(h)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new ac(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:Hs,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Ts,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Ts,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Gs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await rl(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new Ms(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new ac(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Js,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=rl(t);if(await Promise.all([A,a]),this.experienceOptions.workflow=await a,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=sl(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new Ms(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const r=new ac(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(t){const e=da.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),da.setMap("partnerCustomerIds",e)}}function cl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class ll{constructor(){cl(this,"getProduct",void 0),cl(this,"getCommandContext",void 0),cl(this,"getAllLayoutData",void 0),cl(this,"getMetadata",void 0),cl(this,"getWorkflowMetadata",void 0),cl(this,"getStepStorage",void 0),cl(this,"setModelContainer",void 0),cl(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function gl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let hl;var dl;(dl=hl||(hl={})).SelectFrame="SelectFrame",dl.SelectImage="SelectImage",dl.Position="Position";class ul extends Po{constructor(t,e){super(t,e),gl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return co.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return co.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?hl.SelectFrame:e||i||this.getImageData()?hl.Position:hl.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const wl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),jr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),jr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
|
|
1544
1575
|
//# sourceMappingURL=main.js.map
|