UNPKG

@aurigma/ui-framework

Version:

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

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