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