@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.
Files changed (86) hide show
  1. package/README.md +5 -5
  2. package/dist/column-view.d.ts +2 -2
  3. package/dist/column-view.d.ts.map +1 -1
  4. package/dist/column-view.js +14 -12
  5. package/dist/column-view.js.map +1 -1
  6. package/dist/grid-view.js +1 -1
  7. package/dist/grid-view.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/cells.d.ts +31 -23
  12. package/dist/internal/cells.d.ts.map +1 -1
  13. package/dist/internal/cells.js +168 -77
  14. package/dist/internal/cells.js.map +1 -1
  15. package/dist/internal/collection-index.d.ts +8 -11
  16. package/dist/internal/collection-index.d.ts.map +1 -1
  17. package/dist/internal/collection-index.js +53 -73
  18. package/dist/internal/collection-index.js.map +1 -1
  19. package/dist/internal/collection-model.d.ts +24 -4
  20. package/dist/internal/collection-model.d.ts.map +1 -1
  21. package/dist/internal/collection-model.js +247 -96
  22. package/dist/internal/collection-model.js.map +1 -1
  23. package/dist/internal/collection.d.ts +8 -10
  24. package/dist/internal/collection.d.ts.map +1 -1
  25. package/dist/internal/collection.js +38 -48
  26. package/dist/internal/collection.js.map +1 -1
  27. package/dist/internal/controlled-sync.d.ts +11 -0
  28. package/dist/internal/controlled-sync.d.ts.map +1 -0
  29. package/dist/internal/controlled-sync.js +19 -0
  30. package/dist/internal/controlled-sync.js.map +1 -0
  31. package/dist/internal/drop-down.d.ts.map +1 -1
  32. package/dist/internal/drop-down.js +27 -15
  33. package/dist/internal/drop-down.js.map +1 -1
  34. package/dist/internal/expansion.d.ts +3 -2
  35. package/dist/internal/expansion.d.ts.map +1 -1
  36. package/dist/internal/expansion.js +73 -48
  37. package/dist/internal/expansion.js.map +1 -1
  38. package/dist/internal/keys.d.ts +5 -0
  39. package/dist/internal/keys.d.ts.map +1 -0
  40. package/dist/internal/keys.js +13 -0
  41. package/dist/internal/keys.js.map +1 -0
  42. package/dist/internal/selection.d.ts +3 -2
  43. package/dist/internal/selection.d.ts.map +1 -1
  44. package/dist/internal/selection.js +68 -35
  45. package/dist/internal/selection.js.map +1 -1
  46. package/dist/internal/slots.d.ts +10 -0
  47. package/dist/internal/slots.d.ts.map +1 -0
  48. package/dist/internal/slots.js +43 -0
  49. package/dist/internal/slots.js.map +1 -0
  50. package/dist/internal/tree-expansion.d.ts +19 -0
  51. package/dist/internal/tree-expansion.d.ts.map +1 -0
  52. package/dist/internal/tree-expansion.js +72 -0
  53. package/dist/internal/tree-expansion.js.map +1 -0
  54. package/dist/internal/tree-order.d.ts +26 -0
  55. package/dist/internal/tree-order.d.ts.map +1 -0
  56. package/dist/internal/tree-order.js +109 -0
  57. package/dist/internal/tree-order.js.map +1 -0
  58. package/dist/internal/use-collection.d.ts +1 -1
  59. package/dist/internal/use-collection.d.ts.map +1 -1
  60. package/dist/internal/use-collection.js +4 -4
  61. package/dist/internal/use-collection.js.map +1 -1
  62. package/dist/list-view.d.ts.map +1 -1
  63. package/dist/list-view.js +6 -6
  64. package/dist/list-view.js.map +1 -1
  65. package/dist/types.d.ts +72 -22
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js.map +1 -1
  68. package/package.json +17 -9
  69. package/src/column-view.tsx +28 -25
  70. package/src/grid-view.tsx +1 -1
  71. package/src/index.ts +3 -0
  72. package/src/internal/cells.tsx +339 -117
  73. package/src/internal/collection-index.ts +68 -92
  74. package/src/internal/collection-model.ts +327 -112
  75. package/src/internal/collection.ts +45 -65
  76. package/src/internal/controlled-sync.ts +34 -0
  77. package/src/internal/drop-down.tsx +41 -20
  78. package/src/internal/expansion.ts +95 -70
  79. package/src/internal/keys.ts +18 -0
  80. package/src/internal/selection.tsx +100 -51
  81. package/src/internal/slots.ts +67 -0
  82. package/src/internal/tree-expansion.ts +115 -0
  83. package/src/internal/tree-order.ts +208 -0
  84. package/src/internal/use-collection.tsx +5 -5
  85. package/src/list-view.tsx +14 -10
  86. package/src/types.ts +78 -20
@@ -1,109 +1,224 @@
1
1
  import * as Gio from "@gtkx/gi/gio";
2
2
  import * as GObject from "@gtkx/gi/gobject";
3
3
  import * as Gtk from "@gtkx/gi/gtk";
