@aurigma/ui-framework
Version:
A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.
1 lines • 10.1 kB
JavaScript
(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){"use strict";i.r(e),i.d(e,"AuWidgetDataDrivenEditor",(function(){return c})),i.d(e,"widget",(function(){return c}));var n=i(0),r=i(1),s=i(2),a=i(160),o=i(869),c=function(t){function e(){var e=t.call(this)||this;return e.previewUrls=[],e._frameIsReady=!1,e._isReadyEmitted=!1,e._initIFrame=e._initIFrame.bind(e),e}return Object(n.d)(e,t),e.prototype.exportWidgetData=function(t){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.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}}:{}]}))}))},e.prototype.restoreWidgetFromData=function(t,e){return Object(n.b)(this,void 0,void 0,(function(){var e=this;return Object(n.e)(this,(function(i){return this._isRestoring=!0,this._getEditorElement().then((function(){return Object(n.b)(e,void 0,void 0,(function(){var e,i,r;return Object(n.e)(this,(function(s){switch(s.label){case 0:return e=null!==(r=this.params.config)&&void 0!==r?r:{},i=Object(n.a)(Object(n.a)({},e),{access:Object(n.a)(Object(n.a)({},e.access),t.access),design:Object(n.a)(Object(n.a)({},e.design),t.design)}),this.stateId=t.design.designId,this.userId=t.access.userId,[4,this.setEditorConfig(i)];case 1:return s.sent(),[2]}}))}))})),this._isRestoring=!1,this.emitChange(),[2]}))}))},e.prototype.updateParams=function(t,e){},e.prototype.updateParamsAsync=function(e,i){return Object(n.b)(this,void 0,void 0,(function(){var r,s,a,o,c,u,d,h,l,f,p=this;return Object(n.e)(this,(function(m){switch(m.label){case 0:return[4,t.prototype.updateParamsAsync.call(this,e,i)];case 1:return m.sent(),!e.config||this._frameIsReady?[3,3]:[4,this._initIFrame()];case 2:m.sent(),m.label=3;case 3:return this._element=this._getEditorEl(),this._element?null==e.config?[2]:(this.params=e,this.userId=this.driver.user.id,r=this.driver.backOffice,s=r.token,a=r.assetProcessorUrl,o=r.designAtomsApiUrl,c=r.assetStorageUrl,u=r.tenantId,d=r.backOfficeUrl,h=this.language.slice(0,2),[4,this.getLocalization(h)]):[2];case 4:return l=m.sent(),f=Object(n.a)(Object(n.a)({},e.config),{access:Object(n.a)({userId:this.userId,tenantId:null==u?void 0:u.toString(),token:s},e.config.access),api:Object(n.a)({assetProcessor:a,assetStorage:c,designAtoms:o,backOffice:d},e.config.api),settings:Object(n.a)({lang:h},e.config.settings),translation:l}),this.setEditorConfig(f).then((function(){return p._emitOnReady()})),this._scheduleTokenUpdate(e.config),this._element.$isValid.subscribe((function(t){p.isValid=t,p.emitChange()})),[2]}}))}))},e.prototype._emitOnReady=function(){if(!1===this._isReadyEmitted){var t=[].concat(this.params.onReady).filter((function(t){return t}));r.a.functionWrapperConstructor(t)(),this._isReadyEmitted=!0}},e.prototype._scheduleTokenUpdate=function(t){var e=this;this._timerId&&(clearInterval(this._timerId),this._updateToken(t)),this._timerId=setInterval((function(){return Object(n.b)(e,void 0,void 0,(function(){return Object(n.e)(this,(function(e){return[2,this._updateToken(t)]}))}))}),27e5)},e.prototype._updateToken=function(t){var e,i,r;return Object(n.b)(this,void 0,void 0,(function(){var s,a;return Object(n.e)(this,(function(n){switch(n.label){case 0:return(s=null!==(r=null!==(e=t.api.backOffice)&&void 0!==e?e:null===(i=this.driver.backOffice)||void 0===i?void 0:i.backOfficeUrl)&&void 0!==r?r:"")?[4,this._getToken({backOfficeUrl:s,tenantId:t.access.tenantId,userId:this.driver.user.id})]:[2];case 1:return a=n.sent(),this._element.updateToken&&this._element.updateToken(a),[2]}}))}))},e.prototype._getToken=function(t){var e=t.backOfficeUrl,i=t.tenantId,s=t.userId;return Object(n.b)(this,void 0,void 0,(function(){var t,a;return Object(n.e)(this,(function(n){switch(n.label){case 0:return t=r.a.ensureEndsWith(e,"/")+"/api/v1/tenants/".concat(i,"/integrations/gettoken"),a=window.location.origin,[4,fetch(t,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify({userGuid:s,ecommerceDomain:a,origin:a})})];case 1:return[4,n.sent().json()];case 2:return[2,n.sent().result]}}))}))},e.prototype.getLocalization=function(t){var e,i;return Object(n.b)(this,void 0,void 0,(function(){var s,a,o,c;return Object(n.e)(this,(function(n){switch(n.label){case 0:if(s=null===(i=null===(e=this.driver)||void 0===e?void 0:e.localization)||void 0===i?void 0:i.find((function(t){return"data-driven-editor"===t.app})),a={},!s)return[3,6];if(!r.a.isNotNullOrUndefined(s.url)||r.a.isEmptyString(s.url)||"string"!=typeof s.url)return[3,5];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,r.a.loadJson(s.url+"?ts="+Date.now())];case 2:return a=n.sent(),[3,4];case 3:return o=n.sent(),console.error(o),[3,4];case 4:return[3,6];case 5:r.a.isNotNullOrUndefined(s.data)&&"object"==typeof s.data&&0!==Object.keys(s.data).length&&(a=-1!==Object.keys(s.data).indexOf(t)?r.a.DeepMerge(a,s.data):r.a.DeepMerge(a,((c={})[t]=s.data,c))),n.label=6;case 6:return[2,a]}}))}))},e.prototype.setEditorConfig=function(t){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(e){switch(e.label){case 0:return[4,this._element.setEditorConfig(t)];case 1:return e.sent(),[2]}}))}))},e.prototype.setLang=function(t){this._element.setLang(t)},e.prototype.updateToken=function(t){},e.prototype.createPdfPreview=function(t){return Object(n.b)(this,void 0,void 0,(function(){var e;return Object(n.e)(this,(function(i){switch(i.label){case 0:t=t||this.params.config.renderer,i.label=1;case 1:return i.trys.push([1,3,,4]),e=this,[4,this._element.getPdfPreview(t)];case 2:return e.pdfUrl=i.sent(),this.emitChange(),[2,this.pdfUrl];case 3:return i.sent(),this.showToast("Error: can't create pdf file."),[2,""];case 4:return[2]}}))}))},e.prototype.createPreview=function(t){return Object(n.b)(this,void 0,void 0,(function(){var e,i,r,s;return Object(n.e)(this,(function(n){switch(n.label){case 0:t=t||this.params.config.renderer,n.label=1;case 1:return n.trys.push([1,3,,4]),e=this.params.config.preview,i=e.width,r=e.height,s=this,[4,this._element.getPreview(this.stateId,i,r)];case 2:return s.previewUrls=n.sent(),this.emitChange(),[2,this.previewUrls];case 3:return n.sent(),this.showToast("Error: can't create preview images."),[2,[]];case 4:return[2]}}))}))},e.prototype.createIdStr=function(){return Object(n.b)(this,void 0,void 0,(function(){var t;return Object(n.e)(this,(function(e){switch(e.label){case 0:return t=this,[4,this._element.getIdString()];case 1:return t.idStr=e.sent(),this.emitChange(),[2,this.idStr]}}))}))},e.prototype.saveProduct=function(t){return Object(n.b)(this,void 0,void 0,(function(){var e,i,r,s,a;return Object(n.e)(this,(function(n){switch(n.label){case 0:return e=this,[4,this._element.save(t)];case 1:return e.stateId=n.sent(),i=this.params.config.preview,r=i.width,s=i.height,a=this,[4,this._element.getPreviewLink(this.stateId,r,s)];case 2:return a.previewUrlLink=n.sent(),this.emitChange(),[2]}}))}))},e.prototype.validate=function(){return this._element.validate()},e.prototype.setUserInfo=function(t){this._element.setUserInfo(t)},e.prototype.getFormData=function(t){return this._element.getFormData(t)},e.prototype._getEditorEl=function(){if(this._element)return this._element;var t=this._iframeDoc.getElementById("dd-editor");return window.Aurigma=Object.assign(window.Aurigma,this._iframeWin.contentWindow.Aurigma),t},e.prototype._initIFrame=function(){return Object(n.b)(this,void 0,void 0,(function(){var t,e,i=this;return Object(n.e)(this,(function(n){switch(n.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 t=n.sent(),this._iframeDoc.write('<link href="'.concat(t,'/data-driven-editor/styles.css" rel="stylesheet">')),(e=this._iframeDoc.createElement("script")).src="".concat(t,"/data-driven-editor/index.js"),this._iframeDoc.body.appendChild(e),this._frameIsReady=!0,[2,new Promise((function(t,n){e.onload=function(){return t()},e.onerror=function(){n("Can't load widget script!"),i._iframeDoc.write("Can't load widget script!")}}))]}}))}))},e.prototype._getWorkflowElementsBaseUrl=function(){return Object(n.b)(this,void 0,void 0,(function(){var t,e,i,s,a;return Object(n.e)(this,(function(n){switch(n.label){case 0:return t=this.driver.backOffice,e=t.backOfficeUrl,i=t.tenantId,s=t.token,null==e?[3,3]:(a=r.a.removeTrailingSlash(e),[4,fetch("".concat(a,"/api/storefront/v1/tenant-info/applications?tenantId=").concat(i),{headers:{Authorization:"Bearer ".concat(s)}})]);case 1:return[4,n.sent().json()];case 2:return[2,n.sent().workflowElementsUrl];case 3:this._iframeDoc.write("This widget unsupported work without Back Office services!"),n.label=4;case 4:return[2]}}))}))},e.prototype._getEditorElement=function(){var t=this;return new Promise((function(e,i){if(t._element)e(t._element);else{var r=function(){setTimeout((function(){return Object(n.b)(t,void 0,void 0,(function(){return Object(n.e)(this,(function(t){return this._iframeDoc&&(this._element?e(this._element):r()),[2]}))}))}),200)};r()}}))},Object(n.c)([Object(s.a)("au-widget-data-driven-editor",o),Object(n.g)("design:paramtypes",[])],e)}(a.c)}}]);