@dazhicheng/ui 1.6.6 → 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 (105) hide show
  1. package/dist/components/tt-area/TtArea.vue.js +1 -1
  2. package/dist/components/tt-drawer/src/components/DrawerHeader.vue.js +2 -2
  3. package/dist/components/tt-form/src/form-render/expandable.js +31 -32
  4. package/dist/components/tt-form/src/useFormContext.js +1 -1
  5. package/dist/components/tt-icon/index.vue.js +2 -2
  6. package/dist/components/tt-loading/src/loading.vue.js +2 -2
  7. package/dist/components/tt-modal/src/utils/resolve-modal-target.js +1 -3
  8. package/dist/components/tt-panel-select/src/components/PanelMiddle.vue.d.ts +2 -2
  9. package/dist/components/tt-table/index.d.ts +3 -15
  10. package/dist/components/tt-table/index.js +5 -4
  11. package/dist/components/tt-table/src/Table.vue.d.ts +1 -1
  12. package/dist/components/tt-table/src/Table.vue.js +3 -3
  13. package/dist/components/tt-table/src/TableForm.vue.d.ts +0 -9
  14. package/dist/components/tt-table/src/TableForm.vue.js +175 -167
  15. package/dist/components/tt-table/src/components/TableAction.vue.d.ts +2 -12
  16. package/dist/components/tt-table/src/components/TableAction.vue.js +78 -175
  17. package/dist/components/tt-table/src/hooks/useGridProps.js +64 -60
  18. package/dist/components/tt-table/src/hooks/useTableData.js +77 -74
  19. package/dist/components/tt-table/src/hooks/useTableForm.js +22 -23
  20. package/dist/components/tt-table/src/props.d.ts +0 -5
  21. package/dist/components/tt-table/src/props.js +22 -31
  22. package/dist/components/tt-table/src/types/table.d.ts +2 -1
  23. package/dist/components/tt-table/src/types/tableForm.d.ts +0 -2
  24. package/dist/components/tt-table/src/utils/table-api.d.ts +2 -1
  25. package/dist/components/tt-table/src/utils/table-api.js +3 -2
  26. package/dist/components/tt-table/src/utils/table-form-api.js +14 -15
  27. package/dist/components/tt-vtable/index.js +54 -0
  28. package/dist/components/tt-vtable/src/components/TtVTable.vue.d.ts +188 -0
  29. package/dist/components/tt-vtable/src/components/TtVTable.vue.js +227 -0
  30. package/dist/components/tt-vtable/src/components/TtVTable.vue2.js +4 -0
  31. package/dist/components/tt-vtable/src/components/TtVTableForm.vue.d.ts +32 -0
  32. package/dist/components/tt-vtable/src/components/TtVTableForm.vue.js +121 -0
  33. package/dist/components/tt-vtable/src/components/TtVTableForm.vue2.js +4 -0
  34. package/dist/components/tt-vtable/src/components/VTableEmpty.vue.d.ts +64 -0
  35. package/dist/components/tt-vtable/src/components/VTableEmpty.vue.js +97 -0
  36. package/dist/components/tt-vtable/src/components/VTableEmpty.vue2.js +4 -0
  37. package/dist/components/tt-vtable/src/components/VTablePagination.vue.d.ts +53 -0
  38. package/dist/components/tt-vtable/src/components/VTablePagination.vue.js +52 -0
  39. package/dist/components/tt-vtable/src/components/VTablePagination.vue2.js +4 -0
  40. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.d.ts +35 -0
  41. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.js +50 -0
  42. package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue2.js +4 -0
  43. package/dist/components/tt-vtable/src/components/VTableToolbar.vue.d.ts +63 -0
  44. package/dist/components/tt-vtable/src/components/VTableToolbar.vue.js +126 -0
  45. package/dist/components/tt-vtable/src/components/VTableToolbar.vue2.js +4 -0
  46. package/dist/components/tt-vtable/src/components/VTableViewport.vue.js +133 -0
  47. package/dist/components/tt-vtable/src/components/VTableViewport.vue2.js +4 -0
  48. package/dist/components/tt-vtable/src/composables/useVTable.d.ts +41 -0
  49. package/dist/components/tt-vtable/src/composables/useVTable.js +25 -0
  50. package/dist/components/tt-vtable/src/composables/useVTableFormRender.d.ts +13 -0
  51. package/dist/components/tt-vtable/src/composables/useVTableFormRender.js +92 -0
  52. package/dist/components/tt-vtable/src/composables/useVTableRender.d.ts +13 -0
  53. package/dist/components/tt-vtable/src/composables/useVTableRender.js +13 -0
  54. package/dist/components/tt-vtable/src/engine/visactor/createListTable.d.ts +10 -0
  55. package/dist/components/tt-vtable/src/engine/visactor/createListTable.js +63 -0
  56. package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.d.ts +37 -0
  57. package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.js +133 -0
  58. package/dist/components/tt-vtable/src/engine/visactor/index.d.ts +8 -0
  59. package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.d.ts +23 -0
  60. package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.js +70 -0
  61. package/dist/components/tt-vtable/src/engine/visactor/record-adapter.d.ts +38 -0
  62. package/dist/components/tt-vtable/src/engine/visactor/record-adapter.js +41 -0
  63. package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.d.ts +45 -0
  64. package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.js +73 -0
  65. package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.d.ts +25 -0
  66. package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.js +25 -0
  67. package/dist/components/tt-vtable/src/engine/visactor/types.d.ts +29 -0
  68. package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.d.ts +36 -0
  69. package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.js +52 -0
  70. package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.d.ts +74 -0
  71. package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.js +232 -0
  72. package/dist/components/tt-vtable/src/features/editing/useCellEditing.d.ts +48 -0
  73. package/dist/components/tt-vtable/src/features/editing/useCellEditing.js +102 -0
  74. package/dist/components/tt-vtable/src/features/form-integration/useVTableForm.d.ts +51 -0
  75. package/dist/components/tt-vtable/src/features/pagination/useTablePagination.d.ts +40 -0
  76. package/dist/components/tt-vtable/src/features/pagination/useTablePagination.js +51 -0
  77. package/dist/components/tt-vtable/src/features/querying/useRecordQuery.d.ts +38 -0
  78. package/dist/components/tt-vtable/src/features/querying/useRecordQuery.js +57 -0
  79. package/dist/components/tt-vtable/src/features/records/index.d.ts +3 -0
  80. package/dist/components/tt-vtable/src/features/records/record-index.d.ts +122 -0
  81. package/dist/components/tt-vtable/src/features/records/record-index.js +209 -0
  82. package/dist/components/tt-vtable/src/features/records/useRecordSource.d.ts +41 -0
  83. package/dist/components/tt-vtable/src/features/records/useRecordSource.js +249 -0
  84. package/dist/components/tt-vtable/src/features/selection/useRowSelection.d.ts +65 -0
  85. package/dist/components/tt-vtable/src/features/selection/useRowSelection.js +129 -0
  86. package/dist/components/tt-vtable/src/features/tree/useTreeRecords.d.ts +60 -0
  87. package/dist/components/tt-vtable/src/features/tree/useTreeRecords.js +125 -0
  88. package/dist/components/tt-vtable/src/public/index.d.ts +7 -0
  89. package/dist/components/tt-vtable/src/public/table-api.d.ts +215 -0
  90. package/dist/components/tt-vtable/src/public/table-column.d.ts +123 -0
  91. package/dist/components/tt-vtable/src/public/table-errors.d.ts +26 -0
  92. package/dist/components/tt-vtable/src/public/table-errors.js +26 -0
  93. package/dist/components/tt-vtable/src/public/table-events.d.ts +69 -0
  94. package/dist/components/tt-vtable/src/public/table-props.d.ts +216 -0
  95. package/dist/components/tt-vtable/src/public/table-slots.d.ts +37 -0
  96. package/dist/components/tt-vtable/src/runtime/createVTableController.d.ts +12 -0
  97. package/dist/components/tt-vtable/src/runtime/createVTableController.js +238 -0
  98. package/dist/components/tt-vtable/src/runtime/createVTableRuntime.d.ts +79 -0
  99. package/dist/components/tt-vtable/src/runtime/createVTableRuntime.js +380 -0
  100. package/dist/index.d.ts +1 -0
  101. package/dist/index.js +129 -115
  102. package/dist/packages/utils/src/is.js +46 -37
  103. package/dist/style.css +1 -1
  104. package/package.json +3 -1
  105. package/dist/assets/svg/action_more.svg.js +0 -4
