@appscode/ui-builder
Version:
## Motivation
1 lines • 13.8 kB
JavaScript
;var e=require("./wrapper-944ca3a6.js");require("vue"),require("./es.array.concat-5462e385.js"),require("./es.array.find-index-376cd032.js"),require("./index-cc93bc29.js"),require("./web.dom-collections.iterator-4a73d869.js"),require("./set-to-string-tag-4a66b282.js"),require("./object-set-prototype-of-f804d831.js");var t=require("./stickyContent-fa0d230c.js"),n=require("./index-80081729.js"),r=function(t,n,i,s,o,a,c,u){for(var l,f=o,p=0,d=!!c&&e.f(c,u,3);p<s;){if(p in i){if(l=d?d(i[p],p,n):i[p],a>0&&e.i(l))f=r(t,n,l,e.t(l.length),f,a-1)-1;else{if(f>=9007199254740991)throw TypeError("Exceed the acceptable array length");t[f]=l}f++}p++}return f},i=r;e._({target:"Array",proto:!0},{flat:function(){var t=arguments.length?arguments[0]:void 0,n=e.a(this),r=e.t(n.length),s=e.b(n,0);return s.length=i(s,n,n,r,0,void 0===t?1:e.c(t)),s}}),e.d("flat");var s={name:"ub-multi-step-form",mixins:[t.s],components:{ValidationObserver:e.V,InfoCenter:function(){return Promise.resolve().then((function(){return require("./InfoCenter-ecf7ee4f.js")})).then((function(e){return e.default}))},PreviewStep:function(){return Promise.resolve().then((function(){return require("./PreviewStep-9d5ebdaf.js")})).then((function(e){return e.default}))},UbSingleStepForm:function(){return Promise.resolve().then((function(){return require("./SingleStepForm-3a723b1b.js")})).then((function(e){return e.S})).then((function(e){return e.default}))},UbMultistepSidebarItems:function(){return Promise.resolve().then((function(){return require("./SidebarItems-35bc1b32.js")})).then((function(e){return e.default}))}},props:{ui:{type:Object,default:function(){return{}}},schema:{type:Object,default:function(){return{}}},showOptionsStep:{type:Boolean,default:!1},onOptionsValid:{type:Function,default:function(){return function(){}}},onOptionsInvalid:{type:Function,default:function(){return function(){}}},onOptionsCancel:{type:Function,default:function(){return function(){}}},onValid:{type:Function,default:function(){return function(){}}},onInvalid:{type:Function,default:function(){return function(){}}},onCancel:{type:Function,default:function(){return function(){}}},onDeploy:{type:Function,default:function(){return function(){}}},chartUrl:{type:String,default:""}},data:function(){return{activeStepIdentifier:"#-0",mutationObserver:null,observers:{},formMode:"options",doneLoader:!1,cancelLoader:!1,deployLoader:!1,previewLoader:!1,dependencies:{},unWatchers:{}}},created:function(){this.initStickyData("form-root",[["form-content","form-control"]],!0),this.$store.commit("wizard/showSteps$set",this.initializeShowSteps())},mounted:function(){var e;this.initializeValidationObservers(),this.activeStepIdentifier=(null===(e=this.flatenStepsTree[0])||void 0===e?void 0:e.identifier)||"#-0"},computed:e.e(e.e({},e.m({infoCenter:"wizard/infoCenter",modelJson:"wizard/model",configureOptions:"wizard/configureOptions",showSteps:"wizard/showSteps",store$get:"wizard/store$get",functions:"wizard/functions"})),{},{ctx:function(){return{model:e.g(this.modelJson),schema:e.g(this.schema),ui:e.g(this.ui),axios:this.$axios,qs:n.l,getValue:e.h,commit:this.$store.commit,watchDependency:this.watchDependency,loadLocalFile:this.loadLocalFile,storeGet:this.store$get,updateModelValue:this.updateModelValue,route:this.$route}},stepsTree:function(){return this.extractSteps(this.ui&&this.ui.steps,"#",this.showSteps)},flatenStepsTree:function(){return this.stepsTree.flat()||[]},stepTitles:function(){return this.ui&&this.extractStepTitles(this.ui.steps,"#",this.showSteps)},activeStep:{get:function(){var e=this;return"#-preview"===this.activeStepIdentifier?this.flatenStepsTree.length:this.flatenStepsTree.findIndex((function(t){return t.identifier===e.activeStepIdentifier}))},set:function(e){var t,n;e===this.flatenStepsTree.length?this.activeStepIdentifier="#-preview":this.activeStepIdentifier=(null===(t=this.flatenStepsTree[e])||void 0===t?void 0:t.identifier)||(null===(n=this.flatenStepsTree[0])||void 0===n?void 0:n.identifier)||"#-0"}},showPreviewButton:function(){var e;if(this.showOptionsStep&&"options"===this.formMode)return this.activeStep===this.flatenStepsTree.length-1&&1===(null===(e=this.configureOptions)||void 0===e?void 0:e.length);return this.activeStep===this.flatenStepsTree.length-1},showPreviewStep:function(){return"#-preview"===this.activeStepIdentifier}}),methods:{scrollToTop:function(){window.scrollTo(0,0)},extractStepTitles:function(e,t,n){var r=this;return e.filter((function(e,t){return"main"===r.formMode?r.configureOptions.includes(e.id)&&n&&n[t]&&n[t].show:n&&n[t]&&n[t].show})).map((function(e,i){if("multi-step-form"===e.form.type){var s=n.find((function(t){return t.id===e.id}));return{title:e.title,substeps:e.form.steps&&r.extractStepTitles(e.form.steps,"".concat(t,"-").concat(i),s.steps)}}return{title:e.title,identifier:"".concat(t,"-").concat(i)}}))},extractSteps:function(t,n,r){var i=this;return t.filter((function(e,t){return"main"===i.formMode?i.configureOptions.includes(e.id)&&r&&r[t]&&r[t].show:r&&r[t]&&r[t].show})).map((function(t,s){if("multi-step-form"===t.form.type){var o=r.find((function(e){return e.id===t.id}));return i.extractSteps(t.form.steps,"".concat(n,"-").concat(s),o.steps)}return e.e({identifier:"".concat(n,"-").concat(s)},t.form)}))},initializeShowSteps:function(){var e=this;return function t(n){return n.map((function(n){var r={id:n.id,show:!n.if||e.performFuncCall(n.if)};return"multi-step-form"===n.form.type&&(r.steps=t(n.form.steps)),r}))}(this.ui&&this.ui.steps)},performFuncCall:function(t){try{var n=t.split("|"),r=n.shift(),i=e.j(n),s=e.h(this.functions,r);if(void 0===s)throw new Error('function "'.concat(r,'" not declared in your functions.js file'));return s.apply(void 0,[this.ctx].concat(e.j(i)))}catch(e){console.log(e)}},watchDependency:function(e){var t=this,n="modelJson"+e.split("#")[1].replace(/\//g,"."),r=this.$watch(n,(function(n){t.$set(t.dependencies,e,n)}),{deep:!0,immediate:!0});this.$set(this.unWatchers,e,r)},initializeValidationObservers:function(){var e=this;this.flatenStepsTree.forEach((function(t){e.$set(e.observers,"ub-step-observer-".concat(t.identifier),{errors:[],validated:!1,valid:!0,invalid:!1})}))},validateStep:function(e){var n=this;return t._(t.r.mark((function r(){var i,s;return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(i=n.$refs[e][0])){t.next=7;break}return t.next=4,i.validate();case 4:return s=t.sent,n.$set(n.observers,e,{errors:i.errors||[],validated:!0,valid:s,invalid:!s}),t.abrupt("return",s);case 7:case"end":return t.stop()}}),r)})))()},changeActiveStep:function(e){var n=this;return t._(t.r.mark((function r(){return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("#-preview"===n.activeStepIdentifier){t.next=3;break}return t.next=3,n.validateStep("ub-step-observer-".concat(n.activeStepIdentifier));case 3:n.activeStepIdentifier=e,n.scrollToTop();case 5:case"end":return t.stop()}}),r)})))()},goToPreviousStep:function(){var e=this;return t._(t.r.mark((function n(){return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("#-preview"===e.activeStepIdentifier){t.next=3;break}return t.next=3,e.validateStep("ub-step-observer-".concat(e.activeStepIdentifier));case 3:e.activeStep=Math.max(e.activeStep-1,0),e.scrollToTop();case 5:case"end":return t.stop()}}),n)})))()},goToNextStep:function(){var e=this;return t._(t.r.mark((function n(){return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.validateStep("ub-step-observer-".concat(e.activeStepIdentifier));case 2:e.activeStep=Math.min(e.activeStep+1,e.flatenStepsTree.length-1),e.scrollToTop();case 4:case"end":return t.stop()}}),n)})))()},done:function(){var e=this;return t._(t.r.mark((function n(){var r,i,s;return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.doneLoader=!0,r=e.flatenStepsTree.map((function(t){return e.validateStep("ub-step-observer-".concat(t.identifier))})),t.next=4,Promise.all(r);case 4:return i=t.sent,"ub-main-observer",t.next=8,e.$refs["ub-main-observer"].validate();case 8:if(t.t0=t.sent,!t.t0){t.next=11;break}t.t0=i.reduce((function(e,t){return e&&t}),!0);case 11:if(s=t.t0,!e.showOptionsStep){t.next=37;break}if(!s){t.next=28;break}if("options"!==e.formMode){t.next=24;break}return t.next=17,e.onOptionsValid();case 17:return e.formMode="main",t.next=20,e.validateStep("ub-step-observer-".concat(e.activeStepIdentifier));case 20:e.activeStep=1,e.scrollToTop(),t.next=26;break;case 24:e.activeStep=e.flatenStepsTree.length,e.scrollToTop();case 26:t.next=35;break;case 28:if("options"!==e.formMode){t.next=33;break}return t.next=31,e.onOptionsInvalid();case 31:t.next=35;break;case 33:return t.next=35,e.onInvalid();case 35:t.next=44;break;case 37:if(!s){t.next=42;break}e.activeStep=e.flatenStepsTree.length,e.scrollToTop(),t.next=44;break;case 42:return t.next=44,e.onInvalid();case 44:e.doneLoader=!1;case 45:case"end":return t.stop()}}),n)})))()},deploy:function(){var e=this;return t._(t.r.mark((function n(){return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.deployLoader=!0,t.next=3,e.onDeploy();case 3:e.deployLoader=!1;case 4:case"end":return t.stop()}}),n)})))()},cancelFunc:function(){var e=this;return t._(t.r.mark((function n(){return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.cancelLoader=!0,!e.showOptionsStep){t.next=13;break}if("options"!==e.formMode){t.next=7;break}return t.next=5,e.onOptionsCancel();case 5:t.next=11;break;case 7:return t.next=9,e.onCancel();case 9:e.activeStep=0,e.formMode="options";case 11:t.next=15;break;case 13:return t.next=15,e.onCancel();case 15:e.cancelLoader=!1;case 16:case"end":return t.stop()}}),n)})))()},getPreviewYamls:function(){var e=this;return t._(t.r.mark((function n(){var r;return t.r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.previewLoader=!0,t.next=3,e.onValid();case 3:r=t.sent,e.$store.commit("wizard/previewYamls$set",r),e.previewLoader=!1;case 6:case"end":return t.stop()}}),n)})))()}},watch:{activeStep:function(e){this.removeAllSticky(),this.$store.commit("wizard/currentStep$set",e)},formMode:function(){this.initializeValidationObservers(),this.$store.commit("wizard/showSteps$set",this.initializeShowSteps())},showPreviewStep:function(e){e&&this.getPreviewYamls()},dependencies:{deep:!0,handler:function(){this.$store.commit("wizard/showSteps$set",this.initializeShowSteps())}}}},o=e.n({render:function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("validation-observer",{ref:"ub-main-observer",attrs:{slim:""}},[n("div",{staticClass:"ac-system-body",class:{"has-info-content":!e.infoCenter.isHide}},[n("div",{staticClass:"ac-system-left-sidebar"},[n("div",{staticClass:"ac-left-sidebar-wrapper"},[n("div",{staticClass:"ac-lef-sidebar-inner"},[n("div",{staticClass:"menu ac-left-sidebar"},[n("div",{staticClass:"widget-menu style-2"},[n("ub-multistep-sidebar-items",{attrs:{steps:e.stepTitles,"active-step-identifier":e.activeStepIdentifier,"show-preview-step":e.showPreviewStep,"validation-observers":e.observers},on:{"click:multistep-sidebar-item":e.changeActiveStep}})],1)])])])]),e._v(" "),n("div",{staticClass:"ac-system-content"},[n("div",{ref:"form-root",staticClass:"pl-20 pt-20",class:{"ui-builders-wrapper":!e.showPreviewStep}},[n("div",{key:e.formMode,ref:"form-content"},[e._l(e.flatenStepsTree,(function(t){return n("validation-observer",{key:t.identifier,ref:"ub-step-observer-"+t.identifier,refInFor:!0,attrs:{vid:"ub-step-observer-"+t.identifier,slim:""}},[n("keep-alive",[e.showPreviewStep||t.identifier!==e.activeStepIdentifier?e._e():n("ub-single-step-form",{attrs:{label:t.label,ui:t,"show-label":t.show_label,"hide-form":t.hideForm,schema:e.schema,"whole-schema":e.schema,"chart-url":e.chartUrl}})],1)],1)})),e._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:e.showPreviewStep,expression:"showPreviewStep"}]},[n("preview-step",{attrs:{"preview-loader":e.previewLoader}})],1)],2),e._v(" "),n("div",{ref:"form-control",staticClass:"bottom-controls ac-footer-action is-flex is-justify-content-space-between is-align-items-center",class:{"pr-0":!e.showPreviewStep}},[n("div",{staticClass:"buttons is-grouped is-left mb-0"},[n("button",{staticClass:"button ac-button is-danger is-light is-extra-small mb-0",class:{"is-loading":e.cancelLoader},on:{click:function(t){return t.preventDefault(),e.cancelFunc()}}},[n("span",[e._v(e._s(e.$ubt("buttons.cancel")))])])]),e._v(" "),n("div",{staticClass:"buttons is-grouped is-right"},[e.activeStep>0?n("button",{staticClass:"button ac-button is-extra-small",on:{click:function(t){return t.preventDefault(),e.goToPreviousStep()}}},[n("span",[e._v(e._s(e.$ubt("buttons.previous")))])]):e._e(),e._v(" "),e.activeStep<e.flatenStepsTree.length-1?n("button",{staticClass:"button is-primary ac-button is-extra-small mr-0",on:{click:function(t){return t.preventDefault(),e.goToNextStep()}}},[n("span",[e._v(e._s(e.$ubt("buttons.next")))])]):e.showPreviewButton?n("button",{staticClass:"button is-primary ac-button is-extra-small mr-0",class:{"is-loading":e.doneLoader},on:{click:function(t){return t.preventDefault(),e.done()}}},[n("span",[e._v(e._s(e.$ubt("buttons.preview")))])]):e.showPreviewStep?n("button",{staticClass:"button is-primary ac-button is-extra-small mr-0",class:{"is-loading":e.deployLoader},on:{click:function(t){return t.preventDefault(),e.deploy()}}},[n("span",[e._v(e._s(e.$ubt("buttons.deploy")))])]):n("button",{staticClass:"button is-primary ac-button is-extra-small mr-0",class:{"is-loading":e.doneLoader},on:{click:function(t){return t.preventDefault(),e.done()}}},[n("span",[e._v(e._s(e.$ubt("buttons.done")))])])])])])]),e._v(" "),e.infoCenter.isHide?e._e():n("info-center")],1)])},staticRenderFns:[]},void 0,s,void 0,!1,"data-v-153b7780",!1,void 0,void 0,void 0);exports.default=o;