@spiffcommerce/core 12.9.3 → 12.9.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 +2 -2
- package/dist/module.js +9 -9
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -657,7 +657,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
|
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
|
-
`;function hc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class dc{constructor(t){hc(this,"bundleId",void 0),hc(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}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}setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((e=>e.name===t));return A?A.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Qr.getShadowGraphqlClient().mutate({mutation:lc,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 Qr.getShadowGraphqlClient().query({query:gc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Qr.getShadowGraphqlClient().mutate({mutation:cc,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 uc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class wc{constructor(t,e){uc(this,"client",void 0),uc(this,"id",void 0),uc(this,"name",void 0),uc(this,"metadata",void 0),uc(this,"productCollection",void 0),uc(this,"globalConfigurations",void 0),uc(this,"globalPropertyStateManager",void 0),uc(this,"workflowExperiences",[]),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.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new dc(this.id)
|
|
660
|
+
`;function hc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class dc{constructor(t){hc(this,"bundleId",void 0),hc(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}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}setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((e=>e.name===t));return A?A.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Qr.getShadowGraphqlClient().mutate({mutation:lc,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 Qr.getShadowGraphqlClient().query({query:gc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Qr.getShadowGraphqlClient().mutate({mutation:cc,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 uc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class wc{constructor(t,e){uc(this,"client",void 0),uc(this,"id",void 0),uc(this,"name",void 0),uc(this,"metadata",void 0),uc(this,"productCollection",void 0),uc(this,"globalConfigurations",void 0),uc(this,"globalPropertyStateManager",void 0),uc(this,"workflowExperiences",[]),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.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new dc(this.id)}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()}async hasGlobalProperties(){const t=await this.globalConfigurations;return t.length>0&&t.some((t=>t.aspects.length>0))}async getGlobalProperties(){const t=await this.globalConfigurations;if(0===t.length)return[];return(await Promise.all(t.map((t=>Promise.all(t.aspects.map((async t=>{switch(t.type){case tA.FileUpload:return new sc(this,t);case tA.Option:return new oc(this,t,t.entityId?await kr.getOption(t.entityId):void 0)}}))))))).flat()}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){const e=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e)))throw new Error("Unable to add transaction to bundle - Already Exists!");await Qr.getShadowGraphqlClient().mutate({mutation:_o,variables:{id:this.id,transactionId:e}}),this.workflowExperiences.push(t);const A=await this.getGlobalProperties();await Promise.all(A.map((e=>e.applyGlobalState([t]))))}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);if(!(e>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await Qr.getShadowGraphqlClient().mutate({mutation:tc,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(e,1)}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await Qr.getShadowGraphqlClient().mutate({mutation:nc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Qr.getShadowGraphqlClient().mutate({mutation:ec,variables:{id:this.id,details:t,type:e||ia.Owner}})}async updateStakeholders(t){await Qr.getShadowGraphqlClient().mutate({mutation:Ac,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Qr.getShadowGraphqlClient().query({query:qo,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||[]}setWorkflowExperiencesInternal(t){this.workflowExperiences=t}async updateBundle(){if(!(await Qr.getShadowGraphqlClient().mutate({mutation:$o,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async resolveGlobalProperties(){const t=this.productCollection;if(!t)return Promise.resolve([]);const e=new Set;t.products.forEach((t=>t.workflows?.forEach((t=>e.add(t.workflowName)))));const A=await Qr.getShadowGraphqlClient().query({query:ic,errorPolicy:"all",variables:{ids:Array.from(e)}}),i=new Map;return A.data.workflows?.forEach((t=>{t.globalPropertyConfiguration&&i.set(t.globalPropertyConfiguration.id,t.globalPropertyConfiguration)})),Object.values(i)}}function Bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const pc=t.gql`
|
|
661
661
|
fragment RegionFields on Region {
|
|
662
662
|
width
|
|
663
663
|
top
|
|
@@ -1282,5 +1282,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
|
|
|
1282
1282
|
}
|
|
1283
1283
|
}
|
|
1284
1284
|
}
|
|
1285
|
-
`,vc=async t=>{const e=(await Qr.getShadowGraphqlClient().query({query:Cc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},Fc=(t,e)=>{const A=t.workflowState,i=A?JSON.parse(A):void 0;return i?Object.values(i.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 Sc{constructor(t){var e;Bc(this,"options",void 0),Bc(this,"initialized",void 0),Bc(this,"experienceOptions",void 0),Bc(this,"currencyCode",void 0),Bc(this,"customer",void 0),Bc(this,"updateTransactionState",(async t=>{try{return Qr.getShadowGraphqlClient().mutate({...t,mutation:Ys})}catch(t){throw console.error(t),new ar("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,fr=e)}getAssetManager(){return Yr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=gr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return Er(A),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const A=gr.getMap("bundleCustomerIds");if(A?.has(t)){const e=A.get(t);if(e){if(await this.authenticateCustomerId(e)){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=Qr.getShadowGraphqlClient(),A=await e.query({query:fc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||0===A.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const i=A.data.transactions[0],n=i.product?.partner?.id;if(!n)throw new Error(`Unable to read transaction: ${t}`);if(i.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const r=gr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return Br(e),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const a=gr.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.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:Qc,errorPolicy:"all",variables:{id:i.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${i.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:i.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=gr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),gr.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=Qr.getShadowGraphqlClient(),A=(await e.query({query:yc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Dc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.customer=A,{customer:A,isAuthenticated:!1}}const i=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:i}}async authenticateCustomerId(t){const e=Qr.getShadowGraphqlClient(),A=gr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Ic,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Cr(i),this.customer=n,!0)}async generateVerificationCode(t){await Qr.getShadowGraphqlClient().mutate({mutation:xc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Qr.getShadowGraphqlClient().mutate({mutation:Mc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(A?.loginToken){if(!A.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=gr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),gr.setMap("customerTokens",e),Cr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Qr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");Er(e.bundleOwnerId);const A=gr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),gr.setMap("bundleOwnerIds",A),new wc(this,e)}async getExistingBundle(t,e){const A=await Qr.getShadowGraphqlClient().query({query:Xo,variables:{id:t}});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=A.data?.bundles[0],n=gr.getMap("bundleOwnerIds");n?.has(i.id)&&Er(n.get(i.id));const r=new wc(this,i);return i.transactions&&i.transactions.length>0&&await Promise.all(i.transactions.map(((t,A)=>r.reloadWorkflowExperience(t.id,e,A)))),r}async getWorkflowExperience(t,e,A,i){if(!i)return await this.getWorkflowExperienceDeprecated(t,e,A);const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Qr.getShadowGraphqlClient();if("transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:bs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ar("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ar("Existing transaction has no workflow ID.");const a=await vc(r.workflowId);if(!r.product)throw new ar("Failed to load transaction, product not available.");return{transaction:r,workflow:a,readOnly:A}}if("integration"===i.type||"external"===i.type){const e=async()=>{const e="integration"===i.type?{integrationProductId:i.integrationProductId}:{externalIntegrationId:i.externalIntegrationId,externalProductId:i.externalProductId},A=await t.mutate({mutation:Fs,variables:{...e,bulk:i.bulk,workflowId:i.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new ar("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ar("Failed to create transaction, product not available.");return n},A=vc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ar("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new nr("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:s,workflow:a},"transaction"===i.type&&r.workflowState){const t=JSON.parse(r.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else if(!s&&i.workflowState){const t=JSON.parse(i.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Cs(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]),"transaction"!==i.type){const t=gr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),Br(r.transactionOwnerId||""),gr.setMap("transactionOwnerIds",t)}else{const t=(gr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&Br(t)}this.initialized=!0;const o=new Vo(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await o.attachCustomerDetails({email:this.customer.emailAddress}),o}async initFromIntegrationProduct(t){if(""===t)throw new ar("No integration product ID provided.");const e=Qr.getShadowGraphqlClient(),A=await e.mutate({mutation:Fs,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(!A.data||!A.data.transactionCreate)throw new ar("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ar("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=gr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),Br(i.transactionOwnerId||""),gr.setMap("transactionOwnerIds",n),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ar("No transaction ID provided.");const A=Qr.getShadowGraphqlClient();if(e)return await(async()=>{const i=(await A.query({query:bs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:async()=>{throw new nr("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=gr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){Br(n);const i=(await A.query({query:bs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");return this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const n=(await A.mutate({mutation:Ss,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ar("Failed to read transaction.");if(!n.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),Br(n.transactionOwnerId),gr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ar("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot launch experience: Not initialized.");const i=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await vc(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 Wi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Cs(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 Vo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Qr.getShadowGraphqlClient().mutate({mutation:Ps,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=vc(t);if(await Promise.all([n,r]),this.experienceOptions.workflow=await r,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Cs(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 a=new Vo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ar("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Yc{constructor(){bc(this,"getProduct",void 0),bc(this,"getCommandContext",void 0),bc(this,"getAllLayoutData",void 0),bc(this,"getMetadata",void 0),bc(this,"getWorkflowMetadata",void 0),bc(this,"getStepStorage",void 0),bc(this,"setModelContainer",void 0),bc(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,A){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}}function Pc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Nc;var Rc;(Rc=Nc||(Nc={})).SelectFrame="SelectFrame",Rc.SelectImage="SelectImage",Rc.Position="Position";class kc extends yo{constructor(t,e){super(t,e),Pc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return eo.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 eo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,i){return i&&i.length>1&&void 0===t?Nc.SelectFrame:e||A||this.getImageData()?Nc.Position:Nc.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 Hc=t=>{const e=(0,i.useRef)(null),n=(0,i.useRef)(void 0),[r,a]=(0,i.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=Ur(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:w,uiDispatcher:B}=Wr(),p=(0,i.useCallback)((t=>{const e=t;B(new Kr({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),E=(0,i.useCallback)((t=>{o(t),1===l.length&&(n.current=void 0),2===l.length&&a(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),m=(0,i.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new Kr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),C=(0,i.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,A=2===l.length&&"touch"===l[0].pointerType;if(g&&A){const[t,e]=l,A=Math.abs(t.clientX-e.clientX),i=r;i&&p(w.zoom-.0055*(i-A)),a(A)}if(d&&(e||A)&&t.isPrimary){const e=(n?.current?.x||t.screenX)-t.screenX,A=(n?.current?.y||t.screenY)-t.screenY;B(new Kr({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-A/w.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,p,w.zoom,w.xTranslation,w.yTranslation,B]),f=(0,i.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,i.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,A=e.current.hasPointerCapture(t);d&&!A&&e.current.setPointerCapture(t),!d&&A&&e.current.releasePointerCapture(t)}),[e,d,l]),Ha([" "],(()=>{u(!0),B(new Kr({selectedElement:void 0}))}),(()=>u(!1))),Ha(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,i.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,A.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:f,onPointerDown:m,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:Q,children:t.children})};
|
|
1285
|
+
`,vc=async t=>{const e=(await Qr.getShadowGraphqlClient().query({query:Cc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},Fc=(t,e)=>{const A=t.workflowState,i=A?JSON.parse(A):void 0;return i?Object.values(i.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 Sc{constructor(t){var e;Bc(this,"options",void 0),Bc(this,"initialized",void 0),Bc(this,"experienceOptions",void 0),Bc(this,"currencyCode",void 0),Bc(this,"customer",void 0),Bc(this,"updateTransactionState",(async t=>{try{return Qr.getShadowGraphqlClient().mutate({...t,mutation:Ys})}catch(t){throw console.error(t),new ar("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,fr=e)}getAssetManager(){return Yr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=gr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return Er(A),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const A=gr.getMap("bundleCustomerIds");if(A?.has(t)){const e=A.get(t);if(e){if(await this.authenticateCustomerId(e)){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=Qr.getShadowGraphqlClient(),A=await e.query({query:fc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||0===A.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const i=A.data.transactions[0],n=i.product?.partner?.id;if(!n)throw new Error(`Unable to read transaction: ${t}`);if(i.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const r=gr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return Br(e),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const a=gr.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.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:Qc,errorPolicy:"all",variables:{id:i.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${i.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:i.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=gr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),gr.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=Qr.getShadowGraphqlClient(),A=(await e.query({query:yc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Dc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.customer=A,{customer:A,isAuthenticated:!1}}const i=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:i}}async authenticateCustomerId(t){const e=Qr.getShadowGraphqlClient(),A=gr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Ic,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Cr(i),this.customer=n,!0)}async generateVerificationCode(t){await Qr.getShadowGraphqlClient().mutate({mutation:xc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Qr.getShadowGraphqlClient().mutate({mutation:Mc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(A?.loginToken){if(!A.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=gr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),gr.setMap("customerTokens",e),Cr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Qr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");Er(e.bundleOwnerId);const A=gr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),gr.setMap("bundleOwnerIds",A),new wc(this,e)}async getExistingBundle(t,e){const A=await Qr.getShadowGraphqlClient().query({query:Xo,variables:{id:t}});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=A.data?.bundles[0],n=gr.getMap("bundleOwnerIds");n?.has(i.id)&&Er(n.get(i.id));const r=new wc(this,i);if(i.transactions&&i.transactions.length>0){const t=t=>{const A=e?A=>e(A,t):void 0;return this.getWorkflowExperience(void 0,void 0,A,{type:"transaction",transactionId:t})},A=await Promise.all(i.transactions.map((e=>t(e.id))));r.setWorkflowExperiencesInternal(A)}return r}async getWorkflowExperience(t,e,A,i){if(!i)return await this.getWorkflowExperienceDeprecated(t,e,A);const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Qr.getShadowGraphqlClient();if("transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:bs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ar("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ar("Existing transaction has no workflow ID.");const a=await vc(r.workflowId);if(!r.product)throw new ar("Failed to load transaction, product not available.");return{transaction:r,workflow:a,readOnly:A}}if("integration"===i.type||"external"===i.type){const e=async()=>{const e="integration"===i.type?{integrationProductId:i.integrationProductId}:{externalIntegrationId:i.externalIntegrationId,externalProductId:i.externalProductId},A=await t.mutate({mutation:Fs,variables:{...e,bulk:i.bulk,workflowId:i.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new ar("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ar("Failed to create transaction, product not available.");return n},A=vc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ar("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new nr("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:s,workflow:a},"transaction"===i.type&&r.workflowState){const t=JSON.parse(r.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else if(!s&&i.workflowState){const t=JSON.parse(i.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Cs(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]),"transaction"!==i.type){const t=gr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),Br(r.transactionOwnerId||""),gr.setMap("transactionOwnerIds",t)}else{const t=(gr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&Br(t)}this.initialized=!0;const o=new Vo(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await o.attachCustomerDetails({email:this.customer.emailAddress}),o}async initFromIntegrationProduct(t){if(""===t)throw new ar("No integration product ID provided.");const e=Qr.getShadowGraphqlClient(),A=await e.mutate({mutation:Fs,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(!A.data||!A.data.transactionCreate)throw new ar("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ar("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=gr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),Br(i.transactionOwnerId||""),gr.setMap("transactionOwnerIds",n),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ar("No transaction ID provided.");const A=Qr.getShadowGraphqlClient();if(e)return await(async()=>{const i=(await A.query({query:bs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:async()=>{throw new nr("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=gr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){Br(n);const i=(await A.query({query:bs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");return this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const n=(await A.mutate({mutation:Ss,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ar("Failed to read transaction.");if(!n.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),Br(n.transactionOwnerId),gr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ar("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot launch experience: Not initialized.");const i=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await vc(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 Wi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Cs(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 Vo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Qr.getShadowGraphqlClient().mutate({mutation:Ps,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=vc(t);if(await Promise.all([n,r]),this.experienceOptions.workflow=await r,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Cs(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 a=new Vo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ar("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Yc{constructor(){bc(this,"getProduct",void 0),bc(this,"getCommandContext",void 0),bc(this,"getAllLayoutData",void 0),bc(this,"getMetadata",void 0),bc(this,"getWorkflowMetadata",void 0),bc(this,"getStepStorage",void 0),bc(this,"setModelContainer",void 0),bc(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,A){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}}function Pc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;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:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Nc;var Rc;(Rc=Nc||(Nc={})).SelectFrame="SelectFrame",Rc.SelectImage="SelectImage",Rc.Position="Position";class kc extends yo{constructor(t,e){super(t,e),Pc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return eo.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 eo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,i){return i&&i.length>1&&void 0===t?Nc.SelectFrame:e||A||this.getImageData()?Nc.Position:Nc.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 Hc=t=>{const e=(0,i.useRef)(null),n=(0,i.useRef)(void 0),[r,a]=(0,i.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=Ur(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:w,uiDispatcher:B}=Wr(),p=(0,i.useCallback)((t=>{const e=t;B(new Kr({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),E=(0,i.useCallback)((t=>{o(t),1===l.length&&(n.current=void 0),2===l.length&&a(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),m=(0,i.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new Kr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),C=(0,i.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,A=2===l.length&&"touch"===l[0].pointerType;if(g&&A){const[t,e]=l,A=Math.abs(t.clientX-e.clientX),i=r;i&&p(w.zoom-.0055*(i-A)),a(A)}if(d&&(e||A)&&t.isPrimary){const e=(n?.current?.x||t.screenX)-t.screenX,A=(n?.current?.y||t.screenY)-t.screenY;B(new Kr({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-A/w.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,p,w.zoom,w.xTranslation,w.yTranslation,B]),f=(0,i.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,i.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,A=e.current.hasPointerCapture(t);d&&!A&&e.current.setPointerCapture(t),!d&&A&&e.current.releasePointerCapture(t)}),[e,d,l]),Ha([" "],(()=>{u(!0),B(new Kr({selectedElement:void 0}))}),(()=>u(!1))),Ha(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,i.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,A.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:f,onPointerDown:m,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:Q,children:t.children})};
|
|
1286
1286
|
//# sourceMappingURL=main.js.map
|