@dynamicforms/vue-forms 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dynamicforms-vue-forms.js +786 -635
- package/dist/dynamicforms-vue-forms.js.map +1 -1
- package/dist/dynamicforms-vue-forms.umd.cjs +2 -2
- package/dist/dynamicforms-vue-forms.umd.cjs.map +1 -1
- package/dist/index.d.cts +60 -0
- package/dist/index.d.ts +60 -0
- package/package.json +11 -4
- package/readme.md +14 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("lodash-es"),require("vue")):typeof define=="function"&&define.amd?define(["exports","lodash-es","vue"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u((l["dynamicforms-vue-forms"]=l["dynamicforms-vue-forms"]||{},l["dynamicforms-vue-forms"]["[name]"]={}),l["lodash-es"],l.vue))})(this,(function(l,u,c){"use strict";var Me=Object.defineProperty,$e=Object.defineProperties;var He=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var te=(l,u,c)=>u in l?Me(l,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[u]=c,E=(l,u)=>{for(var c in u||(u={}))fe.call(u,c)&&te(l,c,u[c]);if($)for(var c of $(u))pe.call(u,c)&&te(l,c,u[c]);return l},H=(l,u)=>$e(l,He(u));var P=(l,u)=>{var c={};for(var b in l)fe.call(l,b)&&u.indexOf(b)<0&&(c[b]=l[b]);if(l!=null&&$)for(var b of $(l))u.indexOf(b)<0&&pe.call(l,b)&&(c[b]=l[b]);return c};var h=(l,u,c)=>te(l,typeof u!="symbol"?u+"":u,c);var b=(s=>(s[s.SUPPRESS=1]="SUPPRESS",s[s.HIDDEN=5]="HIDDEN",s[s.INVISIBLE=8]="INVISIBLE",s[s.FULL=10]="FULL",s))(b||{});const ne=10;(s=>{function n(i){return i.toUpperCase()==="SUPPRESS"?1:i.toUpperCase()==="HIDDEN"?5:i.toUpperCase()==="INVISIBLE"?8:ne}s.fromString=n;function e(i){const r=typeof i=="number"?i:s.fromString(i);return Object.values(s).includes(r)?r:ne}s.fromAny=e;function t(i){const r=typeof i=="number"?i:s.fromString(i);return Object.values(s).includes(r)}s.isDefined=t})(b||(b={})),Object.freeze(b);const I=b;class y{constructor(n){h(this,"executorFn");this.executorFn=n}static get classIdentifier(){throw new Error("classIdentifier must be declared")}get classIdentifier(){return this.constructor.classIdentifier}execute(n,e,...t){return this.executorFn(n,e,...t)}get eager(){return!1}boundToField(n){}unregister(){}}class R extends Error{}const ie=Symbol("ValueChangedAction");class A extends y{constructor(n){super(n)}static get classIdentifier(){return ie}execute(n,e,t,i){return super.execute(n,e,t,i)}}class x extends String{constructor(e,t,i){super(e);h(this,"plugins");h(this,"options");this.plugins=i,this.options=t}}function U(s){const n=c.unref(s);return typeof n=="object"&&"componentName"in n}function j(s){return typeof c.unref(s)=="function"}class k{get componentName(){return"Comment"}get componentBindings(){return{}}get componentBody(){return""}get extraClasses(){return""}}class se extends k{constructor(e,t=""){super();h(this,"text");h(this,"classes");this.text=e,this.classes=t}get componentName(){return"template"}get componentBody(){return this.text}get extraClasses(){return this.classes}}class v extends k{constructor(e,t=""){super();h(this,"classes");h(this,"text");h(this,"textType");this.classes=t,this.text=e,this.textType=c.computed(()=>this.getTextType)}get resolvedText(){const e=c.unref(this.text);return j(e)?e():e}get getTextType(){const e=this.resolvedText;return e?e instanceof x?"md":U(e)?"component":"string":"string"}get componentName(){switch(c.unref(this.textType)){case"string":return"template";case"md":return"vue-markdown";case"component":return this.resolvedText.componentName;default:return"template"}}get componentBindings(){switch(c.unref(this.textType)){case"string":return{};case"md":{const e=this.resolvedText;return{source:e.toString(),options:e.options,plugins:e.plugins}}case"component":return this.resolvedText.componentProps||{};default:return{}}}get componentBody(){switch(c.unref(this.textType)){case"string":return this.resolvedText;case"component":return this.resolvedText.componentVHtml||"";default:return""}}get extraClasses(){return this.classes}}class re extends v{}const be=Symbol("Validator");class m extends A{constructor(e){super((i,r,a,o)=>{const d=e(a,o,i)||[],g=f=>{var O;f==null||f.forEach(S=>Object.defineProperty(S,"source",{value:this.source,enumerable:!1,configurable:!1}));for(let S=i.errors.length-1;S>=0;S--){const q=i.errors[S];if(q.source===this.source){const M=(O=f==null?void 0:f.findIndex(ee=>u.isEqual(ee,q)))!=null?O:-1;M>=0?f==null||f.splice(M,1):i.errors.splice(S,1)}}f&&f.length>0&&i.errors.push(...f),i.validate()};return d instanceof Promise?(i.beginValidating(),d.then(f=>g(f)).finally(()=>i.endValidating())):g(d),r(i,a,o)});h(this,"source");this.source=Symbol(this.constructor.name)}static get classIdentifier(){return be}get eager(){return!0}replacePlaceholdersFunction(e,t){return()=>{let i=c.unref(e);for(;j(i);)i=c.unref(this.replacePlaceholders(i(),t));return i}}replacePlaceholders(e,t){if(j(e))return this.replacePlaceholdersFunction(e,t);if(U(e))return e;let i=c.unref(e);return Object.keys(t).forEach(r=>{i=i.replaceAll(`{${r}}`,t[r])}),e instanceof x?new x(i.toString(),e.options,e.plugins):i}}class F extends Map{constructor(){super(...arguments);h(this,"eagerActions",new Set);h(this,"registeredActions",[])}register(e){if(!(e instanceof y))throw new Error("Invalid action type");this.registeredActions.push(e);const t=e.classIdentifier,i=this.get(t)||(()=>null);function r(a,...o){return e.execute(a,i,...o)}this.set(t,r),e.eager&&this.eagerActions.add(e.classIdentifier)}trigger(e,t,...i){const r=e.classIdentifier;r===ie&&this.triggerEager(t,...i);const a=this.get(r);try{if(a)return a(t,...i)}catch(o){if(!(o instanceof R))throw o}return null}triggerEager(e,...t){for(const i of this.eagerActions){const r=this.get(i);try{r&&r(e,...t)}catch(a){if(!(a instanceof R))throw a}}}clone(){const e=new F;return this.registeredActions.forEach(t=>e.register(t)),e}cloneWithoutValidators(){const e=new F;return this.registeredActions.forEach(t=>{t instanceof m?t.unregister():e.register(t)}),e}}const me=Symbol("ConditionalStatementAction");class T extends A{constructor(e,t){const i=(r,a,o,d)=>{const g=e.evaluate();if(g!==this.lastResult){for(const f of this.boundFields)t(f,g,this.lastResult);this.lastResult=g}return a(r,o,d)};super(i);h(this,"lastResult");h(this,"boundFields",new Set);e.collectFields().forEach(r=>r.registerAction(new A(i)))}static get classIdentifier(){return me}get eager(){return!0}boundToField(e){this.boundFields.add(e)}}class ae extends T{constructor(n){super(n,(e,t)=>{e.visibility=t?I.FULL:I.SUPPRESS})}}class le extends T{constructor(n){super(n,(e,t)=>{e.enabled=t})}}class oe extends T{constructor(n,e){super(n,(t,i)=>{i&&(t.value=e)})}}var N=(s=>(s[s.NOT=0]="NOT",s[s.OR=1]="OR",s[s.AND=2]="AND",s[s.XOR=3]="XOR",s[s.NAND=4]="NAND",s[s.NOR=5]="NOR",s[s.EQUALS=-1]="EQUALS",s[s.NOT_EQUALS=-2]="NOT_EQUALS",s[s.GT=-3]="GT",s[s.LT=-4]="LT",s[s.GE=-5]="GE",s[s.LE=-6]="LE",s[s.IN=-7]="IN",s[s.NOT_IN=-8]="NOT_IN",s[s.INCLUDES=-9]="INCLUDES",s[s.NOT_INCLUDES=-10]="NOT_INCLUDES",s))(N||{});(s=>{function n(r){const a=r.toLowerCase();if(a==="not")return 0;if(a==="or")return 1;if(a==="and")return 2;if(a==="xor")return 3;if(a==="nand")return 4;if(a==="nor")return 5;if(a==="equals")return-1;if(["not_equals","not-equals","not equals"].includes(a))return-2;if(a==="gt")return-3;if(a==="lt")return-4;if(a==="ge")return-5;if(a==="le")return-6;if(a==="in")return-7;if(["not_in","not-in","not in"].includes(a))return-8;if(a==="includes")return-9;if(["not_includes","not-includes","not includes"].includes(a))return-10;throw new Error(`Unrecognised operator ${a}`)}s.fromString=n;function e(r){const a=typeof r=="number"?r:s.fromString(r);if(Object.values(s).includes(a))return a;throw new Error(`Unrecognised operator ${r}`)}s.fromAny=e;function t(r){const a=typeof r=="number"?r:s.fromString(r);return Object.values(s).includes(a)}s.isDefined=t;function i(r){return r>=0}s.isLogicOperator=i})(N||(N={})),Object.freeze(N);const p=N,ve=Symbol("EnabledChangingAction");class Q extends y{constructor(n){super(n)}static get classIdentifier(){return ve}execute(n,e,t,i){return super.execute(n,e,t,i)}}const ye=Symbol("EnabledChangedAction");class z extends y{constructor(n){super(n)}static get classIdentifier(){return ye}execute(n,e,t,i){return super.execute(n,e,t,i)}}const Ae=Symbol("ValidChangedAction");class W extends y{constructor(n){super(n)}static get classIdentifier(){return Ae}execute(n,e,t,i){return super.execute(n,e,t,i)}}const Ce=Symbol("VisibilityChangingAction");class G extends y{constructor(n){super(n)}static get classIdentifier(){return Ce}execute(n,e,t,i){return super.execute(n,e,t,i)}}const Ve=Symbol("VisibilityChangedAction");class X extends y{constructor(n){super(n)}static get classIdentifier(){return Ve}execute(n,e,t,i){return super.execute(n,e,t,i)}}class V{constructor(){h(this,"validatingCount",0);h(this,"_valid",!0);h(this,"errors",[]);h(this,"actions",new F);h(this,"_visibility",I.FULL);h(this,"_enabled",!0);return c.reactive(this)}get validating(){return this.validatingCount>0}beginValidating(){this.validatingCount++}endValidating(){this.validatingCount=Math.max(0,this.validatingCount-1)}get visibility(){return this._visibility}set visibility(n){const e=this._visibility,t=this.actions.trigger(G,this,n,e);if(!I.isDefined(t!=null?t:n))throw new Error("visibility must be a DisplayMode constant");this._visibility=I.fromAny(t!=null?t:n),this.actions.trigger(X,this,this._visibility,e)}get enabled(){return this._enabled}set enabled(n){const e=this._enabled,t=this.actions.trigger(Q,this,n,e);if(!u.isBoolean(t!=null?t:n))throw new Error("Enabled value must be boolean");this._enabled=t!=null?t:n,this.actions.trigger(z,this,this._enabled,e)}validate(n=!1){n&&this.actions.triggerEager(this,this.value,this.value);const e=this._valid;this._valid=this.valid,this._valid!==e&&this.actions.trigger(W,this,this.valid,e)}get valid(){return this.errors.length===0}get fullValue(){return this.value}get isChanged(){return!u.isEqual(this.value,this.originalValue)}registerAction(n){return this.actions.register(n),n.boundToField(this),n.eager&&this.actions.trigger(Object.getPrototypeOf(n).constructor,this,this.value,this.originalValue),this}triggerAction(n,...e){return this.actions.trigger(n,this,...e)}clearValidators(){this.actions=this.actions.cloneWithoutValidators(),this.errors=[],this._valid=!0}}function _e(s,n){return s?!n:n}class w{constructor(n,e,t){h(this,"operand1");h(this,"operator");h(this,"operand2");this.operand1=n,this.operator=e,this.operand2=t}get operand1Value(){return this.operand1 instanceof w?this.operand1.evaluate():this.operand1 instanceof V?c.unref(this.operand1.value):this.operand1}get operand2Value(){return this.operand2 instanceof w?this.operand2.evaluate():this.operand2 instanceof V?c.unref(this.operand2.value):this.operand2}evaluate(){var t,i,r,a;const n=this.operand1Value,e=this.operand2Value;switch(this.operator){case p.AND:return n&&e;case p.OR:return n||e;case p.NAND:return!(n&&e);case p.NOR:return!(n||e);case p.XOR:return _e(n,e);case p.NOT:return!n;case p.EQUALS:return n==e;case p.NOT_EQUALS:return n!=e;case p.LT:return n<e;case p.LE:return n<=e;case p.GE:return n>=e;case p.GT:return n>e;case p.IN:return(i=(t=e==null?void 0:e.includes)==null?void 0:t.call(e,n))!=null?i:!1;case p.NOT_IN:return!((a=(r=e==null?void 0:e.includes)==null?void 0:r.call(e,n))==null||a);case p.INCLUDES:return u.isString(n)&&u.isString(e)&&n.indexOf(e)>=0;case p.NOT_INCLUDES:return!(u.isString(n)&&u.isString(e)&&n.indexOf(e)>=0);default:throw new Error(`Operator not implemented ${this.operator}`)}}collectFields(){const n=new Set;function e(t){t instanceof V?n.add(t):t instanceof w&&t.collectFields().forEach(r=>n.add(r))}return e(this.operand1),e(this.operand2),n}}const Ee=Symbol("ExecuteAction");class Y extends y{constructor(n){super(n)}static get classIdentifier(){return Ee}execute(n,e,t){return super.execute(n,e,t)}}const Se=Symbol("ListItemAddedAction");class B extends y{constructor(n){super(n)}static get classIdentifier(){return Se}execute(n,e,t,i){return super.execute(n,e,t,i)}}const Ie=Symbol("ListItemRemovedAction");class J extends y{constructor(n){super(n)}static get classIdentifier(){return Ie}execute(n,e,t,i){return super.execute(n,e,t,i)}}class L extends V{constructor(e){super();h(this,"_value");h(this,"_touched",!1);this.init(e)}init(e){if(e){const t=e,{value:i,validators:r,actions:a}=t,o=P(t,["value","validators","actions"]);[...r||[],...a||[]].forEach(d=>this.registerAction(d)),Object.assign(this,o),this._value=i!=null?i:this.originalValue,this.originalValue===void 0&&(this.originalValue=this._value)}this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}get value(){return this._value}set value(e){const t=this._value;!this.enabled||t===e||(this._value=e,this.actions.trigger(A,this,this._value,t),this.parent&&this.parent.notifyValueChanged(),this.validate())}get touched(){return this._touched}set touched(e){this._touched=e}clone(e){var r,a,o;const t=this.constructor,i=new t(H(E({value:(r=e==null?void 0:e.value)!=null?r:this.value},e&&"originalValue"in e?{originalValue:e.originalValue}:{}),{enabled:(a=e==null?void 0:e.enabled)!=null?a:this.enabled,visibility:(o=e==null?void 0:e.visibility)!=null?o:this.visibility}));return i.actions=this.actions.clone(),i.actions.triggerEager(i,i.value,i.originalValue),i}}const ce=new L({value:"EmptyField"}).registerAction(new A(()=>{console.warn("Working with EmptyField! This should not happen")}));function K(s,n){return(s==null?void 0:s.label)==null&&(s==null?void 0:s.icon)==null?n:s}class ue extends L{init(n){if(this._value={label:void 0,icon:void 0},n){const e=n,{value:t,originalValue:i,validators:r,actions:a}=e,o=P(e,["value","originalValue","validators","actions"]);[...r||[],...a||[]].forEach(f=>this.registerAction(f)),Object.assign(this,o);const d=K(t,this._value),g=Object.freeze({label:i==null?void 0:i.label,icon:i==null?void 0:i.icon});this._value=K(d,E({},g)),this.originalValue=K(g,d)}this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}get icon(){return this.value.icon}set icon(n){this.value.icon=n}get label(){return this.value.label}set label(n){this.value.label=n}execute(n){this.actions.trigger(Y,this,n)}}const he=c.defineComponent({__name:"messages-widget",props:{message:{},classes:{}},setup(s){const n=s,e=c.resolveComponent("vue-markdown"),t=new Set(["div","span","p","h1","h2","h3","h4","h5","h6","section","article","aside","nav","header","footer","main","figure","figcaption","blockquote","pre","code","em","strong","small","mark","del","ins","sub","sup","i","b","u","s","a","img","button","input","textarea","select","option","label","form","table","tr","td","th","thead","tbody","tfoot","ul","ol","li","dl","dt","dd"]),i=()=>{if(typeof n.message=="string")return c.h("span",{class:n.classes},n.message);const r=[];return n.message.forEach(a=>{switch(a.componentName){case"template":r.push(c.h("div",{class:[n.classes,a.extraClasses]},a.componentBody));break;case"vue-markdown":if(typeof e=="string")console.warn("You are using markdown for messages-widget, but you haven't registered a vue-markdown component"),r.push(c.h("div",{class:[n.classes,a.extraClasses]},a.componentBindings.source));else{const o=a.componentBindings;r.push(c.h(e,{class:[n.classes,a.extraClasses,"df-messages-widget-markdown"],source:o.source,options:o.options,plugins:o.plugins}))}break;default:r.push(c.h(t.has(a.componentName.toLowerCase())?a.componentName:c.resolveComponent(a.componentName),E(E({class:[n.classes,a.extraClasses]},a.componentBindings),a.componentBody?{innerHTML:a.componentBody}:{})));break}}),r};return(r,a)=>(c.openBlock(),c.createBlock(i))}});class _ extends V{constructor(e,t){super();h(this,"_fields");h(this,"_value",null);h(this,"suppressNotifyValueChanged",!1);if(!_.isValidFields(e))throw new Error("Invalid fields object provided");if(this._fields=Object.create(null),Object.entries(e).forEach(([r,a])=>this.addField(r,a)),t){const i=t,{value:r,validators:a,actions:o}=i,d=P(i,["value","validators","actions"]);[...a||[],...o||[]].forEach(g=>this.registerAction(g)),Object.assign(this,d),this.value=r!=null?r:this.originalValue}this.originalValue===void 0&&(this.originalValue=this.value),this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}addField(e,t){if(Object.hasOwn(this._fields,e))throw new Error(`Field ${e} is already in this form`);Object.defineProperty(t,"parent",{get:()=>this,configurable:!1,enumerable:!1}),Object.defineProperty(t,"fieldName",{get:()=>e,configurable:!1,enumerable:!1}),Object.defineProperty(this._fields,e,{get:()=>t,configurable:!1,enumerable:!0})}static isValidFields(e){function t(i){return i instanceof V}return typeof e=="object"&&e!==null&&Object.entries(e).every(([,i])=>t(i))}static createFromFormData(e){if(e instanceof V)throw new Error("data is already a Form structure, should be a simple object");return new _(e==null?{}:Object.fromEntries(Object.entries(e).map(([t,i])=>[t,new L({value:i})])))}field(e){var t;return(t=this._fields[e])!=null?t:null}get fields(){return this._fields}get value(){const e=Object.create(null);return Object.entries(this._fields).forEach(([t,i])=>{const r=i.value;(i.enabled||i instanceof _&&!u.isEmpty(r))&&(e[t]=r)}),u.isEmpty(e)?null:E({},e)}set value(e){this.suppressNotifyValueChanged=!0;try{Object.entries(this._fields).forEach(([t,i])=>{(e==null||Object.hasOwn(e,t))&&(i.value=e==null?null:e[t])})}finally{this.suppressNotifyValueChanged=!1}this.notifyValueChanged(),this.validate()}get touched(){return Object.values(this._fields).some(e=>e.touched)}set touched(e){Object.values(this._fields).forEach(t=>{t.touched=e})}get fullValue(){const e=Object.create(null);return Object.entries(this._fields).forEach(([t,i])=>{e[t]=i.fullValue}),E({},e)}notifyValueChanged(){if(this.suppressNotifyValueChanged)return;const e=this.value;if(!u.isEqual(e,this._value)){const t=this._value;this._value=e,this.actions.trigger(A,this,e,t),this.parent&&this.parent.notifyValueChanged(),this.validate()}}get valid(){return super.valid&&Object.values(this._fields).every(e=>e.valid)}validate(e=!1){e&&Object.values(this._fields).forEach(t=>t.validate(!0)),super.validate(e)}clone(e){var r,a,o;const t=Object.create(null);Object.entries(this._fields).forEach(([d,g])=>{t[d]=g.clone()});const i=new _(t,H(E({value:(r=e==null?void 0:e.value)!=null?r:this.value},e&&"originalValue"in e?{originalValue:e.originalValue}:{}),{enabled:(a=e==null?void 0:e.enabled)!=null?a:this.enabled,visibility:(o=e==null?void 0:e.visibility)!=null?o:this.visibility}));return i.actions=this.actions.clone(),i.actions.triggerEager(i,i.value,i.originalValue),i}}class D extends V{constructor(e,t){super();h(this,"_value",null);h(this,"_itemTemplate");h(this,"_previousValue");if(this._itemTemplate=e,t){const i=t,{value:r,validators:a,actions:o}=i,d=P(i,["value","validators","actions"]);[...a||[],...o||[]].forEach(g=>this.registerAction(g)),Object.assign(this,d),r&&this.setValueInternal(r)}this.originalValue===void 0&&(this.originalValue=this.value),this._previousValue=this.value,this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}processSetValueItem(e){let t;return e instanceof _?t=e:this._itemTemplate?t=this._itemTemplate.clone({value:e}):t=_.createFromFormData(e),Object.defineProperty(t,"parent",{get:()=>this,configurable:!1,enumerable:!1}),t}setValueInternal(e){Array.isArray(e)&&(this._value=e.map(t=>this.processSetValueItem(t)))}get value(){var t;const e=(t=this._value)==null?void 0:t.map(i=>i.value);return u.isEmpty(e)?null:e}set value(e){const t=this.value;this.setValueInternal(e),this.actions.trigger(A,this,this.value,t),this.parent&&this.parent.notifyValueChanged(),this.validate()}get touched(){var e;return((e=this._value)==null?void 0:e.some(t=>t.touched))||!1}set touched(e){var t;(t=this._value)==null||t.forEach(i=>{i.touched=e})}clone(e){var i,r,a,o,d;const t=new D((i=this._itemTemplate)==null?void 0:i.clone(),H(E({value:[...(a=(r=e==null?void 0:e.value)!=null?r:this.value)!=null?a:[]]},e&&"originalValue"in e?{originalValue:e.originalValue}:{}),{enabled:(o=e==null?void 0:e.enabled)!=null?o:this.enabled,visibility:(d=e==null?void 0:e.visibility)!=null?d:this.visibility}));return t.actions=this.actions.clone(),t.actions.triggerEager(t,t.value,t.originalValue),t}notifyValueChanged(){const e=this.value;if(!u.isEqual(e,this._previousValue)){const t=this._previousValue;this._previousValue=e,this.actions.trigger(A,this,e,t),this.parent&&this.parent.notifyValueChanged(),this.validate()}}get valid(){var e,t;return super.valid&&((t=(e=this._value)==null?void 0:e.every(i=>i.valid))!=null?t:!0)}validate(e=!1){var t;e&&((t=this._value)==null||t.forEach(i=>i.validate(!0))),super.validate(e)}get(e){return this._value!=null?this._value[e]:void 0}push(e){var t,i;return this.insert(e,(i=(t=this._value)==null?void 0:t.length)!=null?i:0)+1}pop(){var e,t;return this.remove(((t=(e=this._value)==null?void 0:e.length)!=null?t:0)-1)}remove(e){var i;if(this._value==null||e<0||this._value.length<=e)return;let t=(i=this._value.splice(e,1))==null?void 0:i[0];return t&&(t=t.clone(),this.actions.trigger(J,this,t,e),this.notifyValueChanged()),t}insert(e,t){for(this._value==null&&(this._value=[]);this._value.length<t;){const r=this.processSetValueItem(null),a=this._value.push(r);this.actions.trigger(B,this,r,a)}const i=this.processSetValueItem(e);return this._value.splice(t,0,i),this.actions.trigger(B,this,i,t),this.notifyValueChanged(),t}clear(){this._value=null,this.notifyValueChanged()}}const de={useMarkdownInValidators:!0};function xe(){return de}function Fe(s){Object.assign(de,s)}const we={install(s,n){n&&Fe(n)}};function C(s){return xe().useMarkdownInValidators?new x(s):s.replace(/[*_~`]/g,"").replace(/!\[(.*?)\]\(.*?\)/g,"$1").replace(/\[(.*?)\]\((.*?)\)/g,"$1").replace(/#+\s?/g,"").replace(/>\s?/g,"").replace(/(\*|-|\d+\.)\s+/g,"").replace(/`{3}[\s\S]*?`{3}/g,"").replace(/`([^`]+)`/g,"$1").replace(/\n{2,}/g,`
|
|
2
|
-
`)}class je extends m{constructor(e,t,i){let r=!1,a,o;super((g,f,O)=>(a=g,o=f,r||(r=!0,this.otherField.registerAction(new A((S,q,M,ee)=>{q(S,M,ee),this.unregistered||this.execute(O,()=>null,a,o)}))),this.isValidComparison(c.unref(g),c.unref(this.otherField.value))?null:[new v(this.replacePlaceholders(i,{newValue:g,oldValue:f,field:O,otherField:this.otherField}))]));h(this,"otherField");h(this,"isValidComparison");h(this,"unregistered",!1);this.otherField=e,this.isValidComparison=t}unregister(){this.unregistered=!0}}class Te extends m{constructor(n,e){const t=e||C("Must be one of [**{allowedAsText}**]");let i=n.join(", ");i.length>60&&(i=u.truncate(i,{length:40,separator:", ",omission:`... (${n.length} items total)`}));const r=(a,o,d)=>n.includes(c.unref(a))?null:[new v(this.replacePlaceholders(t,{newValue:a,oldValue:o,field:d,allowedValues:n,allowedAsText:i}))];super(r)}}function Ne(s){return s==null?0:u.isArray(s)||u.isString(s)?s.length:u.isObject(s)&&Object.getPrototypeOf(s)===Object.prototype?Object.keys(s).length:String(s).length}class Le extends m{constructor(n){const e=n||C("Please enter a value"),t=(i,r,a)=>Ne(c.unref(i))===0?[new v(this.replacePlaceholders(e,{newValue:i,oldValue:r,field:a}))]:null;super(t)}}class Oe extends m{constructor(n,e){const t=e||C("Value must be larger or equal to **{minValue}**"),i=(r,a,o)=>r<n||r===void 0?[new v(this.replacePlaceholders(t,{newValue:r,oldValue:a,field:o,minValue:n}))]:null;super(i)}}class Pe extends m{constructor(n,e){const t=e||C("Value must be less than or equal to **{maxValue}**"),i=(r,a,o)=>r>n||r===void 0?[new v(this.replacePlaceholders(t,{newValue:r,oldValue:a,field:o,maxValue:n}))]:null;super(i)}}class Re extends m{constructor(n,e,t){const i=t||C("Value must be between **{minValue}** and **{maxValue}**"),r=(a,o,d)=>a<n||a>e||a===void 0?[new v(this.replacePlaceholders(i,{newValue:a,oldValue:o,field:d,minValue:n,maxValue:e}))]:null;super(r)}}function Z(s){return s==null?0:u.isArray(s)||u.isString(s)?s.length:u.isObject(s)&&Object.getPrototypeOf(s)===Object.prototype?Object.keys(s).length:String(s).length}class Ue extends m{constructor(n,e){const t=e||C("Length must be larger or equal to **{minLength}**"),i=(r,a,o)=>Z(r)<n?[new v(this.replacePlaceholders(t,{newValue:r,oldValue:a,field:o,minLength:n}))]:null;super(i)}}class ke extends m{constructor(n,e){const t=e||C("Length must be less than or equal to **{maxLength}**"),i=(r,a,o)=>Z(r)>n?[new v(this.replacePlaceholders(t,{newValue:r,oldValue:a,field:o,maxLength:n}))]:null;super(i)}}class Be extends m{constructor(n,e,t){const i=t||C("Length must be between **{minLength}** and **{maxLength}**"),r=(a,o,d)=>{const g=Z(a);return g<n||g>e?[new v(this.replacePlaceholders(i,{newValue:a,oldValue:o,field:d,minLength:n,maxLength:e}))]:null};super(r)}}class De extends m{constructor(n,e){const t=e||C('Value must match pattern "**{pattern}**"'),i=(r,a,o)=>n.test(String(c.unref(r)))?null:[new v(this.replacePlaceholders(t,{newValue:r,oldValue:a,field:o,pattern:n}))];super(i)}}const ge=Object.freeze(Object.defineProperty({__proto__:null,CompareTo:je,InAllowedValues:Te,LengthInRange:Be,MaxLength:ke,MaxValue:Pe,MinLength:Ue,MinValue:Oe,Pattern:De,Required:Le,Validator:m,ValueInRange:Re},Symbol.toStringTag,{value:"Module"})),qe=Object.freeze(Object.defineProperty({__proto__:null,AbortEventHandlingException:R,Action:ue,ActionsMap:F,ConditionalEnabledAction:le,ConditionalStatementAction:T,ConditionalValueAction:oe,ConditionalVisibilityAction:ae,DisplayMode:I,EmptyField:ce,EnabledChangedAction:z,EnabledChangingAction:Q,ExecuteAction:Y,Field:L,FieldActionBase:y,FieldBase:V,Group:_,List:D,ListItemAddedAction:B,ListItemRemovedAction:J,MdString:x,MessagesWidget:he,Operator:p,RenderableValue:re,Statement:w,ValidChangedAction:W,ValidationError:k,ValidationErrorRenderContent:v,ValidationErrorText:se,Validator:m,Validators:ge,ValueChangedAction:A,VisibilityChangedAction:X,VisibilityChangingAction:G,buildErrorMessage:C,isCallableFunction:j,isSimpleComponentDef:U},Symbol.toStringTag,{value:"Module"}));l.AbortEventHandlingException=R,l.Action=ue,l.ActionsMap=F,l.ConditionalEnabledAction=le,l.ConditionalStatementAction=T,l.ConditionalValueAction=oe,l.ConditionalVisibilityAction=ae,l.DisplayMode=I,l.EmptyField=ce,l.EnabledChangedAction=z,l.EnabledChangingAction=Q,l.ExecuteAction=Y,l.Field=L,l.FieldActionBase=y,l.FieldBase=V,l.Group=_,l.List=D,l.ListItemAddedAction=B,l.ListItemRemovedAction=J,l.MdString=x,l.MessagesWidget=he,l.Operator=p,l.RenderableValue=re,l.Statement=w,l.ValidChangedAction=W,l.ValidationError=k,l.ValidationErrorRenderContent=v,l.ValidationErrorText=se,l.Validator=m,l.Validators=ge,l.ValueChangedAction=A,l.VisibilityChangedAction=X,l.VisibilityChangingAction=G,l.buildErrorMessage=C,l.default=qe,l.forms=we,l.isCallableFunction=j,l.isSimpleComponentDef=U,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1
|
+
(function(l,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","lodash","vue"],c):(l=typeof globalThis!="undefined"?globalThis:l||self,c(l.DynamicFormsVueForms={},l._,l.Vue))})(this,(function(l,c,o){"use strict";var Gt=Object.defineProperty,Xt=Object.defineProperties;var Yt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var vt=Object.prototype.hasOwnProperty,yt=Object.prototype.propertyIsEnumerable;var it=(l,c,o)=>c in l?Gt(l,c,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[c]=o,A=(l,c)=>{for(var o in c||(c={}))vt.call(c,o)&&it(l,o,c[o]);if(W)for(var o of W(c))yt.call(c,o)&&it(l,o,c[o]);return l},U=(l,c)=>Xt(l,Yt(c));var k=(l,c)=>{var o={};for(var f in l)vt.call(l,f)&&c.indexOf(f)<0&&(o[f]=l[f]);if(l!=null&&W)for(var f of W(l))c.indexOf(f)<0&&yt.call(l,f)&&(o[f]=l[f]);return o};var h=(l,c,o)=>it(l,typeof c!="symbol"?c+"":c,o);var f=(s=>(s[s.SUPPRESS=1]="SUPPRESS",s[s.HIDDEN=5]="HIDDEN",s[s.INVISIBLE=8]="INVISIBLE",s[s.FULL=10]="FULL",s))(f||{});const nt=10;(s=>{function n(i){return i.toUpperCase()==="SUPPRESS"?1:i.toUpperCase()==="HIDDEN"?5:i.toUpperCase()==="INVISIBLE"?8:nt}s.fromString=n;function t(i){const r=typeof i=="number"?i:s.fromString(i);return Object.values(s).includes(r)?r:nt}s.fromAny=t;function e(i){const r=typeof i=="number"?i:s.fromString(i);return Object.values(s).includes(r)}s.isDefined=e})(f||(f={})),Object.freeze(f);const I=f;class v{constructor(n){h(this,"executorFn");this.executorFn=n}static get classIdentifier(){throw new Error("classIdentifier must be declared")}get classIdentifier(){return this.constructor.classIdentifier}execute(n,t,...e){return this.executorFn(n,t,...e)}get eager(){return!1}boundToField(n){}unregister(){}}class M extends Error{}const st=Symbol("ValueChangedAction");class V extends v{constructor(n){super(n)}static get classIdentifier(){return st}execute(n,t,e,i){return super.execute(n,t,e,i)}}const rt={useMarkdownInValidators:!0};function Vt(){return rt}function Ct(s){Object.assign(rt,s)}const _t={install(s,n){n&&Ct(n)}};class x extends String{constructor(t,e,i){super(t);h(this,"plugins");h(this,"options");this.plugins=i,this.options=e}}function D(s){const n=o.unref(s);return typeof n=="object"&&"componentName"in n}function N(s){return typeof o.unref(s)=="function"}class q{get componentName(){return"Comment"}get componentBindings(){return{}}get componentBody(){return""}get extraClasses(){return""}}class at extends q{constructor(t,e=""){super();h(this,"text");h(this,"classes");this.text=t,this.classes=e}get componentName(){return"template"}get componentBody(){return this.text}get extraClasses(){return this.classes}}class m extends q{constructor(t,e=""){super();h(this,"classes");h(this,"text");h(this,"textType");this.classes=e,this.text=t,this.textType=o.computed(()=>this.getTextType)}get resolvedText(){const t=o.unref(this.text);return N(t)?t():t}get getTextType(){const t=this.resolvedText;return t?t instanceof x?"md":D(t)?"component":"string":"string"}get componentName(){switch(o.unref(this.textType)){case"string":return"template";case"md":return"vue-markdown";case"component":return this.resolvedText.componentName;default:return"template"}}get componentBindings(){switch(o.unref(this.textType)){case"string":return{};case"md":{const t=this.resolvedText;return{source:t.toString(),options:t.options,plugins:t.plugins}}case"component":return this.resolvedText.componentProps||{};default:return{}}}get componentBody(){switch(o.unref(this.textType)){case"string":return this.resolvedText;case"component":return this.resolvedText.componentVHtml||"";default:return""}}get extraClasses(){return this.classes}}class lt extends m{}function y(s){return Vt().useMarkdownInValidators?new x(s):s.replace(/[*_~`]/g,"").replace(/!\[(.*?)\]\(.*?\)/g,"$1").replace(/\[(.*?)\]\((.*?)\)/g,"$1").replace(/#+\s?/g,"").replace(/>\s?/g,"").replace(/(\*|-|\d+\.)\s+/g,"").replace(/`{3}[\s\S]*?`{3}/g,"").replace(/`([^`]+)`/g,"$1").replace(/\n{2,}/g,`
|
|
2
|
+
`)}const At=Symbol("Validator"),Et=()=>y("Validation could not be completed");class b extends V{constructor(t){super((i,r,a,u)=>{var Q;const d=((Q=this.runs.get(i))!=null?Q:0)+1;this.runs.set(i,d);const p=i.validationEpoch,S=()=>this.runs.get(i)===d&&i.validationEpoch===p,w=t(a,u,i)||[],B=C=>{var pt;const j=(pt=C==null?void 0:C.map(T=>this.claim(T)))!=null?pt:[];for(let T=i.errors.length-1;T>=0;T--){const mt=i.errors[T];if(mt.source===this.source){const bt=j.findIndex(zt=>c.isEqual(zt,mt));bt>=0?j.splice(bt,1):i.errors.splice(T,1)}}j.length>0&&i.errors.push(...j),i.validate()};return w instanceof Promise?(i.beginValidating(),w.then(C=>{S()&&B(C)},C=>{S()&&(B([new m(Et())]),console.error("Validation failed",C))}).finally(()=>i.endValidating()).catch(C=>console.error("Validation failed",C))):B(w),r(i,a,u)});h(this,"source");h(this,"runs",new WeakMap);this.source=Symbol(this.constructor.name)}claim(t){const e=t.source;if(e===this.source)return t;const i={value:this.source,enumerable:!1,configurable:!1};if(e===void 0)return Object.defineProperty(t,"source",i),t;const r=Object.getOwnPropertyDescriptors(t);return Object.create(Object.getPrototypeOf(t),U(A({},r),{source:i}))}static get classIdentifier(){return At}get eager(){return!0}replacePlaceholdersFunction(t,e){return()=>{let i=o.unref(t);for(;N(i);)i=o.unref(this.replacePlaceholders(i(),e));return i}}replacePlaceholders(t,e){if(N(t))return this.replacePlaceholdersFunction(t,e);if(D(t))return t;if(o.isRef(t))return this.replacePlaceholdersFunction(()=>o.unref(t),e);let i=o.unref(t);return Object.keys(e).forEach(r=>{i=i.replaceAll(`{${r}}`,e[r])}),t instanceof x?new x(i.toString(),t.options,t.plugins):i}}class P extends Map{constructor(){super(...arguments);h(this,"eagerActions",new Set);h(this,"registeredActions",[])}register(t){if(!(t instanceof v))throw new Error("Invalid action type");this.registeredActions.push(t);const e=t.classIdentifier,i=this.get(e)||(()=>null);function r(a,...u){return t.execute(a,i,...u)}this.set(e,r),t.eager&&this.eagerActions.add(t.classIdentifier)}trigger(t,e,...i){const r=t.classIdentifier;r===st&&this.triggerEager(e,...i);const a=this.get(r);try{if(a)return a(e,...i)}catch(u){if(!(u instanceof M))throw u}return null}triggerEager(t,...e){for(const i of this.eagerActions){const r=this.get(i);try{r&&r(t,...e)}catch(a){if(!(a instanceof M))throw a}}}clone(){const t=new P;return this.registeredActions.forEach(e=>t.register(e)),t}cloneWithoutValidators(){const t=new P;return this.registeredActions.forEach(e=>{e instanceof b?e.unregister():t.register(e)}),t}}const It=Symbol("ConditionalStatementAction");class O extends V{constructor(t,e){const i=(r,a,u,d)=>{const p=t.evaluate();if(p!==this.lastResult){for(const S of this.boundFields)e(S,p,this.lastResult);this.lastResult=p}return a(r,u,d)};super(i);h(this,"lastResult");h(this,"boundFields",new Set);t.collectFields().forEach(r=>r.registerAction(new V(i)))}static get classIdentifier(){return It}get eager(){return!0}boundToField(t){this.boundFields.add(t)}}class ot extends O{constructor(n){super(n,(t,e)=>{t.visibility=e?I.FULL:I.SUPPRESS})}}class ut extends O{constructor(n){super(n,(t,e)=>{t.enabled=e})}}class ct extends O{constructor(n,t){super(n,(e,i)=>{i&&(e.value=t)})}}var L=(s=>(s[s.NOT=0]="NOT",s[s.OR=1]="OR",s[s.AND=2]="AND",s[s.XOR=3]="XOR",s[s.NAND=4]="NAND",s[s.NOR=5]="NOR",s[s.EQUALS=-1]="EQUALS",s[s.NOT_EQUALS=-2]="NOT_EQUALS",s[s.GT=-3]="GT",s[s.LT=-4]="LT",s[s.GE=-5]="GE",s[s.LE=-6]="LE",s[s.IN=-7]="IN",s[s.NOT_IN=-8]="NOT_IN",s[s.INCLUDES=-9]="INCLUDES",s[s.NOT_INCLUDES=-10]="NOT_INCLUDES",s))(L||{});(s=>{function n(r){const a=r.toLowerCase();if(a==="not")return 0;if(a==="or")return 1;if(a==="and")return 2;if(a==="xor")return 3;if(a==="nand")return 4;if(a==="nor")return 5;if(a==="equals")return-1;if(["not_equals","not-equals","not equals"].includes(a))return-2;if(a==="gt")return-3;if(a==="lt")return-4;if(a==="ge")return-5;if(a==="le")return-6;if(a==="in")return-7;if(["not_in","not-in","not in"].includes(a))return-8;if(a==="includes")return-9;if(["not_includes","not-includes","not includes"].includes(a))return-10;throw new Error(`Unrecognised operator ${a}`)}s.fromString=n;function t(r){const a=typeof r=="number"?r:s.fromString(r);if(Object.values(s).includes(a))return a;throw new Error(`Unrecognised operator ${r}`)}s.fromAny=t;function e(r){const a=typeof r=="number"?r:s.fromString(r);return Object.values(s).includes(a)}s.isDefined=e;function i(r){return r>=0}s.isLogicOperator=i})(L||(L={})),Object.freeze(L);const g=L,St=Symbol("EnabledChangingAction");class z extends v{constructor(n){super(n)}static get classIdentifier(){return St}execute(n,t,e,i){return super.execute(n,t,e,i)}}const xt=Symbol("EnabledChangedAction");class G extends v{constructor(n){super(n)}static get classIdentifier(){return xt}execute(n,t,e,i){return super.execute(n,t,e,i)}}const Pt=Symbol("ValidChangedAction");class X extends v{constructor(n){super(n)}static get classIdentifier(){return Pt}execute(n,t,e,i){return super.execute(n,t,e,i)}}const Ft=Symbol("VisibilityChangingAction");class Y extends v{constructor(n){super(n)}static get classIdentifier(){return Ft}execute(n,t,e,i){return super.execute(n,t,e,i)}}const wt=Symbol("VisibilityChangedAction");class J extends v{constructor(n){super(n)}static get classIdentifier(){return wt}execute(n,t,e,i){return super.execute(n,t,e,i)}}class _{constructor(){h(this,"validatingCount",0);h(this,"_valid",!0);h(this,"errors",[]);h(this,"actions",new P);h(this,"_visibility",I.FULL);h(this,"_enabled",!0);h(this,"suppressValidation",!1);h(this,"suppressParentValidityClimb",!1);h(this,"parentValidityClimbPending",!1);h(this,"_validationEpoch",0);return o.reactive(this)}get validating(){return this.validatingCount>0}beginValidating(){this.validatingCount++}endValidating(){this.validatingCount=Math.max(0,this.validatingCount-1)}get visibility(){return this._visibility}set visibility(n){const t=this._visibility,e=this.actions.trigger(Y,this,n,t);if(!I.isDefined(e!=null?e:n))throw new Error("visibility must be a DisplayMode constant");this._visibility=I.fromAny(e!=null?e:n),this.actions.trigger(J,this,this._visibility,t)}get enabled(){return this._enabled}set enabled(n){const t=this._enabled,e=this.actions.trigger(z,this,n,t);if(!c.isBoolean(e!=null?e:n))throw new Error("Enabled value must be boolean");this._enabled=e!=null?e:n,this.actions.trigger(G,this,this._enabled,t)}flushParentValidityClimb(){var n;this.parentValidityClimbPending&&(this.parentValidityClimbPending=!1,(n=this.parent)==null||n.validate())}validate(n=!1){var e;if(this.suppressValidation)return;n&&this.actions.triggerEager(this,this.value,this.value);const t=this._valid;this._valid=this.valid,this._valid!==t&&(this.actions.trigger(X,this,this.valid,t),this.suppressParentValidityClimb?this.parentValidityClimbPending=!0:(e=this.parent)==null||e.validate())}get valid(){return this.errors.length===0}get fullValue(){return this.value}get isChanged(){return!c.isEqual(this.value,this.originalValue)}registerInitialActions(n){n.forEach(t=>{this.actions.register(t),t.boundToField(this)})}registerAction(n){return this.actions.register(n),n.boundToField(this),n.eager&&this.actions.trigger(Object.getPrototypeOf(n).constructor,this,this.value,this.originalValue),this}triggerAction(n,...t){return this.actions.trigger(n,this,...t)}get validationEpoch(){return this._validationEpoch}clearValidators(){this._validationEpoch++,this.actions=this.actions.cloneWithoutValidators(),this.errors=[],this.validate()}}function jt(s,n){return s?!n:n}class F{constructor(n,t,e){h(this,"operand1");h(this,"operator");h(this,"operand2");this.operand1=n,this.operator=t,this.operand2=e}get operand1Value(){return this.operand1 instanceof F?this.operand1.evaluate():this.operand1 instanceof _?o.unref(this.operand1.value):this.operand1}get operand2Value(){return this.operand2 instanceof F?this.operand2.evaluate():this.operand2 instanceof _?o.unref(this.operand2.value):this.operand2}evaluate(){var e,i;const n=this.operand1Value,t=this.operand2Value;switch(this.operator){case g.AND:return!!(n&&t);case g.OR:return!!(n||t);case g.NAND:return!(n&&t);case g.NOR:return!(n||t);case g.XOR:return jt(!!n,!!t);case g.NOT:return!n;case g.EQUALS:return n==t;case g.NOT_EQUALS:return n!=t;case g.LT:return n<t;case g.LE:return n<=t;case g.GE:return n>=t;case g.GT:return n>t;case g.IN:return!!((e=t==null?void 0:t.includes)!=null&&e.call(t,n));case g.NOT_IN:return!((i=t==null?void 0:t.includes)!=null&&i.call(t,n));case g.INCLUDES:return c.isString(n)&&c.isString(t)&&n.indexOf(t)>=0;case g.NOT_INCLUDES:return!(c.isString(n)&&c.isString(t)&&n.indexOf(t)>=0);default:throw new Error(`Operator not implemented ${this.operator}`)}}collectFields(){const n=new Set;function t(e){e instanceof _?n.add(e):e instanceof F&&e.collectFields().forEach(r=>n.add(r))}return t(this.operand1),t(this.operand2),n}}const Tt=Symbol("ExecuteAction");class K extends v{constructor(n){super(n)}static get classIdentifier(){return Tt}execute(n,t,e){return super.execute(n,t,e)}}const Nt=Symbol("ListItemAddedAction");class $ extends v{constructor(n){super(n)}static get classIdentifier(){return Nt}execute(n,t,e,i){return super.execute(n,t,e,i)}}const Ot=Symbol("ListItemRemovedAction");class Z extends v{constructor(n){super(n)}static get classIdentifier(){return Ot}execute(n,t,e,i){return super.execute(n,t,e,i)}}class R extends _{constructor(t){super();h(this,"_value");h(this,"_touched",!1);this.init(t)}init(t){if(t){const e=t,{value:i,validators:r,actions:a}=e,u=k(e,["value","validators","actions"]);this.registerInitialActions([...r||[],...a||[]]),Object.assign(this,u),this._value=i!==void 0?i:this.originalValue,this.originalValue===void 0&&(this.originalValue=this._value)}this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}get value(){return this._value}set value(t){const e=this._value;if(!this.enabled||e===t)return;this._value=t;const i=this.suppressParentValidityClimb;this.suppressParentValidityClimb=!0;try{this.actions.trigger(V,this,this._value,e),this.parent&&this.parent.notifyValueChanged()}finally{this.suppressParentValidityClimb=i,this.validate(),this.flushParentValidityClimb()}}get touched(){return this._touched}set touched(t){this._touched=t}clone(t){var r,a;const e=this.constructor,i=new e(U(A({value:(t==null?void 0:t.value)!==void 0?t.value:this.value},t&&"originalValue"in t?{originalValue:t.originalValue}:{}),{enabled:(r=t==null?void 0:t.enabled)!=null?r:this.enabled,visibility:(a=t==null?void 0:t.visibility)!=null?a:this.visibility}));return i.actions=this.actions.clone(),i.actions.triggerEager(i,i.value,i.originalValue),i}}const ht=new R({value:"EmptyField"}).registerAction(new V(()=>{console.warn("Working with EmptyField! This should not happen")}));function tt(s,n){return(s==null?void 0:s.label)==null&&(s==null?void 0:s.icon)==null?n:s}class dt extends R{init(n){if(this._value={label:void 0,icon:void 0},n){const t=n,{value:e,originalValue:i,validators:r,actions:a}=t,u=k(t,["value","originalValue","validators","actions"]);this.registerInitialActions([...r||[],...a||[]]),Object.assign(this,u);const d=tt(e,this._value),p=Object.freeze({label:i==null?void 0:i.label,icon:i==null?void 0:i.icon});this._value=tt(d,A({},p)),this.originalValue=tt(p,d)}this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}get icon(){return this.value.icon}set icon(n){this.value.icon=n}get label(){return this.value.label}set label(n){this.value.label=n}execute(n){this.actions.trigger(K,this,n)}}const gt=o.defineComponent({__name:"messages-widget",props:{message:{},classes:{}},setup(s){const n=s,t=o.resolveComponent("vue-markdown"),e=new Set(["div","span","p","h1","h2","h3","h4","h5","h6","section","article","aside","nav","header","footer","main","figure","figcaption","blockquote","pre","code","em","strong","small","mark","del","ins","sub","sup","i","b","u","s","a","img","button","input","textarea","select","option","label","form","table","tr","td","th","thead","tbody","tfoot","ul","ol","li","dl","dt","dd"]),i=()=>{if(typeof n.message=="string")return o.h("span",{class:n.classes},n.message);const r=[];return n.message.forEach(a=>{switch(a.componentName){case"template":r.push(o.h("div",{class:[n.classes,a.extraClasses]},a.componentBody));break;case"vue-markdown":if(typeof t=="string")console.warn("You are using markdown for messages-widget, but you haven't registered a vue-markdown component"),r.push(o.h("div",{class:[n.classes,a.extraClasses]},a.componentBindings.source));else{const u=a.componentBindings;r.push(o.h(t,{class:[n.classes,a.extraClasses,"df-messages-widget-markdown"],source:u.source,options:u.options,plugins:u.plugins}))}break;default:r.push(o.h(e.has(a.componentName.toLowerCase())?a.componentName:o.resolveComponent(a.componentName),A(A({class:[n.classes,a.extraClasses]},a.componentBindings),a.componentBody?{innerHTML:a.componentBody}:{})));break}}),r};return(r,a)=>(o.openBlock(),o.createBlock(i))}});class E extends _{constructor(t,e){super();h(this,"_fields");h(this,"_value",null);h(this,"suppressNotifyValueChanged",!1);if(!E.isValidFields(t))throw new Error("Invalid fields object provided");if(this._fields=Object.create(null),Object.entries(t).forEach(([r,a])=>this.addField(r,a)),e){const i=e,{value:r,validators:a,actions:u}=i,d=k(i,["value","validators","actions"]);this.registerInitialActions([...a||[],...u||[]]),Object.assign(this,d),r!==void 0?this.assignMembers(r):this.originalValue!==void 0&&this.assignMembers(this.originalValue)}this.originalValue===void 0&&(this.originalValue=this.value),this._value=this.value,this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}addField(t,e){if(Object.hasOwn(this._fields,t))throw new Error(`Field ${t} is already in this form`);Object.defineProperty(e,"parent",{get:()=>this,configurable:!1,enumerable:!1}),Object.defineProperty(e,"fieldName",{get:()=>t,configurable:!1,enumerable:!1}),Object.defineProperty(this._fields,t,{get:()=>e,configurable:!1,enumerable:!0})}static isValidFields(t){function e(i){return i instanceof _}return typeof t=="object"&&t!==null&&Object.entries(t).every(([,i])=>e(i))}static createFromFormData(t){if(t instanceof _)throw new Error("data is already a Form structure, should be a simple object");return new E(t==null?{}:Object.fromEntries(Object.entries(t).map(([e,i])=>[e,new R({value:i})])))}field(t){var e;return(e=this._fields[t])!=null?e:null}get fields(){return this._fields}get value(){const t=Object.create(null);return Object.entries(this._fields).forEach(([e,i])=>{const r=i.value;(i.enabled||i instanceof E&&!c.isEmpty(r))&&(t[e]=r)}),c.isEmpty(t)?null:A({},t)}assignMembers(t){const e=this.suppressNotifyValueChanged,i=this.suppressValidation;this.suppressNotifyValueChanged=!0,this.suppressValidation=!0;try{Object.entries(this._fields).forEach(([r,a])=>{(t==null||Object.hasOwn(t,r))&&(a.value=t==null?null:t[r])})}finally{this.suppressNotifyValueChanged=e,this.suppressValidation=i}}set value(t){this.assignMembers(t),this.notifyValueChanged(),this.validate()}get touched(){return Object.values(this._fields).some(t=>t.touched)}set touched(t){Object.values(this._fields).forEach(e=>{e.touched=t})}get fullValue(){const t=Object.create(null);return Object.entries(this._fields).forEach(([e,i])=>{t[e]=i.fullValue}),A({},t)}notifyValueChanged(){if(this.suppressNotifyValueChanged)return;const t=this.value;if(!c.isEqual(t,this._value)){const e=this._value;this._value=t;const i=this.suppressParentValidityClimb;this.suppressParentValidityClimb=!0;try{this.actions.trigger(V,this,t,e),this.parent&&this.parent.notifyValueChanged()}finally{this.suppressParentValidityClimb=i,this.validate(),this.flushParentValidityClimb()}}}get valid(){return super.valid&&Object.values(this._fields).every(t=>t.valid)}validate(t=!1){if(t){const e=this.suppressValidation;this.suppressValidation=!0;try{Object.values(this._fields).forEach(i=>i.validate(!0))}finally{this.suppressValidation=e}}super.validate(t)}clone(t){var r,a;const e=Object.create(null);Object.entries(this._fields).forEach(([u,d])=>{e[u]=d.clone()});const i=new E(e,U(A({value:(t==null?void 0:t.value)!==void 0?t.value:this.value},t&&"originalValue"in t?{originalValue:t.originalValue}:{}),{enabled:(r=t==null?void 0:t.enabled)!=null?r:this.enabled,visibility:(a=t==null?void 0:t.visibility)!=null?a:this.visibility}));return i.actions=this.actions.clone(),i.actions.triggerEager(i,i.value,i.originalValue),i}}class H extends _{constructor(t,e){super();h(this,"_value",null);h(this,"_itemTemplate");h(this,"_previousValue");if(this._itemTemplate=t,e){const i=e,{value:r,validators:a,actions:u}=i,d=k(i,["value","validators","actions"]);this.registerInitialActions([...a||[],...u||[]]),Object.assign(this,d),r!=null&&this.setValueInternal(r)}this.originalValue===void 0&&(this.originalValue=this.value),this._previousValue=this.value,this.actions.triggerEager(this,this.value,this.originalValue),this.validate()}processSetValueItem(t){let e;return t instanceof E?e=t:this._itemTemplate?e=this._itemTemplate.clone({value:t}):e=E.createFromFormData(t),Object.defineProperty(e,"parent",{get:()=>this,configurable:!1,enumerable:!1}),e}createPaddingItem(){return this.processSetValueItem(this._itemTemplate?this._itemTemplate.clone():null)}setValueInternal(t){t==null?this._value=null:Array.isArray(t)&&(this._value=t.map(e=>this.processSetValueItem(e)))}get value(){var e;const t=(e=this._value)==null?void 0:e.map(i=>i.value);return c.isEmpty(t)?null:t}set value(t){const e=this._previousValue;this.setValueInternal(t);const i=this.value;this._previousValue=i;const r=this.suppressParentValidityClimb;this.suppressParentValidityClimb=!0;try{this.actions.trigger(V,this,i,e),this.parent&&this.parent.notifyValueChanged()}finally{this.suppressParentValidityClimb=r,this.validate(),this.flushParentValidityClimb()}}get touched(){var t;return((t=this._value)==null?void 0:t.some(e=>e.touched))||!1}set touched(t){var e;(e=this._value)==null||e.forEach(i=>{i.touched=t})}clone(t){var i,r,a,u;const e=new H((i=this._itemTemplate)==null?void 0:i.clone(),U(A({value:[...(r=(t==null?void 0:t.value)!==void 0?t.value:this.value)!=null?r:[]]},t&&"originalValue"in t?{originalValue:t.originalValue}:{}),{enabled:(a=t==null?void 0:t.enabled)!=null?a:this.enabled,visibility:(u=t==null?void 0:t.visibility)!=null?u:this.visibility}));return e.actions=this.actions.clone(),e.actions.triggerEager(e,e.value,e.originalValue),e}notifyValueChanged(){const t=this.value;if(!c.isEqual(t,this._previousValue)){const e=this._previousValue;this._previousValue=t;const i=this.suppressParentValidityClimb;this.suppressParentValidityClimb=!0;try{this.actions.trigger(V,this,t,e),this.parent&&this.parent.notifyValueChanged()}finally{this.suppressParentValidityClimb=i,this.validate(),this.flushParentValidityClimb()}}}get valid(){var t,e;return super.valid&&((e=(t=this._value)==null?void 0:t.every(i=>i.valid))!=null?e:!0)}validate(t=!1){var e;if(t){const i=this.suppressValidation;this.suppressValidation=!0;try{(e=this._value)==null||e.forEach(r=>r.validate(!0))}finally{this.suppressValidation=i}}super.validate(t)}get(t){return this._value!=null?this._value[t]:void 0}push(t){var e,i;return this.insert(t,(i=(e=this._value)==null?void 0:e.length)!=null?i:0)+1}pop(){var t,e;return this.remove(((e=(t=this._value)==null?void 0:t.length)!=null?e:0)-1)}remove(t){var i;if(this._value==null||t<0||this._value.length<=t)return;let e=(i=this._value.splice(t,1))==null?void 0:i[0];return e&&(e=e.clone(),this.actions.trigger(Z,this,e,t),this.notifyValueChanged()),e}insert(t,e){this._value==null&&(this._value=[]);const i=e<0?Math.max(this._value.length+e,0):e;for(;this._value.length<i;){const a=this.createPaddingItem(),u=this._value.push(a)-1;this.actions.trigger($,this,a,u)}const r=this.processSetValueItem(t);return this._value.splice(i,0,r),this.actions.trigger($,this,r,i),this.notifyValueChanged(),i}clear(){this._value=null,this.notifyValueChanged()}}class Lt extends b{constructor(t,e,i){let r=!1,a,u;super((p,S,w)=>(a=p,u=S,r||(r=!0,this.otherField.registerAction(new V((B,Q,C,j)=>{Q(B,C,j),this.unregistered||this.execute(w,()=>null,a,u)}))),this.isValidComparison(o.unref(p),o.unref(this.otherField.value))?null:[new m(this.replacePlaceholders(i,{newValue:p,oldValue:S,field:w,otherField:this.otherField}))]));h(this,"otherField");h(this,"isValidComparison");h(this,"unregistered",!1);this.otherField=t,this.isValidComparison=e}unregister(){this.unregistered=!0}}class Rt extends b{constructor(n,t){const e=t||y("Must be one of [**{allowedAsText}**]");let i=n.join(", ");i.length>60&&(i=c.truncate(i,{length:40,separator:", ",omission:`... (${n.length} items total)`}));const r=(a,u,d)=>n.includes(o.unref(a))?null:[new m(this.replacePlaceholders(e,{newValue:a,oldValue:u,field:d,allowedValues:n,allowedAsText:i}))];super(r)}}function Bt(s){return s==null?0:c.isArray(s)||c.isString(s)?s.length:c.isObject(s)&&Object.getPrototypeOf(s)===Object.prototype?Object.keys(s).length:String(s).length}class Ut extends b{constructor(n){const t=n||y("Please enter a value"),e=(i,r,a)=>Bt(o.unref(i))===0?[new m(this.replacePlaceholders(t,{newValue:i,oldValue:r,field:a}))]:null;super(e)}}class kt extends b{constructor(n,t){const e=t||y("Value must be larger or equal to **{minValue}**"),i=(r,a,u)=>r<n||r===void 0?[new m(this.replacePlaceholders(e,{newValue:r,oldValue:a,field:u,minValue:n}))]:null;super(i)}}class Mt extends b{constructor(n,t){const e=t||y("Value must be less than or equal to **{maxValue}**"),i=(r,a,u)=>r>n||r===void 0?[new m(this.replacePlaceholders(e,{newValue:r,oldValue:a,field:u,maxValue:n}))]:null;super(i)}}class Dt extends b{constructor(n,t,e){const i=e||y("Value must be between **{minValue}** and **{maxValue}**"),r=(a,u,d)=>a<n||a>t||a===void 0?[new m(this.replacePlaceholders(i,{newValue:a,oldValue:u,field:d,minValue:n,maxValue:t}))]:null;super(r)}}function et(s){return s==null?0:c.isArray(s)||c.isString(s)?s.length:c.isObject(s)&&Object.getPrototypeOf(s)===Object.prototype?Object.keys(s).length:String(s).length}class qt extends b{constructor(n,t){const e=t||y("Length must be larger or equal to **{minLength}**"),i=(r,a,u)=>et(r)<n?[new m(this.replacePlaceholders(e,{newValue:r,oldValue:a,field:u,minLength:n}))]:null;super(i)}}class $t extends b{constructor(n,t){const e=t||y("Length must be less than or equal to **{maxLength}**"),i=(r,a,u)=>et(r)>n?[new m(this.replacePlaceholders(e,{newValue:r,oldValue:a,field:u,maxLength:n}))]:null;super(i)}}class Ht extends b{constructor(n,t,e){const i=e||y("Length must be between **{minLength}** and **{maxLength}**"),r=(a,u,d)=>{const p=et(a);return p<n||p>t?[new m(this.replacePlaceholders(i,{newValue:a,oldValue:u,field:d,minLength:n,maxLength:t}))]:null};super(r)}}class Qt extends b{constructor(n,t){const e=t||y('Value must match pattern "**{pattern}**"'),i=(r,a,u)=>n.test(String(o.unref(r)))?null:[new m(this.replacePlaceholders(e,{newValue:r,oldValue:a,field:u,pattern:n}))];super(i)}}const ft=Object.freeze(Object.defineProperty({__proto__:null,CompareTo:Lt,InAllowedValues:Rt,LengthInRange:Ht,MaxLength:$t,MaxValue:Mt,MinLength:qt,MinValue:kt,Pattern:Qt,Required:Ut,Validator:b,ValueInRange:Dt},Symbol.toStringTag,{value:"Module"})),Wt=Object.freeze(Object.defineProperty({__proto__:null,AbortEventHandlingException:M,Action:dt,ActionsMap:P,ConditionalEnabledAction:ut,ConditionalStatementAction:O,ConditionalValueAction:ct,ConditionalVisibilityAction:ot,DisplayMode:I,EmptyField:ht,EnabledChangedAction:G,EnabledChangingAction:z,ExecuteAction:K,Field:R,FieldActionBase:v,FieldBase:_,Group:E,List:H,ListItemAddedAction:$,ListItemRemovedAction:Z,MdString:x,MessagesWidget:gt,Operator:g,RenderableValue:lt,Statement:F,ValidChangedAction:X,ValidationError:q,ValidationErrorRenderContent:m,ValidationErrorText:at,Validator:b,Validators:ft,ValueChangedAction:V,VisibilityChangedAction:J,VisibilityChangingAction:Y,buildErrorMessage:y,isCallableFunction:N,isSimpleComponentDef:D},Symbol.toStringTag,{value:"Module"}));l.AbortEventHandlingException=M,l.Action=dt,l.ActionsMap=P,l.ConditionalEnabledAction=ut,l.ConditionalStatementAction=O,l.ConditionalValueAction=ct,l.ConditionalVisibilityAction=ot,l.DisplayMode=I,l.EmptyField=ht,l.EnabledChangedAction=G,l.EnabledChangingAction=z,l.ExecuteAction=K,l.Field=R,l.FieldActionBase=v,l.FieldBase=_,l.Group=E,l.List=H,l.ListItemAddedAction=$,l.ListItemRemovedAction=Z,l.MdString=x,l.MessagesWidget=gt,l.Operator=g,l.RenderableValue=lt,l.Statement=F,l.ValidChangedAction=X,l.ValidationError=q,l.ValidationErrorRenderContent=m,l.ValidationErrorText=at,l.Validator=b,l.Validators=ft,l.ValueChangedAction=V,l.VisibilityChangedAction=J,l.VisibilityChangingAction=Y,l.buildErrorMessage=y,l.default=Wt,l.forms=_t,l.isCallableFunction=N,l.isSimpleComponentDef=D,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
3
3
|
//# sourceMappingURL=dynamicforms-vue-forms.umd.cjs.map
|