@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.
Files changed (135) hide show
  1. package/css/presets/antdv.css +10 -0
  2. package/css/presets/element-plus.css +10 -0
  3. package/css/style.css +138 -0
  4. package/css/tailwind3-utilities.css +118 -0
  5. package/css/tailwind3.css +20 -0
  6. package/css/tailwind4.css +20 -0
  7. package/dist/core/src/components/Button.d.ts +9 -0
  8. package/dist/core/src/components/Button.d.ts.map +1 -1
  9. package/dist/core/src/components/Button.mjs +11 -6
  10. package/dist/css/presets/antdv.css +10 -0
  11. package/dist/css/presets/element-plus.css +10 -0
  12. package/dist/css/style.css +138 -0
  13. package/dist/css/tailwind3-utilities.css +118 -0
  14. package/dist/css/tailwind3.css +20 -0
  15. package/dist/css/tailwind4.css +20 -0
  16. package/dist/icons/src/CheckCircleFilledIcon.d.ts +3 -0
  17. package/dist/icons/src/CheckCircleFilledIcon.d.ts.map +1 -0
  18. package/dist/icons/src/CheckCircleFilledIcon.mjs +9 -0
  19. package/dist/icons/src/CloseCircleFilledIcon.d.ts +3 -0
  20. package/dist/icons/src/CloseCircleFilledIcon.d.ts.map +1 -0
  21. package/dist/icons/src/CloseCircleFilledIcon.mjs +9 -0
  22. package/dist/icons/src/index.d.ts +2 -0
  23. package/dist/icons/src/index.d.ts.map +1 -1
  24. package/dist/index.full.mjs +6479 -5272
  25. package/dist/index.mjs +118 -98
  26. package/dist/table/src/components/Table.d.ts +3 -3
  27. package/dist/table/src/components/Table.d.ts.map +1 -1
  28. package/dist/table/src/components/Table.mjs +153 -149
  29. package/dist/table/src/components/TableCell.d.ts.map +1 -1
  30. package/dist/table/src/components/TableCell.mjs +109 -86
  31. package/dist/table/src/components/TableEditableCell.d.ts +29 -0
  32. package/dist/table/src/components/TableEditableCell.d.ts.map +1 -0
  33. package/dist/table/src/components/TableEditableCell.mjs +39 -0
  34. package/dist/table/src/components/TableEditableCell.test.d.ts +2 -0
  35. package/dist/table/src/components/TableEditableCell.test.d.ts.map +1 -0
  36. package/dist/table/src/components/TableQuery.d.ts +108 -0
  37. package/dist/table/src/components/TableQuery.d.ts.map +1 -0
  38. package/dist/table/src/components/TableQuery.mjs +244 -0
  39. package/dist/table/src/components/TableQuery.test.d.ts +2 -0
  40. package/dist/table/src/components/TableQuery.test.d.ts.map +1 -0
  41. package/dist/table/src/components/VTableEditCell.vue.d.ts +19 -0
  42. package/dist/table/src/components/VTableEditCell.vue.d.ts.map +1 -0
  43. package/dist/table/src/components/VTableEditCell.vue.mjs +21 -0
  44. package/dist/table/src/components/VTableEditCell.vue2.mjs +4 -0
  45. package/dist/table/src/components/VTableQuery.vue.d.ts +18 -0
  46. package/dist/table/src/components/VTableQuery.vue.d.ts.map +1 -0
  47. package/dist/table/src/components/VTableQuery.vue.mjs +64 -0
  48. package/dist/table/src/components/VTableQuery.vue2.mjs +4 -0
  49. package/dist/table/src/composables/useTableDictionary.d.ts +5 -0
  50. package/dist/table/src/composables/useTableDictionary.d.ts.map +1 -0
  51. package/dist/table/src/composables/useTableDictionary.mjs +168 -0
  52. package/dist/table/src/composables/useTableDictionary.test.d.ts +2 -0
  53. package/dist/table/src/composables/useTableDictionary.test.d.ts.map +1 -0
  54. package/dist/table/src/composables/useTableEdit.d.ts.map +1 -1
  55. package/dist/table/src/composables/useTableEdit.mjs +352 -135
  56. package/dist/table/src/composables/useTableEditable.d.ts +4 -0
  57. package/dist/table/src/composables/useTableEditable.d.ts.map +1 -0
  58. package/dist/table/src/composables/useTableEditable.mjs +125 -0
  59. package/dist/table/src/composables/useTableEditable.test.d.ts +2 -0
  60. package/dist/table/src/composables/useTableEditable.test.d.ts.map +1 -0
  61. package/dist/table/src/composables/useTableQuery.d.ts.map +1 -1
  62. package/dist/table/src/composables/useTableQuery.mjs +33 -33
  63. package/dist/table/src/composables/useTableRequest.d.ts.map +1 -1
  64. package/dist/table/src/composables/useTableRequest.mjs +138 -97
  65. package/dist/table/src/composables/useTableRequest.polling.test.d.ts +2 -0
  66. package/dist/table/src/composables/useTableRequest.polling.test.d.ts.map +1 -0
  67. package/dist/table/src/context.d.ts +4 -0
  68. package/dist/table/src/context.d.ts.map +1 -1
  69. package/dist/table/src/controls.d.ts +4 -0
  70. package/dist/table/src/controls.d.ts.map +1 -0
  71. package/dist/table/src/controls.mjs +97 -0
  72. package/dist/table/src/controls.test.d.ts +2 -0
  73. package/dist/table/src/controls.test.d.ts.map +1 -0
  74. package/dist/table/src/index.d.ts +10 -0
  75. package/dist/table/src/index.d.ts.map +1 -1
  76. package/dist/table/src/renderers.d.ts.map +1 -1
  77. package/dist/table/src/renderers.mjs +88 -23
  78. package/dist/table/src/review-current.repro.test.d.ts +2 -0
  79. package/dist/table/src/review-current.repro.test.d.ts.map +1 -0
  80. package/dist/table/src/types/column.d.ts +4 -1
  81. package/dist/table/src/types/column.d.ts.map +1 -1
  82. package/dist/table/src/types/controls.d.ts +31 -0
  83. package/dist/table/src/types/controls.d.ts.map +1 -0
  84. package/dist/table/src/types/dictionary.d.ts +71 -0
  85. package/dist/table/src/types/dictionary.d.ts.map +1 -0
  86. package/dist/table/src/types/dictionary.typecheck.d.ts +6 -0
  87. package/dist/table/src/types/dictionary.typecheck.d.ts.map +1 -0
  88. package/dist/table/src/types/editable.d.ts +49 -0
  89. package/dist/table/src/types/editable.d.ts.map +1 -0
  90. package/dist/table/src/types/editable.typecheck.d.ts +15 -0
  91. package/dist/table/src/types/editable.typecheck.d.ts.map +1 -0
  92. package/dist/table/src/types/editing.d.ts +41 -4
  93. package/dist/table/src/types/editing.d.ts.map +1 -1
  94. package/dist/table/src/types/editing.typecheck.d.ts.map +1 -1
  95. package/dist/table/src/types/index.d.ts +4 -0
  96. package/dist/table/src/types/index.d.ts.map +1 -1
  97. package/dist/table/src/types/query-form.d.ts +90 -0
  98. package/dist/table/src/types/query-form.d.ts.map +1 -0
  99. package/dist/table/src/types/query-form.typecheck.d.ts +10 -0
  100. package/dist/table/src/types/query-form.typecheck.d.ts.map +1 -0
  101. package/dist/table/src/types/query.d.ts +6 -2
  102. package/dist/table/src/types/query.d.ts.map +1 -1
  103. package/dist/table/src/types/renderers.d.ts +15 -3
  104. package/dist/table/src/types/renderers.d.ts.map +1 -1
  105. package/dist/table/src/types/request.d.ts +20 -2
  106. package/dist/table/src/types/request.d.ts.map +1 -1
  107. package/dist/table/src/types/request.typecheck.d.ts.map +1 -1
  108. package/dist/table/src/utils/cell.d.ts +3 -2
  109. package/dist/table/src/utils/cell.d.ts.map +1 -1
  110. package/dist/table/src/utils/cell.mjs +45 -44
  111. package/dist/table/src/utils/fieldPath.d.ts +6 -0
  112. package/dist/table/src/utils/fieldPath.d.ts.map +1 -0
  113. package/dist/table/src/utils/fieldPath.mjs +29 -0
  114. package/dist/table/src/utils/queryFields.d.ts +4 -0
  115. package/dist/table/src/utils/queryFields.d.ts.map +1 -0
  116. package/dist/table/src/utils/queryFields.mjs +31 -0
  117. package/dist/table/src/utils/queryFields.test.d.ts +2 -0
  118. package/dist/table/src/utils/queryFields.test.d.ts.map +1 -0
  119. package/dist/table/src/utils/stateEqual.d.ts +3 -0
  120. package/dist/table/src/utils/stateEqual.d.ts.map +1 -0
  121. package/dist/table/src/utils/stateEqual.mjs +15 -0
  122. package/dist/theme/src/index.d.ts +4 -0
  123. package/dist/theme/src/index.d.ts.map +1 -1
  124. package/dist/theme/src/presets/antdv/table.d.ts +7 -0
  125. package/dist/theme/src/presets/antdv/table.d.ts.map +1 -1
  126. package/dist/theme/src/presets/antdv/table.mjs +7 -0
  127. package/dist/theme/src/presets/element-plus/table.d.ts +7 -0
  128. package/dist/theme/src/presets/element-plus/table.d.ts.map +1 -1
  129. package/dist/theme/src/presets/element-plus/table.mjs +7 -0
  130. package/dist/theme/src/query.d.ts +128 -0
  131. package/dist/theme/src/query.d.ts.map +1 -0
  132. package/dist/theme/src/query.mjs +56 -0
  133. package/dist/vtable-guild/src/augment.d.ts +2 -1
  134. package/dist/vtable-guild/src/augment.d.ts.map +1 -1
  135. package/package.json +1 -1
