@vtable-guild/vtable-guild 2.9.0-alpha.0 → 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 (193) hide show
  1. package/css/presets/antdv.css +16 -0
  2. package/css/presets/element-plus.css +16 -0
  3. package/css/style.css +200 -0
  4. package/css/tailwind3-utilities.css +168 -0
  5. package/css/tailwind3.css +32 -0
  6. package/css/tailwind4.css +32 -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/core/src/utils/types.d.ts +5 -0
  11. package/dist/core/src/utils/types.d.ts.map +1 -1
  12. package/dist/css/presets/antdv.css +16 -0
  13. package/dist/css/presets/element-plus.css +16 -0
  14. package/dist/css/style.css +200 -0
  15. package/dist/css/tailwind3-utilities.css +168 -0
  16. package/dist/css/tailwind3.css +32 -0
  17. package/dist/css/tailwind4.css +32 -0
  18. package/dist/icons/src/CheckCircleFilledIcon.d.ts +3 -0
  19. package/dist/icons/src/CheckCircleFilledIcon.d.ts.map +1 -0
  20. package/dist/icons/src/CheckCircleFilledIcon.mjs +9 -0
  21. package/dist/icons/src/CloseCircleFilledIcon.d.ts +3 -0
  22. package/dist/icons/src/CloseCircleFilledIcon.d.ts.map +1 -0
  23. package/dist/icons/src/CloseCircleFilledIcon.mjs +9 -0
  24. package/dist/icons/src/index.d.ts +2 -0
  25. package/dist/icons/src/index.d.ts.map +1 -1
  26. package/dist/index.full.mjs +6240 -4423
  27. package/dist/index.mjs +125 -99
  28. package/dist/table/src/components/ExpandIcon.d.ts +18 -0
  29. package/dist/table/src/components/ExpandIcon.d.ts.map +1 -1
  30. package/dist/table/src/components/ExpandIcon.mjs +47 -17
  31. package/dist/table/src/components/FilterDropdown.d.ts +1 -1
  32. package/dist/table/src/components/Table.d.ts +41 -3
  33. package/dist/table/src/components/Table.d.ts.map +1 -1
  34. package/dist/table/src/components/Table.mjs +744 -649
  35. package/dist/table/src/components/TableBody.d.ts.map +1 -1
  36. package/dist/table/src/components/TableBody.mjs +8 -5
  37. package/dist/table/src/components/TableCell.d.ts.map +1 -1
  38. package/dist/table/src/components/TableCell.mjs +125 -94
  39. package/dist/table/src/components/TableEditableCell.d.ts +29 -0
  40. package/dist/table/src/components/TableEditableCell.d.ts.map +1 -0
  41. package/dist/table/src/components/TableEditableCell.mjs +39 -0
  42. package/dist/table/src/components/TableEditableCell.test.d.ts +2 -0
  43. package/dist/table/src/components/TableEditableCell.test.d.ts.map +1 -0
  44. package/dist/table/src/components/TableInstance.test.d.ts +2 -0
  45. package/dist/table/src/components/TableInstance.test.d.ts.map +1 -0
  46. package/dist/table/src/components/TableLazyTree.test.d.ts +2 -0
  47. package/dist/table/src/components/TableLazyTree.test.d.ts.map +1 -0
  48. package/dist/table/src/components/TableQuery.d.ts +108 -0
  49. package/dist/table/src/components/TableQuery.d.ts.map +1 -0
  50. package/dist/table/src/components/TableQuery.mjs +244 -0
  51. package/dist/table/src/components/TableQuery.test.d.ts +2 -0
  52. package/dist/table/src/components/TableQuery.test.d.ts.map +1 -0
  53. package/dist/table/src/components/VTable.vue.d.ts +5 -1
  54. package/dist/table/src/components/VTable.vue.d.ts.map +1 -1
  55. package/dist/table/src/components/VTable.vue.mjs +45 -33
  56. package/dist/table/src/components/VTableEditCell.vue.d.ts +19 -0
  57. package/dist/table/src/components/VTableEditCell.vue.d.ts.map +1 -0
  58. package/dist/table/src/components/VTableEditCell.vue.mjs +21 -0
  59. package/dist/table/src/components/VTableEditCell.vue2.mjs +4 -0
  60. package/dist/table/src/components/VTableQuery.vue.d.ts +18 -0
  61. package/dist/table/src/components/VTableQuery.vue.d.ts.map +1 -0
  62. package/dist/table/src/components/VTableQuery.vue.mjs +64 -0
  63. package/dist/table/src/components/VTableQuery.vue2.mjs +4 -0
  64. package/dist/table/src/components/VirtualTableBody.d.ts.map +1 -1
  65. package/dist/table/src/components/VirtualTableBody.mjs +128 -115
  66. package/dist/table/src/composables/useLazyTreeData.d.ts +19 -0
  67. package/dist/table/src/composables/useLazyTreeData.d.ts.map +1 -0
  68. package/dist/table/src/composables/useLazyTreeData.mjs +123 -0
  69. package/dist/table/src/composables/useLazyTreeData.test.d.ts +2 -0
  70. package/dist/table/src/composables/useLazyTreeData.test.d.ts.map +1 -0
  71. package/dist/table/src/composables/useTableDictionary.d.ts +5 -0
  72. package/dist/table/src/composables/useTableDictionary.d.ts.map +1 -0
  73. package/dist/table/src/composables/useTableDictionary.mjs +168 -0
  74. package/dist/table/src/composables/useTableDictionary.test.d.ts +2 -0
  75. package/dist/table/src/composables/useTableDictionary.test.d.ts.map +1 -0
  76. package/dist/table/src/composables/useTableEdit.d.ts +4 -0
  77. package/dist/table/src/composables/useTableEdit.d.ts.map +1 -0
  78. package/dist/table/src/composables/useTableEdit.mjs +400 -0
  79. package/dist/table/src/composables/useTableEdit.test.d.ts +2 -0
  80. package/dist/table/src/composables/useTableEdit.test.d.ts.map +1 -0
  81. package/dist/table/src/composables/useTableEditable.d.ts +4 -0
  82. package/dist/table/src/composables/useTableEditable.d.ts.map +1 -0
  83. package/dist/table/src/composables/useTableEditable.mjs +125 -0
  84. package/dist/table/src/composables/useTableEditable.test.d.ts +2 -0
  85. package/dist/table/src/composables/useTableEditable.test.d.ts.map +1 -0
  86. package/dist/table/src/composables/useTableQuery.d.ts +4 -0
  87. package/dist/table/src/composables/useTableQuery.d.ts.map +1 -0
  88. package/dist/table/src/composables/useTableQuery.mjs +54 -0
  89. package/dist/table/src/composables/useTableQuery.test.d.ts +2 -0
  90. package/dist/table/src/composables/useTableQuery.test.d.ts.map +1 -0
  91. package/dist/table/src/composables/useTableRequest.d.ts.map +1 -1
  92. package/dist/table/src/composables/useTableRequest.mjs +138 -98
  93. package/dist/table/src/composables/useTableRequest.polling.test.d.ts +2 -0
  94. package/dist/table/src/composables/useTableRequest.polling.test.d.ts.map +1 -0
  95. package/dist/table/src/composables/useTreeData.d.ts +2 -0
  96. package/dist/table/src/composables/useTreeData.d.ts.map +1 -1
  97. package/dist/table/src/composables/useTreeData.mjs +46 -51
  98. package/dist/table/src/context.d.ts +11 -0
  99. package/dist/table/src/context.d.ts.map +1 -1
  100. package/dist/table/src/controls.d.ts +4 -0
  101. package/dist/table/src/controls.d.ts.map +1 -0
  102. package/dist/table/src/controls.mjs +97 -0
  103. package/dist/table/src/controls.test.d.ts +2 -0
  104. package/dist/table/src/controls.test.d.ts.map +1 -0
  105. package/dist/table/src/index.d.ts +27 -1
  106. package/dist/table/src/index.d.ts.map +1 -1
  107. package/dist/table/src/renderers.d.ts +5 -0
  108. package/dist/table/src/renderers.d.ts.map +1 -0
  109. package/dist/table/src/renderers.mjs +117 -0
  110. package/dist/table/src/renderers.test.d.ts +2 -0
  111. package/dist/table/src/renderers.test.d.ts.map +1 -0
  112. package/dist/table/src/review-current.repro.test.d.ts +2 -0
  113. package/dist/table/src/review-current.repro.test.d.ts.map +1 -0
  114. package/dist/table/src/types/column.d.ts +8 -1
  115. package/dist/table/src/types/column.d.ts.map +1 -1
  116. package/dist/table/src/types/controls.d.ts +31 -0
  117. package/dist/table/src/types/controls.d.ts.map +1 -0
  118. package/dist/table/src/types/dictionary.d.ts +71 -0
  119. package/dist/table/src/types/dictionary.d.ts.map +1 -0
  120. package/dist/table/src/types/dictionary.typecheck.d.ts +6 -0
  121. package/dist/table/src/types/dictionary.typecheck.d.ts.map +1 -0
  122. package/dist/table/src/types/editable.d.ts +49 -0
  123. package/dist/table/src/types/editable.d.ts.map +1 -0
  124. package/dist/table/src/types/editable.typecheck.d.ts +15 -0
  125. package/dist/table/src/types/editable.typecheck.d.ts.map +1 -0
  126. package/dist/table/src/types/editing.d.ts +90 -0
  127. package/dist/table/src/types/editing.d.ts.map +1 -0
  128. package/dist/table/src/types/editing.typecheck.d.ts +11 -0
  129. package/dist/table/src/types/editing.typecheck.d.ts.map +1 -0
  130. package/dist/table/src/types/index.d.ts +9 -0
  131. package/dist/table/src/types/index.d.ts.map +1 -1
  132. package/dist/table/src/types/instance.d.ts +18 -0
  133. package/dist/table/src/types/instance.d.ts.map +1 -0
  134. package/dist/table/src/types/instance.typecheck.d.ts +3 -0
  135. package/dist/table/src/types/instance.typecheck.d.ts.map +1 -0
  136. package/dist/table/src/types/query-form.d.ts +90 -0
  137. package/dist/table/src/types/query-form.d.ts.map +1 -0
  138. package/dist/table/src/types/query-form.typecheck.d.ts +10 -0
  139. package/dist/table/src/types/query-form.typecheck.d.ts.map +1 -0
  140. package/dist/table/src/types/query.d.ts +40 -0
  141. package/dist/table/src/types/query.d.ts.map +1 -0
  142. package/dist/table/src/types/query.typecheck.d.ts +14 -0
  143. package/dist/table/src/types/query.typecheck.d.ts.map +1 -0
  144. package/dist/table/src/types/renderers.d.ts +49 -0
  145. package/dist/table/src/types/renderers.d.ts.map +1 -0
  146. package/dist/table/src/types/renderers.typecheck.d.ts +13 -0
  147. package/dist/table/src/types/renderers.typecheck.d.ts.map +1 -0
  148. package/dist/table/src/types/request.d.ts +23 -5
  149. package/dist/table/src/types/request.d.ts.map +1 -1
  150. package/dist/table/src/types/request.typecheck.d.ts.map +1 -1
  151. package/dist/table/src/types/table.d.ts +8 -0
  152. package/dist/table/src/types/table.d.ts.map +1 -1
  153. package/dist/table/src/types/tree.d.ts +5 -0
  154. package/dist/table/src/types/tree.d.ts.map +1 -0
  155. package/dist/table/src/utils/cell.d.ts +5 -0
  156. package/dist/table/src/utils/cell.d.ts.map +1 -1
  157. package/dist/table/src/utils/cell.mjs +76 -46
  158. package/dist/table/src/utils/fieldPath.d.ts +6 -0
  159. package/dist/table/src/utils/fieldPath.d.ts.map +1 -0
  160. package/dist/table/src/utils/fieldPath.mjs +29 -0
  161. package/dist/table/src/utils/queryFields.d.ts +4 -0
  162. package/dist/table/src/utils/queryFields.d.ts.map +1 -0
  163. package/dist/table/src/utils/queryFields.mjs +31 -0
  164. package/dist/table/src/utils/queryFields.test.d.ts +2 -0
  165. package/dist/table/src/utils/queryFields.test.d.ts.map +1 -0
  166. package/dist/table/src/utils/snapshot.d.ts +3 -0
  167. package/dist/table/src/utils/snapshot.d.ts.map +1 -0
  168. package/dist/table/src/utils/snapshot.mjs +30 -0
  169. package/dist/table/src/utils/snapshot.test.d.ts +2 -0
  170. package/dist/table/src/utils/snapshot.test.d.ts.map +1 -0
  171. package/dist/table/src/utils/stateEqual.d.ts +3 -0
  172. package/dist/table/src/utils/stateEqual.d.ts.map +1 -0
  173. package/dist/table/src/utils/stateEqual.mjs +15 -0
  174. package/dist/theme/src/index.d.ts +4 -0
  175. package/dist/theme/src/index.d.ts.map +1 -1
  176. package/dist/theme/src/presets/antdv/table-locale.d.ts +10 -0
  177. package/dist/theme/src/presets/antdv/table-locale.d.ts.map +1 -1
  178. package/dist/theme/src/presets/antdv/table-locale.mjs +2 -0
  179. package/dist/theme/src/presets/antdv/table.d.ts +10 -0
  180. package/dist/theme/src/presets/antdv/table.d.ts.map +1 -1
  181. package/dist/theme/src/presets/antdv/table.mjs +10 -0
  182. package/dist/theme/src/presets/element-plus/table-locale.d.ts +10 -0
  183. package/dist/theme/src/presets/element-plus/table-locale.d.ts.map +1 -1
  184. package/dist/theme/src/presets/element-plus/table-locale.mjs +2 -0
  185. package/dist/theme/src/presets/element-plus/table.d.ts +10 -0
  186. package/dist/theme/src/presets/element-plus/table.d.ts.map +1 -1
  187. package/dist/theme/src/presets/element-plus/table.mjs +10 -0
  188. package/dist/theme/src/query.d.ts +128 -0
  189. package/dist/theme/src/query.d.ts.map +1 -0
  190. package/dist/theme/src/query.mjs +56 -0
  191. package/dist/vtable-guild/src/augment.d.ts +2 -1
  192. package/dist/vtable-guild/src/augment.d.ts.map +1 -1
  193. package/package.json +1 -1
