@vtable-guild/vtable-guild 2.9.0-alpha.0 → 2.9.0-alpha.1

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 (112) hide show
  1. package/css/presets/antdv.css +6 -0
  2. package/css/presets/element-plus.css +6 -0
  3. package/css/style.css +62 -0
  4. package/css/tailwind3-utilities.css +50 -0
  5. package/css/tailwind3.css +12 -0
  6. package/css/tailwind4.css +12 -0
  7. package/dist/core/src/utils/types.d.ts +5 -0
  8. package/dist/core/src/utils/types.d.ts.map +1 -1
  9. package/dist/css/presets/antdv.css +6 -0
  10. package/dist/css/presets/element-plus.css +6 -0
  11. package/dist/css/style.css +62 -0
  12. package/dist/css/tailwind3-utilities.css +50 -0
  13. package/dist/css/tailwind3.css +12 -0
  14. package/dist/css/tailwind4.css +12 -0
  15. package/dist/index.full.mjs +5477 -4867
  16. package/dist/index.mjs +53 -47
  17. package/dist/table/src/components/ExpandIcon.d.ts +18 -0
  18. package/dist/table/src/components/ExpandIcon.d.ts.map +1 -1
  19. package/dist/table/src/components/ExpandIcon.mjs +47 -17
  20. package/dist/table/src/components/FilterDropdown.d.ts +1 -1
  21. package/dist/table/src/components/Table.d.ts +39 -1
  22. package/dist/table/src/components/Table.d.ts.map +1 -1
  23. package/dist/table/src/components/Table.mjs +729 -638
  24. package/dist/table/src/components/TableBody.d.ts.map +1 -1
  25. package/dist/table/src/components/TableBody.mjs +8 -5
  26. package/dist/table/src/components/TableCell.d.ts.map +1 -1
  27. package/dist/table/src/components/TableCell.mjs +74 -66
  28. package/dist/table/src/components/TableInstance.test.d.ts +2 -0
  29. package/dist/table/src/components/TableInstance.test.d.ts.map +1 -0
  30. package/dist/table/src/components/TableLazyTree.test.d.ts +2 -0
  31. package/dist/table/src/components/TableLazyTree.test.d.ts.map +1 -0
  32. package/dist/table/src/components/VTable.vue.d.ts +5 -1
  33. package/dist/table/src/components/VTable.vue.d.ts.map +1 -1
  34. package/dist/table/src/components/VTable.vue.mjs +45 -33
  35. package/dist/table/src/components/VirtualTableBody.d.ts.map +1 -1
  36. package/dist/table/src/components/VirtualTableBody.mjs +128 -115
  37. package/dist/table/src/composables/useLazyTreeData.d.ts +19 -0
  38. package/dist/table/src/composables/useLazyTreeData.d.ts.map +1 -0
  39. package/dist/table/src/composables/useLazyTreeData.mjs +123 -0
  40. package/dist/table/src/composables/useLazyTreeData.test.d.ts +2 -0
  41. package/dist/table/src/composables/useLazyTreeData.test.d.ts.map +1 -0
  42. package/dist/table/src/composables/useTableEdit.d.ts +4 -0
  43. package/dist/table/src/composables/useTableEdit.d.ts.map +1 -0
  44. package/dist/table/src/composables/useTableEdit.mjs +183 -0
  45. package/dist/table/src/composables/useTableEdit.test.d.ts +2 -0
  46. package/dist/table/src/composables/useTableEdit.test.d.ts.map +1 -0
  47. package/dist/table/src/composables/useTableQuery.d.ts +4 -0
  48. package/dist/table/src/composables/useTableQuery.d.ts.map +1 -0
  49. package/dist/table/src/composables/useTableQuery.mjs +54 -0
  50. package/dist/table/src/composables/useTableQuery.test.d.ts +2 -0
  51. package/dist/table/src/composables/useTableQuery.test.d.ts.map +1 -0
  52. package/dist/table/src/composables/useTableRequest.d.ts.map +1 -1
  53. package/dist/table/src/composables/useTableRequest.mjs +70 -71
  54. package/dist/table/src/composables/useTreeData.d.ts +2 -0
  55. package/dist/table/src/composables/useTreeData.d.ts.map +1 -1
  56. package/dist/table/src/composables/useTreeData.mjs +46 -51
  57. package/dist/table/src/context.d.ts +7 -0
  58. package/dist/table/src/context.d.ts.map +1 -1
  59. package/dist/table/src/index.d.ts +17 -1
  60. package/dist/table/src/index.d.ts.map +1 -1
  61. package/dist/table/src/renderers.d.ts +5 -0
  62. package/dist/table/src/renderers.d.ts.map +1 -0
  63. package/dist/table/src/renderers.mjs +52 -0
  64. package/dist/table/src/renderers.test.d.ts +2 -0
  65. package/dist/table/src/renderers.test.d.ts.map +1 -0
  66. package/dist/table/src/types/column.d.ts +5 -1
  67. package/dist/table/src/types/column.d.ts.map +1 -1
  68. package/dist/table/src/types/editing.d.ts +53 -0
  69. package/dist/table/src/types/editing.d.ts.map +1 -0
  70. package/dist/table/src/types/editing.typecheck.d.ts +11 -0
  71. package/dist/table/src/types/editing.typecheck.d.ts.map +1 -0
  72. package/dist/table/src/types/index.d.ts +5 -0
  73. package/dist/table/src/types/index.d.ts.map +1 -1
  74. package/dist/table/src/types/instance.d.ts +18 -0
  75. package/dist/table/src/types/instance.d.ts.map +1 -0
  76. package/dist/table/src/types/instance.typecheck.d.ts +3 -0
  77. package/dist/table/src/types/instance.typecheck.d.ts.map +1 -0
  78. package/dist/table/src/types/query.d.ts +36 -0
  79. package/dist/table/src/types/query.d.ts.map +1 -0
  80. package/dist/table/src/types/query.typecheck.d.ts +14 -0
  81. package/dist/table/src/types/query.typecheck.d.ts.map +1 -0
  82. package/dist/table/src/types/renderers.d.ts +37 -0
  83. package/dist/table/src/types/renderers.d.ts.map +1 -0
  84. package/dist/table/src/types/renderers.typecheck.d.ts +13 -0
  85. package/dist/table/src/types/renderers.typecheck.d.ts.map +1 -0
  86. package/dist/table/src/types/request.d.ts +3 -3
  87. package/dist/table/src/types/request.d.ts.map +1 -1
  88. package/dist/table/src/types/table.d.ts +8 -0
  89. package/dist/table/src/types/table.d.ts.map +1 -1
  90. package/dist/table/src/types/tree.d.ts +5 -0
  91. package/dist/table/src/types/tree.d.ts.map +1 -0
  92. package/dist/table/src/utils/cell.d.ts +4 -0
  93. package/dist/table/src/utils/cell.d.ts.map +1 -1
  94. package/dist/table/src/utils/cell.mjs +81 -52
  95. package/dist/table/src/utils/snapshot.d.ts +3 -0
  96. package/dist/table/src/utils/snapshot.d.ts.map +1 -0
  97. package/dist/table/src/utils/snapshot.mjs +30 -0
  98. package/dist/table/src/utils/snapshot.test.d.ts +2 -0
  99. package/dist/table/src/utils/snapshot.test.d.ts.map +1 -0
  100. package/dist/theme/src/presets/antdv/table-locale.d.ts +10 -0
  101. package/dist/theme/src/presets/antdv/table-locale.d.ts.map +1 -1
  102. package/dist/theme/src/presets/antdv/table-locale.mjs +2 -0
  103. package/dist/theme/src/presets/antdv/table.d.ts +3 -0
  104. package/dist/theme/src/presets/antdv/table.d.ts.map +1 -1
  105. package/dist/theme/src/presets/antdv/table.mjs +3 -0
  106. package/dist/theme/src/presets/element-plus/table-locale.d.ts +10 -0
  107. package/dist/theme/src/presets/element-plus/table-locale.d.ts.map +1 -1
  108. package/dist/theme/src/presets/element-plus/table-locale.mjs +2 -0
  109. package/dist/theme/src/presets/element-plus/table.d.ts +3 -0
  110. package/dist/theme/src/presets/element-plus/table.d.ts.map +1 -1
  111. package/dist/theme/src/presets/element-plus/table.mjs +3 -0
  112. package/package.json +1 -1
