UNPKG

@aurigma/ui-framework

Version:

A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.

1 lines 18.9 kB
(window.multistep_editor_jsonpFunction=window.multistep_editor_jsonpFunction||[]).push([[40],{488:function(t,e,i){i.d(e,"a",function(){return s}),i.d(e,"b",function(){return r});class s{constructor(t){t&&(this.id=t.id,this.productVersionId=t.productVersionId,this.productId=t.productId,this.tenantId=t.tenantId,this.storefrontProductVariantId=t.storefrontProductVariantId,this.options=t.productVariantOptions.map(t=>new r(t)),this.price=t.price)}}class r{constructor(t){t&&(this.productOptionId=t.productOptionId,this.productOptionValueId=t.productOptionValueId,this.productOptionType=t.productOptionType,this.productOptionTraits=t.productOptionTraits,this.productOptionTitle=t.productOptionTitle,this.productOptionValueTitle=t.productOptionValueTitle)}}},541:function(t,e,i){i.d(e,"a",function(){return r});var s,e=i(26),i=i(127),r=(s=i.a,Object(e.a)(n,s),Object.defineProperty(n.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),n.prototype._subscribe=function(t){var e=s.prototype._subscribe.call(this,t);return e.closed||t.next(this._value),e},n.prototype.getValue=function(){var t=this,e=t.hasError,i=t._value;if(e)throw t.thrownError;return this._throwIfClosed(),i},n.prototype.next=function(t){s.prototype.next.call(this,this._value=t)},n);function n(t){var e=s.call(this)||this;return e._value=t,e}},595:function(t,e,i){i.d(e,"a",function(){return s});var r=i(535),n=i(488);class s{constructor(t){var e,i,s;t&&(this.id=t.productVariantId+":"+t.designId,this.productVariantId=t.productVariantId,this.productVersionId=t.productVersionId,this.productId=t.productId,this.sku=t.storefrontProductVariantId,this.designId=t.designId,this.designName=t.designName,this.designGroup=t.designGroup,s=null!=(s=t.productVariantOptions)?s:[],this.options=s.map(t=>new n.b(t)),s=null!=(s=t.productVariantResources)?s:[],this.resources=s.map(t=>new o(t)),i=s.find(t=>t.type===r.d.Preview),s=s.find(t=>t.type===r.d.EditorModel),this.previewUrl=null!=(e=null==i?void 0:i.url)?e:"",this.designResourceId=null!=(e=null==s?void 0:s.resourceId)?e:"",this.previewResourceId=null!=(s=null==i?void 0:i.resourceId)?s:"",this.price=t.price)}}class o{constructor(t){t&&(this.resourceId=t.resourceId,this.name=t.name,this.url=t.url,this.type=t.type,this.resourcePreview=t.resourcePreview)}}},603:function(t,e,i){i.d(e,"a",function(){return s});var e=i(161),r=new e.a(function(t){return t.complete()});var n=i(122),o=i(123);function s(s){return s<=0?function(){return r}:Object(n.a)(function(t,e){var i=0;t.subscribe(new o.a(e,function(t){++i<=s&&(e.next(t),s<=i)&&e.complete()}))})}},927:function(t,e,i){i.r(e),i.d(e,"AuWidgetProductInformationAJAX",function(){return T}),i.d(e,"widget",function(){return T});var e=i(0),s=i(535),r=i(2),n=i(403),o=i(1),a=i(541),u=i(147),c=Object(u.a)(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}),l=i(395),d=i(603),h=i(122),p=i(123);function g(){return new c}var f,v,m,_=i(216);function I(n,t){var e=2<=arguments.length;return function(i){return i.pipe(n?Object(l.a)(function(t,e){return n(t,e,i)}):_.a,Object(d.a)(1),e?(r=t,Object(h.a)(function(t,e){var i=!1;t.subscribe(new p.a(e,function(t){i=!0,e.next(t)},function(){i||e.next(r),e.complete()}))})):(void 0===(s=function(){return new c})&&(s=g),Object(h.a)(function(t,e){var i=!1;t.subscribe(new p.a(e,function(t){i=!0,e.next(t)},function(){return i?e.complete():e.error(s())}))})));var s,r}}(u=f=f||{}).Preselect="Preselect",u.Filter="Filter",(u=m=m||{})[u.Template=1]="Template",u[u.OptionBasedProduct=2]="OptionBasedProduct",(m=v=v||{})[m.Custom=0]="Custom",m[m.ShopifyLegacy=1]="ShopifyLegacy",m[m.DocketManager=2]="DocketManager",m[m.Auth0Saml=3]="Auth0Saml",m[m.NopCommerce=4]="NopCommerce",m[m.WooCommerce=5]="WooCommerce",m[m.Magento=6]="Magento",m[m.BigCommerce=7]="BigCommerce",m[m.Shopify=8]="Shopify",m[m.ShopifyCustom=9]="ShopifyCustom";u=i(160);class k{constructor(t){var e;this.values=[],this.selected=[],t&&(this.id=t.id,this.name=t.title,this.isMultiSelect=!(null==(e=t.traits)||!e.includes("AllowsMultiselect")),this.values=t.productOptionValues.map(t=>new b(t)),this.image=t.image,this.description=t.description,this.tooltip=t.tooltip,this.appearanceDataItems=null==(e=t.appearanceData)?void 0:e.items,this.type=((t,e)=>{if(e)return"checkbox";switch(t){case s.b.Radio:return"radio";case s.b.Chips:return"chips";case s.b.Dropdown:return"dropdown";case s.b.ColorGrid:return"color-grid";case s.b.ColorList:return"color-list";case s.b.ImageGrid:return"image-grid";case s.b.ImageList:return"image-list";default:return console.warn(`Option type ${t} is not supported`),"radio"}})(null==(e=t.appearanceData)?void 0:e.type,this.isMultiSelect),this.selected=this.isMultiSelect?this.values.filter(t=>t.isDefault):[this.values.find(t=>t.isDefault)])}}class b{constructor(t){var e;this.disabled=!1,this.isDefault=!1,t&&(this.id=t.id,this.name=t.title,this.additionalText=t.description,this.color=t.colors[0]||null,this.imageUrl=(null==(e=t.image)?void 0:e.url)||null,this.isDefault=t.isDefault)}}class O{}class y{constructor(t){var e;this.enabled=!1,t&&(this.enabled=null!=(e=t.enabled)&&e,this.skip=t.skip,this.take=t.take,this.productFilterId=t.productFilterId)}}class V{constructor(t){this.onError=t=>{},this.onSuccess=t=>{},t&&(this.onError=t.onError,this.onSuccess=t.onSuccess)}}class w{constructor(t){var e;this.settings={mockups:new y,designs:new y,variants:new y},this.eventsCallbacks={options:new V,mockups:new V,designs:new V,variants:new V},this.productId=null==t?void 0:t.productId,this.productVersionId=null==t?void 0:t.productVersionId,this.productLinkId=null==t?void 0:t.productLinkId,this.options=null!=(e=null==t?void 0:t.options)?e:{},this.choices=null!=(e=null==t?void 0:t.choices)?e:void 0,this.currentSku=null==t?void 0:t.currentSku,this.settings.mockups=new y(null==(e=null==t?void 0:t.settings)?void 0:e.mockups),this.settings.designs=new y(null==(e=null==t?void 0:t.settings)?void 0:e.designs),this.settings.variants=new y(null==(e=null==t?void 0:t.settings)?void 0:e.variants),this.eventsCallbacks.designs=new V(null==(e=null==t?void 0:t.eventsCallbacks)?void 0:e.designs),this.eventsCallbacks.mockups=new V(null==(e=null==t?void 0:t.eventsCallbacks)?void 0:e.mockups),this.eventsCallbacks.options=new V(null==(e=null==t?void 0:t.eventsCallbacks)?void 0:e.options),this.eventsCallbacks.variants=new V(null==(e=null==t?void 0:t.eventsCallbacks)?void 0:e.variants)}getOptionValue(t){return this.options[t]}}var S=i(595),C=i(488);class P{constructor(t){t&&(this.productVariantId=t.productVariantId,this.productVersionId=t.productVersionId,this.productId=t.productId,this.tenantId=t.productVersionId,this.sku=t.storefrontProductVariantId,this.mockupId=t.mockupId,this.mockupName=t.mockupName,this.mockupType=t.mockupType,this.surfaceIndex=t.surfaceIndex,this.surfaceUsageType=t.surfaceUsageType,this.options=t.productVariantOptions.map(t=>new C.b(t)))}}class A{constructor(t){t&&(this.id=t.productId,this.versionId=t.productVersionId,this.linkId=t.productLinkId,this.name=t.name,this.description=t.description,this.customFields=t.customFields,this.tags=t.tags)}}let T=class extends u.a{constructor(){super(),this._priceIsFetching=!1,this._output=new O,this._filteredOutput=null,this._isRestored=!1,this._optionsAreLoaded=new a.a(!1),this._productInfo=null,this._productApiClientConfig=this._createProductApiClientConfig(),this._productsApi=new s.e(this._productApiClientConfig,this.backOfficeUrl),this._productsReferenceApi=new s.c(this._productApiClientConfig,this.backOfficeUrl)}get productInfo(){return this._productInfo}get selectionStrategy(){var t;return null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.selectionStrategy}get selectedVariantSku(){var t;return null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.selectedVariantSku}get isPreselectSelectionStrategy(){return this.selectionStrategy===f.Preselect}get driverChoices(){var t;return(null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.choices)||null}get priceIsFetching(){return this._priceIsFetching}get options(){return!(this.name in this.auWizard.scopeInternal.widgetsData)||this._isRestored?this._output.options:[]}get variants(){var t;return this._params.choices?null==(t=this._filteredOutput)?void 0:t.variants:this._output.variants}get designs(){var t;return this._params.choices?null==(t=this._filteredOutput)?void 0:t.designs:this._output.designs}get mockups(){var t;return this._params.choices?null==(t=this._filteredOutput)?void 0:t.mockups:this._output.mockups}get backOfficeUrl(){return o.a.removeTrailingSlash(this.auWizard.driver.backOffice.backOfficeUrl)}get tenantId(){return this.auWizard.driver.backOffice.tenantId}get token(){return this.auWizard.driver.backOffice.token}get storefrontId(){return this.auWizard.driver.backOffice.storefrontId}get reference(){return this.auWizard.driver.backOffice.externalProductId}get storefrontUserId(){return this.auWizard.driver.user.id}get currencyCode(){return this.auWizard.driver.settings.currency}get quantity(){return this.auWizard.driver.orders.current.quantity}get productLinkId(){var t;return this._params.productLinkId||(null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.productLinkId)}get productId(){var t;return this._params.productId||(null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.productId)}get productVersionId(){var t;return this._params.productVersionId||(null==(t=this.auWizard.driver.backOffice.optionBasedProductInfo)?void 0:t.productVersionId)}get costDetails(){return this._costDetails}get price(){var t;return this._costDetails?null==(t=this._costDetails)?void 0:t.productCost:null}get variantsSettings(){return this._params.settings.variants}get mockupsSettings(){return this._params.settings.mockups}get designsSettings(){return this._params.settings.designs}get currentChoices(){return this._getChoices(this._output.options)}get variantsHashMap(){var t=this._output.variants.map(t=>{let e={};return t.options.forEach(t=>{e[t.productOptionId]=[t.productOptionValueId]}),e});return 0==t.length&&console.warn("There are no available variants"),t}get summary(){var t;if(0<(null==(t=this.options)?void 0:t.length)){let i=[];return this.options.forEach(t=>{var e={};e.name=t.name,e.value=t.selected.map(t=>t.name),i.push(e)}),i}return[]}async getProductVariants(t,e){return this._productsApi.getProductVariants(t,null,e.skip,e.take,null,e.productFilterId,!0,this.isPreselectSelectionStrategy?null:this.selectedVariantSku,this.tenantId)}async getDesignVariants(t,e){return await this._productsApi.getProductVariantDesigns(t,+this.productVersionId,null,null,null,null,e.skip,e.take,null,e.productFilterId,!0,this.isPreselectSelectionStrategy?null:this.selectedVariantSku,this.tenantId)}async getMockupVariants(t,e){return await this._productsApi.getProductVariantMockups(t,+this.productVersionId,null,null,null,null,e.skip,e.take,null,e.productFilterId,!0,this.isPreselectSelectionStrategy?null:this.selectedVariantSku,this.tenantId)}updateParams(t){}async updateParamsAsync(t){if(this._params||(this._params=new w(t),{options:i,variants:e}=this.productId?await this._getOptionsAndVariantsSimultaneously():await this._getOptionsAndVariants(),i=this._selectAvailableVariant(i,e),i=this._disableUnavailableOptions(i,e),this._output.options=i,this.emitChange({options:this._output.options},!1),this._output.variants=e,this.emitChange({variants:this._output.variants},!1),this._optionsAreLoaded.next(!0)),!this.auWizard._isRestoring){if(t.choices&&!Array.isArray(t.choices)&&this._isNewChoices(t.choices)){var e=null==(i=Object.keys(t.choices))?void 0:i.length,i=this.variantsHashMap[0];if(e!=(null==(e=Object.keys(i))?void 0:e.length))return void console.warn("The number of choices is not equal to the number of options.");this._selectValuesBy(t.choices),this.emitChange({filterOutput:this._filteredOutput,options:this._output.options},!1,!0)}t.currentSku&&t.currentSku!==this._params.currentSku&&(this._cancelTokenSource&&this._cancelTokenSource.cancel("Operation canceled"),await this.getPrice(t.currentSku))}}async connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}async exportWidgetData(t){var e;return null!=(e=this._params)&&e.choices?{choices:null==(e=this._params)?void 0:e.choices}:null}async restoreWidgetFromData(e,t){e&&this._optionsAreLoaded.pipe(I(t=>!0===t)).subscribe(()=>{var t=null==e?void 0:e.choices;this._params.choices=t,this._selectValuesBy(t),this._isRestored=!0,this.emitChange({filterOutput:this._filteredOutput,options:this._output.options},!1,!0)})}async getPrice(t){var e;return t?o.a.isEmptyString(this.reference)||o.a.isEmptyString(this.storefrontId)?(console.warn("To get current item price you need reference and storefrontId"),null):(e=n.a.CancelToken,this._cancelTokenSource=e.source(),this._params.currentSku=t,this._priceIsFetching=!0,void await this._productsReferenceApi.getProductCostDetails(this.reference,t,this.storefrontId,null,this.currencyCode,this.quantity,this.tenantId,this._cancelTokenSource.token).then(t=>{this._costDetails=t,this._priceIsFetching=!1,this.emitChange({costDetails:this._costDetails},!1)}).catch(t=>{"Operation canceled"!==t.message&&console.error(t.message)})):null}filterModel(t,i){return Object.values(t).forEach(e=>{Array.isArray(e)?e.length<1||(i=i.filter(t=>null==(t=t.options)?void 0:t.some(t=>e.includes(t.productOptionValueId)))):i=i.filter(t=>null==(t=t.options)?void 0:t.some(t=>e===t.productOptionValueId))}),i}filterVariants(t){t&&this._output&&(this._filteredOutput=Object.assign({},this._output),this._filteredOutput.designs&&(this._filteredOutput.designs=this.filterModel(t,this._filteredOutput.designs)),this._filteredOutput.mockups&&(this._filteredOutput.mockups=this.filterModel(t,this._filteredOutput.mockups)),this._filteredOutput.variants)&&(this._filteredOutput.variants=this.filterModel(t,this._filteredOutput.variants))}_createProductApiClientConfig(){var t=new s.a;return t.apiUrl=this.backOfficeUrl,t.setAuthorizationToken(this.token),t}_getChoices(t){let e={};return t.forEach(t=>{e[t.id]=t.selected.map(t=>t.id)}),e}_selectValuesBy(t){this.filterVariants(t),this._params.choices=t;t=this._applyChoices(this._output.options,t);this._output.options=this._disableUnavailableOptions(t,this._output.variants)}async _getOptionsAndVariants(){return{options:await this._getOptions(),variants:await this._getVariants()}}async _getOptionsAndVariantsSimultaneously(){var[t,e]=await Promise.all([this._getOptions(),this._getVariants()]);return{options:t,variants:e}}_selectAvailableVariant(t,e){if(this._isSelectedVariantAvailable(t,e))return t;let s=this._getVariantsHashMap(e)[0];return t.map(e=>{let i=[e.values.find(t=>t.id===s[e.id][0]).id];return e.selected=e.isMultiSelect?e.values.filter(e=>null==i?void 0:i.some(t=>t===e.id)):[e.values.find(t=>null==i?void 0:i.includes(t.id))],e})}_isSelectedVariantAvailable(t,e){let i=this._getChoices(t);return this._getVariantsHashMap(e).some(t=>JSON.stringify(t)===JSON.stringify(i))}_disableUnavailableOptions(t,e){if(this._getAllVariantsCount(t)===(null==e?void 0:e.length))return t;let s=this._getChoices(t);var r=this._getVariantsHashMap(e);let n=[];if(1===(null==(e=Object.keys(s))?void 0:e.length))n.push(...r);else for(let[e,i]of Object.entries(s)){var o=r.filter(t=>t[e][0]==i[0]&&this._getDifferentOptionsCount(t,s)<=1);n.push(...o)}return t.map(i=>(i.values.map(e=>{var t=n.some(t=>t[i.id][0]===e.id);return e.disabled=!t,e}),i))}_getAllVariantsCount(t){return t.reduce((t,e)=>t*e.values.length,1)}_getDifferentOptionsCount(t,e){let i=0;for(var[s,r]of Object.entries(t)){s=e[s];Array.isArray(s)?s[0]!=r[0]&&i++:s!=r[0]&&i++}return i}_applyChoices(t,e){return t.map(t=>{let i=e[null==t?void 0:t.id];return t.selected=t.isMultiSelect?t.values.filter(e=>null==i?void 0:i.some(t=>t===e.id)):[t.values.find(t=>null==i?void 0:i.includes(t.id))],t})}_getVariantsHashMap(t){t=t.map(t=>{let e={};return t.options.forEach(t=>{e[t.productOptionId]=[t.productOptionValueId]}),e});return 0==t.length&&console.warn("There are no available variants"),t}async _getProductSummary(){if(o.a.isEmptyString(this.reference)||o.a.isEmptyString(this.storefrontId)){if(null!=this.productId)return this._productsApi.getProductSummary(Number.isFinite(Number(this.productId))?Number(this.productId):null,Number.isFinite(Number(this.productVersionId))?Number(this.productVersionId):null,Number.isFinite(Number(this.productLinkId))?Number(this.productLinkId):null,null,this.selectedVariantSku,this.tenantId);throw new Error("There is not enough data to initialize. Use the following data combinations for initialization: productReferenceId and storefrontId or productId.")}return this._productsReferenceApi.getProductSummary(this.reference,Number.isFinite(Number(this.storefrontId))?Number(this.storefrontId):null,null,this.selectedVariantSku,this.tenantId)}async _getOptions(){let t,e=[];try{var i=await this._getProductSummary();this._productInfo=new A(i),e=null==(t=i.options)?void 0:t.map(t=>new k(t)),this.driverChoices&&(e=this._applyChoices(e,this.driverChoices)),this._params.eventsCallbacks.options.onSuccess(e)}catch(t){this._params.eventsCallbacks.options.onError(t)}return e}async _getVariants(){let t=[];try{var e=await this.getProductVariants(+this.productId,this.variantsSettings);t=e.items.map(t=>new C.a(t)),this._params.eventsCallbacks.variants.onSuccess(t),(o.a.isNullOrUndefined(t)||0==(null==t?void 0:t.length))&&this.selectedVariantSku&&console.warn("There are no product variants with this SKU: "+this.selectedVariantSku)}catch(t){this._params.eventsCallbacks.variants.onError(null==t?void 0:t.message)}return this.designsSettings.enabled&&this.getDesignVariants(+this.productId,this.designsSettings).then(t=>{this._output.designs=t.items.map(t=>new S.a(t)),this._params.eventsCallbacks.designs.onSuccess(this._output.designs),!this._filteredOutput.designs&&this._params.choices&&(this._filteredOutput.designs=this.filterModel(this._params.choices,this._output.designs)),this.emitChange({designs:this._output.designs},!1)}).catch(t=>this._params.eventsCallbacks.designs.onError(t)),this.mockupsSettings.enabled&&this.getMockupVariants(+this.productId,this.mockupsSettings).then(t=>{this._output.mockups=t.items.map(t=>new P(t)),this._params.eventsCallbacks.mockups.onSuccess(this._output.mockups),!this._filteredOutput.mockups&&this._params.choices&&(this._filteredOutput.mockups=this.filterModel(this._params.choices,this._output.mockups)),this.emitChange({mockups:this._output.mockups},!1)}).catch(t=>this._params.eventsCallbacks.mockups.onError(t)),t}async _isNewChoices(t){return JSON.stringify(t)!==JSON.stringify(null==(t=this._params)?void 0:t.choices)}};T=Object(e.a)([Object(r.a)("au-widget-pim-ajax"),Object(e.b)("design:paramtypes",[])],T)}}]);