vue-formless 0.0.1 → 0.1.0

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/index.js CHANGED
@@ -1 +1,960 @@
1
-
1
+ import { inject as j, nextTick as We, onMounted as he, toValue as v, watch as ve, onBeforeUnmount as be, ref as q, computed as x, defineComponent as I, createVNode as R, Fragment as Ie, provide as H, mergeProps as Ue, markRaw as O, h as y, getCurrentInstance as Ge, reactive as Ye } from "vue";
2
+ const Z = Symbol("vue-formless.formContext");
3
+ function se() {
4
+ const e = j(Z, null);
5
+ if (!e)
6
+ throw new Error("[vue-formless] useFormContext() must be used inside <FormView>.");
7
+ return e;
8
+ }
9
+ function ue(e) {
10
+ if (!e) return [];
11
+ const t = [];
12
+ let o = 0;
13
+ for (; o < e.length; ) {
14
+ if (e[o] === ".") {
15
+ o++;
16
+ continue;
17
+ }
18
+ if (e[o] === "[") {
19
+ const n = e.indexOf("]", o + 1);
20
+ if (n === -1)
21
+ throw new Error(`Invalid path "${e}": unclosed bracket`);
22
+ const r = e.slice(o + 1, n), l = Number(r);
23
+ if (!Number.isInteger(l) || String(l) !== r || l < 0)
24
+ throw new Error(`Invalid path "${e}": index must be a non-negative integer`);
25
+ t.push({ type: "index", index: l }), o = n + 1;
26
+ } else {
27
+ const n = /^[a-zA-Z_$][a-zA-Z0-9_$]*/.exec(e.slice(o));
28
+ if (!n)
29
+ throw new Error(`Invalid path "${e}" at position ${o}`);
30
+ t.push({ type: "key", key: n[0] }), o += n[0].length;
31
+ }
32
+ }
33
+ return t;
34
+ }
35
+ function ze(e, t) {
36
+ let o = e;
37
+ for (const n of t)
38
+ n.type === "key" ? o = o[n.key] : o = o[n.index];
39
+ return o;
40
+ }
41
+ function He(e, t) {
42
+ if (t.type === "key")
43
+ return e == null || typeof e != "object" || Array.isArray(e) ? void 0 : e[t.key];
44
+ if (Array.isArray(e))
45
+ return e[t.index];
46
+ }
47
+ function B(e, t) {
48
+ const o = ue(t);
49
+ if (o.length === 0) return;
50
+ const n = o[o.length - 1], r = ze(e, o.slice(0, -1));
51
+ return He(r, n);
52
+ }
53
+ function oe(e, t, o, n) {
54
+ const r = t[o], l = o === t.length - 1;
55
+ if (r.type === "key") {
56
+ if (Array.isArray(e))
57
+ throw new Error(`Cannot set "${r.key}" on an array node`);
58
+ const u = e != null && typeof e == "object" ? e : {};
59
+ return l ? { ...u, [r.key]: n } : {
60
+ ...u,
61
+ [r.key]: oe(u[r.key], t, o + 1, n)
62
+ };
63
+ }
64
+ const s = Array.isArray(e) ? [...e] : [];
65
+ return l ? (s[r.index] = n, s) : (s[r.index] = oe(s[r.index], t, o + 1, n), s);
66
+ }
67
+ function De(e, t, o) {
68
+ const n = ue(t);
69
+ if (n.length === 0)
70
+ throw new Error("Cannot set an empty prop");
71
+ return oe(e, n, 0, o);
72
+ }
73
+ function Ke(e) {
74
+ return ue(e).map((t) => t.type === "key" ? t.key : String(t.index)).join(".");
75
+ }
76
+ function Xe(e, t) {
77
+ let o = null;
78
+ function n(r, l) {
79
+ o || (o = [], We(() => {
80
+ if (!o?.length) {
81
+ o = null;
82
+ return;
83
+ }
84
+ let s = e();
85
+ for (const u of o)
86
+ s = De(s, u.prop, u.value);
87
+ o = null, t(s);
88
+ })), o.push({ prop: r, value: l });
89
+ }
90
+ return { update: n };
91
+ }
92
+ const d = 24, P = {
93
+ column: 1
94
+ };
95
+ function qe(e) {
96
+ const t = Math.floor(Number(e));
97
+ return t === 1 / 0 ? d : Number.isFinite(t) ? Math.min(d, Math.max(1, t)) : P.column;
98
+ }
99
+ function Ze(...e) {
100
+ return qe(e.find((t) => t != null) ?? P.column);
101
+ }
102
+ function Je(e, t) {
103
+ const o = t > 0 ? t : P.column, n = Math.max(1, Math.floor(d / o));
104
+ if (e == null || e === "") return n;
105
+ if (typeof e == "number")
106
+ return me(e), e;
107
+ const r = e.trim();
108
+ if (r === "max") return d;
109
+ const l = /^(\d+)x$/.exec(r);
110
+ if (l) {
111
+ const s = Number(l[1]);
112
+ if (s < 1)
113
+ throw new Error(`[vue-formless] col:span "${e}" is invalid`);
114
+ return Math.min(d, s * n);
115
+ }
116
+ if (/^\d+$/.test(r)) {
117
+ const s = Number(r);
118
+ return me(s), s;
119
+ }
120
+ throw new Error(`[vue-formless] col:span "${e}" is invalid`);
121
+ }
122
+ function me(e) {
123
+ if (!Number.isInteger(e) || e < 1 || e > d)
124
+ throw new Error(`[vue-formless] col:span ${e} must be an integer 1–${d}`);
125
+ }
126
+ function Qe(e) {
127
+ if (e == null || e === "" || e === "auto") return "auto";
128
+ if (e === "start" || e === "end") return e;
129
+ throw new Error(`[vue-formless] col:place "${String(e)}" is invalid`);
130
+ }
131
+ const D = Symbol(
132
+ "vue-formless:layout-view"
133
+ );
134
+ function et(e, t, o = { childList: !0 }) {
135
+ if (typeof MutationObserver > "u") return;
136
+ let n = null;
137
+ function r(s) {
138
+ n?.disconnect(), n = null, s && (n = new MutationObserver(t), n.observe(s, o));
139
+ }
140
+ he(() => r(v(e)));
141
+ const l = ve(() => v(e), r, { flush: "post" });
142
+ be(() => {
143
+ l(), n?.disconnect(), n = null;
144
+ });
145
+ }
146
+ function tt(e, t = 0) {
147
+ const o = q([]);
148
+ function n() {
149
+ const r = v(e);
150
+ o.value = r ? Array.from(r.children) : [];
151
+ }
152
+ return ve(() => [v(e), v(t)], n, { immediate: !0 }), et(e, n), o;
153
+ }
154
+ function nt(e, t, o) {
155
+ const n = [];
156
+ if (o === "auto")
157
+ return e.n + t > d && (e.n = 0), n;
158
+ if (o === "start")
159
+ return e.n > 0 && (n.push(d - e.n), e.n = 0), n;
160
+ e.n + t > d && e.n > 0 && (n.push(d - e.n), e.n = 0);
161
+ const r = d - e.n - t;
162
+ return r > 0 && (n.push(r), e.n += r), n;
163
+ }
164
+ function ot(e) {
165
+ return x(() => {
166
+ const t = { n: 0 }, o = /* @__PURE__ */ new Map();
167
+ for (const n of v(e)) {
168
+ const r = nt(t, n.span, n.place);
169
+ o.set(n.id, r), t.n += n.span;
170
+ }
171
+ return o;
172
+ });
173
+ }
174
+ function Ee(e) {
175
+ if (e == null || typeof e != "object") return null;
176
+ if (typeof Element < "u" && e instanceof Element) return e;
177
+ const t = e;
178
+ return z(t.vnode?.el) ?? z(t.subTree?.el) ?? z(t.subTree?.component?.vnode?.el) ?? z(t.$el);
179
+ }
180
+ function z(e) {
181
+ if (typeof Element < "u" && e instanceof Element) return e;
182
+ if (e && e.nodeType === 8) {
183
+ for (let t = e.nextSibling; t; t = t.nextSibling)
184
+ if (typeof Element < "u" && t instanceof Element) return t;
185
+ }
186
+ return null;
187
+ }
188
+ const rt = /* @__PURE__ */ I({
189
+ name: "LayoutBlanks",
190
+ inheritAttrs: !1,
191
+ props: {
192
+ is: {
193
+ type: Object,
194
+ default: void 0
195
+ },
196
+ spans: {
197
+ type: Array,
198
+ required: !0
199
+ }
200
+ },
201
+ setup(e) {
202
+ return () => {
203
+ if (e.spans.length === 0 || e.is == null) return null;
204
+ const t = e.is;
205
+ return R(Ie, null, [e.spans.map((o, n) => R(t, {
206
+ key: n,
207
+ span: o
208
+ }, null))]);
209
+ };
210
+ }
211
+ }), lt = /* @__PURE__ */ I({
212
+ name: "LayoutItem",
213
+ inheritAttrs: !1,
214
+ props: {
215
+ span: {
216
+ type: [String, Number],
217
+ default: void 0
218
+ },
219
+ place: {
220
+ type: String,
221
+ default: void 0
222
+ }
223
+ },
224
+ setup(e, {
225
+ slots: t
226
+ }) {
227
+ const o = j(D, null);
228
+ if (!o) return () => t.default?.() ?? null;
229
+ const {
230
+ span: n,
231
+ blanks: r,
232
+ itemRef: l,
233
+ Col: s,
234
+ disabled: u
235
+ } = o(() => e.span, () => e.place);
236
+ return () => {
237
+ if (u.value) return t.default?.() ?? null;
238
+ const c = s;
239
+ return R(Ie, null, [R(rt, {
240
+ is: s,
241
+ spans: r.value
242
+ }, null), R(c, {
243
+ ref: l,
244
+ span: n.value
245
+ }, {
246
+ default: () => [t.default?.() ?? null]
247
+ })]);
248
+ };
249
+ }
250
+ }), st = /* @__PURE__ */ I({
251
+ name: "LayoutItemPassThrough",
252
+ inheritAttrs: !1,
253
+ setup(e, {
254
+ slots: t
255
+ }) {
256
+ return () => t.default?.() ?? null;
257
+ }
258
+ });
259
+ function ut() {
260
+ return j(D, null) ? lt : st;
261
+ }
262
+ function it(e) {
263
+ const t = q({});
264
+ let o = 0;
265
+ return {
266
+ get value() {
267
+ return t.value;
268
+ },
269
+ setup(n, r) {
270
+ const l = String(++o), s = x(() => Je(v(n), v(e))), u = x(() => Qe(v(r)));
271
+ return t.value[l] = {
272
+ span: s,
273
+ place: u,
274
+ el: null,
275
+ mounted: !1
276
+ }, he(() => {
277
+ const c = t.value[l];
278
+ c && (c.mounted = !0);
279
+ }), be(() => {
280
+ delete t.value[l];
281
+ }), l;
282
+ },
283
+ span(n) {
284
+ return t.value[n]?.span ?? 0;
285
+ },
286
+ ref(n, r) {
287
+ const l = t.value[n];
288
+ if (!l) return;
289
+ const s = Ee(r);
290
+ l.el !== s && (l.el = s);
291
+ }
292
+ };
293
+ }
294
+ function at(e, t) {
295
+ const o = new Map(Object.entries(e).filter(([, n]) => n.el).map(([n, r]) => [r.el, {
296
+ id: n,
297
+ span: r.span,
298
+ place: r.place
299
+ }]));
300
+ return t.filter((n) => o.has(n)).map((n) => o.get(n));
301
+ }
302
+ function ct(e, t) {
303
+ const o = tt(() => Ee(t.value), () => Object.keys(e.value).filter((n) => e.value[n].mounted).join(","));
304
+ return ot(() => at(e.value, o.value));
305
+ }
306
+ function Ce(e = {}) {
307
+ const {
308
+ Row: t,
309
+ Col: o
310
+ } = e;
311
+ return /* @__PURE__ */ I({
312
+ name: "LayoutView",
313
+ inheritAttrs: !1,
314
+ props: {
315
+ disabled: {
316
+ type: Boolean,
317
+ default: !1
318
+ },
319
+ column: {
320
+ type: Number,
321
+ default: void 0
322
+ }
323
+ },
324
+ setup(n, {
325
+ slots: r,
326
+ attrs: l
327
+ }) {
328
+ const s = x(() => !t || !o || n.disabled), u = it(() => Ze(n.column, e.column)), c = q(null), i = ct(u, c);
329
+ return H(D, (m, g) => {
330
+ H(D, null);
331
+ const p = u.setup(m, g);
332
+ return {
333
+ span: x(() => u.span(p)),
334
+ blanks: x(() => i.value.get(p) ?? []),
335
+ itemRef: (E) => u.ref(p, E),
336
+ Col: o,
337
+ disabled: s
338
+ };
339
+ }), () => s.value ? r.default?.() ?? null : R(t, Ue({
340
+ ref: c
341
+ }, l), {
342
+ default: () => [r.default?.() ?? null]
343
+ });
344
+ }
345
+ });
346
+ }
347
+ const ft = /* @__PURE__ */ new Set(["item", "layout", "model", "span"]), mt = /* @__PURE__ */ new Set([
348
+ "component",
349
+ "props",
350
+ "model",
351
+ "prop",
352
+ "item",
353
+ // leftover schema `layout` must not leak into Item snapshot extras
354
+ "layout"
355
+ ]);
356
+ function re(e) {
357
+ const t = {};
358
+ for (const [o, n] of Object.entries(e))
359
+ n !== void 0 && (t[o] = n);
360
+ return t;
361
+ }
362
+ function ie(e) {
363
+ const t = {};
364
+ for (const [o, n] of Object.entries(e))
365
+ o === "span" && n !== void 0 && console.warn("[vue-formless] fl:span is removed; use col:span"), ft.has(o) || (t[o] = n);
366
+ return t;
367
+ }
368
+ function dt(e) {
369
+ const t = {};
370
+ for (const [o, n] of Object.entries(e))
371
+ !mt.has(o) && n !== void 0 && (t[o] = n);
372
+ return t;
373
+ }
374
+ function pt(e) {
375
+ if (e == null || typeof e != "object") return {};
376
+ const t = e.formless;
377
+ if (t == null || typeof t != "object") return {};
378
+ const { model: o, item: n } = t;
379
+ return re({ model: o, item: n });
380
+ }
381
+ function Fe(e) {
382
+ const t = {};
383
+ for (const [o, n] of Object.entries(e))
384
+ !o.startsWith("fl:") || o.length <= 3 || n === void 0 || (t[o.slice(3)] = n);
385
+ return t;
386
+ }
387
+ function wt(e, t) {
388
+ const o = /* @__PURE__ */ new Set();
389
+ for (const r of t)
390
+ o.add(r), o.add(`onUpdate:${r}`);
391
+ const n = {};
392
+ for (const [r, l] of Object.entries(e))
393
+ o.has(r) || (n[r] = l);
394
+ return n;
395
+ }
396
+ function K(e, t) {
397
+ return e == null ? {} : re(typeof e == "function" ? e(t) ?? {} : e);
398
+ }
399
+ function ae(...e) {
400
+ const t = {};
401
+ for (const o of e)
402
+ if (o != null)
403
+ for (const [n, r] of Object.entries(o))
404
+ r !== void 0 && (t[n] = r);
405
+ return t;
406
+ }
407
+ function yt(e) {
408
+ const t = e.Item ? O(e.Item) : void 0;
409
+ return (o, n) => t && n.item !== !1 && (n.item === !0 || (e.isItemEnabled?.() ?? !0)) ? y(
410
+ t,
411
+ ae(
412
+ K(e.itemProps, n.fl),
413
+ n.itemAttrs,
414
+ n.itemOn
415
+ ),
416
+ {
417
+ ...n.itemSlots,
418
+ default: () => o
419
+ }
420
+ ) : o;
421
+ }
422
+ function de(e) {
423
+ return typeof e == "string" ? [e] : [...e];
424
+ }
425
+ function Se(e, t = {}, o = {}) {
426
+ if (o.prop === "")
427
+ throw new Error(`[vue-formless] fl:prop cannot be an empty string (control "${e}")`);
428
+ if (t.prop === "")
429
+ throw new Error(`[vue-formless] prop cannot be an empty string (control "${e}")`);
430
+ const n = de(t.model ?? "modelValue"), r = de(
431
+ o.prop !== void 0 ? o.prop : t.prop ?? e
432
+ );
433
+ if (r.length > n.length)
434
+ throw new Error(
435
+ `createFormControls: prop cannot be longer than model (control "${e}": model has ${n.length}, prop has ${r.length})`
436
+ );
437
+ if (r.some((l) => l === ""))
438
+ throw new Error(`[vue-formless] prop cannot be an empty string (control "${e}")`);
439
+ return { models: n, props: r };
440
+ }
441
+ function Mt(e, t) {
442
+ return e.props.length === 1 ? Ke(e.props[0]) : t;
443
+ }
444
+ function gt(e, t) {
445
+ const o = e.models.indexOf(t);
446
+ if (o === -1)
447
+ throw new Error(
448
+ `[vue-formless] useFormItem("${t}"): not a v-model port of this control`
449
+ );
450
+ const n = e.props[o];
451
+ if (n === void 0)
452
+ throw new Error(
453
+ `[vue-formless] useFormItem("${t}"): port is not bound to a prop`
454
+ );
455
+ return { models: [t], props: [n] };
456
+ }
457
+ function Ae(e, t, o) {
458
+ const n = {};
459
+ for (let r = 0; r < t.props.length; r++) {
460
+ const l = t.models[r], s = t.props[r];
461
+ n[l] = B(e, s), n[`onUpdate:${l}`] = (u) => {
462
+ o(s, u);
463
+ };
464
+ }
465
+ return n;
466
+ }
467
+ const $ = "item:", Q = "onItem:", ee = "fl:", te = "row:", ne = "col:", ht = /* @__PURE__ */ new Set(["column", "gutter"]), vt = /* @__PURE__ */ new Set(["span", "place"]);
468
+ function pe(e) {
469
+ console.warn(e);
470
+ }
471
+ function Oe(e) {
472
+ const t = {}, o = {};
473
+ for (const n of Object.keys(e)) {
474
+ const r = e[n];
475
+ r && (n.startsWith($) && n.length > $.length ? t[n.slice($.length)] = r : o[n] = r);
476
+ }
477
+ return { itemSlots: t, inputSlots: o };
478
+ }
479
+ function Le(e) {
480
+ const t = {}, o = {};
481
+ for (const [n, r] of Object.entries(e))
482
+ n.startsWith(ee) && n.length > ee.length ? t[n.slice(ee.length)] = r : o[n] = r;
483
+ return { fl: t, rest: o };
484
+ }
485
+ function Ve(e) {
486
+ const t = {}, o = {}, n = {};
487
+ for (const [r, l] of Object.entries(e))
488
+ if (r.startsWith(te) && r.length > te.length) {
489
+ const s = r.slice(te.length);
490
+ ht.has(s) ? t[s] = l : pe(`[vue-formless] unknown row:${s} is ignored`);
491
+ } else if (r.startsWith(ne) && r.length > ne.length) {
492
+ const s = r.slice(ne.length);
493
+ vt.has(s) ? o[s] = l : pe(`[vue-formless] unknown col:${s} is ignored`);
494
+ } else
495
+ n[r] = l;
496
+ return { row: t, col: o, rest: n };
497
+ }
498
+ function we(e) {
499
+ if (e == null || e === "") return;
500
+ const t = typeof e == "number" ? e : Number(e);
501
+ if (Number.isFinite(t))
502
+ return t;
503
+ }
504
+ function ke(e) {
505
+ const t = {}, o = {}, n = {};
506
+ for (const [r, l] of Object.entries(e))
507
+ r.startsWith(Q) && r.length > Q.length ? o[bt(r.slice(Q.length))] = l : r.startsWith($) && r.length > $.length ? t[r.slice($.length)] = l : n[r] = l;
508
+ return { itemAttrs: t, itemOn: o, inputAttrs: n };
509
+ }
510
+ function bt(e) {
511
+ const t = e.indexOf(":");
512
+ return t === -1 ? `on${ye(e)}` : `on${ye(e.slice(0, t))}:${e.slice(t + 1)}`;
513
+ }
514
+ function ye(e) {
515
+ return e && e.charAt(0).toUpperCase() + e.slice(1);
516
+ }
517
+ const xe = Symbol(
518
+ "vue-formless.controlRuntime"
519
+ );
520
+ function It(e) {
521
+ H(xe, e);
522
+ }
523
+ const Et = {
524
+ "fl:prop": { type: [String, Array], default: void 0 },
525
+ "col:span": { type: [String, Number], default: void 0 },
526
+ "col:place": { type: String, default: void 0 }
527
+ };
528
+ function Re(e) {
529
+ return I({
530
+ name: e ? `FormViewItem_${e}` : "FormViewItem",
531
+ inheritAttrs: !1,
532
+ props: Et,
533
+ setup(t, { slots: o, attrs: n }) {
534
+ const r = se(), l = ut(), s = j(xe, null);
535
+ if (e != null && !s)
536
+ throw new Error(
537
+ "[vue-formless] useFormItem(port) must be used inside a namespaced control."
538
+ );
539
+ return () => Ft(
540
+ r,
541
+ l,
542
+ s,
543
+ e,
544
+ o,
545
+ n,
546
+ t
547
+ );
548
+ }
549
+ });
550
+ }
551
+ const $e = Re();
552
+ function Ct(e) {
553
+ return se(), e === void 0 ? $e : Re(e);
554
+ }
555
+ function Ft(e, t, o, n, r, l, s) {
556
+ const { fl: u, rest: c } = Le(l), { row: i, col: m, rest: g } = Ve(c), p = { ...u, ...Fe(s) }, { itemAttrs: E, itemOn: b, inputAttrs: L } = ke(g), C = { ...E, ...L }, { itemSlots: w } = Oe(r), f = n == null && o != null, F = s["col:span"] ?? m.span, V = s["col:place"] ?? m.place, a = o?.getFrame(), k = F ?? (f ? a?.colSpan : void 0), _ = V ?? (f ? a?.colPlace : void 0), W = St(e, o, n, p), U = Ae(e.model, W.binding, e.update), J = r.default?.({ field: U }) ?? null;
557
+ !f && (i.column != null || i.gutter != null) && console.warn("[vue-formless] :row:* is ignored on a leaf cell");
558
+ let S = C, A = b, G = w;
559
+ f && a && (S = { ...a.itemAttrs, ...C }, A = { ...a.itemOn, ...b }, G = { ...a.itemSlots, ...w });
560
+ let M, Y, N = !1;
561
+ f && a && (M = a.wrapItem, Y = a.wrapCol, N = a.extraRow);
562
+ let h = J;
563
+ if (N && a) {
564
+ const T = h;
565
+ h = y(
566
+ e.LayoutView,
567
+ {
568
+ disabled: !e.isLayoutEnabled(),
569
+ column: a.rowColumn ?? e.factoryColumn,
570
+ gutter: a.rowGutter ?? e.factoryGutter
571
+ },
572
+ () => T
573
+ );
574
+ }
575
+ if (h = e.wrap(h, {
576
+ item: M === !1 ? !1 : M === !0 ? !0 : void 0,
577
+ fl: W.fl,
578
+ itemAttrs: S,
579
+ itemOn: A,
580
+ itemSlots: G
581
+ }), Y !== !1) {
582
+ const T = h;
583
+ h = y(t, { span: k, place: _ }, () => T);
584
+ }
585
+ return h;
586
+ }
587
+ function St(e, t, o, n) {
588
+ const r = ie(n);
589
+ if (t) {
590
+ const i = t.getFrame(), m = o != null ? gt(i.binding, o) : i.binding, g = {
591
+ ...i.fl,
592
+ ...r,
593
+ controlKey: t.controlKey,
594
+ binding: m,
595
+ getValues: () => m.props.map((p) => B(e.model, p))
596
+ };
597
+ return { binding: m, fl: g };
598
+ }
599
+ const l = n.prop;
600
+ if (l === "")
601
+ throw new Error("[vue-formless] fl:prop cannot be an empty string");
602
+ const s = typeof l == "string" ? l : Array.isArray(l) && l[0] ? String(l[0]) : "", u = l === void 0 ? { models: ["modelValue"], props: [] } : Se(s || "field", {
603
+ prop: l
604
+ }), c = {
605
+ ...r,
606
+ controlKey: s,
607
+ binding: u,
608
+ getValues: () => u.props.map((i) => B(e.model, i))
609
+ };
610
+ return { binding: u, fl: c };
611
+ }
612
+ function Pe(e) {
613
+ const t = e;
614
+ return t.Item = $e, t;
615
+ }
616
+ const le = 0;
617
+ function At(e) {
618
+ return new Proxy(
619
+ {},
620
+ {
621
+ get(t, o) {
622
+ const n = e.value;
623
+ if (n == null) return;
624
+ const r = Reflect.get(n, o, n);
625
+ return typeof r == "function" ? r.bind(n) : r;
626
+ },
627
+ has(t, o) {
628
+ return e.value != null && o in e.value;
629
+ }
630
+ }
631
+ );
632
+ }
633
+ const je = {
634
+ modelValue: {
635
+ type: [Object, Array],
636
+ default: void 0
637
+ },
638
+ "fl:layout": {
639
+ type: Boolean,
640
+ default: !1
641
+ },
642
+ "row:column": { type: Number, default: void 0 },
643
+ "row:gutter": { type: Number, default: void 0 },
644
+ "fl:form": {
645
+ type: [Boolean, String],
646
+ default: "auto"
647
+ },
648
+ "fl:item": {
649
+ type: Boolean,
650
+ default: !0
651
+ }
652
+ }, _e = {
653
+ "update:modelValue": (e) => !0
654
+ };
655
+ function X(e) {
656
+ if (e != null && typeof e == "object")
657
+ throw new Error("[vue-formless] fl:layout is boolean only; use :row:column / :row:gutter");
658
+ return e === !0 || e === "";
659
+ }
660
+ function Ot(e, t) {
661
+ return e === !0 || e === !1 ? e : !t;
662
+ }
663
+ function Lt(e) {
664
+ return e == null ? !1 : "modelValue" in e || "model-value" in e || "onUpdate:modelValue" in e || "onUpdate:model-value" in e;
665
+ }
666
+ function Me(e) {
667
+ const t = yt({
668
+ Item: e.Item,
669
+ itemProps: e.itemProps,
670
+ isItemEnabled: e.isItemEnabled
671
+ }), o = e.isItemEnabled ?? (() => !0);
672
+ H(
673
+ Z,
674
+ Ye({
675
+ get model() {
676
+ return e.getModel();
677
+ },
678
+ update: e.update,
679
+ wrap: t,
680
+ isItemEnabled: o,
681
+ isLayoutEnabled: e.isLayoutEnabled,
682
+ LayoutView: O(e.LayoutView),
683
+ factoryColumn: e.factoryColumn,
684
+ factoryGutter: e.factoryGutter
685
+ })
686
+ );
687
+ }
688
+ function Ne(e, t) {
689
+ const o = j(Z, null);
690
+ if (Lt(Ge()?.vnode.props)) {
691
+ const r = Xe(e, t);
692
+ return { getModel: e, update: r.update };
693
+ }
694
+ if (o)
695
+ return {
696
+ getModel: () => o.model,
697
+ update: o.update
698
+ };
699
+ throw new Error("[vue-formless] FormView requires v-model unless nested inside another FormView.");
700
+ }
701
+ function Vt(e) {
702
+ if (e != null) {
703
+ if (e.Row == null || e.Col == null)
704
+ throw new Error("[vue-formless] createFormView layout requires both Row and Col.");
705
+ return {
706
+ Row: O(e.Row),
707
+ Col: O(e.Col),
708
+ column: e.column,
709
+ gutter: e.gutter
710
+ };
711
+ }
712
+ }
713
+ function Nt(e = {}) {
714
+ const t = Vt(e.layout), o = e.form?.component ? O(e.form.component) : void 0, n = e.form?.props, r = e.item?.component ? O(e.item.component) : void 0, l = e.item?.props, s = Ce(
715
+ t ? { Row: t.Row, Col: t.Col } : {}
716
+ ), u = t?.column ?? P.column, c = t?.gutter ?? le;
717
+ return Pe(
718
+ I({
719
+ name: "FormView",
720
+ inheritAttrs: !1,
721
+ props: je,
722
+ emits: _e,
723
+ setup(i, { slots: m, emit: g, attrs: p, expose: E }) {
724
+ const b = q(null);
725
+ E(At(b));
726
+ const L = j(Z, null) != null, { getModel: C, update: w } = Ne(
727
+ () => i.modelValue,
728
+ (f) => g("update:modelValue", f)
729
+ );
730
+ return Me({
731
+ getModel: C,
732
+ update: w,
733
+ Item: r,
734
+ itemProps: l,
735
+ isItemEnabled: () => i["fl:item"] !== !1,
736
+ isLayoutEnabled: () => X(i["fl:layout"]),
737
+ LayoutView: s,
738
+ factoryColumn: u,
739
+ factoryGutter: c
740
+ }), () => {
741
+ const f = m.default?.() ?? null, F = X(i["fl:layout"]), V = {
742
+ column: i["row:column"] ?? u,
743
+ gutter: i["row:gutter"] ?? c
744
+ }, a = y(
745
+ s,
746
+ { disabled: !F, column: V.column, gutter: V.gutter },
747
+ () => f
748
+ ), k = o ? Ot(i["fl:form"], L) : !1;
749
+ if (!o || !k) return a;
750
+ const _ = {
751
+ layout: F,
752
+ form: k,
753
+ item: i["fl:item"] !== !1,
754
+ modelValue: C()
755
+ };
756
+ return y(
757
+ o,
758
+ {
759
+ ref: b,
760
+ ...ae(K(n, _), p)
761
+ },
762
+ { default: () => a }
763
+ );
764
+ };
765
+ }
766
+ })
767
+ );
768
+ }
769
+ const ge = Ce(), Tt = Pe(
770
+ I({
771
+ name: "FormView",
772
+ inheritAttrs: !1,
773
+ props: je,
774
+ emits: _e,
775
+ setup(e, { slots: t, emit: o }) {
776
+ const { getModel: n, update: r } = Ne(
777
+ () => e.modelValue,
778
+ (l) => o("update:modelValue", l)
779
+ );
780
+ return Me({
781
+ getModel: n,
782
+ update: r,
783
+ isLayoutEnabled: () => X(e["fl:layout"]),
784
+ LayoutView: ge,
785
+ factoryColumn: P.column,
786
+ factoryGutter: le
787
+ }), () => y(
788
+ ge,
789
+ {
790
+ disabled: !X(e["fl:layout"]),
791
+ column: e["row:column"] ?? P.column,
792
+ gutter: e["row:gutter"] ?? le
793
+ },
794
+ () => t.default?.() ?? null
795
+ );
796
+ }
797
+ })
798
+ );
799
+ function Te(e) {
800
+ return e && e.charAt(0).toUpperCase() + e.slice(1);
801
+ }
802
+ function Bt(e) {
803
+ return e && e.charAt(0).toLowerCase() + e.slice(1);
804
+ }
805
+ function kt(e, t) {
806
+ if (e === "self" && t === !1 || e === !1 && t === "self")
807
+ throw new Error(
808
+ '[vue-formless] formless.item "self" conflicts with schema item: false'
809
+ );
810
+ return e ?? t;
811
+ }
812
+ function xt(e) {
813
+ const t = e.internalItem === "self";
814
+ let o;
815
+ e.tagItem === !0 ? o = !0 : e.tagItem === !1 || t || e.internalItem === !1 ? o = !1 : e.internalItem === !0 ? o = !0 : o = e.pageItem;
816
+ let n = e.pageLayoutOn;
817
+ t && e.tagItem !== !0 && (o = !1, n = !1);
818
+ const r = t && e.tagItem === !0 && e.pageLayoutOn;
819
+ return { wrapItem: o, wrapCol: n, extraRow: r, self: t };
820
+ }
821
+ const Rt = {
822
+ "fl:prop": { type: [String, Array], default: void 0 },
823
+ "fl:item": { type: Boolean, default: void 0 },
824
+ "col:span": { type: [String, Number], default: void 0 },
825
+ "col:place": { type: String, default: void 0 },
826
+ "row:column": { type: Number, default: void 0 },
827
+ "row:gutter": { type: Number, default: void 0 }
828
+ };
829
+ function Wt(e, t) {
830
+ const o = jt(e), n = {};
831
+ for (const r of Object.keys(o)) {
832
+ const l = o[r];
833
+ if (!l) continue;
834
+ const s = Te(r);
835
+ n[s] = $t(
836
+ r,
837
+ l,
838
+ t
839
+ );
840
+ }
841
+ return n;
842
+ }
843
+ function $t(e, t, o) {
844
+ const n = pt(t.component), r = n.model ?? t.model, l = kt(n.item, t.item);
845
+ return I({
846
+ name: `Control_${Te(e)}`,
847
+ inheritAttrs: !1,
848
+ props: Rt,
849
+ setup(s, { attrs: u, slots: c }) {
850
+ const i = se();
851
+ let m;
852
+ It({
853
+ controlKey: e,
854
+ getFrame: () => m
855
+ });
856
+ const g = Ct();
857
+ return () => {
858
+ const { fl: p, rest: E } = Le(u), { row: b, col: L, rest: C } = Ve(E), w = { ...p, ...Fe(s) }, f = Se(
859
+ e,
860
+ { model: r, prop: t.prop },
861
+ {
862
+ prop: w.prop
863
+ }
864
+ ), F = t.component, { itemSlots: V, inputSlots: a } = Oe(c), { itemAttrs: k, itemOn: _, inputAttrs: W } = ke(C), U = dt(t), J = w.item === !0 ? !0 : w.item === !1 ? !1 : void 0, S = xt({
865
+ pageItem: i.isItemEnabled(),
866
+ pageLayoutOn: i.isLayoutEnabled(),
867
+ internalItem: l,
868
+ tagItem: J
869
+ }), A = Pt(i, e, f, U, w), G = ae(
870
+ K(o?.props, A),
871
+ K(t.props, A),
872
+ wt(W, f.models)
873
+ ), M = Ae(i.model, f, i.update), Y = f.props[0] ?? e, N = typeof A.label == "string" ? A.label : void 0, h = s["col:span"] ?? L.span, T = s["col:place"] ?? L.place, ce = we(s["row:column"] ?? b.column), fe = we(s["row:gutter"] ?? b.gutter);
874
+ !S.extraRow && (ce != null || fe != null) && console.warn("[vue-formless] :row:* is ignored on a leaf control");
875
+ const Be = F ? y(
876
+ F,
877
+ {
878
+ ...G,
879
+ ...M
880
+ },
881
+ a
882
+ ) : y(
883
+ "div",
884
+ { class: "vue-formless-control", "data-control": e },
885
+ [
886
+ N ? y("label", { class: "vue-formless-control__label" }, String(N)) : null,
887
+ String(B(i.model, Y) ?? "")
888
+ ]
889
+ );
890
+ return m = {
891
+ fl: {
892
+ ...U,
893
+ ...ie(w)
894
+ },
895
+ binding: f,
896
+ wrapItem: S.wrapItem,
897
+ wrapCol: S.wrapCol,
898
+ extraRow: S.extraRow,
899
+ colSpan: h,
900
+ colPlace: T,
901
+ rowColumn: ce,
902
+ rowGutter: fe,
903
+ itemAttrs: k,
904
+ itemOn: _,
905
+ itemSlots: V
906
+ }, y(g, null, () => Be);
907
+ };
908
+ }
909
+ });
910
+ }
911
+ function Pt(e, t, o, n, r) {
912
+ return {
913
+ ...n,
914
+ ...ie(r),
915
+ controlKey: t,
916
+ binding: o,
917
+ getValues: () => o.props.map((l) => B(e.model, l))
918
+ };
919
+ }
920
+ function jt(e) {
921
+ const t = {
922
+ ...e
923
+ };
924
+ for (const o of Object.keys(t)) {
925
+ const n = t[o];
926
+ n && (t[o] = {
927
+ ...n,
928
+ component: n.component && typeof n.component == "object" ? O(n.component) : n.component
929
+ });
930
+ }
931
+ return t;
932
+ }
933
+ export {
934
+ P as DEFAULT_LAYOUT,
935
+ Tt as FormView,
936
+ $e as FormViewItem,
937
+ d as GRID_TOTAL,
938
+ Ae as applyControlBinding,
939
+ gt as bindingForPort,
940
+ Te as camelToPascal,
941
+ Wt as createFormControls,
942
+ Nt as createFormView,
943
+ Ce as createLayoutView,
944
+ Z as formContextKey,
945
+ Ke as formItemProp,
946
+ B as getIn,
947
+ kt as mergeInternalItem,
948
+ ae as overlayProps,
949
+ ue as parsePath,
950
+ Bt as pascalToCamel,
951
+ Se as resolveControlBinding,
952
+ xt as resolveControlShell,
953
+ Mt as resolveFormItemProp,
954
+ K as resolveProps,
955
+ De as setIn,
956
+ de as toBindingList,
957
+ se as useFormContext,
958
+ Ct as useFormItem,
959
+ ut as useLayoutItem
960
+ };