@@ -0,0 +1,168 @@
1
+ import { ref as q, shallowRef as A, toValue as S, watch as K, getCurrentScope as L, onScopeDispose as Q, computed as E } from "vue";
2
+ import { snapshot as x } from "../utils/snapshot.mjs";
3
+ import { stateEqual as z } from "../utils/stateEqual.mjs";
4
+ function M() {
5
+ const e = new Error("Dictionary request cancelled");
6
+ return e.name = "AbortError", e;
7
+ }
8
+ function V(e, r) {
9
+ if (!e || !Array.isArray(e.options) || typeof e.complete != "boolean")
10
+ throw new Error("Dictionary request must return { options, complete }");
11
+ const d = /* @__PURE__ */ new Map();
12
+ for (const a of e.options) {
13
+ if (!a || !["string", "number", "boolean"].includes(typeof a.value) || typeof a.value == "number" && !Number.isFinite(a.value) || typeof a.label != "string")
14
+ throw new Error("Dictionary options require a primitive value and a string label");
15
+ d.set(a.value, { ...a });
16
+ }
17
+ return { options: [...d.values()], complete: e.complete && r === "" };
18
+ }
19
+ function H(e) {
20
+ if (!e.key.trim()) throw new Error("A stable dictionary key is required");
21
+ const r = [], d = Math.max(0, Number.isFinite(e.cacheTime) ? e.cacheTime : 3e5), a = Math.max(
22
+ 1,
23
+ Number.isFinite(e.maxEntries) ? Math.floor(e.maxEntries) : 50
24
+ ), m = (n) => {
25
+ const i = r.indexOf(n);
26
+ i >= 0 && r.splice(i, 1);
27
+ };
28
+ function b() {
29
+ for (const n of [...r])
30
+ !n.pending && (n.expires <= Date.now() || r.length > a) && m(n);
31
+ }
32
+ return Object.freeze({
33
+ key: e.key,
34
+ invalidate() {
35
+ r.splice(0);
36
+ },
37
+ load(n, { signal: i, keyword: v, force: y = !1 }) {
38
+ if (i.aborted) return Promise.reject(M());
39
+ b();
40
+ let s = r.find(
41
+ (t) => t.keyword === v && z(t.params, n)
42
+ );
43
+ if (s?.result && !y) return Promise.resolve(x(s.result));
44
+ if (!s?.pending) {
45
+ s && m(s);
46
+ const t = new AbortController(), f = x(n), o = {
47
+ params: f,
48
+ keyword: v,
49
+ expires: 0,
50
+ controller: t,
51
+ pending: !0,
52
+ users: /* @__PURE__ */ new Set(),
53
+ task: Promise.resolve().then(() => {
54
+ if (t.signal.aborted) throw M();
55
+ return e.request(x(f), { signal: t.signal, keyword: v });
56
+ }).then((u) => {
57
+ if (t.signal.aborted) throw M();
58
+ const p = V(u, v);
59
+ return o.pending = !1, o.result = p, o.expires = Date.now() + d, b(), p;
60
+ }).catch((u) => {
61
+ throw o.pending = !1, m(o), u;
62
+ })
63
+ };
64
+ r.push(o), s = o;
65
+ }
66
+ const l = s, h = /* @__PURE__ */ Symbol();
67
+ return l.users.add(h), new Promise((t, f) => {
68
+ function o() {
69
+ i.removeEventListener("abort", u), l.users.delete(h), !l.users.size && l.pending && (l.controller.abort(), m(l));
70
+ }
71
+ function u() {
72
+ o(), f(M());
73
+ }
74
+ i.addEventListener("abort", u, { once: !0 }), l.task.then(
75
+ (p) => {
76
+ o(), i.aborted ? f(M()) : t(x(p));
77
+ },
78
+ (p) => {
79
+ o(), f(p);
80
+ }
81
+ );
82
+ });
83
+ }
84
+ });
85
+ }
86
+ function I(e) {
87
+ const r = q(e.defaultKeyword ?? ""), d = A([]), a = A(/* @__PURE__ */ new Map()), m = q(!1), b = q(!1), n = A(null);
88
+ let i = x(S(e.params) ?? {}), v = !1, y = 0, s, l, h, t, f = Promise.resolve(!1);
89
+ function o() {
90
+ y++, clearTimeout(l), l = void 0, s?.abort(), s = void 0, t = void 0, h?.(!1), h = void 0, b.value = !1;
91
+ }
92
+ function u(c = !1, g = !1) {
93
+ if (v) return Promise.resolve(!1);
94
+ if (s && l === void 0 && t && t.keyword === r.value && z(t.params, i))
95
+ return f;
96
+ o();
97
+ const P = y, D = new AbortController();
98
+ s = D;
99
+ const C = x(i), F = r.value;
100
+ return t = { params: C, keyword: F }, b.value = !0, m.value = !1, n.value = null, f = new Promise((T) => {
101
+ h = T;
102
+ const N = async () => {
103
+ l = void 0;
104
+ try {
105
+ const w = await e.dictionary.load(C, {
106
+ keyword: F,
107
+ signal: D.signal,
108
+ force: g
109
+ });
110
+ if (v || P !== y) return;
111
+ d.value = w.options, m.value = w.complete;
112
+ const k = w.complete ? /* @__PURE__ */ new Map() : new Map(a.value);
113
+ for (const R of w.options) k.set(R.value, R);
114
+ a.value = k, T(!0);
115
+ } catch (w) {
116
+ if (!v && P === y && !D.signal.aborted) {
117
+ n.value = w instanceof Error ? w : new Error(String(w));
118
+ try {
119
+ e.onError?.(n.value);
120
+ } catch (k) {
121
+ n.value = k instanceof Error ? k : new Error(String(k));
122
+ }
123
+ }
124
+ T(!1);
125
+ } finally {
126
+ P === y && (b.value = !1, s = void 0, h = void 0);
127
+ }
128
+ }, O = c ? 0 : Math.max(0, e.debounceTime ?? 0);
129
+ O ? l = setTimeout(() => {
130
+ N();
131
+ }, O) : N();
132
+ }), f;
133
+ }
134
+ const p = K(
135
+ () => S(e.params),
136
+ (c) => {
137
+ z(i, c ?? {}) || (i = x(c ?? {}), r.value = "", a.value = /* @__PURE__ */ new Map(), d.value = [], u());
138
+ },
139
+ { deep: !0 }
140
+ );
141
+ return L() && Q(() => {
142
+ v = !0, p(), o();
143
+ }), e.manualRequest || u(), {
144
+ options: E(() => d.value),
145
+ valueEnum: E(() => {
146
+ const c = /* @__PURE__ */ new Map();
147
+ for (const g of [...S(e.selectedOptions) ?? [], ...a.value.values()])
148
+ c.set(g.value, { text: g.label, status: g.status });
149
+ return c;
150
+ }),
151
+ filters: E(
152
+ () => m.value ? d.value.map(({ value: c, label: g }) => ({ value: c, text: g })) : []
153
+ ),
154
+ complete: E(() => m.value),
155
+ loading: E(() => b.value),
156
+ error: E(() => n.value),
157
+ keyword: E(() => r.value),
158
+ search(c) {
159
+ return r.value = c, u();
160
+ },
161
+ reload: () => u(!0, !0),
162
+ cancel: o
163
+ };
164
+ }
165
+ export {
166
+ H as createTableDictionary,
167
+ I as useTableDictionary
168
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useTableDictionary.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableDictionary.test.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableDictionary.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { UseTableEditOptions, UseTableEditReturn } from '../types/editing';
2
+ /** Row drafts and validation without coupling the table to a form or HTTP library. */
3
+ export declare function useTableEdit<TRecord extends object>(options: UseTableEditOptions<TRecord>): UseTableEditReturn<TRecord>;
4
+ //# sourceMappingURL=useTableEdit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableEdit.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableEdit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAKV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAiBzB,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,EACjD,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACpC,kBAAkB,CAAC,OAAO,CAAC,CAwiB7B"}
@@ -0,0 +1,400 @@
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];
9
+ if (typeof t != "string" && typeof t != "number")
10
+ throw new Error("useTableEdit requires a string or number row key");
11
+ return t;
12
+ }
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;
21
+ }
22
+ function I(e) {
23
+ const t = h.value, r = e.map(o);
24
+ h.value = r;
25
+ try {
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);
84
+ } catch {
85
+ }
86
+ }
87
+ function R(e) {
88
+ const t = m.value.get(e);
89
+ if (!t) return;
90
+ t.controller.abort();
91
+ const r = new Map(m.value);
92
+ r.delete(e), m.value = r, t.resolve(void 0);
93
+ }
94
+ function T(e) {
95
+ const t = p.value.get(e);
96
+ if (!t) return;
97
+ t.controller.abort();
98
+ const r = new Map(p.value);
99
+ r.delete(e), p.value = r, t.resolve(!1);
100
+ }
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);
105
+ }
106
+ function H(e) {
107
+ const t = p.value.get(e);
108
+ if (t) return t.promise;
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;
119
+ return (async () => {
120
+ try {
121
+ const a = await l.onCancel(o(r.draft), {
122
+ key: e,
123
+ original: r.original === void 0 ? void 0 : o(r.original),
124
+ isNew: r.isNew,
125
+ signal: f.controller.signal
126
+ });
127
+ if (!c() || a === !1) return;
128
+ f.resolve(!0), O(e);
129
+ } catch (a) {
130
+ if (!c()) return;
131
+ const d = {
132
+ type: "cancel",
133
+ message: a instanceof Error ? a.message : String(a),
134
+ cause: a
135
+ };
136
+ q(e, d);
137
+ } finally {
138
+ if (c()) {
139
+ const a = new Map(p.value);
140
+ a.delete(e), p.value = a;
141
+ }
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;
183
+ }
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);
195
+ if (t) return t.promise;
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 = {
205
+ key: e,
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);
211
+ };
212
+ return (async () => {
213
+ let u = "validation";
214
+ try {
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,
220
+ type: "validation",
221
+ message: w?.message ?? "Validation failed"
222
+ });
223
+ return;
224
+ }
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)
230
+ throw new Error("Saving an existing row cannot change its key");
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
249
+ });
250
+ } finally {
251
+ if (c()) {
252
+ const n = new Map(m.value);
253
+ n.delete(e), m.value = n;
254
+ }
255
+ f.resolve(void 0);
256
+ }
257
+ })(), v;
258
+ }
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();
361
+ }), {
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),
378
+ getDraft: (e) => {
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);
385
+ },
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
396
+ };
397
+ }
398
+ export {
399
+ fe as useTableEdit
400
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useTableEdit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableEdit.test.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableEdit.test.ts"],"names":[],"mappings":""}
@@ -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"}