@dazhicheng/ui 1.6.7 → 1.6.8

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 (93) hide show
  1. package/dist/components/tt-form/src/form-render/expandable.js +31 -32
  2. package/dist/components/tt-form/src/useFormContext.js +1 -1
  3. package/dist/components/tt-table/index.d.ts +3 -15
  4. package/dist/components/tt-table/index.js +5 -4
  5. package/dist/components/tt-table/src/Table.vue.d.ts +1 -1
  6. package/dist/components/tt-table/src/Table.vue.js +3 -3
  7. package/dist/components/tt-table/src/TableForm.vue.js +168 -159
  8. package/dist/components/tt-table/src/components/TableAction.vue.d.ts +2 -12
  9. package/dist/components/tt-table/src/components/TableAction.vue.js +78 -175
  10. package/dist/components/tt-table/src/hooks/useGridProps.js +64 -60
  11. package/dist/components/tt-table/src/hooks/useTableData.js +77 -74
  12. package/dist/components/tt-table/src/types/table.d.ts +2 -1
  13. package/dist/components/tt-table/src/utils/table-api.d.ts +2 -1
  14. package/dist/components/tt-table/src/utils/table-api.js +3 -2
  15. package/dist/components/tt-vtable/index.js +54 -0
  16. package/dist/components/tt-vtable/src/components/TtVTable.vue.d.ts +188 -0
  17. package/dist/components/tt-vtable/src/components/TtVTable.vue.js +227 -0
  18. package/dist/components/tt-vtable/src/components/TtVTable.vue2.js +4 -0
  19. package/dist/components/tt-vtable/src/components/TtVTableForm.vue.d.ts +32 -0
  20. package/dist/components/tt-vtable/src/components/TtVTableForm.vue.js +121 -0
  21. package/dist/components/tt-vtable/src/components/TtVTableForm.vue2.js +4 -0
  22. package/dist/components/tt-vtable/src/components/VTableEmpty.vue.d.ts +64 -0
  23. package/dist/components/tt-vtable/src/components/VTableEmpty.vue.js +97 -0
  24. package/dist/components/tt-vtable/src/components/VTableEmpty.vue2.js +4 -0
  25. package/dist/components/tt-vtable/src/components/VTablePagination.vue.d.ts +53 -0
  26. package/dist/components/tt-vtable/src/components/VTablePagination.vue.js +52 -0
  27. package/dist/components/tt-vtable/src/components/VTablePagination.vue2.js +4 -0
  28. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.d.ts +35 -0
  29. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.js +50 -0
  30. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue2.js +4 -0
  31. package/dist/components/tt-vtable/src/components/VTableToolbar.vue.d.ts +63 -0
  32. package/dist/components/tt-vtable/src/components/VTableToolbar.vue.js +126 -0
  33. package/dist/components/tt-vtable/src/components/VTableToolbar.vue2.js +4 -0
  34. package/dist/components/tt-vtable/src/components/VTableViewport.vue.js +133 -0
  35. package/dist/components/tt-vtable/src/components/VTableViewport.vue2.js +4 -0
  36. package/dist/components/tt-vtable/src/composables/useVTable.d.ts +41 -0
  37. package/dist/components/tt-vtable/src/composables/useVTable.js +25 -0
  38. package/dist/components/tt-vtable/src/composables/useVTableFormRender.d.ts +13 -0
  39. package/dist/components/tt-vtable/src/composables/useVTableFormRender.js +92 -0
  40. package/dist/components/tt-vtable/src/composables/useVTableRender.d.ts +13 -0
  41. package/dist/components/tt-vtable/src/composables/useVTableRender.js +13 -0
  42. package/dist/components/tt-vtable/src/engine/visactor/createListTable.d.ts +10 -0
  43. package/dist/components/tt-vtable/src/engine/visactor/createListTable.js +63 -0
  44. package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.d.ts +37 -0
  45. package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.js +133 -0
  46. package/dist/components/tt-vtable/src/engine/visactor/index.d.ts +8 -0
  47. package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.d.ts +23 -0
  48. package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.js +70 -0
  49. package/dist/components/tt-vtable/src/engine/visactor/record-adapter.d.ts +38 -0
  50. package/dist/components/tt-vtable/src/engine/visactor/record-adapter.js +41 -0
  51. package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.d.ts +45 -0
  52. package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.js +73 -0
  53. package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.d.ts +25 -0
  54. package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.js +25 -0
  55. package/dist/components/tt-vtable/src/engine/visactor/types.d.ts +29 -0
  56. package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.d.ts +36 -0
  57. package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.js +52 -0
  58. package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.d.ts +74 -0
  59. package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.js +232 -0
  60. package/dist/components/tt-vtable/src/features/editing/useCellEditing.d.ts +48 -0
  61. package/dist/components/tt-vtable/src/features/editing/useCellEditing.js +102 -0
  62. package/dist/components/tt-vtable/src/features/form-integration/useVTableForm.d.ts +51 -0
  63. package/dist/components/tt-vtable/src/features/pagination/useTablePagination.d.ts +40 -0
  64. package/dist/components/tt-vtable/src/features/pagination/useTablePagination.js +51 -0
  65. package/dist/components/tt-vtable/src/features/querying/useRecordQuery.d.ts +38 -0
  66. package/dist/components/tt-vtable/src/features/querying/useRecordQuery.js +57 -0
  67. package/dist/components/tt-vtable/src/features/records/index.d.ts +3 -0
  68. package/dist/components/tt-vtable/src/features/records/record-index.d.ts +122 -0
  69. package/dist/components/tt-vtable/src/features/records/record-index.js +209 -0
  70. package/dist/components/tt-vtable/src/features/records/useRecordSource.d.ts +41 -0
  71. package/dist/components/tt-vtable/src/features/records/useRecordSource.js +249 -0
  72. package/dist/components/tt-vtable/src/features/selection/useRowSelection.d.ts +65 -0
  73. package/dist/components/tt-vtable/src/features/selection/useRowSelection.js +129 -0
  74. package/dist/components/tt-vtable/src/features/tree/useTreeRecords.d.ts +60 -0
  75. package/dist/components/tt-vtable/src/features/tree/useTreeRecords.js +125 -0
  76. package/dist/components/tt-vtable/src/public/index.d.ts +7 -0
  77. package/dist/components/tt-vtable/src/public/table-api.d.ts +215 -0
  78. package/dist/components/tt-vtable/src/public/table-column.d.ts +123 -0
  79. package/dist/components/tt-vtable/src/public/table-errors.d.ts +26 -0
  80. package/dist/components/tt-vtable/src/public/table-errors.js +26 -0
  81. package/dist/components/tt-vtable/src/public/table-events.d.ts +69 -0
  82. package/dist/components/tt-vtable/src/public/table-props.d.ts +216 -0
  83. package/dist/components/tt-vtable/src/public/table-slots.d.ts +37 -0
  84. package/dist/components/tt-vtable/src/runtime/createVTableController.d.ts +12 -0
  85. package/dist/components/tt-vtable/src/runtime/createVTableController.js +238 -0
  86. package/dist/components/tt-vtable/src/runtime/createVTableRuntime.d.ts +79 -0
  87. package/dist/components/tt-vtable/src/runtime/createVTableRuntime.js +380 -0
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.js +129 -115
  90. package/dist/packages/utils/src/is.js +46 -37
  91. package/dist/style.css +1 -1
  92. package/package.json +3 -1
  93. package/dist/assets/svg/action_more.svg.js +0 -4
