UNPKG

@aurigma/ui-framework

Version:

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

1 lines 9.81 kB
(window.multistep_editor_jsonpFunction=window.multistep_editor_jsonpFunction||[]).push([[22],{869:function(t,e){t.exports='<style>\n :host {\n width: 100%;\n height: 100%;\n }\n</style>\n\n<iframe id="frameID" width="100%" height="100%" style="border: none"></iframe>\n'},940:function(t,e,i){i.r(e),i.d(e,"AuWidgetDataDrivenEditor",function(){return r}),i.d(e,"widget",function(){return r});var l,f=i(0),a=i(1),e=i(2),n=i(160),i=i(869),r=(l=n.c,Object(f.d)(s,l),s.prototype.exportWidgetData=function(t){return Object(f.b)(this,void 0,void 0,function(){return Object(f.e)(this,function(t){return[2,this.params?{design:{designId:this.stateId,isPrivateDesign:!0,designPath:this.params.config.design.designPath,dataSetId:this.params.config.design.dataSetId},access:{userId:this.userId}}:{}]})})},s.prototype.restoreWidgetFromData=function(i,t){return Object(f.b)(this,void 0,void 0,function(){var e=this;return Object(f.e)(this,function(t){return this._isRestoring=!0,this._getEditorElement().then(function(){return Object(f.b)(e,void 0,void 0,function(){var e;return Object(f.e)(this,function(t){switch(t.label){case 0:return e=null!=(e=this.params.config)?e:{},e=Object(f.a)(Object(f.a)({},e),{access:Object(f.a)(Object(f.a)({},e.access),i.access),design:Object(f.a)(Object(f.a)({},e.design),i.design)}),this.stateId=i.design.designId,this.userId=i.access.userId,[4,this.setEditorConfig(e)];case 1:return t.sent(),[2]}})})}),this._isRestoring=!1,this.emitChange(),[2]})})},s.prototype.updateParams=function(t,e){},s.prototype.updateParamsAsync=function(d,h){return Object(f.b)(this,void 0,void 0,function(){var e,i,n,r,s,a,o,c,u=this;return Object(f.e)(this,function(t){switch(t.label){case 0:return[4,l.prototype.updateParamsAsync.call(this,d,h)];case 1:return t.sent(),!d.config||this._frameIsReady?[3,3]:[4,this._initIFrame()];case 2:t.sent(),t.label=3;case 3:return(this._element=this._getEditorEl(),this._element)?null==d.config?[2]:(this.params=d,this.userId=this.driver.user.id,a=this.driver.backOffice,e=a.token,i=a.assetProcessorUrl,n=a.designAtomsApiUrl,r=a.assetStorageUrl,s=a.tenantId,a=a.backOfficeUrl,o=this.language.slice(0,2),[4,this.getLocalization(o)]):[2];case 4:return c=t.sent(),c=Object(f.a)(Object(f.a)({},d.config),{access:Object(f.a)({userId:this.userId,tenantId:null==s?void 0:s.toString(),token:e},d.config.access),api:Object(f.a)({assetProcessor:i,assetStorage:r,designAtoms:n,backOffice:a},d.config.api),settings:Object(f.a)({lang:o},d.config.settings),translation:c}),this.setEditorConfig(c).then(function(){return u._emitOnReady()}),this._scheduleTokenUpdate(d.config),this._element.$isValid.subscribe(function(t){u.isValid=t,u.emitChange()}),[2]}})})},s.prototype._emitOnReady=function(){var t;!1===this._isReadyEmitted&&(t=[].concat(this.params.onReady).filter(function(t){return t}),a.a.functionWrapperConstructor(t)(),this._isReadyEmitted=!0)},s.prototype._scheduleTokenUpdate=function(e){var t=this;this._timerId&&(clearInterval(this._timerId),this._updateToken(e)),this._timerId=setInterval(function(){return Object(f.b)(t,void 0,void 0,function(){return Object(f.e)(this,function(t){return[2,this._updateToken(e)]})})},27e5)},s.prototype._updateToken=function(i){var n;return Object(f.b)(this,void 0,void 0,function(){var e;return Object(f.e)(this,function(t){switch(t.label){case 0:return(e=null!=(n=null!=(n=i.api.backOffice)?n:null==(n=this.driver.backOffice)?void 0:n.backOfficeUrl)?n:"")?[4,this._getToken({backOfficeUrl:e,tenantId:i.access.tenantId,userId:this.driver.user.id})]:[2];case 1:return e=t.sent(),this._element.updateToken&&this._element.updateToken(e),[2]}})})},s.prototype._getToken=function(t){var n=t.backOfficeUrl,r=t.tenantId,s=t.userId;return Object(f.b)(this,void 0,void 0,function(){var e,i;return Object(f.e)(this,function(t){switch(t.label){case 0:return e=a.a.ensureEndsWith(n,"/")+"/api/v1/tenants/".concat(r,"/integrations/gettoken"),i=window.location.origin,[4,fetch(e,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify({userGuid:s,ecommerceDomain:i,origin:i})})];case 1:return[4,t.sent().json()];case 2:return[2,t.sent().result]}})})},s.prototype.getLocalization=function(r){var s;return Object(f.b)(this,void 0,void 0,function(){var e,i,n;return Object(f.e)(this,function(t){switch(t.label){case 0:if(e=null==(s=null==(s=this.driver)?void 0:s.localization)?void 0:s.find(function(t){return"data-driven-editor"===t.app}),i={},!e)return[3,6];if(!a.a.isNotNullOrUndefined(e.url)||a.a.isEmptyString(e.url)||"string"!=typeof e.url)return[3,5];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,a.a.loadJson(e.url+"?ts="+Date.now())];case 2:return i=t.sent(),[3,4];case 3:return n=t.sent(),console.error(n),[3,4];case 4:return[3,6];case 5:a.a.isNotNullOrUndefined(e.data)&&"object"==typeof e.data&&0!==Object.keys(e.data).length&&(i=-1!==Object.keys(e.data).indexOf(r)?a.a.DeepMerge(i,e.data):a.a.DeepMerge(i,((n={})[r]=e.data,n))),t.label=6;case 6:return[2,i]}})})},s.prototype.setEditorConfig=function(e){return Object(f.b)(this,void 0,void 0,function(){return Object(f.e)(this,function(t){switch(t.label){case 0:return[4,this._element.setEditorConfig(e)];case 1:return t.sent(),[2]}})})},s.prototype.setLang=function(t){this._element.setLang(t)},s.prototype.updateToken=function(t){},s.prototype.createPdfPreview=function(i){return Object(f.b)(this,void 0,void 0,function(){var e;return Object(f.e)(this,function(t){switch(t.label){case 0:i=i||this.params.config.renderer,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,(e=this)._element.getPdfPreview(i)];case 2:return e.pdfUrl=t.sent(),this.emitChange(),[2,this.pdfUrl];case 3:return t.sent(),this.showToast("Error: can't create pdf file."),[2,""];case 4:return[2]}})})},s.prototype.createPreview=function(r){return Object(f.b)(this,void 0,void 0,function(){var e,i,n;return Object(f.e)(this,function(t){switch(t.label){case 0:r=r||this.params.config.renderer,t.label=1;case 1:return t.trys.push([1,3,,4]),i=this.params.config.preview,e=i.width,i=i.height,[4,(n=this)._element.getPreview(this.stateId,e,i)];case 2:return n.previewUrls=t.sent(),this.emitChange(),[2,this.previewUrls];case 3:return t.sent(),this.showToast("Error: can't create preview images."),[2,[]];case 4:return[2]}})})},s.prototype.createIdStr=function(){return Object(f.b)(this,void 0,void 0,function(){var e;return Object(f.e)(this,function(t){switch(t.label){case 0:return[4,(e=this)._element.getIdString()];case 1:return e.idStr=t.sent(),this.emitChange(),[2,this.idStr]}})})},s.prototype.saveProduct=function(s){return Object(f.b)(this,void 0,void 0,function(){var e,i,n,r;return Object(f.e)(this,function(t){switch(t.label){case 0:return[4,(e=this)._element.save(s)];case 1:return e.stateId=t.sent(),n=this.params.config.preview,i=n.width,n=n.height,[4,(r=this)._element.getPreviewLink(this.stateId,i,n)];case 2:return r.previewUrlLink=t.sent(),this.emitChange(),[2]}})})},s.prototype.validate=function(){return this._element.validate()},s.prototype.setUserInfo=function(t){this._element.setUserInfo(t)},s.prototype.getFormData=function(t){return this._element.getFormData(t)},s.prototype._getEditorEl=function(){var t;return this._element||(t=this._iframeDoc.getElementById("dd-editor"),window.Aurigma=Object.assign(window.Aurigma,this._iframeWin.contentWindow.Aurigma),t)},s.prototype._initIFrame=function(){return Object(f.b)(this,void 0,void 0,function(){var e,i,n=this;return Object(f.e)(this,function(t){switch(t.label){case 0:return this._iFrameEl=this.querySelectorShadow("#frameID"),this._iframeWin=this._iFrameEl||this._iFrameEl.contentWindow,this._iframeDoc=this._iFrameEl.contentDocument||this._iframeWin.document,this._iframeDoc.write('<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet" />'),this._iframeDoc.write('<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />'),this._iframeDoc.write("<style> .mat-button-toggle-button { height: 100%; } </style>"),this._iframeDoc.write('<div style="width:100%; height:100%">\n<au-data-driven-editor id="dd-editor"></au-data-driven-editor>\n</div>'),[4,this._getWorkflowElementsBaseUrl()];case 1:return e=t.sent(),this._iframeDoc.write('<link href="'.concat(e,'/data-driven-editor/styles.css" rel="stylesheet">')),(i=this._iframeDoc.createElement("script")).src="".concat(e,"/data-driven-editor/index.js"),this._iframeDoc.body.appendChild(i),this._frameIsReady=!0,[2,new Promise(function(t,e){i.onload=function(){return t()},i.onerror=function(){e("Can't load widget script!"),n._iframeDoc.write("Can't load widget script!")}})]}})})},s.prototype._getWorkflowElementsBaseUrl=function(){return Object(f.b)(this,void 0,void 0,function(){var e,i,n;return Object(f.e)(this,function(t){switch(t.label){case 0:return(i=this.driver.backOffice,n=i.backOfficeUrl,e=i.tenantId,i=i.token,null==n)?[3,3]:(n=a.a.removeTrailingSlash(n),[4,fetch("".concat(n,"/api/storefront/v1/tenant-info/applications?tenantId=").concat(e),{headers:{Authorization:"Bearer ".concat(i)}})]);case 1:return[4,t.sent().json()];case 2:return[2,t.sent().workflowElementsUrl];case 3:this._iframeDoc.write("This widget unsupported work without Back Office services!"),t.label=4;case 4:return[2]}})})},s.prototype._getEditorElement=function(){var n=this;return new Promise(function(e,t){var i;n._element?e(n._element):(i=function(){setTimeout(function(){return Object(f.b)(n,void 0,void 0,function(){return Object(f.e)(this,function(t){return this._iframeDoc&&(this._element?e(this._element):i()),[2]})})},200)})()})},Object(f.c)([Object(e.a)("au-widget-data-driven-editor",i),Object(f.g)("design:paramtypes",[])],s));function s(){var t=l.call(this)||this;return t.previewUrls=[],t._frameIsReady=!1,t._isReadyEmitted=!1,t._initIFrame=t._initIFrame.bind(t),t}}}]);