@gtkx/components 0.21.0 → 1.0.0-rc.1

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 (185) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +173 -0
  3. package/dist/cell.d.ts +30 -0
  4. package/dist/cell.d.ts.map +1 -0
  5. package/dist/cell.js +45 -0
  6. package/dist/cell.js.map +1 -0
  7. package/dist/column-view-column.d.ts +24 -14
  8. package/dist/column-view-column.d.ts.map +1 -1
  9. package/dist/column-view-column.js +19 -40
  10. package/dist/column-view-column.js.map +1 -1
  11. package/dist/column-view.d.ts +25 -11
  12. package/dist/column-view.d.ts.map +1 -1
  13. package/dist/column-view.js +53 -83
  14. package/dist/column-view.js.map +1 -1
  15. package/dist/constraint-layout-apply.d.ts +50 -1
  16. package/dist/constraint-layout-apply.d.ts.map +1 -1
  17. package/dist/constraint-layout-apply.js.map +1 -1
  18. package/dist/constraint-layout.d.ts +8 -1
  19. package/dist/constraint-layout.d.ts.map +1 -1
  20. package/dist/constraint-layout.js +12 -9
  21. package/dist/constraint-layout.js.map +1 -1
  22. package/dist/drop-down.d.ts +26 -36
  23. package/dist/drop-down.d.ts.map +1 -1
  24. package/dist/drop-down.js +47 -87
  25. package/dist/drop-down.js.map +1 -1
  26. package/dist/fixed.d.ts +26 -0
  27. package/dist/fixed.d.ts.map +1 -0
  28. package/dist/fixed.js +40 -0
  29. package/dist/fixed.js.map +1 -0
  30. package/dist/grid-view.d.ts +13 -10
  31. package/dist/grid-view.d.ts.map +1 -1
  32. package/dist/grid-view.js +30 -16
  33. package/dist/grid-view.js.map +1 -1
  34. package/dist/grid.d.ts +27 -0
  35. package/dist/grid.d.ts.map +1 -0
  36. package/dist/grid.js +48 -0
  37. package/dist/grid.js.map +1 -0
  38. package/dist/hooks/use-cell-containers.d.ts +18 -0
  39. package/dist/hooks/use-cell-containers.d.ts.map +1 -0
  40. package/dist/hooks/{use-realized-slots.js → use-cell-containers.js} +18 -17
  41. package/dist/hooks/use-cell-containers.js.map +1 -0
  42. package/dist/hooks/use-collection-model.d.ts +26 -0
  43. package/dist/hooks/use-collection-model.d.ts.map +1 -0
  44. package/dist/hooks/use-collection-model.js +35 -0
  45. package/dist/hooks/use-collection-model.js.map +1 -0
  46. package/dist/hooks/use-collection-widget.d.ts +28 -0
  47. package/dist/hooks/use-collection-widget.d.ts.map +1 -0
  48. package/dist/hooks/use-collection-widget.js +21 -0
  49. package/dist/hooks/use-collection-widget.js.map +1 -0
  50. package/dist/hooks/use-drop-down-selection.d.ts +7 -6
  51. package/dist/hooks/use-drop-down-selection.d.ts.map +1 -1
  52. package/dist/hooks/use-drop-down-selection.js +6 -6
  53. package/dist/hooks/use-drop-down-selection.js.map +1 -1
  54. package/dist/hooks/use-expansion-model.d.ts +12 -0
  55. package/dist/hooks/use-expansion-model.d.ts.map +1 -0
  56. package/dist/hooks/use-expansion-model.js +71 -0
  57. package/dist/hooks/use-expansion-model.js.map +1 -0
  58. package/dist/hooks/use-header-menu.d.ts.map +1 -1
  59. package/dist/hooks/use-header-menu.js +12 -24
  60. package/dist/hooks/use-header-menu.js.map +1 -1
  61. package/dist/hooks/use-installed-model.d.ts +4 -0
  62. package/dist/hooks/use-installed-model.d.ts.map +1 -0
  63. package/dist/hooks/use-installed-model.js +15 -0
  64. package/dist/hooks/use-installed-model.js.map +1 -0
  65. package/dist/hooks/use-list-model.d.ts +14 -15
  66. package/dist/hooks/use-list-model.d.ts.map +1 -1
  67. package/dist/hooks/use-list-model.js +61 -34
  68. package/dist/hooks/use-list-model.js.map +1 -1
  69. package/dist/hooks/use-placed-child.d.ts +18 -0
  70. package/dist/hooks/use-placed-child.d.ts.map +1 -0
  71. package/dist/hooks/use-placed-child.js +47 -0
  72. package/dist/hooks/use-placed-child.js.map +1 -0
  73. package/dist/hooks/use-selection-model.d.ts +4 -3
  74. package/dist/hooks/use-selection-model.d.ts.map +1 -1
  75. package/dist/hooks/use-selection-model.js +8 -16
  76. package/dist/hooks/use-selection-model.js.map +1 -1
  77. package/dist/hooks/use-sort-handler.d.ts +10 -5
  78. package/dist/hooks/use-sort-handler.d.ts.map +1 -1
  79. package/dist/hooks/use-sort-handler.js +2 -2
  80. package/dist/hooks/use-sort-handler.js.map +1 -1
  81. package/dist/index.d.ts +11 -17
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +6 -13
  84. package/dist/index.js.map +1 -1
  85. package/dist/list-view.d.ts +17 -9
  86. package/dist/list-view.d.ts.map +1 -1
  87. package/dist/list-view.js +49 -24
  88. package/dist/list-view.js.map +1 -1
  89. package/dist/menu-items.d.ts.map +1 -1
  90. package/dist/menu-items.js.map +1 -1
  91. package/dist/menu.d.ts +6 -10
  92. package/dist/menu.d.ts.map +1 -1
  93. package/dist/menu.js +7 -9
  94. package/dist/menu.js.map +1 -1
  95. package/dist/overlay.d.ts +24 -0
  96. package/dist/overlay.d.ts.map +1 -0
  97. package/dist/overlay.js +49 -0
  98. package/dist/overlay.js.map +1 -0
  99. package/dist/size-group.d.ts +20 -0
  100. package/dist/size-group.d.ts.map +1 -0
  101. package/dist/size-group.js +57 -0
  102. package/dist/size-group.js.map +1 -0
  103. package/dist/types.d.ts +43 -173
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/types.js.map +1 -1
  106. package/dist/utils/{realized-slot-store.d.ts → cell-container-store.d.ts} +7 -9
  107. package/dist/utils/cell-container-store.d.ts.map +1 -0
  108. package/dist/utils/{realized-slot-store.js → cell-container-store.js} +9 -14
  109. package/dist/utils/cell-container-store.js.map +1 -0
  110. package/dist/utils/item-models.d.ts +10 -0
  111. package/dist/utils/item-models.d.ts.map +1 -0
  112. package/dist/utils/{position-only-model.js → item-models.js} +13 -14
  113. package/dist/utils/item-models.js.map +1 -0
  114. package/dist/utils/item-resolver.d.ts +14 -17
  115. package/dist/utils/item-resolver.d.ts.map +1 -1
  116. package/dist/utils/item-resolver.js +34 -43
  117. package/dist/utils/item-resolver.js.map +1 -1
  118. package/dist/utils/list-item-flatten.d.ts +16 -24
  119. package/dist/utils/list-item-flatten.d.ts.map +1 -1
  120. package/dist/utils/list-item-flatten.js +16 -36
  121. package/dist/utils/list-item-flatten.js.map +1 -1
  122. package/package.json +52 -53
  123. package/src/cell.tsx +144 -0
  124. package/src/column-view-column.tsx +57 -48
  125. package/src/column-view.tsx +130 -146
  126. package/src/constraint-layout-apply.ts +53 -1
  127. package/src/constraint-layout.tsx +18 -13
  128. package/src/drop-down.tsx +129 -196
  129. package/src/fixed.tsx +86 -0
  130. package/src/grid-view.tsx +52 -44
  131. package/src/grid.tsx +88 -0
  132. package/src/hooks/{use-realized-slots.ts → use-cell-containers.ts} +30 -30
  133. package/src/hooks/use-collection-model.ts +60 -0
  134. package/src/hooks/use-collection-widget.ts +47 -0
  135. package/src/hooks/use-drop-down-selection.ts +12 -13
  136. package/src/hooks/use-expansion-model.ts +82 -0
  137. package/src/hooks/use-header-menu.ts +24 -23
  138. package/src/hooks/use-installed-model.ts +20 -0
  139. package/src/hooks/use-list-model.ts +103 -87
  140. package/src/hooks/use-placed-child.ts +79 -0
  141. package/src/hooks/use-selection-model.ts +11 -18
  142. package/src/hooks/use-sort-handler.ts +13 -8
  143. package/src/index.ts +25 -27
  144. package/src/list-view.tsx +120 -57
  145. package/src/menu.tsx +12 -14
  146. package/src/overlay.tsx +88 -0
  147. package/src/size-group.tsx +96 -0
  148. package/src/types.ts +55 -206
  149. package/src/utils/{realized-slot-store.ts → cell-container-store.ts} +13 -25
  150. package/src/utils/{position-only-model.ts → item-models.ts} +26 -28
  151. package/src/utils/item-resolver.ts +54 -59
  152. package/src/utils/list-item-flatten.ts +33 -56
  153. package/dist/collection-view.d.ts +0 -30
  154. package/dist/collection-view.d.ts.map +0 -1
  155. package/dist/collection-view.js +0 -52
  156. package/dist/collection-view.js.map +0 -1
  157. package/dist/contexts/column-view-context.d.ts +0 -17
  158. package/dist/contexts/column-view-context.d.ts.map +0 -1
  159. package/dist/contexts/column-view-context.js +0 -10
  160. package/dist/contexts/column-view-context.js.map +0 -1
  161. package/dist/hooks/use-model-installation.d.ts +0 -9
  162. package/dist/hooks/use-model-installation.d.ts.map +0 -1
  163. package/dist/hooks/use-model-installation.js +0 -20
  164. package/dist/hooks/use-model-installation.js.map +0 -1
  165. package/dist/hooks/use-realized-slots.d.ts +0 -20
  166. package/dist/hooks/use-realized-slots.d.ts.map +0 -1
  167. package/dist/hooks/use-realized-slots.js.map +0 -1
  168. package/dist/list-portal-host.d.ts +0 -11
  169. package/dist/list-portal-host.d.ts.map +0 -1
  170. package/dist/list-portal-host.js +0 -8
  171. package/dist/list-portal-host.js.map +0 -1
  172. package/dist/list-slot.d.ts +0 -14
  173. package/dist/list-slot.d.ts.map +0 -1
  174. package/dist/list-slot.js +0 -29
  175. package/dist/list-slot.js.map +0 -1
  176. package/dist/utils/position-only-model.d.ts +0 -10
  177. package/dist/utils/position-only-model.d.ts.map +0 -1
  178. package/dist/utils/position-only-model.js.map +0 -1
  179. package/dist/utils/realized-slot-store.d.ts.map +0 -1
  180. package/dist/utils/realized-slot-store.js.map +0 -1
  181. package/src/collection-view.tsx +0 -125
  182. package/src/contexts/column-view-context.ts +0 -28
  183. package/src/hooks/use-model-installation.ts +0 -25
  184. package/src/list-portal-host.tsx +0 -27
  185. package/src/list-slot.tsx +0 -56
