@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.
Files changed (104) hide show
  1. package/README.md +8 -9
  2. package/dist/adw/combo-row.d.ts +1 -0
  3. package/dist/adw/combo-row.d.ts.map +1 -1
  4. package/dist/adw/combo-row.js.map +1 -1
  5. package/dist/adw/types.d.ts +2 -1
  6. package/dist/adw/types.d.ts.map +1 -1
  7. package/dist/adw/types.js.map +1 -1
  8. package/dist/column-view.d.ts +2 -2
  9. package/dist/column-view.d.ts.map +1 -1
  10. package/dist/column-view.js +15 -13
  11. package/dist/column-view.js.map +1 -1
  12. package/dist/drop-down.d.ts +1 -0
  13. package/dist/drop-down.d.ts.map +1 -1
  14. package/dist/drop-down.js.map +1 -1
  15. package/dist/grid-view.js +2 -2
  16. package/dist/grid-view.js.map +1 -1
  17. package/dist/index.d.ts +1 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +0 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/internal/cells.d.ts +32 -24
  22. package/dist/internal/cells.d.ts.map +1 -1
  23. package/dist/internal/cells.js +168 -77
  24. package/dist/internal/cells.js.map +1 -1
  25. package/dist/internal/collection-index.d.ts +9 -13
  26. package/dist/internal/collection-index.d.ts.map +1 -1
  27. package/dist/internal/collection-index.js +33 -70
  28. package/dist/internal/collection-index.js.map +1 -1
  29. package/dist/internal/collection-model.d.ts +23 -2
  30. package/dist/internal/collection-model.d.ts.map +1 -1
  31. package/dist/internal/collection-model.js +210 -98
  32. package/dist/internal/collection-model.js.map +1 -1
  33. package/dist/internal/collection.d.ts +9 -12
  34. package/dist/internal/collection.d.ts.map +1 -1
  35. package/dist/internal/collection.js +38 -49
  36. package/dist/internal/collection.js.map +1 -1
  37. package/dist/internal/controlled-sync.d.ts +11 -0
  38. package/dist/internal/controlled-sync.d.ts.map +1 -0
  39. package/dist/internal/controlled-sync.js +19 -0
  40. package/dist/internal/controlled-sync.js.map +1 -0
  41. package/dist/internal/drop-down.d.ts.map +1 -1
  42. package/dist/internal/drop-down.js +27 -15
  43. package/dist/internal/drop-down.js.map +1 -1
  44. package/dist/internal/expansion.d.ts +3 -2
  45. package/dist/internal/expansion.d.ts.map +1 -1
  46. package/dist/internal/expansion.js +80 -47
  47. package/dist/internal/expansion.js.map +1 -1
  48. package/dist/internal/keys.d.ts +5 -0
  49. package/dist/internal/keys.d.ts.map +1 -0
  50. package/dist/internal/keys.js +13 -0
  51. package/dist/internal/keys.js.map +1 -0
  52. package/dist/internal/selection.d.ts +3 -2
  53. package/dist/internal/selection.d.ts.map +1 -1
  54. package/dist/internal/selection.js +68 -35
  55. package/dist/internal/selection.js.map +1 -1
  56. package/dist/internal/slots.d.ts +10 -0
  57. package/dist/internal/slots.d.ts.map +1 -0
  58. package/dist/internal/slots.js +43 -0
  59. package/dist/internal/slots.js.map +1 -0
  60. package/dist/internal/tree-expansion.d.ts +20 -0
  61. package/dist/internal/tree-expansion.d.ts.map +1 -0
  62. package/dist/internal/tree-expansion.js +68 -0
  63. package/dist/internal/tree-expansion.js.map +1 -0
  64. package/dist/internal/tree-order.d.ts +27 -0
  65. package/dist/internal/tree-order.d.ts.map +1 -0
  66. package/dist/internal/tree-order.js +71 -0
  67. package/dist/internal/tree-order.js.map +1 -0
  68. package/dist/internal/use-collection.d.ts +5 -5
  69. package/dist/internal/use-collection.d.ts.map +1 -1
  70. package/dist/internal/use-collection.js +6 -6
  71. package/dist/internal/use-collection.js.map +1 -1
  72. package/dist/list-view.d.ts.map +1 -1
  73. package/dist/list-view.js +6 -6
  74. package/dist/list-view.js.map +1 -1
  75. package/dist/types.d.ts +127 -54
  76. package/dist/types.d.ts.map +1 -1
  77. package/dist/types.js.map +1 -1
  78. package/package.json +7 -7
  79. package/src/adw/combo-row.tsx +1 -0
  80. package/src/adw/types.ts +2 -1
  81. package/src/column-view.tsx +38 -35
  82. package/src/drop-down.tsx +1 -0
  83. package/src/grid-view.tsx +2 -2
  84. package/src/index.ts +10 -11
  85. package/src/internal/cells.tsx +345 -123
  86. package/src/internal/collection-index.ts +51 -99
  87. package/src/internal/collection-model.ts +259 -110
  88. package/src/internal/collection.ts +46 -68
  89. package/src/internal/controlled-sync.ts +34 -0
  90. package/src/internal/drop-down.tsx +44 -23
  91. package/src/internal/expansion.ts +104 -67
  92. package/src/internal/keys.ts +18 -0
  93. package/src/internal/selection.tsx +100 -51
  94. package/src/internal/slots.ts +67 -0
  95. package/src/internal/tree-expansion.ts +110 -0
  96. package/src/internal/tree-order.ts +138 -0
  97. package/src/internal/use-collection.tsx +11 -11
  98. package/src/list-view.tsx +14 -10
  99. package/src/types.ts +140 -65
  100. package/dist/size-group.d.ts +0 -12
  101. package/dist/size-group.d.ts.map +0 -1
  102. package/dist/size-group.js +0 -41
  103. package/dist/size-group.js.map +0 -1
  104. package/src/size-group.tsx +0 -77
@@ -1,30 +1,51 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as Gtk from "@gtkx/gi/gtk";
3
- import { GtkTreeExpander } from "@gtkx/jsx/gtk";
3
+ import { GtkSignalListItemFactory, GtkTreeExpander } from "@gtkx/jsx/gtk";
4
4
  import { createPortal, useProperty } from "@gtkx/react";
5
+ import { setObjectProperty, t } from "@gtkx/runtime";
5
6
  import { memo, useLayoutEffect, useState, useSyncExternalStore } from "react";
6
- import { getId } from "./collection-model.js";
7
+ import { slotRefFor } from "./collection-model.js";
7
8
  const ItemCell = memo(ItemCellImpl);
9
+ const ItemRow = memo(ItemRowImpl);
8
10
  const HeaderCell = memo(HeaderCellImpl);
