|
| 1 | +import { unwrap as k } from "@duplojs/utils"; |
| 2 | +import { c as H } from "./kind-DwvbGHaV.js"; |
| 3 | +import { ref as b, effectScope as C, watch as D, h as R } from "vue"; |
| 4 | +const S = H("form-field"); |
| 5 | +function U(e, n) { |
| 6 | + return S.setTo( |
| 7 | + { |
| 8 | + new: e, |
| 9 | + defaultValue: n |
| 10 | + }, |
| 11 | + {} |
| 12 | + ); |
| 13 | +} |
| 14 | +const W = "@duplojs/utils/kind/"; |
| 15 | +function j(e) { |
| 16 | + const n = `${W}${e}`; |
| 17 | + return { |
| 18 | + definition: { |
| 19 | + name: e, |
| 20 | + value: null |
| 21 | + }, |
| 22 | + runTimeKey: n, |
| 23 | + addTo(t, s = null) { |
| 24 | + return { |
| 25 | + ...t, |
| 26 | + [n]: s |
| 27 | + }; |
| 28 | + }, |
| 29 | + setTo(t, s = null) { |
| 30 | + return t[n] = s, t; |
| 31 | + }, |
| 32 | + has(t) { |
| 33 | + return t && (typeof t == "object" || typeof t == "function") && n in t; |
| 34 | + }, |
| 35 | + getValue(t) { |
| 36 | + return t[n]; |
| 37 | + } |
| 38 | + }; |
| 39 | +} |
| 40 | +function q(e) { |
| 41 | + return (n) => j(`@${e}/${n}`); |
| 42 | +} |
| 43 | +function te(e, n, t) { |
| 44 | + const s = j(e), u = n instanceof Array ? n : [n], c = t ?? class { |
| 45 | + }, l = class extends c { |
| 46 | + constructor(r = {}, i = []) { |
| 47 | + super(...i); |
| 48 | + for (const f of u) |
| 49 | + this[f.runTimeKey] = r[f.definition.name] ?? null; |
| 50 | + } |
| 51 | + static [Symbol.hasInstance](r) { |
| 52 | + if (!s.has(r)) |
| 53 | + return !1; |
| 54 | + for (const i of u) |
| 55 | + if (!i.has(r)) |
| 56 | + return !1; |
| 57 | + return !0; |
| 58 | + } |
| 59 | + }; |
| 60 | + return u.forEach((r) => { |
| 61 | + l.prototype[r.runTimeKey] = null; |
| 62 | + }), l.prototype[s.runTimeKey] = null, l; |
| 63 | +} |
| 64 | +const a = q( |
| 65 | + // @ts-expect-error reserved kind namespace |
| 66 | + "DuplojsUtilsEither" |
| 67 | +), y = a("information"), m = "@duplojs/utils/value"; |
| 68 | +function N(e) { |
| 69 | + return { |
| 70 | + [m]: e |
| 71 | + }; |
| 72 | +} |
| 73 | +function A(e) { |
| 74 | + return !!e && typeof e == "object" && m in e; |
| 75 | +} |
| 76 | +const $ = a("left"); |
| 77 | +function _(e, n = void 0) { |
| 78 | + return $.setTo(y.setTo(N(n), e)); |
| 79 | +} |
| 80 | +function E(e) { |
| 81 | + return $.has(e) && y.has(e) && A(e); |
| 82 | +} |
| 83 | +const z = a("right"); |
| 84 | +function B(e, n = void 0) { |
| 85 | + return z.setTo(y.setTo(N(n), e)); |
| 86 | +} |
| 87 | +const G = a("error"); |
| 88 | +function J(e) { |
| 89 | + return G.setTo(_("error", e)); |
| 90 | +} |
| 91 | +const O = a("success"); |
| 92 | +function Q(e) { |
| 93 | + return O.setTo(B("success", e)); |
| 94 | +} |
| 95 | +function ne(e, n) { |
| 96 | + return (t = {}) => { |
| 97 | + const s = t.defaultValue !== void 0 ? typeof t.defaultValue == "function" ? t.defaultValue() : t.defaultValue : typeof n.defaultValue == "function" ? n.defaultValue() : n.defaultValue, u = typeof t.props == "function" ? t.props : () => t.props, c = t.label, l = typeof c == "string" ? () => c : c; |
| 98 | + return U( |
| 99 | + (r, i, f) => { |
| 100 | + const d = `${i}_INP`, w = t?.template ?? n.template ?? f.input; |
| 101 | + let K = !1; |
| 102 | + const p = b(null), v = C(), { errorMessage: g } = v.run(() => { |
| 103 | + const o = b(null); |
| 104 | + return D( |
| 105 | + r, |
| 106 | + () => { |
| 107 | + o.value !== null && V(); |
| 108 | + }, |
| 109 | + { flush: "post" } |
| 110 | + ), { |
| 111 | + errorMessage: o |
| 112 | + }; |
| 113 | + }), V = () => { |
| 114 | + const o = p.value?.check?.() || Q(r.value); |
| 115 | + if (t.dataParser === void 0 || E(o)) |
| 116 | + return o; |
| 117 | + const P = k(o), h = t.dataParser.parse(P); |
| 118 | + if (E(h)) { |
| 119 | + const T = k(h); |
| 120 | + return g.value = T.issues[0]?.message ?? "Error", J( |
| 121 | + [ |
| 122 | + { |
| 123 | + key: d, |
| 124 | + dataParserError: T |
| 125 | + } |
| 126 | + ] |
| 127 | + ); |
| 128 | + } |
| 129 | + return g.value = null, h; |
| 130 | + }, x = () => { |
| 131 | + p.value?.reset?.(), g.value = null; |
| 132 | + }, F = () => { |
| 133 | + v.stop(), K = !0, p.value?.dispose?.(); |
| 134 | + }, I = () => r.value, L = () => R( |
| 135 | + e, |
| 136 | + { |
| 137 | + ...n.props, |
| 138 | + ...u(), |
| 139 | + modelValue: r.value, |
| 140 | + "onUpdate:modelValue": (o) => { |
| 141 | + K || (r.value = o); |
| 142 | + }, |
| 143 | + id: d, |
| 144 | + key: d, |
| 145 | + ref: p |
| 146 | + } |
| 147 | + ), M = t.dataParser && (() => g.value); |
| 148 | + return { |
| 149 | + check: V, |
| 150 | + reset: x, |
| 151 | + dispose: F, |
| 152 | + getVNode: () => w.getVNode( |
| 153 | + { |
| 154 | + getLabel: l, |
| 155 | + fieldKey: d, |
| 156 | + getCurrentValue: I, |
| 157 | + getErrorMessage: M, |
| 158 | + class: t.class |
| 159 | + }, |
| 160 | + { |
| 161 | + input: L |
| 162 | + } |
| 163 | + ) |
| 164 | + }; |
| 165 | + }, |
| 166 | + s |
| 167 | + ); |
| 168 | + }; |
| 169 | +} |
| 170 | +export { |
| 171 | + ne as a, |
| 172 | + y as b, |
| 173 | + U as c, |
| 174 | + A as d, |
| 175 | + J as e, |
| 176 | + S as f, |
| 177 | + B as g, |
| 178 | + a as h, |
| 179 | + E as i, |
| 180 | + q as j, |
| 181 | + m as k, |
| 182 | + _ as l, |
| 183 | + te as m, |
| 184 | + j as n, |
| 185 | + z as r, |
| 186 | + Q as s |
| 187 | +}; |
0 commit comments