@@ -1,49 +1,74 @@
1
1
  import { useLayoutEffect, useMemo, useRef } from "react";
2
- import { createControlledResolver, createModelResolver, createSectionHeaderResolver, } from "../utils/item-resolver.js";
2
+ import { createFlatModel, createSectionModel, createTreeModel, resizeFlatModel, retagRows, } from "../utils/item-models.js";
3
+ import { createItemResolver, createSectionHeaderResolver, createTreeResolver, } from "../utils/item-resolver.js";
3
4
  import { detectStructure, structuralSignature } from "../utils/list-item-flatten.js";
4
- import { createFlatModel, createSectionModel, createTreeModel, resizeFlatModel, retagRows, } from "../utils/position-only-model.js";
5
- const controlledSignature = (structure, autoexpand, items) => (structure === "flat" ? "" : `${structure}|${autoexpand ? 1 : 0}|${structuralSignature(items)}`);
6
- const buildControlledState = (items, autoexpand, structure, signature) => {
5
+ const sectionRows = (sections) => {
6
+ if (sections === undefined)
7
+ return [];
8
+ const rows = [];
9
+ for (const section of sections)
10
+ rows.push(...section.data);
11
+ return rows;
12
+ };
13
+ const sectionSignature = (sections) => {
14
+ if (sections === undefined)
15
+ return "";
16
+ const parts = [];
17
+ for (const section of sections) {
18
+ parts.push(`${section.id}{${structuralSignature(section.data)}}`);
19
+ }
20
+ return parts.join(",");
21
+ };
22
+ const signatureOf = (structure, items, sections) => {
23
+ if (structure === "sections")
24
+ return `sections|${sectionSignature(sections)}`;
25
+ return structure === "flat" ? "" : `${structure}|${structuralSignature(items)}`;
26
+ };
27
+ const buildState = (input) => {
28
+ const { items, sections, structure, signature } = input;
7
29
  const rowValues = new WeakMap();
8
30
  const placeholdersById = new Map();
9
31
  let model;
32
+ let treeModel = null;
10
33
  let flatModel;
11
34
  if (structure === "sections") {
12
- model = createSectionModel(items ?? []);
35
+ model = createSectionModel(sections ?? []);
13
36
  }
14
37
  else if (structure === "tree") {
15
- model = createTreeModel(items ?? [], autoexpand, rowValues, placeholdersById);
38
+ treeModel = createTreeModel(items ?? [], rowValues, placeholdersById);
39
+ model = treeModel;
16
40
  }
17
41
  else {
18
42
  flatModel = createFlatModel(items?.length ?? 0);
19
43
  model = flatModel;
20
44
  }
21
- return { model, flatModel, items, structure, autoexpand, signature, rowValues, placeholdersById };
45
+ return { model, treeModel, flatModel, items, sections, structure, signature, rowValues, placeholdersById };
22
46
  };
23
- const resolveControlledState = (prev, items, autoexpand) => {
24
- if (prev !== null && prev.items === items && prev.autoexpand === autoexpand)
47
+ const resolveState = (prev, items, sections) => {
48
+ if (prev !== null && prev.items === items && prev.sections === sections) {
25
49
  return prev;
26
- const structure = detectStructure(items);
27
- const signature = controlledSignature(structure, autoexpand, items);
50
+ }
51
+ const structure = sections !== undefined ? "sections" : detectStructure(items);
52
+ const signature = signatureOf(structure, items, sections);
53
+ const input = { items, sections, structure, signature };
28
54
  if (prev === null || prev.structure !== structure) {
29
- return buildControlledState(items, autoexpand, structure, signature);
55
+ return buildState(input);
30
56
  }
31
57
  if (structure !== "flat" && prev.signature !== signature) {
32
- return buildControlledState(items, autoexpand, structure, signature);
58
+ return buildState(input);
33
59
  }
34
- if (structure !== "flat") {
60
+ if (structure === "tree") {
35
61
  retagRows(items ?? [], prev.rowValues, prev.placeholdersById);
36
62
  }
37
63
  prev.items = items;
38
- prev.autoexpand = autoexpand;
64
+ prev.sections = sections;
39
65
  prev.signature = signature;
40
66
  return prev;
41
67
  };
42
- const useControlledModel = (mode) => {
43
- const { items } = mode;
44
- const autoexpand = mode.autoexpand ?? false;
68
+ export const useListModel = (input) => {
69
+ const { items, sections } = input;
45
70
  const stateRef = useRef(null);
46
- const state = resolveControlledState(stateRef.current, items, autoexpand);
71
+ const state = resolveState(stateRef.current, items, sections);
47
72
  stateRef.current = state;
48
73
  const { structure, flatModel } = state;
49
74
  useLayoutEffect(() => {
@@ -51,20 +76,22 @@ const useControlledModel = (mode) => {
51
76
  resizeFlatModel(flatModel, items?.length ?? 0);
52
77
  }
53
78
  }, [flatModel, items]);
54
- const resolver = useMemo(() => createControlledResolver(items, structure !== "flat" && autoexpand, state.rowValues), [items, structure, autoexpand, state.rowValues]);
55
- const headerResolver = useMemo(() => createSectionHeaderResolver(structure === "sections" ? items : undefined), [items, structure]);
56
- return { model: state.model, resolver, headerResolver };
57
- };
58
- const useUncontrolledModel = (mode) => {
59
- const { model } = mode;
60
- const resolver = useMemo(() => createModelResolver(model), [model]);
61
- const headerResolver = useMemo(() => createSectionHeaderResolver(undefined), []);
62
- return { model, resolver, headerResolver };
63
- };
64
- export const useListModel = (mode) => {
65
- const controlled = useControlledModel(mode.model === undefined ? { items: mode.items, autoexpand: mode.autoexpand } : { items: [] });
66
- const uncontrolled = useUncontrolledModel(mode.model === undefined ? { model: EMPTY_MODEL } : { model: mode.model });
67
- return mode.model === undefined ? controlled : uncontrolled;
79
+ const resolver = useMemo(() => {
80
+ if (structure === "sections") {
81
+ return createItemResolver(sectionRows(sections), true, state.rowValues);
82
+ }
83
+ if (structure === "tree" && state.treeModel !== null) {
84
+ return createTreeResolver(items, state.rowValues, state.treeModel);
85
+ }
86
+ return createItemResolver(items, false, state.rowValues);
87
+ }, [items, sections, structure, state.rowValues, state.treeModel]);
88
+ const headerResolver = useMemo(() => createSectionHeaderResolver(structure === "sections" ? sections : undefined), [sections, structure]);
89
+ return {
90
+ model: state.model,
91
+ treeModel: state.treeModel,
92
+ resolver,
93
+ headerResolver,
94
+ rowValues: state.rowValues,
95
+ };
68
96
  };
69
- const EMPTY_MODEL = createFlatModel(0);
70
97
  //# sourceMappingURL=use-list-model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-list-model.js","sourceRoot":"","sources":["../../src/hooks/use-list-model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EACH,wBAAwB,EACxB,mBAAmB,EACnB,2BAA2B,GAG9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAsB,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,SAAS,GACZ,MAAM,iCAAiC,CAAC;AA+BzC,MAAM,mBAAmB,GAAG,CACxB,SAAwB,EACxB,UAAmB,EACnB,KAAmC,EAC7B,EAAE,CAAC,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAE9G,MAAM,oBAAoB,GAAG,CACzB,KAAmC,EACnC,UAAmB,EACnB,SAAwB,EACxB,SAAiB,EACI,EAAE;IAC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C,SAAS,CAAC,EACxF,CAAC,QAAQ,EAAE,SAAS,CAAC,CACxB,CAAC;IAEF,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ;QACR,cAAc;QACd,SAAS,EAAE,KAAK,CAAC,SAAS;KAC7B,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gio from \"@gtkx/gi/gio\";\nimport type * as GObject from \"@gtkx/gi/gobject\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport { useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { ItemNode, SectionNode } from \"../types.js\";\nimport {\n createFlatModel,\n createSectionModel,\n createTreeModel,\n resizeFlatModel,\n retagRows,\n} from \"../utils/item-models.js\";\nimport {\n createItemResolver,\n createSectionHeaderResolver,\n createTreeResolver,\n type ItemResolver,\n type RowValue,\n} from \"../utils/item-resolver.js\";\nimport { detectStructure, type ListStructure, structuralSignature } from \"../utils/list-item-flatten.js\";\n\ntype ListModelInput<T, S> = {\n items: ItemNode<T>[] | undefined;\n sections?: SectionNode<S, T>[] | undefined;\n};\n\ntype ListModelResult<T, S> = {\n model: Gio.ListModel;\n treeModel: Gtk.TreeListModel | null;\n resolver: ItemResolver<T, S>;\n headerResolver: ItemResolver<T, S>;\n rowValues: WeakMap<GObject.Object, RowValue<T>>;\n};\n\ntype ListModelStructure = \"sections\" | ListStructure;\n\ntype ListModelState<T, S> = {\n model: Gio.ListModel;\n treeModel: Gtk.TreeListModel | null;\n flatModel: Gtk.StringList | undefined;\n items: ItemNode<T>[] | undefined;\n sections: SectionNode<S, T>[] | undefined;\n structure: ListModelStructure;\n signature: string;\n rowValues: WeakMap<GObject.Object, RowValue<T>>;\n placeholdersById: Map<string, GObject.Object>;\n};\n\nconst sectionRows = <T, S>(sections: SectionNode<S, T>[] | undefined): ItemNode<T>[] => {\n if (sections === undefined) return [];\n const rows: ItemNode<T>[] = [];\n for (const section of sections) rows.push(...section.data);\n return rows;\n};\n\nconst sectionSignature = <T, S>(sections: SectionNode<S, T>[] | undefined): string => {\n if (sections === undefined) return \"\";\n const parts: string[] = [];\n for (const section of sections) {\n parts.push(`${section.id}{${structuralSignature(section.data)}}`);\n }\n return parts.join(\",\");\n};\n\nconst signatureOf = <T, S>(\n structure: ListModelStructure,\n items: ItemNode<T>[] | undefined,\n sections: SectionNode<S, T>[] | undefined,\n): string => {\n if (structure === \"sections\") return `sections|${sectionSignature(sections)}`;\n return structure === \"flat\" ? \"\" : `${structure}|${structuralSignature(items)}`;\n};\n\ntype ListModelInternalInput<T, S> = {\n items: ItemNode<T>[] | undefined;\n sections: SectionNode<S, T>[] | undefined;\n structure: ListModelStructure;\n signature: string;\n};\n\nconst buildState = <T, S>(input: ListModelInternalInput<T, S>): ListModelState<T, S> => {\n const { items, sections, structure, signature } = input;\n const rowValues = new WeakMap<GObject.Object, RowValue<T>>();\n const placeholdersById = new Map<string, GObject.Object>();\n let model: Gio.ListModel;\n let treeModel: Gtk.TreeListModel | null = null;\n let flatModel: Gtk.StringList | undefined;\n if (structure === \"sections\") {\n model = createSectionModel(sections ?? []);\n } else if (structure === \"tree\") {\n treeModel = createTreeModel(items ?? [], rowValues, placeholdersById);\n model = treeModel;\n } else {\n flatModel = createFlatModel(items?.length ?? 0);\n model = flatModel;\n }\n return { model, treeModel, flatModel, items, sections, structure, signature, rowValues, placeholdersById };\n};\n\nconst resolveState = <T, S>(\n prev: ListModelState<T, S> | null,\n items: ItemNode<T>[] | undefined,\n sections: SectionNode<S, T>[] | undefined,\n): ListModelState<T, S> => {\n if (prev !== null && prev.items === items && prev.sections === sections) {\n return prev;\n }\n const structure: ListModelStructure = sections !== undefined ? \"sections\" : detectStructure(items);\n const signature = signatureOf(structure, items, sections);\n const input: ListModelInternalInput<T, S> = { items, sections, structure, signature };\n if (prev === null || prev.structure !== structure) {\n return buildState(input);\n }\n if (structure !== \"flat\" && prev.signature !== signature) {\n return buildState(input);\n }\n if (structure === \"tree\") {\n retagRows(items ?? [], prev.rowValues, prev.placeholdersById);\n }\n prev.items = items;\n prev.sections = sections;\n prev.signature = signature;\n return prev;\n};\n\nexport const useListModel = <T, S>(input: ListModelInput<T, S>): ListModelResult<T, S> => {\n const { items, sections } = input;\n const stateRef = useRef<ListModelState<T, S> | null>(null);\n const state = resolveState(stateRef.current, items, sections);\n stateRef.current = state;\n const { structure, flatModel } = state;\n\n useLayoutEffect(() => {\n if (flatModel !== undefined) {\n resizeFlatModel(flatModel, items?.length ?? 0);\n }\n }, [flatModel, items]);\n\n const resolver = useMemo(() => {\n if (structure === \"sections\") {\n return createItemResolver<T, S>(sectionRows(sections), true, state.rowValues);\n }\n if (structure === \"tree\" && state.treeModel !== null) {\n return createTreeResolver<T, S>(items, state.rowValues, state.treeModel);\n }\n return createItemResolver<T, S>(items, false, state.rowValues);\n }, [items, sections, structure, state.rowValues, state.treeModel]);\n\n const headerResolver = useMemo(\n () => createSectionHeaderResolver<T, S>(structure === \"sections\" ? sections : undefined),\n [sections, structure],\n );\n\n return {\n model: state.model,\n treeModel: state.treeModel,\n resolver,\n headerResolver,\n rowValues: state.rowValues,\n };\n};\n"]}
@@ -0,0 +1,18 @@
1
+ import type * as GObject from "@gtkx/gi/gobject";
2
+ import { type Context, type ReactNode, type Ref, type RefCallback, type RefObject } from "react";
3
+ export type ParentContext<T> = {
4
+ Context: Context<RefObject<T | null> | null>;
5
+ useParentRef: () => RefObject<T | null>;
6
+ };
7
+ export declare const createParentContext: <T>(orphanMessage: string) => ParentContext<T>;
8
+ export type PlacedChildRender<T> = (ref: RefCallback<T>) => ReactNode;
9
+ export type PlacedChildOptions<T extends GObject.Object, P> = {
10
+ render: PlacedChildRender<T>;
11
+ ref?: Ref<T | null> | undefined;
12
+ placement: P;
13
+ samePlacement: (a: P, b: P) => boolean;
14
+ place: (object: T, placement: P, previous: P | undefined) => void;
15
+ release: (object: T) => void;
16
+ };
17
+ export declare const usePlacedChild: <T extends GObject.Object, P>(options: PlacedChildOptions<T, P>) => ReactNode;
18
+ //# sourceMappingURL=use-placed-child.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-placed-child.d.ts","sourceRoot":"","sources":["../../src/hooks/use-placed-child.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EACH,KAAK,OAAO,EAEZ,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,SAAS,EAKjB,MAAM,OAAO,CAAC;AAEf,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7C,YAAY,EAAE,MAAM,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,CAAC,iBAAiB,MAAM,KAAG,aAAa,CAAC,CAAC,CAU7E,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;AAEtE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI;IAC1D,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,CAAC,CAAC;IACb,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IACvC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;IAClE,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,OAAO,CAAC,MAAM,EAAE,CAAC,WAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,SAkC/F,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { createPortal, rootElement } from "@gtkx/react";
2
+ import { useMergeRefs } from "@gtkx/react/internal";
3
+ import { createContext, useCallback, useContext, useLayoutEffect, useRef, } from "react";
4
+ export const createParentContext = (orphanMessage) => {
5
+ const context = createContext(null);
6
+ return {
7
+ Context: context,
8
+ useParentRef: () => {
9
+ const ref = useContext(context);
10
+ if (!ref)
11
+ throw new Error(orphanMessage);
12
+ return ref;
13
+ },
14
+ };
15
+ };
16
+ export const usePlacedChild = (options) => {
17
+ const { render, ref, placement, samePlacement, place, release } = options;
18
+ const objectRef = useRef(null);
19
+ const appliedRef = useRef(null);
20
+ const captureObject = useCallback((object) => {
21
+ objectRef.current = object;
22
+ }, []);
23
+ const setObjectRef = useMergeRefs(ref, captureObject);
24
+ useLayoutEffect(() => {
25
+ const object = objectRef.current;
26
+ const applied = appliedRef.current;
27
+ if (applied !== null && applied.object !== object) {
28
+ release(applied.object);
29
+ appliedRef.current = null;
30
+ }
31
+ if (object === null)
32
+ return;
33
+ const current = appliedRef.current;
34
+ if (current === null || !samePlacement(current.placement, placement)) {
35
+ place(object, placement, current?.placement);
36
+ appliedRef.current = { object, placement };
37
+ }
38
+ });
39
+ useLayoutEffect(() => () => {
40
+ const applied = appliedRef.current;
41
+ if (applied !== null)
42
+ release(applied.object);
43
+ appliedRef.current = null;
44
+ }, []);
45
+ return createPortal(render(setObjectRef), rootElement);
46
+ };
47
+ //# sourceMappingURL=use-placed-child.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-placed-child.js","sourceRoot":"","sources":["../../src/hooks/use-placed-child.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAA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O,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC9B,CAAC;QACD,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO;QAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YACnE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YAC7C,UAAU,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/C,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,eAAe,CACX,GAAG,EAAE,CAAC,GAAG,EAAE;QACP,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC9C,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,CAAC,EACD,EAAE,CACL,CAAC;IAEF,OAAO,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC,CAAC;AAC3D,CAAC,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport { createPortal, rootElement } from \"@gtkx/react\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport {\n type Context,\n createContext,\n type ReactNode,\n type Ref,\n type RefCallback,\n type RefObject,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n} from \"react\";\n\nexport type ParentContext<T> = {\n Context: Context<RefObject<T | null> | null>;\n useParentRef: () => RefObject<T | null>;\n};\n\nexport const createParentContext = <T>(orphanMessage: string): ParentContext<T> => {\n const context = createContext<RefObject<T | null> | null>(null);\n return {\n Context: context,\n useParentRef: (): RefObject<T | null> => {\n const ref = useContext(context);\n if (!ref) throw new Error(orphanMessage);\n return ref;\n },\n };\n};\n\nexport type PlacedChildRender<T> = (ref: RefCallback<T>) => ReactNode;\n\nexport type PlacedChildOptions<T extends GObject.Object, P> = {\n render: PlacedChildRender<T>;\n ref?: Ref<T | null> | undefined;\n placement: P;\n samePlacement: (a: P, b: P) => boolean;\n place: (object: T, placement: P, previous: P | undefined) => void;\n release: (object: T) => void;\n};\n\nexport const usePlacedChild = <T extends GObject.Object, P>(options: PlacedChildOptions<T, P>): ReactNode => {\n const { render, ref, placement, samePlacement, place, release } = options;\n const objectRef = useRef<T | null>(null);\n const appliedRef = useRef<{ object: T; placement: P } | null>(null);\n const captureObject = useCallback<RefCallback<T>>((object) => {\n objectRef.current = object;\n }, []);\n const setObjectRef = useMergeRefs<T>(ref, captureObject);\n\n useLayoutEffect(() => {\n const object = objectRef.current;\n const applied = appliedRef.current;\n if (applied !== null && applied.object !== object) {\n release(applied.object);\n appliedRef.current = null;\n }\n if (object === null) return;\n const current = appliedRef.current;\n if (current === null || !samePlacement(current.placement, placement)) {\n place(object, placement, current?.placement);\n appliedRef.current = { object, placement };\n }\n });\n\n useLayoutEffect(\n () => () => {\n const applied = appliedRef.current;\n if (applied !== null) release(applied.object);\n appliedRef.current = null;\n },\n [],\n );\n\n return createPortal(render(setObjectRef), rootElement);\n};\n"]}
@@ -1,12 +1,13 @@
1
1
  import type * as Gio from "@gtkx/gi/gio";
2
2
  import * as Gtk from "@gtkx/gi/gtk";
3
3
  import type { ItemResolver } from "../utils/item-resolver.js";
4
- export interface SelectionModelOptions<T, S> {
4
+ type SelectionModelOptions<T, S> = {
5
5
  base: Gio.ListModel;
6
6
  selectionMode: Gtk.SelectionMode | null | undefined;
7
- selected: string[] | null | undefined;
7
+ selectedIds: string[] | null | undefined;
8
8
  onSelectionChanged: ((ids: string[]) => void) | null | undefined;
9
9
  resolver: ItemResolver<T, S>;
10
- }
10
+ };
11
11
  export declare const useSelectionModel: <T, S>(options: SelectionModelOptions<T, S>) => Gtk.SelectionModel;
12
+ export {};
12
13
  //# sourceMappingURL=use-selection-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection-model.d.ts","sourceRoot":"","sources":["../../src/hooks/use-selection-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,WAAW,qBAAqB,CAAC,CAAC,EAAE,CAAC;IACvC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC;IACpB,aAAa,EAAE,GAAG,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACtC,kBAAkB,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACjE,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAChC;AAsED,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,EAAE,SAAS,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,GAAG,CAAC,cAsClF,CAAC"}
1
+ {"version":3,"file":"use-selection-model.d.ts","sourceRoot":"","sources":["../../src/hooks/use-selection-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAIpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,KAAK,qBAAqB,CAAC,CAAC,EAAE,CAAC,IAAI;IAC/B,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC;IACpB,aAAa,EAAE,GAAG,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,kBAAkB,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACjE,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAChC,CAAC;AA8DF,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,WAAW,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,GAAG,CAAC,cAsClF,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import * as Gtk from "@gtkx/gi/gtk";
2
2
  import { useSignal } from "@gtkx/react";
3
+ import { isSameArray } from "@gtkx/utils";
3
4
  import { useLayoutEffect, useRef } from "react";
4
5
  const createSelectionModel = (mode, base) => {
5
6
  if (mode === Gtk.SelectionMode.MULTIPLE)
@@ -25,7 +26,7 @@ const applySelectedPositions = (model, positions) => {
25
26
  return;
26
27
  }
27
28
  const requested = bitsetOf(positions);
28
- const changed = model.getSelection();
29
+ const changed = model.getSelection().copy();
29
30
  changed.difference(requested);
30
31
  if (changed.isEmpty())
31
32
  return;
@@ -57,23 +58,14 @@ const idsToPositions = (ids, resolver) => {
57
58
  return [];
58
59
  const positions = [];
59
60
  for (const id of ids) {
60
- const position = resolver.positionOf(id);
61
+ const position = resolver.positionOfId(id);
61
62
  if (position >= 0)
62
63
  positions.push(position);
63
64
  }
64
65
  return positions;
65
66
  };
66
- const sameIds = (a, b) => {
67
- if (a.length !== b.length)
68
- return false;
69
- for (let index = 0; index < a.length; index++) {
70
- if (a[index] !== b[index])
71
- return false;
72
- }
73
- return true;
74
- };
75
67
  export const useSelectionModel = (options) => {
76
- const { base, selectionMode, selected, onSelectionChanged, resolver } = options;
68
+ const { base, selectionMode, selectedIds, onSelectionChanged, resolver } = options;
77
69
  const mode = selectionMode ?? Gtk.SelectionMode.SINGLE;
78
70
  const modelRef = useRef(null);
79
71
  const modeRef = useRef(null);
@@ -92,7 +84,7 @@ export const useSelectionModel = (options) => {
92
84
  if (!callback)
93
85
  return;
94
86
  const ids = readSelectedIds(model, resolverRef.current);
95
- if (lastReportedRef.current !== null && sameIds(lastReportedRef.current, ids))
87
+ if (lastReportedRef.current !== null && isSameArray(lastReportedRef.current, ids))
96
88
  return;
97
89
  lastReportedRef.current = ids;
98
90
  callback(ids);
@@ -101,11 +93,11 @@ export const useSelectionModel = (options) => {
101
93
  useLayoutEffect(() => {
102
94
  if (model.getModel() !== base)
103
95
  model.setModel(base);
104
- if (selected !== undefined && selected !== null) {
105
- applySelectedPositions(model, idsToPositions(selected, resolver));
96
+ if (selectedIds !== undefined && selectedIds !== null) {
97
+ applySelectedPositions(model, idsToPositions(selectedIds, resolver));
106
98
  }
107
99
  report();
108
- }, [model, base, selected, resolver]);
100
+ }, [model, base, selectedIds, resolver]);
109
101
  return model;
110
102
  };
111
103
  //# sourceMappingURL=use-selection-model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection-model.js","sourceRoot":"","sources":["../../src/hooks/use-selection-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAahD,MAAM,oBAAoB,GAAG,CAAC,IAAuB,EAAE,IAAmB,EAA0B,EAAE;IAClG,IAAI,IAAI,KAAK,GAAG,CAAC,aAAa,CAAC,QAAQ;QAAE,OAAO,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7E,IAAI,IAAI,KAAK,GAAG,CAAC,aAAa,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtE,OAAO,IAAI,GAAG,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EA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CAAC,OAAO,EAAE,GAAG,CAAC;YAAE,OAAO;QAC1F,eAAe,CAAC,OAAO,GAAG,GAAG,CAAC;QAC9B,QAAQ,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,SAAS,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAE9C,eAAe,CAAC,GAAG,EAAE;QACjB,IAAI,KAAK,CAAC,QAAQ,EAAE,KAAK,IAAI;YAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACpD,sBAAsB,CAAC,KAAK,EAAE,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,EAAE,CAAC;IACb,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEzC,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import type * as Gio from \"@gtkx/gi/gio\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { isSameArray } from \"@gtkx/utils\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { ItemResolver } from \"../utils/item-resolver.js\";\n\ntype SelectionModelOptions<T, S> = {\n base: Gio.ListModel;\n selectionMode: Gtk.SelectionMode | null | undefined;\n selectedIds: string[] | null | undefined;\n onSelectionChanged: ((ids: string[]) => void) | null | undefined;\n resolver: ItemResolver<T, S>;\n};\n\ntype WrappingSelectionModel = (Gtk.SingleSelection | Gtk.MultiSelection | Gtk.NoSelection) & Gtk.SelectionModel;\n\nconst createSelectionModel = (mode: Gtk.SelectionMode, base: Gio.ListModel): WrappingSelectionModel => {\n if (mode === Gtk.SelectionMode.MULTIPLE) return Gtk.MultiSelection.new(base);\n if (mode === Gtk.SelectionMode.NONE) return Gtk.NoSelection.new(base);\n return new Gtk.SingleSelection({ model: base, autoselect: false, canUnselect: true });\n};\n\nconst bitsetOf = (positions: number[]): Gtk.Bitset => {\n const bitset = Gtk.Bitset.newEmpty();\n for (const position of positions) {\n if (position >= 0) bitset.add(position);\n }\n return bitset;\n};\n\nconst applySelectedPositions = (model: Gtk.SelectionModel, positions: number[]): void => {\n if (model instanceof Gtk.MultiSelection) {\n if (positions.length === 0) {\n const current = model.getSelection();\n if (!current.isEmpty()) model.unselectAll();\n return;\n }\n const requested = bitsetOf(positions);\n const changed = model.getSelection().copy();\n changed.difference(requested);\n if (changed.isEmpty()) return;\n model.setSelection(requested, changed);\n return;\n }\n if (positions.length === 0) {\n model.unselectAll();\n return;\n }\n const first = positions[0];\n if (first !== undefined && first >= 0) model.selectItem(first, true);\n};\n\nconst readSelectedIds = <T, S>(model: Gtk.SelectionModel, resolver: ItemResolver<T, S>): string[] => {\n const selection = model.getSelection();\n const ids: string[] = [];\n const count = Number(selection.getSize());\n for (let index = 0; index < count; index++) {\n const position = selection.getNth(index);\n const id = resolver.idOf(position);\n if (id !== undefined) ids.push(id);\n }\n return ids;\n};\n\nconst idsToPositions = <T, S>(ids: string[] | null | undefined, resolver: ItemResolver<T, S>): number[] => {\n if (ids === undefined || ids === null) return [];\n const positions: number[] = [];\n for (const id of ids) {\n const position = resolver.positionOfId(id);\n if (position >= 0) positions.push(position);\n }\n return positions;\n};\n\nexport const useSelectionModel = <T, S>(options: SelectionModelOptions<T, S>): Gtk.SelectionModel => {\n const { base, selectionMode, selectedIds, onSelectionChanged, resolver } = options;\n const mode = selectionMode ?? Gtk.SelectionMode.SINGLE;\n\n const modelRef = useRef<WrappingSelectionModel | null>(null);\n const modeRef = useRef<Gtk.SelectionMode | null>(null);\n if (modelRef.current === null || modeRef.current !== mode) {\n modelRef.current = createSelectionModel(mode, base);\n modeRef.current = mode;\n }\n const model = modelRef.current;\n\n const onChangedRef = useRef(onSelectionChanged);\n onChangedRef.current = onSelectionChanged;\n const resolverRef = useRef(resolver);\n resolverRef.current = resolver;\n const lastReportedRef = useRef<string[] | null>(null);\n\n const report = (): void => {\n const callback = onChangedRef.current;\n if (!callback) return;\n const ids = readSelectedIds(model, resolverRef.current);\n if (lastReportedRef.current !== null && isSameArray(lastReportedRef.current, ids)) return;\n lastReportedRef.current = ids;\n callback(ids);\n };\n\n useSignal(model, \"selection-changed\", report);\n\n useLayoutEffect(() => {\n if (model.getModel() !== base) model.setModel(base);\n if (selectedIds !== undefined && selectedIds !== null) {\n applySelectedPositions(model, idsToPositions(selectedIds, resolver));\n }\n report();\n }, [model, base, selectedIds, resolver]);\n\n return model;\n};\n"]}
@@ -1,12 +1,17 @@
1
1
  import * as Gtk from "@gtkx/gi/gtk";
2
- import { type GObjectTarget } from "@gtkx/react/internal";
3
- import type { ColumnRegistration } from "../contexts/column-view-context.js";
4
- export interface SortHandlerOptions {
5
- columnView: GObjectTarget<Gtk.ColumnView>;
2
+ import { type ObjectProp } from "@gtkx/react/internal";
3
+ export type ColumnRegistration = {
4
+ id: string;
5
+ column: Gtk.ColumnViewColumn;
6
+ sortable: boolean;
7
+ };
8
+ type SortHandlerOptions = {
9
+ columnView: ObjectProp<Gtk.ColumnView>;
6
10
  sortColumn: string | null | undefined;
7
11
  sortOrder: Gtk.SortType | null | undefined;
8
12
  onSortChanged: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
9
13
  columns: ColumnRegistration[];
10
- }
14
+ };
11
15
  export declare const useSortHandler: (options: SortHandlerOptions) => void;
16
+ export {};
12
17
  //# sourceMappingURL=use-sort-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-sort-handler.d.ts","sourceRoot":"","sources":["../../src/hooks/use-sort-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,sBAAsB,CAAC;AAEhF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AA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cAAc,YAAa,kBAAkB,KAAG,IAwC5D,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import * as Gtk from "@gtkx/gi/gtk";
2
- import { resolveGobjectTarget } from "@gtkx/react/internal";
2
+ import { resolveObjectProp } from "@gtkx/react/internal";
3
3
  import { useLayoutEffect, useRef } from "react";
4
4
  const neutralSorter = () => Gtk.CustomSorter.new(() => 0);
5
5
  const ensureColumnSorters = (columns, activeId) => {
@@ -73,7 +73,7 @@ export const useSortHandler = (options) => {
73
73
  sorter.on("changed", handler);
74
74
  };
75
75
  useLayoutEffect(() => {
76
- const view = resolveGobjectTarget(columnView);
76
+ const view = resolveObjectProp(columnView);
77
77
  if (view === null)
78
78
  return;
79
79
  ensureColumnSorters(columns, activeId);
@@ -1 +1 @@
1
- {"version":3,"file":"use-sort-handler.js","sourceRoot":"","sources":["../../src/hooks/use-sort-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAsB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAWhD,MAAM,aAAa,GAAG,GAAqB,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAE5E,MAAM,mBAAmB,GAAG,CAAC,OAA6B,EAAE,QAAuB,EAAQ,EAAE;IACzF,KAAK,MAAM,YAAY,IAAI,OAAO,EAAE,CAAC;QACjC,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,IAAI,YAAY,CAAC,EAAE,KAAK,QAAQ,CAAC;QAC1E,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC;QAC3D,IAAI,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC;YAC5B,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;Q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AS,EAAE,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,eAAe,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { type ObjectProp, resolveObjectProp } from \"@gtkx/react/internal\";\nimport { useLayoutEffect, useRef } from \"react\";\n\nexport type ColumnRegistration = {\n id: string;\n column: Gtk.ColumnViewColumn;\n sortable: boolean;\n};\n\ntype SortHandlerOptions = {\n columnView: ObjectProp<Gtk.ColumnView>;\n sortColumn: string | null | undefined;\n sortOrder: Gtk.SortType | null | undefined;\n onSortChanged: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n columns: ColumnRegistration[];\n};\n\nconst neutralSorter = (): Gtk.CustomSorter => Gtk.CustomSorter.new(() => 0);\n\nconst ensureColumnSorters = (columns: ColumnRegistration[], activeId: string | null): void => {\n for (const registration of columns) {\n const wantsSorter = registration.sortable || registration.id === activeId;\n const hasSorter = registration.column.getSorter() !== null;\n if (wantsSorter && !hasSorter) {\n registration.column.setSorter(neutralSorter());\n } else if (!wantsSorter && hasSorter) {\n registration.column.setSorter(null);\n }\n }\n};\n\nconst columnForId = (columns: ColumnRegistration[], id: string | null): Gtk.ColumnViewColumn | null => {\n if (id === null) return null;\n for (const registration of columns) {\n if (registration.id === id) return registration.column;\n }\n return null;\n};\n\nconst idForColumn = (columns: ColumnRegistration[], column: Gtk.ColumnViewColumn | null): string | null => {\n if (column === null) return null;\n for (const registration of columns) {\n if (registration.column === column) return registration.id;\n }\n return column.getId();\n};\n\nconst primarySort = (sorter: Gtk.Sorter): { column: Gtk.ColumnViewColumn | null; order: Gtk.SortType } =>\n sorter instanceof Gtk.ColumnViewSorter\n ? { column: sorter.getPrimarySortColumn(), order: sorter.getPrimarySortOrder() }\n : { column: null, order: Gtk.SortType.ASCENDING };\n\ntype SorterSubscription = {\n sorter: Gtk.Sorter | null;\n handler: ((change: Gtk.SorterChange) => void) | null;\n};\n\nconst disconnectSorter = (subscription: SorterSubscription): void => {\n if (subscription.sorter !== null && subscription.handler !== null) {\n subscription.sorter.off(\"changed\", subscription.handler);\n }\n subscription.sorter = null;\n subscription.handler = null;\n};\n\nexport const useSortHandler = (options: SortHandlerOptions): void => {\n const { columnView, sortColumn, sortOrder, onSortChanged, columns } = options;\n const activeId = sortColumn ?? null;\n const order = sortOrder ?? Gtk.SortType.ASCENDING;\n\n const onChangedRef = useRef(onSortChanged);\n onChangedRef.current = onSortChanged;\n const columnsRef = useRef(columns);\n columnsRef.current = columns;\n const suppressRef = useRef(false);\n const subscriptionRef = useRef<SorterSubscription>({ sorter: null, handler: null });\n\n const resubscribe = (sorter: Gtk.Sorter | null): void => {\n const subscription = subscriptionRef.current;\n if (sorter === subscription.sorter) return;\n disconnectSorter(subscription);\n if (sorter === null) return;\n const handler = (): void => {\n if (suppressRef.current) return;\n const callback = onChangedRef.current;\n if (!callback) return;\n const { column, order: primaryOrder } = primarySort(sorter);\n callback(idForColumn(columnsRef.current, column), primaryOrder);\n };\n subscription.sorter = sorter;\n subscription.handler = handler;\n sorter.on(\"changed\", handler);\n };\n\n useLayoutEffect(() => {\n const view = resolveObjectProp(columnView);\n if (view === null) return;\n ensureColumnSorters(columns, activeId);\n suppressRef.current = true;\n view.sortByColumn(columnForId(columns, activeId), order);\n suppressRef.current = false;\n resubscribe(view.getSorter());\n });\n\n useLayoutEffect(() => () => disconnectSorter(subscriptionRef.current), []);\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -1,19 +1,13 @@
1
- /**
2
- * Higher-level GTKX components: declarative, opinionated abstractions layered on
3
- * top of the generated `@gtkx/jsx` element bindings and the `@gtkx/react`
4
- * runtime. Each component pairs a GObject widget with a gtkx-authored prop
5
- * surface (item models, render callbacks, selection, sorting) and is exported
6
- * under an unprefixed name to distinguish it from the raw `Gtk*`/`Adw*`/`G*`
7
- * intrinsic element it builds upon.
8
- *
9
- * @packageDocumentation
10
- */
11
- export { ColumnView, type ColumnViewComponentProps } from "./column-view.js";
12
- export { ColumnViewColumn, type ColumnViewColumnComponentProps } from "./column-view-column.js";
1
+ export { type ColumnDef, type ColumnDefDeclarativeProps, ColumnView, type ColumnViewDeclarativeProps, type ColumnViewProps, type ColumnViewSortProps, } from "./column-view.js";
13
2
  export { ConstraintLayout, type ConstraintLayoutProps } from "./constraint-layout.js";
14
- export { ComboRow, type ComboRowComponentProps, DropDown, type DropDownComponentProps } from "./drop-down.js";
15
- export { GridView, type GridViewComponentProps } from "./grid-view.js";
16
- export { ListView, type ListViewComponentProps } from "./list-view.js";
17
- export { Menu, type MenuProps } from "./menu.js";
18
- export type { ColumnViewColumnProps, ColumnViewProps, ConstraintGuideProps, ConstraintProps, ConstraintVflProps, DropDownProps, GridViewProps, ListItem, ListViewProps, MenuEntry, MenuItemsProps, } from "./types.js";
3
+ export type { ConstraintGuideProps, ConstraintProps, ConstraintVflProps } from "./constraint-layout-apply.js";
4
+ export { DropDown, type DropDownDeclarativeProps, type DropDownItemRenderer, type DropDownProps } from "./drop-down.js";
5
+ export { Fixed, type FixedChildProps, type FixedPlacementProps, type FixedProps } from "./fixed.js";
6
+ export { Grid, type GridChildProps, type GridPlacement, type GridProps } from "./grid.js";
7
+ export { GridView, type GridViewDeclarativeProps, type GridViewProps } from "./grid-view.js";
8
+ export { ListView, type ListViewDeclarativeProps, type ListViewProps } from "./list-view.js";
9
+ export { Menu, type MenuItemsProps, type MenuProps } from "./menu.js";
10
+ export { Overlay, type OverlayChildProps, type OverlayPlacementProps, type OverlayProps } from "./overlay.js";
11
+ export { SizeGroup, type SizeGroupChildProps, type SizeGroupProps } from "./size-group.js";
12
+ export type { ChildProps, CollectionItemSizeProps, ControlledExpansionProps, ControlledSelectionProps, ItemNode, MenuEntry, RenderItemProps, SectionNode, WidgetProps, } from "./types.js";
19
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,KAAK,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EACR,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,aAAa,EACb,SAAS,EACT,cAAc,GACjB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,UAAU,EACV,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,mBAAmB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACtF,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,KAAK,wBAAwB,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxH,OAAO,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,KAAK,wBAAwB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,KAAK,wBAAwB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,KAAK,mBAAmB,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC3F,YAAY,EACR,UAAU,EACV,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,QAAQ,EACR,SAAS,EACT,eAAe,EACf,WAAW,EACX,WAAW,GACd,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,18 +1,11 @@
1
- /**
2
- * Higher-level GTKX components: declarative, opinionated abstractions layered on
3
- * top of the generated `@gtkx/jsx` element bindings and the `@gtkx/react`
4
- * runtime. Each component pairs a GObject widget with a gtkx-authored prop
5
- * surface (item models, render callbacks, selection, sorting) and is exported
6
- * under an unprefixed name to distinguish it from the raw `Gtk*`/`Adw*`/`G*`
7
- * intrinsic element it builds upon.
8
- *
9
- * @packageDocumentation
10
- */
11
- export { ColumnView } from "./column-view.js";
12
- export { ColumnViewColumn } from "./column-view-column.js";
1
+ export { ColumnView, } from "./column-view.js";
13
2
  export { ConstraintLayout } from "./constraint-layout.js";
14
- export { ComboRow, DropDown } from "./drop-down.js";
3
+ export { DropDown } from "./drop-down.js";
4
+ export { Fixed } from "./fixed.js";
5
+ export { Grid } from "./grid.js";
15
6
  export { GridView } from "./grid-view.js";
16
7
  export { ListView } from "./list-view.js";
17
8
  export { Menu } from "./menu.js";
9
+ export { Overlay } from "./overlay.js";
10
+ export { SizeGroup } from "./size-group.js";
18
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAiC,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAuC,MAAM,yBAAyB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAA8B,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAA+B,QAAQ,EAA+B,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAA+B,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAA+B,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,GAIb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAA8B,MAAM,wBAAwB,CAAC;AAEtF,OAAO,EAAE,QAAQ,EAAgF,MAAM,gBAAgB,CAAC;AACxH,OAAO,EAAE,KAAK,EAAmE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,IAAI,EAA2D,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAqD,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAqD,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAuC,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,OAAO,EAAyE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAiD,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n type ColumnDef,\n type ColumnDefDeclarativeProps,\n ColumnView,\n type ColumnViewDeclarativeProps,\n type ColumnViewProps,\n type ColumnViewSortProps,\n} from \"./column-view.js\";\nexport { ConstraintLayout, type ConstraintLayoutProps } from \"./constraint-layout.js\";\nexport type { ConstraintGuideProps, ConstraintProps, ConstraintVflProps } from \"./constraint-layout-apply.js\";\nexport { DropDown, type DropDownDeclarativeProps, type DropDownItemRenderer, type DropDownProps } from \"./drop-down.js\";\nexport { Fixed, type FixedChildProps, type FixedPlacementProps, type FixedProps } from \"./fixed.js\";\nexport { Grid, type GridChildProps, type GridPlacement, type GridProps } from \"./grid.js\";\nexport { GridView, type GridViewDeclarativeProps, type GridViewProps } from \"./grid-view.js\";\nexport { ListView, type ListViewDeclarativeProps, type ListViewProps } from \"./list-view.js\";\nexport { Menu, type MenuItemsProps, type MenuProps } from \"./menu.js\";\nexport { Overlay, type OverlayChildProps, type OverlayPlacementProps, type OverlayProps } from \"./overlay.js\";\nexport { SizeGroup, type SizeGroupChildProps, type SizeGroupProps } from \"./size-group.js\";\nexport type {\n ChildProps,\n CollectionItemSizeProps,\n ControlledExpansionProps,\n ControlledSelectionProps,\n ItemNode,\n MenuEntry,\n RenderItemProps,\n SectionNode,\n WidgetProps,\n} from \"./types.js\";\n"]}
@@ -1,16 +1,24 @@
1
1
  import { type GtkListViewProps } from "@gtkx/jsx/gtk";
2
2
  import type { ReactNode } from "react";
3
- import type { ListViewProps } from "./types.js";
3
+ import type { CollectionItemSizeProps, ControlledExpansionProps, ControlledSelectionProps, ItemNode, RenderItemProps, SectionNode } from "./types.js";
4
+ export type ListViewDeclarativeProps<T = unknown, S = unknown> = CollectionItemSizeProps & ControlledSelectionProps & ControlledExpansionProps & {
5
+ items?: ItemNode<T>[] | undefined;
6
+ sections?: SectionNode<S, T>[] | undefined;
7
+ renderItem: (props: RenderItemProps<T>) => ReactNode;
8
+ renderHeader?: ((info: {
9
+ section: S;
10
+ }) => ReactNode) | null | undefined;
11
+ };
4
12
  /**
5
- * Props for the {@link ListView} component: the raw `GtkListView` element
6
- * surface with its factory/model wiring replaced by the declarative
7
- * {@link ListViewProps} API.
13
+ * Props for {@link ListView}. Combines the underlying Gtk.ListView props with
14
+ * declarative collection props: flat items or grouped sections, a per-row renderItem,
15
+ * an optional section header renderer, controlled selection and expansion, and
16
+ * estimated item sizing.
8
17
  */
9
- export type ListViewComponentProps<T = unknown, S = unknown> = Omit<GtkListViewProps, keyof ListViewProps<T, S>> & ListViewProps<T, S>;
18
+ export type ListViewProps<T = unknown, S = unknown> = Omit<GtkListViewProps, "model" | "factory" | "headerFactory" | keyof ListViewDeclarativeProps<T, S>> & ListViewDeclarativeProps<T, S>;
10
19
  /**
11
- * A `GtkListView` driven by a declarative `items`/`renderItem` API with
12
- * optional controlled selection, section headers, and tree autoexpansion.
13
- * Supplying an external `model` switches to the uncontrolled form.
20
+ * Renders a Gtk.ListView: a scrollable, single-column list backed by a collection
21
+ * model, with each row drawn by renderItem and optional section headers.
14
22
  */
15
- export declare const ListView: <T = unknown, S = unknown>(props: ListViewComponentProps<T, S>) => ReactNode;
23
+ export declare const ListView: <T = unknown, S = unknown>(props: ListViewProps<T, S>) => ReactNode;
16
24
  //# sourceMappingURL=list-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"list-view.d.ts","sourceRoot":"","sources":["../src/list-view.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAO,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAgBhD;;;;GAIG;AACH,MAAM,MAAM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