@@ -0,0 +1,183 @@
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];
8
+ if (typeof t != "string" && typeof t != "number")
9
+ throw new Error("useTableEdit requires a string or number row key");
10
+ return t;
11
+ }
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;
16
+ }
17
+ function P(e, t) {
18
+ g.value = new Map(g.value).set(e, t);
19
+ try {
20
+ u.onError?.(t, e);
21
+ } catch {
22
+ }
23
+ }
24
+ function S(e) {
25
+ const t = c.value.get(e);
26
+ if (!t) return;
27
+ t.controller.abort();
28
+ const n = new Map(c.value);
29
+ n.delete(e), c.value = n, t.resolve(void 0);
30
+ }
31
+ function N(e) {
32
+ const t = s.value.get(e);
33
+ if (!t) return;
34
+ t.controller.abort();
35
+ const n = new Map(s.value);
36
+ n.delete(e), s.value = n, t.resolve(!1);
37
+ }
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);
42
+ }
43
+ function y(e) {
44
+ const t = s.value.get(e);
45
+ 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;
56
+ return (async () => {
57
+ try {
58
+ const o = await u.onCancel(a(n.draft), {
59
+ key: e,
60
+ original: n.original === void 0 ? void 0 : a(n.original),
61
+ isNew: n.isNew,
62
+ signal: i.controller.signal
63
+ });
64
+ if (!f() || o === !1) return;
65
+ i.resolve(!0), K(e);
66
+ } catch (o) {
67
+ if (!f()) return;
68
+ const b = {
69
+ type: "cancel",
70
+ message: o instanceof Error ? o.message : String(o),
71
+ cause: o
72
+ };
73
+ P(e, b);
74
+ } finally {
75
+ if (f()) {
76
+ const o = new Map(s.value);
77
+ o.delete(e), s.value = o;
78
+ }
79
+ i.resolve(!1);
80
+ }
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);
104
+ 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 = {
114
+ 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);
120
+ };
121
+ return (async () => {
122
+ let w = "validation";
123
+ 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,
129
+ type: "validation",
130
+ message: h?.message ?? "Validation failed"
131
+ });
132
+ return;
133
+ }
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)
139
+ 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
147
+ });
148
+ } finally {
149
+ if (f()) {
150
+ const l = new Map(c.value);
151
+ l.delete(e), c.value = l;
152
+ }
153
+ i.resolve(void 0);
154
+ }
155
+ })(), m;
156
+ }
157
+ return O() && V(() => {
158
+ d = !0;
159
+ for (const e of r.value.keys()) K(e);
160
+ }), {
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),
169
+ getDraft: (e) => {
170
+ const t = r.value.get(e);
171
+ return t ? a(t.draft) : void 0;
172
+ },
173
+ start: (e) => A(e, !1),
174
+ add: (e) => A(e, !0),
175
+ setDraft: j,
176
+ save: q,
177
+ cancel: y,
178
+ cancelAll: T
179
+ };
180
+ }
181
+ export {
182
+ H as useTableEdit
183
+ };
@@ -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 { UseTableQueryOptions, UseTableQueryReturn } from '../types/query';
2
+ /** Form state and submit protocol; controls and layout remain owned by the host UI library. */
3
+ export declare function useTableQuery<TValues extends object, TParams extends object = TValues>(options: UseTableQueryOptions<TValues, TParams>): UseTableQueryReturn<TValues, TParams>;
4
+ //# sourceMappingURL=useTableQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableQuery.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAG/E,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,OAAO,EACpF,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,GAC9C,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAsFvC"}
@@ -0,0 +1,54 @@
1
+ import { ref as y, shallowRef as g, watch as O, getCurrentScope as S, onScopeDispose as j, computed as h } from "vue";
2
+ import { snapshot as e } from "../utils/snapshot.mjs";
3
+ function R(a) {
4
+ const d = e(a.defaultValues), c = y(e(d)), v = g(), p = g(), f = a.collapsed ?? y(a.defaultCollapsed ?? !0), i = y(!1), b = g(null);
5
+ let o = 0, l = !1;
6
+ const k = a.onCollapse ? O(f, (r) => a.onCollapse?.(r), { flush: "sync" }) : void 0;
7
+ function w(r) {
8
+ const s = a.fieldTransforms, t = {};
9
+ for (const [n, m] of Object.entries(r))
10
+ Object.prototype.hasOwnProperty.call(s ?? {}, n) && s?.[n] || (t[n] = m);
11
+ for (const n of Object.keys(s ?? {})) {
12
+ const m = s?.[n];
13
+ m && Object.assign(t, m(r[n], r));
14
+ }
15
+ const u = t;
16
+ return e(a.transform?.(u, r) ?? u);
17
+ }
18
+ async function C(r) {
19
+ if (l) return !1;
20
+ const s = ++o;
21
+ i.value = !0, b.value = null;
22
+ try {
23
+ const t = e(c.value), u = w(t);
24
+ return v.value = e(t), p.value = e(u), await (r ? a.onReset ?? a.onSubmit : a.onSubmit)?.(e(u), e(t)), !l && s === o;
25
+ } catch (t) {
26
+ return !l && s === o && (b.value = t instanceof Error ? t : new Error(String(t))), !1;
27
+ } finally {
28
+ !l && s === o && (i.value = !1);
29
+ }
30
+ }
31
+ return S() && j(() => {
32
+ l = !0, o++, i.value = !1, k?.();
33
+ }), {
34
+ draft: c,
35
+ submitted: h(() => v.value && e(v.value)),
36
+ params: h(() => p.value && e(p.value)),
37
+ collapsed: f,
38
+ submitting: h(() => i.value),
39
+ error: b,
40
+ submit: () => C(!1),
41
+ reset() {
42
+ return l ? Promise.resolve(!1) : (c.value = e(d), C(!0));
43
+ },
44
+ resetFields() {
45
+ l || (c.value = e(d));
46
+ },
47
+ toggleCollapsed() {
48
+ f.value = !f.value;
49
+ }
50
+ };
51
+ }
52
+ export {
53
+ R as useTableQuery
54
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useTableQuery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableQuery.test.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableQuery.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"useTableRequest.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,kBAAkB,CAAA;AA4CzB,2FAA2F;AAC3F,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChD,OAAO,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAyL5F"}
1
+ {"version":3,"file":"useTableRequest.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTableRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,kBAAkB,CAAA;AAsCzB,2FAA2F;AAC3F,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChD,OAAO,EAAE,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAyL5F"}
@@ -1,127 +1,126 @@
1
- import { shallowRef as O, ref as q, toValue as I, watch as Q, getCurrentScope as U, onScopeDispose as W, computed as w } from "vue";
2
- import { positiveInteger as D } from "./usePagination.mjs";
3
- function n(e) {
4
- return e instanceof Date ? new Date(e.getTime()) : Array.isArray(e) ? e.map((t) => n(t)) : e && Object.getPrototypeOf(e) === Object.prototype ? Object.fromEntries(
5
- Object.entries(e).map(([t, r]) => [t, n(r)])
6
- ) : e;
7
- }
8
- function F(e, t) {
1
+ import { shallowRef as w, ref as D, toValue as I, watch as J, getCurrentScope as Q, onScopeDispose as U, computed as S } from "vue";
2
+ import { positiveInteger as M } from "./usePagination.mjs";
3
+ import { snapshot as l } from "../utils/snapshot.mjs";
4
+ function W(e, t, r = /* @__PURE__ */ new WeakMap()) {
9
5
  if (Object.is(e, t)) return !0;
10
6
  if (e instanceof Date && t instanceof Date) return e.getTime() === t.getTime();
11
7
  if (!e || !t || typeof e != "object" || typeof t != "object" || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) || Object.getPrototypeOf(e) !== Object.prototype && !Array.isArray(e)) return !1;
12
- const r = Object.entries(e), i = Object.entries(t);
13
- return r.length === i.length && r.every(
14
- ([c, o]) => Object.prototype.hasOwnProperty.call(t, c) && F(o, Reflect.get(t, c))
8
+ if (r.get(e)?.has(t)) return !0;
9
+ const n = r.get(e) ?? /* @__PURE__ */ new WeakSet();
10
+ r.set(e, n), n.add(t);
11
+ const f = Object.entries(e), o = Object.entries(t);
12
+ return f.length === o.length && f.every(
13
+ ([c, P]) => Object.prototype.hasOwnProperty.call(t, c) && W(P, Reflect.get(t, c), r)
15
14
  );
16
15
  }
17
16
  function X(e) {
18
17
  const t = [];
19
18
  for (const r of Array.isArray(e) ? e : [e]) {
20
19
  if (!r.order) continue;
21
- const i = r.field ?? r.columnKey;
22
- i != null && t.push([Array.isArray(i) ? i.join(".") : String(i), r.order]);
20
+ const n = r.field ?? r.columnKey;
21
+ n != null && t.push([Array.isArray(n) ? n.join(".") : String(n), r.order]);
23
22
  }
24
23
  return Object.fromEntries(t);
25
24
  }
26
- function _(e) {
27
- const t = n(e.defaultParams ?? {}), r = O(n(t)), i = O({}), c = O({}), o = q(D(e.initialPagination?.current, 1)), p = q(D(e.initialPagination?.pageSize, 10)), K = q(Math.max(0, e.initialPagination?.total ?? 0)), L = O([]), S = q(!1), v = O(null), G = Object.freeze({ sort: !0, filter: !0, pagination: !0 });
28
- let j = !1, y = 0, b, P, A, g, C = Promise.resolve();
25
+ function $(e) {
26
+ const t = l(e.defaultParams ?? {}), r = w(l(t)), n = w({}), f = w({}), o = D(M(e.initialPagination?.current, 1)), c = D(M(e.initialPagination?.pageSize, 10)), P = D(Math.max(0, e.initialPagination?.total ?? 0)), F = w([]), O = D(!1), g = w(null), B = Object.freeze({ sort: !0, filter: !0, pagination: !0 });
27
+ let j = !1, y = 0, h, z, A, d, C = Promise.resolve();
29
28
  function E() {
30
- y++, b !== void 0 && clearTimeout(b), b = void 0, P?.abort(), P = void 0, A?.(), A = void 0, S.value = !1, g = void 0;
29
+ y++, h !== void 0 && clearTimeout(h), h = void 0, z?.abort(), z = void 0, A?.(), A = void 0, O.value = !1, d = void 0;
31
30
  }
32
- function m(l = !1, M = !1) {
31
+ function m(i = !1, x = !1) {
33
32
  if (j) return Promise.resolve();
34
33
  let a;
35
34
  try {
36
- const s = n({ ...t, ...r.value, ...I(e.params) });
35
+ const s = l({ ...t, ...r.value, ...I(e.params) });
37
36
  a = {
38
37
  ...e.beforeSearchSubmit?.(s) ?? s,
39
38
  current: o.value,
40
- pageSize: p.value
39
+ pageSize: c.value
41
40
  };
42
41
  } catch (s) {
43
- return E(), v.value = s instanceof Error ? s : new Error(String(s)), e.onError?.(v.value), Promise.resolve();
42
+ return E(), g.value = s instanceof Error ? s : new Error(String(s)), e.onError?.(g.value), Promise.resolve();
44
43
  }
45
- const d = n(i.value), h = n(c.value), V = n({ params: a, sort: d, filters: h });
46
- if (!l && g !== void 0 && F(g, V)) return C;
47
- E(), g = V;
48
- const x = y, z = new AbortController();
49
- return P = z, S.value = !0, v.value = null, C = new Promise((s) => {
44
+ const p = l(n.value), b = l(f.value), L = l({ params: a, sort: p, filters: b });
45
+ if (!i && d !== void 0 && W(d, L)) return C;
46
+ E(), d = L;
47
+ const R = y, T = new AbortController();
48
+ return z = T, O.value = !0, g.value = null, C = new Promise((s) => {
50
49
  A = s;
51
- const k = async () => {
52
- b = void 0;
50
+ const N = async () => {
51
+ h = void 0;
53
52
  try {
54
- for (let f = 0; f < 2; f++) {
55
- const u = await e.request(a, d, h, { signal: z.signal });
56
- if (j || x !== y || z.signal.aborted) return;
53
+ for (let v = 0; v < 2; v++) {
54
+ const u = await e.request(a, p, b, { signal: T.signal });
55
+ if (j || R !== y || T.signal.aborted) return;
57
56
  if (u.success === !1) throw new Error("Table request was unsuccessful");
58
57
  if (!Array.isArray(u.data))
59
58
  throw new Error("Table request data must be an array");
60
59
  if (!Number.isSafeInteger(u.total) || u.total < 0)
61
60
  throw new Error("Table request total must be a non-negative safe integer");
62
- const T = Math.max(1, Math.ceil(u.total / a.pageSize));
63
- if (f === 0 && u.total > 0 && a.current > T) {
64
- o.value = T, a = { ...a, current: T };
61
+ const q = Math.max(1, Math.ceil(u.total / a.pageSize));
62
+ if (v === 0 && u.total > 0 && a.current > q) {
63
+ o.value = q, a = { ...a, current: q };
65
64
  continue;
66
65
  }
67
- const R = e.postData ? e.postData(u.data) : u.data;
68
- if (!Array.isArray(R)) throw new Error("Table postData must return an array");
69
- o.value = Math.min(a.current, T), K.value = u.total, L.value = R, g = n({ params: { ...a, current: o.value }, sort: d, filters: h }), e.onLoad?.(R, u);
66
+ const k = e.postData ? e.postData(u.data) : u.data;
67
+ if (!Array.isArray(k)) throw new Error("Table postData must return an array");
68
+ o.value = Math.min(a.current, q), P.value = u.total, F.value = k, d = l({ params: { ...a, current: o.value }, sort: p, filters: b }), e.onLoad?.(k, u);
70
69
  break;
71
70
  }
72
- } catch (f) {
73
- !j && x === y && !z.signal.aborted && (v.value = f instanceof Error ? f : new Error(String(f)), g = void 0, e.onError?.(v.value));
71
+ } catch (v) {
72
+ !j && R === y && !T.signal.aborted && (g.value = v instanceof Error ? v : new Error(String(v)), d = void 0, e.onError?.(g.value));
74
73
  } finally {
75
- x === y && (S.value = !1, P = void 0, A = void 0), s();
74
+ R === y && (O.value = !1, z = void 0, A = void 0), s();
76
75
  }
77
- }, B = M ? 0 : Math.max(0, e.debounceTime ?? 0);
78
- B > 0 ? b = setTimeout(() => {
79
- k();
80
- }, B) : k();
76
+ }, V = x ? 0 : Math.max(0, e.debounceTime ?? 0);
77
+ V > 0 ? h = setTimeout(() => {
78
+ N();
79
+ }, V) : N();
81
80
  }), C;
82
81
  }
83
- const H = (l, M, a) => {
82
+ const G = (i, x, a) => {
84
83
  if (a.action === "select") return;
85
- const d = D(a.pagination?.pageSize, p.value), h = d !== p.value;
86
- i.value = X(M), c.value = n(l), o.value = a.action !== "paginate" || h && e.resetOnPageSizeChange !== !1 ? 1 : D(a.pagination?.current, o.value), p.value = d, m();
84
+ const p = M(a.pagination?.pageSize, c.value), b = p !== c.value;
85
+ n.value = X(x), f.value = l(i), o.value = a.action !== "paginate" || b && e.resetOnPageSizeChange !== !1 ? 1 : M(a.pagination?.current, o.value), c.value = p, m();
87
86
  };
88
- let N = n(I(e.params));
89
- const J = Q(
87
+ let K = l(I(e.params));
88
+ const H = J(
90
89
  () => I(e.params),
91
- (l) => {
92
- F(N, l) || (N = n(l), o.value = 1, m());
90
+ (i) => {
91
+ W(K, i) || (K = l(i), o.value = 1, m());
93
92
  },
94
93
  { deep: !0 }
95
94
  );
96
- return U() && W(() => {
97
- j = !0, J(), E();
95
+ return Q() && U(() => {
96
+ j = !0, H(), E();
98
97
  }), e.manualRequest || m(), {
99
- dataSource: L,
100
- loading: w(() => S.value),
101
- error: v,
102
- pagination: w(() => ({
98
+ dataSource: F,
99
+ loading: S(() => O.value),
100
+ error: g,
101
+ pagination: S(() => ({
103
102
  ...e.pagination,
104
103
  current: o.value,
105
- pageSize: p.value,
106
- total: K.value
104
+ pageSize: c.value,
105
+ total: P.value
107
106
  })),
108
- query: w(() => r.value),
109
- sort: w(() => i.value),
110
- filters: w(() => c.value),
111
- manual: G,
112
- onChange: H,
113
- reload(l = !1) {
114
- return l && (o.value = 1), m(!0, !0);
107
+ query: S(() => r.value),
108
+ sort: S(() => n.value),
109
+ filters: S(() => f.value),
110
+ manual: B,
111
+ onChange: G,
112
+ reload(i = !1) {
113
+ return i && (o.value = 1), m(!0, !0);
115
114
  },
116
- submit(l = {}) {
117
- return r.value = n(l), o.value = 1, m();
115
+ submit(i = {}) {
116
+ return r.value = l(i), o.value = 1, m(!0);
118
117
  },
119
- reset() {
120
- return r.value = n(t), i.value = {}, c.value = {}, o.value = 1, m();
118
+ reset(i = t) {
119
+ return r.value = l(i), n.value = {}, f.value = {}, o.value = 1, m(!0);
121
120
  },
122
121
  cancel: E
123
122
  };
124
123
  }
125
124
  export {
126
- _ as useTableRequest
125
+ $ as useTableRequest
127
126
  };
@@ -25,6 +25,8 @@ export interface UseTreeDataOptions<TRecord = Record<string, unknown>> {
25
25
  indentSize?: () => number | undefined;
26
26
  /** Row key resolver */
27
27
  getRowKey: (record: TRecord, index: number) => Key;
28
+ /** Includes lazy parents whose children have not loaded yet. */
29
+ hasChildren?: (record: TRecord) => boolean;
28
30
  /** Default expanded keys (uncontrolled) */
29
31
  defaultExpandedRowKeys?: () => Key[] | undefined;
30
32
  /** Controlled expanded keys */
@@ -1 +1 @@
1
- {"version":3,"file":"useTreeData.d.ts","sourceRoot":"","sources":["../../../../../table/src/composables/useTreeData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAEnC,MAAM,WAAW,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAA;IACf,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAA;IACjB,sCAAsC;IACtC,WAAW,EAAE,OAAO,CAAA;IACpB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,GAAG,CAAA;CAChB;AAED,MAAM,WAAW,kBAAkB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACnE,2BAA2B;IAC3B,IAAI,EAAE,MAAM,OAAO,EAAE,CAAA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,GAAG,EAAE,GAAG,KAAK,OAAO,CAAA;IACrC,4BAA4B;IAC5B,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAC3B,wBAAwB;IACxB,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAChC;AAED,wBAAgB,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3F,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACnC,iBAAiB,CAAC,OAAO,CAAC,CAgK5B"}
@@ -1,97 +1,92 @@
1
- import { computed as s, ref as k, watch as z } from "vue";
2
- function M(e) {
3
- const o = s(() => e.childrenColumnName?.() ?? "children"), R = s(() => e.indentSize?.() ?? 15), v = s(() => {
4
- const a = o.value;
5
- return e.data().some(
6
- (t) => Array.isArray(t[a]) && t[a].length > 0
7
- );
8
- }), r = k(/* @__PURE__ */ new Set()), E = /* @__PURE__ */ new Set();
9
- let g = !1;
10
- const x = s(() => e.expandedRowKeys?.() !== void 0);
11
- z(
1
+ import { computed as r, ref as z, watch as T } from "vue";
2
+ function O(e) {
3
+ const f = r(() => e.childrenColumnName?.() ?? "children"), C = r(() => e.indentSize?.() ?? 15), x = (a) => e.hasChildren?.(a) ?? (Array.isArray(a[f.value]) && a[f.value].length > 0), o = r(() => e.data().some(x)), s = z(/* @__PURE__ */ new Set()), E = /* @__PURE__ */ new Set();
4
+ let K = !1;
5
+ const v = r(() => e.expandedRowKeys?.() !== void 0);
6
+ T(
12
7
  [
13
8
  () => e.data(),
14
9
  () => e.defaultExpandAllRows?.(),
15
10
  () => e.defaultExpandedRowKeys?.()
16
11
  ],
17
12
  () => {
18
- if (!x.value)
13
+ if (!v.value)
19
14
  if (e.defaultExpandAllRows?.()) {
20
15
  let a = function(n) {
21
16
  n.forEach((u) => {
22
- const c = u[w], f = l++;
23
- if (Array.isArray(c) && c.length > 0) {
24
- const y = e.getRowKey(u, f);
25
- (!t || !E.has(y)) && d.add(y), E.add(y), a(c);
17
+ const h = u[w], c = l++;
18
+ if (x(u)) {
19
+ const y = e.getRowKey(u, c);
20
+ (!d || !E.has(y)) && t.add(y), E.add(y), Array.isArray(h) && a(h);
26
21
  }
27
22
  });
28
23
  };
29
- const t = e.preserveStateOnDataChange?.() === !0, d = t ? new Set(r.value) : /* @__PURE__ */ new Set(), w = o.value;
24
+ const d = e.preserveStateOnDataChange?.() === !0, t = d ? new Set(s.value) : /* @__PURE__ */ new Set(), w = f.value;
30
25
  let l = 0;
31
- a(e.data()), r.value = d;
32
- } else e.defaultExpandedRowKeys?.() && (!e.preserveStateOnDataChange?.() || !g) && (r.value = new Set(e.defaultExpandedRowKeys()), g = !0);
26
+ a(e.data()), s.value = t;
27
+ } else e.defaultExpandedRowKeys?.() && (!e.preserveStateOnDataChange?.() || !K) && (s.value = new Set(e.defaultExpandedRowKeys()), K = !0);
33
28
  },
34
29
  { immediate: !0 }
35
30
  );
36
- const i = s({
37
- get: () => x.value ? new Set(e.expandedRowKeys()) : r.value,
31
+ const i = r({
32
+ get: () => v.value ? new Set(e.expandedRowKeys()) : s.value,
38
33
  set: (a) => {
39
- r.value = a;
34
+ s.value = a;
40
35
  }
41
36
  });
42
37
  function A(a) {
43
38
  return i.value.has(a);
44
39
  }
45
- function C(a, t) {
46
- const d = e.getRowKey(a, t), l = !i.value.has(d);
47
- if (x.value) {
40
+ function D(a, d) {
41
+ const t = e.getRowKey(a, d), l = !i.value.has(t);
42
+ if (v.value) {
48
43
  e.onExpand?.(l, a);
49
44
  const n = new Set(i.value);
50
- l ? n.add(d) : n.delete(d), e.onExpandedRowsChange?.(Array.from(n));
45
+ l ? n.add(t) : n.delete(t), e.onExpandedRowsChange?.(Array.from(n));
51
46
  } else {
52
- const n = new Set(r.value);
53
- l ? n.add(d) : n.delete(d), r.value = n, e.onExpand?.(l, a), e.onExpandedRowsChange?.(Array.from(n));
47
+ const n = new Set(s.value);
48
+ l ? n.add(t) : n.delete(t), s.value = n, e.onExpand?.(l, a), e.onExpandedRowsChange?.(Array.from(n));
54
49
  }
55
50
  }
56
- const K = s(() => {
51
+ const g = r(() => {
57
52
  const a = e.pageData?.() ?? e.data();
58
- if (!v.value)
53
+ if (!o.value)
59
54
  return a.map((n) => ({
60
55
  record: n,
61
56
  level: 0,
62
57
  expanded: !1,
63
58
  hasChildren: !1
64
59
  }));
65
- const t = o.value, d = [], w = i.value;
66
- function l(n, u, c) {
67
- n.forEach((f, y) => {
68
- const h = f[t], S = Array.isArray(h) && h.length > 0, m = e.getRowKey(f, d.length), p = S && w.has(m);
69
- d.push({
70
- record: f,
60
+ const d = f.value, t = [], w = i.value;
61
+ function l(n, u, h) {
62
+ n.forEach((c, y) => {
63
+ const S = c[d], m = x(c), p = e.getRowKey(c, t.length), R = m && w.has(p);
64
+ t.push({
65
+ record: c,
71
66
  level: u,
72
- expanded: p,
73
- hasChildren: S,
74
- parentKey: c
75
- }), p && h && l(h, u + 1, m);
67
+ expanded: R,
68
+ hasChildren: m,
69
+ parentKey: h
70
+ }), R && S && l(S, u + 1, p);
76
71
  });
77
72
  }
78
- return l(a, 0), d;
79
- }), D = s(() => {
73
+ return l(a, 0), t;
74
+ }), k = r(() => {
80
75
  const a = /* @__PURE__ */ new Map();
81
- for (const t of K.value)
82
- a.set(t.record, t);
76
+ for (const d of g.value)
77
+ a.set(d.record, d);
83
78
  return a;
84
79
  });
85
80
  return {
86
- flattenData: K,
87
- rowMetaMap: D,
88
- isTreeData: v,
89
- toggleTreeExpand: C,
81
+ flattenData: g,
82
+ rowMetaMap: k,
83
+ isTreeData: o,
84
+ toggleTreeExpand: D,
90
85
  isTreeExpanded: A,
91
- expandedKeys: r,
92
- indentSize: R
86
+ expandedKeys: s,
87
+ indentSize: C
93
88
  };
94
89
  }
95
90
  export {
96
- M as useTreeData
91
+ O as useTreeData
97
92
  };