9
- const isListItem = (value) => value instanceof Gtk.ListItem;
10
- const isListHeader = (value) => value instanceof Gtk.ListHeader;
11
+ const CELL_OPTIONS = { isHost: isListItem, prepare: prepareCell };
12
+ const HEADER_OPTIONS = { isHost: isListHeader, prepare: prepareCell };
13
+ const ROW_OPTIONS = { isHost: isColumnViewRow };
14
+ const NO_SIZE = { width: -1, height: -1 };
15
+ const NO_ROW_PROPS = {};
16
+ const ROW_TEXT_DESCRIPTOR = t.string("borrowed");
11
17
  const placeholder = (size) => new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });
18
+ function isListItem(value) {
19
+ return value instanceof Gtk.ListItem;
20
+ }
21
+ function isListHeader(value) {
22
+ return value instanceof Gtk.ListHeader;
23
+ }
24
+ function isColumnViewRow(value) {
25
+ return value instanceof Gtk.ColumnViewRow;
26
+ }
27
+ function prepareCell(host, size) {
28
+ if (host.getChild() === null) {
29
+ host.setChild(placeholder(size));
30
+ }
31
+ }
12
32
  function notifyEntry(entry) {
13
33
  for (const listener of entry.listeners) {
14
34
  listener();
15
35
  }
16
36
  }
