@velis/dynamicforms
Version:
Data entry boilerplate components and a RESTful API consumer
5 lines • 104 kB
JavaScript
(function(h,V){typeof exports=="object"&&typeof module!="undefined"?V(exports,require("@dynamicforms/vuetify-inputs"),require("@kyvg/vue3-notification"),require("lodash-es"),require("vue"),require("vuetify/components/VIcon"),require("axios"),require("vuetify/components/VInput"),require("vuetify/components/VAlert"),require("vuetify/components/VGrid"),require("date-fns"),require("vue-ionicon"),require("vuetify/components/VBtn"),require("vuetify/components/VCard"),require("vuetify/components/VSwitch"),require("vuetify/components/transitions"),require("vuetify/components/VForm"),require("vuetify/components/VLayout"),require("vuetify/components/VDialog"),require("resize-observer-polyfill"),require("vuetify/components/VCheckbox"),require("vuetify/components/VColorPicker"),require("vuetify/components/VFileInput"),require("vuetify/components/VList"),require("vuetify/components/VMain"),require("vuetify/components/VMenu"),require("vuetify/components/VProgressLinear"),require("vuetify/components/VProgressCircular"),require("vuetify/components/VTextarea"),require("vuetify/components/VTextField"),require("vue-router")):typeof define=="function"&&define.amd?define(["exports","@dynamicforms/vuetify-inputs","@kyvg/vue3-notification","lodash-es","vue","vuetify/components/VIcon","axios","vuetify/components/VInput","vuetify/components/VAlert","vuetify/components/VGrid","date-fns","vue-ionicon","vuetify/components/VBtn","vuetify/components/VCard","vuetify/components/VSwitch","vuetify/components/transitions","vuetify/components/VForm","vuetify/components/VLayout","vuetify/components/VDialog","resize-observer-polyfill","vuetify/components/VCheckbox","vuetify/components/VColorPicker","vuetify/components/VFileInput","vuetify/components/VList","vuetify/components/VMain","vuetify/components/VMenu","vuetify/components/VProgressLinear","vuetify/components/VProgressCircular","vuetify/components/VTextarea","vuetify/components/VTextField","vue-router"],V):(h=typeof globalThis!="undefined"?globalThis:h||self,V((h.dynamicforms=h.dynamicforms||{},h.dynamicforms["[name]"]={}),h["@dynamicforms/vuetify-inputs"],h["@kyvg/vue3-notification"],h["lodash-es"],h.vue,h["vuetify/components/VIcon"],h.axios,h["vuetify/components/VInput"],h["vuetify/components/VAlert"],h["vuetify/components/VGrid"],h["date-fns"],h["vue-ionicon"],h["vuetify/components/VBtn"],h["vuetify/components/VCard"],h["vuetify/components/VSwitch"],h["vuetify/components/transitions"],h["vuetify/components/VForm"],h["vuetify/components/VLayout"],h["vuetify/components/VDialog"],h["resize-observer-polyfill"],h["vuetify/components/VCheckbox"],h["vuetify/components/VColorPicker"],h["vuetify/components/VFileInput"],h["vuetify/components/VList"],h["vuetify/components/VMain"],h["vuetify/components/VMenu"],h["vuetify/components/VProgressLinear"],h["vuetify/components/VProgressCircular"],h["vuetify/components/VTextarea"],h["vuetify/components/VTextField"],h["vue-router"]))})(this,function(h,V,B,S,t,ke,me,Y,q,U,xe,kt,Ue,O,_t,je,St,_e,Me,Vt,Dt,Nt,Bt,Se,Lt,Et,Tt,Ot,$t,Rt,At){"use strict";var Qr=Object.defineProperty,Xr=Object.defineProperties;var Yr=Object.getOwnPropertyDescriptors;var Ct=Object.getOwnPropertySymbols;var Zr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable;var He=(h,V,B)=>V in h?Qr(h,V,{enumerable:!0,configurable:!0,writable:!0,value:B}):h[V]=B,_=(h,V)=>{for(var B in V||(V={}))Zr.call(V,B)&&He(h,B,V[B]);if(Ct)for(var B of Ct(V))Jr.call(V,B)&&He(h,B,V[B]);return h},v=(h,V)=>Xr(h,Yr(V));var l=(h,V,B)=>He(h,typeof V!="symbol"?V+"":V,B);var g=(h,V,B)=>new Promise((S,t)=>{var ke=q=>{try{Y(B.next(q))}catch(U){t(U)}},me=q=>{try{Y(B.throw(q))}catch(U){t(U)}},Y=q=>q.done?S(q.value):Promise.resolve(q.value).then(ke,me);Y((B=B.apply(h,V)).next())});const A=r=>window.gettext?window.gettext(r):r,G=(r,e)=>window.interpolate?window.interpolate(r,e,!0):r.replace(/%\(\w+\)s/g,n=>String(e[n.slice(2,-2)]));function Pt(){return{gettext:A,interpolate:G}}let Ft=0;const It=["HEADER","ROW_START","ROW_END","FIELD_START","FIELD_END","FORM_HEADER","FORM_FOOTER","ROW_CLICK","ROW_RIGHT_CLICK","VALUE_CHANGED"];function ee(r,e,n){const o=n==null?void 0:n.dialog;return o&&o.resolvePromise&&o.close&&(o.resolvePromise({action:r,payload:e,extraData:n,dialog:o}),o.close()),!0}function te(r){return`action${S.upperFirst(S.camelCase(S.toLower(r)))}`}class I{constructor(e,n){l(this,"name");l(this,"uniqueId");l(this,"position");l(this,"fieldName");l(this,"label");l(this,"labelAvailable");l(this,"icon");l(this,"iconAvailable");l(this,"displayStyle");l(this,"payload");l(this,"title");l(this,"extra_data");const o=++Ft,s=e.name,i=e.position;(!S.isString(s)||!/^[a-zA-Z-_]+$/.test(s))&&console.warn(`Action name must be a valid string, matching [a-zA-Z-_]+. Got ${s}. Impossible to construct handler function name`,e);const a=!S.isString(e.label)||e.label.length===0?null:e.label,c=!S.isString(e.icon)||e.icon.length===0?null:e.icon,p=["asButton","showLabel","showIcon"];function u(b){if(b==null||!S.isObjectLike(b))return null;const k=p.reduce((D,N)=>(S.isBoolean(b[N])&&(D[N]=b[N]),D),{});return Object.keys(k).length===0?null:k}function d(b,k){if(e.displayStyle==null)return;const D=u(e.displayStyle[k]);D&&(b[k]=D)}const f=u(e.displayStyle)||{};d(f,"xl"),d(f,"lg"),d(f,"md"),d(f,"sm"),d(f,"xs"),It.indexOf(i)===-1&&console.warn(`Action position ${i} not known`,e);const y=e instanceof I?e.fieldName:e.field_name,w=!S.isString(y)||y.length===0?null:y,C=!S.isString(e.title)||e.title.length===0?null:e.title,m=te(e.name);this[m]=e[m],Object.defineProperties(this,{name:{get(){return s},enumerable:!0},uniqueId:{get(){return o},enumerable:!1},position:{get(){return i},enumerable:!0},fieldName:{get(){return w},enumerable:!0},label:{get(){return a},enumerable:!0},labelAvailable:{get(){return a!=null},enumerable:!0},icon:{get(){return c},enumerable:!0},iconAvailable:{get(){return c!=null},enumerable:!0},displayStyle:{get(){return f},enumerable:!0},title:{get(){return C},enumerable:!0},extra_data:{get(){var b;return(b=e.extra_data)!=null?b:{}},enumerable:!0},payload:{get(){return n},enumerable:!0}})}static closeAction(e={}){return new I(_({name:"close",label:A("Close"),icon:"close-outline",displayStyle:{asButton:!0,showLabel:!0,showIcon:!0},position:"FORM_FOOTER"},e))}static yesAction(e={}){return new I(_({name:"yes",label:A("Yes"),icon:"thumbs-up-outline",displayStyle:{asButton:!0,showLabel:!0,showIcon:!0},position:"FORM_FOOTER"},e))}static noAction(e={}){return new I(_({name:"no",label:A("No"),icon:"thumbs-down-outline",displayStyle:{asButton:!0,showLabel:!0,showIcon:!0},position:"FORM_FOOTER"},e))}}class E{constructor(e,n){l(this,"actions");l(this,"filterCache");l(this,"payload");this.actions=Object.values(e).reduce((o,s)=>{if(s==null)return o;const i=s.name;return i==null?(console.error("Action has no name and will not be added to the list",s),o):(s instanceof I&&(n===void 0||s.payload===n)?o[i]=s:o[i]=new I(s,n),o)},{}),this.filterCache={},Object.defineProperties(this,{payload:{get(){return n},enumerable:!0}})}get actionsList(){return Object.values(this.actions)}get length(){return this.actionsList.length}*[Symbol.iterator](){for(const e of this.actionsList)yield e}hasAction(e){return this.actionsList.some(n=>n.uniqueId===e.uniqueId)}filter(e,n=null){const o=e+(n?`|${n}`:"");return this.filterCache[o]===void 0&&(this.filterCache[o]=new E(Object.values(this.actions).filter(s=>s.position===e&&(s.fieldName==null||s.fieldName===n)).reduce((s,i)=>(s[i.name]=this.actions[i.name],s),{}))),this.filterCache[o]}get header(){return this.filter("HEADER")}get rowStart(){return this.filter("ROW_START")}get rowEnd(){return this.filter("ROW_END")}get rowClick(){return this.filter("ROW_CLICK")}get rowRightClick(){return this.filter("ROW_RIGHT_CLICK")}fieldAll(e){const n=this.filter("FIELD_START",e),o=this.filter("FIELD_END",e),s=[...n.actionsList,...o.actionsList];return new E(s)}fieldStart(e){return this.filter("FIELD_START",e)}fieldEnd(e){return this.filter("FIELD_END",e)}get formHeader(){return this.filter("FORM_HEADER")}get formFooter(){return this.filter("FORM_FOOTER")}get valueChanged(){return this.filter("VALUE_CHANGED")}}class Ht{}function z(r,e=!0){const n=t.inject("actionHandler",void 0),o=r!=null?r:t.inject("payload",{});class s{constructor(){l(this,"handlers",new Ht);l(this,"register",(u,d)=>(this.handlers[u]=d,this));l(this,"call",(u,d)=>g(this,null,function*(){const f=yield this.recursiveCall(u,o.value,d,e),y=yield this.resolveAction(u,d);return f||y}));l(this,"recursiveCall",(u,d,f,y=!0)=>g(this,null,function*(){var w,C;return y?(yield this.executeHandler(u,d,f))||((w=yield n==null?void 0:n.recursiveCall(u,d,f,y))!=null?w:!1):((C=yield n==null?void 0:n.recursiveCall(u,d,f,y))!=null?C:!1)||(yield this.executeHandler(u,d,f))}));l(this,"executeHandler",(u,d,f)=>g(this,null,function*(){var w,C,m,b,k,D,N;if(u instanceof E){for(const X of u){const Ce=_(_({},(w=X.payload)==null?void 0:w["$extra-data"]),f);if(yield(m=(C=this.handlers)[X.name])==null?void 0:m.call(C,X,d,Ce))return!0}return!1}const y=_(_({},(b=u.payload)==null?void 0:b["$extra-data"]),f);return(N=(D=(k=this.handlers)[u.name])==null?void 0:D.call(k,u,d,y))!=null?N:!1}));l(this,"resolveAction",(u,d)=>g(this,null,function*(){var y,w,C,m,b;if(u instanceof E){for(const k of u){const D=_(_({},(y=k.payload)==null?void 0:y["$extra-data"]),d);if(yield(w=k==null?void 0:k[te(k.name)])==null?void 0:w.call(k,k,k.payload,D))return!0}return!1}const f=_(_({},(C=u.payload)==null?void 0:C["$extra-data"]),d);return(b=(m=u==null?void 0:u[te(u.name)])==null?void 0:m.call(u,u,u.payload,f))!=null?b:!1}))}}const i=new s,a=i.call,c=i.register;return t.provide("actionHandler",i),{registerHandler:c,callHandler:a,handler:i}}var ne=(r=>(r[r.SUPPRESS=1]="SUPPRESS",r[r.HIDDEN=5]="HIDDEN",r[r.INVISIBLE=8]="INVISIBLE",r[r.FULL=10]="FULL",r))(ne||{});const qe=10;(r=>{function e(s){return s.toUpperCase()==="SUPPRESS"?1:s.toUpperCase()==="HIDDEN"?5:s.toUpperCase()==="INVISIBLE"?8:qe}r.fromString=e;function n(s){const i=typeof s=="number"?s:r.fromString(s);return Object.values(r).includes(i)?i:qe}r.fromAny=n;function o(s){const i=typeof s=="number"?s:r.fromString(s);return Object.values(r).includes(i)}r.isDefined=o})(ne||(ne={})),Object.freeze(ne);const $=ne,xt=["onClick"],Ut={key:0,style:{display:"inline-block",float:"right","vertical-align":"middle"}},jt=["onClick"],Mt={style:{display:"inline-block","max-width":"95%"},class:"notification-title"},qt=["innerHTML"],Wt={style:{display:"inline-block","max-width":"95%"},class:"notification-content"},zt=["innerHTML"],Ve=t.defineComponent({__name:"df-notifications",props:{width:{default:350},position:{default:"top center"}},setup(r){return(e,n)=>{const o=t.resolveComponent("notifications");return t.openBlock(),t.createBlock(o,{width:e.width,position:e.position},{body:t.withCtx(({item:s,close:i})=>[t.createElementVNode("div",{class:t.normalizeClass(["vue-notification",s.type]),onClick:a=>s.data.onNotificationClose(s,i,!0)},[t.createElementVNode("div",null,[s.data.duration===-1?(t.openBlock(),t.createElementBlock("div",Ut,[t.createElementVNode("button",{type:"button",class:"close",onClick:a=>s.data.onNotificationClose(s,i)},[t.createVNode(ke.VIcon,{icon:"mdi-window-close"})],8,jt)])):t.createCommentVNode("",!0),t.createElementVNode("div",Mt,[t.createElementVNode("div",{innerHTML:s.title},null,8,qt)]),t.createElementVNode("div",Wt,[t.createElementVNode("div",{style:{"margin-left":"0.4em"},innerHTML:s.text},null,8,zt)])])],10,xt)]),_:1},8,["width","position"])}}}),We=t.defineComponent({__name:"df-app",setup(r){return(e,n)=>{const o=t.resolveComponent("ModalView");return t.openBlock(),t.createElementBlock("div",null,[t.createVNode(Ve),t.createVNode(o),t.renderSlot(e.$slots,"default")])}}});var fe;(r=>{function e(o){return o.type==="group"}r.isGroupTemplate=e;function n(o){return"rows"in o}r.isLayoutTemplate=n})(fe||(fe={}));var re=(r=>(r[r.SMALL=1]="SMALL",r[r.MEDIUM=2]="MEDIUM",r[r.LARGE=3]="LARGE",r[r.X_LARGE=4]="X_LARGE",r[r.DEFAULT=0]="DEFAULT",r))(re||{});const ze=0;(r=>{const e=["large","lg","modal-lg"],n=["medium","md","modal-md"],o=["small","sm","modal-sm"],s=["x-large","xl","modal-xl"];function i(c){return c===void 0?ze:e.includes(c)?3:n.includes(c)?2:o.includes(c)?1:s.includes(c)?4:ze}r.fromString=i;function a(c){const p=typeof c=="number"?c:r.fromString(c);return Object.values(r).includes(p)}r.isDefined=a})(re||(re={})),Object.freeze(re);const P=re;class Gt{constructor(e){l(this,"inputType");l(this,"fieldCSSClass");l(this,"pattern");l(this,"min");l(this,"max");l(this,"minLength");l(this,"maxLength");l(this,"step");l(this,"size");l(this,"formDateFormat");l(this,"formTimeFormat");l(this,"multiple");l(this,"allowTags");l(this,"formComponentDef");var n,o;this.inputType=e.input_type,this.fieldCSSClass=e.field_class,this.pattern=e.pattern,this.min=e.min,this.max=e.max,this.minLength=(n=e.min_length)!=null?n:0,this.maxLength=(o=e.max_length)!=null?o:1e20,this.step=e.step,this.size=e.size,this.formDateFormat=e.form_date_format,this.formTimeFormat=e.form_time_format,this.multiple=e.multiple,this.allowTags=e.allow_tags,this.formComponentDef=e.form_component_def}}class De{constructor(e){l(this,"uuid");l(this,"name");l(this,"label");l(this,"placeholder");l(this,"align");l(this,"visibility");l(this,"renderParams");l(this,"readOnly");l(this,"componentName");l(this,"helpText");l(this,"choices");l(this,"ajax");l(this,"widthClasses");l(this,"allowNull");l(this,"renderKey");l(this,"conditionalVisibility");this.renderKey=0,Object.defineProperties(this,{fieldDef:{get(){return e},enumerable:!1},uuid:{get(){return e.uuid},enumerable:!0},name:{get(){return e.name},enumerable:!0},label:{get(){return e.label},enumerable:!0},placeholder:{get(){return e.placeholder},enumerable:!0},align:{get(){return e.alignment==="decimal"?"right":e.alignment},enumerable:!0},visibility:{get(){return $.fromAny(e.visibility.form)},enumerable:!0},renderParams:{get(){return new Gt(e.render_params)},enumerable:!0},readOnly:{get(){return e.read_only===!0},enumerable:!0},componentName:{get(){return e.render_params.form_component_name},enumerable:!0,configurable:!0},choices:{get(){return e.choices},enumerable:!0},ajax:{get(){return e.ajax},enumerable:!0},colspan:{get(){return e.colspan},enumerable:!0,configurable:!0},helpText:{get(){return e.help_text},enumerable:!0},allowNull:{get(){return e.allow_null},enumerable:!0},conditionalVisibility:{get(){return e.conditional_visibility},enumerable:!0}})}get isVisible(){return this.visibility!==$.SUPPRESS&&this.visibility!==$.HIDDEN}setVisibility(e){let n;$.isDefined(e)?n=$.fromAny(e):e?n=$.FULL:n=$.HIDDEN,n!==this.fieldDef.visibility.form&&(this.fieldDef.visibility.form=n,this.renderKey++)}}let Ge;class Ke extends De{constructor(n,o,s){super(s);l(this,"layoutFieldComponentName");l(this,"colspan");let i=0;Object.defineProperty(this,"layoutFieldComponentName",{get(){return o.component_name||"FormField"},enumerable:!0,configurable:!0}),Object.defineProperty(this,"colspan",{get(){return o.colspan||1},enumerable:!0,configurable:!0}),Object.defineProperty(this,"renderKey",{get(){return i},set(a){i=a,n.renderKey++},enumerable:!0})}}class Qe extends Ke{constructor(n,o,s){var e=(...oo)=>(super(...oo),l(this,"title"),l(this,"layout"),this);if(s==null){const i={uuid:crypto.randomUUID(),name:null,label:"",placeholder:"",alignment:"left",visibility:{form:$.FULL,table:$.SUPPRESS},render_params:{input_type:"",form_component_name:"df-form-layout"},read_only:!0,choices:[],colspan:1,help_text:"",allow_null:!1};e(n,o,i)}else e(n,o,s);Object.defineProperty(this,"layoutFieldComponentName",{get(){return o.component_name||"FormFieldGroup"},enumerable:!0,configurable:!0}),Object.defineProperty(this,"title",{get(){return o.title},enumerable:!0}),Object.defineProperty(this,"layout",{get(){return new Ge(o.layout)},enumerable:!0}),Object.defineProperty(this,"componentName",{get(){return"FormFieldGroup"},enumerable:!0,configurable:!0})}}function Kt(r,e,n){switch(e.type){case"column":return new Ke(r,e,n);case"group":return new Qe(r,e,n);default:throw Error(`Unknown layout column type "${e.type}"`)}}class Qt{constructor(e,n,o){l(this,"renderKey");l(this,"columns");l(this,"componentName");this.columns=e.columns.map(s=>{const i=Kt(this,s,o[s.field]);return n[s.field]=i,i}),this.renderKey=0,Object.defineProperty(this,"componentName",{get(){return e.component_name},enumerable:!0})}get anyVisible(){return this.columns.reduce((e,n)=>e||n.isVisible,!1)}}class pe{constructor(e){l(this,"fields");l(this,"rows");l(this,"componentName");l(this,"fieldName");l(this,"size");e===void 0?(this.fields={},this.rows=[],Object.defineProperty(this,"size",{get(){return P.DEFAULT},enumerable:!0})):(this.fields={},this.rows=e.rows.map(n=>new Qt(n,this.fields,e.fields)),Object.keys(e.fields).forEach(n=>{n in this.fields||(this.fields[n]=new De(e.fields[n]))}),Object.defineProperty(this,"componentName",{get(){return e.component_name},enumerable:!0}),Object.defineProperty(this,"size",{get(){return P.fromString(e.size)},enumerable:!0}))}}Ge=pe;function Xt(r){return r instanceof Qe}function Ne(r){const e=[];return r.fields&&e.push(...Object.values(r.fields)),fe.isLayoutTemplate(r)&&r.rows.forEach(n=>{var o;(o=n.columns)==null||o.forEach(s=>{fe.isGroupTemplate(s)&&s.layout&&s.field==null?e.push(...Ne(s.layout)):Xt(s)&&s.layout&&s.field==null&&e.push(...Ne(s.layout))})}),e}class j{constructor(e,n){l(this,"$extra-data");this.setData(e,n)}static create(e,n){return t.reactive(new j(e,n))}addExtraData(e){const n=_(_({},this["$extra-data"]),e);Object.defineProperty(this,"$extra-data",{get(){return n},enumerable:!1,configurable:!0})}clear(){Object.getOwnPropertyNames(this).forEach(e=>{delete this[e]})}setData(e,n){let o={},s={};return e==null||(e instanceof j?[o,s]=this.copyWithProperties(e):n!=null&&n.fields&&Ne(n).forEach(i=>{if(i.visibility!==$.SUPPRESS){if(i.readOnly&&i.name!=null&&!i.name.endsWith("-display"))o[i.name]={get(){return e[i.name]},enumerable:!1,configurable:!0};else if(i.name!=null){const a=this;a[i.name]=e[i.name],Object.defineProperty(a,`set${i.name}Value`,{get(){return function(p){a[i.name]=p}},enumerable:!1,configurable:!0})}}})),Object.defineProperty(this,"$extra-data",{get(){return s},enumerable:!1,configurable:!0}),Object.defineProperties(this,o),Object.defineProperty(this,"_properties",{get(){return o},enumerable:!1,configurable:!0}),this}replaceData(e,n){return this.clear(),this.setData(e,n)}copyWithProperties(e){return Object.entries(e).forEach(([n,o])=>{this[n]=o}),[S.cloneDeep(e._properties),S.cloneDeep(e["$extra-data"])]}}let Yt=0;class Be{constructor(e,n,o,s,i){l(this,"title");l(this,"body");l(this,"options");l(this,"actions");l(this,"actionHandlers");l(this,"dialogId");l(this,"_topOfTheStack");l(this,"close");l(this,"promise");l(this,"resolvePromise");l(this,"rejectPromise");this.title=e,this.body=n,this.options=o,this.actions=s,this.actionHandlers=i,this.dialogId=++Yt,this.close=()=>null,this.promise=new Promise(()=>{}),this.resolvePromise=()=>null,this.rejectPromise=()=>null}get topOfTheStack(){return this._topOfTheStack||!1}set topOfTheStack(e){this._topOfTheStack=e}}function Le(r,e){if(e==null)return null;if(typeof e=="string")return()=>t.h("span",null,e);if(e instanceof E)return()=>t.h(t.resolveComponent("DfActions"),{slot:r,actions:e});if(e&&"componentName"in e&&"props"in e){const n=S.isString(e.componentName)?t.resolveComponent(e.componentName):e.componentName;return()=>t.h(n,_({slot:r},e.props))}return e}const Xe=t.defineComponent({methods:{renderFunction(r,e,n,o,s,i){return t.h(t.resolveComponent("DfModalDialog"),{show:!0,options:s||{},key:r,actionHandlers:i},{title:Le("title",e),body:Le("body",n),actions:Le("actions",o)})}}});class Zt{constructor(){l(this,"list");l(this,"currentRef");this.list=[],this.currentRef=t.ref(null)}setCurrent(){const e=this.list.length?this.list[this.list.length-1]:null;this.currentRef.value!==e&&(this.currentRef.value=e)}get current(){return this.currentRef.value}push(e,n){const o=S.findIndex(this.list,{dialogId:n});if(o!==-1)e.dialogId=n,this.list[o]=e,o===this.list.length-1&&(e.topOfTheStack=!0);else{if(this.list.length&&(this.list[this.list.length-1].topOfTheStack=!1),e.actions instanceof E){const i=j.create(e.actions.payload||j.create());i.addExtraData({dialog:e}),e.actions=new E(e.actions.actions,i)}this.list.push(e),e.topOfTheStack=!0}const s=this;return e.close=()=>s.pop(e.dialogId),e.promise=new Promise((i,a)=>{e.resolvePromise=i,e.rejectPromise=a}),this.setCurrent(),e.dialogId}getDialogFromId(e){const n=S.findIndex(this.list,{dialogId:e});return n!==-1?this.list[n]:null}pop(e){const n=S.findIndex(this.list,{dialogId:e});n!==-1&&(this.list.splice(n,1),this.list.length&&n===this.list.length&&(this.list[this.list.length-1].topOfTheStack=!0)),this.setCurrent()}isCurrentDialogPromise(e){var n;return((n=this.current)==null?void 0:n.promise)===e}getDialogDefFromPromise(e){return S.find(this.list,{promise:e})}}const Z=new Zt;let Jt=0;const K=[],vt=t.defineComponent({name:"ModalView",mixins:[Xe],setup(){const r=++Jt;return t.onMounted(()=>{K.push(r),K.length>1&&K.indexOf(r)>0&&console.warn("Multiple instances of ModalView placed in VDom. there should be only one!",K)}),t.onUnmounted(()=>{const e=K.indexOf(r);e>-1&&K.splice(e,1)}),{uniqueId:r}},render(){const r=Z.current,e=r==null?void 0:r.dialogId;return!r||K.indexOf(this.uniqueId)!==0?t.h("div",{key:e}):this.renderFunction(e,r.title,r.body,r.actions,r.options,r.actionHandlers)}}),Ye={size:P.DEFAULT},W={get isInstalled(){return K.length>0},getDialogDefinition(r){return r instanceof Promise?Z.getDialogDefFromPromise(r):Z.getDialogFromId(r)},fromRenderFunctions(r,e){return Z.push(e,r)},fromFormDefinition(r){const e=r.layout,n=r.payload,o=r.actions,s=r.actionHandlers,i=r.errors;return this.message(r.title,{componentName:r.layout.componentName,props:{layout:e,payload:n,actions:o,errors:i}},o.formFooter,{size:e.size||P.DEFAULT},s)},message(r,e,n,o,s){if(n)for(const a of n){const c=te(a.name);a[c]||(a[c]=ee)}const i=new Be(r,e,o||Ye,n||new E({close:I.closeAction({actionClose:ee})}),s);return Z.push(i),i.promise},yesNo(r,e,n,o){const s=new Be(r,e,o||Ye,n||new E({yes:I.yesAction({actionYes:ee}),no:I.noAction({actionNo:ee})}));return Z.push(s),s.promise}};var oe=(r=>(r[r.Label=0]="Label",r[r.Filter=1]="Filter",r[r.Data=2]="Data",r))(oe||{});(r=>{r.headerRows=[0,1];function e(o){return Object.values(r).includes(o)}r.isDefined=e;function n(o){return r.headerRows.includes(o)}r.isTHead=n})(oe||(oe={})),Object.freeze(oe);const F=oe,he={showLabelOrHelpText:!0,handlers:void 0,dialogHandlers:void 0};function M(r,e){const n=t.computed({get(){return r.modelValue},set(p){e("update:modelValue",p)}}),o=t.computed(()=>r.errors||[]),s=t.computed(()=>o.value.length),i=t.computed(()=>r.showLabelOrHelpText?r.field.label:""),a=t.computed(()=>r.showLabelOrHelpText?r.field.helpText:""),c=t.computed(()=>({label:i.value,"error-messages":o.value,"error-count":s.value+10,hint:a.value,"persistent-hint":!0,"hide-details":"auto"}));return{value:n,errorsList:o,errorsDisplayCount:s,label:i,helpText:a,baseBinds:c}}const en=t.defineComponent({__name:"date-time",props:t.mergeDefaults({field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},he),emits:["onValueConfirmed","update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{value:s,baseBinds:i}=M(n,o),a=t.computed(()=>n.field.renderParams.inputType),c=t.computed(()=>n.field.renderParams.formDateFormat),p=t.computed(()=>n.field.renderParams.formTimeFormat);return(u,d)=>(t.openBlock(),t.createBlock(t.unref(V.DfDateTime),{modelValue:t.unref(s),"onUpdate:modelValue":d[0]||(d[0]=f=>t.isRef(s)?s.value=f:null),label:t.unref(i).label,errors:t.unref(i)["error-messages"],hint:t.unref(i).hint,"persistent-hint":t.unref(i)["persistent-hint"],clearable:!0,"input-type":a.value,"display-format-date":c.value,"display-format-time":p.value},null,8,["modelValue","label","errors","hint","persistent-hint","input-type","display-format-date","display-format-time"]))}}),tn=t.defineComponent({__name:"df-checkbox",props:t.mergeDefaults({field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},he),emits:["update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{value:s,baseBinds:i}=M(n,o);return(a,c)=>(t.openBlock(),t.createBlock(t.unref(V.DfCheckbox),t.mergeProps({modelValue:t.unref(s),"onUpdate:modelValue":c[0]||(c[0]=p=>t.isRef(s)?s.value=p:null),"allow-null":n.field.allowNull,class:a.field.renderParams.fieldCSSClass,name:a.field.name,enabled:!a.field.readOnly},t.unref(i)),null,16,["modelValue","allow-null","class","name","enabled"]))}}),nn=t.defineComponent({__name:"df-ckeditor",props:t.mergeDefaults({field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},he),emits:["update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{baseBinds:s,value:i}=M(n,o);return(a,c)=>(t.openBlock(),t.createBlock(t.unref(V.DfRtfEditor),{modelValue:t.unref(i),"onUpdate:modelValue":c[0]||(c[0]=p=>t.isRef(i)?i.value=p:null),label:t.unref(s).label,errors:t.unref(s)["error-messages"],hint:t.unref(s).hint,"persistent-hint":t.unref(s)["persistent-hint"],"hide-details":t.unref(s)["hide-details"]},null,8,["modelValue","label","errors","hint","persistent-hint","hide-details"]))}}),rn=t.defineComponent({__name:"df-color",props:{field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},emits:["update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{value:s,baseBinds:i}=M(n,o);return(a,c)=>(t.openBlock(),t.createBlock(t.unref(V.DfColor),t.mergeProps({modelValue:t.unref(s),"onUpdate:modelValue":c[0]||(c[0]=p=>t.isRef(s)?s.value=p:null),class:a.field.renderParams.fieldCSSClass,name:a.field.name,errors:t.unref(i)["error-messages"],enabled:!a.field.readOnly},t.unref(i)),null,16,["modelValue","class","name","errors","enabled"]))}}),Ze=250,Je=new Promise(()=>{});class on{constructor(){l(this,"activeRequests");l(this,"requestCounter");l(this,"apiClient");l(this,"dialogPromise");this.activeRequests={},this.requestCounter=0,this.dialogPromise=Je}addRequest(){const e=++this.requestCounter;return this.activeRequests[e]=new Date().getTime(),{requestId:e,timestamp:this.activeRequests[e]}}removeRequest(e){e&&(delete this.activeRequests[e],this.progressDialogCheck())}loading(){return Object.keys(this.activeRequests).length}get isShowingProgress(){return W.getDialogDefinition(this.dialogPromise)!=null}oldestActiveRequest(){const e=this.activeRequests,n=Object.keys(e);if(n.length===0)return{requestId:null,timestamp:null,age:null};const o=Number(n[0]);return{requestId:o,timestamp:e[o],age:new Date().getTime()-e[o]}}progressDialogCheck(){return g(this,null,function*(){if(!W.isInstalled)return;const e=this.oldestActiveRequest(),n=e.age?e.age:-1;if(n>=Ze&&!this.isShowingProgress)this.show();else if(n>=Ze&&this.isShowingProgress){if(!this.apiClient)return;const o=yield this.apiClient.get("/dynamicforms/progress/",{headers:{"x-df-timestamp":e.timestamp}});if(this.isShowingProgress){const i=W.getDialogDefinition(this.dialogPromise).body;i.props!=null&&(i.props.progress=Number(o.data.value),i.props.label=o.data.comment)}}else this.loading()===0&&this.isShowingProgress&&this.hide()})}show(){console.log(G(A("Showing progress: We have %(active_requests)s active requests to server oldest is %(age)s old with timestamp %(timestamp)s"),{active_requests:this.loading(),age:this.oldestActiveRequest().age,timestamp:this.oldestActiveRequest().timestamp}));const e=A("Performing operation");this.dialogPromise=W.message(e,{componentName:"LoadingIndicator",props:{loading:!0,label:null,progress:null}})}hide(){const e=W.getDialogDefinition(this.dialogPromise);e!=null&&e.close(),this.dialogPromise=Je}}const se=new on;window.setInterval(()=>{se.progressDialogCheck()},250);const sn=2083,T=me.create({xsrfCookieName:"csrftoken",xsrfHeaderName:"X-CSRFToken"});se.apiClient=T;function Q(r){let e=r.data;return typeof e=="string"&&(e=new String(e)),e&&Object.defineProperty(e,"$response-object",{get(){return r},enumerable:!1,configurable:!1}),e}T.interceptors.request.use(r=>{var n,o,s;const e=(n=r.showProgress)!=null?n:!0;if(r.headers["x-df-axios"]="axios",!((o=r.url)!=null&&o.includes("/dynamicforms/progress"))&&!((s=r.url)!=null&&s.includes("unpkg.com"))&&e){const i=se.addRequest();r.sequence=i.requestId,r.headers["x-df-timestamp"]=i.timestamp}if(S.toLower(r.method)==="get"&&S.size(r.url)>sn&&S.includes(S.map(S.keys(r.headers),i=>S.toLower(i)),"x-viewmode")){const i="Your request exceeds maximum length";console.error(i),new AbortController().abort(i)}return r}),T.interceptors.response.use(r=>(se.removeRequest(r.config.sequence),r),r=>(se.removeRequest(r.config.sequence),Promise.reject(r)));const an=t.defineComponent({__name:"df-file",props:{field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},emits:["update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{value:s,baseBinds:i}=M(n,o),a={upload:(c,p)=>g(this,null,function*(){const u=new FormData;u.append("file",c,c.name);const d=yield T.post("/dynamicforms/preupload-file/",u,{showProgress:!1,onUploadProgress:function(y){var w;y.event.lengthComputable&&p!=null&&p(y.loaded,(w=y.total)!=null?w:0)}});return console.log(d.data.identifier),d.data.identifier}),delete:c=>g(this,null,function*(){return yield T.delete(`/dynamicforms/preupload-file/${encodeURIComponent(c)}/`),Promise.resolve()}),touch:c=>g(this,null,function*(){return console.log("Touching file:",c),Promise.resolve()})};return(c,p)=>(t.openBlock(),t.createBlock(t.unref(V.DfFile),{modelValue:t.unref(s),"onUpdate:modelValue":p[0]||(p[0]=u=>t.isRef(s)?s.value=u:null),comms:a,class:t.normalizeClass(c.field.renderParams.fieldCSSClass),name:c.field.name,label:t.unref(i).label,errors:t.unref(i)["error-messages"],enabled:!c.field.readOnly,hint:t.unref(i).hint},null,8,["modelValue","class","name","label","errors","enabled","hint"]))}}),ln=t.defineComponent({__name:"df-input",props:{field:{},actions:{},errors:{},showLabelOrHelpText:{type:Boolean},modelValue:{},handlers:{},dialogHandlers:{}},emits:["update:modelValue"],setup(r,{emit:e}){const n=r,o=e,{value:s,baseBinds:i}=M(n,o),a=t.computed(()=>n.field.renderParams.inputType);return(c,p)=>(t.openBlock(),t.createBlock(t.unref(V.DfInput),t.mergeProps({modelValue:t.unref(s),"onUpdate:modelValue":p[0]||(p[0]=u=>t.isRef(s)?s.value=u:null),class:c.field.renderParams.fieldCSSClass,name:c.field.name,errors:t.unref(i)["error-messages"],enabled:!c.field.readOnly,"input-type":a.value,step:c.field.renderParams.step,min:c.field.renderParams.min,max:c.field.renderParams.max},t.unref(i)),null,16,["modelValue","class","name","errors","enabled","input-type","step","min","max"]))}});var ie=(r=>(r[r.TABLE=1]="TABLE",r[r.FORM=2]="FORM",r[r.DIALOG=3]="DIALOG",r))(ie||{});(r=>{function e(o){return o.toUpperCase()==="TABLE"?1:o.toUpperCase()==="FORM"?2:o.toUpperCase()==="DIALOG"?3:1}r.fromString=e;function n(o){const s=typeof o=="number"?o:r.fromString(o);return Object.values(r).includes(s)}r.isDefined=n})(ie||(ie={})),Object.freeze(ie);const H=ie;function ve(r){if(r)return r.split(".").reduce((e,n)=>{var o;return(o=e[n])!=null?o:{}},window)}var ae=(r=>(r[r.ASC=1]="ASC",r[r.DESC=2]="DESC",r[r.UNORDERED=0]="UNORDERED",r))(ae||{});(r=>{function e(o){return o.toLowerCase().includes("asc")?1:o.toLowerCase().includes("desc")?2:0}r.fromString=e;function n(o){return Object.values(r).includes(o)}r.isDefined=n})(ae||(ae={})),Object.freeze(ae);const L=ae;class et{constructor(e,n,o){l(this,"direction");l(this,"changeCounter");l(this,"column");l(this,"orderingArray");l(this,"isOrderable");l(this,"isOrdered");l(this,"segment");this.direction=L.fromString(e),this.changeCounter=0;const s=/seg-(\d+)/.exec(e),i=s!=null?Number(s[1]):0;n.length=Math.max(n.length,i),i&&n.splice(i-1,1,this),Object.defineProperties(this,{column:{get(){return o},enumerable:!1},orderingArray:{get(){return n},enumerable:!1},isOrderable:{get(){return e.includes("ordering")},enumerable:!0},isOrdered:{get(){return this.isOrderable&&this.segment>0&&this.direction!==L.UNORDERED},enumerable:!0},segment:{get(){return this.isOrderable&&n.indexOf(this)+1||null},enumerable:!0}})}cycleOrdering(){this.isOrdered?this.direction===L.ASC?this.direction=L.DESC:this.direction=L.UNORDERED:this.direction=L.ASC}setSorted(e,n){let o=n||(this.segment>0?this.segment:1);if(o>this.orderingArray.length+1&&(o=this.orderingArray.length+1),this.isOrderable)L.isDefined(e)?(this.segment&&this.orderingArray.splice(this.segment-1,1),e!==L.UNORDERED&&this.orderingArray.splice(o-1,0,this),this.direction=e):console.warn(`unknown sort direction "${e}" for the column ${this.column.name}. not doing anything`);else throw new Error(`column ${this.column.name} is not orderable, but you are trying to set its order direction.`)}handleColumnHeaderClick(e){if(this.isOrderable){if(!e.altKey)if(e.ctrlKey&&e.shiftKey)this.setSorted(L.UNORDERED);else if(e.ctrlKey)this.setSorted(this.direction===L.ASC?L.DESC:L.ASC,1);else if(e.shiftKey){const o=this.segment||this.orderingArray.length+1,s=this.direction===L.ASC?L.DESC:L.ASC;this.setSorted(s,o)}else this.cycleOrdering(),this.orderingArray.splice(0,this.orderingArray.length),this.setSorted(this.direction,1);this.changeCounter++}}calculateOrderingValue(e){const n=this.orderingArray.map(o=>({name:o.column.name,direction:o.direction}));return e?e(n):n.map(o=>(o.direction===L.ASC?"":"-")+o.name)}calculateOrderingFunction(e){const n=this.orderingArray.map(o=>({name:o.column.name,direction:o.direction}));return e?e(n):n}}class ye{constructor(e,n){l(this,"name");l(this,"label");l(this,"align");l(this,"visibility");l(this,"renderParams");l(this,"maxWidth");l(this,"ordering");l(this,"_maxWidth");l(this,"layout");l(this,"CSSClass");l(this,"CSSClassHead");l(this,"renderComponentName");l(this,"renderDecoratorFunction");l(this,"formFieldInstance");var i;this._maxWidth=0,e.ordering=e.ordering||"",this.ordering=new et(e.ordering,n,this),this.layout=null;const o=((i=e.render_params)==null?void 0:i.table)||"";let s=this.renderDecoratorPlain;if(o&&o.substring(0,13)==="df-tablecell-")switch(o.substring(13)){case"bool":s=this.renderDecoratorBool;break;case"link":s=this.renderDecoratorLink;break;case"email":s=this.renderDecoratorEmail;break;case"file":s=this.renderDecoratorFile;break;case"ipaddr":s=this.renderDecoratorIP;break;case"color":s=this.renderDecoratorColor;break}else o&&o.substring(0,1)!=="#"&&(s=ve(o));Object.defineProperties(this,{name:{get(){return e.name},enumerable:!0},label:{get(){return e.label},enumerable:!0},align:{get(){return e.alignment==="decimal"?"right":e.alignment},enumerable:!0},visibility:{get(){return $.fromAny(e.visibility.table)},enumerable:!0},CSSClass:{get(){return e.table_classes||""},enumerable:!0},CSSClassHead:{get(){return this.ordering.isOrderable&&"ordering"||""},enumerable:!0},renderParams:{get(){return e.render_params},enumerable:!0},renderComponentName:{get(){return o&&o.substring(0,1)==="#"?o.substring(1):""},enumerable:!0},renderDecoratorFunction:{get(){return(a,c)=>s.apply(this,[a,c])},enumerable:!0},maxWidth:{get(){return this._maxWidth},enumerable:!0}})}setLayout(e){this.layout=e}setMaxWidth(e){e>this._maxWidth&&(this._maxWidth=e)}renderDecoratorPlain(e,n){return e[this.name]}renderDecoratorColor(e,n){return n?this.renderDecoratorPlain(e,n):`<div style="display: inline-block; width: 1.25em; height: 1.25em; background-color: ${e[this.name]}"/>`}renderDecoratorBool(e,n){if(n)return this.renderDecoratorPlain(e,n);const o=e[this.name];return o===null?"null":`<span style="color: ${o?"green":"red"};">${o?"✔":"✘"}</span>`}renderDecoratorLink(e,n){return n?this.renderDecoratorPlain(e,n):`<a href="${e[this.name]}">${e[this.name]}</a>`}renderDecoratorEmail(e,n){if(n)return this.renderDecoratorPlain(e,n);const o=e[this.name],s=o.includes("<")?o.substring(0,o.indexOf("<")).trim():o;return`<a href="mailto:${o}">${s}</a>`}renderDecoratorFile(e,n){if(n)return this.renderDecoratorPlain(e,n);const o=e[this.name];if(o){const s=`(function(e) {
e.preventDefault();
e.stopPropagation();
window.open('${o.replace(/\/$/,"")}', '_blank');
})`.replace(/\s+/g," "),i=o.replace(/^.*[\\/]/,"");return`<a href="javascript:void(0)" onclick="${s}(event)">${i}</a>`}return null}renderDecoratorIP(e,n){if(n)return this.renderDecoratorPlain(e,n);let o=e[this.name];const s=o.split(".");return s.length===4&&(o=s.map(i=>`${i.length<3?`<span style="opacity: .5">${"000".slice(i.length-3)}</span>`:""}<span>${i}</span>`).join(".")),`<code>${o}</code>`}}class Ee extends Array{constructor(e,n){if(super(),!(e&&n))return;const o=t.reactive([]),s=e.map(i=>new ye(n[i],o));for(let i=o.length-1;i>=0;i--)o[i]||o.splice(i,1);this.push(...s)}}class ge{constructor(e){l(this,"items");l(this,"length");Object.defineProperties(this,{items:{get(){return e},enumerable:!1},length:{get(){return e.length},enumerable:!0}}),this.forEach(n=>{n&&n.name&&(this[n.name]=n)})}push(e){return this[e.name]=e,this.items.push(e)}forEach(e,n){return this.items.forEach(e,n||this)}map(e,n){return this.items.map(e,n||this)}reduce(e,n){return this.items.reduce(e,n)}}class Te{constructor(e){l(this,"dfControlStructure");const n=e.df_control_data||{};delete e.df_control_data,Object.assign(this,e),this.dfControlStructure=t.reactive({measuredHeight:null,isShowing:!0,componentName:"GenericTRow",CSSClass:n.row_css_class||"",CSSStyle:n.row_css_style||""}),Object.defineProperty(this.dfControlStructure,"actions",{get(){return n.actions||""},enumerable:!0})}setMeasuredHeight(e){this.dfControlStructure.measuredHeight!==e&&(this.dfControlStructure.measuredHeight=e)}setIsShowing(e){this.dfControlStructure.isShowing!==e&&(this.dfControlStructure.isShowing=e)}}class cn{constructor(e){l(this,"columns");l(this,"value");l(this,"payload");if(!e){this.columns=new ge([]),this.payload=j.create();return}const n=S.filter(e.columns,a=>!S.includes(a.name,"#actions"));let o=S.clone(e.record);o=S.mapValues(o,()=>null),this.value=new Te(o);const s={};n.forEach(a=>{s[a.name]=a});const i=S.filter(new Ee(n.map(a=>a.name),s),a=>a.visibility===$.FULL);i.forEach(a=>{const c=a.name.replace(/-display$/,""),p=s[c];p.help_text="",p.label="",a.formFieldInstance=new De(p)}),this.columns=new ge(i),this.payload=j.create(o,{fields:this.columns,rows:[],component_name:""})}}class tt{constructor(e,n){l(this,"logic");l(this,"visibilityHandler");l(this,"next");l(this,"rows");l(this,"rowIndices");this.logic=e,this.visibilityHandler=()=>(console.log("Empty handler"),!1),this.rows=t.reactive([]),this.replaceRows(n)}replaceRows(e){this.rows.splice(0,this.rows.length),this.next=null,this.rowIndices={},e&&"results"in e&&Array.isArray(e.results)?(this.updateRows(e.results),this.next=e.next,this.decorate(this.rows)):Array.isArray(e)&&this.updateRows(e)}get data(){return this.rows}decorate(e){if(!e||!e.length){this.visibilityHandler=()=>(console.log("Empty handler 2"),!1);return}const n=this.logic.pkName,o=e[0][n],s=e[e.length-1][n],i=this;this.visibilityHandler=a=>o!==a&&s!==a?!1:{callback:c=>{i.loadMoreRows(c)},once:!0}}loadMoreRows(e){return g(this,null,function*(){if(!e||!this.next)return;const n=yield this.logic.fetchNewRows(this.next);n!==void 0&&(this.updateRows(n.results),this.next=n.next,this.decorate(n.results))})}updateRows(e){const n=this.logic.pkName;e.map(o=>{const s=new Te(o),i=s[n],a=this.rowIndices[i];if(a!=null)this.rows[a]=s;else{const c=this.rows.push(s);this.rowIndices[i]=c-1}return null})}reIndex(){this.rowIndices={};const e=this.logic.pkName;this.rows.forEach((n,o)=>{this.rowIndices[n[e]]=o})}deleteRow(e){this.rows.splice(this.rowIndices[e],1),this.reIndex()}}class Oe{constructor(){l(this,"pkName");l(this,"fields");l(this,"tableColumns");l(this,"loading");l(this,"responsiveTableLayouts");l(this,"formFields");l(this,"formLayout");l(this,"formComponent");l(this,"errors");l(this,"actions");l(this,"ux_def");l(this,"rows");l(this,"formData");l(this,"requestedPKValue");l(this,"ordering");l(this,"filterDefinition");l(this,"filterData");l(this,"titles");l(this,"dialogHandlers");l(this,"rowSelect",!1);l(this,"setDialogHandlers",e=>{this.dialogHandlers=e});this.pkName="id",this.loading=!1,this.fields={},this.tableColumns=new Ee([],{}),this.responsiveTableLayouts=void 0,this.formFields={},this.formLayout=null,this.formComponent="df-form-layout",this.errors={},this.actions=new E({}),this.ux_def={},this.rows=new tt(this,[]),this.formData=j.create(),this.requestedPKValue=null,this.ordering={parameter:"ordering",style:void 0,counter:0},this.filterDefinition=null,this.filterData={},this.titles={new:"",edit:"",table:""}}get tableDefinition(){return{title:this.title("table"),pkName:this.pkName,columns:this.tableColumns,responsiveTableLayouts:this.responsiveTableLayouts,columnDefs:this.fields,rows:this.rows,loading:this.loading,actions:this.actions,filterDefinition:this.filterDefinition,rowSelect:this.rowSelect}}get pkValue(){var e;return this.requestedPKValue==="new"||this.requestedPKValue==null?this.requestedPKValue:(e=this.formData)==null?void 0:e[this.pkName]}processUXDefinition(e){this.pkName=e.primary_key_name,this.titles=e.titles,e.columns.forEach(n=>{this.fields[n.name]=n}),this.rowSelect=e.row_select,this.tableColumns=new Ee(e.columns.map(n=>n.name),this.fields),this.rows.replaceRows(e.rows),this.setOrdering(e.ordering_parameter,e.ordering_style,this.tableColumns[0].ordering.changeCounter),this.responsiveTableLayouts=e.responsive_table_layouts,this.actions=new E(e.actions),this.filterDefinition=new cn(e.filter)}get formDefinition(){return this.formLayout=new pe(this.ux_def.dialog),this.formData.replaceData(this.ux_def.record,this.formLayout),this.actions=new E(this.ux_def.actions),{title:this.title(this.pkValue==="new"?"new":"edit"),pkName:this.pkName,pkValue:this.pkValue,layout:this.formLayout,payload:this.formData,loading:this.loading,actions:this.actions,errors:this.errors}}title(e){return this.titles[e]}setOrdering(e,n,o){this.ordering={parameter:e||"ordering",style:n,counter:o}}filter(e=null){return g(this,null,function*(){e&&(this.filterData=Object.fromEntries(Object.entries(e).filter(([n,o])=>!S.includes([null,void 0,NaN],o)&&!n.endsWith("-display")))),yield this.reload(!0)})}}class le{constructor(e,n){l(this,"pkName","id");l(this,"ux_def",{});l(this,"layout");l(this,"titles",{new:"",edit:"",table:""});l(this,"actions",new E({}));l(this,"data");l(this,"loading",!1);l(this,"errors",t.reactive({}));l(this,"actionHandlers");l(this,"api");l(this,"beforeDialog");l(this,"afterDialog");this.actionHandlers=e,Object.assign(this,n),this.data=j.create()}title(e){var n;return(n=this.titles[e])!=null?n:""}get pkValue(){var e,n;return(n=(e=this.data)==null?void 0:e[this.pkName])!=null?n:"new"}get definition(){return{title:this.title(this.pkValue==="new"?"new":"edit"),pkName:this.pkName,pkValue:this.pkValue,layout:this.layout,payload:this.data,loading:this.loading,actions:this.actions,errors:this.errors,actionHandlers:this.actionHandlers}}withErrors(e){return Object.keys(this.errors).forEach(n=>delete this.errors[n]),Object.assign(this.errors,e),this}execute(e){return g(this,null,function*(){var s,i;const n=this.definition;e&&(Object.assign(n.payload,e),this.data=n.payload),(s=this.beforeDialog)==null||s.call(this,this);const o=yield W.fromFormDefinition(n);return(i=this.afterDialog)==null||i.call(this,this,o),{data:this.data,action:o}})}delete(){return g(this,null,function*(){if(this.pkValue!==void 0&&this.pkValue!=="new")return this.api.delete();throw{response:{data:{detail:A("Cannot delete new record.")}}}})}save(){return g(this,null,function*(){return this.pkValue!=="new"&&this.pkValue?this.api.update(this.data):this.api.create(this.data)})}getRecord(){return g(this,null,function*(){return this.api.retrieve()})}getUXDefinition(){return g(this,null,function*(){return this.layout?this.ux_def.record=yield this.getRecord():(this.ux_def=yield this.api.componentDefinition(),this.pkName=this.ux_def.primary_key_name,this.titles=this.ux_def.titles),this.layout=new pe(this.ux_def.dialog),this.data=this.data.replaceData(this.ux_def.record,this.layout),this.actions=new E(this.ux_def.actions),this.definition})}}const dn={style:{flex:"auto"}},$e=t.defineComponent({__name:"api-consumer",props:{consumer:{},displayComponent:{},handlers:{},dialogHandlers:{}},setup(r){const e=r;H.isDefined(e.displayComponent)||console.warn(G("ApiConsumer.displayComponent property has an unsupported value '%(component)s'",{component:e.displayComponent}));const n=t.computed(()=>{switch(e.displayComponent){case H.TABLE:return"df-table";case H.FORM:return"df-form";case H.DIALOG:return"df-modal";default:throw Error("Unknown component display type")}}),o=t.computed(()=>e.displayComponent),s=t.computed(()=>{switch(o.value){case H.TABLE:return e.consumer.tableDefinition;case H.FORM:return e.consumer.definition;default:throw Error("Unknown component display type")}}),{handler:i}=z();e.consumer instanceof Oe&&e.consumer.setDialogHandlers(e.dialogHandlers);function a(m,b){return g(this,null,function*(){return(yield W.yesNo(A("Delete"),A("Are you sure you want to delete this record?"))).action.name.toUpperCase()==="YES"&&(yield e.consumer.deleteRow(b)),!0})}function c(m,b){return e.displayComponent===H.TABLE&&e.consumer.filter(b),!0}function p(){return g(this,null,function*(){return yield e.consumer.dialogForm("new"),!0})}function u(m,b,k){return g(this,null,function*(){return k.rowType!==F.Data||b==null?!1:(yield e.consumer.dialogForm(b[e.consumer.pkName]),!0)})}function d(m,b,k){if(k.rowType===F.Label&&m.position==="ROW_CLICK"&&k.column){const D=k.column.ordering.changeCounter;return k.column.ordering.handleColumnHeaderClick(k.event),D!==k.column.ordering.changeCounter&&e.consumer.reload(),!0}return!1}const f=()=>g(this,null,function*(){return yield e.consumer.getUXDefinition(),!0}),y=()=>g(this,null,function*(){var m;try{yield e.consumer.save(),e.consumer.withErrors({})}catch(b){return e.consumer.withErrors(_({},(m=b==null?void 0:b.response)==null?void 0:m.data)),!0}return yield e.consumer.getUXDefinition(),!0});function w(){e.displayComponent===H.FORM&&(e.consumer instanceof le||console.error("Showing FORM requires a FormConsumerBase consumer, but the provided one is not",e.consumer)),e.displayComponent===H.TABLE&&e.consumer instanceof le&&console.error("Showing TABLE requires a ConsumerLogicBase consumer, but the provided one is not",e.consumer)}w(),t.watch(()=>e.displayComponent,w);const C={delete:a,value_changed:c,sort:d,add:p,edit:u,cancel:f,submit:y};for(const m of Object.keys(_(_({},C),e.handlers)))i.register(m,(b,k,D)=>g(this,null,function*(){var N,X,Ce;return(yield(X=(N=e==null?void 0:e.handlers)==null?void 0:N[m])==null?void 0:X.call(N,b,k,D))||(yield(Ce=C==null?void 0:C[m])==null?void 0:Ce.call(C,b,k,D))}));return(m,b)=>{var k,D;return t.openBlock(),t.createElementBlock("div",dn,[(t.openBlock(),t.createBlock(t.resolveDynamicComponent(n.value),t.mergeProps(s.value,{"sub-handlers":(k=m.handlers)==null?void 0:k.subhandlers,"dialog-sub-handlers":(D=m.dialogHandlers)==null?void 0:D.subhandlers}),null,16,["sub-handlers","dialog-sub-handlers"]))])}}});function un(r,e,n){return new Proxy(r,{get:(o,s)=>{var i;return s===e?(i=o[s])!=null?i:n:s==="__pk_name"?e:s==="__isInternalRecord"?!0:o[s]},set:(o,s,i)=>(s!==e&&(o[s]=i),!0)})}function mn(r){const e=S.cloneDeep(r),n=r.__pk_name;return e[n]=r[n],e}function fn(r){return!!(r&&(r!=null&&r.__isInternalRecord))}function pn(r){const e=t.isRef(r)?r:t.ref(r);return t.computed(()=>e.value.replace(/\/+$/,""))}class hn{constructor(e,n=!1){l(this,"baseUrl");l(this,"headers",{"x-viewmode":"TABLE_ROW","x-pagination":1});l(this,"trailingSlash");l(this,"detail_url",e=>`${this.baseUrl.value}${e?`/${e}`:""}`);l(this,"componentDefinition",(e,n)=>g(this,null,function*(){return(yield T.get(this.compose_url(this.definition_url(this.detail_url(e))),e?n:_({headers:this.headers},n))).data}));l(this,"list",e=>g(this,null,function*(){const n=yield T.get(this.compose_url(this.baseUrl.value),_({headers:this.headers},e));let o=n.data;return Array.isArray(o)&&(o={next:null,prev:null,results:o}),v(_({},o),{"$response-object":n})}));l(this,"retrieve",(e,n)=>g(this,null,function*(){return Q(yield T.get(this.compose_url(this.data_url(this.detail_url(e))),n))}));l(this,"create",(e,n)=>g(this,null,function*(){return Q(yield T.post(this.compose_url(this.baseUrl.value),e,n))}));l(this,"update",(e,n,o)=>g(this,null,function*(){return Q(yield T.put(this.compose_url(this.detail_url(e)),n,o))}));l(this,"delete",(e,n)=>g(this,null,function*(){return Q(yield T.delete(this.compose_url(this.detail_url(e)),n))}));this.baseUrl=pn(e),this.trailingSlash=n}compose_url(e){return this.trailingSlash?`${e}/`:e}definition_url(e){return`${e}.componentdef`}data_url(e){return`${e}.json`}}class yn{constructor(e){l(this,"data");l(this,"ux_def");l(this,"pk");l(this,"pkName");l(this,"counter");l(this,"componentDefinition",()=>this.ux_def);l(this,"retrieve",()=>this.data.find(e=>this.comparePk(e)));this.data=e.data,this.ux_def=e.definition,this.pk=t.ref(e.pk),this.pkName=e.pkName,this.counter=t.computed(()=>-this.data.filter(n=>fn(n)).length)}comparePk(e){return e[this.pkName]===this.pk.value}create(e){return this.data.push(un(_({},e),this.pkName,this.counter.value-1)),e}update(e){return g(this,null,function*(){const n=this.retrieve();for(const[o,s]of Object.entries(e))n[o]=s;return n})}delete(){const e=this.data.findIndex(o=>this.comparePk(o)),n=this.data[e];return this.data.splice(e,1),n}}class nt extends le{constructor(e,n,o){super(n,o),this.api=new yn(e)}}function Re(r){return g(this,null,function*(){var s;let e={},n,o;yield r.getUXDefinition();do{const i=yield r.withErrors(e).execute(o),a=i.action;if(o=i.data,e={},a.action.name==="submit")try{n=yield r.save()}catch(c){e=_({},(s=c==null?void 0:c.response)==null?voi