@vtable-guild/vtable-guild 2.9.0-alpha.1 → 2.9.0-alpha.2
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/css/presets/antdv.css +10 -0
- package/css/presets/element-plus.css +10 -0
- package/css/style.css +138 -0
- package/css/tailwind3-utilities.css +118 -0
- package/css/tailwind3.css +20 -0
- package/css/tailwind4.css +20 -0
- package/dist/core/src/components/Button.d.ts +9 -0
- package/dist/core/src/components/Button.d.ts.map +1 -1
- package/dist/core/src/components/Button.mjs +11 -6
- package/dist/css/presets/antdv.css +10 -0
- package/dist/css/presets/element-plus.css +10 -0
- package/dist/css/style.css +138 -0
- package/dist/css/tailwind3-utilities.css +118 -0
- package/dist/css/tailwind3.css +20 -0
- package/dist/css/tailwind4.css +20 -0
- package/dist/icons/src/CheckCircleFilledIcon.d.ts +3 -0
- package/dist/icons/src/CheckCircleFilledIcon.d.ts.map +1 -0
- package/dist/icons/src/CheckCircleFilledIcon.mjs +9 -0
- package/dist/icons/src/CloseCircleFilledIcon.d.ts +3 -0
- package/dist/icons/src/CloseCircleFilledIcon.d.ts.map +1 -0
- package/dist/icons/src/CloseCircleFilledIcon.mjs +9 -0
- package/dist/icons/src/index.d.ts +2 -0
- package/dist/icons/src/index.d.ts.map +1 -1
- package/dist/index.full.mjs +6479 -5272
- package/dist/index.mjs +118 -98
- package/dist/table/src/components/Table.d.ts +3 -3
- package/dist/table/src/components/Table.d.ts.map +1 -1
- package/dist/table/src/components/Table.mjs +153 -149
- package/dist/table/src/components/TableCell.d.ts.map +1 -1
- package/dist/table/src/components/TableCell.mjs +109 -86
- package/dist/table/src/components/TableEditableCell.d.ts +29 -0
- package/dist/table/src/components/TableEditableCell.d.ts.map +1 -0
- package/dist/table/src/components/TableEditableCell.mjs +39 -0
- package/dist/table/src/components/TableEditableCell.test.d.ts +2 -0
- package/dist/table/src/components/TableEditableCell.test.d.ts.map +1 -0
- package/dist/table/src/components/TableQuery.d.ts +108 -0
- package/dist/table/src/components/TableQuery.d.ts.map +1 -0
- package/dist/table/src/components/TableQuery.mjs +244 -0
- package/dist/table/src/components/TableQuery.test.d.ts +2 -0
- package/dist/table/src/components/TableQuery.test.d.ts.map +1 -0
- package/dist/table/src/components/VTableEditCell.vue.d.ts +19 -0
- package/dist/table/src/components/VTableEditCell.vue.d.ts.map +1 -0
- package/dist/table/src/components/VTableEditCell.vue.mjs +21 -0
- package/dist/table/src/components/VTableEditCell.vue2.mjs +4 -0
- package/dist/table/src/components/VTableQuery.vue.d.ts +18 -0
- package/dist/table/src/components/VTableQuery.vue.d.ts.map +1 -0
- package/dist/table/src/components/VTableQuery.vue.mjs +64 -0
- package/dist/table/src/components/VTableQuery.vue2.mjs +4 -0
- package/dist/table/src/composables/useTableDictionary.d.ts +5 -0
- package/dist/table/src/composables/useTableDictionary.d.ts.map +1 -0
- package/dist/table/src/composables/useTableDictionary.mjs +168 -0
- package/dist/table/src/composables/useTableDictionary.test.d.ts +2 -0
- package/dist/table/src/composables/useTableDictionary.test.d.ts.map +1 -0
- package/dist/table/src/composables/useTableEdit.d.ts.map +1 -1
- package/dist/table/src/composables/useTableEdit.mjs +352 -135
- package/dist/table/src/composables/useTableEditable.d.ts +4 -0
- package/dist/table/src/composables/useTableEditable.d.ts.map +1 -0
- package/dist/table/src/composables/useTableEditable.mjs +125 -0
- package/dist/table/src/composables/useTableEditable.test.d.ts +2 -0
- package/dist/table/src/composables/useTableEditable.test.d.ts.map +1 -0
- package/dist/table/src/composables/useTableQuery.d.ts.map +1 -1
- package/dist/table/src/composables/useTableQuery.mjs +33 -33
- package/dist/table/src/composables/useTableRequest.d.ts.map +1 -1
- package/dist/table/src/composables/useTableRequest.mjs +138 -97
- package/dist/table/src/composables/useTableRequest.polling.test.d.ts +2 -0
- package/dist/table/src/composables/useTableRequest.polling.test.d.ts.map +1 -0
- package/dist/table/src/context.d.ts +4 -0
- package/dist/table/src/context.d.ts.map +1 -1
- package/dist/table/src/controls.d.ts +4 -0
- package/dist/table/src/controls.d.ts.map +1 -0
- package/dist/table/src/controls.mjs +97 -0
- package/dist/table/src/controls.test.d.ts +2 -0
- package/dist/table/src/controls.test.d.ts.map +1 -0
- package/dist/table/src/index.d.ts +10 -0
- package/dist/table/src/index.d.ts.map +1 -1
- package/dist/table/src/renderers.d.ts.map +1 -1
- package/dist/table/src/renderers.mjs +88 -23
- package/dist/table/src/review-current.repro.test.d.ts +2 -0
- package/dist/table/src/review-current.repro.test.d.ts.map +1 -0
- package/dist/table/src/types/column.d.ts +4 -1
- package/dist/table/src/types/column.d.ts.map +1 -1
- package/dist/table/src/types/controls.d.ts +31 -0
- package/dist/table/src/types/controls.d.ts.map +1 -0
- package/dist/table/src/types/dictionary.d.ts +71 -0
- package/dist/table/src/types/dictionary.d.ts.map +1 -0
- package/dist/table/src/types/dictionary.typecheck.d.ts +6 -0
- package/dist/table/src/types/dictionary.typecheck.d.ts.map +1 -0
- package/dist/table/src/types/editable.d.ts +49 -0
- package/dist/table/src/types/editable.d.ts.map +1 -0
- package/dist/table/src/types/editable.typecheck.d.ts +15 -0
- package/dist/table/src/types/editable.typecheck.d.ts.map +1 -0
- package/dist/table/src/types/editing.d.ts +41 -4
- package/dist/table/src/types/editing.d.ts.map +1 -1
- package/dist/table/src/types/editing.typecheck.d.ts.map +1 -1
- package/dist/table/src/types/index.d.ts +4 -0
- package/dist/table/src/types/index.d.ts.map +1 -1
- package/dist/table/src/types/query-form.d.ts +90 -0
- package/dist/table/src/types/query-form.d.ts.map +1 -0
- package/dist/table/src/types/query-form.typecheck.d.ts +10 -0
- package/dist/table/src/types/query-form.typecheck.d.ts.map +1 -0
- package/dist/table/src/types/query.d.ts +6 -2
- package/dist/table/src/types/query.d.ts.map +1 -1
- package/dist/table/src/types/renderers.d.ts +15 -3
- package/dist/table/src/types/renderers.d.ts.map +1 -1
- package/dist/table/src/types/request.d.ts +20 -2
- package/dist/table/src/types/request.d.ts.map +1 -1
- package/dist/table/src/types/request.typecheck.d.ts.map +1 -1
- package/dist/table/src/utils/cell.d.ts +3 -2
- package/dist/table/src/utils/cell.d.ts.map +1 -1
- package/dist/table/src/utils/cell.mjs +45 -44
- package/dist/table/src/utils/fieldPath.d.ts +6 -0
- package/dist/table/src/utils/fieldPath.d.ts.map +1 -0
- package/dist/table/src/utils/fieldPath.mjs +29 -0
- package/dist/table/src/utils/queryFields.d.ts +4 -0
- package/dist/table/src/utils/queryFields.d.ts.map +1 -0
- package/dist/table/src/utils/queryFields.mjs +31 -0
- package/dist/table/src/utils/queryFields.test.d.ts +2 -0
- package/dist/table/src/utils/queryFields.test.d.ts.map +1 -0
- package/dist/table/src/utils/stateEqual.d.ts +3 -0
- package/dist/table/src/utils/stateEqual.d.ts.map +1 -0
- package/dist/table/src/utils/stateEqual.mjs +15 -0
- package/dist/theme/src/index.d.ts +4 -0
- package/dist/theme/src/index.d.ts.map +1 -1
- package/dist/theme/src/presets/antdv/table.d.ts +7 -0
- package/dist/theme/src/presets/antdv/table.d.ts.map +1 -1
- package/dist/theme/src/presets/antdv/table.mjs +7 -0
- package/dist/theme/src/presets/element-plus/table.d.ts +7 -0
- package/dist/theme/src/presets/element-plus/table.d.ts.map +1 -1
- package/dist/theme/src/presets/element-plus/table.mjs +7 -0
- package/dist/theme/src/query.d.ts +128 -0
- package/dist/theme/src/query.d.ts.map +1 -0
- package/dist/theme/src/query.mjs +56 -0
- package/dist/vtable-guild/src/augment.d.ts +2 -1
- package/dist/vtable-guild/src/augment.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,183 +1,400 @@
|
|
|
1
|
-
import { shallowRef as
|
|
2
|
-
import { snapshot as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { shallowRef as N, toValue as F, watch as ne, getCurrentScope as oe, onScopeDispose as ae, computed as x, nextTick as se } from "vue";
|
|
2
|
+
import { snapshot as Y } from "../utils/snapshot.mjs";
|
|
3
|
+
import { stateEqual as ie } from "../utils/stateEqual.mjs";
|
|
4
|
+
function fe(l) {
|
|
5
|
+
const i = N(/* @__PURE__ */ new Map()), M = N(/* @__PURE__ */ new Map()), m = N(/* @__PURE__ */ new Map()), p = N(/* @__PURE__ */ new Map()), S = N(), h = N(), o = l.clone ?? ((e) => Y(e));
|
|
6
|
+
let y = !1;
|
|
7
|
+
function g(e) {
|
|
8
|
+
const t = typeof l.rowKey == "function" ? l.rowKey(e) : e[l.rowKey];
|
|
8
9
|
if (typeof t != "string" && typeof t != "number")
|
|
9
10
|
throw new Error("useTableEdit requires a string or number row key");
|
|
10
11
|
return t;
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
13
|
+
function P() {
|
|
14
|
+
const e = [...h.value ?? F(l.dataSource) ?? []], t = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const r of e) {
|
|
16
|
+
const s = g(r);
|
|
17
|
+
if (t.has(s)) throw new Error("useTableEdit requires unique source row keys");
|
|
18
|
+
t.add(s);
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
16
21
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
22
|
+
function I(e) {
|
|
23
|
+
const t = h.value, r = e.map(o);
|
|
24
|
+
h.value = r;
|
|
19
25
|
try {
|
|
20
|
-
|
|
26
|
+
l.onChange(e);
|
|
27
|
+
} catch (s) {
|
|
28
|
+
throw h.value === r && (h.value = t), s;
|
|
29
|
+
} finally {
|
|
30
|
+
se(() => {
|
|
31
|
+
h.value === r && (h.value = void 0, b());
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function b() {
|
|
36
|
+
const e = S.value;
|
|
37
|
+
e && (S.value = void 0, e.controller.abort(), e.resolve({ valid: !1, errors: /* @__PURE__ */ new Map(), obsolete: !0 }));
|
|
38
|
+
}
|
|
39
|
+
function B(e, t, r) {
|
|
40
|
+
return {
|
|
41
|
+
key: e,
|
|
42
|
+
original: t.original === void 0 ? void 0 : o(t.original),
|
|
43
|
+
isNew: t.isNew,
|
|
44
|
+
signal: r
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function G(e, t, r, s) {
|
|
48
|
+
const v = l.toDraft?.(o(e), {
|
|
49
|
+
key: t,
|
|
50
|
+
original: r === void 0 ? void 0 : o(r),
|
|
51
|
+
isNew: s
|
|
52
|
+
}) ?? e;
|
|
53
|
+
if (g(v) !== t) throw new Error("Converting an editor cannot change its row key");
|
|
54
|
+
return o(v);
|
|
55
|
+
}
|
|
56
|
+
function z(e, t, r) {
|
|
57
|
+
const s = o(t.draft), v = l.toValue?.(s, B(e, t, r)) ?? s;
|
|
58
|
+
if (g(v) !== e)
|
|
59
|
+
throw new Error("Converting a submission cannot change its row key");
|
|
60
|
+
return o(v);
|
|
61
|
+
}
|
|
62
|
+
function D(e, t = new AbortController().signal) {
|
|
63
|
+
const r = P(), s = new Set(r.map(g)), v = (d, u) => e ? z(d, u, t) : o(u.draft), f = r.map((d) => {
|
|
64
|
+
const u = g(d), n = i.value.get(u);
|
|
65
|
+
if (e && n?.isNew) throw new Error("A cached new row duplicates a source row key");
|
|
66
|
+
return n ? v(u, n) : o(d);
|
|
67
|
+
}), c = [], a = [];
|
|
68
|
+
for (const [d, u] of i.value) {
|
|
69
|
+
if (s.has(d)) continue;
|
|
70
|
+
const n = v(d, u);
|
|
71
|
+
u.position === "top" ? c.unshift(n) : a.push(n);
|
|
72
|
+
}
|
|
73
|
+
return [...c, ...f, ...a];
|
|
74
|
+
}
|
|
75
|
+
function K(e) {
|
|
76
|
+
if (!M.value.has(e)) return;
|
|
77
|
+
const t = new Map(M.value);
|
|
78
|
+
t.delete(e), M.value = t;
|
|
79
|
+
}
|
|
80
|
+
function q(e, t) {
|
|
81
|
+
M.value = new Map(M.value).set(e, t);
|
|
82
|
+
try {
|
|
83
|
+
l.onError?.(t, e);
|
|
21
84
|
} catch {
|
|
22
85
|
}
|
|
23
86
|
}
|
|
24
|
-
function
|
|
25
|
-
const t =
|
|
87
|
+
function R(e) {
|
|
88
|
+
const t = m.value.get(e);
|
|
26
89
|
if (!t) return;
|
|
27
90
|
t.controller.abort();
|
|
28
|
-
const
|
|
29
|
-
|
|
91
|
+
const r = new Map(m.value);
|
|
92
|
+
r.delete(e), m.value = r, t.resolve(void 0);
|
|
30
93
|
}
|
|
31
|
-
function
|
|
32
|
-
const t =
|
|
94
|
+
function T(e) {
|
|
95
|
+
const t = p.value.get(e);
|
|
33
96
|
if (!t) return;
|
|
34
97
|
t.controller.abort();
|
|
35
|
-
const
|
|
36
|
-
|
|
98
|
+
const r = new Map(p.value);
|
|
99
|
+
r.delete(e), p.value = r, t.resolve(!1);
|
|
37
100
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
const t = new Map(
|
|
41
|
-
t.delete(e),
|
|
101
|
+
function O(e) {
|
|
102
|
+
b(), R(e), T(e);
|
|
103
|
+
const t = new Map(i.value);
|
|
104
|
+
t.delete(e), i.value = t, K(e);
|
|
42
105
|
}
|
|
43
|
-
function
|
|
44
|
-
const t =
|
|
106
|
+
function H(e) {
|
|
107
|
+
const t = p.value.get(e);
|
|
45
108
|
if (t) return t.promise;
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
50
|
-
let
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
}),
|
|
54
|
-
|
|
55
|
-
const
|
|
109
|
+
const r = i.value.get(e);
|
|
110
|
+
if (y || !r) return Promise.resolve(!1);
|
|
111
|
+
if (b(), R(e), K(e), !l.onCancel)
|
|
112
|
+
return O(e), Promise.resolve(!0);
|
|
113
|
+
let s;
|
|
114
|
+
const v = new Promise((a) => {
|
|
115
|
+
s = a;
|
|
116
|
+
}), f = { controller: new AbortController(), promise: v, resolve: s };
|
|
117
|
+
p.value = new Map(p.value).set(e, f);
|
|
118
|
+
const c = () => !y && p.value.get(e) === f;
|
|
56
119
|
return (async () => {
|
|
57
120
|
try {
|
|
58
|
-
const
|
|
121
|
+
const a = await l.onCancel(o(r.draft), {
|
|
59
122
|
key: e,
|
|
60
|
-
original:
|
|
61
|
-
isNew:
|
|
62
|
-
signal:
|
|
123
|
+
original: r.original === void 0 ? void 0 : o(r.original),
|
|
124
|
+
isNew: r.isNew,
|
|
125
|
+
signal: f.controller.signal
|
|
63
126
|
});
|
|
64
|
-
if (!
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
67
|
-
if (!
|
|
68
|
-
const
|
|
127
|
+
if (!c() || a === !1) return;
|
|
128
|
+
f.resolve(!0), O(e);
|
|
129
|
+
} catch (a) {
|
|
130
|
+
if (!c()) return;
|
|
131
|
+
const d = {
|
|
69
132
|
type: "cancel",
|
|
70
|
-
message:
|
|
71
|
-
cause:
|
|
133
|
+
message: a instanceof Error ? a.message : String(a),
|
|
134
|
+
cause: a
|
|
72
135
|
};
|
|
73
|
-
|
|
136
|
+
q(e, d);
|
|
74
137
|
} finally {
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
77
|
-
|
|
138
|
+
if (c()) {
|
|
139
|
+
const a = new Map(p.value);
|
|
140
|
+
a.delete(e), p.value = a;
|
|
78
141
|
}
|
|
79
|
-
|
|
142
|
+
f.resolve(!1);
|
|
143
|
+
}
|
|
144
|
+
})(), v;
|
|
145
|
+
}
|
|
146
|
+
function Z() {
|
|
147
|
+
return Promise.all([...i.value.keys()].map(H));
|
|
148
|
+
}
|
|
149
|
+
function J(e, t, r = "bottom") {
|
|
150
|
+
if (y) return !1;
|
|
151
|
+
const s = g(e);
|
|
152
|
+
if (i.value.has(s) || l.mode !== "multiple" && i.value.size > 0) return !1;
|
|
153
|
+
const v = t ? void 0 : o(e), f = G(e, s, v, t);
|
|
154
|
+
return b(), i.value = new Map(i.value).set(s, {
|
|
155
|
+
draft: f,
|
|
156
|
+
original: v,
|
|
157
|
+
isNew: t,
|
|
158
|
+
position: r
|
|
159
|
+
}), !0;
|
|
160
|
+
}
|
|
161
|
+
function _(e, t = {}) {
|
|
162
|
+
if (y || l.mode !== "multiple" && i.value.size > 0) return !1;
|
|
163
|
+
const r = P(), s = new Set(r.map(g)), v = s.size + [...i.value.keys()].filter((n) => !s.has(n)).length, f = Number.isFinite(l.maxRows) ? Math.max(0, Math.floor(l.maxRows)) : void 0;
|
|
164
|
+
if (f !== void 0 && v >= f) return !1;
|
|
165
|
+
const c = e ?? l.createRecord?.();
|
|
166
|
+
if (!c) return !1;
|
|
167
|
+
const a = g(c);
|
|
168
|
+
if (s.has(a) || i.value.has(a)) return !1;
|
|
169
|
+
const d = t.mode === "source";
|
|
170
|
+
if (d && (l.dataSource === void 0 || !l.onChange)) return !1;
|
|
171
|
+
const u = t.position ?? "bottom";
|
|
172
|
+
if (!J(c, !d, u)) return !1;
|
|
173
|
+
if (d)
|
|
174
|
+
try {
|
|
175
|
+
const n = r.map(o);
|
|
176
|
+
u === "top" ? n.unshift(o(c)) : n.push(o(c)), I(n);
|
|
177
|
+
} catch (n) {
|
|
178
|
+
return O(a), q(a, {
|
|
179
|
+
type: "save",
|
|
180
|
+
message: n instanceof Error ? n.message : String(n),
|
|
181
|
+
cause: n
|
|
182
|
+
}), !1;
|
|
80
183
|
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
isNew: t
|
|
93
|
-
}), !0);
|
|
94
|
-
}
|
|
95
|
-
function j(e, t) {
|
|
96
|
-
const n = r.value.get(e);
|
|
97
|
-
if (d || !n) return !1;
|
|
98
|
-
const v = typeof t == "function" ? t(a(n.draft)) : { ...a(n.draft), ...t };
|
|
99
|
-
if (E(v) !== e) throw new Error("Editing a row key is unsupported");
|
|
100
|
-
return S(e), N(e), p(e), r.value = new Map(r.value).set(e, { ...n, draft: a(v) }), !0;
|
|
101
|
-
}
|
|
102
|
-
function q(e) {
|
|
103
|
-
const t = c.value.get(e);
|
|
184
|
+
return !0;
|
|
185
|
+
}
|
|
186
|
+
function $(e, t) {
|
|
187
|
+
const r = i.value.get(e);
|
|
188
|
+
if (y || !r) return !1;
|
|
189
|
+
const s = typeof t == "function" ? t(o(r.draft)) : { ...o(r.draft), ...t };
|
|
190
|
+
if (g(s) !== e) throw new Error("Editing a row key is unsupported");
|
|
191
|
+
return b(), R(e), T(e), K(e), i.value = new Map(i.value).set(e, { ...r, draft: o(s) }), !0;
|
|
192
|
+
}
|
|
193
|
+
function ee(e) {
|
|
194
|
+
const t = m.value.get(e);
|
|
104
195
|
if (t) return t.promise;
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
let
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
}),
|
|
112
|
-
|
|
113
|
-
const
|
|
196
|
+
const r = i.value.get(e);
|
|
197
|
+
if (y || !r || p.value.has(e)) return Promise.resolve(void 0);
|
|
198
|
+
b(), K(e);
|
|
199
|
+
let s;
|
|
200
|
+
const v = new Promise((u) => {
|
|
201
|
+
s = u;
|
|
202
|
+
}), f = { controller: new AbortController(), promise: v, resolve: s };
|
|
203
|
+
m.value = new Map(m.value).set(e, f);
|
|
204
|
+
const c = () => !y && m.value.get(e) === f, a = {
|
|
114
205
|
key: e,
|
|
115
|
-
original:
|
|
116
|
-
isNew:
|
|
117
|
-
signal:
|
|
118
|
-
},
|
|
119
|
-
|
|
206
|
+
original: r.original === void 0 ? void 0 : o(r.original),
|
|
207
|
+
isNew: r.isNew,
|
|
208
|
+
signal: f.controller.signal
|
|
209
|
+
}, d = (u) => {
|
|
210
|
+
c() && q(e, u);
|
|
120
211
|
};
|
|
121
212
|
return (async () => {
|
|
122
|
-
let
|
|
213
|
+
let u = "validation";
|
|
123
214
|
try {
|
|
124
|
-
const
|
|
125
|
-
if (!
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
...
|
|
215
|
+
const n = o(r.draft), w = await l.validate?.(o(n), a);
|
|
216
|
+
if (!c()) return;
|
|
217
|
+
if (w?.message || Object.keys(w?.fields ?? {}).length > 0) {
|
|
218
|
+
d({
|
|
219
|
+
...w,
|
|
129
220
|
type: "validation",
|
|
130
|
-
message:
|
|
221
|
+
message: w?.message ?? "Validation failed"
|
|
131
222
|
});
|
|
132
223
|
return;
|
|
133
224
|
}
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
if (!
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
225
|
+
u = "save";
|
|
226
|
+
const E = z(e, { ...r, draft: n }, a.signal), j = await l.onSave?.(o(E), a);
|
|
227
|
+
if (!c() || j === !1) return;
|
|
228
|
+
const U = j === !0 ? E : j ?? E;
|
|
229
|
+
if (!r.isNew && g(U) !== e)
|
|
139
230
|
throw new Error("Saving an existing row cannot change its key");
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
231
|
+
const A = o(U), k = g(A);
|
|
232
|
+
if (k !== e && i.value.has(k))
|
|
233
|
+
throw new Error("Saving a new row cannot duplicate another draft row key");
|
|
234
|
+
if (l.dataSource !== void 0 && l.onChange) {
|
|
235
|
+
const C = P().map(o);
|
|
236
|
+
if (r.isNew && C.some((V) => g(V) === e || g(V) === k))
|
|
237
|
+
throw new Error("Saving a new row cannot duplicate a source row key");
|
|
238
|
+
const X = C.findIndex((V) => g(V) === e);
|
|
239
|
+
if (X >= 0 ? C[X] = o(A) : r.position === "top" ? C.unshift(o(A)) : C.push(o(A)), I(C), !c()) return;
|
|
240
|
+
}
|
|
241
|
+
b();
|
|
242
|
+
const W = new Map(i.value);
|
|
243
|
+
W.delete(e), i.value = W, K(e), f.resolve(A);
|
|
244
|
+
} catch (n) {
|
|
245
|
+
d({
|
|
246
|
+
type: u,
|
|
247
|
+
message: n instanceof Error ? n.message : String(n),
|
|
248
|
+
cause: n
|
|
147
249
|
});
|
|
148
250
|
} finally {
|
|
149
|
-
if (
|
|
150
|
-
const
|
|
151
|
-
|
|
251
|
+
if (c()) {
|
|
252
|
+
const n = new Map(m.value);
|
|
253
|
+
n.delete(e), m.value = n;
|
|
152
254
|
}
|
|
153
|
-
|
|
255
|
+
f.resolve(void 0);
|
|
154
256
|
}
|
|
155
|
-
})(),
|
|
257
|
+
})(), v;
|
|
156
258
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
259
|
+
function te() {
|
|
260
|
+
if (y) return Promise.resolve({ valid: !1, errors: /* @__PURE__ */ new Map(), obsolete: !0 });
|
|
261
|
+
if (S.value) return S.value.promise;
|
|
262
|
+
const e = D(!1), t = new Set(P().map(g)), r = e.map((a) => {
|
|
263
|
+
const d = g(a), u = i.value.get(d);
|
|
264
|
+
return {
|
|
265
|
+
key: d,
|
|
266
|
+
record: o(a),
|
|
267
|
+
entry: u ? {
|
|
268
|
+
...u,
|
|
269
|
+
draft: o(u.draft),
|
|
270
|
+
original: u.original === void 0 ? void 0 : o(u.original)
|
|
271
|
+
} : void 0
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
let s;
|
|
275
|
+
const v = new Promise((a) => {
|
|
276
|
+
s = a;
|
|
277
|
+
}), f = { controller: new AbortController(), promise: v, resolve: s };
|
|
278
|
+
S.value = f;
|
|
279
|
+
const c = () => !y && S.value === f;
|
|
280
|
+
return (async () => {
|
|
281
|
+
const a = /* @__PURE__ */ new Map(), d = [];
|
|
282
|
+
for (const n of r) {
|
|
283
|
+
if (!c()) return;
|
|
284
|
+
try {
|
|
285
|
+
if (n.entry?.isNew && t.has(n.key))
|
|
286
|
+
throw new Error("A cached new row duplicates a source row key");
|
|
287
|
+
const w = n.entry ?? {
|
|
288
|
+
original: o(n.record),
|
|
289
|
+
draft: G(n.record, n.key, n.record, !1),
|
|
290
|
+
isNew: !1,
|
|
291
|
+
position: "bottom"
|
|
292
|
+
}, E = await l.validate?.(
|
|
293
|
+
o(w.draft),
|
|
294
|
+
B(n.key, w, f.controller.signal)
|
|
295
|
+
);
|
|
296
|
+
if (!c()) return;
|
|
297
|
+
(E?.message || Object.keys(E?.fields ?? {}).length) && a.set(n.key, {
|
|
298
|
+
...E,
|
|
299
|
+
type: "validation",
|
|
300
|
+
message: E?.message ?? "Validation failed"
|
|
301
|
+
});
|
|
302
|
+
} catch (w) {
|
|
303
|
+
if (!c()) return;
|
|
304
|
+
a.set(n.key, {
|
|
305
|
+
type: "validation",
|
|
306
|
+
message: w instanceof Error ? w.message : String(w),
|
|
307
|
+
cause: w
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!c()) return;
|
|
312
|
+
if (!a.size)
|
|
313
|
+
for (const n of r) {
|
|
314
|
+
try {
|
|
315
|
+
d.push(
|
|
316
|
+
n.entry ? z(n.key, n.entry, f.controller.signal) : o(n.record)
|
|
317
|
+
);
|
|
318
|
+
} catch (w) {
|
|
319
|
+
a.set(n.key, {
|
|
320
|
+
type: "validation",
|
|
321
|
+
message: w instanceof Error ? w.message : String(w),
|
|
322
|
+
cause: w
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (!c()) return;
|
|
326
|
+
}
|
|
327
|
+
if (!c()) return;
|
|
328
|
+
const u = new Map([...M.value].filter(([, n]) => n.type !== "validation"));
|
|
329
|
+
for (const [n, w] of a) u.set(n, w);
|
|
330
|
+
M.value = u;
|
|
331
|
+
for (const [n, w] of a) {
|
|
332
|
+
try {
|
|
333
|
+
l.onError?.(Y(w), n);
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
if (!c()) return;
|
|
337
|
+
}
|
|
338
|
+
S.value = void 0, f.resolve({
|
|
339
|
+
valid: a.size === 0,
|
|
340
|
+
errors: new Map(a),
|
|
341
|
+
...a.size ? {} : { values: d.map(o) }
|
|
342
|
+
});
|
|
343
|
+
})(), v;
|
|
344
|
+
}
|
|
345
|
+
function L() {
|
|
346
|
+
b(), h.value = void 0;
|
|
347
|
+
for (const e of m.value.keys()) R(e);
|
|
348
|
+
for (const e of p.value.keys()) T(e);
|
|
349
|
+
i.value = /* @__PURE__ */ new Map(), M.value = /* @__PURE__ */ new Map();
|
|
350
|
+
}
|
|
351
|
+
let Q = F(l.dataSource)?.map(o);
|
|
352
|
+
const re = l.dataSource === void 0 ? void 0 : ne(
|
|
353
|
+
() => F(l.dataSource),
|
|
354
|
+
(e) => {
|
|
355
|
+
h.value && (h.value = void 0, b()), !ie(Q, e) && (Q = e?.map(o), b());
|
|
356
|
+
},
|
|
357
|
+
{ deep: !0, flush: "sync" }
|
|
358
|
+
);
|
|
359
|
+
return oe() && ae(() => {
|
|
360
|
+
y = !0, re?.(), L();
|
|
160
361
|
}), {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
168
|
-
|
|
362
|
+
records: x(() => D(!1)),
|
|
363
|
+
validating: x(() => !!S.value),
|
|
364
|
+
editableKeys: x(() => [...i.value.keys()]),
|
|
365
|
+
savingKeys: x(() => new Set(m.value.keys())),
|
|
366
|
+
cancellingKeys: x(() => new Set(p.value.keys())),
|
|
367
|
+
errors: x(() => new Map(M.value)),
|
|
368
|
+
newRecords: x(() => {
|
|
369
|
+
const e = [], t = [];
|
|
370
|
+
for (const r of i.value.values()) {
|
|
371
|
+
if (!r.isNew) continue;
|
|
372
|
+
const s = o(r.draft);
|
|
373
|
+
r.position === "top" ? e.unshift(s) : t.push(s);
|
|
374
|
+
}
|
|
375
|
+
return [...e, ...t];
|
|
376
|
+
}),
|
|
377
|
+
isEditing: (e) => i.value.has(e),
|
|
169
378
|
getDraft: (e) => {
|
|
170
|
-
const t =
|
|
171
|
-
return t ?
|
|
379
|
+
const t = i.value.get(e);
|
|
380
|
+
return t ? o(t.draft) : void 0;
|
|
381
|
+
},
|
|
382
|
+
getOriginal: (e) => {
|
|
383
|
+
const t = i.value.get(e)?.original;
|
|
384
|
+
return t === void 0 ? void 0 : o(t);
|
|
172
385
|
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
386
|
+
getDrafts: () => new Map([...i.value].map(([e, t]) => [e, o(t.draft)])),
|
|
387
|
+
getValues: () => D(!0),
|
|
388
|
+
validateAll: te,
|
|
389
|
+
reset: L,
|
|
390
|
+
start: (e) => J(e, !1),
|
|
391
|
+
add: _,
|
|
392
|
+
setDraft: $,
|
|
393
|
+
save: ee,
|
|
394
|
+
cancel: H,
|
|
395
|
+
cancelAll: Z
|
|
179
396
|
};
|
|
180
397
|
}
|
|
181
398
|
export {
|
|
182
|
-
|
|
399
|
+
fe as useTableEdit
|
|
183
400
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseTableEditableOptions, UseTableEditableReturn } from '../types/editable';
|
|
2
|
+
/** Optional column-to-editor wiring on top of the same useTableEdit row state. */
|
|
3
|
+
export declare function useTableEditable<T extends object>(options: UseTableEditableOptions<T>): UseTableEditableReturn<T>;
|
|
4
|
+
//# sourceMappingURL=useTableEditable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableEditable.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableEditable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,mBAAmB,CAAA;AAkB1B,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAClC,sBAAsB,CAAC,CAAC,CAAC,CAoJ3B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { h as I, toValue as y } from "vue";
|
|
2
|
+
import { useTableEdit as k } from "./useTableEdit.mjs";
|
|
3
|
+
import { snapshot as T } from "../utils/snapshot.mjs";
|
|
4
|
+
import { setField as h, getField as w } from "../utils/fieldPath.mjs";
|
|
5
|
+
import K from "../components/TableEditableCell.mjs";
|
|
6
|
+
import { valueEnumEntries as A } from "../utils/valueEnum.mjs";
|
|
7
|
+
function E(s) {
|
|
8
|
+
return s.flatMap(
|
|
9
|
+
(c) => typeof c == "symbol" ? [] : "children" in c ? E(c.children) : [c]
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function N(s) {
|
|
13
|
+
const c = s.clone ?? T, p = () => E(y(s.columns)).filter(
|
|
14
|
+
(e) => e.editor && e.dataIndex !== void 0
|
|
15
|
+
);
|
|
16
|
+
function g(e, t, r) {
|
|
17
|
+
return {
|
|
18
|
+
...r,
|
|
19
|
+
name: Array.isArray(e.dataIndex) ? e.dataIndex.join(".") : String(e.dataIndex),
|
|
20
|
+
column: e,
|
|
21
|
+
draft: c(t),
|
|
22
|
+
original: r.original && c(r.original),
|
|
23
|
+
value: w(t, e.dataIndex)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function b(e, t, r) {
|
|
27
|
+
const n = c(e);
|
|
28
|
+
for (const a of p()) {
|
|
29
|
+
const l = a.editor, u = r ? l.transform : l.convertValue;
|
|
30
|
+
u && h(
|
|
31
|
+
n,
|
|
32
|
+
a.dataIndex,
|
|
33
|
+
u(w(n, a.dataIndex), g(a, n, t))
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
const f = k({
|
|
39
|
+
...s,
|
|
40
|
+
toDraft: (e, t) => b(e, t, !1),
|
|
41
|
+
toValue: (e, t) => b(e, t, !0),
|
|
42
|
+
async validate(e, t) {
|
|
43
|
+
const r = {};
|
|
44
|
+
for (const n of p()) {
|
|
45
|
+
const a = n.editor, l = g(n, e, t), u = await a.validate?.(l.value, { ...l, signal: t.signal });
|
|
46
|
+
if (t.signal.aborted) return;
|
|
47
|
+
u && (r[l.name] = u);
|
|
48
|
+
}
|
|
49
|
+
return Object.keys(r).length ? { fields: r } : s.validate?.(e, t);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
function x(e) {
|
|
53
|
+
return typeof s.rowKey == "function" ? s.rowKey(e) : e[s.rowKey];
|
|
54
|
+
}
|
|
55
|
+
function m(e) {
|
|
56
|
+
const t = x(e.record), r = f.getDraft(t), n = e.column.editor;
|
|
57
|
+
if (!r || !n || e.column.dataIndex === void 0) return;
|
|
58
|
+
const a = g(e.column, r, {
|
|
59
|
+
key: t,
|
|
60
|
+
original: f.getOriginal(t),
|
|
61
|
+
isNew: f.newRecords.value.some((o) => x(o) === t)
|
|
62
|
+
}), l = (o) => typeof o == "function" ? o(a) : o;
|
|
63
|
+
if (l(n.editable) === !1 || l(n.readonly)) return;
|
|
64
|
+
const u = [
|
|
65
|
+
...y(n.options) ?? y(n.dictionary?.options) ?? A(e.column.valueEnum).flatMap(([o, i]) => {
|
|
66
|
+
const d = typeof i == "string" ? i : i.text;
|
|
67
|
+
return typeof d == "string" ? [{ value: o, label: d, ...typeof i == "object" ? { status: i.status } : {} }] : [];
|
|
68
|
+
})
|
|
69
|
+
];
|
|
70
|
+
for (const o of Array.isArray(a.value) ? a.value : [a.value]) {
|
|
71
|
+
if (typeof o != "string" && typeof o != "number" && typeof o != "boolean" || u.some((v) => v.value === o))
|
|
72
|
+
continue;
|
|
73
|
+
const i = y(n.dictionary?.valueEnum)?.get(o), d = typeof i == "string" ? i : i?.text;
|
|
74
|
+
typeof d == "string" && u.push({ value: o, label: d });
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
key: t,
|
|
78
|
+
column: e.column,
|
|
79
|
+
draft: r,
|
|
80
|
+
value: a.value,
|
|
81
|
+
valueType: n.valueType ?? (e.column.valueEnum ? "select" : e.column.valueType ?? "text"),
|
|
82
|
+
fieldProps: typeof n.fieldProps == "function" ? n.fieldProps(a) : n.fieldProps ?? {},
|
|
83
|
+
options: u,
|
|
84
|
+
onSearch: n.dictionary ? (o) => {
|
|
85
|
+
n.dictionary.search(o);
|
|
86
|
+
} : void 0,
|
|
87
|
+
loading: y(n.dictionary?.loading) ?? !1,
|
|
88
|
+
disabled: !!l(n.disabled) || f.savingKeys.value.has(t) || f.cancellingKeys.value.has(t),
|
|
89
|
+
readonly: !1,
|
|
90
|
+
error: f.errors.value.get(t)?.fields?.[a.name],
|
|
91
|
+
name: a.name,
|
|
92
|
+
mode: "edit",
|
|
93
|
+
onChange(o) {
|
|
94
|
+
const i = m(e);
|
|
95
|
+
i && !i.disabled && f.setDraft(t, (d) => {
|
|
96
|
+
h(d, e.column.dataIndex, o);
|
|
97
|
+
const v = n.onValueChange?.(
|
|
98
|
+
o,
|
|
99
|
+
g(e.column, d, {
|
|
100
|
+
key: t,
|
|
101
|
+
original: f.getOriginal(t),
|
|
102
|
+
isNew: a.isNew
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
return v ? { ...d, ...v } : d;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...f,
|
|
112
|
+
getCell: m,
|
|
113
|
+
renderEditor(e) {
|
|
114
|
+
const t = m(e);
|
|
115
|
+
return t ? I(K, {
|
|
116
|
+
context: t,
|
|
117
|
+
controls: y(s.controls),
|
|
118
|
+
ui: s.ui
|
|
119
|
+
}) : void 0;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
N as useTableEditable
|
|
125
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableEditable.test.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableEditable.test.ts"],"names":[],"mappings":""}
|