4
- import { childLevelKey, ROOT_LEVEL_KEY } from "./collection-index.js";
5
- const OBJECT_CACHE_MAX = 1 << 20;
6
- const newStore = () => new Gio.ListStore({ itemType: GObject.TYPE_OBJECT });
7
- function getId(value) {
8
- const item = value instanceof Gtk.TreeListRow ? value.getItem() : value;
9
- return item instanceof Gtk.StringObject ? item.getString() : null;
10
- }
11
- function objectFor(state, id) {
12
- const existing = state.objects.get(id);
13
- if (existing !== undefined) {
14
- return existing;
4
+ import { registerClass } from "@gtkx/runtime";
5
+ import { createCollectionIndex, emptyLevel } from "./collection-index.js";
6
+ import { encodePart } from "./keys.js";
7
+ import { adoptIndex, createTreeExpansion, pruneSlots } from "./tree-expansion.js";
8
+ const STORE_CLASS_KEY = Symbol.for("gtkx.components.lazy-level-store");
9
+ const SLOTS_KEY = Symbol.for("gtkx.components.lazy-level-store.slots");
10
+ const EMPTY_INDEX = createCollectionIndex(undefined, undefined, true);
11
+ const SLOTS = sharedSlots();
12
+ const newRootStore = () => new Gio.ListStore({ itemType: GObject.TYPE_OBJECT });
13
+ function sharedSlots() {
14
+ const cached = Reflect.get(globalThis, SLOTS_KEY);
15
+ if (cached instanceof WeakMap) {
16
+ return cached;
15
17
  }
16
- const created = Gtk.StringObject.new(id);
17
- state.objects.set(id, created);
18
+ const created = new WeakMap();
19
+ Reflect.set(globalThis, SLOTS_KEY, created);
18
20
  return created;
19
21
  }
20
- function commonPrefix(previous, next, max) {
21
- let count = 0;
22
- while (count < max && previous[count] === next[count]) {
23
- count += 1;
24
- }
25
- return count;
26
- }
27
- function commonSuffix(previous, next, max) {
28
- let count = 0;
29
- while (count < max && previous[previous.length - 1 - count] === next[next.length - 1 - count]) {
30
- count += 1;
22
+ function registeredStoreClass() {
23
+ const cached = Reflect.get(globalThis, STORE_CLASS_KEY);
24
+ if (typeof cached === "function") {
25
+ return cached;
31
26
  }
32
- return count;
27
+ registerClass(LazyLevelStore, { typeName: "GtkxLazyLevelStore", implements: [Gio.ListModel] });
28
+ Reflect.set(globalThis, STORE_CLASS_KEY, LazyLevelStore);
29
+ return LazyLevelStore;
33
30
  }
34
- function spliceRange(previous, next) {
35
- const shared = Math.min(previous.length, next.length);
36
- const start = commonPrefix(previous, next, shared);
37
- if (start === previous.length && start === next.length) {
31
+ function slotRefFor(value) {
32
+ const item = value instanceof Gtk.TreeListRow ? value.getItem() : value;
33
+ if (item === null) {
38
34
  return null;
39
35
  }
40
- const tail = commonSuffix(previous, next, shared - start);
41
- return { start, removed: previous.length - start - tail, added: next.slice(start, next.length - tail) };
36
+ const ref = SLOTS.get(item);
37
+ return ref === undefined || ref.slot === -1 ? null : ref;
42
38
  }
43
- function levelFor(state, key) {
44
- const existing = state.levels.get(key);
45
- if (existing !== undefined) {
46
- return existing;
39
+ function slotPathAt(store, slot) {
40
+ return store.level.path + encodePart(String(slot));
41
+ }
42
+ function growStore(store) {
43
+ for (let slot = store.refs.length; slot < store.level.items.length; slot++) {
44
+ store.refs.push({ store, slot });
45
+ store.objects.push(null);
46
+ store.childStores.push(null);
47
47
  }
48
- const created = { store: newStore(), ids: [], canExpand: new Map() };
49
- state.levels.set(key, created);
50
- return created;
51
48
  }
52
- function refreshExpandable(current, level) {
53
- const next = new Map();
54
- for (const [index, id] of level.ids.entries()) {
55
- const isWanted = level.expandableFlags[index] ?? false;
56
- const previous = current.canExpand.get(id);
57
- next.set(id, isWanted);
58
- if (previous !== undefined && previous !== isWanted) {
59
- current.store.itemsChanged(index, 1, 1);
49
+ function newLevelStore(level) {
50
+ const store = new (registeredStoreClass())();
51
+ store.level = level;
52
+ growStore(store);
53
+ return store;
54
+ }
55
+ function collectFlips(previous, next, overlap) {
56
+ const flipped = new Set();
57
+ for (let slot = 0; slot < overlap; slot++) {
58
+ if ((previous.expandableFlags[slot] ?? false) !== (next.expandableFlags[slot] ?? false)) {
59
+ flipped.add(slot);
60
60
  }
61
61
  }
62
- current.canExpand = next;
62
+ return flipped;
63
63
  }
64
- function didSpliceLevel(state, level) {
65
- const current = levelFor(state, level.key);
66
- const range = spliceRange(current.ids, level.ids);
67
- if (range === null) {
68
- return false;
64
+ function pruneFlips(context, store, flipped) {
65
+ if (flipped.size === 0) {
66
+ return;
67
+ }
68
+ pruneSlots(context.expansion, store.level.path, (slot) => flipped.has(slot));
69
+ for (const slot of flipped) {
70
+ store.childStores[slot] = null;
69
71
  }
70
- current.store.splice(range.start, range.removed, range.added.map((id) => objectFor(state, id)));
71
- current.ids = [...level.ids];
72
- return true;
73
72
  }
74
- function dropUnvisited(state, visited) {
75
- for (const key of state.levels.keys()) {
76
- if (!visited.has(key)) {
77
- state.levels.delete(key);
73
+ function detachRefs(store, nextLength) {
74
+ for (let slot = nextLength; slot < store.refs.length; slot++) {
75
+ const ref = store.refs[slot];
76
+ if (ref !== undefined) {
77
+ ref.slot = -1;
78
78
  }
79
79
  }
80
80
  }
81
- function pruneObjects(state, index) {
82
- if (state.objects.size <= OBJECT_CACHE_MAX) {
81
+ function shrinkStore(context, store, nextLength) {
82
+ if (store.refs.length <= nextLength) {
83
+ return;
84
+ }
85
+ detachRefs(store, nextLength);
86
+ pruneSlots(context.expansion, store.level.path, (slot) => slot >= nextLength);
87
+ store.refs.length = nextLength;
88
+ store.objects.length = nextLength;
89
+ store.childStores.length = nextLength;
90
+ }
91
+ function emitTailSplice(store, previousLength, nextLength) {
92
+ if (nextLength < previousLength) {
93
+ store.itemsChanged(nextLength, previousLength - nextLength, 0);
83
94
  return;
84
95
  }
85
- for (const id of state.objects.keys()) {
86
- if (!index.hasId(id)) {
87
- state.objects.delete(id);
96
+ if (nextLength > previousLength) {
97
+ store.itemsChanged(previousLength, 0, nextLength - previousLength);
98
+ }
99
+ }
100
+ function extendRuns(runs, slot) {
101
+ const last = runs.at(-1);
102
+ if (last !== undefined && last.start + last.length === slot) {
103
+ last.length += 1;
104
+ return;
105
+ }
106
+ runs.push({ start: slot, length: 1 });
107
+ }
108
+ function collectFlipRuns(flipped) {
109
+ const runs = [];
110
+ for (const slot of flipped) {
111
+ extendRuns(runs, slot);
112
+ }
113
+ return runs;
114
+ }
115
+ function emitFlips(store, flipped) {
116
+ for (const run of collectFlipRuns(flipped)) {
117
+ store.itemsChanged(run.start, run.length, run.length);
118
+ }
119
+ }
120
+ function childSync(context, store, slot, flipped) {
121
+ const child = store.childStores[slot] ?? null;
122
+ if (child === null || flipped.has(slot)) {
123
+ return undefined;
124
+ }
125
+ const level = context.index.childLevel(store.level, slot);
126
+ return level === undefined ? undefined : { store: child, level };
127
+ }
128
+ function childSyncs(context, store, overlap, flipped) {
129
+ const syncs = [];
130
+ for (let slot = 0; slot < overlap; slot++) {
131
+ const sync = childSync(context, store, slot, flipped);
132
+ if (sync !== undefined) {
133
+ syncs.push(sync);
88
134
  }
89
135
  }
136
+ return syncs;
137
+ }
138
+ function syncEntry(context, entry) {
139
+ const { store, level } = entry;
140
+ const previousLength = store.refs.length;
141
+ const overlap = Math.min(previousLength, level.items.length);
142
+ const flipped = collectFlips(store.level, level, overlap);
143
+ store.level = level;
144
+ pruneFlips(context, store, flipped);
145
+ shrinkStore(context, store, level.items.length);
146
+ growStore(store);
147
+ emitTailSplice(store, previousLength, level.items.length);
148
+ emitFlips(store, flipped);
149
+ return childSyncs(context, store, overlap, flipped);
150
+ }
151
+ function pushSyncs(pending, syncs) {
152
+ for (const sync of syncs) {
153
+ pending.push(sync);
154
+ }
155
+ }
156
+ function syncLevel(context, store, level) {
157
+ const pending = [{ store, level }];
158
+ while (pending.length > 0) {
159
+ const entry = pending.pop();
160
+ if (entry !== undefined) {
161
+ pushSyncs(pending, syncEntry(context, entry).toReversed());
162
+ }
163
+ }
164
+ }
165
+ function ensureChildStore(index, store, slot) {
166
+ const existing = store.childStores[slot] ?? null;
167
+ if (existing !== null || !(store.level.expandableFlags[slot] ?? false)) {
168
+ return existing;
169
+ }
170
+ const level = index.childLevel(store.level, slot);
171
+ if (level === undefined) {
172
+ return null;
173
+ }
174
+ const created = newLevelStore(level);
175
+ store.childStores[slot] = created;
176
+ return created;
90
177
  }
91
178
  function childStoreFor(state, object) {
92
- const id = getId(object);
93
- if (id === null) {
179
+ const ref = slotRefFor(object);
180
+ if (ref === null) {
94
181
  return null;
95
182
  }
96
- return state.levels.get(childLevelKey(id))?.store ?? null;
183
+ return ensureChildStore(state.index, ref.store, ref.slot);
184
+ }
185
+ function treeFor(state, store) {
186
+ return (state.trees.get(store) ?? Gtk.TreeListModel.new(store, false, false, (object) => childStoreFor(state, object)));
187
+ }
188
+ function nextTrees(state, index) {
189
+ if (!index.isTree) {
190
+ return new Map();
191
+ }
192
+ return new Map(state.groupStores.map((store) => [store, treeFor(state, store)]));
193
+ }
194
+ function pruneRebuiltLevels(state, next) {
195
+ const stores = new Set([...state.trees.keys(), ...next.keys()]);
196
+ for (const store of stores) {
197
+ if (state.trees.get(store) !== next.get(store)) {
198
+ pruneSlots(state.expansion, store.level.path, () => true);
199
+ }
200
+ }
97
201
  }
98
- function ensureTree(state) {
99
- state.tree ??= Gtk.TreeListModel.new(levelFor(state, ROOT_LEVEL_KEY).store, false, false, (object) => childStoreFor(state, object));
100
- return state.tree;
202
+ function adoptTrees(state, index) {
203
+ const next = nextTrees(state, index);
204
+ pruneRebuiltLevels(state, next);
205
+ state.trees = next;
206
+ state.treeModels = next.values().toArray();
101
207
  }
102
208
  function desiredRootModels(state, index) {
103
- if (index.isTree) {
104
- return [ensureTree(state)];
209
+ adoptTrees(state, index);
210
+ return index.isTree ? [...state.treeModels] : [...state.groupStores];
211
+ }
212
+ function rowAt(state, position) {
213
+ let offset = position;
214
+ for (const tree of state.treeModels) {
215
+ const count = tree.getNItems();
216
+ if (offset < count) {
217
+ return tree.getRow(offset);
218
+ }
219
+ offset -= count;
105
220
  }
106
- return index.groups.map((level) => levelFor(state, level.key).store);
221
+ return null;
107
222
  }
108
223
  function hasSameModels(previous, next) {
109
224
  return previous.length === next.length && next.every((model, index) => previous[index] === model);
@@ -116,46 +231,82 @@ function syncRoot(state, index) {
116
231
  state.root.splice(0, state.rootModels.length, next);
117
232
  state.rootModels = next;
118
233
  }
119
- function syncModel(state, index) {
120
- const levels = [...index.groups, ...index.children.values()];
121
- const visited = new Set();
122
- let didChange = false;
123
- for (const level of levels) {
124
- didChange = didSpliceLevel(state, level) || didChange;
125
- visited.add(level.key);
234
+ function adjustGroupStores(state, context) {
235
+ const { groups } = context.index;
236
+ state.groupStores.length = Math.min(state.groupStores.length, groups.length);
237
+ for (const level of groups.slice(state.groupStores.length)) {
238
+ state.groupStores.push(newLevelStore(level));
126
239
  }
127
- if (didChange || visited.size !== state.levels.size) {
128
- dropUnvisited(state, visited);
129
- pruneObjects(state, index);
240
+ }
241
+ function stepGroupStores(state, context, surviving) {
242
+ for (const [group, level] of context.index.groups.entries()) {
243
+ const store = state.groupStores[group];
244
+ if (store !== undefined && group < surviving) {
245
+ syncLevel(context, store, level);
246
+ }
130
247
  }
131
- syncRoot(state, index);
132
- refreshExpandableLevels(state, index, levels);
133
248
  }
134
- function refreshExpandableLevels(state, index, levels) {
135
- if (!index.isTree) {
136
- return;
249
+ function syncModel(state, index) {
250
+ const context = { index, expansion: state.expansion };
251
+ const surviving = Math.min(state.groupStores.length, index.groups.length);
252
+ state.index = index;
253
+ state.expansion.isSyncing = true;
254
+ try {
255
+ adjustGroupStores(state, context);
256
+ syncRoot(state, index);
257
+ stepGroupStores(state, context, surviving);
137
258
  }
138
- for (const level of levels) {
139
- refreshExpandable(levelFor(state, level.key), level);
259
+ finally {
260
+ state.expansion.isSyncing = false;
140
261
  }
262
+ adoptIndex(state.expansion, index);
141
263
  }
142
264
  function createCollectionModel() {
143
- const root = newStore();
265
+ registeredStoreClass();
266
+ const root = newRootStore();
144
267
  const state = {
145
268
  root,
146
269
  rootModels: [],
147
270
  model: Gtk.FlattenListModel.new(root),
148
- objects: new Map(),
149
- levels: new Map(),
150
- tree: null,
271
+ groupStores: [],
272
+ trees: new Map(),
273
+ treeModels: [],
274
+ expansion: createTreeExpansion(EMPTY_INDEX),
275
+ index: EMPTY_INDEX,
151
276
  };
152
277
  return {
153
278
  model: state.model,
154
- treeModel: () => state.tree,
279
+ expansion: state.expansion,
280
+ rowAt: (position) => rowAt(state, position),
155
281
  sync: (index) => {
156
282
  syncModel(state, index);
157
283
  },
158
284
  };
159
285
  }
160
- export { createCollectionModel, getId };
286
+ class LazyLevelStore extends GObject.Object {
287
+ level = emptyLevel();
288
+ refs = [];
289
+ objects = [];
290
+ childStores = [];
291
+ createItem(position, ref) {
292
+ const created = Gtk.StringObject.new("");
293
+ this.objects[position] = created;
294
+ SLOTS.set(created, ref);
295
+ return created;
296
+ }
297
+ vfuncGetItemType() {
298
+ return GObject.TYPE_OBJECT;
299
+ }
300
+ vfuncGetNItems() {
301
+ return this.refs.length;
302
+ }
303
+ vfuncGetItem(position) {
304
+ const ref = this.refs[position];
305
+ if (ref === undefined) {
306
+ return null;
307
+ }
308
+ return this.objects[position] ?? this.createItem(position, ref);
309
+ }
310
+ }
311
+ export { createCollectionModel, slotPathAt, slotRefFor };
161
312
  //# sourceMappingURL=collection-model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection-model.js","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,cAAc,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AA6BtE,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,CAAC;AAEjC,MAAM,QAAQ,GAAG,GAAkB,EAAE,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,EAA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EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAwB,CAAC","sourcesContent":["import * as Gio from \"@gtkx/gi/gio\";\nimport * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport type { CollectionIndex, Level } from \"./collection-index.js\";\nimport { childLevelKey, ROOT_LEVEL_KEY } from \"./collection-index.js\";\n\ntype LevelState = {\n store: Gio.ListStore;\n ids: string[];\n canExpand: Map<string, boolean>;\n};\n\ntype SpliceRange = {\n start: number;\n removed: number;\n added: string[];\n};\n\ntype ModelState = {\n root: Gio.ListStore;\n rootModels: GObject.Object[];\n model: Gtk.FlattenListModel;\n objects: Map<string, Gtk.StringObject>;\n levels: Map<string, LevelState>;\n tree: Gtk.TreeListModel | null;\n};\n\ntype CollectionModel = {\n model: Gtk.FlattenListModel;\n treeModel: () => Gtk.TreeListModel | null;\n sync: (index: CollectionIndex) => void;\n};\n\nconst OBJECT_CACHE_MAX = 1 << 20;\n\nconst newStore = (): Gio.ListStore => new Gio.ListStore({ itemType: GObject.TYPE_OBJECT });\n\nfunction getId(value: GObject.Object | null): string | null {\n const item = value instanceof Gtk.TreeListRow ? value.getItem() : value;\n\n return item instanceof Gtk.StringObject ? item.getString() : null;\n}\n\nfunction objectFor(state: ModelState, id: string): Gtk.StringObject {\n const existing = state.objects.get(id);\n\n if (existing !== undefined) {\n return existing;\n }\n\n const created = Gtk.StringObject.new(id);\n state.objects.set(id, created);\n\n return created;\n}\n\nfunction commonPrefix(previous: string[], next: string[], max: number): number {\n let count = 0;\n\n while (count < max && previous[count] === next[count]) {\n count += 1;\n }\n\n return count;\n}\n\nfunction commonSuffix(previous: string[], next: string[], max: number): number {\n let count = 0;\n\n while (count < max && previous[previous.length - 1 - count] === next[next.length - 1 - count]) {\n count += 1;\n }\n\n return count;\n}\n\nfunction spliceRange(previous: string[], next: string[]): SpliceRange | null {\n const shared = Math.min(previous.length, next.length);\n const start = commonPrefix(previous, next, shared);\n\n if (start === previous.length && start === next.length) {\n return null;\n }\n\n const tail = commonSuffix(previous, next, shared - start);\n\n return { start, removed: previous.length - start - tail, added: next.slice(start, next.length - tail) };\n}\n\nfunction levelFor(state: ModelState, key: string): LevelState {\n const existing = state.levels.get(key);\n\n if (existing !== undefined) {\n return existing;\n }\n\n const created: LevelState = { store: newStore(), ids: [], canExpand: new Map() };\n state.levels.set(key, created);\n\n return created;\n}\n\nfunction refreshExpandable(current: LevelState, level: Level): void {\n const next: Map<string, boolean> = new Map();\n\n for (const [index, id] of level.ids.entries()) {\n const isWanted = level.expandableFlags[index] ?? false;\n const previous = current.canExpand.get(id);\n next.set(id, isWanted);\n\n if (previous !== undefined && previous !== isWanted) {\n current.store.itemsChanged(index, 1, 1);\n }\n }\n\n current.canExpand = next;\n}\n\nfunction didSpliceLevel(state: ModelState, level: Level): boolean {\n const current = levelFor(state, level.key);\n const range = spliceRange(current.ids, level.ids);\n\n if (range === null) {\n return false;\n }\n\n current.store.splice(range.start, range.removed, range.added.map((id) => objectFor(state, id)));\n current.ids = [...level.ids];\n\n return true;\n}\n\nfunction dropUnvisited(state: ModelState, visited: Set<string>): void {\n for (const key of state.levels.keys()) {\n if (!visited.has(key)) {\n state.levels.delete(key);\n }\n }\n}\n\nfunction pruneObjects(state: ModelState, index: CollectionIndex): void {\n if (state.objects.size <= OBJECT_CACHE_MAX) {\n return;\n }\n\n for (const id of state.objects.keys()) {\n if (!index.hasId(id)) {\n state.objects.delete(id);\n }\n }\n}\n\nfunction childStoreFor(state: ModelState, object: GObject.Object): Gio.ListStore | null {\n const id = getId(object);\n\n if (id === null) {\n return null;\n }\n\n return state.levels.get(childLevelKey(id))?.store ?? null;\n}\n\nfunction ensureTree(state: ModelState): Gtk.TreeListModel {\n state.tree ??= Gtk.TreeListModel.new(levelFor(state, ROOT_LEVEL_KEY).store, false, false, (object) =>\n childStoreFor(state, object));\n\n return state.tree;\n}\n\nfunction desiredRootModels(state: ModelState, index: CollectionIndex): GObject.Object[] {\n if (index.isTree) {\n return [ensureTree(state)];\n }\n\n return index.groups.map((level) => levelFor(state, level.key).store);\n}\n\nfunction hasSameModels(previous: GObject.Object[], next: GObject.Object[]): boolean {\n return previous.length === next.length && next.every((model, index) => previous[index] === model);\n}\n\nfunction syncRoot(state: ModelState, index: CollectionIndex): void {\n const next = desiredRootModels(state, index);\n\n if (hasSameModels(state.rootModels, next)) {\n return;\n }\n\n state.root.splice(0, state.rootModels.length, next);\n state.rootModels = next;\n}\n\nfunction syncModel(state: ModelState, index: CollectionIndex): void {\n const levels = [...index.groups, ...index.children.values()];\n const visited: Set<string> = new Set();\n let didChange = false;\n\n for (const level of levels) {\n didChange = didSpliceLevel(state, level) || didChange;\n visited.add(level.key);\n }\n\n if (didChange || visited.size !== state.levels.size) {\n dropUnvisited(state, visited);\n pruneObjects(state, index);\n }\n\n syncRoot(state, index);\n refreshExpandableLevels(state, index, levels);\n}\n\nfunction refreshExpandableLevels(state: ModelState, index: CollectionIndex, levels: Level[]): void {\n if (!index.isTree) {\n return;\n }\n\n for (const level of levels) {\n refreshExpandable(levelFor(state, level.key), level);\n }\n}\n\nfunction createCollectionModel(): CollectionModel {\n const root = newStore();\n\n const state: ModelState = {\n root,\n rootModels: [],\n model: Gtk.FlattenListModel.new(root),\n objects: new Map(),\n levels: new Map(),\n tree: null,\n };\n\n return {\n model: state.model,\n treeModel: () => state.tree,\n sync: (index) => {\n syncModel(state, index);\n },\n };\n}\n\nexport { createCollectionModel, getId, type CollectionModel };\n"]}
1
+ {"version":3,"file":"collection-model.js","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,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;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CAAC,CAAC;QAC5B,CAAC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,cAAe,SAAQ,OAAO,CAAC,MAAM;IAEvC,KAAK,GAAU,UAAU,EAAE,CAAC;IAC5B,IAAI,GAAc,EAAE,CAAC;IACrB,OAAO,GAAgC,EAAE,CAAC;IAC1C,WAAW,GAA0B,EAAE,CAAC;IAEhC,UAAU,CAAC,QAAgB,EAAE,GAAY;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;QACjC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,gBAAgB;QACZ,OAAO,OAAO,CAAC,WAAW,CAAC;IAC/B,CAAC;IAED,cAAc;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,QAAgB;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEhC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;CACJ;AAED,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,UAAU,EAAsC,CAAC","sourcesContent":["import * as Gio from \"@gtkx/gi/gio\";\nimport * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { registerClass } from \"@gtkx/runtime\";\nimport type { CollectionIndex, Level } from \"./collection-index.js\";\nimport type { TreeExpansion } from \"./tree-expansion.js\";\nimport { createCollectionIndex, emptyLevel } from \"./collection-index.js\";\nimport { encodePart } from \"./keys.js\";\nimport { adoptIndex, createTreeExpansion, pruneSlots } from \"./tree-expansion.js\";\n\ntype LevelStore = Gio.ListModel & LazyLevelStore;\n\ntype SlotRef = {\n store: LevelStore;\n slot: number;\n};\n\ntype SyncContext = {\n index: CollectionIndex;\n expansion: TreeExpansion;\n};\n\ntype SlotRun = {\n start: number;\n length: number;\n};\n\ntype LevelSync = {\n store: LevelStore;\n level: Level;\n};\n\ntype ModelState = {\n root: Gio.ListStore;\n rootModels: GObject.Object[];\n model: Gtk.FlattenListModel;\n groupStores: LevelStore[];\n trees: Map<LevelStore, Gtk.TreeListModel>;\n treeModels: Gtk.TreeListModel[];\n expansion: TreeExpansion;\n index: CollectionIndex;\n};\n\ntype CollectionModel = {\n model: Gtk.FlattenListModel;\n expansion: TreeExpansion;\n rowAt: (position: number) => Gtk.TreeListRow | null;\n sync: (index: CollectionIndex) => void;\n};\n\nconst STORE_CLASS_KEY = Symbol.for(\"gtkx.components.lazy-level-store\");\nconst SLOTS_KEY = Symbol.for(\"gtkx.components.lazy-level-store.slots\");\nconst EMPTY_INDEX = createCollectionIndex(undefined, undefined, true);\nconst SLOTS = sharedSlots();\n\nconst newRootStore = (): Gio.ListStore => new Gio.ListStore({ itemType: GObject.TYPE_OBJECT });\n\nfunction sharedSlots(): WeakMap<GObject.Object, SlotRef> {\n const cached: unknown = Reflect.get(globalThis, SLOTS_KEY);\n\n if (cached instanceof WeakMap) {\n return cached as WeakMap<GObject.Object, SlotRef>;\n }\n\n const created: WeakMap<GObject.Object, SlotRef> = new WeakMap();\n Reflect.set(globalThis, SLOTS_KEY, created);\n\n return created;\n}\n\nfunction registeredStoreClass(): typeof LazyLevelStore {\n const cached: unknown = Reflect.get(globalThis, STORE_CLASS_KEY);\n\n if (typeof cached === \"function\") {\n return cached as typeof LazyLevelStore;\n }\n\n registerClass(LazyLevelStore, { typeName: \"GtkxLazyLevelStore\", implements: [Gio.ListModel] });\n Reflect.set(globalThis, STORE_CLASS_KEY, LazyLevelStore);\n\n return LazyLevelStore;\n}\n\nfunction slotRefFor(value: GObject.Object | null): SlotRef | null {\n const item = value instanceof Gtk.TreeListRow ? value.getItem() : value;\n\n if (item === null) {\n return null;\n }\n\n const ref = SLOTS.get(item);\n\n return ref === undefined || ref.slot === -1 ? null : ref;\n}\n\nfunction slotPathAt(store: LevelStore, slot: number): string {\n return store.level.path + encodePart(String(slot));\n}\n\nfunction growStore(store: LevelStore): void {\n for (let slot = store.refs.length; slot < store.level.items.length; slot++) {\n store.refs.push({ store, slot });\n store.objects.push(null);\n store.childStores.push(null);\n }\n}\n\nfunction newLevelStore(level: Level): LevelStore {\n const store = new (registeredStoreClass())() as LevelStore;\n store.level = level;\n growStore(store);\n\n return store;\n}\n\nfunction collectFlips(previous: Level, next: Level, overlap: number): Set<number> {\n const flipped: Set<number> = new Set();\n\n for (let slot = 0; slot < overlap; slot++) {\n if ((previous.expandableFlags[slot] ?? false) !== (next.expandableFlags[slot] ?? false)) {\n flipped.add(slot);\n }\n }\n\n return flipped;\n}\n\nfunction pruneFlips(context: SyncContext, store: LevelStore, flipped: Set<number>): void {\n if (flipped.size === 0) {\n return;\n }\n\n pruneSlots(context.expansion, store.level.path, (slot) => flipped.has(slot));\n\n for (const slot of flipped) {\n store.childStores[slot] = null;\n }\n}\n\nfunction detachRefs(store: LevelStore, nextLength: number): void {\n for (let slot = nextLength; slot < store.refs.length; slot++) {\n const ref = store.refs[slot];\n\n if (ref !== undefined) {\n ref.slot = -1;\n }\n }\n}\n\nfunction shrinkStore(context: SyncContext, store: LevelStore, nextLength: number): void {\n if (store.refs.length <= nextLength) {\n return;\n }\n\n detachRefs(store, nextLength);\n pruneSlots(context.expansion, store.level.path, (slot) => slot >= nextLength);\n store.refs.length = nextLength;\n store.objects.length = nextLength;\n store.childStores.length = nextLength;\n}\n\nfunction emitTailSplice(store: LevelStore, previousLength: number, nextLength: number): void {\n if (nextLength < previousLength) {\n store.itemsChanged(nextLength, previousLength - nextLength, 0);\n\n return;\n }\n\n if (nextLength > previousLength) {\n store.itemsChanged(previousLength, 0, nextLength - previousLength);\n }\n}\n\nfunction extendRuns(runs: SlotRun[], slot: number): void {\n const last = runs.at(-1);\n\n if (last !== undefined && last.start + last.length === slot) {\n last.length += 1;\n\n return;\n }\n\n runs.push({ start: slot, length: 1 });\n}\n\nfunction collectFlipRuns(flipped: Set<number>): SlotRun[] {\n const runs: SlotRun[] = [];\n\n for (const slot of flipped) {\n extendRuns(runs, slot);\n }\n\n return runs;\n}\n\nfunction emitFlips(store: LevelStore, flipped: Set<number>): void {\n for (const run of collectFlipRuns(flipped)) {\n store.itemsChanged(run.start, run.length, run.length);\n }\n}\n\nfunction childSync(\n context: SyncContext,\n store: LevelStore,\n slot: number,\n flipped: Set<number>,\n): LevelSync | undefined {\n const child = store.childStores[slot] ?? null;\n\n if (child === null || flipped.has(slot)) {\n return undefined;\n }\n\n const level = context.index.childLevel(store.level, slot);\n\n return level === undefined ? undefined : { store: child, level };\n}\n\nfunction childSyncs(context: SyncContext, store: LevelStore, overlap: number, flipped: Set<number>): LevelSync[] {\n const syncs: LevelSync[] = [];\n\n for (let slot = 0; slot < overlap; slot++) {\n const sync = childSync(context, store, slot, flipped);\n\n if (sync !== undefined) {\n syncs.push(sync);\n }\n }\n\n return syncs;\n}\n\nfunction syncEntry(context: SyncContext, entry: LevelSync): LevelSync[] {\n const { store, level } = entry;\n const previousLength = store.refs.length;\n const overlap = Math.min(previousLength, level.items.length);\n const flipped = collectFlips(store.level, level, overlap);\n store.level = level;\n pruneFlips(context, store, flipped);\n shrinkStore(context, store, level.items.length);\n growStore(store);\n emitTailSplice(store, previousLength, level.items.length);\n emitFlips(store, flipped);\n\n return childSyncs(context, store, overlap, flipped);\n}\n\nfunction pushSyncs(pending: LevelSync[], syncs: LevelSync[]): void {\n for (const sync of syncs) {\n pending.push(sync);\n }\n}\n\nfunction syncLevel(context: SyncContext, store: LevelStore, level: Level): void {\n const pending: LevelSync[] = [{ store, level }];\n\n while (pending.length > 0) {\n const entry = pending.pop();\n\n if (entry !== undefined) {\n pushSyncs(pending, syncEntry(context, entry).toReversed());\n }\n }\n}\n\nfunction ensureChildStore(index: CollectionIndex, store: LevelStore, slot: number): LevelStore | null {\n const existing = store.childStores[slot] ?? null;\n\n if (existing !== null || !(store.level.expandableFlags[slot] ?? false)) {\n return existing;\n }\n\n const level = index.childLevel(store.level, slot);\n\n if (level === undefined) {\n return null;\n }\n\n const created = newLevelStore(level);\n store.childStores[slot] = created;\n\n return created;\n}\n\nfunction childStoreFor(state: ModelState, object: GObject.Object): Gio.ListModel | null {\n const ref = slotRefFor(object);\n\n if (ref === null) {\n return null;\n }\n\n return ensureChildStore(state.index, ref.store, ref.slot);\n}\n\nfunction treeFor(state: ModelState, store: LevelStore): Gtk.TreeListModel {\n return (\n state.trees.get(store) ?? Gtk.TreeListModel.new(store, false, false, (object) => childStoreFor(state, object))\n );\n}\n\nfunction nextTrees(state: ModelState, index: CollectionIndex): Map<LevelStore, Gtk.TreeListModel> {\n if (!index.isTree) {\n return new Map();\n }\n\n return new Map(state.groupStores.map((store) => [store, treeFor(state, store)]));\n}\n\nfunction pruneRebuiltLevels(state: ModelState, next: Map<LevelStore, Gtk.TreeListModel>): void {\n const stores: Set<LevelStore> = new Set([...state.trees.keys(), ...next.keys()]);\n\n for (const store of stores) {\n if (state.trees.get(store) !== next.get(store)) {\n pruneSlots(state.expansion, store.level.path, () => true);\n }\n }\n}\n\nfunction adoptTrees(state: ModelState, index: CollectionIndex): void {\n const next = nextTrees(state, index);\n pruneRebuiltLevels(state, next);\n state.trees = next;\n state.treeModels = next.values().toArray();\n}\n\nfunction desiredRootModels(state: ModelState, index: CollectionIndex): GObject.Object[] {\n adoptTrees(state, index);\n\n return index.isTree ? [...state.treeModels] : [...state.groupStores];\n}\n\nfunction rowAt(state: ModelState, position: number): Gtk.TreeListRow | null {\n let offset = position;\n\n for (const tree of state.treeModels) {\n const count = tree.getNItems();\n\n if (offset < count) {\n return tree.getRow(offset);\n }\n\n offset -= count;\n }\n\n return null;\n}\n\nfunction hasSameModels(previous: GObject.Object[], next: GObject.Object[]): boolean {\n return previous.length === next.length && next.every((model, index) => previous[index] === model);\n}\n\nfunction syncRoot(state: ModelState, index: CollectionIndex): void {\n const next = desiredRootModels(state, index);\n\n if (hasSameModels(state.rootModels, next)) {\n return;\n }\n\n state.root.splice(0, state.rootModels.length, next);\n state.rootModels = next;\n}\n\nfunction adjustGroupStores(state: ModelState, context: SyncContext): void {\n const { groups } = context.index;\n state.groupStores.length = Math.min(state.groupStores.length, groups.length);\n\n for (const level of groups.slice(state.groupStores.length)) {\n state.groupStores.push(newLevelStore(level));\n }\n}\n\nfunction stepGroupStores(state: ModelState, context: SyncContext, surviving: number): void {\n for (const [group, level] of context.index.groups.entries()) {\n const store = state.groupStores[group];\n\n if (store !== undefined && group < surviving) {\n syncLevel(context, store, level);\n }\n }\n}\n\nfunction syncModel(state: ModelState, index: CollectionIndex): void {\n const context: SyncContext = { index, expansion: state.expansion };\n const surviving = Math.min(state.groupStores.length, index.groups.length);\n state.index = index;\n state.expansion.isSyncing = true;\n\n try {\n adjustGroupStores(state, context);\n syncRoot(state, index);\n stepGroupStores(state, context, surviving);\n } finally {\n state.expansion.isSyncing = false;\n }\n\n adoptIndex(state.expansion, index);\n}\n\nfunction createCollectionModel(): CollectionModel {\n registeredStoreClass();\n const root = newRootStore();\n\n const state: ModelState = {\n root,\n rootModels: [],\n model: Gtk.FlattenListModel.new(root),\n groupStores: [],\n trees: new Map(),\n treeModels: [],\n expansion: createTreeExpansion(EMPTY_INDEX),\n index: EMPTY_INDEX,\n };\n\n return {\n model: state.model,\n expansion: state.expansion,\n rowAt: (position) => rowAt(state, position),\n sync: (index) => {\n syncModel(state, index);\n },\n };\n}\n\nclass LazyLevelStore extends GObject.Object implements Gio.ListModelImpl {\n declare itemsChanged: Gio.ListModel[\"itemsChanged\"];\n level: Level = emptyLevel();\n refs: SlotRef[] = [];\n objects: (Gtk.StringObject | null)[] = [];\n childStores: (LevelStore | null)[] = [];\n\n private createItem(position: number, ref: SlotRef): Gtk.StringObject {\n const created = Gtk.StringObject.new(\"\");\n this.objects[position] = created;\n SLOTS.set(created, ref);\n\n return created;\n }\n\n vfuncGetItemType(): bigint {\n return GObject.TYPE_OBJECT;\n }\n\n vfuncGetNItems(): number {\n return this.refs.length;\n }\n\n vfuncGetItem(position: number): GObject.Object | null {\n const ref = this.refs[position];\n\n if (ref === undefined) {\n return null;\n }\n\n return this.objects[position] ?? this.createItem(position, ref);\n }\n}\n\nexport { createCollectionModel, slotPathAt, slotRefFor, type CollectionModel, type SlotRef };\n"]}
@@ -1,18 +1,16 @@
1
- import type * as Gtk from "@gtkx/gi/gtk";
2
1
  import type { ListItem } from "../types.js";
3
2
  import type { CollectionIndex } from "./collection-index.js";
4
- import type { CollectionModel } from "./collection-model.js";
5
- type Collection = {
3
+ import type { CollectionModel, SlotRef } from "./collection-model.js";
4
+ type Collection = Pick<CollectionModel, "model" | "expansion" | "rowAt"> & {
6
5
  isTree: boolean;
7
- model: Gtk.FlattenListModel;
8
- treeModel: () => Gtk.TreeListModel | null;
9
- itemFor: (id: string) => ListItem | undefined;
10
- sectionFor: (id: string) => unknown;
6
+ itemAt: (ref: SlotRef) => ListItem | undefined;
7
+ sectionFor: (levelPath: string) => unknown;
11
8
  idAt: (position: number) => string | null;
9
+ pathAt: (position: number) => string | null;
12
10
  positionFor: (id: string) => number;
13
11
  positionsFor: (ids: string[]) => number[];
14
12
  };
15
- declare function eachRow(tree: Gtk.TreeListModel, visit: (row: Gtk.TreeListRow, id: string | null) => void): void;
16
- declare function createCollection(gtk: CollectionModel, index: CollectionIndex): Collection;
17
- export { createCollection, eachRow, type Collection };
13
+ declare function isCollectionIdle(collection: Collection): boolean;
14
+ declare function createCollection(collectionModel: CollectionModel, index: CollectionIndex): Collection;
15
+ export { createCollection, isCollectionIdle, type Collection };
18
16
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/internal/collection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,KAAK,UAAU,GAAG;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,GAAG,CAAC,gBAAgB,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;IAC1C,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;IAC9C,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC1C,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;CAC7C,CAAC;AAkBF,iBAAS,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,CAIxG;AAoDD,iBAAS,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,UAAU,CAWlF;AAED,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/internal/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAItE,KAAK,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC,GAAG;IACvE,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,SAAS,CAAC;IAC/C,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3C,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC5C,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;CAC7C,CAAC;AAgDF,iBAAS,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAIzD;AAED,iBAAS,gBAAgB,CAAC,eAAe,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,UAAU,CAa9F;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,CAAC"}
@@ -1,64 +1,54 @@
1
- import { getId } from "./collection-model.js";
2
- const ascending = (a, b) => a - b;
3
- function visitRow(tree, position, visit) {
4
- const row = tree.getRow(position);
5
- if (row === null) {
6
- return;
1
+ import { slotPathAt, slotRefFor } from "./collection-model.js";
2
+ import { findPositions } from "./tree-order.js";
3
+ const NO_POSITIONS = [];
4
+ function positionsFor(collectionModel, ids) {
5
+ if (ids.length === 0) {
6
+ return NO_POSITIONS;
7
7
  }
8
- visit(row, getId(row.getItem()));
8
+ const { expansion } = collectionModel;
9
+ return findPositions(expansion.index, expansion.slots, new Set(ids));
9
10
  }
10
- function eachRow(tree, visit) {
11
- for (let position = 0; position < tree.getNItems(); position++) {
12
- visitRow(tree, position, visit);
13
- }
11
+ function positionFor(collectionModel, id) {
12
+ const [first = -1] = positionsFor(collectionModel, [id]);
13
+ return first;
14
14
  }
15
- function collectWanted(item, position, wanted, out) {
16
- const id = getId(item);
17
- if (id !== null && wanted.has(id)) {
18
- out.push(position);
15
+ function refAt(collectionModel, position) {
16
+ if (position < 0) {
17
+ return null;
19
18
  }
19
+ return slotRefFor(collectionModel.model.getItem(position));
20
20
  }
21
- function scanPositions(tree, ids) {
22
- const wanted = new Set(ids);
23
- const positions = [];
24
- const count = tree.getNItems();
25
- for (let position = 0; position < count; position++) {
26
- collectWanted(tree.getItem(position), position, wanted, positions);
27
- }
28
- return positions;
21
+ function itemAt(index, ref) {
22
+ return index.itemAt(ref.store.level.path, ref.slot);
29
23
  }
30
- function indexPositions(index, ids) {
31
- const positions = [];
32
- for (const id of ids) {
33
- const position = index.positionFor(id);
34
- if (position >= 0) {
35
- positions.push(position);
36
- }
37
- }
38
- return positions.toSorted(ascending);
24
+ function idAt(collectionModel, index, position) {
25
+ const ref = refAt(collectionModel, position);
26
+ return ref === null ? null : (itemAt(index, ref)?.id ?? null);
39
27
  }
40
- function positionsFor(gtk, index, ids) {
41
- if (!index.isTree) {
42
- return indexPositions(index, ids);
28
+ function pathAt(collectionModel, position) {
29
+ const ref = refAt(collectionModel, position);
30
+ if (ref === null) {
31
+ return null;
43
32
  }
44
- const tree = gtk.treeModel();
45
- return tree === null ? [] : scanPositions(tree, ids);
33
+ return slotPathAt(ref.store, ref.slot);
46
34
  }
47
- function positionFor(gtk, index, id) {
48
- const [first = -1] = positionsFor(gtk, index, [id]);
49
- return first;
35
+ function isCollectionIdle(collection) {
36
+ const { expansion } = collection;
37
+ return !expansion.isApplying && !expansion.isSyncing;
50
38
  }
51
- function createCollection(gtk, index) {
39
+ function createCollection(collectionModel, index) {
52
40
  return {
41
+ model: collectionModel.model,
42
+ expansion: collectionModel.expansion,
53
43
  isTree: index.isTree,
54
- model: gtk.model,
55
- treeModel: () => (index.isTree ? gtk.treeModel() : null),
56
- itemFor: index.itemFor,
44
+ rowAt: collectionModel.rowAt,
45
+ itemAt: (ref) => itemAt(index, ref),
57
46
  sectionFor: index.sectionFor,
58
- idAt: (position) => getId(gtk.model.getItem(position)),
59
- positionFor: (id) => positionFor(gtk, index, id),
60
- positionsFor: (ids) => positionsFor(gtk, index, ids),
47
+ idAt: (position) => idAt(collectionModel, index, position),
48
+ pathAt: (position) => pathAt(collectionModel, position),
49
+ positionFor: (id) => positionFor(collectionModel, id),
50
+ positionsFor: (ids) => positionsFor(collectionModel, ids),
61
51
  };
62
52
  }
63
- export { createCollection, eachRow };
53
+ export { createCollection, isCollectionIdle };
64
54
  //# sourceMappingURL=collection.js.map