@@ -0,0 +1,52 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isClient as n, isObject as m, isNumber as i, isArray as a, isString as p, isBoolean as c, isDef as l } from "../../../../../packages/utils/src/is.js";
4
+ import "vue";
5
+ import "dayjs";
6
+ import "numeral";
7
+ import "xe-utils";
8
+ import "dayjs/plugin/utc";
9
+ import "dayjs/plugin/timezone";
10
+ import "../../../../../node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js";
11
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js";
12
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf8.js";
13
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js";
14
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-pkcs7.js";
15
+ import "lodash-es";
16
+ const d = "tt-vtable:columns:";
17
+ function S(e) {
18
+ return c(e) || e === "left" || e === "right";
19
+ }
20
+ function g(e) {
21
+ if (!m(e)) return !1;
22
+ const r = e;
23
+ return p(r.key) && !!r.key && c(r.visible) && i(r.order) && Number.isInteger(r.order) && r.order >= 0 && (!l(r.width) || i(r.width) && r.width > 0) && (!r.frozen || S(r.frozen));
24
+ }
25
+ function h(e) {
26
+ if (!m(e)) return !1;
27
+ const r = e;
28
+ return i(r.schemaVersion) && Number.isInteger(r.schemaVersion) && r.schemaVersion > 0 && a(r.columns) && r.columns.every(g);
29
+ }
30
+ function A() {
31
+ function e(t) {
32
+ return `${d}${t}`;
33
+ }
34
+ async function r(t) {
35
+ if (!n || !t) return;
36
+ const o = window.localStorage.getItem(e(t));
37
+ if (!o) return;
38
+ const s = JSON.parse(o);
39
+ return h(s) ? s : void 0;
40
+ }
41
+ async function f(t, o) {
42
+ !n || !t || window.localStorage.setItem(e(t), JSON.stringify(o));
43
+ }
44
+ async function u(t) {
45
+ !n || !t || window.localStorage.removeItem(e(t));
46
+ }
47
+ return { read: r, write: f, remove: u };
48
+ }
49
+ export {
50
+ A as createLocalColumnPreferenceStorage,
51
+ h as isColumnPreferenceSnapshot
52
+ };
@@ -0,0 +1,74 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ import { VTableColumnFrozen, VTableColumnPreference, VTableColumnPreferenceSnapshot, VTableColumnPreferenceStorage } from './column-preference-storage';
3
+ /** 列偏好 feature 所需的结构化列字段。 */
4
+ export interface VTablePreferenceColumn<Column> {
5
+ /** 稳定语义列主键。 */
6
+ key: string;
7
+ /** 可选嵌套分组列。 */
8
+ columns?: readonly Column[];
9
+ /** 初始可见性。 */
10
+ visible?: boolean;
11
+ /** 初始宽度。 */
12
+ width?: number | string;
13
+ /** 初始冻结位置。 */
14
+ frozen?: VTableColumnFrozen;
15
+ }
16
+ /** 面向工具栏的列偏好视图。 */
17
+ export interface VTableColumnPreferenceEntry<Column> extends VTableColumnPreference {
18
+ /** 当前源列。 */
19
+ column: Column;
20
+ /** 在语义列树中的嵌套深度。 */
21
+ depth: number;
22
+ }
23
+ /** 暴露给 runtime 的列偏好状态与动作。 */
24
+ export interface VTableColumnPreferences<Column> {
25
+ /** 应用偏好前的源列。 */
26
+ sourceColumns: Readonly<Ref<readonly Column[]>>;
27
+ /** 应用偏好后的可见有序列。 */
28
+ columns: ComputedRef<readonly Column[]>;
29
+ /** 面向工具栏的全部源列扁平设置。 */
30
+ entries: ComputedRef<readonly VTableColumnPreferenceEntry<Column>[]>;
31
+ /** 异步偏好读取是否进行中。 */
32
+ isLoading: Readonly<Ref<boolean>>;
33
+ /** 最近一次持久化错误。 */
34
+ error: Readonly<Ref<Error | undefined>>;
35
+ /** 替换源列根引用并校正已保存主键。 */
36
+ replaceAll: (columns: readonly Column[]) => void;
37
+ /** 显示一个语义列。 */
38
+ show: (key: string) => void;
39
+ /** 隐藏一个语义列。 */
40
+ hide: (key: string) => void;
41
+ /** 在同级列集合中移动一列。 */
42
+ move: (key: string, targetIndex: number) => void;
43
+ /** 保存一个数字列宽。 */
44
+ setWidth: (key: string, width: number) => void;
45
+ /** 保存一个冻结位置。 */
46
+ setFrozen: (key: string, frozen: VTableColumnFrozen | undefined) => void;
47
+ /** 从配置的 storage 加载偏好。 */
48
+ load: () => Promise<void>;
49
+ /** 恢复源列默认值并删除持久化内容。 */
50
+ resetPreferences: () => Promise<void>;
51
+ }
52
+ /** 列偏好 feature 所需依赖。 */
53
+ export interface UseColumnPreferencesOptions<Column extends VTablePreferenceColumn<Column>> {
54
+ /** 仅按引用监听的 maybe-reactive 源列根。 */
55
+ columns: MaybeRefOrGetter<readonly Column[]>;
56
+ /** 开启持久化时必需的命名空间。 */
57
+ columnsKey?: MaybeRefOrGetter<string | undefined>;
58
+ /** 是否开启偏好持久化。 */
59
+ persistent?: MaybeRefOrGetter<boolean>;
60
+ /** 随每份偏好快照写入的版本。 */
61
+ schemaVersion?: number;
62
+ /** 可选的本地或服务端 storage 实现。 */
63
+ storage?: VTableColumnPreferenceStorage;
64
+ /** 列宽和拖拽持久化的防抖时长。 */
65
+ writeDelay?: number;
66
+ /** 有效列变化时调用。 */
67
+ onColumnsChange?: (columns: readonly Column[]) => void;
68
+ /** 一次本地偏好操作完成后调用。 */
69
+ onPreferencesChange?: (snapshot: VTableColumnPreferenceSnapshot) => void;
70
+ /** 读取、写入或删除偏好失败时调用。 */
71
+ onError?: (error: Error) => void;
72
+ }
73
+ /** 创建可扩展且可防持久化竞态的列偏好 feature。 */
74
+ export declare function useColumnPreferences<Column extends VTablePreferenceColumn<Column>>(options: UseColumnPreferencesOptions<Column>): VTableColumnPreferences<Column>;
@@ -0,0 +1,232 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isDef as X, isError as Y, isNumber as Z, isClient as S } from "../../../../../packages/utils/src/is.js";
4
+ import { shallowRef as p, computed as O, watch as V, toValue as h, onScopeDispose as _ } from "vue";
5
+ import "dayjs";
6
+ import "numeral";
7
+ import "xe-utils";
8
+ import "dayjs/plugin/utc";
9
+ import "dayjs/plugin/timezone";
10
+ import "../../../../../node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js";
11
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js";
12
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf8.js";
13
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js";
14
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-pkcs7.js";
15
+ import "lodash-es";
16
+ import { createLocalColumnPreferenceStorage as $ } from "./column-preference-storage.js";
17
+ function ee(r) {
18
+ return new Error(Y(r) ? String(r).replace(/^Error:\s*/, "") : String(r));
19
+ }
20
+ function N(r) {
21
+ const o = /* @__PURE__ */ new Map();
22
+ function n(i) {
23
+ i.forEach((s, a) => {
24
+ var v;
25
+ const f = {
26
+ key: s.key,
27
+ visible: s.visible !== !1,
28
+ order: a
29
+ };
30
+ Z(s.width) && s.width > 0 && (f.width = s.width), s.frozen && (f.frozen = s.frozen), o.set(s.key, f), (v = s.columns) != null && v.length && n(s.columns);
31
+ });
32
+ }
33
+ return n(r), o;
34
+ }
35
+ function F(r, o) {
36
+ const n = N(r);
37
+ return n.forEach((i, s) => {
38
+ const a = o.get(s);
39
+ a && n.set(s, { ...i, ...a, key: s });
40
+ }), n;
41
+ }
42
+ function re(r, o) {
43
+ return { schemaVersion: o, columns: [...r.values()].map((n) => ({ ...n })) };
44
+ }
45
+ function ne(r) {
46
+ return new Map(r.columns.map((o) => [o.key, { ...o }]));
47
+ }
48
+ function q(r, o) {
49
+ var n;
50
+ if (r.some((i) => i.key === o)) return r.map((i) => i.key);
51
+ for (const i of r) {
52
+ if (!((n = i.columns) != null && n.length)) continue;
53
+ const s = q(i.columns, o);
54
+ if (s) return s;
55
+ }
56
+ }
57
+ function L(r, o) {
58
+ return [...r].sort((n, i) => {
59
+ var f, v;
60
+ const s = ((f = o.get(n.key)) == null ? void 0 : f.order) ?? 0, a = ((v = o.get(i.key)) == null ? void 0 : v.order) ?? 0;
61
+ return s - a;
62
+ }).filter((n) => {
63
+ var i;
64
+ return ((i = o.get(n.key)) == null ? void 0 : i.visible) !== !1;
65
+ }).map((n) => {
66
+ var f;
67
+ const i = o.get(n.key), s = (f = n.columns) != null && f.length ? L(n.columns, o) : void 0;
68
+ return {
69
+ ...n,
70
+ visible: !0,
71
+ ...i != null && i.width ? { width: i.width } : {},
72
+ ...X(i == null ? void 0 : i.frozen) ? { frozen: i.frozen } : {},
73
+ ...s ? { columns: s } : {}
74
+ };
75
+ });
76
+ }
77
+ function Pe(r) {
78
+ const o = p([]), n = p(/* @__PURE__ */ new Map()), i = p(!1), s = p(), a = r.storage ?? $(), f = r.schemaVersion ?? 1, v = Math.max(0, r.writeDelay ?? 180);
79
+ let d = 0, w = 0, l;
80
+ const M = O(() => L(o.value, n.value)), W = O(() => {
81
+ const e = [];
82
+ function t(c, u) {
83
+ c.forEach((m) => {
84
+ var g;
85
+ const y = n.value.get(m.key) ?? {
86
+ key: m.key,
87
+ visible: m.visible !== !1,
88
+ order: 0
89
+ };
90
+ e.push({ ...y, column: m, depth: u }), (g = m.columns) != null && g.length && t(m.columns, u + 1);
91
+ });
92
+ }
93
+ return t(o.value, 0), e;
94
+ });
95
+ function b() {
96
+ return h(r.columnsKey) || void 0;
97
+ }
98
+ function E(e) {
99
+ var c;
100
+ const t = ee(e);
101
+ s.value = t, (c = r.onError) == null || c.call(r, t);
102
+ }
103
+ function P() {
104
+ var e;
105
+ (e = r.onColumnsChange) == null || e.call(r, M.value);
106
+ }
107
+ function K() {
108
+ return re(n.value, f);
109
+ }
110
+ async function z() {
111
+ if (!h(r.persistent ?? !1)) return;
112
+ const e = b();
113
+ if (e)
114
+ try {
115
+ await a.write(e, K());
116
+ } catch (t) {
117
+ E(t);
118
+ }
119
+ }
120
+ function A() {
121
+ if (!S) {
122
+ z();
123
+ return;
124
+ }
125
+ l && window.clearTimeout(l), l = window.setTimeout(() => {
126
+ l = void 0, z();
127
+ }, v);
128
+ }
129
+ function x(e) {
130
+ var c;
131
+ w += 1, n.value = e;
132
+ const t = K();
133
+ P(), (c = r.onPreferencesChange) == null || c.call(r, t), A();
134
+ }
135
+ function k(e, t) {
136
+ o.value = [...e], n.value = F(o.value, n.value), t && (w += 1), P();
137
+ }
138
+ function I(e) {
139
+ k(e, !0);
140
+ }
141
+ function C(e, t) {
142
+ const c = n.value.get(e);
143
+ if (!c) return;
144
+ const u = new Map(n.value);
145
+ u.set(e, { ...c, ...t, key: e }), x(u);
146
+ }
147
+ function j(e) {
148
+ C(e, { visible: !0 });
149
+ }
150
+ function B(e) {
151
+ C(e, { visible: !1 });
152
+ }
153
+ function G(e, t) {
154
+ const c = q(o.value, e);
155
+ if (!c) return;
156
+ const u = c.indexOf(e);
157
+ if (u < 0) return;
158
+ const m = Number.isFinite(t) ? Math.max(0, Math.min(Math.floor(t), c.length - 1)) : u;
159
+ if (u === m) return;
160
+ const y = [...c];
161
+ y.splice(u, 1), y.splice(m, 0, e);
162
+ const g = new Map(n.value);
163
+ y.forEach((D, U) => {
164
+ const R = g.get(D);
165
+ R && g.set(D, { ...R, order: U });
166
+ }), x(g);
167
+ }
168
+ function H(e, t) {
169
+ !Number.isFinite(t) || t <= 0 || C(e, { width: t });
170
+ }
171
+ function J(e, t) {
172
+ C(e, { frozen: t ?? !1 });
173
+ }
174
+ async function T() {
175
+ if (!h(r.persistent ?? !1)) return;
176
+ const e = b();
177
+ if (!e) return;
178
+ d += 1;
179
+ const t = d, c = w;
180
+ i.value = !0, s.value = void 0;
181
+ try {
182
+ const u = await a.read(e);
183
+ if (t !== d || c !== w || !u || u.schemaVersion !== f) return;
184
+ n.value = F(o.value, ne(u)), P();
185
+ } catch (u) {
186
+ t === d && E(u);
187
+ } finally {
188
+ t === d && (i.value = !1);
189
+ }
190
+ }
191
+ async function Q() {
192
+ var t;
193
+ w += 1, d += 1, l && S && window.clearTimeout(l), l = void 0, n.value = N(o.value), s.value = void 0, P(), (t = r.onPreferencesChange) == null || t.call(r, K());
194
+ const e = b();
195
+ if (!(!e || !h(r.persistent ?? !1)))
196
+ try {
197
+ await a.remove(e);
198
+ } catch (c) {
199
+ E(c);
200
+ }
201
+ }
202
+ return V(
203
+ () => h(r.columns),
204
+ (e) => k(e, !1),
205
+ { immediate: !0 }
206
+ ), V(
207
+ [() => h(r.persistent ?? !1), () => h(r.columnsKey)],
208
+ ([e]) => {
209
+ e && T();
210
+ },
211
+ { immediate: !0 }
212
+ ), _(() => {
213
+ d += 1, l && S && window.clearTimeout(l);
214
+ }), {
215
+ sourceColumns: o,
216
+ columns: M,
217
+ entries: W,
218
+ isLoading: i,
219
+ error: s,
220
+ replaceAll: I,
221
+ show: j,
222
+ hide: B,
223
+ move: G,
224
+ setWidth: H,
225
+ setFrozen: J,
226
+ load: T,
227
+ resetPreferences: Q
228
+ };
229
+ }
230
+ export {
231
+ Pe as useColumnPreferences
232
+ };
@@ -0,0 +1,48 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+ import { TtVTableEditingCell, TtVTableFieldPath, TtVTableRowKey } from '../../public/table-api';
3
+ import { TtVTableEditCommit } from '../../public/table-events';
4
+ import { TtVTableEditValidator } from '../../public/table-props';
5
+ /** 暴露给 runtime 的编辑状态与动作。 */
6
+ export interface VTableCellEditing<Key extends TtVTableRowKey> {
7
+ /** 当前单元格;未编辑时为 undefined。 */
8
+ activeCell: Readonly<Ref<Readonly<TtVTableEditingCell<Key>> | undefined>>;
9
+ /** 当前单元格是否正在校验。 */
10
+ isValidating: Readonly<Ref<boolean>>;
11
+ /** 当前校验错误。 */
12
+ validationError: Readonly<Ref<Error | undefined>>;
13
+ /** 是否存在活动编辑器。 */
14
+ isEditing: ComputedRef<boolean>;
15
+ /** 开始编辑单元格。 */
16
+ start: (rowKey: Key, field: TtVTableFieldPath) => Promise<void>;
17
+ /** 更新草稿且不修改 runtime 记录。 */
18
+ setValue: (value: unknown) => void;
19
+ /** 校验并提交当前草稿。 */
20
+ commit: (value?: unknown) => Promise<boolean>;
21
+ /** 取消当前编辑。 */
22
+ cancel: () => void;
23
+ /** 仅校验当前草稿且不提交。 */
24
+ validate: (value?: unknown) => Promise<boolean>;
25
+ /** 组件销毁时释放编辑器状态。 */
26
+ release: () => void;
27
+ }
28
+ /** 单元格编辑 feature 所需依赖。 */
29
+ export interface UseCellEditingOptions<Row extends Record<string, unknown>, Key extends TtVTableRowKey> {
30
+ /** 按主键读取一条 runtime 记录。 */
31
+ getRecordByKey: (key: Key) => Row | undefined;
32
+ /** 从 runtime 记录读取字段值。 */
33
+ getFieldValue: (record: Row, field: TtVTableFieldPath) => unknown;
34
+ /** 通过 records feature 提交一个单元格。 */
35
+ setCellValue: (key: Key, field: TtVTableFieldPath, value: unknown, source: "editing") => Promise<void> | void;
36
+ /** 读取字段配置的校验函数。 */
37
+ getValidator?: (field: TtVTableFieldPath) => TtVTableEditValidator<Row, Key> | undefined;
38
+ /** 捕获状态后打开原生或 Vue 编辑器。 */
39
+ startNativeEditing?: (key: Key, field: TtVTableFieldPath) => Promise<void> | void;
40
+ /** 关闭原生或 Vue 编辑器。 */
41
+ cancelNativeEditing?: () => void;
42
+ /** 编辑提交成功后调用一次。 */
43
+ onCommit?: (change: TtVTableEditCommit<Key>) => void;
44
+ /** 校验或提交失败时调用。 */
45
+ onError?: (error: Error) => void;
46
+ }
47
+ /** 创建草稿隔离且可防异步校验竞态的编辑 feature。 */
48
+ export declare function useCellEditing<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey>(options: UseCellEditingOptions<Row, Key>): VTableCellEditing<Key>;
@@ -0,0 +1,102 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isError as B } from "../../../../../packages/utils/src/is.js";
4
+ import { shallowRef as g, computed as F } from "vue";
5
+ import "dayjs";
6
+ import "numeral";
7
+ import "xe-utils";
8
+ import "dayjs/plugin/utc";
9
+ import "dayjs/plugin/timezone";
10
+ import "../../../../../node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js";
11
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js";
12
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf8.js";
13
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js";
14
+ import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-pkcs7.js";
15
+ import "lodash-es";
16
+ function o(e, a) {
17
+ return !!e && !!a && e.rowKey === a.rowKey && e.field === a.field;
18
+ }
19
+ function N(e) {
20
+ if (e === !1) return new Error("Cell validation failed.");
21
+ if (!(e === !0 || !e))
22
+ return new Error(e);
23
+ }
24
+ function S(e) {
25
+ return new Error(B(e) ? String(e).replace(/^Error:\s*/, "") : String(e));
26
+ }
27
+ function P(e) {
28
+ const a = g(), d = g(!1), u = g();
29
+ let n = 0;
30
+ const K = F(() => !!a.value);
31
+ async function x(l, c) {
32
+ var i;
33
+ const r = e.getRecordByKey(l);
34
+ if (!r) throw new Error(`Cannot edit missing record "${String(l)}".`);
35
+ const t = e.getFieldValue(r, c);
36
+ n += 1, u.value = void 0, a.value = { rowKey: l, field: c, previousValue: t, value: t }, await ((i = e.startNativeEditing) == null ? void 0 : i.call(e, l, c));
37
+ }
38
+ function w(l) {
39
+ a.value && (a.value = { ...a.value, value: l });
40
+ }
41
+ async function y(l = ((c) => (c = a.value) == null ? void 0 : c.value)()) {
42
+ var m, V, h;
43
+ const r = a.value;
44
+ if (!r) return !1;
45
+ const t = e.getRecordByKey(r.rowKey);
46
+ if (!t) return !1;
47
+ const i = (m = e.getValidator) == null ? void 0 : m.call(e, r.field);
48
+ if (!i)
49
+ return u.value = void 0, !0;
50
+ n += 1;
51
+ const f = n;
52
+ d.value = !0, u.value = void 0;
53
+ try {
54
+ const E = await i({
55
+ record: t,
56
+ rowKey: r.rowKey,
57
+ field: r.field,
58
+ previousValue: r.previousValue,
59
+ value: l
60
+ });
61
+ if (f !== n || !o(r, a.value)) return !1;
62
+ const v = N(E);
63
+ return u.value = v, v && ((V = e.onError) == null || V.call(e, v)), !v;
64
+ } catch (E) {
65
+ const v = S(E);
66
+ return f !== n || !o(r, a.value) || (u.value = v, (h = e.onError) == null || h.call(e, v)), !1;
67
+ } finally {
68
+ f === n && (d.value = !1);
69
+ }
70
+ }
71
+ async function C(l = ((c) => (c = a.value) == null ? void 0 : c.value)()) {
72
+ var t, i;
73
+ const r = a.value;
74
+ if (!r || d.value || (w(l), !await y(l) || !o(r, a.value))) return !1;
75
+ try {
76
+ if (await e.setCellValue(r.rowKey, r.field, l, "editing"), !o(r, a.value)) return !1;
77
+ const f = {
78
+ rowKey: r.rowKey,
79
+ field: r.field,
80
+ previousValue: r.previousValue,
81
+ value: l,
82
+ changedFields: [r.field],
83
+ source: "editing"
84
+ };
85
+ return a.value = void 0, u.value = void 0, (t = e.onCommit) == null || t.call(e, f), !0;
86
+ } catch (f) {
87
+ const m = S(f);
88
+ return u.value = m, (i = e.onError) == null || i.call(e, m), !1;
89
+ }
90
+ }
91
+ function s() {
92
+ var l;
93
+ n += 1, d.value = !1, u.value = void 0, a.value = void 0, (l = e.cancelNativeEditing) == null || l.call(e);
94
+ }
95
+ function q() {
96
+ s();
97
+ }
98
+ return { activeCell: a, isValidating: d, validationError: u, isEditing: K, start: x, setValue: w, commit: C, cancel: s, validate: y, release: q };
99
+ }
100
+ export {
101
+ P as useCellEditing
102
+ };
@@ -0,0 +1,51 @@
1
+ import { Ref } from 'vue';
2
+ import { TtExtendedFormApi, TtFormProps } from '../../../../tt-form';
3
+ import { TtVTableApi, TtVTableRowKey } from '../../public/table-api';
4
+ import { TtVTableProps } from '../../public/table-props';
5
+ /** TtVTableForm 的组合属性。 */
6
+ export interface TtVTableFormProps<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey, FormValues extends Record<string, unknown> = Record<string, unknown>> {
7
+ /** TtForm 配置。 */
8
+ form: TtFormProps<FormValues>;
9
+ /** TtVTable 配置。 */
10
+ table: TtVTableProps<Row, Key, FormValues>;
11
+ }
12
+ /** TtVTableForm 仅组合 form 与 table 两个命名空间。 */
13
+ export interface TtVTableFormApi<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> {
14
+ /** 稳定 TtForm API。 */
15
+ form: TtExtendedFormApi;
16
+ /** 稳定 TtVTable API。 */
17
+ table: TtVTableApi<Row, Key>;
18
+ }
19
+ /** 表单查询状态写入策略。 */
20
+ export interface VTableFormQueryStrategy {
21
+ /** 是否把分页恢复为初始状态。 */
22
+ resetPagination: boolean;
23
+ /** 是否同时清理排序和筛选。 */
24
+ resetSortAndFilters: boolean;
25
+ }
26
+ /** 表单与表格联动 feature 所需依赖。 */
27
+ export interface UseVTableFormOptions<FormValues extends Record<string, unknown>> {
28
+ /** 初始查询参数根快照。 */
29
+ initialQueryParams?: Readonly<Partial<FormValues>>;
30
+ /** 原子写入查询参数及对应重置策略。 */
31
+ applyQueryState: (queryParams: Readonly<Partial<FormValues>>, strategy: VTableFormQueryStrategy) => void;
32
+ /** 使用当前查询状态发起远程请求。 */
33
+ fetchRecords: () => Promise<boolean>;
34
+ /** 表单提交并准备查询前调用。 */
35
+ onSubmit?: (values: Readonly<FormValues>) => Promise<void> | void;
36
+ /** 表单重置并准备查询前调用。 */
37
+ onReset?: (values: Readonly<FormValues>) => Promise<void> | void;
38
+ }
39
+ /** 表单与表格联动状态及动作。 */
40
+ export interface VTableFormIntegration<FormValues extends Record<string, unknown>> {
41
+ /** 当前不可变查询参数根快照。 */
42
+ queryParams: Readonly<Ref<Readonly<Partial<FormValues>>>>;
43
+ /** 是否正在执行提交或重置查询。 */
44
+ isSubmitting: Readonly<Ref<boolean>>;
45
+ /** 提交表单并执行一次查询。 */
46
+ submit: (values: FormValues) => Promise<boolean>;
47
+ /** 重置表单状态并执行一次查询。 */
48
+ reset: (values: FormValues) => Promise<boolean>;
49
+ }
50
+ /** 创建表单提交、重置与表格查询之间的单向联动。 */
51
+ export declare function useVTableForm<FormValues extends Record<string, unknown>>(options: UseVTableFormOptions<FormValues>): VTableFormIntegration<FormValues>;
@@ -0,0 +1,40 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ import { TtVTablePageChange } from '../../public/table-events';
3
+ /** 暴露给 runtime 的分页状态与动作。 */
4
+ export interface VTablePagination<Row> {
5
+ /** 当前从 1 开始的页码。 */
6
+ page: Readonly<Ref<number>>;
7
+ /** 每页记录数。 */
8
+ pageSize: Readonly<Ref<number>>;
9
+ /** 记录总数。 */
10
+ total: ComputedRef<number>;
11
+ /** 总页数。 */
12
+ pageCount: ComputedRef<number>;
13
+ /** 当前本地页记录,远程模式下为已加载记录。 */
14
+ pageRecords: ComputedRef<readonly Row[]>;
15
+ /** 修改当前页码。 */
16
+ setPage: (page: number) => void;
17
+ /** 修改每页数量并回到第一页。 */
18
+ setPageSize: (pageSize: number) => void;
19
+ /** 恢复配置的初始分页状态。 */
20
+ reset: () => void;
21
+ /** 接收最近一次有效远程响应的总数。 */
22
+ setRemoteTotal: (total: number) => void;
23
+ /** records 或 total 变化后校正页码。 */
24
+ reconcilePage: () => void;
25
+ }
26
+ /** 分页 feature 所需依赖。 */
27
+ export interface UseTablePaginationOptions<Row> {
28
+ /** 初始从 1 开始的页码。 */
29
+ initialPage?: number;
30
+ /** 初始每页记录数。 */
31
+ initialPageSize?: number;
32
+ /** 是否使用远程记录源。 */
33
+ isRemote: MaybeRefOrGetter<boolean>;
34
+ /** 读取 runtime 当前加载的记录。 */
35
+ getRecords: () => readonly Row[];
36
+ /** 每次语义分页变化调用一次。 */
37
+ onChange?: (change: TtVTablePageChange) => Promise<void> | void;
38
+ }
39
+ /** 创建单一状态源的本地或远程分页。 */
40
+ export declare function useTablePagination<Row>(options: UseTablePaginationOptions<Row>): VTablePagination<Row>;
@@ -0,0 +1,51 @@
1
+ import { shallowRef as f, computed as s, toValue as h, watch as S } from "vue";
2
+ function r(e, i) {
3
+ return !Number.isFinite(e) || e <= 0 ? i : Math.max(1, Math.floor(e));
4
+ }
5
+ function x(e) {
6
+ return !Number.isFinite(e) || e <= 0 ? 0 : Math.floor(e);
7
+ }
8
+ function b(e) {
9
+ const i = r(e.initialPage ?? 1, 1), o = r(e.initialPageSize ?? 20, 20), a = f(i), n = f(o), m = f(0), c = s(() => h(e.isRemote) ? m.value : e.getRecords().length), l = s(() => Math.max(1, Math.ceil(c.value / n.value))), P = s(() => {
10
+ const u = e.getRecords();
11
+ if (h(e.isRemote)) return u;
12
+ const t = (a.value - 1) * n.value;
13
+ return u.slice(t, t + n.value);
14
+ });
15
+ function g(u) {
16
+ var t;
17
+ (t = e.onChange) == null || t.call(e, { page: a.value, pageSize: n.value, reason: u });
18
+ }
19
+ function d(u) {
20
+ const t = Math.min(r(u, a.value), l.value);
21
+ t !== a.value && (a.value = t, g("page"));
22
+ }
23
+ function z(u) {
24
+ const t = r(u, n.value);
25
+ t === n.value && a.value === 1 || (n.value = t, a.value = 1, g("page-size"));
26
+ }
27
+ function R() {
28
+ a.value === i && n.value === o || (a.value = i, n.value = o, g("reset"));
29
+ }
30
+ function M(u) {
31
+ m.value = x(u), v();
32
+ }
33
+ function v() {
34
+ a.value <= l.value || (a.value = l.value);
35
+ }
36
+ return S(c, v), {
37
+ page: a,
38
+ pageSize: n,
39
+ total: c,
40
+ pageCount: l,
41
+ pageRecords: P,
42
+ setPage: d,
43
+ setPageSize: z,
44
+ reset: R,
45
+ setRemoteTotal: M,
46
+ reconcilePage: v
47
+ };
48
+ }
49
+ export {
50
+ b as useTablePagination
51
+ };