@appscode/ui-builder
Version:
## Motivation
1 lines • 13.6 kB
JavaScript
import{f as e,i as t,t as n,_ as i,a as r,b as s,c as o,d as a,V as c,e as u,m as p,g as l,h as f,j as d,n as v}from"./wrapper-5d451278.js";import"vue";import"./es.array.concat-bc6da240.js";import"./es.array.find-index-091ba8fd.js";import"./index-ba66ec6f.js";import"./web.dom-collections.iterator-98113e95.js";import"./set-to-string-tag-edc1b53a.js";import"./object-set-prototype-of-866dfe15.js";import{s as h,_ as m,r as b}from"./stickyContent-c27d9838.js";import{l as w}from"./index-f7c726f7.js";var S=function(i,r,s,o,a,c,u,p){for(var l,f=a,d=0,v=!!u&&e(u,p,3);d<o;){if(d in s){if(l=v?v(s[d],d,r):s[d],c>0&&t(l))f=S(i,r,l,n(l.length),f,c-1)-1;else{if(f>=9007199254740991)throw TypeError("Exceed the acceptable array length");i[f]=l}f++}d++}return f},x=S;i({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,t=r(this),i=n(t.length),a=s(t,0);return a.length=x(a,t,t,i,0,void 0===e?1:o(e)),a}}),a("flat");var g=v({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,{name:"ub-multi-step-form",mixins:[h],components:{ValidationObserver:c,InfoCenter:function(){return import("./InfoCenter-500fc9f1.js").then((function(e){return e.default}))},PreviewStep:function(){return import("./PreviewStep-b5b07b87.js").then((function(e){return e.default}))},UbSingleStepForm:function(){return import("./SingleStepForm-e4a2064c.js").then((function(e){return e.S})).then((function(e){return e.default}))},UbMultistepSidebarItems:function(){return import("./SidebarItems-aa070898.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:u(u({},p({infoCenter:"wizard/infoCenter",modelJson:"wizard/model",configureOptions:"wizard/configureOptions",showSteps:"wizard/showSteps",store$get:"wizard/store$get",functions:"wizard/functions"})),{},{ctx:function(){return{model:l(this.modelJson),schema:l(this.schema),ui:l(this.ui),axios:this.$axios,qs:w,getValue:f,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 i=this;return e.filter((function(e,t){return"main"===i.formMode?i.configureOptions.includes(e.id)&&n&&n[t]&&n[t].show:n&&n[t]&&n[t].show})).map((function(e,r){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&&i.extractStepTitles(e.form.steps,"".concat(t,"-").concat(r),s.steps)}}return{title:e.title,identifier:"".concat(t,"-").concat(r)}}))},extractSteps:function(e,t,n){var i=this;return e.filter((function(e,t){return"main"===i.formMode?i.configureOptions.includes(e.id)&&n&&n[t]&&n[t].show:n&&n[t]&&n[t].show})).map((function(e,r){if("multi-step-form"===e.form.type){var s=n.find((function(t){return t.id===e.id}));return i.extractSteps(e.form.steps,"".concat(t,"-").concat(r),s.steps)}return u({identifier:"".concat(t,"-").concat(r)},e.form)}))},initializeShowSteps:function(){var e=this;return function t(n){return n.map((function(n){var i={id:n.id,show:!n.if||e.performFuncCall(n.if)};return"multi-step-form"===n.form.type&&(i.steps=t(n.form.steps)),i}))}(this.ui&&this.ui.steps)},performFuncCall:function(e){try{var t=e.split("|"),n=t.shift(),i=d(t),r=f(this.functions,n);if(void 0===r)throw new Error('function "'.concat(n,'" not declared in your functions.js file'));return r.apply(void 0,[this.ctx].concat(d(i)))}catch(e){console.log(e)}},watchDependency:function(e){var t=this,n="modelJson"+e.split("#")[1].replace(/\//g,"."),i=this.$watch(n,(function(n){t.$set(t.dependencies,e,n)}),{deep:!0,immediate:!0});this.$set(this.unWatchers,e,i)},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 t=this;return m(b.mark((function n(){var i,r;return b.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(i=t.$refs[e][0])){n.next=7;break}return n.next=4,i.validate();case 4:return r=n.sent,t.$set(t.observers,e,{errors:i.errors||[],validated:!0,valid:r,invalid:!r}),n.abrupt("return",r);case 7:case"end":return n.stop()}}),n)})))()},changeActiveStep:function(e){var t=this;return m(b.mark((function n(){return b.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("#-preview"===t.activeStepIdentifier){n.next=3;break}return n.next=3,t.validateStep("ub-step-observer-".concat(t.activeStepIdentifier));case 3:t.activeStepIdentifier=e,t.scrollToTop();case 5:case"end":return n.stop()}}),n)})))()},goToPreviousStep:function(){var e=this;return m(b.mark((function t(){return b.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()}}),t)})))()},goToNextStep:function(){var e=this;return m(b.mark((function t(){return b.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()}}),t)})))()},done:function(){var e=this;return m(b.mark((function t(){var n,i,r;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.doneLoader=!0,n=e.flatenStepsTree.map((function(t){return e.validateStep("ub-step-observer-".concat(t.identifier))})),t.next=4,Promise.all(n);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(r=t.t0,!e.showOptionsStep){t.next=37;break}if(!r){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(!r){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()}}),t)})))()},deploy:function(){var e=this;return m(b.mark((function t(){return b.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()}}),t)})))()},cancelFunc:function(){var e=this;return m(b.mark((function t(){return b.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()}}),t)})))()},getPreviewYamls:function(){var e=this;return m(b.mark((function t(){var n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.previewLoader=!0,t.next=3,e.onValid();case 3:n=t.sent,e.$store.commit("wizard/previewYamls$set",n),e.previewLoader=!1;case 6:case"end":return t.stop()}}),t)})))()}},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())}}}},void 0,!1,void 0,!1,void 0,void 0,void 0);export default g;