@dynamicforms/vue-forms
Version:
Data entry forms for vue - logic (no controls here)
1,057 lines (1,056 loc) • 33.2 kB
JavaScript
var ht = Object.defineProperty, gt = Object.defineProperties;
var dt = Object.getOwnPropertyDescriptors;
var w = Object.getOwnPropertySymbols;
var J = Object.prototype.hasOwnProperty, K = Object.prototype.propertyIsEnumerable;
var B = (n, i, t) => i in n ? ht(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t, P = (n, i) => {
for (var t in i || (i = {}))
J.call(i, t) && B(n, t, i[t]);
if (w)
for (var t of w(i))
K.call(i, t) && B(n, t, i[t]);
return n;
}, O = (n, i) => gt(n, dt(i));
var I = (n, i) => {
var t = {};
for (var e in n)
J.call(n, e) && i.indexOf(e) < 0 && (t[e] = n[e]);
if (n != null && w)
for (var e of w(n))
i.indexOf(e) < 0 && K.call(n, e) && (t[e] = n[e]);
return t;
};
var o = (n, i, t) => B(n, typeof i != "symbol" ? i + "" : i, t);
import { isEqual as R, isBoolean as ft, isString as V, isEmpty as q, truncate as pt, isArray as tt, isObject as et } from "lodash-es";
import { unref as d, computed as z, reactive as bt } from "vue";
var S = /* @__PURE__ */ ((n) => (n[n.SUPPRESS = 1] = "SUPPRESS", n[n.HIDDEN = 5] = "HIDDEN", n[n.INVISIBLE = 8] = "INVISIBLE", n[n.FULL = 10] = "FULL", n))(S || {});
const Y = 10;
((n) => {
function i(s) {
return s.toUpperCase() === "SUPPRESS" ? 1 : s.toUpperCase() === "HIDDEN" ? 5 : s.toUpperCase() === "INVISIBLE" ? 8 : Y;
}
n.fromString = i;
function t(s) {
const r = typeof s == "number" ? s : n.fromString(s);
return Object.values(n).includes(r) ? r : Y;
}
n.fromAny = t;
function e(s) {
const r = typeof s == "number" ? s : n.fromString(s);
return Object.values(n).includes(r);
}
n.isDefined = e;
})(S || (S = {}));
Object.freeze(S);
const A = S;
class p {
constructor(i) {
o(this, "executorFn");
this.executorFn = i;
}
static get classIdentifier() {
throw new Error("classIdentifier must be declared");
}
get classIdentifier() {
return this.constructor.classIdentifier;
}
execute(i, t, ...e) {
return this.executorFn(i, t, ...e);
}
// eslint-disable-next-line class-methods-use-this
get eager() {
return !1;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
boundToField(i) {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
unregister() {
}
}
class M extends Error {
}
const it = Symbol("ValueChangedAction");
class v extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return it;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
class F extends String {
}
function G(n) {
const i = d(n);
return typeof i == "object" && "componentName" in i;
}
class H {
get componentName() {
return "Comment";
}
// eslint-disable-line class-methods-use-this
get componentBindings() {
return {};
}
// eslint-disable-line class-methods-use-this
get componentBody() {
return "";
}
// eslint-disable-line class-methods-use-this
}
class vt extends H {
constructor(t) {
super();
o(this, "text");
this.text = t;
}
get componentName() {
return "template";
}
// eslint-disable-line class-methods-use-this
get componentBody() {
return this.text;
}
}
class b extends H {
constructor(t) {
super();
o(this, "text");
o(this, "textType");
this.text = t, this.textType = z(() => this.getTextType);
}
get getTextType() {
const t = d(this.text);
return t ? t instanceof F ? "md" : G(t) ? "component" : "string" : "string";
}
get componentName() {
switch (d(this.textType)) {
case "string":
return "template";
case "md":
return "vue-markdown";
case "component":
return d(this.text).componentName;
default:
return "template";
}
}
get componentBindings() {
switch (d(this.textType)) {
case "string":
return {};
case "md":
return { source: this.text.toString() };
case "component":
return d(this.text).componentProps;
default:
return {};
}
}
get componentBody() {
switch (d(this.textType)) {
case "string":
return d(this.text);
default:
return "";
}
}
}
const mt = Symbol("Validator");
class f extends v {
/**
* Creates a new validator
* @param validationFn Function that validates the field value and returns errors or null
*/
constructor(t) {
super((s, r, a, l) => {
const c = t(a, l, s) || [], u = (h) => {
var C;
h == null || h.forEach(
(x) => Object.defineProperty(x, "source", { value: this.source, enumerable: !1, configurable: !1 })
);
for (let x = s.errors.length - 1; x >= 0; x--) {
const T = s.errors[x];
if (T.source === this.source) {
const j = (C = h == null ? void 0 : h.findIndex(($) => R($, T))) != null ? C : -1;
j >= 0 ? h == null || h.splice(j, 1) : s.errors.splice(x, 1);
}
}
h && h.length > 0 && s.errors.push(...h), s.validate();
};
return c instanceof Promise ? (s.validating = ++s.validatingCount > 0, c.then((h) => u(h)).finally(() => {
s.validatingCount = Math.max(0, s.validatingCount - 1), s.validating = s.validatingCount > 0;
})) : u(c), r(s, a, l);
});
o(this, "source");
this.source = Symbol(this.constructor.name);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return mt;
}
// eslint-disable-next-line class-methods-use-this
get eager() {
return !0;
}
// eslint-disable-next-line class-methods-use-this
replacePlaceholders(t, e) {
if (G(t)) return t;
let s = t;
return Object.keys(e).forEach((r) => {
s = s.replaceAll(`{${r}}`, e[r]);
}), t instanceof F ? new F(s) : s;
}
}
class N extends Map {
constructor() {
super(...arguments);
o(this, "eagerActions", /* @__PURE__ */ new Set());
o(this, "registeredActions", []);
}
register(t) {
if (!(t instanceof p)) throw new Error("Invalid action type");
this.registeredActions.push(t);
const e = t.classIdentifier, s = this.get(e) || (() => null);
function r(a, ...l) {
return t.execute(a, s, ...l);
}
this.set(e, r), t.eager && this.eagerActions.add(t.classIdentifier);
}
trigger(t, e, ...s) {
const r = t.classIdentifier;
r === it && this.triggerEager(e, ...s);
const a = this.get(r);
try {
if (a) return a(e, ...s);
} catch (l) {
if (!(l instanceof M)) throw l;
}
return null;
}
triggerEager(t, ...e) {
for (const s of this.eagerActions) {
const r = this.get(s);
try {
r && r(t, ...e);
} catch (a) {
if (!(a instanceof M)) throw a;
}
}
}
clone() {
const t = new N();
return this.registeredActions.forEach((e) => t.register(e)), t;
}
cloneWithoutValidators() {
const t = new N();
return this.registeredActions.forEach((e) => {
e instanceof f ? e.unregister() : t.register(e);
}), t;
}
}
const yt = Symbol("ConditionalStatementAction");
class U extends v {
constructor(t, e) {
const s = (r, a, l, c) => {
const u = t.evaluate();
if (u !== this.lastResult) {
for (const h of this.boundFields)
e(h, u, this.lastResult);
this.lastResult = u;
}
return a(r, l, c);
};
super(s);
o(this, "lastResult");
// boundField tracks the fields this action is bound to. so that it may perform the executorFn on them and not on the
// ValueChangedAction fields that will call the actionExecutor
o(this, "boundFields", /* @__PURE__ */ new Set());
t.collectFields().forEach((r) => r.registerAction(new v(s)));
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return yt;
}
// eslint-disable-next-line class-methods-use-this
get eager() {
return !0;
}
boundToField(t) {
this.boundFields.add(t);
}
}
class xt extends U {
constructor(i) {
super(i, (t, e) => {
t.visibility = e ? A.FULL : A.SUPPRESS;
});
}
}
class Et extends U {
constructor(i) {
super(i, (t, e) => {
t.enabled = e;
});
}
}
class Vt extends U {
constructor(i, t) {
super(i, (e, s) => {
s && (e.value = t);
});
}
}
var L = /* @__PURE__ */ ((n) => (n[n.NOT = 0] = "NOT", n[n.OR = 1] = "OR", n[n.AND = 2] = "AND", n[n.XOR = 3] = "XOR", n[n.NAND = 4] = "NAND", n[n.NOR = 5] = "NOR", n[n.EQUALS = -1] = "EQUALS", n[n.NOT_EQUALS = -2] = "NOT_EQUALS", n[n.GT = -3] = "GT", n[n.LT = -4] = "LT", n[n.GE = -5] = "GE", n[n.LE = -6] = "LE", n[n.IN = -7] = "IN", n[n.NOT_IN = -8] = "NOT_IN", n[n.INCLUDES = -9] = "INCLUDES", n[n.NOT_INCLUDES = -10] = "NOT_INCLUDES", n))(L || {});
((n) => {
function i(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}`);
}
n.fromString = i;
function t(r) {
const a = typeof r == "number" ? r : n.fromString(r);
if (Object.values(n).includes(a)) return a;
throw new Error(`Unrecognised operator ${r}`);
}
n.fromAny = t;
function e(r) {
const a = typeof r == "number" ? r : n.fromString(r);
return Object.values(n).includes(a);
}
n.isDefined = e;
function s(r) {
return r >= 0;
}
n.isLogicOperator = s;
})(L || (L = {}));
Object.freeze(L);
const g = L, At = Symbol("EnabledChangingAction");
class nt extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return At;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const Ct = Symbol("EnabledChangedAction");
class st extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return Ct;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const It = Symbol("ValidChangedAction");
class rt extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return It;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const _t = Symbol("VisibilityChangingAction");
class at extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return _t;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const St = Symbol("VisibilityChangedAction");
class lt extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return St;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
class y {
constructor() {
o(this, "reactiveValue", z(() => this.value));
// contains original field value as was provided at creation
o(this, "validatingCount", 0);
o(this, "validating", !1);
o(this, "_valid", !0);
// is current value valid as per FE and BE validators?
o(this, "errors", []);
// when member of a Group, fieldName specifies the name of this field
o(this, "actions", new N());
// default property handlers
o(this, "_visibility", A.FULL);
o(this, "_enabled", !0);
}
get visibility() {
return this._visibility;
}
set visibility(i) {
const t = this._visibility, e = this.actions.trigger(at, this, i, t);
if (!A.isDefined(e != null ? e : i)) throw new Error("visibility must be a DisplayMode constant");
this._visibility = A.fromAny(e != null ? e : i), this.actions.trigger(lt, this, this._visibility, t);
}
get enabled() {
return this._enabled;
}
set enabled(i) {
const t = this._enabled, e = this.actions.trigger(nt, this, i, t);
if (!ft(e != null ? e : i)) throw new Error("Enabled value must be boolean");
this._enabled = e != null ? e : i, this.actions.trigger(st, this, this._enabled, t);
}
validate() {
const i = this._valid;
this._valid = this.valid, this._valid !== i && this.actions.trigger(rt, this, this.valid, i);
}
get valid() {
return this.errors.length === 0;
}
get fullValue() {
return this.value;
}
get isChanged() {
return !R(this.value, this.originalValue);
}
registerAction(i) {
const t = i;
return this.actions.register(t), t.boundToField(this), t.eager && this.actions.trigger(Object.getPrototypeOf(i).constructor, this, this.value, this.originalValue), this;
}
triggerAction(i, ...t) {
return this.actions.trigger(i, this, ...t);
}
clearValidators() {
this.actions = this.actions.cloneWithoutValidators(), this.errors = [], this._valid = !0;
}
}
function Ft(n, i) {
return n ? !i : i;
}
class _ {
constructor(i, t, e) {
o(this, "operand1");
o(this, "operator");
o(this, "operand2");
this.operand1 = i, this.operator = t, this.operand2 = e;
}
get operand1Value() {
return this.operand1 instanceof _ ? this.operand1.evaluate() : this.operand1 instanceof y ? d(this.operand1.value) : this.operand1;
}
get operand2Value() {
return this.operand2 instanceof _ ? this.operand2.evaluate() : this.operand2 instanceof y ? d(this.operand2.value) : this.operand2;
}
evaluate() {
var e, s, r, a;
const i = this.operand1Value, t = this.operand2Value;
switch (this.operator) {
case g.AND:
return i && t;
case g.OR:
return i || t;
case g.NAND:
return !(i && t);
case g.NOR:
return !(i || t);
case g.XOR:
return Ft(i, t);
case g.NOT:
return !i;
case g.EQUALS:
return i == t;
case g.NOT_EQUALS:
return i != t;
case g.LT:
return i < t;
case g.LE:
return i <= t;
case g.GE:
return i >= t;
case g.GT:
return i > t;
case g.IN:
return (s = (e = t == null ? void 0 : t.includes) == null ? void 0 : e.call(t, i)) != null ? s : !1;
case g.NOT_IN:
return !((a = (r = t == null ? void 0 : t.includes) == null ? void 0 : r.call(t, i)) == null || a);
case g.INCLUDES:
return V(i) && V(t) && i.indexOf(t) >= 0;
case g.NOT_INCLUDES:
return !(V(i) && V(t) && i.indexOf(t) >= 0);
default:
throw new Error(`Operator not implemented ${this.operator}`);
}
}
/**
* Recursively collects all fields used in this statement and its nested statements
* @returns A set of all fields used in this statement
*/
collectFields() {
const i = /* @__PURE__ */ new Set();
function t(e) {
e instanceof y ? i.add(e) : e instanceof _ && e.collectFields().forEach((r) => i.add(r));
}
return t(this.operand1), t(this.operand2), i;
}
}
const Nt = Symbol("ExecuteAction");
class ot extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return Nt;
}
execute(i, t, e) {
return super.execute(i, t, e);
}
}
const Lt = Symbol("ListItemAddedAction");
class Q extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return Lt;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const Tt = Symbol("ListItemRemovedAction");
class ct extends p {
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(i) {
super(i);
}
// eslint-disable-next-line class-methods-use-this
static get classIdentifier() {
return Tt;
}
execute(i, t, e, s) {
return super.execute(i, t, e, s);
}
}
const Z = Symbol("FieldConstructorGuard");
class D extends y {
constructor(t) {
super();
o(this, "_value");
if (t !== Z) {
const e = this.constructor.name;
throw new TypeError(`Don't use constructor to instantiate ${e}. Use ${e}.create<T>`);
}
}
init(t) {
if (t) {
const e = t, { value: s, validators: r, actions: a } = e, l = I(e, ["value", "validators", "actions"]);
[...r || [], ...a || []].forEach((c) => this.registerAction(c)), Object.assign(this, l), this._value = s != null ? s : this.originalValue, this.originalValue === void 0 && (this.originalValue = this._value);
}
this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
}
/**
* Creates a new reactive Field instance.
* @param params Initial field parameters
* @returns Reactive Field instance
*/
static create(t) {
const e = bt(new this(Z));
return e.init(t), e;
}
get value() {
return this._value;
}
set value(t) {
const e = this._value;
!this.enabled || e === t || (this._value = t, this.actions.trigger(v, this, this._value, e), this.parent && this.parent.notifyValueChanged(), this.validate());
}
clone(t) {
var s, r, a;
const e = this.constructor.create(O(P({
value: (s = t == null ? void 0 : t.value) != null ? s : 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 e.actions = this.actions.clone(), e.actions.triggerEager(e, e.value, e.originalValue), e;
}
}
const jt = D.create({ value: "EmptyField" }).registerAction(new v(
() => {
console.warn("Working with EmptyField! This should not happen");
}
));
function k(n, i) {
return (n == null ? void 0 : n.label) == null && (n == null ? void 0 : n.icon) == null ? i : n;
}
class wt extends D {
constructor(i) {
super(i), this._value = { label: void 0, icon: void 0 };
}
init(i) {
if (i) {
const t = i, { value: e, originalValue: s, validators: r, actions: a } = t, l = I(t, ["value", "originalValue", "validators", "actions"]);
[...r || [], ...a || []].forEach((h) => this.registerAction(h)), Object.assign(this, l);
const c = k(e, this._value), u = Object.freeze({ label: s == null ? void 0 : s.label, icon: s == null ? void 0 : s.icon });
this._value = k(c, u), this.originalValue = k(u, c);
}
this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
}
static create(i) {
return super.create(i);
}
get icon() {
return this.value.icon;
}
set icon(i) {
this.value.icon = i;
}
get label() {
return this.value.label;
}
set label(i) {
this.value.label = i;
}
execute(i) {
this.actions.trigger(ot, this, i);
}
}
class E extends y {
constructor(t, e) {
super();
o(this, "_fields");
o(this, "_value", null);
o(this, "reactiveValue", z(() => this.value));
o(this, "suppressNotifyValueChanged", !1);
if (!E.isValidFields(t)) throw new Error("Invalid fields object provided");
if (this._fields = {}, Object.entries(t).forEach(([r, a]) => this.addField(r, a)), e) {
const s = e, { value: r, validators: a, actions: l } = s, c = I(s, ["value", "validators", "actions"]);
[...a || [], ...l || []].forEach((u) => this.registerAction(u)), Object.assign(this, c), 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(t, e) {
if (this.fields[t] !== void 0)
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() {
return e;
}, configurable: !1, enumerable: !0 }
);
}
static isValidFields(t) {
function e(s) {
return s instanceof y;
}
return typeof t == "object" && t !== null && Object.entries(t).every(([, s]) => e(s));
}
static createFromFormData(t) {
if (t instanceof y)
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, s]) => [e, D.create({ value: s })])
)
);
}
field(t) {
var e;
return (e = this._fields[t]) != null ? e : null;
}
get fields() {
return this._fields;
}
get value() {
const t = {};
return Object.entries(this._fields).forEach(([e, s]) => {
const r = s.value;
(s.enabled || s instanceof E && !q(r)) && (t[e] = r);
}), q(t) ? null : t;
}
set value(t) {
this.suppressNotifyValueChanged = !0;
try {
Object.entries(this._fields).forEach(([e, s]) => {
(t == null || e in t) && (s.value = t == null ? null : t[e]);
});
} finally {
this.suppressNotifyValueChanged = !1;
}
this.notifyValueChanged(), this.validate();
}
get fullValue() {
const t = {};
return Object.entries(this._fields).forEach(([e, s]) => {
t[e] = s.fullValue;
}), t;
}
notifyValueChanged() {
if (this.suppressNotifyValueChanged) return;
const t = this.value;
if (!R(t, this._value)) {
const e = this._value;
this._value = t, this.actions.trigger(v, this, t, e), this.parent && this.parent.notifyValueChanged(), this.validate();
}
}
get valid() {
return super.valid && Object.values(this._fields).every((t) => t.valid);
}
clone(t) {
var r, a, l;
const e = {};
Object.entries(this._fields).forEach(([c, u]) => {
e[c] = u.clone();
});
const s = new E(e, O(P({
value: (r = t == null ? void 0 : t.value) != null ? r : this.value
}, t && "originalValue" in t ? { originalValue: t.originalValue } : {}), {
enabled: (a = t == null ? void 0 : t.enabled) != null ? a : this.enabled,
visibility: (l = t == null ? void 0 : t.visibility) != null ? l : this.visibility
}));
return s.actions = this.actions.clone(), s.actions.triggerEager(s, s.value, s.originalValue), s;
}
}
class X extends y {
constructor(t, e) {
super();
o(this, "_value", null);
o(this, "_itemTemplate");
o(this, "_previousValue");
if (this._itemTemplate = t, e) {
const s = e, { value: r, validators: a, actions: l } = s, c = I(s, ["value", "validators", "actions"]);
[...a || [], ...l || []].forEach((u) => this.registerAction(u)), Object.assign(this, c), 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(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;
}
setValueInternal(t) {
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((s) => s.value);
return q(t) ? null : t;
}
set value(t) {
const e = this.value;
this.setValueInternal(t), this.actions.trigger(v, this, this.value, e), this.parent && this.parent.notifyValueChanged(), this.validate();
}
clone(t) {
var s, r, a, l;
const e = new X((s = this._itemTemplate) == null ? void 0 : s.clone(), O(P({
value: [...(r = t == null ? void 0 : t.value) != null ? r : this.value]
}, t && "originalValue" in t ? { originalValue: t.originalValue } : {}), {
enabled: (a = t == null ? void 0 : t.enabled) != null ? a : this.enabled,
visibility: (l = t == null ? void 0 : t.visibility) != null ? l : this.visibility
}));
return e.actions = this.actions.clone(), e.actions.triggerEager(e, e.value, e.originalValue), e;
}
notifyValueChanged() {
const t = this.value;
if (!R(t, this._previousValue)) {
const e = this._previousValue;
this._previousValue = t, this.actions.trigger(v, this, t, e), this.parent && this.parent.notifyValueChanged(), this.validate();
}
}
get valid() {
var t, e;
return super.valid && ((e = (t = this._value) == null ? void 0 : t.every((s) => s.valid)) != null ? e : !0);
}
get(t) {
return this._value != null ? this._value[t] : void 0;
}
push(t) {
var e, s;
return this.insert(t, (s = (e = this._value) == null ? void 0 : e.length) != null ? s : 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 s;
if (this._value == null || t < 0 || this._value.length <= t) return;
let e = (s = this._value.splice(t, 1)) == null ? void 0 : s[0];
return e && (e = e.clone(), this.actions.trigger(ct, this, e, t), this.notifyValueChanged()), e;
}
insert(t, e) {
for (this._value == null && (this._value = []); this._value.length < e; ) {
const r = this.processSetValueItem(null), a = this._value.push(r);
this.actions.trigger(Q, this, r, a);
}
const s = this.processSetValueItem(t);
return this._value.splice(e, 0, s), this.actions.trigger(Q, this, s, e), this.notifyValueChanged(), e;
}
clear() {
this._value = null, this.notifyValueChanged();
}
}
const ut = { useMarkdownInValidators: !0 };
function Pt() {
return ut;
}
function Ot(n) {
Object.assign(ut, n);
}
const Kt = {
install(n, i) {
i && Ot(i);
}
};
function m(n) {
return Pt().useMarkdownInValidators ? new F(n) : n.replace(/[*_~`]/g, "").replace(/\[.*?\]\((.*?)\)/g, "$1").replace(/!\[.*?\]\((.*?)\)/g, "").replace(/#+\s?/g, "").replace(/>\s?/g, "").replace(/(\*|-|\d+\.)\s+/g, "").replace(/`{3}[\s\S]*?`{3}/g, "").replace(/`([^`]+)`/g, "$1").replace(/\n{2,}/g, `
`);
}
class Rt extends f {
constructor(t, e, s) {
let r = !1, a, l;
super((u, h, C) => (a = u, l = h, r || (r = !0, this.otherField.registerAction(new v((x, T, j, $) => {
T(x, j, $), this.unregistered || this.execute(C, () => null, a, l);
}))), this.isValidComparison(d(u), d(this.otherField.value)) ? null : [
new b(
this.replacePlaceholders(s, { newValue: u, oldValue: h, field: C, otherField: this.otherField })
)
]));
o(this, "unregistered", !1);
this.otherField = t, this.isValidComparison = e;
}
unregister() {
this.unregistered = !0;
}
}
class Ut extends f {
constructor(i, t) {
const e = t || m("Must be one of [**{allowedAsText}**]");
let s = i.join(", ");
s.length > 60 && (s = pt(s, {
length: 40,
separator: ", ",
omission: `... (${i.length} items total)`
}));
const r = (a, l, c) => i.includes(d(a)) ? null : [
new b(
this.replacePlaceholders(e, { newValue: a, oldValue: l, field: c, allowedValues: i, allowedAsText: s })
)
];
super(r);
}
}
function Dt(n) {
return n == null ? 0 : tt(n) || V(n) ? n.length : et(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
}
class $t extends f {
constructor(i) {
const t = i || m("Please enter a value"), e = (s, r, a) => Dt(d(s)) === 0 ? [new b(
this.replacePlaceholders(t, { newValue: s, oldValue: r, field: a })
)] : null;
super(e);
}
}
class Bt extends f {
constructor(i, t) {
const e = t || m("Value must be larger or equal to **{minValue}**"), s = (r, a, l) => r < i || r === void 0 ? [
new b(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, minValue: i }))
] : null;
super(s);
}
}
class kt extends f {
constructor(i, t) {
const e = t || m("Value must be less than or equal to **{maxValue}**"), s = (r, a, l) => r > i || r === void 0 ? [
new b(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, maxValue: i }))
] : null;
super(s);
}
}
class qt extends f {
constructor(i, t, e) {
const s = e || m("Value must be between **{minValue}** and **{maxValue}**"), r = (a, l, c) => a < i || a > t || a === void 0 ? [
new b(
this.replacePlaceholders(s, { newValue: a, oldValue: l, field: c, minValue: i, maxValue: t })
)
] : null;
super(r);
}
}
function W(n) {
return n == null ? 0 : tt(n) || V(n) ? n.length : et(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
}
class Mt extends f {
constructor(i, t) {
const e = t || m("Length must be larger or equal to **{minLength}**"), s = (r, a, l) => W(r) < i ? [
new b(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, minLength: i }))
] : null;
super(s);
}
}
class Qt extends f {
constructor(i, t) {
const e = t || m("Length must be less than or equal to **{maxLength}**"), s = (r, a, l) => W(r) > i ? [
new b(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, maxLength: i }))
] : null;
super(s);
}
}
class zt extends f {
constructor(i, t, e) {
const s = e || m("Length must be between **{minLength}** and **{maxLength}**"), r = (a, l, c) => {
const u = W(a);
return u < i || u > t ? [
new b(
this.replacePlaceholders(s, { newValue: a, oldValue: l, field: c, minLength: i, maxLength: t })
)
] : null;
};
super(r);
}
}
class Gt extends f {
constructor(i, t) {
const e = t || m('Value must match pattern "**{pattern}**"'), s = (r, a, l) => i.test(String(d(r))) ? null : [
new b(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, pattern: i }))
];
super(s);
}
}
const Ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
CompareTo: Rt,
InAllowedValues: Ut,
LengthInRange: zt,
MaxLength: Qt,
MaxValue: kt,
MinLength: Mt,
MinValue: Bt,
Pattern: Gt,
Required: $t,
Validator: f,
ValueInRange: qt
}, Symbol.toStringTag, { value: "Module" })), Yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
AbortEventHandlingException: M,
Action: wt,
ActionsMap: N,
ConditionalEnabledAction: Et,
ConditionalStatementAction: U,
ConditionalValueAction: Vt,
ConditionalVisibilityAction: xt,
DisplayMode: A,
EmptyField: jt,
EnabledChangedAction: st,
EnabledChangingAction: nt,
ExecuteAction: ot,
Field: D,
FieldActionBase: p,
FieldBase: y,
Group: E,
List: X,
ListItemAddedAction: Q,
ListItemRemovedAction: ct,
MdString: F,
Operator: g,
Statement: _,
ValidChangedAction: rt,
ValidationError: H,
ValidationErrorRenderContent: b,
ValidationErrorText: vt,
Validator: f,
Validators: Ht,
ValueChangedAction: v,
VisibilityChangedAction: lt,
VisibilityChangingAction: at,
buildErrorMessage: m,
isCustomModalContentComponentDef: G
}, Symbol.toStringTag, { value: "Module" }));
export {
M as AbortEventHandlingException,
wt as Action,
N as ActionsMap,
Et as ConditionalEnabledAction,
U as ConditionalStatementAction,
Vt as ConditionalValueAction,
xt as ConditionalVisibilityAction,
A as DisplayMode,
jt as EmptyField,
st as EnabledChangedAction,
nt as EnabledChangingAction,
ot as ExecuteAction,
D as Field,
p as FieldActionBase,
y as FieldBase,
E as Group,
X as List,
Q as ListItemAddedAction,
ct as ListItemRemovedAction,
F as MdString,
g as Operator,
_ as Statement,
rt as ValidChangedAction,
H as ValidationError,
b as ValidationErrorRenderContent,
vt as ValidationErrorText,
f as Validator,
Ht as Validators,
v as ValueChangedAction,
lt as VisibilityChangedAction,
at as VisibilityChangingAction,
m as buildErrorMessage,
Yt as default,
Kt as forms,
G as isCustomModalContentComponentDef
};
//# sourceMappingURL=dynamicforms-vue-forms.js.map