@gtkx/components 1.0.0-rc.4 → 1.1.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 +5 -5
- package/dist/column-view.d.ts +2 -2
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +14 -12
- package/dist/column-view.js.map +1 -1
- package/dist/grid-view.js +1 -1
- package/dist/grid-view.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +31 -23
- 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 +8 -11
- package/dist/internal/collection-index.d.ts.map +1 -1
- package/dist/internal/collection-index.js +53 -73
- package/dist/internal/collection-index.js.map +1 -1
- package/dist/internal/collection-model.d.ts +24 -4
- package/dist/internal/collection-model.d.ts.map +1 -1
- package/dist/internal/collection-model.js +247 -96
- package/dist/internal/collection-model.js.map +1 -1
- package/dist/internal/collection.d.ts +8 -10
- package/dist/internal/collection.d.ts.map +1 -1
- package/dist/internal/collection.js +38 -48
- 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 +73 -48
- 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 +19 -0
- package/dist/internal/tree-expansion.d.ts.map +1 -0
- package/dist/internal/tree-expansion.js +72 -0
- package/dist/internal/tree-expansion.js.map +1 -0
- package/dist/internal/tree-order.d.ts +26 -0
- package/dist/internal/tree-order.d.ts.map +1 -0
- package/dist/internal/tree-order.js +109 -0
- package/dist/internal/tree-order.js.map +1 -0
- package/dist/internal/use-collection.d.ts +1 -1
- package/dist/internal/use-collection.d.ts.map +1 -1
- package/dist/internal/use-collection.js +4 -4
- 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 +72 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -9
- package/src/column-view.tsx +28 -25
- package/src/grid-view.tsx +1 -1
- package/src/index.ts +3 -0
- package/src/internal/cells.tsx +339 -117
- package/src/internal/collection-index.ts +68 -92
- package/src/internal/collection-model.ts +327 -112
- package/src/internal/collection.ts +45 -65
- package/src/internal/controlled-sync.ts +34 -0
- package/src/internal/drop-down.tsx +41 -20
- package/src/internal/expansion.ts +95 -70
- 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 +115 -0
- package/src/internal/tree-order.ts +208 -0
- package/src/internal/use-collection.tsx +5 -5
- package/src/list-view.tsx +14 -10
- package/src/types.ts +78 -20
|
@@ -1,106 +1,86 @@
|
|
|
1
|
-
|
|
1
|
+
import { decodePartAt, encodePart } from "./keys.js";
|
|
2
|
+
const emptyLevel = () => ({ path: "", items: [], expandableFlags: [] });
|
|
2
3
|
const hasChildren = (item) => item.children !== undefined && item.children.length > 0;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
const canExpand = hasChildren(item);
|
|
9
|
-
level.expandableFlags.push(canExpand);
|
|
10
|
-
if (!canExpand) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const key = childLevelKey(item.id);
|
|
14
|
-
state.children.set(key, collectLevel(state, key, item.children ?? []));
|
|
15
|
-
}
|
|
16
|
-
function collectLevel(state, key, items) {
|
|
17
|
-
const level = { key, ids: [], expandableFlags: [] };
|
|
18
|
-
for (const item of items) {
|
|
19
|
-
level.ids.push(item.id);
|
|
20
|
-
state.itemsById.set(item.id, item);
|
|
21
|
-
collectChildren(state, level, item);
|
|
22
|
-
}
|
|
4
|
+
function newLevel(state, path, items) {
|
|
5
|
+
const expandableFlags = state.isTree ? items.map((item) => hasChildren(item)) : [];
|
|
6
|
+
const level = { path, items, expandableFlags };
|
|
7
|
+
state.levels.set(path, level);
|
|
23
8
|
return level;
|
|
24
9
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
for (const level of state.groups) {
|
|
30
|
-
starts.push(offset);
|
|
31
|
-
for (const id of level.ids) {
|
|
32
|
-
positions.set(id, offset);
|
|
33
|
-
offset += 1;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
state.positions = positions;
|
|
37
|
-
state.starts = starts;
|
|
10
|
+
function slotItems(state, parent, slot) {
|
|
11
|
+
const owner = state.levels.get(parent.path) === parent ? parent : levelFor(state, parent.path);
|
|
12
|
+
const item = owner?.items[slot];
|
|
13
|
+
return item !== undefined && hasChildren(item) ? item.children : undefined;
|
|
38
14
|
}
|
|
39
|
-
function
|
|
40
|
-
if (state.isTree) {
|
|
41
|
-
return
|
|
15
|
+
function childLevel(state, parent, slot) {
|
|
16
|
+
if (!state.isTree) {
|
|
17
|
+
return undefined;
|
|
42
18
|
}
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
const path = parent.path + encodePart(String(slot));
|
|
20
|
+
const cached = state.levels.get(path);
|
|
21
|
+
if (cached !== undefined) {
|
|
22
|
+
return cached;
|
|
45
23
|
}
|
|
46
|
-
|
|
24
|
+
const items = slotItems(state, parent, slot);
|
|
25
|
+
return items === undefined ? undefined : newLevel(state, path, items);
|
|
47
26
|
}
|
|
48
|
-
function
|
|
49
|
-
let
|
|
50
|
-
let
|
|
51
|
-
while (
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
high = middle - 1;
|
|
27
|
+
function descendPath(state, levelPath, group) {
|
|
28
|
+
let level = state.levels.get(encodePart(group));
|
|
29
|
+
let offset = encodePart(group).length;
|
|
30
|
+
while (level !== undefined && offset < levelPath.length) {
|
|
31
|
+
const part = decodePartAt(levelPath, offset);
|
|
32
|
+
if (part === null) {
|
|
33
|
+
return undefined;
|
|
58
34
|
}
|
|
35
|
+
level = childLevel(state, level, Number(part));
|
|
36
|
+
offset += encodePart(part).length;
|
|
59
37
|
}
|
|
60
|
-
return
|
|
38
|
+
return level;
|
|
61
39
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return undefined;
|
|
40
|
+
function levelFor(state, levelPath) {
|
|
41
|
+
const cached = state.levels.get(levelPath);
|
|
42
|
+
if (cached !== undefined) {
|
|
43
|
+
return cached;
|
|
67
44
|
}
|
|
68
|
-
|
|
45
|
+
const group = decodePartAt(levelPath, 0);
|
|
46
|
+
return group === null ? undefined : descendPath(state, levelPath, group);
|
|
69
47
|
}
|
|
70
48
|
function buildGroups(state, source, sections) {
|
|
71
49
|
if (sections === undefined) {
|
|
72
|
-
return [
|
|
50
|
+
return [newLevel(state, encodePart("0"), source)];
|
|
73
51
|
}
|
|
74
|
-
return sections.map((section) =>
|
|
52
|
+
return sections.map((section, group) => {
|
|
53
|
+
const path = encodePart(String(group));
|
|
54
|
+
state.sectionValues.set(path, section.value);
|
|
55
|
+
return newLevel(state, path, section.data);
|
|
56
|
+
});
|
|
75
57
|
}
|
|
76
58
|
function isTreeSource(source, sections, isFlat) {
|
|
77
|
-
if (
|
|
59
|
+
if (isFlat) {
|
|
78
60
|
return false;
|
|
79
61
|
}
|
|
80
|
-
|
|
62
|
+
if (sections === undefined) {
|
|
63
|
+
return source.some((item) => hasChildren(item));
|
|
64
|
+
}
|
|
65
|
+
return sections.some((section) => section.data.some((item) => hasChildren(item)));
|
|
81
66
|
}
|
|
82
67
|
function createCollectionIndex(items, sections, isFlat) {
|
|
83
68
|
const source = items ?? [];
|
|
84
69
|
const state = {
|
|
85
70
|
isTree: isTreeSource(source, sections, isFlat),
|
|
86
71
|
groups: [],
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
sections,
|
|
90
|
-
positions: null,
|
|
91
|
-
starts: null,
|
|
72
|
+
levels: new Map(),
|
|
73
|
+
sectionValues: new Map(),
|
|
92
74
|
};
|
|
93
75
|
state.groups = buildGroups(state, source, sections);
|
|
94
76
|
return {
|
|
95
77
|
isTree: state.isTree,
|
|
96
|
-
size: state.itemsById.size,
|
|
97
78
|
groups: state.groups,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
sectionFor: (
|
|
102
|
-
positionFor: (id) => positionFor(state, id),
|
|
79
|
+
childLevel: (level, slot) => childLevel(state, level, slot),
|
|
80
|
+
levelFor: (levelPath) => levelFor(state, levelPath),
|
|
81
|
+
itemAt: (levelPath, slot) => levelFor(state, levelPath)?.items[slot],
|
|
82
|
+
sectionFor: (levelPath) => state.sectionValues.get(levelPath),
|
|
103
83
|
};
|
|
104
84
|
}
|
|
105
|
-
export { createCollectionIndex,
|
|
85
|
+
export { createCollectionIndex, emptyLevel };
|
|
106
86
|
//# sourceMappingURL=collection-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-index.js","sourceRoot":"","sources":["../../src/internal/collection-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collection-index.js","sourceRoot":"","sources":["../../src/internal/collection-index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA0BrD,MAAM,UAAU,GAAG,GAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;AAC/E,MAAM,WAAW,GAAG,CAAC,IAAc,EAAsB,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;AAEpH,SAAS,QAAQ,CAAC,KAAiB,EAAE,IAAY,EAAE,KAAiB;IAChE,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnF,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;IACtD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAE9B,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,KAAiB,EAAE,MAAa,EAAE,IAAY;IAC7D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAEhC,OAAO,IAAI,KAAK,SAAS,IAAI,WA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N,CAAC;AAED,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAoC,CAAC","sourcesContent":["import type { ListItem, ListSection } from \"../types.js\";\nimport { decodePartAt, encodePart } from \"./keys.js\";\n\ntype Level = {\n path: string;\n items: ListItem[];\n expandableFlags: boolean[];\n};\n\ntype CollectionIndex = {\n isTree: boolean;\n groups: Level[];\n childLevel: (level: Level, slot: number) => Level | undefined;\n levelFor: (levelPath: string) => Level | undefined;\n itemAt: (levelPath: string, slot: number) => ListItem | undefined;\n sectionFor: (levelPath: string) => unknown;\n};\n\ntype IndexState = {\n isTree: boolean;\n groups: Level[];\n levels: Map<string, Level>;\n sectionValues: Map<string, unknown>;\n};\n\ntype ParentItem = ListItem & { children: ListItem[] };\n\nconst emptyLevel = (): Level => ({ path: \"\", items: [], expandableFlags: [] });\nconst hasChildren = (item: ListItem): item is ParentItem => item.children !== undefined && item.children.length > 0;\n\nfunction newLevel(state: IndexState, path: string, items: ListItem[]): Level {\n const expandableFlags = state.isTree ? items.map((item) => hasChildren(item)) : [];\n const level: Level = { path, items, expandableFlags };\n state.levels.set(path, level);\n\n return level;\n}\n\nfunction slotItems(state: IndexState, parent: Level, slot: number): ListItem[] | undefined {\n const owner = state.levels.get(parent.path) === parent ? parent : levelFor(state, parent.path);\n const item = owner?.items[slot];\n\n return item !== undefined && hasChildren(item) ? item.children : undefined;\n}\n\nfunction childLevel(state: IndexState, parent: Level, slot: number): Level | undefined {\n if (!state.isTree) {\n return undefined;\n }\n\n const path = parent.path + encodePart(String(slot));\n const cached = state.levels.get(path);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const items = slotItems(state, parent, slot);\n\n return items === undefined ? undefined : newLevel(state, path, items);\n}\n\nfunction descendPath(state: IndexState, levelPath: string, group: string): Level | undefined {\n let level = state.levels.get(encodePart(group));\n let offset = encodePart(group).length;\n\n while (level !== undefined && offset < levelPath.length) {\n const part = decodePartAt(levelPath, offset);\n\n if (part === null) {\n return undefined;\n }\n\n level = childLevel(state, level, Number(part));\n offset += encodePart(part).length;\n }\n\n return level;\n}\n\nfunction levelFor(state: IndexState, levelPath: string): Level | undefined {\n const cached = state.levels.get(levelPath);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const group = decodePartAt(levelPath, 0);\n\n return group === null ? undefined : descendPath(state, levelPath, group);\n}\n\nfunction buildGroups(state: IndexState, source: ListItem[], sections: ListSection[] | undefined): Level[] {\n if (sections === undefined) {\n return [newLevel(state, encodePart(\"0\"), source)];\n }\n\n return sections.map((section, group) => {\n const path = encodePart(String(group));\n state.sectionValues.set(path, section.value);\n\n return newLevel(state, path, section.data);\n });\n}\n\nfunction isTreeSource(source: ListItem[], sections: ListSection[] | undefined, isFlat: boolean): boolean {\n if (isFlat) {\n return false;\n }\n\n if (sections === undefined) {\n return source.some((item) => hasChildren(item));\n }\n\n return sections.some((section) => section.data.some((item) => hasChildren(item)));\n}\n\nfunction createCollectionIndex(\n items: ListItem[] | undefined,\n sections: ListSection[] | undefined,\n isFlat: boolean,\n): CollectionIndex {\n const source = items ?? [];\n\n const state: IndexState = {\n isTree: isTreeSource(source, sections, isFlat),\n groups: [],\n levels: new Map(),\n sectionValues: new Map(),\n };\n\n state.groups = buildGroups(state, source, sections);\n\n return {\n isTree: state.isTree,\n groups: state.groups,\n childLevel: (level, slot) => childLevel(state, level, slot),\n levelFor: (levelPath) => levelFor(state, levelPath),\n itemAt: (levelPath, slot) => levelFor(state, levelPath)?.items[slot],\n sectionFor: (levelPath) => state.sectionValues.get(levelPath),\n };\n}\n\nexport { createCollectionIndex, emptyLevel, type CollectionIndex, type Level };\n"]}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
import * as Gio from "@gtkx/gi/gio";
|
|
1
2
|
import * as GObject from "@gtkx/gi/gobject";
|
|
2
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
-
import type { CollectionIndex } from "./collection-index.js";
|
|
4
|
+
import type { CollectionIndex, Level } from "./collection-index.js";
|
|
5
|
+
import type { TreeExpansion } from "./tree-expansion.js";
|
|
6
|
+
type LevelStore = Gio.ListModel & LazyLevelStore;
|
|
7
|
+
type SlotRef = {
|
|
8
|
+
store: LevelStore;
|
|
9
|
+
slot: number;
|
|
10
|
+
};
|
|
4
11
|
type CollectionModel = {
|
|
5
12
|
model: Gtk.FlattenListModel;
|
|
6
|
-
|
|
13
|
+
expansion: TreeExpansion;
|
|
14
|
+
rowAt: (position: number) => Gtk.TreeListRow | null;
|
|
7
15
|
sync: (index: CollectionIndex) => void;
|
|
8
16
|
};
|
|
9
|
-
declare function
|
|
17
|
+
declare function slotRefFor(value: GObject.Object | null): SlotRef | null;
|
|
18
|
+
declare function slotPathAt(store: LevelStore, slot: number): string;
|
|
10
19
|
declare function createCollectionModel(): CollectionModel;
|
|
11
|
-
|
|
20
|
+
declare class LazyLevelStore extends GObject.Object implements Gio.ListModelImpl {
|
|
21
|
+
itemsChanged: Gio.ListModel["itemsChanged"];
|
|
22
|
+
level: Level;
|
|
23
|
+
refs: SlotRef[];
|
|
24
|
+
objects: (Gtk.StringObject | null)[];
|
|
25
|
+
childStores: (LevelStore | null)[];
|
|
26
|
+
private createItem;
|
|
27
|
+
vfuncGetItemType(): bigint;
|
|
28
|
+
vfuncGetNItems(): number;
|
|
29
|
+
vfuncGetItem(position: number): GObject.Object | null;
|
|
30
|
+
}
|
|
31
|
+
export { createCollectionModel, slotPathAt, slotRefFor, type CollectionModel, type SlotRef };
|
|
12
32
|
//# sourceMappingURL=collection-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-model.d.ts","sourceRoot":"","sources":["../../src/internal/collection-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collection-model.d.ts","sourceRoot":"","sources":["../../src/internal/collection-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM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