@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,238 @@
1
+ import { shallowRef as c, computed as l, watch as a } from "vue";
2
+ import { createTtVTableError as S } from "../public/table-errors.js";
3
+ function ke() {
4
+ let o, g = [];
5
+ const h = [], u = c([]), R = c(!1), K = c(), d = c(1), y = c(20), C = c(0), f = c([]), V = c([]), B = c([]), m = c([]), E = c(), w = c(!1), A = c(), q = c([]), L = c([]), p = c(!1), P = c(0), N = c(0), _ = l(() => u.value), O = l(() => u.value.length), z = l(() => C.value), I = l(() => f.value), M = l(() => V.value), k = l(() => B.value), D = l(() => m.value);
6
+ function r() {
7
+ if (o) return o;
8
+ throw S("TT_VTABLE_NOT_READY", "TtVTable controller 尚未绑定存活组件。", {});
9
+ }
10
+ function n(e) {
11
+ if (o) {
12
+ e(o);
13
+ return;
14
+ }
15
+ h.push(e);
16
+ }
17
+ function i(e, t) {
18
+ return a(e, (s) => t.value = s, { immediate: !0 });
19
+ }
20
+ function F() {
21
+ return (o == null ? void 0 : o.records.getAll()) ?? u.value;
22
+ }
23
+ function Q(e) {
24
+ return o == null ? void 0 : o.records.getByKey(e);
25
+ }
26
+ function H(e) {
27
+ u.value = [...e], n((t) => t.records.replaceAll(e));
28
+ }
29
+ function U(e) {
30
+ n((t) => t.records.append(e));
31
+ }
32
+ function W(e, t) {
33
+ n((s) => s.records.insertAt(e, t));
34
+ }
35
+ function Y(e, t, s) {
36
+ n((v) => v.records.patchByKey(e, t, s));
37
+ }
38
+ function j(e) {
39
+ n((t) => t.records.patchMany(e));
40
+ }
41
+ function G(e, t, s, v) {
42
+ n((we) => we.records.setCellValue(e, t, s, v));
43
+ }
44
+ function J(e) {
45
+ n((t) => t.records.removeByKeys(e));
46
+ }
47
+ function X() {
48
+ return r().query.fetch();
49
+ }
50
+ function Z() {
51
+ return r().query.refresh();
52
+ }
53
+ function $() {
54
+ r().query.cancel();
55
+ }
56
+ function T(e) {
57
+ d.value = e, n((t) => t.pagination.setPage(e));
58
+ }
59
+ function x(e) {
60
+ y.value = e, d.value = 1, n((t) => t.pagination.setPageSize(e));
61
+ }
62
+ function b() {
63
+ n((e) => e.pagination.reset());
64
+ }
65
+ function ee(e) {
66
+ f.value = [...e], n((t) => t.selection.setKeys(e));
67
+ }
68
+ function te(e, t) {
69
+ n((s) => s.selection.toggleKey(e, t));
70
+ }
71
+ function ne() {
72
+ n((e) => e.selection.selectCurrentPage());
73
+ }
74
+ function oe() {
75
+ n((e) => e.selection.selectLoadedRecords());
76
+ }
77
+ function ce() {
78
+ f.value = [], n((e) => e.selection.clear());
79
+ }
80
+ function re(e) {
81
+ m.value = [...e], n((t) => t.columns.replaceAll(e));
82
+ }
83
+ function ie(e) {
84
+ n((t) => t.columns.show(e));
85
+ }
86
+ function se(e) {
87
+ n((t) => t.columns.hide(e));
88
+ }
89
+ function le(e, t) {
90
+ n((s) => s.columns.move(e, t));
91
+ }
92
+ function ae() {
93
+ return r().columns.resetPreferences();
94
+ }
95
+ function ue(e, t) {
96
+ return r().editing.start(e, t);
97
+ }
98
+ function de(e) {
99
+ return r().editing.commit(e);
100
+ }
101
+ function fe() {
102
+ r().editing.cancel();
103
+ }
104
+ function ge(e) {
105
+ return r().editing.validate(e);
106
+ }
107
+ function ye(e) {
108
+ return r().tree.expand(e);
109
+ }
110
+ function me(e) {
111
+ r().tree.collapse(e);
112
+ }
113
+ function pe(e) {
114
+ return r().tree.toggle(e);
115
+ }
116
+ function ve(e) {
117
+ return r().tree.fetchChildren(e);
118
+ }
119
+ function he() {
120
+ r().layout.recalculate();
121
+ }
122
+ function Re(e) {
123
+ r().layout.scrollToRecord(e);
124
+ }
125
+ function Ke(e, t) {
126
+ r().layout.scrollToCell(e, t);
127
+ }
128
+ function Ce() {
129
+ return o == null ? void 0 : o.native.getInstance();
130
+ }
131
+ const Ve = {
132
+ records: {
133
+ records: _,
134
+ count: O,
135
+ getAll: F,
136
+ getByKey: Q,
137
+ replaceAll: H,
138
+ append: U,
139
+ insertAt: W,
140
+ patchByKey: Y,
141
+ patchMany: j,
142
+ setCellValue: G,
143
+ removeByKeys: J
144
+ },
145
+ query: {
146
+ isFetching: R,
147
+ error: K,
148
+ fetch: X,
149
+ refresh: Z,
150
+ cancel: $
151
+ },
152
+ pagination: {
153
+ page: d,
154
+ pageSize: y,
155
+ total: z,
156
+ setPage: T,
157
+ setPageSize: x,
158
+ reset: b
159
+ },
160
+ selection: {
161
+ keys: I,
162
+ loadedRows: M,
163
+ missingKeys: k,
164
+ setKeys: ee,
165
+ toggleKey: te,
166
+ selectCurrentPage: ne,
167
+ selectLoadedRecords: oe,
168
+ clear: ce
169
+ },
170
+ columns: {
171
+ columns: D,
172
+ replaceAll: re,
173
+ show: ie,
174
+ hide: se,
175
+ move: le,
176
+ resetPreferences: ae
177
+ },
178
+ editing: {
179
+ activeCell: E,
180
+ isValidating: w,
181
+ validationError: A,
182
+ start: ue,
183
+ commit: de,
184
+ cancel: fe,
185
+ validate: ge
186
+ },
187
+ tree: {
188
+ expandedKeys: q,
189
+ loadingKeys: L,
190
+ expand: ye,
191
+ collapse: me,
192
+ toggle: pe,
193
+ fetchChildren: ve
194
+ },
195
+ layout: {
196
+ isReady: p,
197
+ width: P,
198
+ height: N,
199
+ recalculate: he,
200
+ scrollToRecord: Re,
201
+ scrollToCell: Ke
202
+ },
203
+ native: { getInstance: Ce }
204
+ };
205
+ function Be(e) {
206
+ if (o !== e) {
207
+ if (o)
208
+ throw S("TT_VTABLE_CONTROLLER_BOUND", "同一个 controller 不能绑定两个存活表格。", {});
209
+ o = e, g = [
210
+ i(e.records.records, u),
211
+ i(e.query.isFetching, R),
212
+ i(e.query.error, K),
213
+ i(e.pagination.page, d),
214
+ i(e.pagination.pageSize, y),
215
+ a(e.pagination.total, (t) => C.value = t, { immediate: !0 }),
216
+ a(e.selection.keys, (t) => f.value = t, { immediate: !0 }),
217
+ a(e.selection.loadedRows, (t) => V.value = t, { immediate: !0 }),
218
+ a(e.selection.missingKeys, (t) => B.value = t, { immediate: !0 }),
219
+ a(e.columns.columns, (t) => m.value = t, { immediate: !0 }),
220
+ i(e.editing.activeCell, E),
221
+ i(e.editing.isValidating, w),
222
+ i(e.editing.validationError, A),
223
+ i(e.tree.expandedKeys, q),
224
+ i(e.tree.loadingKeys, L),
225
+ i(e.layout.isReady, p),
226
+ i(e.layout.width, P),
227
+ i(e.layout.height, N)
228
+ ], h.splice(0).forEach((t) => t(e));
229
+ }
230
+ }
231
+ function Ee(e) {
232
+ o === e && (g.forEach((t) => t()), g = [], o = void 0, p.value = !1);
233
+ }
234
+ return { tableApi: Ve, bind: Be, unbind: Ee };
235
+ }
236
+ export {
237
+ ke as createVTableController
238
+ };
@@ -0,0 +1,79 @@
1
+ import { ListTable } from '@visactor/vtable';
2
+ import { ComputedRef, Ref } from 'vue';
3
+ import { TtVTableApi, TtVTableColumn, TtVTableEditCommit, TtVTableFeatureOptions, TtVTableFetchRecords, TtVTableFetchRequest, TtVTableFetchResponse, TtVTableMutationMode, TtVTableNativeEvents, TtVTablePageChange, TtVTableRecordChange, TtVTableRowKey, TtVTableRowKeySource, TtVTableSortDescriptor, TtVTableTreeLoadError, TtVTableTreeLoadSuccess } from '../public';
4
+ /** 封装层内部选择列使用的稳定字段。 */
5
+ export declare const TT_VTABLE_SELECTION_FIELD = "__tt_vtable_selection__";
6
+ /** 创建运行时所需的响应式输入。 */
7
+ export interface CreateVTableRuntimeOptions<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey, QueryParams extends Record<string, unknown> = Record<string, unknown>> {
8
+ /** 初始本地记录根快照。 */
9
+ records?: readonly Row[];
10
+ /** 读取最新本地记录根快照。 */
11
+ getRecords: () => readonly Row[] | undefined;
12
+ /** 读取最新语义列根。 */
13
+ getColumns: () => readonly TtVTableColumn<Row, Key>[];
14
+ /** 业务主键字段路径或读取函数。 */
15
+ rowKey: TtVTableRowKeySource<Row, Key>;
16
+ /** 当前受控选择主键。 */
17
+ selectedRowKeys: Ref<Key[]>;
18
+ /** 读取最新查询参数根。 */
19
+ getQueryParams: () => QueryParams;
20
+ /** 读取最新 feature 配置。 */
21
+ getFeatures: () => TtVTableFeatureOptions<Row, Key> | undefined;
22
+ /** 读取最新原生事件。 */
23
+ getNativeEvents: () => TtVTableNativeEvents | undefined;
24
+ /** 远程记录请求。 */
25
+ fetchRecords?: TtVTableFetchRecords<Row, QueryParams>;
26
+ /** 记录所有权策略。 */
27
+ mutationMode?: TtVTableMutationMode;
28
+ /** 精确记录变化回调。 */
29
+ onRecordChange?: (change: TtVTableRecordChange<Row, Key>) => void;
30
+ /** 最新远程请求成功回调。 */
31
+ onFetchSuccess?: (response: TtVTableFetchResponse<Row>, request: TtVTableFetchRequest<QueryParams>) => void;
32
+ /** 最新远程请求失败回调。 */
33
+ onFetchError?: (error: Error, request: TtVTableFetchRequest<QueryParams>) => void;
34
+ /** 分页变化回调。 */
35
+ onPageChange?: (change: TtVTablePageChange) => void;
36
+ /** 排序变化回调。 */
37
+ onSortChange?: (sort: readonly TtVTableSortDescriptor[]) => void;
38
+ /** 筛选变化回调。 */
39
+ onFilterChange?: (filters: Readonly<Record<string, unknown>>) => void;
40
+ /** 编辑提交回调。 */
41
+ onEditCommit?: (change: TtVTableEditCommit<Key>) => void;
42
+ /** 编辑失败回调。 */
43
+ onEditError?: (error: Error) => void;
44
+ /** 树子节点加载成功回调。 */
45
+ onTreeLoadSuccess?: (change: TtVTableTreeLoadSuccess<Row, Key>) => void;
46
+ /** 树子节点加载失败回调。 */
47
+ onTreeLoadError?: (failure: TtVTableTreeLoadError<Key>) => void;
48
+ /** 列偏好变化回调。 */
49
+ onColumnPreferencesChange?: (preferences: unknown) => void;
50
+ }
51
+ /** 运行时暴露给组件层的状态与生命周期。 */
52
+ export interface TtVTableRuntime<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey, QueryParams extends Record<string, unknown> = Record<string, unknown>> {
53
+ /** 稳定公共 API。 */
54
+ tableApi: TtVTableApi<Row, Key>;
55
+ /** 传给原生视口的列,包含内部选择列。 */
56
+ renderColumns: ComputedRef<readonly TtVTableColumn<Row, Key>[]>;
57
+ /** 当前是否使用远程记录源。 */
58
+ isRemote: boolean;
59
+ /** 当前选择模式。 */
60
+ selectionMode: ComputedRef<"multiple" | "none" | "single">;
61
+ /** 当前查询排序。 */
62
+ sort: Readonly<Ref<readonly TtVTableSortDescriptor[]>>;
63
+ /** 当前查询筛选。 */
64
+ filters: Readonly<Ref<Readonly<Record<string, unknown>>>>;
65
+ /** 从运行时记录读取稳定业务主键。 */
66
+ getRowKey: (record: Row) => Key;
67
+ /** 视口获得原生实例后的入口。 */
68
+ acceptNativeInstance: (table: ListTable) => void;
69
+ /** 视口释放原生实例引用。 */
70
+ clearNativeInstance: (table: ListTable) => void;
71
+ /** 更新视口测量尺寸。 */
72
+ acceptViewportSize: (width: number, height: number) => void;
73
+ /** 外部 records 根替换入口。 */
74
+ acceptRecords: (records: readonly Row[]) => void;
75
+ /** 释放运行时及异步任务。 */
76
+ release: () => void;
77
+ }
78
+ /** 创建不依赖原生实例的稳定 TtVTable 运行时。 */
79
+ export declare function createVTableRuntime<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey, QueryParams extends Record<string, unknown> = Record<string, unknown>>(options: CreateVTableRuntimeOptions<Row, Key, QueryParams>): TtVTableRuntime<Row, Key, QueryParams>;
@@ -0,0 +1,380 @@
1
+ import "axios";
2
+ import "element-plus";
3
+ import { isFunction as ye, isString as ve, isObject as Ce, isArray as Te } from "../../../../packages/utils/src/is.js";
4
+ import { shallowRef as v, computed as Q, watch as Se, nextTick as pe } 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 { createVisactorTableEngine as we } from "../engine/visactor/createListTable.js";
17
+ import "../engine/visactor/createVueCellLayout.js";
18
+ import { bindNativeEvents as Ee } from "../engine/visactor/native-boundaries.js";
19
+ import { createTtVTableError as x } from "../public/table-errors.js";
20
+ import { useColumnPreferences as _e } from "../features/column-preferences/useColumnPreferences.js";
21
+ import { useCellEditing as Ie } from "../features/editing/useCellEditing.js";
22
+ import { useTablePagination as xe } from "../features/pagination/useTablePagination.js";
23
+ import { useRecordQuery as Ae } from "../features/querying/useRecordQuery.js";
24
+ import { getRecordFieldValue as q } from "../features/records/record-index.js";
25
+ import { useRecordSource as Fe } from "../features/records/useRecordSource.js";
26
+ import { useRowSelection as Ke } from "../features/selection/useRowSelection.js";
27
+ import { useTreeRecords as Ne } from "../features/tree/useTreeRecords.js";
28
+ const A = "__tt_vtable_selection__";
29
+ function M(n) {
30
+ return n === "expand";
31
+ }
32
+ function B(n) {
33
+ return Ce(n);
34
+ }
35
+ function ot(n) {
36
+ var z, H;
37
+ const s = we(), p = v(!1), V = v(0), b = v(0), F = v([]), D = v({});
38
+ let K = !1, l, i, u, f, m, N = !1;
39
+ const R = ye(n.fetchRecords), C = Q(
40
+ () => {
41
+ var e, t;
42
+ return ((t = (e = n.getFeatures()) == null ? void 0 : e.selection) == null ? void 0 : t.mode) ?? "none";
43
+ }
44
+ );
45
+ function U() {
46
+ var t;
47
+ const e = (t = n.getFeatures()) == null ? void 0 : t.pagination;
48
+ return e === !1 ? void 0 : e;
49
+ }
50
+ function w() {
51
+ var t;
52
+ const e = (t = n.getFeatures()) == null ? void 0 : t.tree;
53
+ return e === !1 ? void 0 : e;
54
+ }
55
+ function W() {
56
+ var t;
57
+ const e = (t = n.getFeatures()) == null ? void 0 : t.editing;
58
+ return e === !1 ? void 0 : e;
59
+ }
60
+ function P() {
61
+ var t;
62
+ const e = (t = n.getFeatures()) == null ? void 0 : t.columnPreferences;
63
+ return e === !1 ? void 0 : e;
64
+ }
65
+ const T = U(), S = w(), h = P();
66
+ function E() {
67
+ !R || N || (N = !0, pe(() => {
68
+ N = !1, m == null || m.fetch();
69
+ }));
70
+ }
71
+ function $() {
72
+ i == null || i.reconcilePage(), u == null || u.reconcileRecords(), f == null || f.onRecordsReplaced(), L();
73
+ }
74
+ const o = Fe({
75
+ records: R ? [] : n.records,
76
+ rowKey: n.rowKey,
77
+ childrenField: S == null ? void 0 : S.childrenField,
78
+ mutationMode: n.mutationMode,
79
+ engine: s,
80
+ onRecordChange: n.onRecordChange,
81
+ onRecordsReplaced: $
82
+ });
83
+ i = xe({
84
+ initialPage: T == null ? void 0 : T.page,
85
+ initialPageSize: T == null ? void 0 : T.pageSize,
86
+ isRemote: R,
87
+ getRecords: o.getAll,
88
+ onChange: (e) => {
89
+ var t;
90
+ (t = n.onPageChange) == null || t.call(n, e), L(), E();
91
+ }
92
+ });
93
+ function j(e) {
94
+ var c;
95
+ const t = ((c = w()) == null ? void 0 : c.childrenField) || "children", r = q(e, t);
96
+ return Te(r) ? r : void 0;
97
+ }
98
+ f = Ne({
99
+ defaultExpandedKeys: S == null ? void 0 : S.defaultExpandedKeys,
100
+ getRecordByKey: o.getByKey,
101
+ getRowKey: o.getRowKey,
102
+ getChildren: j,
103
+ setChildren: o.setChildren,
104
+ fetchTreeChildren: (e) => {
105
+ const t = w();
106
+ return t != null && t.fetchTreeChildren ? t.fetchTreeChildren(e) : Promise.resolve([]);
107
+ },
108
+ cacheChildren: () => {
109
+ const e = w();
110
+ return (e == null ? void 0 : e.cacheChildren) ?? !0;
111
+ },
112
+ setNativeExpanded: ce,
113
+ setNativeLoading: oe,
114
+ onLoadSuccess: n.onTreeLoadSuccess,
115
+ onLoadError: n.onTreeLoadError
116
+ }), u = Ke({
117
+ mode: C,
118
+ selectedRowKeys: n.selectedRowKeys,
119
+ getLoadedRecords: o.getAll,
120
+ getCurrentPageRecords: () => i.pageRecords.value,
121
+ getRecordByKey: o.getByKey,
122
+ getRowKey: o.getRowKey,
123
+ isRowSelectable: (e) => {
124
+ var t, r, c;
125
+ return ((c = (r = (t = n.getFeatures()) == null ? void 0 : t.selection) == null ? void 0 : r.isRowSelectable) == null ? void 0 : c.call(r, e)) ?? !0;
126
+ },
127
+ reserveAcrossPages: () => {
128
+ var e, t;
129
+ return ((t = (e = n.getFeatures()) == null ? void 0 : e.selection) == null ? void 0 : t.reserveAcrossPages) ?? !1;
130
+ },
131
+ getCascadeRecords: (e) => {
132
+ var t, r;
133
+ return (r = (t = n.getFeatures()) == null ? void 0 : t.selection) != null && r.cascade ? f.getCascadeRecords(e) : [e];
134
+ },
135
+ syncNativeSelection: O
136
+ });
137
+ const k = Ie({
138
+ getRecordByKey: o.getByKey,
139
+ getFieldValue: q,
140
+ setCellValue: o.setCellValue,
141
+ getValidator: (e) => {
142
+ var r;
143
+ const t = W();
144
+ if (t)
145
+ return (r = t.validators) == null ? void 0 : r[String(e)];
146
+ },
147
+ startNativeEditing: ae,
148
+ cancelNativeEditing: () => {
149
+ var e;
150
+ return (e = s.getInstance()) == null ? void 0 : e.cancelEditCell();
151
+ },
152
+ onCommit: n.onEditCommit,
153
+ onError: n.onEditError
154
+ }), g = _e({
155
+ columns: n.getColumns,
156
+ columnsKey: () => {
157
+ var e;
158
+ return (e = P()) == null ? void 0 : e.columnsKey;
159
+ },
160
+ persistent: () => {
161
+ var e;
162
+ return !!((e = P()) != null && e.persistent);
163
+ },
164
+ schemaVersion: h == null ? void 0 : h.schemaVersion,
165
+ writeDelay: h == null ? void 0 : h.writeDelay,
166
+ storage: h == null ? void 0 : h.storage,
167
+ onPreferencesChange: n.onColumnPreferencesChange
168
+ }), Y = Q(() => C.value === "none" ? g.columns.value : [{
169
+ key: A,
170
+ field: A,
171
+ title: "",
172
+ width: 44,
173
+ minWidth: 44,
174
+ maxWidth: 44,
175
+ frozen: "left",
176
+ native: C.value === "multiple" ? { cellType: "checkbox", headerType: "checkbox" } : { cellType: "radio", radioCheckType: "column" }
177
+ }, ...g.columns.value]);
178
+ function G() {
179
+ return {
180
+ page: i.page.value,
181
+ pageSize: i.pageSize.value,
182
+ queryParams: n.getQueryParams(),
183
+ sort: F.value,
184
+ filters: D.value
185
+ };
186
+ }
187
+ R && (m = Ae({
188
+ fetchRecords: (e) => n.fetchRecords(e),
189
+ getRequestSnapshot: G,
190
+ replaceRecords: o.replaceAll,
191
+ setTotal: i.setRemoteTotal,
192
+ immediate: !1,
193
+ onSuccess: n.onFetchSuccess,
194
+ onError: n.onFetchError
195
+ }), Se(n.getQueryParams, E, {
196
+ immediate: ((H = (z = n.getFeatures()) == null ? void 0 : z.query) == null ? void 0 : H.immediate) ?? !0
197
+ }));
198
+ const J = v(!1), X = v(), Z = m ?? {
199
+ isFetching: J,
200
+ error: X,
201
+ fetch: async () => !1,
202
+ refresh: async () => !1,
203
+ cancel: () => {
204
+ }
205
+ };
206
+ function _() {
207
+ const e = s.getInstance();
208
+ if (!e || !p.value)
209
+ throw x("TT_VTABLE_NOT_READY", "原生 VTable 实例尚未就绪。", {});
210
+ return e;
211
+ }
212
+ function I(e, t) {
213
+ var a;
214
+ const r = o.getRecordIndex(e);
215
+ if (r === void 0) return;
216
+ const c = (a = s.getInstance()) == null ? void 0 : a.getCellAddrByFieldRecord(t, r);
217
+ if (!(!c || c.col < 0 || c.row < 0))
218
+ return c;
219
+ }
220
+ function ee() {
221
+ _(), s.recalculate();
222
+ }
223
+ function te(e) {
224
+ const t = _(), r = o.getRecordIndex(e);
225
+ if (r === void 0)
226
+ throw x("TT_VTABLE_RECORD_NOT_FOUND", `未找到 rowKey ${String(e)}。`, { rowKey: e });
227
+ t.scrollToRow(t.getBodyRowIndexByRecordIndex(r), !1);
228
+ }
229
+ function re(e, t) {
230
+ const r = _(), c = I(e, t);
231
+ if (!c)
232
+ throw x("TT_VTABLE_RECORD_NOT_FOUND", `未找到 rowKey ${String(e)} 对应单元格。`, {
233
+ rowKey: e,
234
+ field: t
235
+ });
236
+ r.scrollToCell(c);
237
+ }
238
+ const ne = {
239
+ records: o,
240
+ query: Z,
241
+ pagination: i,
242
+ selection: u,
243
+ columns: {
244
+ columns: g.columns,
245
+ replaceAll: g.replaceAll,
246
+ show: g.show,
247
+ hide: g.hide,
248
+ move: g.move,
249
+ resetPreferences: g.resetPreferences
250
+ },
251
+ editing: k,
252
+ tree: f,
253
+ layout: {
254
+ isReady: p,
255
+ width: V,
256
+ height: b,
257
+ recalculate: ee,
258
+ scrollToRecord: te,
259
+ scrollToCell: re
260
+ },
261
+ native: {
262
+ getInstance: s.getInstance
263
+ }
264
+ };
265
+ function O(e) {
266
+ const t = s.getInstance();
267
+ if (!t || C.value === "none") return;
268
+ const r = new Set(e);
269
+ o.getAll().forEach((c) => {
270
+ const a = o.getRowKey(c), d = o.getRecordIndex(a);
271
+ if (d === void 0) return;
272
+ if (C.value === "multiple") {
273
+ t.setCellCheckboxStateByRecordIndex(d, A, r.has(a));
274
+ return;
275
+ }
276
+ if (!r.has(a)) return;
277
+ const y = t.getCellAddrByFieldRecord(A, d);
278
+ y && t.setCellRadioState(y.col, y.row);
279
+ });
280
+ }
281
+ function L() {
282
+ var e, t;
283
+ !s.getInstance() || R || ((e = n.getFeatures()) == null ? void 0 : e.pagination) === !1 || !((t = n.getFeatures()) != null && t.pagination) || s.updatePagination({
284
+ currentPage: i.page.value - 1,
285
+ perPageCount: i.pageSize.value
286
+ });
287
+ }
288
+ function ce(e, t) {
289
+ const r = g.columns.value.find((y) => y.tree && y.field !== void 0);
290
+ if (!(r != null && r.field)) return;
291
+ const c = I(e, r.field), a = s.getInstance();
292
+ if (!a || !c) return;
293
+ M(a.getHierarchyState(c.col, c.row)) !== t && a.toggleHierarchyState(c.col, c.row);
294
+ }
295
+ function oe(e, t) {
296
+ var a;
297
+ if (!t) return;
298
+ const r = g.columns.value.find((d) => d.tree && d.field !== void 0);
299
+ if (!(r != null && r.field)) return;
300
+ const c = I(e, r.field);
301
+ c && ((a = s.getInstance()) == null || a.setLoadingHierarchyState(c.col, c.row));
302
+ }
303
+ function ae(e, t) {
304
+ const r = _(), c = I(e, t);
305
+ if (!c)
306
+ throw x("TT_VTABLE_RECORD_NOT_FOUND", `未找到 rowKey ${String(e)} 对应编辑单元格。`, {
307
+ rowKey: e,
308
+ field: t
309
+ });
310
+ r.startEditCell(c.col, c.row);
311
+ }
312
+ function se(e) {
313
+ if (B(e.originData)) {
314
+ u.onNativeSelectionChange(e.originData, e.checked);
315
+ return;
316
+ }
317
+ if (e.checked) {
318
+ u.selectCurrentPage();
319
+ return;
320
+ }
321
+ const t = new Set(i.pageRecords.value.map(o.getRowKey));
322
+ u.setKeys(u.keys.value.filter((r) => !t.has(r)));
323
+ }
324
+ function ie(e) {
325
+ B(e.originData) && u.onNativeSelectionChange(e.originData, !0);
326
+ }
327
+ function le(e) {
328
+ B(e.originData) && f.onNativeHierarchyChange(e.originData, M(e.hierarchyState));
329
+ }
330
+ function de(e) {
331
+ var c, a, d;
332
+ const t = ve(e.field) ? e.field : String(e.field), r = e.order === "asc" || e.order === "desc" ? [{ field: t, order: e.order }] : [];
333
+ if (F.value = r, (c = n.onSortChange) == null || c.call(n, r), !R) return !0;
334
+ if (((d = (a = n.getFeatures()) == null ? void 0 : a.query) == null ? void 0 : d.resetPageOnSort) ?? !0) {
335
+ const y = i.page.value;
336
+ i.reset(), i.page.value === y && E();
337
+ } else
338
+ E();
339
+ return !0;
340
+ }
341
+ function ue(e) {
342
+ const t = e.on("checkbox_state_change", se), r = e.on("radio_state_change", ie), c = e.on("tree_hierarchy_state_change", le), a = e.on("sort_click", de), d = Ee(e, n.getNativeEvents());
343
+ return () => {
344
+ e.off(t), e.off(r), e.off(c), e.off(a), d();
345
+ };
346
+ }
347
+ function ge(e) {
348
+ K || (l == null || l(), s.setInstance(e), l = ue(e), p.value = !0, o.syncToEngine(), L(), O(u.keys.value), f.syncExpandedState());
349
+ }
350
+ function fe(e) {
351
+ s.getInstance() === e && (l == null || l(), l = void 0, p.value = !1, s.setInstance(void 0));
352
+ }
353
+ function he(e, t) {
354
+ V.value = e, b.value = t;
355
+ }
356
+ function me(e) {
357
+ R || o.replaceAll(e);
358
+ }
359
+ function Re() {
360
+ K || (K = !0, l == null || l(), l = void 0, m == null || m.cancel(), k.release(), f.release(), o.release(), p.value = !1, s.release());
361
+ }
362
+ return {
363
+ tableApi: ne,
364
+ renderColumns: Y,
365
+ isRemote: R,
366
+ selectionMode: C,
367
+ sort: F,
368
+ filters: D,
369
+ getRowKey: o.getRowKey,
370
+ acceptNativeInstance: ge,
371
+ clearNativeInstance: fe,
372
+ acceptViewportSize: he,
373
+ acceptRecords: me,
374
+ release: Re
375
+ };
376
+ }
377
+ export {
378
+ A as TT_VTABLE_SELECTION_FIELD,
379
+ ot as createVTableRuntime
380
+ };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './components/tt-modal-form';
16
16
  export * from './components/tt-image';
17
17
  export * from './components/tt-loading';
18
18
  export * from './components/tt-table';
19
+ export * from './components/tt-vtable';
19
20
  export * from './components/tt-upload';
20
21
  export * from './components/tt-nav-anchor';
21
22
  export * from './components/tt-api-component';