@dazhicheng/ui 1.6.7 → 1.6.9
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.
- package/dist/components/tt-form/src/form-render/expandable.js +31 -32
- package/dist/components/tt-form/src/useFormContext.js +1 -1
- package/dist/components/tt-panel-select/src/index.vue.js +28 -28
- package/dist/components/tt-table/index.d.ts +3 -15
- package/dist/components/tt-table/index.js +5 -4
- package/dist/components/tt-table/src/Table.vue.d.ts +1 -1
- package/dist/components/tt-table/src/Table.vue.js +3 -3
- package/dist/components/tt-table/src/TableForm.vue.js +168 -159
- package/dist/components/tt-table/src/components/TableAction.vue.d.ts +2 -12
- package/dist/components/tt-table/src/components/TableAction.vue.js +78 -175
- package/dist/components/tt-table/src/hooks/useGridProps.js +64 -60
- package/dist/components/tt-table/src/hooks/useTableData.js +77 -74
- package/dist/components/tt-table/src/types/table.d.ts +2 -1
- package/dist/components/tt-table/src/utils/table-api.d.ts +2 -1
- package/dist/components/tt-table/src/utils/table-api.js +3 -2
- package/dist/components/tt-vtable/index.js +54 -0
- package/dist/components/tt-vtable/src/components/TtVTable.vue.d.ts +188 -0
- package/dist/components/tt-vtable/src/components/TtVTable.vue.js +227 -0
- package/dist/components/tt-vtable/src/components/TtVTable.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/TtVTableForm.vue.d.ts +32 -0
- package/dist/components/tt-vtable/src/components/TtVTableForm.vue.js +121 -0
- package/dist/components/tt-vtable/src/components/TtVTableForm.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/VTableEmpty.vue.d.ts +64 -0
- package/dist/components/tt-vtable/src/components/VTableEmpty.vue.js +97 -0
- package/dist/components/tt-vtable/src/components/VTableEmpty.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/VTablePagination.vue.d.ts +53 -0
- package/dist/components/tt-vtable/src/components/VTablePagination.vue.js +52 -0
- package/dist/components/tt-vtable/src/components/VTablePagination.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.d.ts +35 -0
- package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue.js +50 -0
- package/dist/components/tt-vtable/src/components/VTableSelectionAlert.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/VTableToolbar.vue.d.ts +63 -0
- package/dist/components/tt-vtable/src/components/VTableToolbar.vue.js +126 -0
- package/dist/components/tt-vtable/src/components/VTableToolbar.vue2.js +4 -0
- package/dist/components/tt-vtable/src/components/VTableViewport.vue.js +133 -0
- package/dist/components/tt-vtable/src/components/VTableViewport.vue2.js +4 -0
- package/dist/components/tt-vtable/src/composables/useVTable.d.ts +41 -0
- package/dist/components/tt-vtable/src/composables/useVTable.js +25 -0
- package/dist/components/tt-vtable/src/composables/useVTableFormRender.d.ts +13 -0
- package/dist/components/tt-vtable/src/composables/useVTableFormRender.js +92 -0
- package/dist/components/tt-vtable/src/composables/useVTableRender.d.ts +13 -0
- package/dist/components/tt-vtable/src/composables/useVTableRender.js +13 -0
- package/dist/components/tt-vtable/src/engine/visactor/createListTable.d.ts +10 -0
- package/dist/components/tt-vtable/src/engine/visactor/createListTable.js +63 -0
- package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.d.ts +37 -0
- package/dist/components/tt-vtable/src/engine/visactor/createVueCellLayout.js +133 -0
- package/dist/components/tt-vtable/src/engine/visactor/index.d.ts +8 -0
- package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.d.ts +23 -0
- package/dist/components/tt-vtable/src/engine/visactor/native-boundaries.js +70 -0
- package/dist/components/tt-vtable/src/engine/visactor/record-adapter.d.ts +38 -0
- package/dist/components/tt-vtable/src/engine/visactor/record-adapter.js +41 -0
- package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.d.ts +45 -0
- package/dist/components/tt-vtable/src/engine/visactor/toColumnDefinitions.js +73 -0
- package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.d.ts +25 -0
- package/dist/components/tt-vtable/src/engine/visactor/toListTableOptions.js +25 -0
- package/dist/components/tt-vtable/src/engine/visactor/types.d.ts +29 -0
- package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.d.ts +5 -0
- package/dist/components/tt-vtable/src/features/column-preferences/column-preference-storage.js +52 -0
- package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.d.ts +74 -0
- package/dist/components/tt-vtable/src/features/column-preferences/useColumnPreferences.js +232 -0
- package/dist/components/tt-vtable/src/features/editing/useCellEditing.d.ts +48 -0
- package/dist/components/tt-vtable/src/features/editing/useCellEditing.js +102 -0
- package/dist/components/tt-vtable/src/features/form-integration/useVTableForm.d.ts +51 -0
- package/dist/components/tt-vtable/src/features/pagination/useTablePagination.d.ts +40 -0
- package/dist/components/tt-vtable/src/features/pagination/useTablePagination.js +51 -0
- package/dist/components/tt-vtable/src/features/querying/useRecordQuery.d.ts +38 -0
- package/dist/components/tt-vtable/src/features/querying/useRecordQuery.js +57 -0
- package/dist/components/tt-vtable/src/features/records/index.d.ts +3 -0
- package/dist/components/tt-vtable/src/features/records/record-index.d.ts +122 -0
- package/dist/components/tt-vtable/src/features/records/record-index.js +209 -0
- package/dist/components/tt-vtable/src/features/records/useRecordSource.d.ts +41 -0
- package/dist/components/tt-vtable/src/features/records/useRecordSource.js +249 -0
- package/dist/components/tt-vtable/src/features/selection/useRowSelection.d.ts +65 -0
- package/dist/components/tt-vtable/src/features/selection/useRowSelection.js +129 -0
- package/dist/components/tt-vtable/src/features/tree/useTreeRecords.d.ts +60 -0
- package/dist/components/tt-vtable/src/features/tree/useTreeRecords.js +125 -0
- package/dist/components/tt-vtable/src/public/column-preferences.d.ts +32 -0
- package/dist/components/tt-vtable/src/public/index.d.ts +8 -0
- package/dist/components/tt-vtable/src/public/table-api.d.ts +215 -0
- package/dist/components/tt-vtable/src/public/table-column.d.ts +123 -0
- package/dist/components/tt-vtable/src/public/table-errors.d.ts +26 -0
- package/dist/components/tt-vtable/src/public/table-errors.js +26 -0
- package/dist/components/tt-vtable/src/public/table-events.d.ts +69 -0
- package/dist/components/tt-vtable/src/public/table-props.d.ts +216 -0
- package/dist/components/tt-vtable/src/public/table-slots.d.ts +37 -0
- package/dist/components/tt-vtable/src/runtime/createVTableController.d.ts +12 -0
- package/dist/components/tt-vtable/src/runtime/createVTableController.js +238 -0
- package/dist/components/tt-vtable/src/runtime/createVTableRuntime.d.ts +79 -0
- package/dist/components/tt-vtable/src/runtime/createVTableRuntime.js +380 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +129 -115
- package/dist/packages/utils/src/is.js +46 -37
- package/dist/style.css +1 -1
- package/package.json +3 -1
- package/dist/assets/svg/action_more.svg.js +0 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { TtVTableFetchRequest, TtVTableFetchResponse } from '../../public/table-props';
|
|
3
|
+
/** 挂载 AbortSignal 前用于发起请求的快照。 */
|
|
4
|
+
export type VTableRecordRequestSnapshot<QueryParams extends Record<string, unknown>> = Omit<TtVTableFetchRequest<QueryParams>, "signal">;
|
|
5
|
+
/** 暴露给 runtime 的远程查询状态与动作。 */
|
|
6
|
+
export interface VTableRecordQuery<QueryParams extends Record<string, unknown>> {
|
|
7
|
+
/** 最新请求是否进行中。 */
|
|
8
|
+
isFetching: Readonly<Ref<boolean>>;
|
|
9
|
+
/** 最近一次被接纳请求的错误。 */
|
|
10
|
+
error: Readonly<Ref<Error | undefined>>;
|
|
11
|
+
/** 使用当前状态和可选覆盖参数执行请求。 */
|
|
12
|
+
fetch: (overrides?: Partial<VTableRecordRequestSnapshot<QueryParams>>) => Promise<boolean>;
|
|
13
|
+
/** 不重置分页并重放最近一次被接纳的请求。 */
|
|
14
|
+
refresh: () => Promise<boolean>;
|
|
15
|
+
/** 取消当前请求并使其响应失效。 */
|
|
16
|
+
cancel: () => void;
|
|
17
|
+
}
|
|
18
|
+
/** 远程查询 feature 所需依赖。 */
|
|
19
|
+
export interface UseRecordQueryOptions<Row, QueryParams extends Record<string, unknown>> {
|
|
20
|
+
/** 远程记录请求回调。 */
|
|
21
|
+
fetchRecords: (request: TtVTableFetchRequest<QueryParams>) => Promise<TtVTableFetchResponse<Row>>;
|
|
22
|
+
/** 读取最新请求状态。 */
|
|
23
|
+
getRequestSnapshot: () => VTableRecordRequestSnapshot<QueryParams>;
|
|
24
|
+
/** 最新请求成功后替换 runtime 记录。 */
|
|
25
|
+
replaceRecords: (records: readonly Row[]) => Promise<void> | void;
|
|
26
|
+
/** 最新请求成功后保存总数。 */
|
|
27
|
+
setTotal: (total: number) => void;
|
|
28
|
+
/** 仅按根引用监听的 maybe-reactive 查询参数。 */
|
|
29
|
+
queryParams?: MaybeRefOrGetter<QueryParams>;
|
|
30
|
+
/** 是否立即执行首次请求。 */
|
|
31
|
+
immediate?: boolean;
|
|
32
|
+
/** 最新请求被接纳后调用。 */
|
|
33
|
+
onSuccess?: (response: TtVTableFetchResponse<Row>, request: TtVTableFetchRequest<QueryParams>) => void;
|
|
34
|
+
/** 最新且未中止的请求失败时调用。 */
|
|
35
|
+
onError?: (error: Error, request: TtVTableFetchRequest<QueryParams>) => void;
|
|
36
|
+
}
|
|
37
|
+
/** 创建可防止请求竞态的远程记录查询 feature。 */
|
|
38
|
+
export declare function useRecordQuery<Row, QueryParams extends Record<string, unknown> = Record<string, unknown>>(options: UseRecordQueryOptions<Row, QueryParams>): VTableRecordQuery<QueryParams>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "axios";
|
|
2
|
+
import "element-plus";
|
|
3
|
+
import { isError as p } from "../../../../../packages/utils/src/is.js";
|
|
4
|
+
import { shallowRef as h, watch as E, toValue as v, onScopeDispose as R } 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 w(r) {
|
|
17
|
+
return new Error(p(r) ? String(r).replace(/^Error:\s*/, "") : String(r));
|
|
18
|
+
}
|
|
19
|
+
function y(r) {
|
|
20
|
+
return r.name === "AbortError";
|
|
21
|
+
}
|
|
22
|
+
function I(r) {
|
|
23
|
+
const c = h(!1), n = h();
|
|
24
|
+
let e, t = 0, o;
|
|
25
|
+
async function i(S = {}) {
|
|
26
|
+
var d, q;
|
|
27
|
+
e == null || e.abort(), e = new AbortController(), t += 1;
|
|
28
|
+
const s = t, m = { ...r.getRequestSnapshot(), ...S }, a = {
|
|
29
|
+
...m,
|
|
30
|
+
signal: e.signal
|
|
31
|
+
};
|
|
32
|
+
c.value = !0, n.value = void 0;
|
|
33
|
+
try {
|
|
34
|
+
const u = await r.fetchRecords(a);
|
|
35
|
+
return s !== t || a.signal.aborted || (await r.replaceRecords(u.records), s !== t || a.signal.aborted) ? !1 : (r.setTotal(u.total), o = m, (d = r.onSuccess) == null || d.call(r, u, a), !0);
|
|
36
|
+
} catch (u) {
|
|
37
|
+
const l = w(u);
|
|
38
|
+
return s !== t || a.signal.aborted || y(l) || (n.value = l, (q = r.onError) == null || q.call(r, l, a)), !1;
|
|
39
|
+
} finally {
|
|
40
|
+
s === t && (c.value = !1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function g() {
|
|
44
|
+
return i(o);
|
|
45
|
+
}
|
|
46
|
+
function f() {
|
|
47
|
+
t += 1, e == null || e.abort(), e = void 0, c.value = !1;
|
|
48
|
+
}
|
|
49
|
+
return r.queryParams ? E(
|
|
50
|
+
() => v(r.queryParams),
|
|
51
|
+
() => void i(),
|
|
52
|
+
{ immediate: r.immediate ?? !0 }
|
|
53
|
+
) : (r.immediate ?? !0) && i(), R(f), { isFetching: c, error: n, fetch: i, refresh: g, cancel: f };
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
I as useRecordQuery
|
|
57
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { TtVTableFieldPath, TtVTableRowKey, TtVTableRowKeySource } from '../../public';
|
|
2
|
+
/** 根记录或树节点在源 records 中的索引路径。 */
|
|
3
|
+
export type TtVTableRecordPath = readonly number[];
|
|
4
|
+
/** rowKey 索引中的一条记录位置。 */
|
|
5
|
+
export interface TtVTableRecordLocation<Row, Key extends TtVTableRowKey = TtVTableRowKey> {
|
|
6
|
+
/** 当前业务主键。 */
|
|
7
|
+
rowKey: Key;
|
|
8
|
+
/** 当前运行时记录。 */
|
|
9
|
+
record: Row;
|
|
10
|
+
/** 从根 records 到当前记录的源索引路径。 */
|
|
11
|
+
path: TtVTableRecordPath;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 把字段路径规范为可逐层读取的片段。
|
|
15
|
+
* @param field 字段或点分隔字段路径
|
|
16
|
+
* @returns 路径片段
|
|
17
|
+
*/
|
|
18
|
+
export declare function toFieldSegments(field: TtVTableFieldPath): (number | string)[];
|
|
19
|
+
/**
|
|
20
|
+
* 按字段路径读取记录值。
|
|
21
|
+
* @param record 业务记录
|
|
22
|
+
* @param field 字段或点分隔字段路径
|
|
23
|
+
* @returns 路径对应值
|
|
24
|
+
*/
|
|
25
|
+
export declare function getRecordFieldValue<Row extends Record<string, unknown>>(record: Readonly<Row>, field: TtVTableFieldPath): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* 判断值是否是合法业务主键。
|
|
28
|
+
* @param rowKey 待判断主键
|
|
29
|
+
* @returns 是否为非空字符串或有限数字
|
|
30
|
+
*/
|
|
31
|
+
export declare function isValidVTableRowKey(rowKey: unknown): rowKey is TtVTableRowKey;
|
|
32
|
+
/**
|
|
33
|
+
* 按字段路径创建只复制命中分支的新记录。
|
|
34
|
+
* @param record 原记录
|
|
35
|
+
* @param field 字段或点分隔字段路径
|
|
36
|
+
* @param value 待写值
|
|
37
|
+
* @returns 更新后的记录
|
|
38
|
+
*/
|
|
39
|
+
export declare function toRecordWithFieldValue<Row extends Record<string, unknown>>(record: Row, field: TtVTableFieldPath, value: unknown): Row;
|
|
40
|
+
/**
|
|
41
|
+
* 按字段路径直接修改共享记录。
|
|
42
|
+
* @param record 共享记录
|
|
43
|
+
* @param field 字段或点分隔字段路径
|
|
44
|
+
* @param value 待写值
|
|
45
|
+
*/
|
|
46
|
+
export declare function setSharedRecordFieldValue<Row extends Record<string, unknown>>(record: Row, field: TtVTableFieldPath, value: unknown): void;
|
|
47
|
+
/**
|
|
48
|
+
* 按源索引路径读取根记录或树节点。
|
|
49
|
+
* @param records 根记录集合
|
|
50
|
+
* @param path 源索引路径
|
|
51
|
+
* @param childrenField 子节点字段路径
|
|
52
|
+
* @returns 命中的记录
|
|
53
|
+
*/
|
|
54
|
+
export declare function getRecordAtPath<Row extends Record<string, unknown>>(records: readonly Row[], path: TtVTableRecordPath, childrenField: string): Row | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* 在运行时根数组中替换记录,并只复制树路径上的父分支。
|
|
57
|
+
* @param records 运行时根记录数组
|
|
58
|
+
* @param path 目标源索引路径
|
|
59
|
+
* @param nextRecord 更新后的目标记录
|
|
60
|
+
* @param childrenField 子节点字段路径
|
|
61
|
+
*/
|
|
62
|
+
export declare function replaceRecordAtPath<Row extends Record<string, unknown>>(records: Row[], path: TtVTableRecordPath, nextRecord: Row, childrenField: string): void;
|
|
63
|
+
/** 维护 rowKey 到源索引路径的稳定映射。 */
|
|
64
|
+
export declare class TtVTableRecordIndex<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> {
|
|
65
|
+
/** 业务主键字段路径或读取函数。 */
|
|
66
|
+
private readonly rowKeySource;
|
|
67
|
+
/** 子节点字段路径。 */
|
|
68
|
+
private readonly childrenField;
|
|
69
|
+
/** 当前主键位置映射。 */
|
|
70
|
+
private locations;
|
|
71
|
+
/**
|
|
72
|
+
* 创建空 rowKey 索引。
|
|
73
|
+
* @param rowKeySource 业务主键字段路径或读取函数
|
|
74
|
+
* @param childrenField 子节点字段路径
|
|
75
|
+
*/
|
|
76
|
+
constructor(rowKeySource: TtVTableRowKeySource<Row, Key>, childrenField?: string);
|
|
77
|
+
/** 当前索引记录数量。 */
|
|
78
|
+
get size(): number;
|
|
79
|
+
/**
|
|
80
|
+
* 从业务记录读取并校验主键。
|
|
81
|
+
* @param record 业务记录
|
|
82
|
+
* @returns 合法业务主键
|
|
83
|
+
*/
|
|
84
|
+
getRowKey(record: Row): Key;
|
|
85
|
+
/**
|
|
86
|
+
* 使用新的根记录重建并原子替换索引。
|
|
87
|
+
* @param records 运行时根记录
|
|
88
|
+
*/
|
|
89
|
+
replace(records: readonly Row[]): void;
|
|
90
|
+
/**
|
|
91
|
+
* 判断索引是否包含主键。
|
|
92
|
+
* @param rowKey 业务主键
|
|
93
|
+
* @returns 是否存在
|
|
94
|
+
*/
|
|
95
|
+
has(rowKey: Key): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* 按主键读取位置。
|
|
98
|
+
* @param rowKey 业务主键
|
|
99
|
+
* @returns 当前记录位置
|
|
100
|
+
*/
|
|
101
|
+
getLocation(rowKey: Key): TtVTableRecordLocation<Row, Key> | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* 按主键读取记录。
|
|
104
|
+
* @param rowKey 业务主键
|
|
105
|
+
* @returns 当前运行时记录
|
|
106
|
+
*/
|
|
107
|
+
getRecord(rowKey: Key): Row | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* 原子迁移一条记录的主键、引用和路径。
|
|
110
|
+
* @param previousRowKey 变化前主键
|
|
111
|
+
* @param nextRowKey 变化后主键
|
|
112
|
+
* @param record 更新后的记录
|
|
113
|
+
* @param path 当前源索引路径
|
|
114
|
+
*/
|
|
115
|
+
replaceLocation(previousRowKey: Key, nextRowKey: Key, record: Row, path: TtVTableRecordPath): void;
|
|
116
|
+
/**
|
|
117
|
+
* 更新 copy-on-write 后树分支上的记录引用。
|
|
118
|
+
* @param records 当前运行时根记录
|
|
119
|
+
* @param path 已修改记录路径
|
|
120
|
+
*/
|
|
121
|
+
refreshBranch(records: readonly Row[], path: TtVTableRecordPath): void;
|
|
122
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var E = (r, t, o) => t in r ? b(r, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[t] = o;
|
|
3
|
+
var f = (r, t, o) => E(r, typeof t != "symbol" ? t + "" : t, o);
|
|
4
|
+
import "axios";
|
|
5
|
+
import "element-plus";
|
|
6
|
+
import { isFunction as F, isArray as u, isNumber as g, isString as I, isObject as T } from "../../../../../packages/utils/src/is.js";
|
|
7
|
+
import "vue";
|
|
8
|
+
import "dayjs";
|
|
9
|
+
import "numeral";
|
|
10
|
+
import "xe-utils";
|
|
11
|
+
import "dayjs/plugin/utc";
|
|
12
|
+
import "dayjs/plugin/timezone";
|
|
13
|
+
import "../../../../../node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js";
|
|
14
|
+
import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js";
|
|
15
|
+
import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf8.js";
|
|
16
|
+
import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js";
|
|
17
|
+
import "../../../../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-pkcs7.js";
|
|
18
|
+
import "lodash-es";
|
|
19
|
+
import { createTtVTableError as m } from "../../public/table-errors.js";
|
|
20
|
+
function L(r) {
|
|
21
|
+
return g(r) ? [r] : r.split(".").filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
function V(r) {
|
|
24
|
+
return T(r) || u(r);
|
|
25
|
+
}
|
|
26
|
+
function w(r, t) {
|
|
27
|
+
return u(r) ? g(t) ? r[t] : void 0 : r[t];
|
|
28
|
+
}
|
|
29
|
+
function p(r, t) {
|
|
30
|
+
let o = r;
|
|
31
|
+
const e = L(t);
|
|
32
|
+
for (const i of e) {
|
|
33
|
+
if (!V(o)) return;
|
|
34
|
+
o = w(o, i);
|
|
35
|
+
}
|
|
36
|
+
return o;
|
|
37
|
+
}
|
|
38
|
+
function K(r) {
|
|
39
|
+
return I(r) ? !!r : g(r) && Number.isFinite(r);
|
|
40
|
+
}
|
|
41
|
+
function y(r) {
|
|
42
|
+
return u(r) ? [...r] : T(r) ? { ...r } : {};
|
|
43
|
+
}
|
|
44
|
+
function R(r, t, o) {
|
|
45
|
+
if (u(r)) {
|
|
46
|
+
g(t) && (r[t] = o);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
r[t] = o;
|
|
50
|
+
}
|
|
51
|
+
function A(r, t, o) {
|
|
52
|
+
const e = L(t);
|
|
53
|
+
if (!e.length) return r;
|
|
54
|
+
const i = { ...r };
|
|
55
|
+
let c = r, n = i;
|
|
56
|
+
return e.forEach((s, l) => {
|
|
57
|
+
if (l === e.length - 1) {
|
|
58
|
+
R(n, s, o);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const h = V(c) ? w(c, s) : void 0, d = y(h);
|
|
62
|
+
R(n, s, d), c = h, n = d;
|
|
63
|
+
}), i;
|
|
64
|
+
}
|
|
65
|
+
function _(r, t, o) {
|
|
66
|
+
let e = r, i;
|
|
67
|
+
for (let c = 0; c < t.length; c += 1) {
|
|
68
|
+
const n = t[c];
|
|
69
|
+
if (n === void 0 || (i = e[n], !i)) return;
|
|
70
|
+
if (c === t.length - 1) return i;
|
|
71
|
+
const s = p(i, o);
|
|
72
|
+
if (!u(s)) return;
|
|
73
|
+
e = s;
|
|
74
|
+
}
|
|
75
|
+
return i;
|
|
76
|
+
}
|
|
77
|
+
function q(r, t, o, e) {
|
|
78
|
+
if (!t.length) return;
|
|
79
|
+
if (t.length === 1) {
|
|
80
|
+
const n = t[0];
|
|
81
|
+
if (n === void 0) return;
|
|
82
|
+
r[n] = o;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let i = o;
|
|
86
|
+
for (let n = t.length - 2; n >= 0; n -= 1) {
|
|
87
|
+
const s = t.slice(0, n + 1), l = _(r, s, e);
|
|
88
|
+
if (!l) return;
|
|
89
|
+
const a = p(l, e);
|
|
90
|
+
if (!u(a)) return;
|
|
91
|
+
const h = [...a], d = t[n + 1];
|
|
92
|
+
if (d === void 0) return;
|
|
93
|
+
h[d] = i, i = A(l, e, h);
|
|
94
|
+
}
|
|
95
|
+
const c = t[0];
|
|
96
|
+
c !== void 0 && (r[c] = i);
|
|
97
|
+
}
|
|
98
|
+
class G {
|
|
99
|
+
/**
|
|
100
|
+
* 创建空 rowKey 索引。
|
|
101
|
+
* @param rowKeySource 业务主键字段路径或读取函数
|
|
102
|
+
* @param childrenField 子节点字段路径
|
|
103
|
+
*/
|
|
104
|
+
constructor(t, o = "children") {
|
|
105
|
+
/** 业务主键字段路径或读取函数。 */
|
|
106
|
+
f(this, "rowKeySource");
|
|
107
|
+
/** 子节点字段路径。 */
|
|
108
|
+
f(this, "childrenField");
|
|
109
|
+
/** 当前主键位置映射。 */
|
|
110
|
+
f(this, "locations", /* @__PURE__ */ new Map());
|
|
111
|
+
this.rowKeySource = t, this.childrenField = o;
|
|
112
|
+
}
|
|
113
|
+
/** 当前索引记录数量。 */
|
|
114
|
+
get size() {
|
|
115
|
+
return this.locations.size;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 从业务记录读取并校验主键。
|
|
119
|
+
* @param record 业务记录
|
|
120
|
+
* @returns 合法业务主键
|
|
121
|
+
*/
|
|
122
|
+
getRowKey(t) {
|
|
123
|
+
const o = F(this.rowKeySource) ? this.rowKeySource(t) : p(t, this.rowKeySource);
|
|
124
|
+
if (!K(o))
|
|
125
|
+
throw m("TT_VTABLE_ROW_KEY_INVALID", "rowKey 必须是非空字符串或有限数字。", { rowKey: o });
|
|
126
|
+
return o;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 使用新的根记录重建并原子替换索引。
|
|
130
|
+
* @param records 运行时根记录
|
|
131
|
+
*/
|
|
132
|
+
replace(t) {
|
|
133
|
+
const o = /* @__PURE__ */ new Map(), e = (i, c) => {
|
|
134
|
+
i.forEach((n, s) => {
|
|
135
|
+
const l = this.getRowKey(n);
|
|
136
|
+
if (o.has(l))
|
|
137
|
+
throw m("TT_VTABLE_DUPLICATE_ROW_KEY", `rowKey ${String(l)} 在整棵记录树中重复。`, {
|
|
138
|
+
rowKey: l
|
|
139
|
+
});
|
|
140
|
+
const a = [...c, s];
|
|
141
|
+
o.set(l, { rowKey: l, record: n, path: a });
|
|
142
|
+
const h = p(n, this.childrenField);
|
|
143
|
+
u(h) && h.length && e(h, a);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
e(t, []), this.locations = o;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 判断索引是否包含主键。
|
|
150
|
+
* @param rowKey 业务主键
|
|
151
|
+
* @returns 是否存在
|
|
152
|
+
*/
|
|
153
|
+
has(t) {
|
|
154
|
+
return this.locations.has(t);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 按主键读取位置。
|
|
158
|
+
* @param rowKey 业务主键
|
|
159
|
+
* @returns 当前记录位置
|
|
160
|
+
*/
|
|
161
|
+
getLocation(t) {
|
|
162
|
+
return this.locations.get(t);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 按主键读取记录。
|
|
166
|
+
* @param rowKey 业务主键
|
|
167
|
+
* @returns 当前运行时记录
|
|
168
|
+
*/
|
|
169
|
+
getRecord(t) {
|
|
170
|
+
var o;
|
|
171
|
+
return (o = this.locations.get(t)) == null ? void 0 : o.record;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 原子迁移一条记录的主键、引用和路径。
|
|
175
|
+
* @param previousRowKey 变化前主键
|
|
176
|
+
* @param nextRowKey 变化后主键
|
|
177
|
+
* @param record 更新后的记录
|
|
178
|
+
* @param path 当前源索引路径
|
|
179
|
+
*/
|
|
180
|
+
replaceLocation(t, o, e, i) {
|
|
181
|
+
if (o !== t && this.locations.has(o))
|
|
182
|
+
throw m("TT_VTABLE_DUPLICATE_ROW_KEY", `rowKey ${String(o)} 已存在。`, {
|
|
183
|
+
rowKey: o
|
|
184
|
+
});
|
|
185
|
+
this.locations.delete(t), this.locations.set(o, { rowKey: o, record: e, path: [...i] });
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 更新 copy-on-write 后树分支上的记录引用。
|
|
189
|
+
* @param records 当前运行时根记录
|
|
190
|
+
* @param path 已修改记录路径
|
|
191
|
+
*/
|
|
192
|
+
refreshBranch(t, o) {
|
|
193
|
+
for (let e = 1; e <= o.length; e += 1) {
|
|
194
|
+
const i = o.slice(0, e), c = _(t, i, this.childrenField);
|
|
195
|
+
if (!c) continue;
|
|
196
|
+
const n = this.getRowKey(c), s = this.locations.get(n);
|
|
197
|
+
s && (s.record = c, s.path = i);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export {
|
|
202
|
+
G as TtVTableRecordIndex,
|
|
203
|
+
_ as getRecordAtPath,
|
|
204
|
+
p as getRecordFieldValue,
|
|
205
|
+
K as isValidVTableRowKey,
|
|
206
|
+
q as replaceRecordAtPath,
|
|
207
|
+
L as toFieldSegments,
|
|
208
|
+
A as toRecordWithFieldValue
|
|
209
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TtVTableMutationMode, TtVTableRecordChange, TtVTableRecordsApi, TtVTableRowKey, TtVTableRowKeySource } from '../../public';
|
|
2
|
+
import { VisactorRecordIndex, VisactorTableEngine } from '../../engine/visactor';
|
|
3
|
+
import { TtVTableRecordIndex } from './record-index';
|
|
4
|
+
/** records feature 依赖。 */
|
|
5
|
+
export interface UseRecordSourceOptions<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> {
|
|
6
|
+
/** 初始本地或远程记录。 */
|
|
7
|
+
records?: readonly Row[];
|
|
8
|
+
/** 业务主键字段路径或读取函数。 */
|
|
9
|
+
rowKey: TtVTableRowKeySource<Row, Key>;
|
|
10
|
+
/** 子节点字段路径。 */
|
|
11
|
+
childrenField?: string;
|
|
12
|
+
/** 记录所有权策略。 */
|
|
13
|
+
mutationMode?: TtVTableMutationMode;
|
|
14
|
+
/** 稳定 VisActor 适配器。 */
|
|
15
|
+
engine: VisactorTableEngine<Row>;
|
|
16
|
+
/** 接收 API 或 renderer 产生的精确记录变化。 */
|
|
17
|
+
onRecordChange?: (change: TtVTableRecordChange<Row, Key>) => void;
|
|
18
|
+
/** 根记录替换后的协调回调。 */
|
|
19
|
+
onRecordsReplaced?: (records: readonly Row[]) => void;
|
|
20
|
+
}
|
|
21
|
+
/** records feature 提供给 runtime 和其他 feature 的完整契约。 */
|
|
22
|
+
export interface TtVTableRecordSource<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey> extends TtVTableRecordsApi<Row, Key> {
|
|
23
|
+
/** 当前 rowKey 索引。 */
|
|
24
|
+
recordIndex: TtVTableRecordIndex<Row, Key>;
|
|
25
|
+
/** 从记录读取并校验业务主键。 */
|
|
26
|
+
getRowKey: (record: Row) => Key;
|
|
27
|
+
/** 按主键读取原生源索引。 */
|
|
28
|
+
getRecordIndex: (rowKey: Key) => VisactorRecordIndex | undefined;
|
|
29
|
+
/** 为树 feature 写入 copy-on-write 子节点。 */
|
|
30
|
+
setChildren: (parentKey: Key, children: readonly Row[]) => void;
|
|
31
|
+
/** 原生实例 ready 后只同步最终记录快照。 */
|
|
32
|
+
syncToEngine: () => void;
|
|
33
|
+
/** 幂等释放 feature。 */
|
|
34
|
+
release: () => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 创建浅层运行时 records、rowKey 索引和增量更新动作。
|
|
38
|
+
* @param options 初始记录、主键、所有权策略和 VisActor 适配器
|
|
39
|
+
* @returns records feature
|
|
40
|
+
*/
|
|
41
|
+
export declare function useRecordSource<Row extends Record<string, unknown>, Key extends TtVTableRowKey = TtVTableRowKey>(options: UseRecordSourceOptions<Row, Key>): TtVTableRecordSource<Row, Key>;
|