17
- function notifyRoster(state) {
37
+ function notifyRegistry(state) {
18
38
  state.snapshot = null;
39
+ state.version += 1;
19
40
  for (const listener of state.listeners) {
20
41
  listener();
21
42
  }
22
43
  }
23
- function createEntry(state, cell) {
44
+ function createEntry(state, host) {
24
45
  state.serial += 1;
25
46
  const entry = {
26
47
  key: `gtkx-cell-${String(state.serial)}`,
27
- cell,
48
+ host,
28
49
  item: null,
29
50
  listeners: new Set(),
30
51
  subscribe: (onChange) => {
@@ -37,102 +58,97 @@ function createEntry(state, cell) {
37
58
  };
38
59
  return entry;
39
60
  }
40
- function setupCell(state, cell) {
41
- cell.setChild(placeholder(state.size));
42
- state.entries.set(cell, createEntry(state, cell));
43
- notifyRoster(state);
61
+ function setupHost(state, host) {
62
+ state.prepare?.(host, state.size);
63
+ state.entries.set(host, createEntry(state, host));
64
+ notifyRegistry(state);
44
65
  }
45
- function teardownCell(state, cell) {
46
- if (state.entries.delete(cell)) {
47
- notifyRoster(state);
66
+ function teardownHost(state, host) {
67
+ if (state.entries.delete(host)) {
68
+ notifyRegistry(state);
48
69
  }
49
70
  }
50
- function writeBinding(state, cell, item) {
51
- const entry = state.entries.get(cell);
71
+ function writeBinding(state, host, item) {
72
+ const entry = state.entries.get(host);
52
73
  if (entry === undefined) {
53
74
  return;
54
75
  }
55
76
  entry.item = item;
56
77
  notifyEntry(entry);
57
78
  }
58
- function boundItem(cell) {
59
- if (cell instanceof Gtk.ListItem) {
60
- return cell.getItem();
61
- }
62
- return cell instanceof Gtk.ListHeader ? cell.getItem() : null;
63
- }
64
- function bindCell(state, cell) {
65
- if (cell.getChild() === null) {
66
- cell.setChild(placeholder(state.size));
67
- }
68
- writeBinding(state, cell, boundItem(cell));
79
+ function bindHost(state, host) {
80
+ state.prepare?.(host, state.size);
81
+ writeBinding(state, host, host.getItem());
69
82
  }
70
- function subscribeRoster(state, onChange) {
83
+ function subscribeRegistry(state, onChange) {
71
84
  state.listeners.add(onChange);
72
85
  return () => {
73
86
  state.listeners.delete(onChange);
74
87
  };
75
88
  }
76
- function rosterSnapshot(state) {
89
+ function getRegistryEntries(state) {
77
90
  state.snapshot ??= state.entries.values().toArray();
78
91
  return state.snapshot;
79
92
  }
80
- function guarded(isCell, run) {
81
- return (cell) => {
82
- if (isCell(cell)) {
83
- run(cell);
93
+ function guarded(isHost, run) {
94
+ return (host) => {
95
+ if (isHost(host)) {
96
+ run(host);
84
97
  }
85
98
  };
86
99
  }
87
- function createHandlers(state, isCell) {
100
+ function createHandlers(state) {
101
+ const { isHost } = state;
88
102
  return {
89
- onSetup: guarded(isCell, (cell) => {
90
- setupCell(state, cell);
103
+ onSetup: guarded(isHost, (host) => {
104
+ setupHost(state, host);
91
105
  }),
92
- onBind: guarded(isCell, (cell) => {
93
- bindCell(state, cell);
106
+ onBind: guarded(isHost, (host) => {
107
+ bindHost(state, host);
94
108
  }),
95
- onUnbind: guarded(isCell, (cell) => {
96
- writeBinding(state, cell, null);
109
+ onUnbind: guarded(isHost, (host) => {
110
+ writeBinding(state, host, null);
97
111
  }),
98
- onTeardown: guarded(isCell, (cell) => {
99
- teardownCell(state, cell);
112
+ onTeardown: guarded(isHost, (host) => {
113
+ teardownHost(state, host);
100
114
  }),
101
115
  };
102
116
  }
103
- function createCellStore(isCell, size) {
117
+ function createCellRegistry(options, size) {
104
118
  const state = {
119
+ ...options,
105
120
  size,
106
121
  entries: new Map(),
107
122
  snapshot: null,
108
123
  listeners: new Set(),
109
124
  serial: 0,
125
+ version: 0,
110
126
  };
111
127
  return {
112
- handlers: createHandlers(state, isCell),
128
+ handlers: createHandlers(state),
113
129
  setSize: (next) => {
114
130
  state.size = next;
115
131
  },
116
- subscribe: (onChange) => subscribeRoster(state, onChange),
117
- getSnapshot: () => rosterSnapshot(state),
132
+ subscribe: (onChange) => subscribeRegistry(state, onChange),
133
+ getVersion: () => state.version,
134
+ getEntries: () => getRegistryEntries(state),
118
135
  };
119
136
  }
120
- function useCellStore(isCell, size) {
121
- const [store] = useState(() => createCellStore(isCell, size));
137
+ function useCellRegistry(options, size) {
138
+ const [registry] = useState(() => createCellRegistry(options, size));
122
139
  useLayoutEffect(() => {
123
- store.setSize(size);
140
+ registry.setSize(size);
124
141
  });
125
- return store;
142
+ return registry;
126
143
  }
127
144
  function useItemCells(size) {
128
- return useCellStore(isListItem, size);
145
+ return useCellRegistry(CELL_OPTIONS, size);
129
146
  }
130
147
  function useHeaderCells(size) {
131
- return useCellStore(isListHeader, size);
148
+ return useCellRegistry(HEADER_OPTIONS, size);
132
149
  }
133
150
  function isRowWanted(options, item) {
134
- const { expandedIds } = options;
135
- return expandedIds == null ? options.isRowExpanded === true : expandedIds.includes(item.id);
151
+ return options.expandedIds?.includes(item.id) ?? false;
136
152
  }
137
153
  function itemArgs(item, options) {
138
154
  const args = { item: item.value, index: options.position ?? 0 };
@@ -146,40 +162,115 @@ function itemArgs(item, options) {
146
162
  }
147
163
  return args;
148
164
  }
149
- function wrapExpander(item, row, content) {
165
+ function slotFor(options) {
166
+ const ref = slotRefFor(options.item);
167
+ const item = ref === null ? undefined : options.collection.itemAt(ref);
168
+ if (item === undefined) {
169
+ return null;
170
+ }
171
+ return { item, row: options.row, args: itemArgs(item, options) };
172
+ }
173
+ function useItemSlot(entry, collection, expandedIds) {
174
+ const position = useProperty(entry.host, "position");
175
+ const item = useSyncExternalStore(entry.subscribe, entry.getItem);
176
+ const row = item instanceof Gtk.TreeListRow ? item : null;
177
+ return slotFor({ item, position, row, collection, expandedIds });
178
+ }
179
+ function expanderDescriptionFor(slot, descriptions) {
180
+ const { isExpanded } = slot.args;
181
+ if (isExpanded === undefined || descriptions == null) {
182
+ return undefined;
183
+ }
184
+ return isExpanded ? descriptions.collapse : descriptions.expand;
185
+ }
186
+ function wrapExpander(slot, content, descriptions) {
187
+ const { item, row } = slot;
150
188
  const expander = row === null
151
189
  ? (content)
152
- : (_jsx(GtkTreeExpander, { listRow: row, hideExpander: item.hideExpander ?? false, indentForDepth: item.indentForDepth ?? true, indentForIcon: item.indentForIcon ?? true, children: content }));
190
+ : (_jsx(GtkTreeExpander, { listRow: row, hideExpander: item.shouldHideExpander ?? false, indentForDepth: item.shouldIndentForDepth ?? true, indentForIcon: item.shouldIndentForIcon ?? true, accessibleDescription: expanderDescriptionFor(slot, descriptions), children: content }));
153
191
  return expander;
154
192
  }
155
- function itemBody(options) {
156
- const id = getId(options.item);
157
- const item = id === null ? undefined : options.collection.itemFor(id);
158
- if (item === undefined) {
193
+ function itemBody(slot, render, descriptions) {
194
+ if (slot === null) {
159
195
  return null;
160
196
  }
161
- const render = options.render;
162
- return wrapExpander(item, options.row, render(itemArgs(item, options)));
197
+ const renderItem = render;
198
+ return wrapExpander(slot, renderItem(slot.args), descriptions);
163
199
  }
164
- function ItemCellImpl({ entry, render, collection, expandedIds }) {
165
- const item = useSyncExternalStore(entry.subscribe, entry.getItem);
166
- const position = useProperty(entry.cell, "position");
167
- const row = item instanceof Gtk.TreeListRow ? item : null;
168
- const isRowExpanded = useProperty(row, "expanded");
169
- const body = itemBody({ item, position, row, isRowExpanded, render, collection, expandedIds });
170
- return createPortal(body, entry.cell, entry.key);
200
+ function rowText(value) {
201
+ return value ?? null;
202
+ }
203
+ /* eslint-disable-next-line unicorn/consistent-boolean-name -- reads the flag off a row, paired with rowText */
204
+ function rowFlag(value) {
205
+ return value ?? true;
206
+ }
207
+ function rowPropsFor(slot, rowProps) {
208
+ const resolve = rowProps;
209
+ const props = slot === null ? NO_ROW_PROPS : resolve(slot.args);
210
+ return {
211
+ accessibleLabel: rowText(props.accessibleLabel),
212
+ accessibleDescription: rowText(props.accessibleDescription),
213
+ isActivatable: rowFlag(props.isActivatable),
214
+ isFocusable: rowFlag(props.isFocusable),
215
+ isSelectable: rowFlag(props.isSelectable),
216
+ };
217
+ }
218
+ function setRowText(host, name, value) {
219
+ setObjectProperty(host, name, ROW_TEXT_DESCRIPTOR, value);
220
+ }
221
+ function applyRowProps(host, props) {
222
+ setRowText(host, "accessible-label", props.accessibleLabel);
223
+ setRowText(host, "accessible-description", props.accessibleDescription);
224
+ host.setActivatable(props.isActivatable);
225
+ host.setFocusable(props.isFocusable);
226
+ host.setSelectable(props.isSelectable);
227
+ }
228
+ function ItemCellImpl({ entry, render, collection, expandedIds, expanderDescriptions }) {
229
+ const slot = useItemSlot(entry, collection, expandedIds);
230
+ const body = itemBody(slot, render, expanderDescriptions);
231
+ return createPortal(body, entry.host, entry.key);
232
+ }
233
+ function ItemRowImpl({ entry, rowProps, collection, expandedIds }) {
234
+ const slot = useItemSlot(entry, collection, expandedIds);
235
+ const props = rowPropsFor(slot, rowProps);
236
+ useLayoutEffect(() => {
237
+ applyRowProps(entry.host, props);
238
+ });
239
+ return null;
171
240
  }
172
241
  function HeaderCellImpl({ entry, render, collection }) {
173
242
  const item = useSyncExternalStore(entry.subscribe, entry.getItem);
174
- const id = getId(item);
243
+ const ref = slotRefFor(item);
175
244
  const renderHeader = render;
176
- const body = id === null ? null : renderHeader({ section: collection.sectionFor(id) });
177
- return createPortal(body, entry.cell, entry.key);
245
+ const body = ref === null ? null : renderHeader({ section: collection.sectionFor(ref.store.path) });
246
+ return createPortal(body, entry.host, entry.key);
178
247
  }
179
- function usePortalEntries(store) {
180
- return useSyncExternalStore(store.subscribe, store.getSnapshot);
248
+ function usePortalEntries(registry) {
249
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
250
+ return registry.getEntries();
181
251
  }
182
- const ItemPortals = ({ store, render, collection, expandedIds }) => usePortalEntries(store).map((entry) => (_jsx(ItemCell, { entry: entry, render: render, collection: collection, expandedIds: expandedIds }, entry.key)));
183
- const HeaderPortals = ({ store, render, collection }) => usePortalEntries(store).map((entry) => (_jsx(HeaderCell, { entry: entry, render: render, collection: collection }, entry.key)));
184
- export { useItemCells, useHeaderCells, ItemPortals, HeaderPortals, };
252
+ const ItemPortals = ({ registry, render, collection, expandedIds, expanderDescriptions, }) => usePortalEntries(registry).map((entry) => (_jsx(ItemCell, { entry: entry, render: render, collection: collection, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions }, entry.key)));
253
+ const RowPortals = ({ registry, rowProps, collection, expandedIds }) => usePortalEntries(registry).map((entry) => (_jsx(ItemRow, { entry: entry, rowProps: rowProps, collection: collection, expandedIds: expandedIds }, entry.key)));
254
+ const HeaderPortals = ({ registry, render, collection }) => usePortalEntries(registry).map((entry) => (_jsx(HeaderCell, { entry: entry, render: render, collection: collection }, entry.key)));
255
+ const useSectionHeader = (render, collection, size) => {
256
+ const registry = useHeaderCells(size);
257
+ if (render == null) {
258
+ return { factoryProps: {}, portals: null };
259
+ }
260
+ return {
261
+ factoryProps: { headerFactory: _jsx(GtkSignalListItemFactory, { ...registry.handlers }) },
262
+ portals: _jsx(HeaderPortals, { registry: registry, render: render, collection: collection }),
263
+ };
264
+ };
265
+ const useRowProps = (rowProps, collection, expandedIds) => {
266
+ const registry = useCellRegistry(ROW_OPTIONS, NO_SIZE);
267
+ if (rowProps == null) {
268
+ return { factoryProps: {}, portals: null };
269
+ }
270
+ return {
271
+ factoryProps: { rowFactory: _jsx(GtkSignalListItemFactory, { ...registry.handlers }) },
272
+ portals: (_jsx(RowPortals, { registry: registry, rowProps: rowProps, collection: collection, expandedIds: expandedIds })),
273
+ };
274
+ };
275
+ export { useItemCells, useRowProps, useSectionHeader, ItemPortals, };
185
276
  //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AzF,KAAK,CAAC,GAAG,CAAoF,CAC/G,CAAC,CAAC;AAEP,MAAM,aAAa,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAsB,EAAa,EAAE,CACnF,gBAAgB,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACnC,KAAC,UAAU,IAAiB,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,IAA/D,KAAK,CAAC,GAAG,CAA0D,CACvF,CAAC,CAAC;AAEP,OAAO,EACH,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,GAGhB,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkTreeExpander } from \"@gtkx/jsx/gtk\";\nimport { createPortal, useProperty } from \"@gtkx/react\";\nimport { memo, useLayoutEffect, useState, useSyncExternalStore } from \"react\";\nimport type { HeaderRenderer, Item, ItemRenderer, RenderItemArgs } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { getId } from \"./collection-model.js\";\n\ntype CellSize = {\n width: number;\n height: number;\n};\n\ntype CellHost = GObject.Object & {\n getChild: () => Gtk.Widget | null;\n setChild: (child: Gtk.Widget | null) => void;\n};\n\ntype CellEntry<C extends CellHost> = {\n key: string;\n cell: C;\n item: GObject.Object | null;\n listeners: Set<() => void>;\n subscribe: (onChange: () => void) => () => void;\n getItem: () => GObject.Object | null;\n};\n\ntype FactoryHandlers = {\n onSetup: (cell: GObject.Object) => void;\n onBind: (cell: GObject.Object) => void;\n onUnbind: (cell: GObject.Object) => void;\n onTeardown: (cell: GObject.Object) => void;\n};\n\ntype CellStore<C extends CellHost> = {\n handlers: FactoryHandlers;\n setSize: (size: CellSize) => void;\n subscribe: (onChange: () => void) => () => void;\n getSnapshot: () => CellEntry<C>[];\n};\n\ntype StoreState<C extends CellHost> = {\n size: CellSize;\n entries: Map<C, CellEntry<C>>;\n snapshot: CellEntry<C>[] | null;\n listeners: Set<() => void>;\n serial: number;\n};\n\ntype CellGuard<C extends CellHost> = (value: GObject.Object) => value is C;\n\ntype ItemBodyOptions = {\n item: GObject.Object | null;\n position: number | undefined;\n row: Gtk.TreeListRow | null;\n isRowExpanded: boolean | undefined;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype ItemCellProps = {\n entry: CellEntry<Gtk.ListItem>;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype ItemPortalsProps = {\n store: CellStore<Gtk.ListItem>;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds?: string[] | null | undefined;\n};\n\ntype HeaderCellProps = {\n entry: CellEntry<Gtk.ListHeader>;\n render: HeaderRenderer<never>;\n collection: Collection;\n};\n\ntype HeaderPortalsProps = {\n store: CellStore<Gtk.ListHeader>;\n render: HeaderRenderer<never>;\n collection: Collection;\n};\n\nconst ItemCell = memo(ItemCellImpl);\nconst HeaderCell = memo(HeaderCellImpl);\n\nconst isListItem = (value: GObject.Object): value is Gtk.ListItem => value instanceof Gtk.ListItem;\nconst isListHeader = (value: GObject.Object): value is Gtk.ListHeader => value instanceof Gtk.ListHeader;\n\nconst placeholder = (size: CellSize): Gtk.Widget =>\n new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });\n\nfunction notifyEntry<C extends CellHost>(entry: CellEntry<C>): void {\n for (const listener of entry.listeners) {\n listener();\n }\n}\n\nfunction notifyRoster<C extends CellHost>(state: StoreState<C>): void {\n state.snapshot = null;\n\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction createEntry<C extends CellHost>(state: StoreState<C>, cell: C): CellEntry<C> {\n state.serial += 1;\n\n const entry: CellEntry<C> = {\n key: `gtkx-cell-${String(state.serial)}`,\n cell,\n item: null,\n listeners: new Set(),\n subscribe: (onChange) => {\n entry.listeners.add(onChange);\n\n return () => {\n entry.listeners.delete(onChange);\n };\n },\n getItem: () => entry.item,\n };\n\n return entry;\n}\n\nfunction setupCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n cell.setChild(placeholder(state.size));\n state.entries.set(cell, createEntry(state, cell));\n notifyRoster(state);\n}\n\nfunction teardownCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n if (state.entries.delete(cell)) {\n notifyRoster(state);\n }\n}\n\nfunction writeBinding<C extends CellHost>(state: StoreState<C>, cell: C, item: GObject.Object | null): void {\n const entry = state.entries.get(cell);\n\n if (entry === undefined) {\n return;\n }\n\n entry.item = item;\n notifyEntry(entry);\n}\n\nfunction boundItem(cell: CellHost): GObject.Object | null {\n if (cell instanceof Gtk.ListItem) {\n return cell.getItem();\n }\n\n return cell instanceof Gtk.ListHeader ? cell.getItem() : null;\n}\n\nfunction bindCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n if (cell.getChild() === null) {\n cell.setChild(placeholder(state.size));\n }\n\n writeBinding(state, cell, boundItem(cell));\n}\n\nfunction subscribeRoster<C extends CellHost>(state: StoreState<C>, onChange: () => void): () => void {\n state.listeners.add(onChange);\n\n return () => {\n state.listeners.delete(onChange);\n };\n}\n\nfunction rosterSnapshot<C extends CellHost>(state: StoreState<C>): CellEntry<C>[] {\n state.snapshot ??= state.entries.values().toArray();\n\n return state.snapshot;\n}\n\nfunction guarded<C extends CellHost>(isCell: CellGuard<C>, run: (cell: C) => void): (cell: GObject.Object) => void {\n return (cell) => {\n if (isCell(cell)) {\n run(cell);\n }\n };\n}\n\nfunction createHandlers<C extends CellHost>(state: StoreState<C>, isCell: CellGuard<C>): FactoryHandlers {\n return {\n onSetup: guarded(isCell, (cell) => {\n setupCell(state, cell);\n }),\n onBind: guarded(isCell, (cell) => {\n bindCell(state, cell);\n }),\n onUnbind: guarded(isCell, (cell) => {\n writeBinding(state, cell, null);\n }),\n onTeardown: guarded(isCell, (cell) => {\n teardownCell(state, cell);\n }),\n };\n}\n\nfunction createCellStore<C extends CellHost>(isCell: CellGuard<C>, size: CellSize): CellStore<C> {\n const state: StoreState<C> = {\n size,\n entries: new Map(),\n snapshot: null,\n listeners: new Set(),\n serial: 0,\n };\n\n return {\n handlers: createHandlers(state, isCell),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRoster(state, onChange),\n getSnapshot: () => rosterSnapshot(state),\n };\n}\n\nfunction useCellStore<C extends CellHost>(isCell: CellGuard<C>, size: CellSize): CellStore<C> {\n const [store] = useState(() => createCellStore(isCell, size));\n\n useLayoutEffect(() => {\n store.setSize(size);\n });\n\n return store;\n}\n\nfunction useItemCells(size: CellSize): CellStore<Gtk.ListItem> {\n return useCellStore(isListItem, size);\n}\n\nfunction useHeaderCells(size: CellSize): CellStore<Gtk.ListHeader> {\n return useCellStore(isListHeader, size);\n}\n\nfunction isRowWanted(options: ItemBodyOptions, item: Item): boolean {\n const { expandedIds } = options;\n\n return expandedIds == null ? options.isRowExpanded === true : expandedIds.includes(item.id);\n}\n\nfunction itemArgs(item: Item, options: ItemBodyOptions): RenderItemArgs<unknown> {\n const args: RenderItemArgs<unknown> = { item: item.value, index: options.position ?? 0 };\n const row = options.row;\n\n if (row === null) {\n return args;\n }\n\n args.depth = row.getDepth();\n\n if (row.isExpandable()) {\n args.isExpanded = isRowWanted(options, item);\n }\n\n return args;\n}\n\nfunction wrapExpander(item: Item, row: Gtk.TreeListRow | null, content: ReactNode): ReactNode {\n const expander: ReactNode =\n row === null\n ? (\n content\n )\n : (\n <GtkTreeExpander\n listRow={row}\n hideExpander={item.hideExpander ?? false}\n indentForDepth={item.indentForDepth ?? true}\n indentForIcon={item.indentForIcon ?? true}\n >\n {content}\n </GtkTreeExpander>\n );\n\n return expander;\n}\n\nfunction itemBody(options: ItemBodyOptions): ReactNode {\n const id = getId(options.item);\n const item = id === null ? undefined : options.collection.itemFor(id);\n\n if (item === undefined) {\n return null;\n }\n\n const render = options.render as ItemRenderer<unknown>;\n\n return wrapExpander(item, options.row, render(itemArgs(item, options)));\n}\n\nfunction ItemCellImpl({ entry, render, collection, expandedIds }: ItemCellProps): ReactNode {\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const position = useProperty(entry.cell, \"position\");\n const row = item instanceof Gtk.TreeListRow ? item : null;\n const isRowExpanded = useProperty(row, \"expanded\");\n const body = itemBody({ item, position, row, isRowExpanded, render, collection, expandedIds });\n\n return createPortal(body, entry.cell, entry.key);\n}\n\nfunction HeaderCellImpl({ entry, render, collection }: HeaderCellProps): ReactNode {\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const id = getId(item);\n const renderHeader = render as HeaderRenderer<unknown>;\n const body = id === null ? null : renderHeader({ section: collection.sectionFor(id) });\n\n return createPortal(body, entry.cell, entry.key);\n}\n\nfunction usePortalEntries<C extends CellHost>(store: CellStore<C>): CellEntry<C>[] {\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n}\n\nconst ItemPortals = ({ store, render, collection, expandedIds }: ItemPortalsProps): ReactNode =>\n usePortalEntries(store).map((entry) => (\n <ItemCell key={entry.key} entry={entry} render={render} collection={collection} expandedIds={expandedIds} />\n ));\n\nconst HeaderPortals = ({ store, render, collection }: HeaderPortalsProps): ReactNode =>\n usePortalEntries(store).map((entry) => (\n <HeaderCell key={entry.key} entry={entry} render={render} collection={collection} />\n ));\n\nexport {\n useItemCells,\n useHeaderCells,\n ItemPortals,\n HeaderPortals,\n type CellSize,\n type CellStore,\n};\n"]}
1
+ {"version":3,"file":"cells.js","sourceRoot":"","sources":["../../src/internal/cells.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,IA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EAAE,CAAC;IAC/C,CAAC;IAED,OAAO;QACH,YAAY,EAAE,EAAE,aAAa,EAAE,KAAC,wBAAwB,OAAK,QAAQ,CAAC,QAAQ,GAAI,EAAE;QACpF,OAAO,EAAE,KAAC,aAAa,IAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAI;KACzF,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAChB,QAAwD,EACxD,UAAsB,EACtB,WAAwC,EACjC,EAAE;IACT,MAAM,QAAQ,GAAG,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEvD,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO;QACH,YAAY,EAAE,EAAE,UAAU,EAAE,KAAC,wBAAwB,OAAK,QAAQ,CAAC,QAAQ,GAAI,EAAE;QACjF,OAAO,EAAE,CACL,KAAC,UAAU,IAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAI,CAC3G;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,GAEd,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkSignalListItemFactory, GtkTreeExpander } from \"@gtkx/jsx/gtk\";\nimport { createPortal, useProperty } from \"@gtkx/react\";\nimport { setObjectProperty, t } from \"@gtkx/runtime\";\nimport { memo, useLayoutEffect, useState, useSyncExternalStore } from \"react\";\nimport type {\n ExpanderDescriptions,\n ListItem,\n ListItemRenderArgs,\n ListItemRenderer,\n ListRowProps,\n ListRowPropsResolver,\n ListSectionRenderer,\n} from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { slotRefFor } from \"./collection-model.js\";\n\ntype CellSize = {\n width: number;\n height: number;\n};\n\ntype FactoryHost = GObject.Object & {\n getItem: () => GObject.Object | null;\n};\n\ntype CellHost = FactoryHost & {\n getChild: () => Gtk.Widget | null;\n setChild: (child: Gtk.Widget | null) => void;\n};\n\ntype CellEntry<H extends FactoryHost> = {\n key: string;\n host: H;\n item: GObject.Object | null;\n listeners: Set<() => void>;\n subscribe: (onChange: () => void) => () => void;\n getItem: () => GObject.Object | null;\n};\n\ntype FactoryHandlers = {\n onSetup: (host: GObject.Object) => void;\n onBind: (host: GObject.Object) => void;\n onUnbind: (host: GObject.Object) => void;\n onTeardown: (host: GObject.Object) => void;\n};\n\ntype CellRegistry<H extends FactoryHost> = {\n handlers: FactoryHandlers;\n setSize: (size: CellSize) => void;\n subscribe: (onChange: () => void) => () => void;\n getVersion: () => number;\n getEntries: () => CellEntry<H>[];\n};\n\ntype HostGuard<H extends FactoryHost> = (value: GObject.Object) => value is H;\n\ntype CellRegistryOptions<H extends FactoryHost> = {\n isHost: HostGuard<H>;\n prepare?: ((host: H, size: CellSize) => void) | undefined;\n};\n\ntype CellRegistryState<H extends FactoryHost> = CellRegistryOptions<H> & {\n size: CellSize;\n entries: Map<H, CellEntry<H>>;\n snapshot: CellEntry<H>[] | null;\n listeners: Set<() => void>;\n serial: number;\n version: number;\n};\n\ntype ResolvedRowProps = {\n accessibleLabel: string | null;\n accessibleDescription: string | null;\n isActivatable: boolean;\n isFocusable: boolean;\n isSelectable: boolean;\n};\n\ntype ItemSlotOptions = {\n item: GObject.Object | null;\n position: number | undefined;\n row: Gtk.TreeListRow | null;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype PositionedHost = Gtk.ListItem | Gtk.ColumnViewRow;\n\ntype ItemSlot = {\n item: ListItem;\n row: Gtk.TreeListRow | null;\n args: ListItemRenderArgs<unknown>;\n};\n\ntype ItemCellProps = {\n entry: CellEntry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n};\n\ntype ItemPortalsProps = {\n registry: CellRegistry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n collection: Collection;\n expandedIds?: string[] | null | undefined;\n expanderDescriptions?: ExpanderDescriptions | null | undefined;\n};\n\ntype ItemRowProps = {\n entry: CellEntry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype RowPortalsProps = {\n registry: CellRegistry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype HeaderCellProps = {\n entry: CellEntry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype HeaderPortalsProps = {\n registry: CellRegistry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype SectionHeaderSlot = {\n factoryProps: { headerFactory?: ReactElement };\n portals: ReactNode;\n};\n\ntype RowSlot = {\n factoryProps: { rowFactory?: ReactElement };\n portals: ReactNode;\n};\n\nconst ItemCell = memo(ItemCellImpl);\nconst ItemRow = memo(ItemRowImpl);\nconst HeaderCell = memo(HeaderCellImpl);\nconst CELL_OPTIONS: CellRegistryOptions<Gtk.ListItem> = { isHost: isListItem, prepare: prepareCell };\nconst HEADER_OPTIONS: CellRegistryOptions<Gtk.ListHeader> = { isHost: isListHeader, prepare: prepareCell };\nconst ROW_OPTIONS: CellRegistryOptions<Gtk.ColumnViewRow> = { isHost: isColumnViewRow };\nconst NO_SIZE: CellSize = { width: -1, height: -1 };\nconst NO_ROW_PROPS: ListRowProps = {};\nconst ROW_TEXT_DESCRIPTOR = t.string(\"borrowed\");\n\nconst placeholder = (size: CellSize): Gtk.Widget =>\n new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });\n\nfunction isListItem(value: GObject.Object): value is Gtk.ListItem {\n return value instanceof Gtk.ListItem;\n}\n\nfunction isListHeader(value: GObject.Object): value is Gtk.ListHeader {\n return value instanceof Gtk.ListHeader;\n}\n\nfunction isColumnViewRow(value: GObject.Object): value is Gtk.ColumnViewRow {\n return value instanceof Gtk.ColumnViewRow;\n}\n\nfunction prepareCell(host: CellHost, size: CellSize): void {\n if (host.getChild() === null) {\n host.setChild(placeholder(size));\n }\n}\n\nfunction notifyEntry<H extends FactoryHost>(entry: CellEntry<H>): void {\n for (const listener of entry.listeners) {\n listener();\n }\n}\n\nfunction notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): void {\n state.snapshot = null;\n state.version += 1;\n\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction createEntry<H extends FactoryHost>(state: CellRegistryState<H>, host: H): CellEntry<H> {\n state.serial += 1;\n\n const entry: CellEntry<H> = {\n key: `gtkx-cell-${String(state.serial)}`,\n host,\n item: null,\n listeners: new Set(),\n subscribe: (onChange) => {\n entry.listeners.add(onChange);\n\n return () => {\n entry.listeners.delete(onChange);\n };\n },\n getItem: () => entry.item,\n };\n\n return entry;\n}\n\nfunction setupHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n state.entries.set(host, createEntry(state, host));\n notifyRegistry(state);\n}\n\nfunction teardownHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n if (state.entries.delete(host)) {\n notifyRegistry(state);\n }\n}\n\nfunction writeBinding<H extends FactoryHost>(state: CellRegistryState<H>, host: H, item: GObject.Object | null): void {\n const entry = state.entries.get(host);\n\n if (entry === undefined) {\n return;\n }\n\n entry.item = item;\n notifyEntry(entry);\n}\n\nfunction bindHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n writeBinding(state, host, host.getItem());\n}\n\nfunction subscribeRegistry<H extends FactoryHost>(state: CellRegistryState<H>, onChange: () => void): () => void {\n state.listeners.add(onChange);\n\n return () => {\n state.listeners.delete(onChange);\n };\n}\n\nfunction getRegistryEntries<H extends FactoryHost>(state: CellRegistryState<H>): CellEntry<H>[] {\n state.snapshot ??= state.entries.values().toArray();\n\n return state.snapshot;\n}\n\nfunction guarded<H extends FactoryHost>(isHost: HostGuard<H>, run: (host: H) => void): (host: GObject.Object) => void {\n return (host) => {\n if (isHost(host)) {\n run(host);\n }\n };\n}\n\nfunction createHandlers<H extends FactoryHost>(state: CellRegistryState<H>): FactoryHandlers {\n const { isHost } = state;\n\n return {\n onSetup: guarded(isHost, (host) => {\n setupHost(state, host);\n }),\n onBind: guarded(isHost, (host) => {\n bindHost(state, host);\n }),\n onUnbind: guarded(isHost, (host) => {\n writeBinding(state, host, null);\n }),\n onTeardown: guarded(isHost, (host) => {\n teardownHost(state, host);\n }),\n };\n}\n\nfunction createCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const state: CellRegistryState<H> = {\n ...options,\n size,\n entries: new Map(),\n snapshot: null,\n listeners: new Set(),\n serial: 0,\n version: 0,\n };\n\n return {\n handlers: createHandlers(state),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRegistry(state, onChange),\n getVersion: () => state.version,\n getEntries: () => getRegistryEntries(state),\n };\n}\n\nfunction useCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const [registry] = useState(() => createCellRegistry(options, size));\n\n useLayoutEffect(() => {\n registry.setSize(size);\n });\n\n return registry;\n}\n\nfunction useItemCells(size: CellSize): CellRegistry<Gtk.ListItem> {\n return useCellRegistry(CELL_OPTIONS, size);\n}\n\nfunction useHeaderCells(size: CellSize): CellRegistry<Gtk.ListHeader> {\n return useCellRegistry(HEADER_OPTIONS, size);\n}\n\nfunction isRowWanted(options: ItemSlotOptions, item: ListItem): boolean {\n return options.expandedIds?.includes(item.id) ?? false;\n}\n\nfunction itemArgs(item: ListItem, options: ItemSlotOptions): ListItemRenderArgs<unknown> {\n const args: ListItemRenderArgs<unknown> = { item: item.value, index: options.position ?? 0 };\n const row = options.row;\n\n if (row === null) {\n return args;\n }\n\n args.depth = row.getDepth();\n\n if (row.isExpandable()) {\n args.isExpanded = isRowWanted(options, item);\n }\n\n return args;\n}\n\nfunction slotFor(options: ItemSlotOptions): ItemSlot | null {\n const ref = slotRefFor(options.item);\n const item = ref === null ? undefined : options.collection.itemAt(ref);\n\n if (item === undefined) {\n return null;\n }\n\n return { item, row: options.row, args: itemArgs(item, options) };\n}\n\nfunction useItemSlot(\n entry: CellEntry<PositionedHost>,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): ItemSlot | null {\n const position = useProperty(entry.host, \"position\");\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const row = item instanceof Gtk.TreeListRow ? item : null;\n\n return slotFor({ item, position, row, collection, expandedIds });\n}\n\nfunction expanderDescriptionFor(\n slot: ItemSlot,\n descriptions: ExpanderDescriptions | null | undefined,\n): string | undefined {\n const { isExpanded } = slot.args;\n\n if (isExpanded === undefined || descriptions == null) {\n return undefined;\n }\n\n return isExpanded ? descriptions.collapse : descriptions.expand;\n}\n\nfunction wrapExpander(\n slot: ItemSlot,\n content: ReactNode,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n const { item, row } = slot;\n\n const expander: ReactNode =\n row === null\n ? (\n content\n )\n : (\n <GtkTreeExpander\n listRow={row}\n hideExpander={item.shouldHideExpander ?? false}\n indentForDepth={item.shouldIndentForDepth ?? true}\n indentForIcon={item.shouldIndentForIcon ?? true}\n accessibleDescription={expanderDescriptionFor(slot, descriptions)}\n >\n {content}\n </GtkTreeExpander>\n );\n\n return expander;\n}\n\nfunction itemBody(\n slot: ItemSlot | null,\n render: ListItemRenderer<never>,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n if (slot === null) {\n return null;\n }\n\n const renderItem = render as ListItemRenderer<unknown>;\n\n return wrapExpander(slot, renderItem(slot.args), descriptions);\n}\n\nfunction rowText(value: string | undefined): string | null {\n return value ?? null;\n}\n\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- reads the flag off a row, paired with rowText */\nfunction rowFlag(value: boolean | undefined): boolean {\n return value ?? true;\n}\n\nfunction rowPropsFor(slot: ItemSlot | null, rowProps: ListRowPropsResolver<never>): ResolvedRowProps {\n const resolve = rowProps as ListRowPropsResolver<unknown>;\n const props = slot === null ? NO_ROW_PROPS : resolve(slot.args);\n\n return {\n accessibleLabel: rowText(props.accessibleLabel),\n accessibleDescription: rowText(props.accessibleDescription),\n isActivatable: rowFlag(props.isActivatable),\n isFocusable: rowFlag(props.isFocusable),\n isSelectable: rowFlag(props.isSelectable),\n };\n}\n\nfunction setRowText(host: Gtk.ColumnViewRow, name: string, value: string | null): void {\n setObjectProperty(host, name, ROW_TEXT_DESCRIPTOR, value);\n}\n\nfunction applyRowProps(host: Gtk.ColumnViewRow, props: ResolvedRowProps): void {\n setRowText(host, \"accessible-label\", props.accessibleLabel);\n setRowText(host, \"accessible-description\", props.accessibleDescription);\n host.setActivatable(props.isActivatable);\n host.setFocusable(props.isFocusable);\n host.setSelectable(props.isSelectable);\n}\n\nfunction ItemCellImpl({ entry, render, collection, expandedIds, expanderDescriptions }: ItemCellProps): ReactNode {\n const slot = useItemSlot(entry, collection, expandedIds);\n const body = itemBody(slot, render, expanderDescriptions);\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction ItemRowImpl({ entry, rowProps, collection, expandedIds }: ItemRowProps): ReactNode {\n const slot = useItemSlot(entry, collection, expandedIds);\n const props = rowPropsFor(slot, rowProps);\n\n useLayoutEffect(() => {\n applyRowProps(entry.host, props);\n });\n\n return null;\n}\n\nfunction HeaderCellImpl({ entry, render, collection }: HeaderCellProps): ReactNode {\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const ref = slotRefFor(item);\n const renderHeader = render as ListSectionRenderer<unknown>;\n const body = ref === null ? null : renderHeader({ section: collection.sectionFor(ref.store.path) });\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction usePortalEntries<H extends FactoryHost>(registry: CellRegistry<H>): CellEntry<H>[] {\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n\n return registry.getEntries();\n}\n\nconst ItemPortals = ({\n registry,\n render,\n collection,\n expandedIds,\n expanderDescriptions,\n}: ItemPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <ItemCell\n key={entry.key}\n entry={entry}\n render={render}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n />\n ));\n\nconst RowPortals = ({ registry, rowProps, collection, expandedIds }: RowPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <ItemRow\n key={entry.key}\n entry={entry}\n rowProps={rowProps}\n collection={collection}\n expandedIds={expandedIds}\n />\n ));\n\nconst HeaderPortals = ({ registry, render, collection }: HeaderPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <HeaderCell key={entry.key} entry={entry} render={render} collection={collection} />\n ));\n\nconst useSectionHeader = (\n render: ListSectionRenderer<never> | null | undefined,\n collection: Collection,\n size: CellSize,\n): SectionHeaderSlot => {\n const registry = useHeaderCells(size);\n\n if (render == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { headerFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: <HeaderPortals registry={registry} render={render} collection={collection} />,\n };\n};\n\nconst useRowProps = (\n rowProps: ListRowPropsResolver<never> | null | undefined,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): RowSlot => {\n const registry = useCellRegistry(ROW_OPTIONS, NO_SIZE);\n\n if (rowProps == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { rowFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: (\n <RowPortals registry={registry} rowProps={rowProps} collection={collection} expandedIds={expandedIds} />\n ),\n };\n};\n\nexport {\n useItemCells,\n useRowProps,\n useSectionHeader,\n ItemPortals,\n type CellSize,\n};\n"]}
@@ -1,21 +1,17 @@
1
- import type { Item, Section } from "../types.js";
1
+ import type { ListItem, ListSection } from "../types.js";
2
2
  type Level = {
3
- key: string;
4
- ids: string[];
5
- isExpandable: boolean[];
3
+ path: string;
4
+ items: ListItem[];
5
+ expandableFlags: boolean[];
6
6
  };
7
7
  type CollectionIndex = {
8
8
  isTree: boolean;
9
- size: number;
10
9
  groups: Level[];
11
10
  children: Map<string, Level>;
12
- has: (id: string) => boolean;
13
- itemFor: (id: string) => Item | undefined;
14
- sectionFor: (id: string) => unknown;
15
- positionFor: (id: string) => number;
11
+ itemAt: (levelPath: string, slot: number) => ListItem | undefined;
12
+ sectionFor: (levelPath: string) => unknown;
13
+ expandablePathsFor: (id: string) => string[];
16
14
  };
17
- declare const ROOT_LEVEL_KEY = "";
18
- declare const childLevelKey: (id: string) => string;
19
- declare function createCollectionIndex(items: Item[] | undefined, sections: Section[] | undefined, isFlat: boolean): CollectionIndex;
20
- export { createCollectionIndex, childLevelKey, ROOT_LEVEL_KEY, type CollectionIndex, type Level };
15
+ declare function createCollectionIndex(items: ListItem[] | undefined, sections: ListSection[] | undefined, isFlat: boolean): CollectionIndex;
16
+ export { createCollectionIndex, type CollectionIndex, type Level };
21
17
  //# sourceMappingURL=collection-index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection-index.d.ts","sourceRoot":"","sources":["../../src/internal/collection-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEjD,KAAK,KAAK,GAAG;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,YAAY,EAAE,OAAO,EAAE,CAAC;CAC3B,CAAC;AAEF,KAAK,eAAe,GAAG;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,EAAE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UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3C,kBAAkB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;CAChD,CAAC;AA2EF,iBAAS,qBAAqB,CAC1B,KAAK,EAAE,QAAQ,EAAE,GAAG,SAAS,EAC7B,QAAQ,EAAE,WAAW,EAAE,GAAG,SAAS,EACnC,MAAM,EAAE,OAAO,GAChB,eAAe,CAsBjB;AAED,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,KAAK,EAAE,CAAC"}
@@ -1,77 +1,43 @@
1
- const ROOT_LEVEL_KEY = "";
1
+ import { encodePart } from "./keys.js";
2
+ const NO_PATHS = [];
2
3
  const hasChildren = (item) => item.children !== undefined && item.children.length > 0;
3
- const childLevelKey = (id) => `child:${id}`;
4
- function collectChildren(state, level, item) {
5
- if (!state.isTree) {
4
+ function pushPath(table, id, path) {
5
+ const existing = table.get(id);
6
+ if (existing === undefined) {
7
+ table.set(id, [path]);
6
8
  return;
7
9
  }
10
+ existing.push(path);
11
+ }
12
+ function collectChildren(state, level, slotPath, item) {
8
13
  const canExpand = hasChildren(item);
9
- level.isExpandable.push(canExpand);
14
+ level.expandableFlags.push(canExpand);
10
15
  if (!canExpand) {
11
16
  return;
12
17
  }
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: [], isExpandable: [] };
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
- }
23
- return level;
24
- }
25
- function buildPositions(state) {
26
- const positions = new Map();
27
- const starts = [];
28
- let offset = 0;
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;
18
+ pushPath(state.expandablePaths, item.id, slotPath);
19
+ state.children.set(slotPath, collectLevel(state, slotPath, item.children ?? []));
38
20
  }
39
- function positionFor(state, id) {
40
- if (state.isTree) {
41
- return -1;
42
- }
43
- if (state.positions === null) {
44
- buildPositions(state);
45
- }
46
- return state.positions?.get(id) ?? -1;
47
- }
48
- function sectionAt(starts, position) {
49
- let low = 0;
50
- let high = starts.length - 1;
51
- while (low < high) {
52
- const middle = Math.ceil((low + high) / 2);
53
- if ((starts[middle] ?? 0) <= position) {
54
- low = middle;
55
- }
56
- else {
57
- high = middle - 1;
58
- }
21
+ function collectLevel(state, path, items) {
22
+ const level = { path, items, expandableFlags: [] };
23
+ state.levels.set(path, level);
24
+ if (!state.isTree) {
25
+ return level;
59
26
  }
60
- return low;
61
- }
62
- function sectionFor(state, id) {
63
- const sections = state.sections;
64
- const position = positionFor(state, id);
65
- if (sections === undefined || position < 0 || state.starts === null) {
66
- return undefined;
27
+ for (const [slot, item] of items.entries()) {
28
+ collectChildren(state, level, path + encodePart(String(slot)), item);
67
29
  }
68
- return sections[sectionAt(state.starts, position)]?.value;
30
+ return level;
69
31
  }
70
32
  function buildGroups(state, source, sections) {
71
33
  if (sections === undefined) {
72
- return [collectLevel(state, ROOT_LEVEL_KEY, source)];
34
+ return [collectLevel(state, encodePart("0"), source)];
73
35
  }
74
- return sections.map((section) => collectLevel(state, section.id, section.data));
36
+ return sections.map((section, group) => {
37
+ const path = encodePart(String(group));
38
+ state.sectionValues.set(path, section.value);
39
+ return collectLevel(state, path, section.data);
40
+ });
75
41
  }
76
42
  function isTreeSource(source, sections, isFlat) {
77
43
  if (sections !== undefined || isFlat) {
@@ -85,22 +51,19 @@ function createCollectionIndex(items, sections, isFlat) {
85
51
  isTree: isTreeSource(source, sections, isFlat),
86
52
  groups: [],
87
53
  children: new Map(),
88
- itemsById: new Map(),
89
- sections,
90
- positions: null,
91
- starts: null,
54
+ levels: new Map(),
55
+ expandablePaths: new Map(),
56
+ sectionValues: new Map(),
92
57
  };
93
58
  state.groups = buildGroups(state, source, sections);
94
59
  return {
95
60
  isTree: state.isTree,
96
- size: state.itemsById.size,
97
61
  groups: state.groups,
98
62
  children: state.children,
99
- has: (id) => state.itemsById.has(id),
100
- itemFor: (id) => state.itemsById.get(id),
101
- sectionFor: (id) => sectionFor(state, id),
102
- positionFor: (id) => positionFor(state, id),
63
+ itemAt: (levelPath, slot) => state.levels.get(levelPath)?.items[slot],
64
+ sectionFor: (levelPath) => state.sectionValues.get(levelPath),
65
+ expandablePathsFor: (id) => state.expandablePaths.get(id) ?? NO_PATHS,
103
66
  };
104
67
  }
105
- export { createCollectionIndex, childLevelKey, ROOT_LEVEL_KEY };
68
+ export { createCollectionIndex };
106
69
  //# sourceMappingURL=collection-index.js.map