@gtkx/components 1.0.0-rc.3 → 1.0.0
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/README.md +8 -9
- package/dist/adw/combo-row.d.ts +1 -0
- package/dist/adw/combo-row.d.ts.map +1 -1
- package/dist/adw/combo-row.js.map +1 -1
- package/dist/adw/types.d.ts +2 -1
- package/dist/adw/types.d.ts.map +1 -1
- package/dist/adw/types.js.map +1 -1
- package/dist/column-view.d.ts +2 -2
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +15 -13
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +1 -0
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js.map +1 -1
- package/dist/grid-view.js +2 -2
- package/dist/grid-view.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +32 -24
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js +168 -77
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/collection-index.d.ts +9 -13
- package/dist/internal/collection-index.d.ts.map +1 -1
- package/dist/internal/collection-index.js +33 -70
- package/dist/internal/collection-index.js.map +1 -1
- package/dist/internal/collection-model.d.ts +23 -2
- package/dist/internal/collection-model.d.ts.map +1 -1
- package/dist/internal/collection-model.js +210 -98
- package/dist/internal/collection-model.js.map +1 -1
- package/dist/internal/collection.d.ts +9 -12
- package/dist/internal/collection.d.ts.map +1 -1
- package/dist/internal/collection.js +38 -49
- package/dist/internal/collection.js.map +1 -1
- package/dist/internal/controlled-sync.d.ts +11 -0
- package/dist/internal/controlled-sync.d.ts.map +1 -0
- package/dist/internal/controlled-sync.js +19 -0
- package/dist/internal/controlled-sync.js.map +1 -0
- package/dist/internal/drop-down.d.ts.map +1 -1
- package/dist/internal/drop-down.js +27 -15
- package/dist/internal/drop-down.js.map +1 -1
- package/dist/internal/expansion.d.ts +3 -2
- package/dist/internal/expansion.d.ts.map +1 -1
- package/dist/internal/expansion.js +80 -47
- package/dist/internal/expansion.js.map +1 -1
- package/dist/internal/keys.d.ts +5 -0
- package/dist/internal/keys.d.ts.map +1 -0
- package/dist/internal/keys.js +13 -0
- package/dist/internal/keys.js.map +1 -0
- package/dist/internal/selection.d.ts +3 -2
- package/dist/internal/selection.d.ts.map +1 -1
- package/dist/internal/selection.js +68 -35
- package/dist/internal/selection.js.map +1 -1
- package/dist/internal/slots.d.ts +10 -0
- package/dist/internal/slots.d.ts.map +1 -0
- package/dist/internal/slots.js +43 -0
- package/dist/internal/slots.js.map +1 -0
- package/dist/internal/tree-expansion.d.ts +20 -0
- package/dist/internal/tree-expansion.d.ts.map +1 -0
- package/dist/internal/tree-expansion.js +68 -0
- package/dist/internal/tree-expansion.js.map +1 -0
- package/dist/internal/tree-order.d.ts +27 -0
- package/dist/internal/tree-order.d.ts.map +1 -0
- package/dist/internal/tree-order.js +71 -0
- package/dist/internal/tree-order.js.map +1 -0
- package/dist/internal/use-collection.d.ts +5 -5
- package/dist/internal/use-collection.d.ts.map +1 -1
- package/dist/internal/use-collection.js +6 -6
- package/dist/internal/use-collection.js.map +1 -1
- package/dist/list-view.d.ts.map +1 -1
- package/dist/list-view.js +6 -6
- package/dist/list-view.js.map +1 -1
- package/dist/types.d.ts +127 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -7
- package/src/adw/combo-row.tsx +1 -0
- package/src/adw/types.ts +2 -1
- package/src/column-view.tsx +38 -35
- package/src/drop-down.tsx +1 -0
- package/src/grid-view.tsx +2 -2
- package/src/index.ts +10 -11
- package/src/internal/cells.tsx +345 -123
- package/src/internal/collection-index.ts +51 -99
- package/src/internal/collection-model.ts +259 -110
- package/src/internal/collection.ts +46 -68
- package/src/internal/controlled-sync.ts +34 -0
- package/src/internal/drop-down.tsx +44 -23
- package/src/internal/expansion.ts +104 -67
- package/src/internal/keys.ts +18 -0
- package/src/internal/selection.tsx +100 -51
- package/src/internal/slots.ts +67 -0
- package/src/internal/tree-expansion.ts +110 -0
- package/src/internal/tree-order.ts +138 -0
- package/src/internal/use-collection.tsx +11 -11
- package/src/list-view.tsx +14 -10
- package/src/types.ts +140 -65
- package/dist/size-group.d.ts +0 -12
- package/dist/size-group.d.ts.map +0 -1
- package/dist/size-group.js +0 -41
- package/dist/size-group.js.map +0 -1
- package/src/size-group.tsx +0 -77
|
@@ -1,132 +1,87 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ListItem, ListSection } from "../types.js";
|
|
2
|
+
import { encodePart } from "./keys.js";
|
|
2
3
|
|
|
3
4
|
type Level = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
path: string;
|
|
6
|
+
items: ListItem[];
|
|
7
|
+
expandableFlags: boolean[];
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
type CollectionIndex = {
|
|
10
11
|
isTree: boolean;
|
|
11
|
-
size: number;
|
|
12
12
|
groups: Level[];
|
|
13
13
|
children: Map<string, Level>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
positionFor: (id: string) => number;
|
|
14
|
+
itemAt: (levelPath: string, slot: number) => ListItem | undefined;
|
|
15
|
+
sectionFor: (levelPath: string) => unknown;
|
|
16
|
+
expandablePathsFor: (id: string) => string[];
|
|
18
17
|
};
|
|
19
18
|
|
|
20
19
|
type IndexState = {
|
|
21
20
|
isTree: boolean;
|
|
22
21
|
groups: Level[];
|
|
23
22
|
children: Map<string, Level>;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
starts: number[] | null;
|
|
23
|
+
levels: Map<string, Level>;
|
|
24
|
+
expandablePaths: Map<string, string[]>;
|
|
25
|
+
sectionValues: Map<string, unknown>;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
const
|
|
28
|
+
const NO_PATHS: string[] = [];
|
|
31
29
|
|
|
32
|
-
const hasChildren = (item:
|
|
33
|
-
const childLevelKey = (id: string): string => `child:${id}`;
|
|
30
|
+
const hasChildren = (item: ListItem): boolean => item.children !== undefined && item.children.length > 0;
|
|
34
31
|
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
32
|
+
function pushPath(table: Map<string, string[]>, id: string, path: string): void {
|
|
33
|
+
const existing = table.get(id);
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
if (existing === undefined) {
|
|
36
|
+
table.set(id, [path]);
|
|
42
37
|
|
|
43
|
-
if (!canExpand) {
|
|
44
38
|
return;
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
state.children.set(key, collectLevel(state, key, item.children ?? []));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function collectLevel(state: IndexState, key: string, items: Item[]): Level {
|
|
52
|
-
const level: Level = { key, ids: [], isExpandable: [] };
|
|
53
|
-
|
|
54
|
-
for (const item of items) {
|
|
55
|
-
level.ids.push(item.id);
|
|
56
|
-
state.itemsById.set(item.id, item);
|
|
57
|
-
collectChildren(state, level, item);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return level;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function buildPositions(state: IndexState): void {
|
|
64
|
-
const positions: Map<string, number> = new Map();
|
|
65
|
-
const starts: number[] = [];
|
|
66
|
-
let offset = 0;
|
|
67
|
-
|
|
68
|
-
for (const level of state.groups) {
|
|
69
|
-
starts.push(offset);
|
|
70
|
-
|
|
71
|
-
for (const id of level.ids) {
|
|
72
|
-
positions.set(id, offset);
|
|
73
|
-
offset += 1;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
state.positions = positions;
|
|
78
|
-
state.starts = starts;
|
|
41
|
+
existing.push(path);
|
|
79
42
|
}
|
|
80
43
|
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
44
|
+
function collectChildren(state: IndexState, level: Level, slotPath: string, item: ListItem): void {
|
|
45
|
+
const canExpand = hasChildren(item);
|
|
46
|
+
level.expandableFlags.push(canExpand);
|
|
85
47
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
48
|
+
if (!canExpand) {
|
|
49
|
+
return;
|
|
88
50
|
}
|
|
89
51
|
|
|
90
|
-
|
|
52
|
+
pushPath(state.expandablePaths, item.id, slotPath);
|
|
53
|
+
state.children.set(slotPath, collectLevel(state, slotPath, item.children ?? []));
|
|
91
54
|
}
|
|
92
55
|
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
56
|
+
function collectLevel(state: IndexState, path: string, items: ListItem[]): Level {
|
|
57
|
+
const level: Level = { path, items, expandableFlags: [] };
|
|
58
|
+
state.levels.set(path, level);
|
|
96
59
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if ((starts[middle] ?? 0) <= position) {
|
|
101
|
-
low = middle;
|
|
102
|
-
} else {
|
|
103
|
-
high = middle - 1;
|
|
104
|
-
}
|
|
60
|
+
if (!state.isTree) {
|
|
61
|
+
return level;
|
|
105
62
|
}
|
|
106
63
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
function sectionFor(state: IndexState, id: string): unknown {
|
|
111
|
-
const sections = state.sections;
|
|
112
|
-
const position = positionFor(state, id);
|
|
113
|
-
|
|
114
|
-
if (sections === undefined || position < 0 || state.starts === null) {
|
|
115
|
-
return undefined;
|
|
64
|
+
for (const [slot, item] of items.entries()) {
|
|
65
|
+
collectChildren(state, level, path + encodePart(String(slot)), item);
|
|
116
66
|
}
|
|
117
67
|
|
|
118
|
-
return
|
|
68
|
+
return level;
|
|
119
69
|
}
|
|
120
70
|
|
|
121
|
-
function buildGroups(state: IndexState, source:
|
|
71
|
+
function buildGroups(state: IndexState, source: ListItem[], sections: ListSection[] | undefined): Level[] {
|
|
122
72
|
if (sections === undefined) {
|
|
123
|
-
return [collectLevel(state,
|
|
73
|
+
return [collectLevel(state, encodePart("0"), source)];
|
|
124
74
|
}
|
|
125
75
|
|
|
126
|
-
return sections.map((section) =>
|
|
76
|
+
return sections.map((section, group) => {
|
|
77
|
+
const path = encodePart(String(group));
|
|
78
|
+
state.sectionValues.set(path, section.value);
|
|
79
|
+
|
|
80
|
+
return collectLevel(state, path, section.data);
|
|
81
|
+
});
|
|
127
82
|
}
|
|
128
83
|
|
|
129
|
-
function isTreeSource(source:
|
|
84
|
+
function isTreeSource(source: ListItem[], sections: ListSection[] | undefined, isFlat: boolean): boolean {
|
|
130
85
|
if (sections !== undefined || isFlat) {
|
|
131
86
|
return false;
|
|
132
87
|
}
|
|
@@ -135,8 +90,8 @@ function isTreeSource(source: Item[], sections: Section[] | undefined, isFlat: b
|
|
|
135
90
|
}
|
|
136
91
|
|
|
137
92
|
function createCollectionIndex(
|
|
138
|
-
items:
|
|
139
|
-
sections:
|
|
93
|
+
items: ListItem[] | undefined,
|
|
94
|
+
sections: ListSection[] | undefined,
|
|
140
95
|
isFlat: boolean,
|
|
141
96
|
): CollectionIndex {
|
|
142
97
|
const source = items ?? [];
|
|
@@ -145,24 +100,21 @@ function createCollectionIndex(
|
|
|
145
100
|
isTree: isTreeSource(source, sections, isFlat),
|
|
146
101
|
groups: [],
|
|
147
102
|
children: new Map(),
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
starts: null,
|
|
103
|
+
levels: new Map(),
|
|
104
|
+
expandablePaths: new Map(),
|
|
105
|
+
sectionValues: new Map(),
|
|
152
106
|
};
|
|
153
107
|
|
|
154
108
|
state.groups = buildGroups(state, source, sections);
|
|
155
109
|
|
|
156
110
|
return {
|
|
157
111
|
isTree: state.isTree,
|
|
158
|
-
size: state.itemsById.size,
|
|
159
112
|
groups: state.groups,
|
|
160
113
|
children: state.children,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
positionFor: (id) => positionFor(state, id),
|
|
114
|
+
itemAt: (levelPath, slot) => state.levels.get(levelPath)?.items[slot],
|
|
115
|
+
sectionFor: (levelPath) => state.sectionValues.get(levelPath),
|
|
116
|
+
expandablePathsFor: (id) => state.expandablePaths.get(id) ?? NO_PATHS,
|
|
165
117
|
};
|
|
166
118
|
}
|
|
167
119
|
|
|
168
|
-
export { createCollectionIndex,
|
|
120
|
+
export { createCollectionIndex, type CollectionIndex, type Level };
|