@1771technologies/lytenyte-pro 1.0.0-beta.1 → 1.0.0-beta.11
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/+types.d.ts +24 -7
- package/dist/cell-selection/adjust-rect-for-row-and-cell-span.d.ts +1 -1
- package/dist/cell-selection/adjust-rect-for-row-and-cell-span.js +1 -1
- package/dist/cell-selection/are-rects-equal.d.ts +1 -1
- package/dist/cell-selection/bound-selection-rect.d.ts +1 -1
- package/dist/cell-selection/cell-selection-driver.js +9 -1
- package/dist/cell-selection/deselect-rect-range.d.ts +1 -1
- package/dist/cell-selection/deselect-rect-range.js +1 -1
- package/dist/cell-selection/expand-cell-selection-down.d.ts +2 -2
- package/dist/cell-selection/expand-cell-selection-down.js +1 -1
- package/dist/cell-selection/expand-cell-selection-end.d.ts +2 -2
- package/dist/cell-selection/expand-cell-selection-end.js +1 -1
- package/dist/cell-selection/expand-cell-selection-start.d.ts +2 -2
- package/dist/cell-selection/expand-cell-selection-start.js +1 -1
- package/dist/cell-selection/expand-cell-selection-up.d.ts +2 -2
- package/dist/cell-selection/expand-cell-selection-up.js +1 -1
- package/dist/cell-selection/full-width-start-end-index.d.ts +1 -1
- package/dist/cell-selection/get-root-cell.d.ts +1 -1
- package/dist/cell-selection/get-root-cell.js +2 -2
- package/dist/cell-selection/is-bottom-rect.d.ts +1 -1
- package/dist/cell-selection/is-center-col-rect.d.ts +1 -1
- package/dist/cell-selection/is-center-rect.d.ts +1 -1
- package/dist/cell-selection/is-end-rect.d.ts +1 -1
- package/dist/cell-selection/is-overlapping-rect.d.ts +1 -1
- package/dist/cell-selection/is-start-rect.d.ts +1 -1
- package/dist/cell-selection/is-top-rect.d.ts +1 -1
- package/dist/cell-selection/is-within-selection-rect.d.ts +1 -1
- package/dist/cell-selection/split-cell-selection-rect.d.ts +1 -1
- package/dist/cell-selection/update-additive-cell-selection.d.ts +2 -2
- package/dist/cell-selection/update-additive-cell-selection.js +4 -4
- package/dist/cell-selection/use-edge-scroll.d.ts +2 -2
- package/dist/cells/cell.js +2 -1
- package/dist/column-manager/use-column-manager.d.ts +2 -2
- package/dist/column-manager/use-column-manager.js +1 -1
- package/dist/column-manager/use-columns-from-context.d.ts +2 -2
- package/dist/column-manager/use-columns-from-context.js +1 -1
- package/dist/filter-tree/filter-tree.d.ts +7 -7
- package/dist/filter-tree/filter-tree.js +8 -8
- package/dist/filter-tree/hooks/use-tree-item.d.ts +2 -2
- package/dist/filter-tree/hooks/use-tree-item.js +2 -2
- package/dist/grid-box/+types.d.ts +1 -1
- package/dist/grid-box/context.d.ts +1 -1
- package/dist/grid-box/use-aggregation-box-items.d.ts +2 -2
- package/dist/grid-box/use-column-box-items.d.ts +2 -2
- package/dist/grid-box/use-row-group-box-items.d.ts +2 -2
- package/dist/grid-provider/context.d.ts +2 -2
- package/dist/grid-provider/provider.d.ts +2 -2
- package/dist/grid-provider/provider.js +1 -1
- package/dist/grid-provider/use-grid.d.ts +2 -2
- package/dist/grid-provider/use-grid.js +1 -1
- package/dist/grid.d.ts +1 -0
- package/dist/grid.js +2 -0
- package/dist/header/resize-handler.js +1 -0
- package/dist/header/use-drag-move.d.ts +2 -2
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/row-data-source-client/built-ins/built-ins.d.ts +1 -1
- package/dist/row-data-source-client/built-ins/built-ins.js +1 -1
- package/dist/row-data-source-client/pivots/create-pivot-columns.js +2 -2
- package/dist/row-data-source-client/tree/evaluator-aggregation.d.ts +1 -1
- package/dist/row-data-source-client/tree/evaluator-group.d.ts +1 -1
- package/dist/row-data-source-client/tree/traverse.d.ts +1 -1
- package/dist/row-data-source-client/tree/traverse.js +1 -1
- package/dist/row-data-source-client/use-client-data-source-paginated.d.ts +2 -2
- package/dist/row-data-source-client/use-client-data-source-paginated.js +41 -25
- package/dist/row-data-source-client/use-client-data-source.d.ts +2 -2
- package/dist/row-data-source-client/use-client-data-source.js +43 -27
- package/dist/row-data-source-client/use-client-tree-data-source.d.ts +1 -1
- package/dist/row-data-source-client/use-client-tree-data-source.js +41 -25
- package/dist/row-data-source-server/async-tree/apply-delete-action-to-tree.js +1 -1
- package/dist/row-data-source-server/async-tree/make-async-tree.js +3 -3
- package/dist/row-data-source-server/use-server-data-source.d.ts +1 -1
- package/dist/row-data-source-server/use-server-data-source.js +8 -5
- package/dist/sort-manager/context.d.ts +3 -3
- package/dist/sort-manager/hooks/use-sort-manager.d.ts +2 -2
- package/dist/sort-manager/hooks/use-sort-manager.js +2 -2
- package/dist/sort-manager/hooks/use-sort-row-item.d.ts +1 -1
- package/dist/sort-manager/hooks/use-sort-row-item.js +1 -1
- package/dist/sort-manager/utils/sort-item-to-sort-model.d.ts +1 -1
- package/dist/sort-manager/utils/sort-model-to-sort-items.d.ts +1 -1
- package/dist/state/api/column-autosize.d.ts +1 -1
- package/dist/state/api/column-autosize.js +1 -1
- package/dist/state/api/column-move.js +1 -1
- package/dist/state/api/dialog-frame.d.ts +1 -1
- package/dist/state/api/edit-begin.d.ts +1 -1
- package/dist/state/api/edit-begin.js +1 -1
- package/dist/state/api/edit-end.d.ts +1 -1
- package/dist/state/api/edit-is-cell-active.d.ts +1 -1
- package/dist/state/api/edit-update.d.ts +1 -1
- package/dist/state/api/edit-update.js +1 -1
- package/dist/state/api/export-csv.js +1 -1
- package/dist/state/api/export-data-rect.js +1 -1
- package/dist/state/api/focus-cell.d.ts +1 -1
- package/dist/state/api/popover-frame.d.ts +2 -2
- package/dist/state/api/row-detail-rendered-height.d.ts +2 -2
- package/dist/state/helpers/empty-row-data-source.js +1 -0
- package/package.json +15 -9
|
@@ -10,7 +10,7 @@ import { sum } from "./sum.js";
|
|
|
10
10
|
* Collection of built-in array utility functions for numerical and statistical operations.
|
|
11
11
|
* Each function handles null and undefined values gracefully.
|
|
12
12
|
* @example
|
|
13
|
-
* import { builtIns } from './builtIns';
|
|
13
|
+
* import { builtIns } from './builtIns.js';
|
|
14
14
|
*
|
|
15
15
|
* const data = [1, null, 3, 2];
|
|
16
16
|
* builtIns.sum(data); // Returns 6
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createColumnPivotsFromPaths } from "./create-pivot-columns-from-paths";
|
|
2
|
-
import { createPivotTree } from "./create-pivot-tree";
|
|
1
|
+
import { createColumnPivotsFromPaths } from "./create-pivot-columns-from-paths.js";
|
|
2
|
+
import { createPivotTree } from "./create-pivot-tree.js";
|
|
3
3
|
export function createPivotColumns(model, lookup, grid, leafRows) {
|
|
4
4
|
const activeColumns = model.columns.filter((c) => lookup.has(c.field) && (c.active ?? true));
|
|
5
5
|
const activeValues = model.values.filter((c) => lookup.has(c.field) && (c.active ?? true));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AggregationItem } from "../+types";
|
|
1
|
+
import type { AggregationItem } from "../+types.js";
|
|
2
2
|
export declare function aggregationEvaluator<Data>(agg: AggregationItem<Data>[], data: Data[]): Record<string, unknown>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { GroupItem } from "../+types";
|
|
1
|
+
import type { GroupItem } from "../+types.js";
|
|
2
2
|
export declare function groupEvaluator<Data>(g: GroupItem<Data>[] | ((d: Data) => (string | null | undefined)[]), d: Data): (string | null | undefined)[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { BranchNode, Root, TreeNode } from "../+types";
|
|
1
|
+
import type { BranchNode, Root, TreeNode } from "../+types.js";
|
|
2
2
|
export declare function traverse<Data>(root: Root<Data> | BranchNode<Data>, fn: (node: TreeNode<Data>, lookupKey: string | null) => boolean | void, comparator?: (l: TreeNode<Data>, r: TreeNode<Data>) => number): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GridAtom, RowDataSourceClientPaginated } from "../+types";
|
|
2
|
-
import { type ClientRowDataSourceParams } from "../+types";
|
|
1
|
+
import type { GridAtom, RowDataSourceClientPaginated } from "../+types.js";
|
|
2
|
+
import { type ClientRowDataSourceParams } from "../+types.js";
|
|
3
3
|
interface DataAtoms<T> {
|
|
4
4
|
readonly top: GridAtom<T[]>;
|
|
5
5
|
readonly center: GridAtom<T[]>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {} from "../+types";
|
|
1
|
+
import {} from "../+types.js";
|
|
2
2
|
import { useRef } from "react";
|
|
3
3
|
import { atom, createStore } from "@1771technologies/atom";
|
|
4
|
-
import { traverse } from "./tree/traverse";
|
|
4
|
+
import { traverse } from "./tree/traverse.js";
|
|
5
5
|
import { dateComparator, makeGridAtom, numberComparator, stringComparator, } from "@1771technologies/lytenyte-shared";
|
|
6
6
|
import { clamp, equal, get } from "@1771technologies/lytenyte-js-utils";
|
|
7
|
-
import { makeClientTree } from "./tree/client-tree";
|
|
8
|
-
import { computeFilteredRows } from "./filter/compute-filtered-rows";
|
|
9
|
-
import { builtIns } from "./built-ins/built-ins";
|
|
7
|
+
import { makeClientTree } from "./tree/client-tree.js";
|
|
8
|
+
import { computeFilteredRows } from "./filter/compute-filtered-rows.js";
|
|
9
|
+
import { builtIns } from "./built-ins/built-ins.js";
|
|
10
10
|
export function makeClientDataSourcePaginated(p) {
|
|
11
11
|
const rdsStore = createStore();
|
|
12
12
|
const pageInternal = atom(0);
|
|
@@ -19,6 +19,9 @@ export function makeClientDataSourcePaginated(p) {
|
|
|
19
19
|
const data = atom(p.data);
|
|
20
20
|
const topData = atom(p.topData ?? []);
|
|
21
21
|
const bottomData = atom(p.bottomData ?? []);
|
|
22
|
+
const dataToSrc$ = atom((g) => {
|
|
23
|
+
return new Map(g(data).map((c, i) => [c, i]));
|
|
24
|
+
});
|
|
22
25
|
const cache = new Map();
|
|
23
26
|
const centerNodes = atom((g) => {
|
|
24
27
|
const nodes = [];
|
|
@@ -149,6 +152,13 @@ export function makeClientDataSourcePaginated(p) {
|
|
|
149
152
|
};
|
|
150
153
|
return comparator;
|
|
151
154
|
});
|
|
155
|
+
const idToNode = atom((g) => {
|
|
156
|
+
const map = new Map();
|
|
157
|
+
traverse(g(tree).root, (node) => {
|
|
158
|
+
map.set(node.id, node);
|
|
159
|
+
});
|
|
160
|
+
return map;
|
|
161
|
+
});
|
|
152
162
|
const initialized = atom(false);
|
|
153
163
|
const flat = atom((g) => {
|
|
154
164
|
if (!g(initialized))
|
|
@@ -299,30 +309,32 @@ export function makeClientDataSourcePaginated(p) {
|
|
|
299
309
|
};
|
|
300
310
|
const rowUpdate = (updates) => {
|
|
301
311
|
const grid = rdsStore.get(grid$);
|
|
302
|
-
const t = rdsStore.get(tree);
|
|
303
312
|
const d = rdsStore.get(data);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
313
|
+
const idMap = rdsStore.get(idToNode);
|
|
314
|
+
const dataToSrc = rdsStore.get(dataToSrc$);
|
|
315
|
+
for (const [key, next] of updates.entries()) {
|
|
316
|
+
const row = typeof key === "string" ? rowById(key) : rowByIndex(key);
|
|
317
|
+
const treeNode = typeof key === "string" ? idMap.get(key) : null;
|
|
318
|
+
if ((!row && !treeNode) || !grid) {
|
|
319
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
309
320
|
continue;
|
|
310
321
|
}
|
|
311
|
-
if (row
|
|
312
|
-
row.data =
|
|
322
|
+
if (row?.kind === "branch") {
|
|
323
|
+
row.data = next;
|
|
313
324
|
}
|
|
314
325
|
else {
|
|
315
|
-
const
|
|
326
|
+
const data = row?.kind === "leaf" ? row.data : treeNode?.data.data;
|
|
327
|
+
const source = dataToSrc.get(data);
|
|
316
328
|
if (source == null) {
|
|
317
|
-
console.error(`Failed to find the row
|
|
329
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
318
330
|
continue;
|
|
319
331
|
}
|
|
320
|
-
d[source] =
|
|
332
|
+
d[source] = next;
|
|
321
333
|
}
|
|
322
|
-
grid.state.rowDataStore.rowInvalidateIndex(rowIndex);
|
|
323
334
|
}
|
|
324
335
|
rdsStore.set(data, [...d]);
|
|
325
336
|
rdsStore.set(snapshot, (prev) => prev + 1);
|
|
337
|
+
grid.state.rowDataStore.rowClearCache();
|
|
326
338
|
};
|
|
327
339
|
const rowToIndex = (rowId) => {
|
|
328
340
|
const f = rdsStore.get(flat);
|
|
@@ -375,11 +387,10 @@ export function makeClientDataSourcePaginated(p) {
|
|
|
375
387
|
const field = grid.api.columnField(c, row);
|
|
376
388
|
return field;
|
|
377
389
|
}));
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
});
|
|
390
|
+
if (p.transformInFilterItem) {
|
|
391
|
+
return p.transformInFilterItem({ column: c, values: [...values] });
|
|
392
|
+
}
|
|
393
|
+
return [...values].map((x) => ({ id: `${x}`, label: `${x}`, value: x }));
|
|
383
394
|
},
|
|
384
395
|
rowAreAllSelected: (rowId) => {
|
|
385
396
|
const g = rdsStore.get(grid$);
|
|
@@ -436,6 +447,11 @@ export function makeClientDataSourcePaginated(p) {
|
|
|
436
447
|
const grid = rdsStore.get(grid$);
|
|
437
448
|
grid?.state.rowDataStore.rowClearCache();
|
|
438
449
|
},
|
|
450
|
+
rowSetCenterData: (d) => {
|
|
451
|
+
rdsStore.set(data, d);
|
|
452
|
+
const grid = rdsStore.get(grid$);
|
|
453
|
+
grid?.state.rowDataStore.rowClearCache();
|
|
454
|
+
},
|
|
439
455
|
rowSetTopData: (data) => {
|
|
440
456
|
rdsStore.set(topData, data);
|
|
441
457
|
const grid = rdsStore.get(grid$);
|
|
@@ -527,12 +543,12 @@ export function useClientRowDataSourcePaginated(p) {
|
|
|
527
543
|
if (p.reflectData) {
|
|
528
544
|
// Need to queue the microtask since it we cannot update state during render.
|
|
529
545
|
if (p.data !== da.center.get())
|
|
530
|
-
queueMicrotask(() =>
|
|
546
|
+
queueMicrotask(() => ds.current.rowSetCenterData(p.data));
|
|
531
547
|
if (!equal(p.topData ?? [], da.top.get())) {
|
|
532
|
-
queueMicrotask(() =>
|
|
548
|
+
queueMicrotask(() => ds.current.rowSetTopData(p.topData ?? []));
|
|
533
549
|
}
|
|
534
550
|
if (!equal(p.bottomData ?? [], da.bottom.get()))
|
|
535
|
-
queueMicrotask(() =>
|
|
551
|
+
queueMicrotask(() => ds.current.rowSetBotData(p.bottomData ?? []));
|
|
536
552
|
}
|
|
537
553
|
return ds.current;
|
|
538
554
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GridAtom, RowDataSourceClient } from "../+types";
|
|
2
|
-
import { type ClientRowDataSourceParams } from "../+types";
|
|
1
|
+
import type { GridAtom, RowDataSourceClient } from "../+types.js";
|
|
2
|
+
import { type ClientRowDataSourceParams } from "../+types.js";
|
|
3
3
|
interface DataAtoms<T> {
|
|
4
4
|
readonly top: GridAtom<T[]>;
|
|
5
5
|
readonly center: GridAtom<T[]>;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {} from "../+types";
|
|
1
|
+
import {} from "../+types.js";
|
|
2
2
|
import { useRef } from "react";
|
|
3
3
|
import { atom, createStore } from "@1771technologies/atom";
|
|
4
|
-
import { traverse } from "./tree/traverse";
|
|
4
|
+
import { traverse } from "./tree/traverse.js";
|
|
5
5
|
import { dateComparator, makeGridAtom, numberComparator, stringComparator, } from "@1771technologies/lytenyte-shared";
|
|
6
6
|
import { equal, get, itemsWithIdToMap } from "@1771technologies/lytenyte-js-utils";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { computeFilteredRows } from "./filter/compute-filtered-rows.js";
|
|
8
|
+
import { builtIns } from "./built-ins/built-ins.js";
|
|
9
|
+
import { createPivotColumns } from "./pivots/create-pivot-columns.js";
|
|
10
|
+
import { createAggModel } from "./pivots/create-agg-model.js";
|
|
11
|
+
import { makeClientTree } from "./tree/client-tree.js";
|
|
12
12
|
export function makeClientDataSource(p) {
|
|
13
13
|
const rdsStore = createStore();
|
|
14
14
|
const data = atom(p.data);
|
|
15
15
|
const topData = atom(p.topData ?? []);
|
|
16
16
|
const bottomData = atom(p.bottomData ?? []);
|
|
17
|
+
const dataToSrc$ = atom((g) => {
|
|
18
|
+
return new Map(g(data).map((c, i) => [c, i]));
|
|
19
|
+
});
|
|
17
20
|
const cache = new Map();
|
|
18
21
|
const centerNodes = atom((g) => {
|
|
19
22
|
const nodes = [];
|
|
@@ -199,6 +202,13 @@ export function makeClientDataSource(p) {
|
|
|
199
202
|
};
|
|
200
203
|
return comparator;
|
|
201
204
|
});
|
|
205
|
+
const idToNode = atom((g) => {
|
|
206
|
+
const map = new Map();
|
|
207
|
+
traverse(g(tree).root, (node) => {
|
|
208
|
+
map.set(node.id, node);
|
|
209
|
+
});
|
|
210
|
+
return map;
|
|
211
|
+
});
|
|
202
212
|
const tree = atom((g) => (g(columnPivotMode) ? g(pivotTree) : g(normalTree)));
|
|
203
213
|
const initialized = atom(false);
|
|
204
214
|
const flatPivot = atom((g) => {
|
|
@@ -429,30 +439,32 @@ export function makeClientDataSource(p) {
|
|
|
429
439
|
};
|
|
430
440
|
const rowUpdate = (updates) => {
|
|
431
441
|
const grid = rdsStore.get(grid$);
|
|
432
|
-
const t = rdsStore.get(normalTree);
|
|
433
442
|
const d = rdsStore.get(data);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
443
|
+
const idMap = rdsStore.get(idToNode);
|
|
444
|
+
const dataToSrc = rdsStore.get(dataToSrc$);
|
|
445
|
+
for (const [key, next] of updates.entries()) {
|
|
446
|
+
const row = typeof key === "string" ? rowById(key) : rowByIndex(key);
|
|
447
|
+
const treeNode = typeof key === "string" ? idMap.get(key) : null;
|
|
448
|
+
if ((!row && !treeNode) || !grid) {
|
|
449
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
439
450
|
continue;
|
|
440
451
|
}
|
|
441
|
-
if (row
|
|
442
|
-
row.data =
|
|
452
|
+
if (row?.kind === "branch") {
|
|
453
|
+
row.data = next;
|
|
443
454
|
}
|
|
444
455
|
else {
|
|
445
|
-
const
|
|
456
|
+
const data = row?.kind === "leaf" ? row.data : treeNode?.data.data;
|
|
457
|
+
const source = dataToSrc.get(data);
|
|
446
458
|
if (source == null) {
|
|
447
|
-
console.error(`Failed to find the row
|
|
459
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
448
460
|
continue;
|
|
449
461
|
}
|
|
450
|
-
d[source] =
|
|
462
|
+
d[source] = next;
|
|
451
463
|
}
|
|
452
|
-
grid.state.rowDataStore.rowInvalidateIndex(rowIndex);
|
|
453
464
|
}
|
|
454
465
|
rdsStore.set(data, [...d]);
|
|
455
466
|
rdsStore.set(snapshot, (prev) => prev + 1);
|
|
467
|
+
grid.state.rowDataStore.rowClearCache();
|
|
456
468
|
};
|
|
457
469
|
const rowToIndex = (rowId) => {
|
|
458
470
|
const f = rdsStore.get(flat);
|
|
@@ -500,11 +512,10 @@ export function makeClientDataSource(p) {
|
|
|
500
512
|
const field = grid.api.columnField(c, row);
|
|
501
513
|
return field;
|
|
502
514
|
}));
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
});
|
|
515
|
+
if (p.transformInFilterItem) {
|
|
516
|
+
return p.transformInFilterItem({ column: c, values: [...values] });
|
|
517
|
+
}
|
|
518
|
+
return [...values].map((x) => ({ id: `${x}`, label: `${x}`, value: x }));
|
|
508
519
|
},
|
|
509
520
|
rowAdd: (newRows, place = "end") => {
|
|
510
521
|
rdsStore.set(data, (prev) => {
|
|
@@ -546,6 +557,11 @@ export function makeClientDataSource(p) {
|
|
|
546
557
|
const grid = rdsStore.get(grid$);
|
|
547
558
|
grid?.state.rowDataStore.rowClearCache();
|
|
548
559
|
},
|
|
560
|
+
rowSetCenterData: (d) => {
|
|
561
|
+
rdsStore.set(data, d);
|
|
562
|
+
const grid = rdsStore.get(grid$);
|
|
563
|
+
grid?.state.rowDataStore.rowClearCache();
|
|
564
|
+
},
|
|
549
565
|
rowSetTopData: (data) => {
|
|
550
566
|
rdsStore.set(topData, data);
|
|
551
567
|
const grid = rdsStore.get(grid$);
|
|
@@ -656,12 +672,12 @@ export function useClientRowDataSource(p) {
|
|
|
656
672
|
if (p.reflectData) {
|
|
657
673
|
// Need to queue the microtask since it we cannot update state during render.
|
|
658
674
|
if (p.data !== da.center.get())
|
|
659
|
-
queueMicrotask(() =>
|
|
675
|
+
queueMicrotask(() => ds.current.rowSetCenterData(p.data));
|
|
660
676
|
if (!equal(p.topData ?? [], da.top.get())) {
|
|
661
|
-
queueMicrotask(() =>
|
|
677
|
+
queueMicrotask(() => ds.current.rowSetTopData(p.topData ?? []));
|
|
662
678
|
}
|
|
663
679
|
if (!equal(p.bottomData ?? [], da.bottom.get()))
|
|
664
|
-
queueMicrotask(() =>
|
|
680
|
+
queueMicrotask(() => ds.current.rowSetBotData(p.bottomData ?? []));
|
|
665
681
|
}
|
|
666
682
|
return ds.current;
|
|
667
683
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GridAtom, RowDataSourceClient, ClientTreeDataSourceParams } from "../+types";
|
|
1
|
+
import type { GridAtom, RowDataSourceClient, ClientTreeDataSourceParams } from "../+types.js";
|
|
2
2
|
interface DataAtoms<T> {
|
|
3
3
|
readonly top: GridAtom<T[]>;
|
|
4
4
|
readonly center: GridAtom<T[]>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {} from "../+types";
|
|
1
|
+
import {} from "../+types.js";
|
|
2
2
|
import { useRef } from "react";
|
|
3
3
|
import { atom, createStore } from "@1771technologies/atom";
|
|
4
|
-
import { traverse } from "./tree/traverse";
|
|
4
|
+
import { traverse } from "./tree/traverse.js";
|
|
5
5
|
import { dateComparator, makeGridAtom, numberComparator, stringComparator, } from "@1771technologies/lytenyte-shared";
|
|
6
6
|
import { equal } from "@1771technologies/lytenyte-js-utils";
|
|
7
|
-
import { makeClientTree } from "./tree/client-tree";
|
|
8
|
-
import { computeFilteredRows } from "./filter/compute-filtered-rows";
|
|
9
|
-
import { builtIns } from "./built-ins/built-ins";
|
|
7
|
+
import { makeClientTree } from "./tree/client-tree.js";
|
|
8
|
+
import { computeFilteredRows } from "./filter/compute-filtered-rows.js";
|
|
9
|
+
import { builtIns } from "./built-ins/built-ins.js";
|
|
10
10
|
export function makeClientTreeDataSource(p) {
|
|
11
11
|
const rdsStore = createStore();
|
|
12
12
|
const data = atom(p.data);
|
|
13
13
|
const topData = atom(p.topData ?? []);
|
|
14
14
|
const bottomData = atom(p.bottomData ?? []);
|
|
15
|
+
const dataToSrc$ = atom((g) => {
|
|
16
|
+
return new Map(g(data).map((c, i) => [c, i]));
|
|
17
|
+
});
|
|
15
18
|
const cache = new Map();
|
|
16
19
|
const centerNodes = atom((g) => {
|
|
17
20
|
const nodes = [];
|
|
@@ -130,6 +133,13 @@ export function makeClientTreeDataSource(p) {
|
|
|
130
133
|
};
|
|
131
134
|
return comparator;
|
|
132
135
|
});
|
|
136
|
+
const idToNode = atom((g) => {
|
|
137
|
+
const map = new Map();
|
|
138
|
+
traverse(g(tree).root, (node) => {
|
|
139
|
+
map.set(node.id, node);
|
|
140
|
+
});
|
|
141
|
+
return map;
|
|
142
|
+
});
|
|
133
143
|
const initialized = atom(false);
|
|
134
144
|
const flat = atom((g) => {
|
|
135
145
|
if (!g(initialized))
|
|
@@ -275,30 +285,32 @@ export function makeClientTreeDataSource(p) {
|
|
|
275
285
|
};
|
|
276
286
|
const rowUpdate = (updates) => {
|
|
277
287
|
const grid = rdsStore.get(grid$);
|
|
278
|
-
const t = rdsStore.get(tree);
|
|
279
288
|
const d = rdsStore.get(data);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
289
|
+
const idMap = rdsStore.get(idToNode);
|
|
290
|
+
const dataToSrc = rdsStore.get(dataToSrc$);
|
|
291
|
+
for (const [key, next] of updates.entries()) {
|
|
292
|
+
const row = typeof key === "string" ? rowById(key) : rowByIndex(key);
|
|
293
|
+
const treeNode = typeof key === "string" ? idMap.get(key) : null;
|
|
294
|
+
if ((!row && !treeNode) || !grid) {
|
|
295
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
285
296
|
continue;
|
|
286
297
|
}
|
|
287
|
-
if (row
|
|
288
|
-
row.data =
|
|
298
|
+
if (row?.kind === "branch") {
|
|
299
|
+
row.data = next;
|
|
289
300
|
}
|
|
290
301
|
else {
|
|
291
|
-
const
|
|
302
|
+
const data = row?.kind === "leaf" ? row.data : treeNode?.data.data;
|
|
303
|
+
const source = dataToSrc.get(data);
|
|
292
304
|
if (source == null) {
|
|
293
|
-
console.error(`Failed to find the row
|
|
305
|
+
console.error(`Failed to find the row with identifier ${key} which is being updated.`);
|
|
294
306
|
continue;
|
|
295
307
|
}
|
|
296
|
-
d[source] =
|
|
308
|
+
d[source] = next;
|
|
297
309
|
}
|
|
298
|
-
grid.state.rowDataStore.rowInvalidateIndex(rowIndex);
|
|
299
310
|
}
|
|
300
311
|
rdsStore.set(data, [...d]);
|
|
301
312
|
rdsStore.set(snapshot, (prev) => prev + 1);
|
|
313
|
+
grid.state.rowDataStore.rowClearCache();
|
|
302
314
|
};
|
|
303
315
|
const rowToIndex = (rowId) => {
|
|
304
316
|
const f = rdsStore.get(flat);
|
|
@@ -346,11 +358,10 @@ export function makeClientTreeDataSource(p) {
|
|
|
346
358
|
const field = grid.api.columnField(c, row);
|
|
347
359
|
return field;
|
|
348
360
|
}));
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
361
|
+
if (p.transformInFilterItem) {
|
|
362
|
+
return p.transformInFilterItem({ column: c, values: [...values] });
|
|
363
|
+
}
|
|
364
|
+
return [...values].map((x) => ({ id: `${x}`, label: `${x}`, value: x }));
|
|
354
365
|
},
|
|
355
366
|
rowAdd: (newRows, place = "end") => {
|
|
356
367
|
rdsStore.set(data, (prev) => {
|
|
@@ -392,6 +403,11 @@ export function makeClientTreeDataSource(p) {
|
|
|
392
403
|
const grid = rdsStore.get(grid$);
|
|
393
404
|
grid?.state.rowDataStore.rowClearCache();
|
|
394
405
|
},
|
|
406
|
+
rowSetCenterData: (d) => {
|
|
407
|
+
rdsStore.set(data, d);
|
|
408
|
+
const grid = rdsStore.get(grid$);
|
|
409
|
+
grid?.state.rowDataStore.rowClearCache();
|
|
410
|
+
},
|
|
395
411
|
rowSetTopData: (data) => {
|
|
396
412
|
rdsStore.set(topData, data);
|
|
397
413
|
const grid = rdsStore.get(grid$);
|
|
@@ -502,12 +518,12 @@ export function useClientTreeDataSource(p) {
|
|
|
502
518
|
if (p.reflectData) {
|
|
503
519
|
// Need to queue the microtask since it we cannot update state during render.
|
|
504
520
|
if (p.data !== da.center.get())
|
|
505
|
-
queueMicrotask(() =>
|
|
521
|
+
queueMicrotask(() => ds.current.rowSetCenterData(p.data));
|
|
506
522
|
if (!equal(p.topData ?? [], da.top.get())) {
|
|
507
|
-
queueMicrotask(() =>
|
|
523
|
+
queueMicrotask(() => ds.current.rowSetTopData(p.topData ?? []));
|
|
508
524
|
}
|
|
509
525
|
if (!equal(p.bottomData ?? [], da.bottom.get()))
|
|
510
|
-
queueMicrotask(() =>
|
|
526
|
+
queueMicrotask(() => ds.current.rowSetBotData(p.bottomData ?? []));
|
|
511
527
|
}
|
|
512
528
|
return ds.current;
|
|
513
529
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getParentNodeByPath } from "./get-parent-node-by-path";
|
|
1
|
+
import { getParentNodeByPath } from "./get-parent-node-by-path.js";
|
|
2
2
|
export function applyDeleteActionToTree(p, tree) {
|
|
3
3
|
// No op. We aren't deleting keys or indices
|
|
4
4
|
if (!p.relIndices?.length && !p.paths?.length)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { applyDeleteActionToTree } from "./apply-delete-action-to-tree";
|
|
2
|
-
import { applySetActionToTree } from "./apply-set-action-to-tree";
|
|
3
|
-
import { getParentNodeByPath } from "./get-parent-node-by-path";
|
|
1
|
+
import { applyDeleteActionToTree } from "./apply-delete-action-to-tree.js";
|
|
2
|
+
import { applySetActionToTree } from "./apply-set-action-to-tree.js";
|
|
3
|
+
import { getParentNodeByPath } from "./get-parent-node-by-path.js";
|
|
4
4
|
export function makeAsyncTree() {
|
|
5
5
|
const tree = {
|
|
6
6
|
kind: "root",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { RowDataSourceServer, RowDataSourceServerParams } from "../+types";
|
|
1
|
+
import type { RowDataSourceServer, RowDataSourceServerParams } from "../+types.js";
|
|
2
2
|
export declare function makeServerDataSource<T>({ dataFetcher, dataColumnPivotFetcher, dataInFilterItemFetcher, cellUpdateHandler, cellUpdateOptimistically, blockSize, }: RowDataSourceServerParams<T>): RowDataSourceServer<T>;
|
|
3
3
|
export declare function useServerDataSource<T>(p: RowDataSourceServerParams<T>): RowDataSourceServer<T>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { atom, createStore } from "@1771technologies/atom";
|
|
2
2
|
import { useRef } from "react";
|
|
3
|
-
import { makeAsyncTree } from "./async-tree/make-async-tree";
|
|
3
|
+
import { makeAsyncTree } from "./async-tree/make-async-tree.js";
|
|
4
4
|
import { makeGridAtom } from "@1771technologies/lytenyte-shared";
|
|
5
|
-
import { getNodeDepth } from "./utils/get-node-depth";
|
|
6
|
-
import { getRequestId } from "./utils/get-request-id";
|
|
7
|
-
import { RangeTree } from "./range-tree/range-tree";
|
|
8
|
-
import { getNodePath } from "./utils/get-node-path";
|
|
5
|
+
import { getNodeDepth } from "./utils/get-node-depth.js";
|
|
6
|
+
import { getRequestId } from "./utils/get-request-id.js";
|
|
7
|
+
import { RangeTree } from "./range-tree/range-tree.js";
|
|
8
|
+
import { getNodePath } from "./utils/get-node-path.js";
|
|
9
9
|
import { equal } from "@1771technologies/lytenyte-js-utils";
|
|
10
10
|
export function makeServerDataSource({ dataFetcher, dataColumnPivotFetcher, dataInFilterItemFetcher, cellUpdateHandler, cellUpdateOptimistically = true, blockSize = 200, }) {
|
|
11
11
|
let grid = null;
|
|
@@ -651,6 +651,9 @@ export function makeServerDataSource({ dataFetcher, dataColumnPivotFetcher, data
|
|
|
651
651
|
rowSelect,
|
|
652
652
|
rowSelectAll,
|
|
653
653
|
rowSetBotData,
|
|
654
|
+
rowSetCenterData: () => {
|
|
655
|
+
throw new Error("Server side data source does not support full row updates");
|
|
656
|
+
},
|
|
654
657
|
rowSetTopData,
|
|
655
658
|
rowToIndex,
|
|
656
659
|
rowUpdate,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Dispatch, type SetStateAction } from "react";
|
|
2
|
-
import type { SortItem } from "./+types";
|
|
3
|
-
import type { SortRowItem } from "./hooks/use-sort-row-item";
|
|
4
|
-
import type { Grid } from "../+types";
|
|
2
|
+
import type { SortItem } from "./+types.js";
|
|
3
|
+
import type { SortRowItem } from "./hooks/use-sort-row-item.js";
|
|
4
|
+
import type { Grid } from "../+types.js";
|
|
5
5
|
export interface SortManagerContext {
|
|
6
6
|
readonly grid: Grid<any>;
|
|
7
7
|
readonly sortItems: SortItem[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Grid } from "../../+types";
|
|
2
|
-
import type { SortItem } from "../+types";
|
|
2
|
+
import type { SortItem } from "../+types.js";
|
|
3
3
|
export interface UseSortManagerArgs<T> {
|
|
4
4
|
readonly grid: Grid<T>;
|
|
5
5
|
readonly pivotMode?: boolean;
|
|
@@ -11,5 +11,5 @@ export declare function useSortManager<T>({ grid, pivotMode }: UseSortManagerArg
|
|
|
11
11
|
mode: boolean;
|
|
12
12
|
grid: Grid<T>;
|
|
13
13
|
};
|
|
14
|
-
rows: import("./use-sort-row-item").SortRowItem[];
|
|
14
|
+
rows: import("./use-sort-row-item.js").SortRowItem[];
|
|
15
15
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { sortModelToSortItems } from "../utils/sort-model-to-sort-items";
|
|
2
|
+
import { sortModelToSortItems } from "../utils/sort-model-to-sort-items.js";
|
|
3
3
|
import { itemsWithIdToMap } from "@1771technologies/lytenyte-js-utils";
|
|
4
|
-
import { useSortRowItems } from "./use-sort-row-item";
|
|
4
|
+
import { useSortRowItems } from "./use-sort-row-item.js";
|
|
5
5
|
import { useEvent } from "@1771technologies/lytenyte-react-hooks";
|
|
6
6
|
export function useSortManager({ grid, pivotMode }) {
|
|
7
7
|
const statePivotMode = grid.state.columnPivotMode.useValue();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useSortableColumnItems } from "./use-sortable-column-items";
|
|
2
|
+
import { useSortableColumnItems } from "./use-sortable-column-items.js";
|
|
3
3
|
import { itemsWithIdToMap } from "@1771technologies/lytenyte-js-utils";
|
|
4
4
|
export function useSortRowItems(sortItems, setSortItems, grid, pivotMode) {
|
|
5
5
|
const columnItems = useSortableColumnItems(grid, pivotMode);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SortItem } from "../+types";
|
|
1
|
+
import type { SortItem } from "../+types.js";
|
|
2
2
|
import type { Column, SortModelItem } from "../../+types";
|
|
3
3
|
export declare function sortItemsToSortModel(sortItems: SortItem[], lookup: Map<string, Column<any>>): SortModelItem<any>[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { measureText } from "@1771technologies/lytenyte-shared";
|
|
2
|
-
import { resolveColumn } from "../helpers/resolve-column";
|
|
2
|
+
import { resolveColumn } from "../helpers/resolve-column.js";
|
|
3
3
|
export const makeColumnAutosize = (grid) => {
|
|
4
4
|
return (params) => {
|
|
5
5
|
const errorRef = { current: false };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { focusCell, isFullWidthMap } from "@1771technologies/lytenyte-shared";
|
|
2
2
|
import { runWithBackoff } from "@1771technologies/lytenyte-js-utils";
|
|
3
|
-
import { editOnChange } from "../helpers/edit-on-change";
|
|
3
|
+
import { editOnChange } from "../helpers/edit-on-change.js";
|
|
4
4
|
export const makeEditBegin = (grid) => {
|
|
5
5
|
return (params) => {
|
|
6
6
|
if (grid.state.editCellMode.get() === "readonly" || grid.state.columnPivotMode.get())
|