@@ -0,0 +1,65 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ import { TtVTableRowKey } from '../../public/table-api';
3
+ import { TtVTableSelectionOptions } from '../../public/table-props';
4
+ /** 支持的行选择模式。 */
5
+ export type VTableSelectionMode = NonNullable<TtVTableSelectionOptions<unknown>["mode"]>;
6
+ /** 暴露给表格 runtime 的选择状态。 */
7
+ export interface VTableSelectionState<Row, Key extends TtVTableRowKey> {
8
+ /** 按选择顺序稳定排列的主键。 */
9
+ keys: ComputedRef<readonly Key[]>;
10
+ /** 当前 runtime 数据源中仍存在的已选记录。 */
11
+ loadedRows: ComputedRef<readonly Row[]>;
12
+ /** 当前 runtime 数据源中不存在的已选主键。 */
13
+ missingKeys: ComputedRef<readonly Key[]>;
14
+ /** 是否正在把公共 model 同步到原生选择状态。 */
15
+ isSyncingNative: Readonly<Ref<boolean>>;
16
+ }
17
+ /** 挂载到表格命名空间 API 的选择动作。 */
18
+ export interface VTableSelectionActions<Row, Key extends TtVTableRowKey> {
19
+ /** 替换全部已选主键。 */
20
+ setKeys: (keys: readonly Key[]) => void;
21
+ /** 按主键切换一条记录的选择状态。 */
22
+ toggleKey: (key: Key, selected?: boolean) => void;
23
+ /** 选择当前页全部可选记录。 */
24
+ selectCurrentPage: () => void;
25
+ /** 选择 runtime 当前已加载的全部可选记录。 */
26
+ selectLoadedRecords: () => void;
27
+ /** 清空选择。 */
28
+ clear: () => void;
29
+ /** 判断记录是否允许选择。 */
30
+ isSelectable: (record: Row) => boolean;
31
+ }
32
+ /** 完整的选择 feature 契约。 */
33
+ export interface VTableRowSelection<Row, Key extends TtVTableRowKey> extends VTableSelectionState<Row, Key>, VTableSelectionActions<Row, Key> {
34
+ /** 接收并应用 VTable 的 checkbox 或 radio 变化。 */
35
+ onNativeSelectionChange: (record: Row, selected: boolean) => void;
36
+ /** runtime 记录源变化后校正已选主键。 */
37
+ reconcileRecords: () => void;
38
+ /** 原生实例 ready 后同步最终选择状态。 */
39
+ syncNativeState: () => Promise<void>;
40
+ }
41
+ /** 行选择 feature 所需依赖。 */
42
+ export interface UseRowSelectionOptions<Row, Key extends TtVTableRowKey> {
43
+ /** 选择模式。 */
44
+ mode: MaybeRefOrGetter<VTableSelectionMode>;
45
+ /** 公共 selected-row-keys model。 */
46
+ selectedRowKeys: Ref<Key[]>;
47
+ /** 读取 runtime 当前加载的全部记录。 */
48
+ getLoadedRecords: () => readonly Row[];
49
+ /** 读取当前本地页或远程页记录。 */
50
+ getCurrentPageRecords: () => readonly Row[];
51
+ /** 按业务主键读取一条已加载记录。 */
52
+ getRecordByKey: (key: Key) => Row | undefined;
53
+ /** 读取记录的稳定业务主键。 */
54
+ getRowKey: (record: Row) => Key;
55
+ /** 可选的业务可选性判断函数。 */
56
+ isRowSelectable?: (record: Row) => boolean;
57
+ /** 是否跨远程分页保留未加载主键。 */
58
+ reserveAcrossPages?: MaybeRefOrGetter<boolean>;
59
+ /** 返回参与树级联的记录,结果包含源记录。 */
60
+ getCascadeRecords?: (record: Row) => readonly Row[];
61
+ /** 把公共主键同步到原生 checkbox 或 radio 视觉状态。 */
62
+ syncNativeSelection?: (keys: readonly Key[]) => Promise<void> | void;
63
+ }
64
+ /** 创建受控的单选或多选行选择 feature。 */
65
+ export declare function useRowSelection<Row, Key extends TtVTableRowKey = TtVTableRowKey>(options: UseRowSelectionOptions<Row, Key>): VTableRowSelection<Row, Key>;
@@ -0,0 +1,129 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isNumber as L, isString as V } from "../../../../../packages/utils/src/is.js";
4
+ import { shallowRef as F, computed as o, toValue as K, watch as S } 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 M(e) {
17
+ return V(e) ? !!e : L(e) && Number.isFinite(e);
18
+ }
19
+ function w(e, n) {
20
+ return e.length === n.length && e.every((u, c) => u === n[c]);
21
+ }
22
+ function O(e) {
23
+ const n = /* @__PURE__ */ new Set(), u = [];
24
+ return e.forEach((c) => {
25
+ !M(c) || n.has(c) || (n.add(c), u.push(c));
26
+ }), u;
27
+ }
28
+ function p(e) {
29
+ const n = F(!1);
30
+ let u = 0;
31
+ const c = o(() => K(e.mode)), s = o(() => d(e.selectedRowKeys.value)), h = o(() => {
32
+ const t = [];
33
+ return s.value.forEach((r) => {
34
+ const l = e.getRecordByKey(r);
35
+ l && t.push(l);
36
+ }), t;
37
+ }), N = o(() => s.value.filter((t) => !e.getRecordByKey(t)));
38
+ function d(t) {
39
+ const r = O(t);
40
+ return c.value === "none" ? [] : c.value === "single" ? r.slice(0, 1) : r;
41
+ }
42
+ function i(t) {
43
+ return e.isRowSelectable ? e.isRowSelectable(t) : !0;
44
+ }
45
+ function a(t) {
46
+ const r = d(t);
47
+ w(e.selectedRowKeys.value, r) || (e.selectedRowKeys.value = r);
48
+ }
49
+ function b(t) {
50
+ var l;
51
+ return (((l = e.getCascadeRecords) == null ? void 0 : l.call(e, t)) ?? [t]).filter(i).map(e.getRowKey);
52
+ }
53
+ function m(t, r) {
54
+ const l = e.getRecordByKey(t);
55
+ if (!l || !i(l) || c.value === "none") return;
56
+ const x = s.value.includes(t), R = r ?? !x, A = c.value === "single" ? [t] : b(l);
57
+ if (c.value === "single") {
58
+ a(R ? [t] : []);
59
+ return;
60
+ }
61
+ const f = new Set(s.value);
62
+ A.forEach((g) => {
63
+ R ? f.add(g) : f.delete(g);
64
+ }), a([...f]);
65
+ }
66
+ function v(t) {
67
+ if (c.value === "none") return;
68
+ const r = t.filter(i).map(e.getRowKey);
69
+ if (c.value === "single") {
70
+ a(r.slice(0, 1));
71
+ return;
72
+ }
73
+ a([...s.value, ...r]);
74
+ }
75
+ function z() {
76
+ v(e.getCurrentPageRecords());
77
+ }
78
+ function B() {
79
+ v(e.getLoadedRecords());
80
+ }
81
+ function C() {
82
+ a([]);
83
+ }
84
+ function q(t, r) {
85
+ n.value || m(e.getRowKey(t), r);
86
+ }
87
+ function E() {
88
+ K(e.reserveAcrossPages ?? !1) || a(s.value.filter((t) => !!e.getRecordByKey(t)));
89
+ }
90
+ async function y(t) {
91
+ if (!e.syncNativeSelection) return;
92
+ u += 1;
93
+ const r = u;
94
+ n.value = !0;
95
+ try {
96
+ await e.syncNativeSelection(t);
97
+ } finally {
98
+ r === u && (n.value = !1);
99
+ }
100
+ }
101
+ function P() {
102
+ return y(s.value);
103
+ }
104
+ return S(
105
+ e.selectedRowKeys,
106
+ (t) => {
107
+ const r = d(t);
108
+ w(t, r) || (e.selectedRowKeys.value = r), y(r);
109
+ },
110
+ { immediate: !0 }
111
+ ), S(c, () => a(e.selectedRowKeys.value)), {
112
+ keys: s,
113
+ loadedRows: h,
114
+ missingKeys: N,
115
+ isSyncingNative: n,
116
+ setKeys: a,
117
+ toggleKey: m,
118
+ selectCurrentPage: z,
119
+ selectLoadedRecords: B,
120
+ clear: C,
121
+ isSelectable: i,
122
+ onNativeSelectionChange: q,
123
+ reconcileRecords: E,
124
+ syncNativeState: P
125
+ };
126
+ }
127
+ export {
128
+ p as useRowSelection
129
+ };
@@ -0,0 +1,60 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ import { TtVTableRowKey } from '../../public/table-api';
3
+ import { TtVTableTreeLoadError, TtVTableTreeLoadSuccess } from '../../public/table-events';
4
+ import { TtVTableTreeChildrenRequest } from '../../public/table-props';
5
+ /** 暴露给 runtime 的树状态与动作。 */
6
+ export interface VTableTreeRecords<Row, Key extends TtVTableRowKey> {
7
+ /** 已展开业务主键。 */
8
+ expandedKeys: Readonly<Ref<readonly Key[]>>;
9
+ /** 正在加载子节点的业务主键。 */
10
+ loadingKeys: Readonly<Ref<readonly Key[]>>;
11
+ /** 最近一次未中止的树请求错误。 */
12
+ error: Readonly<Ref<Error | undefined>>;
13
+ /** 是否至少有一个树请求进行中。 */
14
+ isLoading: ComputedRef<boolean>;
15
+ /** 展开节点并在需要时懒加载子节点。 */
16
+ expand: (key: Key) => Promise<void>;
17
+ /** 折叠节点且不丢弃已缓存子节点。 */
18
+ collapse: (key: Key) => void;
19
+ /** 切换节点展开状态。 */
20
+ toggle: (key: Key) => Promise<void>;
21
+ /** 加载节点子记录并复用重复请求。 */
22
+ fetchChildren: (key: Key) => Promise<readonly Row[]>;
23
+ /** 应用原生层级状态事件。 */
24
+ onNativeHierarchyChange: (record: Row, expanded: boolean) => Promise<void>;
25
+ /** records 根引用变化后使进行中的请求失效。 */
26
+ onRecordsReplaced: () => void;
27
+ /** 返回树选择级联使用的已加载后代记录。 */
28
+ getCascadeRecords: (record: Row) => readonly Row[];
29
+ /** 原生实例 ready 后同步最终展开快照。 */
30
+ syncExpandedState: () => Promise<void>;
31
+ /** 释放进行中的请求和状态。 */
32
+ release: () => void;
33
+ }
34
+ /** 树记录 feature 所需依赖。 */
35
+ export interface UseTreeRecordsOptions<Row, Key extends TtVTableRowKey> {
36
+ /** 初始展开主键。 */
37
+ defaultExpandedKeys?: readonly Key[];
38
+ /** 按主键读取一条 runtime 记录。 */
39
+ getRecordByKey: (key: Key) => Row | undefined;
40
+ /** 读取记录的稳定业务主键。 */
41
+ getRowKey: (record: Row) => Key;
42
+ /** 从 runtime 记录读取已加载子记录。 */
43
+ getChildren: (record: Row) => readonly Row[] | undefined;
44
+ /** 通过 records feature 写入复制后的子记录。 */
45
+ setChildren: (parentKey: Key, children: readonly Row[]) => Promise<void> | void;
46
+ /** 可选的子节点懒加载请求回调。 */
47
+ fetchTreeChildren?: (request: TtVTableTreeChildrenRequest<Row, Key>) => Promise<readonly Row[]>;
48
+ /** 后续展开时是否复用已加载子记录。 */
49
+ cacheChildren?: MaybeRefOrGetter<boolean>;
50
+ /** 同步一个原生层级状态。 */
51
+ setNativeExpanded?: (key: Key, expanded: boolean) => Promise<void> | void;
52
+ /** 同步一个原生层级加载状态。 */
53
+ setNativeLoading?: (key: Key, loading: boolean) => Promise<void> | void;
54
+ /** 当前子记录被接纳后调用一次。 */
55
+ onLoadSuccess?: (change: TtVTableTreeLoadSuccess<Row, Key>) => void;
56
+ /** 当前未中止请求失败后调用一次。 */
57
+ onLoadError?: (failure: TtVTableTreeLoadError<Key>) => void;
58
+ }
59
+ /** 创建树展开和可防竞态的懒加载 feature。 */
60
+ export declare function useTreeRecords<Row, Key extends TtVTableRowKey = TtVTableRowKey>(options: UseTreeRecordsOptions<Row, Key>): VTableTreeRecords<Row, Key>;
@@ -0,0 +1,125 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isArray as G, isError as j } from "../../../../../packages/utils/src/is.js";
4
+ import { shallowRef as E, computed as D, onScopeDispose as H, toValue as M } 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 V(r) {
17
+ return new Error(j(r) ? String(r).replace(/^Error:\s*/, "") : String(r));
18
+ }
19
+ function x(r, n) {
20
+ return r.includes(n) ? [...r] : [...r, n];
21
+ }
22
+ function T(r, n) {
23
+ return r.filter((i) => i !== n);
24
+ }
25
+ function re(r) {
26
+ const n = E([...new Set(r.defaultExpandedKeys ?? [])]), i = E([]), v = E(), u = /* @__PURE__ */ new Map();
27
+ let s = 0, h = !1;
28
+ const L = D(() => i.value.length > 0);
29
+ async function w(e, t, a = !0) {
30
+ var c;
31
+ n.value = t ? x(n.value, e) : T(n.value, e), a && await ((c = r.setNativeExpanded) == null ? void 0 : c.call(r, e, t));
32
+ }
33
+ async function K(e, t) {
34
+ var a;
35
+ i.value = t ? x(i.value, e) : T(i.value, e), await ((a = r.setNativeLoading) == null ? void 0 : a.call(r, e, t));
36
+ }
37
+ function m(e) {
38
+ const t = u.get(e);
39
+ if (t) return t.promise;
40
+ const a = r.getRecordByKey(e);
41
+ if (!a) return Promise.reject(new Error(`Cannot load children for missing record "${String(e)}".`));
42
+ const c = r.getChildren(a);
43
+ if (M(r.cacheChildren ?? !0) && (c != null && c.length) || !r.fetchTreeChildren)
44
+ return Promise.resolve(c ?? []);
45
+ const l = new AbortController(), d = s, g = {}, S = (async () => {
46
+ var q, b;
47
+ try {
48
+ await K(e, !0), v.value = void 0;
49
+ const o = await r.fetchTreeChildren({ parent: a, parentKey: e, signal: l.signal });
50
+ if (l.signal.aborted || d !== s || h) return [];
51
+ if (!G(o)) throw new Error("Tree child request must return an array.");
52
+ const f = [...o];
53
+ return await r.setChildren(e, f), l.signal.aborted || d !== s || h ? [] : ((q = r.onLoadSuccess) == null || q.call(r, { parentKey: e, children: f }), f);
54
+ } catch (o) {
55
+ const f = V(o);
56
+ if (l.signal.aborted || d !== s || h) return [];
57
+ throw v.value = f, (b = r.onLoadError) == null || b.call(r, { parentKey: e, error: f }), f;
58
+ } finally {
59
+ const o = u.get(e);
60
+ (o == null ? void 0 : o.token) === g && u.delete(e), d === s && !h && await K(e, !1);
61
+ }
62
+ })();
63
+ return u.set(e, { controller: l, promise: S, token: g }), S;
64
+ }
65
+ async function R(e) {
66
+ await w(e, !0);
67
+ try {
68
+ await m(e);
69
+ } catch (t) {
70
+ throw await w(e, !1), t;
71
+ }
72
+ }
73
+ function C(e) {
74
+ w(e, !1);
75
+ }
76
+ function N(e) {
77
+ return n.value.includes(e) ? (C(e), Promise.resolve()) : R(e);
78
+ }
79
+ async function p(e, t) {
80
+ const a = r.getRowKey(e);
81
+ if (await w(a, t, !1), !!t)
82
+ try {
83
+ await m(a);
84
+ } catch (c) {
85
+ throw await w(a, !1), c;
86
+ }
87
+ }
88
+ function P() {
89
+ s += 1, u.forEach((e) => e.controller.abort()), u.clear(), i.value = [], v.value = void 0, n.value = n.value.filter((e) => !!r.getRecordByKey(e));
90
+ }
91
+ function A(e) {
92
+ const t = /* @__PURE__ */ new Set(), a = [];
93
+ function c(l) {
94
+ var g;
95
+ const d = r.getRowKey(l);
96
+ t.has(d) || (t.add(d), a.push(l), (g = r.getChildren(l)) == null || g.forEach(c));
97
+ }
98
+ return c(e), a;
99
+ }
100
+ async function B() {
101
+ var e;
102
+ for (const t of n.value) await ((e = r.setNativeExpanded) == null ? void 0 : e.call(r, t, !0));
103
+ }
104
+ function y() {
105
+ h || (h = !0, s += 1, u.forEach((e) => e.controller.abort()), u.clear(), i.value = []);
106
+ }
107
+ return H(y), {
108
+ expandedKeys: n,
109
+ loadingKeys: i,
110
+ error: v,
111
+ isLoading: L,
112
+ expand: R,
113
+ collapse: C,
114
+ toggle: N,
115
+ fetchChildren: m,
116
+ onNativeHierarchyChange: p,
117
+ onRecordsReplaced: P,
118
+ getCascadeRecords: A,
119
+ syncExpandedState: B,
120
+ release: y
121
+ };
122
+ }
123
+ export {
124
+ re as useTreeRecords
125
+ };
@@ -0,0 +1,7 @@
1
+ /** TtVTable 公共 API、列、事件、props、slots 与错误类型。 */
2
+ export * from './table-api';
3
+ export * from './table-column';
4
+ export * from './table-errors';
5
+ export * from './table-events';
6
+ export * from './table-props';
7
+ export * from './table-slots';
@@ -0,0 +1,215 @@
1
+ import { ListTable } from '@visactor/vtable';
2
+ import { ComputedRef, Ref } from 'vue';
3
+ import { TtVTableColumn } from './table-column';
4
+ /** 业务记录允许使用的稳定主键。 */
5
+ export type TtVTableRowKey = number | string;
6
+ /** VTable 可读取的字段路径。 */
7
+ export type TtVTableFieldPath = number | string;
8
+ /** 记录更新时采用的所有权策略。 */
9
+ export type TtVTableMutationMode = "copy-on-write" | "shared";
10
+ /** 精确记录变更的来源。 */
11
+ export type TtVTableRecordChangeSource = "api" | "editing" | "renderer" | "tree";
12
+ /** 远程排序方向。 */
13
+ export type TtVTableSortDirection = "asc" | "desc";
14
+ /** 一条远程排序条件。 */
15
+ export interface TtVTableSortDescriptor {
16
+ /** 参与排序的字段。 */
17
+ field: TtVTableFieldPath;
18
+ /** 当前排序方向。 */
19
+ order: TtVTableSortDirection;
20
+ }
21
+ /** 一条按主键提交的记录补丁。 */
22
+ export interface TtVTableRecordPatch<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
23
+ /** 目标记录主键。 */
24
+ rowKey: Key;
25
+ /** 要覆盖的顶层字段。 */
26
+ changes: Partial<Row>;
27
+ /** 本次变更来源。 */
28
+ source?: TtVTableRecordChangeSource;
29
+ }
30
+ /** 单次记录变化的精确描述。 */
31
+ export interface TtVTableRecordChange<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
32
+ /** 变化前的记录主键。 */
33
+ rowKey: Key;
34
+ /** 变化后的记录主键。 */
35
+ nextRowKey: Key;
36
+ /** 变化后的运行时记录。 */
37
+ record: Readonly<Row>;
38
+ /** 变化前的运行时记录。 */
39
+ previousRecord: Readonly<Row>;
40
+ /** 本次变化涉及的字段。 */
41
+ changedFields: readonly TtVTableFieldPath[];
42
+ /** 变更来源。 */
43
+ source: TtVTableRecordChangeSource;
44
+ }
45
+ /** 当前编辑单元格的稳定身份。 */
46
+ export interface TtVTableEditingCell<Key extends TtVTableRowKey = TtVTableRowKey> {
47
+ /** 业务记录主键。 */
48
+ rowKey: Key;
49
+ /** 当前字段路径。 */
50
+ field: TtVTableFieldPath;
51
+ /** 开始编辑时的值。 */
52
+ previousValue: unknown;
53
+ /** 当前草稿值。 */
54
+ value: unknown;
55
+ }
56
+ /** records 命名空间的只读状态与动作。 */
57
+ export interface TtVTableRecordsApi<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
58
+ /** 当前运行时持有的浅层工作列表。 */
59
+ records: ComputedRef<readonly Row[]>;
60
+ /** 当前记录数量。 */
61
+ count: ComputedRef<number>;
62
+ /** 返回当前运行时工作列表的只读视图。 */
63
+ getAll: () => readonly Row[];
64
+ /** 按业务主键读取当前记录。 */
65
+ getByKey: (rowKey: Key) => Row | undefined;
66
+ /** 使用新的根快照替换全部记录。 */
67
+ replaceAll: (records: readonly Row[]) => void;
68
+ /** 在尾部追加一条或多条记录。 */
69
+ append: (records: Row | readonly Row[]) => void;
70
+ /** 在指定源索引前插入一条或多条记录。 */
71
+ insertAt: (recordIndex: number, records: Row | readonly Row[]) => void;
72
+ /** 按业务主键更新一条记录。 */
73
+ patchByKey: (rowKey: Key, changes: Partial<Row>, source?: TtVTableRecordChangeSource) => void;
74
+ /** 在一次原生调度内更新多条记录。 */
75
+ patchMany: (patches: readonly TtVTableRecordPatch<Row, Key>[]) => void;
76
+ /** 按业务主键和字段路径更新一个单元格。 */
77
+ setCellValue: (rowKey: Key, field: TtVTableFieldPath, value: unknown, source?: TtVTableRecordChangeSource) => void;
78
+ /** 按业务主键删除多条记录。 */
79
+ removeByKeys: (rowKeys: readonly Key[]) => void;
80
+ }
81
+ /** query 命名空间的只读状态与动作。 */
82
+ export interface TtVTableQueryApi {
83
+ /** 最新请求是否仍在进行。 */
84
+ isFetching: Readonly<Ref<boolean>>;
85
+ /** 最新有效请求错误。 */
86
+ error: Readonly<Ref<Error | undefined>>;
87
+ /** 使用当前查询状态发起请求。 */
88
+ fetch: () => Promise<boolean>;
89
+ /** 重放最近一次已接受请求。 */
90
+ refresh: () => Promise<boolean>;
91
+ /** 取消当前请求并使其响应失效。 */
92
+ cancel: () => void;
93
+ }
94
+ /** pagination 命名空间的只读状态与动作。 */
95
+ export interface TtVTablePaginationApi {
96
+ /** 当前页码,起始值为 1。 */
97
+ page: Readonly<Ref<number>>;
98
+ /** 当前每页记录数。 */
99
+ pageSize: Readonly<Ref<number>>;
100
+ /** 当前总记录数。 */
101
+ total: ComputedRef<number>;
102
+ /** 修改当前页码。 */
103
+ setPage: (page: number) => void;
104
+ /** 修改每页记录数并回到第一页。 */
105
+ setPageSize: (pageSize: number) => void;
106
+ /** 恢复初始分页状态。 */
107
+ reset: () => void;
108
+ }
109
+ /** selection 命名空间的只读状态与动作。 */
110
+ export interface TtVTableSelectionApi<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
111
+ /** 按选择顺序保存的主键。 */
112
+ keys: ComputedRef<readonly Key[]>;
113
+ /** 当前已加载且能按主键命中的选中记录。 */
114
+ loadedRows: ComputedRef<readonly Row[]>;
115
+ /** 已选但当前未加载的主键。 */
116
+ missingKeys: ComputedRef<readonly Key[]>;
117
+ /** 替换全部选择主键。 */
118
+ setKeys: (rowKeys: readonly Key[]) => void;
119
+ /** 切换一个主键的选择状态。 */
120
+ toggleKey: (rowKey: Key, selected?: boolean) => void;
121
+ /** 选择当前页可选记录。 */
122
+ selectCurrentPage: () => void;
123
+ /** 选择运行时已经加载的全部可选记录。 */
124
+ selectLoadedRecords: () => void;
125
+ /** 清空选择。 */
126
+ clear: () => void;
127
+ }
128
+ /** columns 命名空间的只读状态与动作。 */
129
+ export interface TtVTableColumnsApi<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> {
130
+ /** 当前生效的语义列树。 */
131
+ columns: ComputedRef<readonly TtVTableColumn<Row, Key>[]>;
132
+ /** 替换全部语义列。 */
133
+ replaceAll: (columns: readonly TtVTableColumn<Row, Key>[]) => void;
134
+ /** 显示指定列。 */
135
+ show: (columnKey: string) => void;
136
+ /** 隐藏指定列。 */
137
+ hide: (columnKey: string) => void;
138
+ /** 在同级列中移动指定列。 */
139
+ move: (columnKey: string, targetIndex: number) => void;
140
+ /** 恢复默认列偏好。 */
141
+ resetPreferences: () => Promise<void>;
142
+ }
143
+ /** editing 命名空间的只读状态与动作。 */
144
+ export interface TtVTableEditingApi<Key extends TtVTableRowKey = TtVTableRowKey> {
145
+ /** 当前编辑单元格。 */
146
+ activeCell: Readonly<Ref<Readonly<TtVTableEditingCell<Key>> | undefined>>;
147
+ /** 当前是否正在执行异步校验。 */
148
+ isValidating: Readonly<Ref<boolean>>;
149
+ /** 当前编辑校验错误。 */
150
+ validationError: Readonly<Ref<Error | undefined>>;
151
+ /** 开始编辑一个单元格。 */
152
+ start: (rowKey: Key, field: TtVTableFieldPath) => Promise<void>;
153
+ /** 校验并提交当前编辑。 */
154
+ commit: (value?: unknown) => Promise<boolean>;
155
+ /** 取消当前编辑。 */
156
+ cancel: () => void;
157
+ /** 仅校验当前编辑值。 */
158
+ validate: (value?: unknown) => Promise<boolean>;
159
+ }
160
+ /** tree 命名空间的只读状态与动作。 */
161
+ export interface TtVTableTreeApi<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
162
+ /** 当前展开节点主键。 */
163
+ expandedKeys: Readonly<Ref<readonly Key[]>>;
164
+ /** 当前正在加载子节点的主键。 */
165
+ loadingKeys: Readonly<Ref<readonly Key[]>>;
166
+ /** 展开一个节点。 */
167
+ expand: (rowKey: Key) => Promise<void>;
168
+ /** 收起一个节点。 */
169
+ collapse: (rowKey: Key) => void;
170
+ /** 切换一个节点的展开状态。 */
171
+ toggle: (rowKey: Key) => Promise<void>;
172
+ /** 获取或加载一个节点的子记录。 */
173
+ fetchChildren: (rowKey: Key) => Promise<readonly Row[]>;
174
+ }
175
+ /** layout 命名空间的只读状态与动作。 */
176
+ export interface TtVTableLayoutApi<Key extends TtVTableRowKey = TtVTableRowKey> {
177
+ /** 原生实例是否已经可用。 */
178
+ isReady: Readonly<Ref<boolean>>;
179
+ /** 当前可用容器宽度。 */
180
+ width: Readonly<Ref<number>>;
181
+ /** 当前可用容器高度。 */
182
+ height: Readonly<Ref<number>>;
183
+ /** 重新计算表格布局。 */
184
+ recalculate: () => void;
185
+ /** 滚动到指定记录。 */
186
+ scrollToRecord: (rowKey: Key) => void;
187
+ /** 滚动到指定记录和字段。 */
188
+ scrollToCell: (rowKey: Key, field: TtVTableFieldPath) => void;
189
+ }
190
+ /** native 命名空间的高级逃生口。 */
191
+ export interface TtVTableNativeApi {
192
+ /** 返回当前原生 ListTable,未就绪或释放后返回 undefined。 */
193
+ getInstance: () => ListTable | undefined;
194
+ }
195
+ /** TtVTable 稳定且按能力分组的公共 API。 */
196
+ export interface TtVTableApi<Row extends Record<string, unknown> = Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> {
197
+ /** 记录状态与增量动作。 */
198
+ records: TtVTableRecordsApi<Row, Key>;
199
+ /** 远程查询状态与动作。 */
200
+ query: TtVTableQueryApi;
201
+ /** 分页状态与动作。 */
202
+ pagination: TtVTablePaginationApi;
203
+ /** 单选、多选状态与动作。 */
204
+ selection: TtVTableSelectionApi<Row, Key>;
205
+ /** 列状态与偏好动作。 */
206
+ columns: TtVTableColumnsApi<Row, Key>;
207
+ /** 编辑状态与动作。 */
208
+ editing: TtVTableEditingApi<Key>;
209
+ /** 树节点状态与动作。 */
210
+ tree: TtVTableTreeApi<Row, Key>;
211
+ /** 视口布局状态与动作。 */
212
+ layout: TtVTableLayoutApi<Key>;
213
+ /** 原生实例逃生口。 */
214
+ native: TtVTableNativeApi;
215
+ }