@vueye-table/vue 3.0.0-alpha.1 → 3.0.0-alpha.10
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/index.d.ts +123 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +828 -36
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,64 @@
|
|
|
1
|
-
import { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
2
|
-
import { CellPosition, CellRange, ColumnDef, DataTable, EditResult, GridBounds, GridDirection, GridKey, GridSelection, MoveOptions, TableColumn, TableOptions, TableRow, TableSnapshot, TableStatePatch } from "@vueye-table/core";
|
|
1
|
+
import { ComponentPublicInstance, ComputedRef, MaybeRef, MaybeRefOrGetter } from "vue";
|
|
2
|
+
import { CellPosition, CellRange, ColumnDef, CopyOptions, DataTable, DeepKeys, EditResult, EditorSpec, ExpandedState, GridBounds, GridDirection, GridKey, GridSelection, MoveOptions, PathValue, PendingChanges, RowKey, StreamOptions, TableColumn, TableIssue, TableOptions, TableRenderItem, TableRow, TableSnapshot, TableState, TableStatePatch, TreeLoadController, TreeLoadSignal, VirtualAlign, VirtualItem, VirtualWindow } from "@vueye-table/core";
|
|
3
|
+
//#region src/row-draft.d.ts
|
|
4
|
+
/** A column-value bag. Only configured columns are present; dotted paths stay dotted keys. */
|
|
5
|
+
type RowDraftValues<TRow> = { -readonly [P in DeepKeys<TRow>]?: PathValue<TRow, P>; };
|
|
6
|
+
interface RowDraft<TRow> {
|
|
7
|
+
readonly rowKey: RowKey;
|
|
8
|
+
readonly values: RowDraftValues<TRow>;
|
|
9
|
+
readonly issues: readonly TableIssue[];
|
|
10
|
+
readonly status: "editing" | "saving" | "saved" | "cancelled" | "stale";
|
|
11
|
+
readonly pending: boolean;
|
|
12
|
+
/** Supply raw text for the column parser, including numeric/date input. */
|
|
13
|
+
setInput(column: string, input: string): void;
|
|
14
|
+
/** Set a computed column whose id is not a path in the row type. */
|
|
15
|
+
setValue(column: string, value: unknown): void;
|
|
16
|
+
save(): Promise<EditResult<TRow>>;
|
|
17
|
+
/** Discard an unsubmitted draft. A submitted validation batch is owned by the engine. */
|
|
18
|
+
cancel(): boolean;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/source.d.ts
|
|
22
|
+
interface SourceContext {
|
|
23
|
+
readonly signal: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
type TableSource<TRow> = AsyncIterable<TRow | readonly TRow[]> | ((context: SourceContext) => AsyncIterable<TRow | readonly TRow[]>);
|
|
26
|
+
interface LoadMoreContext extends SourceContext {
|
|
27
|
+
/** Undefined on the first page. Validate or narrow the opaque cursor in your loader. */
|
|
28
|
+
readonly cursor: unknown;
|
|
29
|
+
readonly state: TableState;
|
|
30
|
+
}
|
|
31
|
+
interface LoadMoreResult<TRow> {
|
|
32
|
+
readonly rows: readonly TRow[];
|
|
33
|
+
readonly cursor?: unknown;
|
|
34
|
+
readonly done: boolean;
|
|
35
|
+
}
|
|
36
|
+
type LoadMore<TRow> = (context: LoadMoreContext) => Promise<LoadMoreResult<TRow>>;
|
|
37
|
+
/** Schedule once per rendering frame and return its cancellation function. */
|
|
38
|
+
type FrameScheduler = (publish: () => void) => () => void;
|
|
39
|
+
interface SourceOptions<TRow> {
|
|
40
|
+
readonly source?: MaybeRef<TableSource<TRow> | undefined> | undefined;
|
|
41
|
+
readonly loadMore?: MaybeRef<LoadMore<TRow> | undefined> | undefined;
|
|
42
|
+
readonly streamOptions?: Omit<StreamOptions, "signal"> | undefined;
|
|
43
|
+
/** Non-component scopes use a 16ms timer by default. */
|
|
44
|
+
readonly scheduleFrame?: FrameScheduler | undefined;
|
|
45
|
+
/** Remaining flattened items at which a virtual renderer requests the next cursor page. */
|
|
46
|
+
readonly endThreshold?: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
interface SourceBinding {
|
|
49
|
+
readonly endThreshold: number;
|
|
50
|
+
readonly loadingMode: "source" | "cursor" | undefined;
|
|
51
|
+
readonly canLoadMore: boolean;
|
|
52
|
+
readonly loadError: TableIssue | undefined;
|
|
53
|
+
loadNext(this: void): Promise<void>;
|
|
54
|
+
retry(this: void): void;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
3
57
|
//#region src/use-data-table.d.ts
|
|
4
58
|
/** Options accepted by {@link useDataTable}. Data, columns, and state may be refs or getters. */
|
|
5
|
-
interface UseDataTableOptions<TRow> extends Omit<TableOptions<TRow>, "data" | "columns" | "rowCount"> {
|
|
6
|
-
|
|
59
|
+
interface UseDataTableOptions<TRow, TSignal extends TreeLoadSignal = AbortSignal> extends Omit<TableOptions<TRow, TSignal>, "data" | "columns" | "rowCount">, SourceOptions<TRow> {
|
|
60
|
+
/** Initial rows for a source, or the caller-owned array for an ordinary table. */
|
|
61
|
+
readonly data?: MaybeRefOrGetter<readonly TRow[]> | undefined;
|
|
7
62
|
readonly columns: MaybeRefOrGetter<readonly ColumnDef<TRow>[]>;
|
|
8
63
|
readonly rowCount?: MaybeRefOrGetter<number | undefined> | undefined;
|
|
9
64
|
/**
|
|
@@ -18,11 +73,14 @@ type TableOperations<TRow> = Omit<DataTable<TRow>, "getSnapshot" | "getState" |
|
|
|
18
73
|
* `table.rows` and `table.pageCount` directly, and every change goes through a named operation.
|
|
19
74
|
* Watching a field needs a getter: `watch(() => table.page, ...)`.
|
|
20
75
|
*/
|
|
21
|
-
type DataTableBinding<TRow> = TableSnapshot<TRow> & TableOperations<TRow> & {
|
|
76
|
+
type DataTableBinding<TRow> = TableSnapshot<TRow> & SourceBinding & TableOperations<TRow> & {
|
|
22
77
|
/** The engine behind the binding. */
|
|
23
78
|
readonly table: DataTable<TRow>;
|
|
24
79
|
/** The current snapshot, replaced on every change. */
|
|
25
80
|
readonly snapshot: TableSnapshot<TRow>;
|
|
81
|
+
readonly expanded: ExpandedState;
|
|
82
|
+
readonly pendingChanges: PendingChanges<TRow>;
|
|
83
|
+
editRow(key: RowKey): RowDraft<TRow>;
|
|
26
84
|
};
|
|
27
85
|
/**
|
|
28
86
|
* A binding for any row type, for components that accept every table. Row types make the binding
|
|
@@ -34,6 +92,9 @@ type AnyDataTableBinding = DataTableBinding<any>;
|
|
|
34
92
|
* columns, row count, and state, and stops listening when the scope ends.
|
|
35
93
|
*/
|
|
36
94
|
declare function useDataTable<TRow>(options: UseDataTableOptions<TRow>): DataTableBinding<TRow>;
|
|
95
|
+
declare function useDataTable<TRow, TSignal extends TreeLoadSignal = AbortSignal>(options: UseDataTableOptions<TRow, TSignal> & (AbortSignal extends TSignal ? unknown : {
|
|
96
|
+
readonly createChildLoadController: () => TreeLoadController<TSignal>;
|
|
97
|
+
})): DataTableBinding<TRow>;
|
|
37
98
|
//#endregion
|
|
38
99
|
//#region src/use-data-grid.d.ts
|
|
39
100
|
/** The cell being edited and the text typed so far. */
|
|
@@ -46,12 +107,15 @@ interface GridEditor {
|
|
|
46
107
|
* copy, paste, and clearing. Positions refer to the current page and the visible columns.
|
|
47
108
|
*/
|
|
48
109
|
interface DataGridBinding<TRow> {
|
|
110
|
+
readonly table: DataTableBinding<TRow>;
|
|
49
111
|
readonly selection: GridSelection | undefined;
|
|
50
112
|
readonly range: CellRange | undefined;
|
|
51
113
|
readonly editor: GridEditor | undefined;
|
|
52
114
|
readonly bounds: ComputedRef<GridBounds>;
|
|
53
115
|
/** The latest edit outcome, to show a rejected value. */
|
|
54
116
|
readonly lastResult: EditResult<TRow> | undefined;
|
|
117
|
+
/** Serializable editor metadata for an editable cell; no component resolution. */
|
|
118
|
+
editorFor(position: CellPosition): EditorSpec | undefined;
|
|
55
119
|
cellAt(position: CellPosition): {
|
|
56
120
|
row: TableRow<TRow>;
|
|
57
121
|
column: TableColumn<TRow>;
|
|
@@ -69,16 +133,27 @@ interface DataGridBinding<TRow> {
|
|
|
69
133
|
updateDraft(draft: string): void;
|
|
70
134
|
/** Write the draft through the table, then move the focus if asked. */
|
|
71
135
|
commitEdit(then?: GridDirection): EditResult<TRow> | undefined;
|
|
136
|
+
/** Submit through core validation; retain a refused/pending editor for correction. */
|
|
137
|
+
submitEdit(edit?: {
|
|
138
|
+
readonly input: string;
|
|
139
|
+
} | {
|
|
140
|
+
readonly value: unknown;
|
|
141
|
+
}, then?: GridDirection): EditResult<TRow> | undefined;
|
|
142
|
+
toggleCheckbox(): boolean;
|
|
72
143
|
cancelEdit(): void;
|
|
73
144
|
/** The selected range as tab-separated text. */
|
|
74
|
-
copy(): string;
|
|
145
|
+
copy(options?: CopyOptions): string;
|
|
75
146
|
/** Paste tab-separated text at the top-left of the selection. */
|
|
76
147
|
paste(text: string): EditResult<TRow> | undefined;
|
|
77
148
|
clear(): EditResult<TRow> | undefined;
|
|
78
149
|
/** Handle a key press. Returns `true` when the grid used it, so the caller can prevent the default. */
|
|
79
150
|
handleKey(event: GridKey): boolean;
|
|
80
151
|
}
|
|
81
|
-
|
|
152
|
+
interface DataGridOptions {
|
|
153
|
+
/** Falls back to the first visible column if the configured column is hidden. */
|
|
154
|
+
readonly treeColumn?: () => string | undefined;
|
|
155
|
+
}
|
|
156
|
+
declare function useDataGrid<TRow>(table: DataTableBinding<TRow>, gridOptions?: DataGridOptions): DataGridBinding<TRow>;
|
|
82
157
|
//#endregion
|
|
83
158
|
//#region src/injection.d.ts
|
|
84
159
|
/** Make a table available to every component below the current one. */
|
|
@@ -92,5 +167,45 @@ declare function provideDataGrid<TRow>(grid: DataGridBinding<TRow>): void;
|
|
|
92
167
|
/** Read the grid provided by an ancestor, or `undefined` outside a grid. */
|
|
93
168
|
declare function injectDataGrid<TRow = unknown>(): DataGridBinding<TRow> | undefined;
|
|
94
169
|
//#endregion
|
|
95
|
-
|
|
170
|
+
//#region src/use-virtual.d.ts
|
|
171
|
+
interface VirtualViewportOptions {
|
|
172
|
+
readonly scrollElement: MaybeRefOrGetter<HTMLElement | null | undefined>;
|
|
173
|
+
readonly overscan?: number | undefined;
|
|
174
|
+
/** Number of items rendered before mount, without overscan. Defaults to 10. */
|
|
175
|
+
readonly initialCount?: number | undefined;
|
|
176
|
+
/** Space before the items, such as a sticky header or leading row-number column. */
|
|
177
|
+
readonly scrollMargin?: MaybeRefOrGetter<number> | undefined;
|
|
178
|
+
}
|
|
179
|
+
interface UseVirtualRowsOptions<TRow> extends VirtualViewportOptions {
|
|
180
|
+
readonly estimateRowHeight?: number | ((index: number) => number) | undefined;
|
|
181
|
+
/** Connect logical grid focus to the rendered data row, skipping details. */
|
|
182
|
+
readonly grid?: DataGridBinding<TRow> | undefined;
|
|
183
|
+
}
|
|
184
|
+
interface UseVirtualColumnsOptions extends VirtualViewportOptions {
|
|
185
|
+
readonly estimateColumnWidth?: number | ((index: number) => number) | undefined;
|
|
186
|
+
}
|
|
187
|
+
interface VirtualRowItem<TRow> extends VirtualItem {
|
|
188
|
+
readonly renderItem: TableRenderItem<TRow>;
|
|
189
|
+
}
|
|
190
|
+
interface VirtualColumnItem<TRow> extends VirtualItem {
|
|
191
|
+
readonly column: TableColumn<TRow>;
|
|
192
|
+
}
|
|
193
|
+
interface VirtualBinding<TItem extends VirtualItem> extends Omit<VirtualWindow, "items"> {
|
|
194
|
+
readonly items: readonly TItem[];
|
|
195
|
+
getItem(index: number): TItem | undefined;
|
|
196
|
+
scrollToIndex(index: number, options?: {
|
|
197
|
+
readonly align?: VirtualAlign | undefined;
|
|
198
|
+
}): void;
|
|
199
|
+
scrollToKey(key: RowKey, options?: {
|
|
200
|
+
readonly align?: VirtualAlign | undefined;
|
|
201
|
+
}): void;
|
|
202
|
+
/** Pass the virtual item key explicitly; null releases its previously observed element. */
|
|
203
|
+
measureElement(element: Element | ComponentPublicInstance | null, key: RowKey): void;
|
|
204
|
+
}
|
|
205
|
+
/** Virtualize data and detail render items. scrollToKey accepts the parent data-row key. */
|
|
206
|
+
declare function useVirtualRows<TRow>(table: DataTableBinding<TRow>, options: UseVirtualRowsOptions<TRow>): VirtualBinding<VirtualRowItem<TRow>>;
|
|
207
|
+
/** Virtualize visible columns and bring the active logical column into view. */
|
|
208
|
+
declare function useVirtualColumns<TRow>(grid: DataGridBinding<TRow>, options: UseVirtualColumnsOptions): VirtualBinding<VirtualColumnItem<TRow>>;
|
|
209
|
+
//#endregion
|
|
210
|
+
export { type AnyDataTableBinding, type DataGridBinding, type DataGridOptions, type DataTableBinding, type FrameScheduler, type GridEditor, type LoadMore, type LoadMoreContext, type LoadMoreResult, type RowDraft, type RowDraftValues, type SourceBinding, type SourceContext, type SourceOptions, type TableSource, type UseDataTableOptions, type UseVirtualColumnsOptions, type UseVirtualRowsOptions, type VirtualBinding, type VirtualColumnItem, type VirtualRowItem, type VirtualViewportOptions, injectDataGrid, injectDataTable, provideDataGrid, provideDataTable, useDataGrid, useDataTable, useVirtualColumns, useVirtualRows };
|
|
96
211
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/use-data-table.ts","../src/use-data-grid.ts","../src/injection.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/row-draft.ts","../src/source.ts","../src/use-data-table.ts","../src/use-data-grid.ts","../src/injection.ts","../src/use-virtual.ts"],"mappings":";;;;KAYY,eAAe,qBACd,KAAK,SAAS,SAAS,UAAU,MAAM;UAGnC,SAAS;WACf,QAAQ;WACR,QAAQ,eAAe;WACvB,iBAAiB;WACjB;WACA;;EAET,SAAS,gBAAgB;;EAEzB,SAAS,gBAAgB;EACzB,QAAQ,QAAQ,WAAW;;EAE3B;;;;UCVe;WACN,QAAQ;;KAEP,YAAY,QACpB,cAAc,gBAAgB,YAC5B,SAAS,kBAAkB,cAAc,gBAAgB;UAC9C,wBAAwB;;WAE9B;WACA,OAAO;;UAED,eAAe;WACrB,eAAe;WACf;WACA;;KAEC,SAAS,SAAS,SAAS,oBAAoB,QAAQ,eAAe;;KAEtE,kBAAkB;UACb,cAAc;WACpB,SAAS,SA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