@@ -1,183 +1,400 @@
1
- import { shallowRef as x, getCurrentScope as O, onScopeDispose as V, computed as M } from "vue";
2
- import { snapshot as B } from "../utils/snapshot.mjs";
3
- function H(u) {
4
- const r = x(/* @__PURE__ */ new Map()), g = x(/* @__PURE__ */ new Map()), c = x(/* @__PURE__ */ new Map()), s = x(/* @__PURE__ */ new Map()), a = u.clone ?? ((e) => B(e));
5
- let d = !1;
6
- function E(e) {
7
- const t = typeof u.rowKey == "function" ? u.rowKey(e) : e[u.rowKey];
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 p(e) {
13
- if (!g.value.has(e)) return;
14
- const t = new Map(g.value);
15
- t.delete(e), g.value = t;
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 P(e, t) {
18
- g.value = new Map(g.value).set(e, t);
22
+ function I(e) {
23
+ const t = h.value, r = e.map(o);
24
+ h.value = r;
19
25
  try {
20
- u.onError?.(t, e);
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 S(e) {
25
- const t = c.value.get(e);
87
+ function R(e) {
88
+ const t = m.value.get(e);
26
89
  if (!t) return;
27
90
  t.controller.abort();
28
- const n = new Map(c.value);
29
- n.delete(e), c.value = n, t.resolve(void 0);
91
+ const r = new Map(m.value);
92
+ r.delete(e), m.value = r, t.resolve(void 0);
30
93
  }
31
- function N(e) {
32
- const t = s.value.get(e);
94
+ function T(e) {
95
+ const t = p.value.get(e);
33
96
  if (!t) return;
34
97
  t.controller.abort();
35
- const n = new Map(s.value);
36
- n.delete(e), s.value = n, t.resolve(!1);
98
+ const r = new Map(p.value);
99
+ r.delete(e), p.value = r, t.resolve(!1);
37
100
  }
38
- function K(e) {
39
- S(e), N(e);
40
- const t = new Map(r.value);
41
- t.delete(e), r.value = t, p(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 y(e) {
44
- const t = s.value.get(e);
106
+ function H(e) {
107
+ const t = p.value.get(e);
45
108
  if (t) return t.promise;
46
- const n = r.value.get(e);
47
- if (d || !n) return Promise.resolve(!1);
48
- if (S(e), p(e), !u.onCancel)
49
- return K(e), Promise.resolve(!0);
50
- let v;
51
- const m = new Promise((o) => {
52
- v = o;
53
- }), i = { controller: new AbortController(), promise: m, resolve: v };
54
- s.value = new Map(s.value).set(e, i);
55
- const f = () => !d && s.value.get(e) === i;
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 o = await u.onCancel(a(n.draft), {
121
+ const a = await l.onCancel(o(r.draft), {
59
122
  key: e,
60
- original: n.original === void 0 ? void 0 : a(n.original),
61
- isNew: n.isNew,
62
- signal: i.controller.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 (!f() || o === !1) return;
65
- i.resolve(!0), K(e);
66
- } catch (o) {
67
- if (!f()) return;
68
- const b = {
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: o instanceof Error ? o.message : String(o),
71
- cause: o
133
+ message: a instanceof Error ? a.message : String(a),
134
+ cause: a
72
135
  };
73
- P(e, b);
136
+ q(e, d);
74
137
  } finally {
75
- if (f()) {
76
- const o = new Map(s.value);
77
- o.delete(e), s.value = o;
138
+ if (c()) {
139
+ const a = new Map(p.value);
140
+ a.delete(e), p.value = a;
78
141
  }
79
- i.resolve(!1);
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
- })(), m;
82
- }
83
- function T() {
84
- return Promise.all([...r.value.keys()].map(y));
85
- }
86
- function A(e, t) {
87
- if (d) return !1;
88
- const n = E(e);
89
- return r.value.has(n) || u.mode !== "multiple" && r.value.size > 0 ? !1 : (r.value = new Map(r.value).set(n, {
90
- draft: a(e),
91
- original: t ? void 0 : a(e),
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 n = r.value.get(e);
106
- if (d || !n || s.value.has(e)) return Promise.resolve(void 0);
107
- p(e);
108
- let v;
109
- const m = new Promise((w) => {
110
- v = w;
111
- }), i = { controller: new AbortController(), promise: m, resolve: v };
112
- c.value = new Map(c.value).set(e, i);
113
- const f = () => !d && c.value.get(e) === i, o = {
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: n.original === void 0 ? void 0 : a(n.original),
116
- isNew: n.isNew,
117
- signal: i.controller.signal
118
- }, b = (w) => {
119
- f() && P(e, w);
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 w = "validation";
213
+ let u = "validation";
123
214
  try {
124
- const l = a(n.draft), h = await u.validate?.(a(l), o);
125
- if (!f()) return;
126
- if (h?.message || Object.keys(h?.fields ?? {}).length > 0) {
127
- b({
128
- ...h,
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: h?.message ?? "Validation failed"
221
+ message: w?.message ?? "Validation failed"
131
222
  });
132
223
  return;
133
224
  }
134
- w = "save";
135
- const C = await u.onSave?.(a(l), o);
136
- if (!f() || C === !1) return;
137
- const D = C === !0 ? l : C ?? l;
138
- if (!n.isNew && E(D) !== e)
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 z = a(D), R = new Map(r.value);
141
- R.delete(e), r.value = R, p(e), i.resolve(z);
142
- } catch (l) {
143
- b({
144
- type: w,
145
- message: l instanceof Error ? l.message : String(l),
146
- cause: l
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 (f()) {
150
- const l = new Map(c.value);
151
- l.delete(e), c.value = l;
251
+ if (c()) {
252
+ const n = new Map(m.value);
253
+ n.delete(e), m.value = n;
152
254
  }
153
- i.resolve(void 0);
255
+ f.resolve(void 0);
154
256
  }
155
- })(), m;
257
+ })(), v;
156
258
  }
157
- return O() && V(() => {
158
- d = !0;
159
- for (const e of r.value.keys()) K(e);
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
- editableKeys: M(() => [...r.value.keys()]),
162
- savingKeys: M(() => new Set(c.value.keys())),
163
- cancellingKeys: M(() => new Set(s.value.keys())),
164
- errors: M(() => new Map(g.value)),
165
- newRecords: M(
166
- () => [...r.value.values()].filter((e) => e.isNew).map((e) => a(e.draft))
167
- ),
168
- isEditing: (e) => r.value.has(e),
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 = r.value.get(e);
171
- return t ? a(t.draft) : void 0;
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
- start: (e) => A(e, !1),
174
- add: (e) => A(e, !0),
175
- setDraft: j,
176
- save: q,
177
- cancel: y,
178
- cancelAll: T
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
- H as useTableEdit
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useTableEditable.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableEditable.test.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableEditable.test.ts"],"names":[],"mappings":""}