@gtkx/components 1.0.0-rc.1 → 1.0.0-rc.3

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 (220) hide show
  1. package/dist/adw/combo-row.d.ts +11 -0
  2. package/dist/adw/combo-row.d.ts.map +1 -0
  3. package/dist/adw/combo-row.js +14 -0
  4. package/dist/adw/combo-row.js.map +1 -0
  5. package/dist/adw/index.d.ts +4 -0
  6. package/dist/adw/index.d.ts.map +1 -0
  7. package/dist/adw/index.js +3 -0
  8. package/dist/adw/index.js.map +1 -0
  9. package/dist/adw/toast.d.ts +10 -0
  10. package/dist/adw/toast.d.ts.map +1 -0
  11. package/dist/adw/toast.js +51 -0
  12. package/dist/adw/toast.js.map +1 -0
  13. package/dist/adw/types.d.ts +35 -0
  14. package/dist/adw/types.d.ts.map +1 -0
  15. package/dist/adw/types.js +2 -0
  16. package/dist/adw/types.js.map +1 -0
  17. package/dist/column-view.d.ts +7 -29
  18. package/dist/column-view.d.ts.map +1 -1
  19. package/dist/column-view.js +98 -70
  20. package/dist/column-view.js.map +1 -1
  21. package/dist/drop-down.d.ts +7 -28
  22. package/dist/drop-down.d.ts.map +1 -1
  23. package/dist/drop-down.js +10 -86
  24. package/dist/drop-down.js.map +1 -1
  25. package/dist/grid-view.d.ts +6 -16
  26. package/dist/grid-view.d.ts.map +1 -1
  27. package/dist/grid-view.js +25 -33
  28. package/dist/grid-view.js.map +1 -1
  29. package/dist/index.d.ts +6 -12
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -6
  32. package/dist/index.js.map +1 -1
  33. package/dist/internal/cells.d.ts +50 -0
  34. package/dist/internal/cells.d.ts.map +1 -0
  35. package/dist/internal/cells.js +185 -0
  36. package/dist/internal/cells.js.map +1 -0
  37. package/dist/internal/collection-index.d.ts +21 -0
  38. package/dist/internal/collection-index.d.ts.map +1 -0
  39. package/dist/internal/collection-index.js +106 -0
  40. package/dist/internal/collection-index.js.map +1 -0
  41. package/dist/internal/collection-model.d.ts +12 -0
  42. package/dist/internal/collection-model.d.ts.map +1 -0
  43. package/dist/internal/collection-model.js +164 -0
  44. package/dist/internal/collection-model.js.map +1 -0
  45. package/dist/internal/collection.d.ts +18 -0
  46. package/dist/internal/collection.d.ts.map +1 -0
  47. package/dist/internal/collection.js +64 -0
  48. package/dist/internal/collection.js.map +1 -0
  49. package/dist/internal/drop-down.d.ts +16 -0
  50. package/dist/internal/drop-down.d.ts.map +1 -0
  51. package/dist/internal/drop-down.js +110 -0
  52. package/dist/internal/drop-down.js.map +1 -0
  53. package/dist/internal/expansion.d.ts +9 -0
  54. package/dist/internal/expansion.d.ts.map +1 -0
  55. package/dist/internal/expansion.js +74 -0
  56. package/dist/internal/expansion.js.map +1 -0
  57. package/dist/internal/selection.d.ts +13 -0
  58. package/dist/internal/selection.d.ts.map +1 -0
  59. package/dist/internal/selection.js +100 -0
  60. package/dist/internal/selection.js.map +1 -0
  61. package/dist/internal/use-collection.d.ts +17 -0
  62. package/dist/internal/use-collection.d.ts.map +1 -0
  63. package/dist/internal/use-collection.js +34 -0
  64. package/dist/internal/use-collection.js.map +1 -0
  65. package/dist/internal/use-widget-ref.d.ts +4 -0
  66. package/dist/internal/use-widget-ref.d.ts.map +1 -0
  67. package/dist/internal/use-widget-ref.js +8 -0
  68. package/dist/internal/use-widget-ref.js.map +1 -0
  69. package/dist/list-view.d.ts +5 -20
  70. package/dist/list-view.d.ts.map +1 -1
  71. package/dist/list-view.js +32 -53
  72. package/dist/list-view.js.map +1 -1
  73. package/dist/size-group.d.ts +8 -16
  74. package/dist/size-group.d.ts.map +1 -1
  75. package/dist/size-group.js +35 -51
  76. package/dist/size-group.js.map +1 -1
  77. package/dist/types.d.ts +98 -27
  78. package/dist/types.d.ts.map +1 -1
  79. package/dist/types.js.map +1 -1
  80. package/package.json +17 -6
  81. package/src/adw/combo-row.tsx +20 -0
  82. package/src/adw/index.ts +9 -0
  83. package/src/adw/toast.tsx +74 -0
  84. package/src/adw/types.ts +45 -0
  85. package/src/column-view.tsx +176 -160
  86. package/src/drop-down.tsx +12 -185
  87. package/src/grid-view.tsx +29 -73
  88. package/src/index.ts +18 -26
  89. package/src/internal/cells.tsx +345 -0
  90. package/src/internal/collection-index.ts +168 -0
  91. package/src/internal/collection-model.ts +246 -0
  92. package/src/internal/collection.ts +104 -0
  93. package/src/internal/drop-down.tsx +186 -0
  94. package/src/internal/expansion.ts +122 -0
  95. package/src/internal/selection.tsx +162 -0
  96. package/src/internal/use-collection.tsx +57 -0
  97. package/src/internal/use-widget-ref.ts +11 -0
  98. package/src/list-view.tsx +43 -139
  99. package/src/size-group.tsx +63 -82
  100. package/src/types.ts +158 -28
  101. package/dist/cell.d.ts +0 -30
  102. package/dist/cell.d.ts.map +0 -1
  103. package/dist/cell.js +0 -45
  104. package/dist/cell.js.map +0 -1
  105. package/dist/column-view-column.d.ts +0 -27
  106. package/dist/column-view-column.d.ts.map +0 -1
  107. package/dist/column-view-column.js +0 -30
  108. package/dist/column-view-column.js.map +0 -1
  109. package/dist/constraint-layout-apply.d.ts +0 -55
  110. package/dist/constraint-layout-apply.d.ts.map +0 -1
  111. package/dist/constraint-layout-apply.js +0 -107
  112. package/dist/constraint-layout-apply.js.map +0 -1
  113. package/dist/constraint-layout.d.ts +0 -20
  114. package/dist/constraint-layout.d.ts.map +0 -1
  115. package/dist/constraint-layout.js +0 -88
  116. package/dist/constraint-layout.js.map +0 -1
  117. package/dist/fixed.d.ts +0 -26
  118. package/dist/fixed.d.ts.map +0 -1
  119. package/dist/fixed.js +0 -40
  120. package/dist/fixed.js.map +0 -1
  121. package/dist/grid.d.ts +0 -27
  122. package/dist/grid.d.ts.map +0 -1
  123. package/dist/grid.js +0 -48
  124. package/dist/grid.js.map +0 -1
  125. package/dist/hooks/use-cell-containers.d.ts +0 -18
  126. package/dist/hooks/use-cell-containers.d.ts.map +0 -1
  127. package/dist/hooks/use-cell-containers.js +0 -67
  128. package/dist/hooks/use-cell-containers.js.map +0 -1
  129. package/dist/hooks/use-collection-model.d.ts +0 -26
  130. package/dist/hooks/use-collection-model.d.ts.map +0 -1
  131. package/dist/hooks/use-collection-model.js +0 -35
  132. package/dist/hooks/use-collection-model.js.map +0 -1
  133. package/dist/hooks/use-collection-widget.d.ts +0 -28
  134. package/dist/hooks/use-collection-widget.d.ts.map +0 -1
  135. package/dist/hooks/use-collection-widget.js +0 -21
  136. package/dist/hooks/use-collection-widget.js.map +0 -1
  137. package/dist/hooks/use-drop-down-selection.d.ts +0 -16
  138. package/dist/hooks/use-drop-down-selection.d.ts.map +0 -1
  139. package/dist/hooks/use-drop-down-selection.js +0 -35
  140. package/dist/hooks/use-drop-down-selection.js.map +0 -1
  141. package/dist/hooks/use-expansion-model.d.ts +0 -12
  142. package/dist/hooks/use-expansion-model.d.ts.map +0 -1
  143. package/dist/hooks/use-expansion-model.js +0 -71
  144. package/dist/hooks/use-expansion-model.js.map +0 -1
  145. package/dist/hooks/use-header-menu.d.ts +0 -4
  146. package/dist/hooks/use-header-menu.d.ts.map +0 -1
  147. package/dist/hooks/use-header-menu.js +0 -20
  148. package/dist/hooks/use-header-menu.js.map +0 -1
  149. package/dist/hooks/use-installed-model.d.ts +0 -4
  150. package/dist/hooks/use-installed-model.d.ts.map +0 -1
  151. package/dist/hooks/use-installed-model.js +0 -15
  152. package/dist/hooks/use-installed-model.js.map +0 -1
  153. package/dist/hooks/use-list-model.d.ts +0 -19
  154. package/dist/hooks/use-list-model.d.ts.map +0 -1
  155. package/dist/hooks/use-list-model.js +0 -97
  156. package/dist/hooks/use-list-model.js.map +0 -1
  157. package/dist/hooks/use-placed-child.d.ts +0 -18
  158. package/dist/hooks/use-placed-child.d.ts.map +0 -1
  159. package/dist/hooks/use-placed-child.js +0 -47
  160. package/dist/hooks/use-placed-child.js.map +0 -1
  161. package/dist/hooks/use-selection-model.d.ts +0 -13
  162. package/dist/hooks/use-selection-model.d.ts.map +0 -1
  163. package/dist/hooks/use-selection-model.js +0 -103
  164. package/dist/hooks/use-selection-model.js.map +0 -1
  165. package/dist/hooks/use-sort-handler.d.ts +0 -17
  166. package/dist/hooks/use-sort-handler.d.ts.map +0 -1
  167. package/dist/hooks/use-sort-handler.js +0 -87
  168. package/dist/hooks/use-sort-handler.js.map +0 -1
  169. package/dist/menu-items.d.ts +0 -5
  170. package/dist/menu-items.d.ts.map +0 -1
  171. package/dist/menu-items.js +0 -48
  172. package/dist/menu-items.js.map +0 -1
  173. package/dist/menu.d.ts +0 -14
  174. package/dist/menu.d.ts.map +0 -1
  175. package/dist/menu.js +0 -24
  176. package/dist/menu.js.map +0 -1
  177. package/dist/overlay.d.ts +0 -24
  178. package/dist/overlay.d.ts.map +0 -1
  179. package/dist/overlay.js +0 -49
  180. package/dist/overlay.js.map +0 -1
  181. package/dist/utils/cell-container-store.d.ts +0 -28
  182. package/dist/utils/cell-container-store.d.ts.map +0 -1
  183. package/dist/utils/cell-container-store.js +0 -98
  184. package/dist/utils/cell-container-store.js.map +0 -1
  185. package/dist/utils/item-models.d.ts +0 -10
  186. package/dist/utils/item-models.d.ts.map +0 -1
  187. package/dist/utils/item-models.js +0 -82
  188. package/dist/utils/item-models.js.map +0 -1
  189. package/dist/utils/item-resolver.d.ts +0 -25
  190. package/dist/utils/item-resolver.d.ts.map +0 -1
  191. package/dist/utils/item-resolver.js +0 -102
  192. package/dist/utils/item-resolver.js.map +0 -1
  193. package/dist/utils/list-item-flatten.d.ts +0 -24
  194. package/dist/utils/list-item-flatten.d.ts.map +0 -1
  195. package/dist/utils/list-item-flatten.js +0 -68
  196. package/dist/utils/list-item-flatten.js.map +0 -1
  197. package/src/cell.tsx +0 -144
  198. package/src/column-view-column.tsx +0 -82
  199. package/src/constraint-layout-apply.ts +0 -173
  200. package/src/constraint-layout.tsx +0 -135
  201. package/src/fixed.tsx +0 -86
  202. package/src/grid.tsx +0 -88
  203. package/src/hooks/use-cell-containers.ts +0 -93
  204. package/src/hooks/use-collection-model.ts +0 -60
  205. package/src/hooks/use-collection-widget.ts +0 -47
  206. package/src/hooks/use-drop-down-selection.ts +0 -52
  207. package/src/hooks/use-expansion-model.ts +0 -82
  208. package/src/hooks/use-header-menu.ts +0 -34
  209. package/src/hooks/use-installed-model.ts +0 -20
  210. package/src/hooks/use-list-model.ts +0 -161
  211. package/src/hooks/use-placed-child.ts +0 -79
  212. package/src/hooks/use-selection-model.ts +0 -114
  213. package/src/hooks/use-sort-handler.ts +0 -107
  214. package/src/menu-items.ts +0 -48
  215. package/src/menu.tsx +0 -32
  216. package/src/overlay.tsx +0 -88
  217. package/src/utils/cell-container-store.ts +0 -114
  218. package/src/utils/item-models.ts +0 -113
  219. package/src/utils/item-resolver.ts +0 -138
  220. package/src/utils/list-item-flatten.ts +0 -90
@@ -1,88 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { GtkConstraintLayout } from "@gtkx/jsx/gtk";
3
- import { useMergeRefs } from "@gtkx/react/internal";
4
- import { createContext, useContext, useEffect, useLayoutEffect, useRef, } from "react";
5
- import { applyConstraint, applyGuide, applyVfl, } from "./constraint-layout-apply.js";
6
- const ORPHAN_MESSAGE = "<ConstraintLayout.Constraint> / <Guide> / <Vfl> must be a child of <ConstraintLayout>";
7
- const ConstraintLayoutContext = createContext(null);
8
- const useConstraintLayoutRef = () => {
9
- const ref = useContext(ConstraintLayoutContext);
10
- if (!ref)
11
- throw new Error(ORPHAN_MESSAGE);
12
- return ref;
13
- };
14
- const cleanupContribution = (cleanupRef) => {
15
- const cleanup = cleanupRef.current;
16
- if (!cleanup)
17
- return;
18
- cleanupRef.current = null;
19
- cleanup();
20
- };
21
- const useLayoutContribution = (apply, deps) => {
22
- const layoutRef = useConstraintLayoutRef();
23
- useLayoutEffect(() => {
24
- const layout = layoutRef.current;
25
- if (!layout)
26
- return;
27
- return apply(layout);
28
- }, deps);
29
- };
30
- const useDeferredContribution = (apply, deps) => {
31
- const layoutRef = useConstraintLayoutRef();
32
- const cleanupRef = useRef(null);
33
- useLayoutEffect(() => () => cleanupContribution(cleanupRef), deps);
34
- useEffect(() => {
35
- const layout = layoutRef.current;
36
- if (!layout)
37
- return;
38
- const cleanup = apply(layout);
39
- cleanupRef.current = cleanup;
40
- return () => {
41
- if (cleanupRef.current === cleanup)
42
- cleanupContribution(cleanupRef);
43
- };
44
- }, deps);
45
- };
46
- /**
47
- * Installs a Gtk.ConstraintLayout on a host widget and exposes child components to
48
- * populate it: {@link ConstraintProps | ConstraintLayout.Constraint} for individual constraints,
49
- * {@link ConstraintGuideProps | ConstraintLayout.Guide} for spacing guides, and {@link ConstraintVflProps | ConstraintLayout.Vfl}
50
- * for constraints authored in the Visual Format Language.
51
- */
52
- export const ConstraintLayout = Object.assign(({ children, ref }) => {
53
- const layoutRef = useRef(null);
54
- const mergedRef = useMergeRefs(ref, layoutRef);
55
- return (_jsxs(_Fragment, { children: [_jsx(GtkConstraintLayout, { ref: mergedRef }), _jsx(ConstraintLayoutContext.Provider, { value: layoutRef, children: children })] }));
56
- }, {
57
- Guide: (props) => {
58
- useLayoutContribution((layout) => applyGuide(layout, props), [
59
- props.id,
60
- props.minWidth,
61
- props.minHeight,
62
- props.natWidth,
63
- props.natHeight,
64
- props.maxWidth,
65
- props.maxHeight,
66
- props.strength,
67
- ]);
68
- return null;
69
- },
70
- Constraint: (props) => {
71
- useDeferredContribution((layout) => applyConstraint(layout, props), [
72
- props.target,
73
- props.targetAttribute,
74
- props.relation,
75
- props.source,
76
- props.sourceAttribute,
77
- props.multiplier,
78
- props.constant,
79
- props.strength,
80
- ]);
81
- return null;
82
- },
83
- Vfl: (props) => {
84
- useDeferredContribution((layout) => applyVfl(layout, props), [props.lines, props.hspacing, props.vspacing]);
85
- return null;
86
- },
87
- });
88
- //# sourceMappingURL=constraint-layout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constraint-layout.js","sourceRoot":"","sources":["../src/constraint-layout.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,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K,CAAC,SAAS;YACf,KAAK,CAAC,QAAQ;SACjB,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,UAAU,EAAE,CAAC,KAAsB,EAAa,EAAE;QAC9C,uBAAuB,CACnB,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,EAC1C;YACI,KAAK,CAAC,MAAM;YACZ,KAAK,CAAC,eAAe;YACrB,KAAK,CAAC,QAAQ;YACd,KAAK,CAAC,MAAM;YACZ,KAAK,CAAC,eAAe;YACrB,KAAK,CAAC,UAAU;YAChB,KAAK,CAAC,QAAQ;YACd,KAAK,CAAC,QAAQ;SACjB,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,GAAG,EAAE,CAAC,KAAyB,EAAa,EAAE;QAC1C,uBAAuB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5G,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CACJ,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkConstraintLayout } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport {\n type Context,\n createContext,\n type ReactNode,\n type Ref,\n type RefObject,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from \"react\";\nimport {\n applyConstraint,\n applyGuide,\n applyVfl,\n type ConstraintGuideProps,\n type ConstraintProps,\n type ConstraintVflProps,\n} from \"./constraint-layout-apply.js\";\n\nconst ORPHAN_MESSAGE = \"<ConstraintLayout.Constraint> / <Guide> / <Vfl> must be a child of <ConstraintLayout>\";\n\nconst ConstraintLayoutContext: Context<RefObject<Gtk.ConstraintLayout | null> | null> =\n createContext<RefObject<Gtk.ConstraintLayout | null> | null>(null);\n\nconst useConstraintLayoutRef = (): RefObject<Gtk.ConstraintLayout | null> => {\n const ref = useContext(ConstraintLayoutContext);\n if (!ref) throw new Error(ORPHAN_MESSAGE);\n return ref;\n};\n\n/** Props for {@link ConstraintLayout}. */\nexport type ConstraintLayoutProps = {\n children?: ReactNode;\n ref?: Ref<Gtk.ConstraintLayout | null>;\n};\n\ntype ContributionCleanupRef = { current: (() => void) | null };\n\nconst cleanupContribution = (cleanupRef: ContributionCleanupRef): void => {\n const cleanup = cleanupRef.current;\n if (!cleanup) return;\n cleanupRef.current = null;\n cleanup();\n};\n\nconst useLayoutContribution = (apply: (layout: Gtk.ConstraintLayout) => () => void, deps: unknown[]): void => {\n const layoutRef = useConstraintLayoutRef();\n useLayoutEffect(() => {\n const layout = layoutRef.current;\n if (!layout) return;\n return apply(layout);\n }, deps);\n};\n\nconst useDeferredContribution = (apply: (layout: Gtk.ConstraintLayout) => () => void, deps: unknown[]): void => {\n const layoutRef = useConstraintLayoutRef();\n const cleanupRef = useRef<(() => void) | null>(null);\n\n useLayoutEffect(() => () => cleanupContribution(cleanupRef), deps);\n\n useEffect(() => {\n const layout = layoutRef.current;\n if (!layout) return;\n const cleanup = apply(layout);\n cleanupRef.current = cleanup;\n return () => {\n if (cleanupRef.current === cleanup) cleanupContribution(cleanupRef);\n };\n }, deps);\n};\n\n/**\n * Installs a Gtk.ConstraintLayout on a host widget and exposes child components to\n * populate it: {@link ConstraintProps | ConstraintLayout.Constraint} for individual constraints,\n * {@link ConstraintGuideProps | ConstraintLayout.Guide} for spacing guides, and {@link ConstraintVflProps | ConstraintLayout.Vfl}\n * for constraints authored in the Visual Format Language.\n */\nexport const ConstraintLayout: ((props: ConstraintLayoutProps) => ReactNode) & {\n Guide: (props: ConstraintGuideProps) => ReactNode;\n Constraint: (props: ConstraintProps) => ReactNode;\n Vfl: (props: ConstraintVflProps) => ReactNode;\n} = Object.assign(\n ({ children, ref }: ConstraintLayoutProps): ReactNode => {\n const layoutRef = useRef<Gtk.ConstraintLayout | null>(null);\n const mergedRef = useMergeRefs<Gtk.ConstraintLayout>(ref, layoutRef);\n return (\n <>\n <GtkConstraintLayout ref={mergedRef} />\n <ConstraintLayoutContext.Provider value={layoutRef}>{children}</ConstraintLayoutContext.Provider>\n </>\n );\n },\n {\n Guide: (props: ConstraintGuideProps): ReactNode => {\n useLayoutContribution(\n (layout) => applyGuide(layout, props),\n [\n props.id,\n props.minWidth,\n props.minHeight,\n props.natWidth,\n props.natHeight,\n props.maxWidth,\n props.maxHeight,\n props.strength,\n ],\n );\n return null;\n },\n Constraint: (props: ConstraintProps): ReactNode => {\n useDeferredContribution(\n (layout) => applyConstraint(layout, props),\n [\n props.target,\n props.targetAttribute,\n props.relation,\n props.source,\n props.sourceAttribute,\n props.multiplier,\n props.constant,\n props.strength,\n ],\n );\n return null;\n },\n Vfl: (props: ConstraintVflProps): ReactNode => {\n useDeferredContribution((layout) => applyVfl(layout, props), [props.lines, props.hspacing, props.vspacing]);\n return null;\n },\n },\n);\n"]}
package/dist/fixed.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import * as Gsk from "@gtkx/gi/gsk";
2
- import type * as Gtk from "@gtkx/gi/gtk";
3
- import { type GtkFixedProps } from "@gtkx/jsx/gtk";
4
- import { type ElementType, type ReactNode, type Ref } from "react";
5
- import type { ChildProps } from "./types.js";
6
- /** Props for {@link Fixed}. */
7
- export type FixedProps = GtkFixedProps & {
8
- ref?: Ref<Gtk.Fixed | null>;
9
- children?: ReactNode;
10
- };
11
- export type FixedPlacementProps = {
12
- x?: number | null | undefined;
13
- y?: number | null | undefined;
14
- /** Full transform applied to the child, overriding x and y when provided. */
15
- transform?: Gsk.Transform | null | undefined;
16
- };
17
- /** Positions a single child inside a {@link Fixed} at coordinates x and y, or by an explicit transform. */
18
- export type FixedChildProps<C extends ElementType> = ChildProps<C, FixedPlacementProps>;
19
- /**
20
- * Renders a Gtk.Fixed container whose children are placed at explicit positions via
21
- * {@link Fixed.Child}.
22
- */
23
- export declare const Fixed: ((props: FixedProps) => ReactNode) & {
24
- Child: <C extends ElementType>(props: FixedChildProps<C>) => ReactNode;
25
- };
26
- //# sourceMappingURL=fixed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fixed.d.ts","sourceRoot":"","sources":["../src/fixed.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAEH,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,GAAG,EAOX,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAU7C,+BAA+B;AAC/B,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,mBAAmB,GAAG;IAC9B,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9B,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9B,6EAA6E;IAC7E,SAAS,CAAC,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;CAChD,CAAC;AAEF,2GAA2G;AAC3G,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,WAAW,IAAI,UAAU,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;AA8BxF;;;GAGG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,KAAK,SAAS,CAAC,GAAG;IACrD,KAAK,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CAY1E,CAAC"}
package/dist/fixed.js DELETED
@@ -1,40 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as Graphene from "@gtkx/gi/graphene";
3
- import * as Gsk from "@gtkx/gi/gsk";
4
- import { GtkFixed } from "@gtkx/jsx/gtk";
5
- import { useMergeRefs } from "@gtkx/react/internal";
6
- import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState, } from "react";
7
- const FixedContext = createContext(undefined);
8
- const useFixedInstance = () => {
9
- const fixed = useContext(FixedContext);
10
- if (fixed === undefined)
11
- throw new Error("<Fixed.Child> must be a child of <Fixed>");
12
- return fixed;
13
- };
14
- const transformOf = (x, y, transform) => transform !== undefined ? transform : Gsk.Transform.new().translate(Graphene.Point.create(x, y));
15
- const FixedChild = ({ component, x, y, transform, ref, ...rest }) => {
16
- const fixed = useFixedInstance();
17
- const Component = component;
18
- const widgetRef = useRef(null);
19
- const captureWidget = useCallback((node) => {
20
- widgetRef.current = node;
21
- }, []);
22
- const setWidget = useMergeRefs(ref, captureWidget);
23
- useLayoutEffect(() => {
24
- const widget = widgetRef.current;
25
- if (widget === null || fixed === null)
26
- return;
27
- fixed.setChildTransform(widget, transformOf(x ?? 0, y ?? 0, transform));
28
- });
29
- return _jsx(Component, { ...rest, ref: setWidget });
30
- };
31
- /**
32
- * Renders a Gtk.Fixed container whose children are placed at explicit positions via
33
- * {@link Fixed.Child}.
34
- */
35
- export const Fixed = Object.assign(({ children, ref, ...rest }) => {
36
- const [fixed, setFixed] = useState(null);
37
- const mergedRef = useMergeRefs(ref, setFixed);
38
- return (_jsx(GtkFixed, { ...rest, ref: mergedRef, children: _jsx(FixedContext.Provider, { value: fixed, children: children }) }));
39
- }, { Child: FixedChild });
40
- //# sourceMappingURL=fixed.js.map
package/dist/fixed.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"fixed.js","sourceRoot":"","sources":["../src/fixed.tsx"],"names":[],"mappings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,CAAC;IACP,MAAM,SAAS,GAAG,YAAY,CAAa,GAAG,EAAE,aAAa,CAAC,CAAC;IAE/D,eAAe,CAAC,GAAG,EAAE;QACjB,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;QACjC,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO;QAC9C,KAAK,CAAC,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,KAAC,SAAS,OAAK,IAAI,EAAE,GAAG,EAAE,SAAS,GAAI,CAAC;AACnD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAEd,MAAM,CAAC,MAAM,CACb,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,EAAc,EAAa,EAAE;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,YAAY,CAAY,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzD,OAAO,CACH,KAAC,QAAQ,OAAK,IAAI,EAAE,GAAG,EAAE,SAAS,YAC9B,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAyB,GAChE,CACd,CAAC;AACN,CAAC,EACD,EAAE,KAAK,EAAE,UAAU,EAAE,CACxB,CAAC","sourcesContent":["import * as Graphene from \"@gtkx/gi/graphene\";\nimport * as Gsk from \"@gtkx/gi/gsk\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkFixed, type GtkFixedProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport {\n createContext,\n type ElementType,\n type ReactNode,\n type Ref,\n type RefCallback,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport type { ChildProps } from \"./types.js\";\n\nconst FixedContext = createContext<Gtk.Fixed | null | undefined>(undefined);\n\nconst useFixedInstance = (): Gtk.Fixed | null => {\n const fixed = useContext(FixedContext);\n if (fixed === undefined) throw new Error(\"<Fixed.Child> must be a child of <Fixed>\");\n return fixed;\n};\n\n/** Props for {@link Fixed}. */\nexport type FixedProps = GtkFixedProps & { ref?: Ref<Gtk.Fixed | null>; children?: ReactNode };\n\nexport type FixedPlacementProps = {\n x?: number | null | undefined;\n y?: number | null | undefined;\n /** Full transform applied to the child, overriding x and y when provided. */\n transform?: Gsk.Transform | null | undefined;\n};\n\n/** Positions a single child inside a {@link Fixed} at coordinates x and y, or by an explicit transform. */\nexport type FixedChildProps<C extends ElementType> = ChildProps<C, FixedPlacementProps>;\n\nconst transformOf = (x: number, y: number, transform: Gsk.Transform | null | undefined): Gsk.Transform | null =>\n transform !== undefined ? transform : Gsk.Transform.new().translate(Graphene.Point.create(x, y));\n\nconst FixedChild = <C extends ElementType>({\n component,\n x,\n y,\n transform,\n ref,\n ...rest\n}: FixedChildProps<C>): ReactNode => {\n const fixed = useFixedInstance();\n const Component: ElementType = component;\n const widgetRef = useRef<Gtk.Widget | null>(null);\n const captureWidget = useCallback<RefCallback<Gtk.Widget>>((node) => {\n widgetRef.current = node;\n }, []);\n const setWidget = useMergeRefs<Gtk.Widget>(ref, captureWidget);\n\n useLayoutEffect(() => {\n const widget = widgetRef.current;\n if (widget === null || fixed === null) return;\n fixed.setChildTransform(widget, transformOf(x ?? 0, y ?? 0, transform));\n });\n\n return <Component {...rest} ref={setWidget} />;\n};\n\n/**\n * Renders a Gtk.Fixed container whose children are placed at explicit positions via\n * {@link Fixed.Child}.\n */\nexport const Fixed: ((props: FixedProps) => ReactNode) & {\n Child: <C extends ElementType>(props: FixedChildProps<C>) => ReactNode;\n} = Object.assign(\n ({ children, ref, ...rest }: FixedProps): ReactNode => {\n const [fixed, setFixed] = useState<Gtk.Fixed | null>(null);\n const mergedRef = useMergeRefs<Gtk.Fixed>(ref, setFixed);\n return (\n <GtkFixed {...rest} ref={mergedRef}>\n <FixedContext.Provider value={fixed}>{children}</FixedContext.Provider>\n </GtkFixed>\n );\n },\n { Child: FixedChild },\n);\n"]}
package/dist/grid.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import type * as Gtk from "@gtkx/gi/gtk";
2
- import { type GtkGridProps } from "@gtkx/jsx/gtk";
3
- import { type ElementType, type ReactNode, type Ref } from "react";
4
- import type { ChildProps } from "./types.js";
5
- /** Props for {@link Grid}. */
6
- export type GridProps = GtkGridProps & {
7
- ref?: Ref<Gtk.Grid | null>;
8
- children?: ReactNode;
9
- };
10
- export type GridPlacement = {
11
- column?: number | null | undefined;
12
- row?: number | null | undefined;
13
- /** Number of columns the child spans (defaults to 1). */
14
- columnSpan?: number | null | undefined;
15
- /** Number of rows the child spans (defaults to 1). */
16
- rowSpan?: number | null | undefined;
17
- };
18
- /** Places a single child inside a {@link Grid} at a column and row, optionally spanning multiple cells. */
19
- export type GridChildProps<C extends ElementType> = ChildProps<C, GridPlacement>;
20
- /**
21
- * Renders a Gtk.Grid whose children are attached at explicit column/row positions via
22
- * {@link Grid.Child}.
23
- */
24
- export declare const Grid: ((props: GridProps) => ReactNode) & {
25
- Child: <C extends ElementType>(props: GridChildProps<C>) => ReactNode;
26
- };
27
- //# sourceMappingURL=grid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../src/grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAY,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAU,MAAM,OAAO,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7C,8BAA8B;AAC9B,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,aAAa,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAChC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC,CAAC;AAEF,2GAA2G;AAC3G,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;AA6CjF;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC,GAAG;IACnD,KAAK,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CAazE,CAAC"}
package/dist/grid.js DELETED
@@ -1,48 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { GtkGrid } from "@gtkx/jsx/gtk";
3
- import { useMergeRefs } from "@gtkx/react/internal";
4
- import { Children, useRef } from "react";
5
- import { createParentContext, usePlacedChild } from "./hooks/use-placed-child.js";
6
- const { Context: GridContext, useParentRef: useGridRef } = createParentContext("<Grid.Child> must be a child of <Grid>");
7
- const placementOf = (props) => ({
8
- column: props.column ?? 0,
9
- row: props.row ?? 0,
10
- columnSpan: props.columnSpan ?? 1,
11
- rowSpan: props.rowSpan ?? 1,
12
- });
13
- const samePlacement = (a, b) => a.column === b.column && a.row === b.row && a.columnSpan === b.columnSpan && a.rowSpan === b.rowSpan;
14
- const GridChild = ({ component, column, row, columnSpan, rowSpan, ref, ...rest }) => {
15
- const gridRef = useGridRef();
16
- const Component = component;
17
- return usePlacedChild({
18
- render: (placeRef) => _jsx(Component, { ...rest, ref: placeRef }),
19
- ref,
20
- placement: placementOf({ column, row, columnSpan, rowSpan }),
21
- samePlacement,
22
- place: (widget, placement, previous) => {
23
- const grid = gridRef.current;
24
- if (!grid)
25
- return;
26
- if (previous !== undefined && widget.getParent() === grid)
27
- grid.remove(widget);
28
- if (widget.getParent() !== grid) {
29
- grid.attach(widget, placement.column, placement.row, placement.columnSpan, placement.rowSpan);
30
- }
31
- },
32
- release: (widget) => {
33
- const grid = gridRef.current;
34
- if (grid && widget.getParent() === grid)
35
- grid.remove(widget);
36
- },
37
- });
38
- };
39
- /**
40
- * Renders a Gtk.Grid whose children are attached at explicit column/row positions via
41
- * {@link Grid.Child}.
42
- */
43
- export const Grid = Object.assign(({ children, ref, ...rest }) => {
44
- const gridRef = useRef(null);
45
- const mergedRef = useMergeRefs(ref, gridRef);
46
- return (_jsxs(_Fragment, { children: [_jsx(GtkGrid, { ...rest, ref: mergedRef }), _jsx(GridContext.Provider, { value: gridRef, children: Children.toArray(children) })] }));
47
- }, { Child: GridChild });
48
- //# sourceMappingURL=grid.js.map
package/dist/grid.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"grid.js","sourceRoot":"","sources":["../src/grid.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAqB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAA8C,MAAM,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGlF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,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,IAAI,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/E,IAAI,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC;gBAC9B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;YAClG,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;YAChB,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;YAC7B,IAAI,IAAI,IAAI,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjE,CAAC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAEb,MAAM,CAAC,MAAM,CACb,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,EAAa,EAAa,EAAE;IACjD,MAAM,OAAO,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,YAAY,CAAW,GAAG,EAAE,OAAO,CAAC,CAAC;IACvD,OAAO,CACH,8BACI,KAAC,OAAO,OAAK,IAAI,EAAE,GAAG,EAAE,SAAS,GAAI,EACrC,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAwB,IAC1F,CACN,CAAC;AACN,CAAC,EACD,EAAE,KAAK,EAAE,SAAS,EAAE,CACvB,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkGrid, type GtkGridProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { Children, type ElementType, type ReactNode, type Ref, useRef } from \"react\";\nimport { createParentContext, usePlacedChild } from \"./hooks/use-placed-child.js\";\nimport type { ChildProps } from \"./types.js\";\n\nconst { Context: GridContext, useParentRef: useGridRef } = createParentContext<Gtk.Grid>(\n \"<Grid.Child> must be a child of <Grid>\",\n);\n\n/** Props for {@link Grid}. */\nexport type GridProps = GtkGridProps & { ref?: Ref<Gtk.Grid | null>; children?: ReactNode };\n\nexport type GridPlacement = {\n column?: number | null | undefined;\n row?: number | null | undefined;\n /** Number of columns the child spans (defaults to 1). */\n columnSpan?: number | null | undefined;\n /** Number of rows the child spans (defaults to 1). */\n rowSpan?: number | null | undefined;\n};\n\n/** Places a single child inside a {@link Grid} at a column and row, optionally spanning multiple cells. */\nexport type GridChildProps<C extends ElementType> = ChildProps<C, GridPlacement>;\n\ntype Placement = { column: number; row: number; columnSpan: number; rowSpan: number };\n\nconst placementOf = (props: GridPlacement): Placement => ({\n column: props.column ?? 0,\n row: props.row ?? 0,\n columnSpan: props.columnSpan ?? 1,\n rowSpan: props.rowSpan ?? 1,\n});\n\nconst samePlacement = (a: Placement, b: Placement): boolean =>\n a.column === b.column && a.row === b.row && a.columnSpan === b.columnSpan && a.rowSpan === b.rowSpan;\n\nconst GridChild = <C extends ElementType>({\n component,\n column,\n row,\n columnSpan,\n rowSpan,\n ref,\n ...rest\n}: GridChildProps<C>): ReactNode => {\n const gridRef = useGridRef();\n const Component: ElementType = component;\n return usePlacedChild<Gtk.Widget, Placement>({\n render: (placeRef) => <Component {...rest} ref={placeRef} />,\n ref,\n placement: placementOf({ column, row, columnSpan, rowSpan }),\n samePlacement,\n place: (widget, placement, previous) => {\n const grid = gridRef.current;\n if (!grid) return;\n if (previous !== undefined && widget.getParent() === grid) grid.remove(widget);\n if (widget.getParent() !== grid) {\n grid.attach(widget, placement.column, placement.row, placement.columnSpan, placement.rowSpan);\n }\n },\n release: (widget) => {\n const grid = gridRef.current;\n if (grid && widget.getParent() === grid) grid.remove(widget);\n },\n });\n};\n\n/**\n * Renders a Gtk.Grid whose children are attached at explicit column/row positions via\n * {@link Grid.Child}.\n */\nexport const Grid: ((props: GridProps) => ReactNode) & {\n Child: <C extends ElementType>(props: GridChildProps<C>) => ReactNode;\n} = Object.assign(\n ({ children, ref, ...rest }: GridProps): ReactNode => {\n const gridRef = useRef<Gtk.Grid | null>(null);\n const mergedRef = useMergeRefs<Gtk.Grid>(ref, gridRef);\n return (\n <>\n <GtkGrid {...rest} ref={mergedRef} />\n <GridContext.Provider value={gridRef}>{Children.toArray(children)}</GridContext.Provider>\n </>\n );\n },\n { Child: GridChild },\n);\n"]}
@@ -1,18 +0,0 @@
1
- import type * as GObject from "@gtkx/gi/gobject";
2
- import * as Gtk from "@gtkx/gi/gtk";
3
- import { type ObjectProp } from "@gtkx/react/internal";
4
- import { CellContainerStore } from "../utils/cell-container-store.js";
5
- export type FactoryInstaller<W extends GObject.Object> = {
6
- install(widget: W, factory: Gtk.SignalListItemFactory): void;
7
- uninstall(widget: W): void;
8
- };
9
- export declare const makeFactoryInstaller: <W extends GObject.Object>(setFactory: (widget: W, factory: Gtk.SignalListItemFactory | null) => void) => FactoryInstaller<W>;
10
- type CellContainersOptions<W extends GObject.Object> = {
11
- object: ObjectProp<W>;
12
- installer: FactoryInstaller<W>;
13
- estimatedHeight?: number | undefined;
14
- estimatedWidth?: number | undefined;
15
- };
16
- export declare const useCellContainers: <W extends GObject.Object>(options: CellContainersOptions<W>) => CellContainerStore;
17
- export {};
18
- //# sourceMappingURL=use-cell-containers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-cell-containers.d.ts","sourceRoot":"","sources":["../../src/hooks/use-cell-containers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAiBtE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,IAAI;IACrD,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAC7D,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,OAAO,CAAC,MAAM,cAC7C,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,qBAAqB,GAAG,IAAI,KAAK,IAAI,KAC3E,gBAAgB,CAAC,CAAC,CAGnB,CAAC;AAEH,KAAK,qBAAqB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,IAAI;IACnD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC,CAAC;AAOF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,CAAC,MAAM,WAAW,qBAAqB,CAAC,CAAC,CAAC,KAAG,kBA+C/F,CAAC"}
@@ -1,67 +0,0 @@
1
- import * as Gtk from "@gtkx/gi/gtk";
2
- import { useObjectAttachment } from "@gtkx/react/internal";
3
- import { useRef } from "react";
4
- import { CellContainerStore } from "../utils/cell-container-store.js";
5
- const isChildContainer = (container) => container instanceof Gtk.ListItem || container instanceof Gtk.ListHeader;
6
- const positionOf = (container) => {
7
- if (container instanceof Gtk.ListItem)
8
- return container.getPosition();
9
- if (container instanceof Gtk.ListHeader)
10
- return container.getStart();
11
- return -1;
12
- };
13
- export const makeFactoryInstaller = (setFactory) => ({
14
- install: (widget, factory) => setFactory(widget, factory),
15
- uninstall: (widget) => setFactory(widget, null),
16
- });
17
- const applyEstimatedSize = (child, height, width) => {
18
- if (height === undefined && width === undefined)
19
- return;
20
- child.setSizeRequest(width ?? -1, height ?? -1);
21
- };
22
- export const useCellContainers = (options) => {
23
- const { object, installer, estimatedHeight, estimatedWidth } = options;
24
- const storeRef = useRef(null);
25
- if (storeRef.current === null)
26
- storeRef.current = new CellContainerStore();
27
- const store = storeRef.current;
28
- const installerRef = useRef(installer);
29
- installerRef.current = installer;
30
- const factoryRef = useRef(null);
31
- if (factoryRef.current === null) {
32
- const factory = Gtk.SignalListItemFactory.new();
33
- factory.on("setup", (container) => {
34
- if (isChildContainer(container) && container.getChild() === null) {
35
- const placeholder = new Gtk.Box();
36
- applyEstimatedSize(placeholder, estimatedHeight, estimatedWidth);
37
- container.setChild(placeholder);
38
- }
39
- store.addContainer(container);
40
- });
41
- factory.on("bind", (container) => {
42
- if (isChildContainer(container)) {
43
- const item = container.getItem();
44
- const treeRow = item instanceof Gtk.TreeListRow ? item : null;
45
- store.bind(container, positionOf(container), treeRow);
46
- }
47
- });
48
- factory.on("unbind", (container) => {
49
- store.unbind(container);
50
- });
51
- factory.on("teardown", (container) => {
52
- store.removeContainer(container);
53
- });
54
- factoryRef.current = factory;
55
- }
56
- const factory = factoryRef.current;
57
- useObjectAttachment(object, {
58
- attach: (widget) => {
59
- installerRef.current.install(widget, factory);
60
- return { widget };
61
- },
62
- detach: (attachment) => installerRef.current.uninstall(attachment.widget),
63
- isSame: (attachment, widget) => attachment.widget === widget,
64
- });
65
- return store;
66
- };
67
- //# sourceMappingURL=use-cell-containers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-cell-containers.js","sourceRoot":"","sources":["../../src/hooks/use-cell-containers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAmB,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAA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,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE;YAC/B,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,EAAE;YACjC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IACjC,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IAEnC,mBAAmB,CAAmB,MAAM,EAAE;QAC1C,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACf,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,MAAM,EAAE,CAAC;QACtB,CAAC;QACD,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;QACzE,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,KAAK,MAAM;KAC/D,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { type ObjectProp, useObjectAttachment } from \"@gtkx/react/internal\";\nimport { useRef } from \"react\";\nimport { CellContainerStore } from \"../utils/cell-container-store.js\";\n\ntype ChildContainer = {\n getChild(): Gtk.Widget | null;\n setChild(child: Gtk.Widget | null): void;\n getItem(): GObject.Object | null;\n};\n\nconst isChildContainer = (container: GObject.Object): container is GObject.Object & ChildContainer =>\n container instanceof Gtk.ListItem || container instanceof Gtk.ListHeader;\n\nconst positionOf = (container: GObject.Object & ChildContainer): number => {\n if (container instanceof Gtk.ListItem) return container.getPosition();\n if (container instanceof Gtk.ListHeader) return container.getStart();\n return -1;\n};\n\nexport type FactoryInstaller<W extends GObject.Object> = {\n install(widget: W, factory: Gtk.SignalListItemFactory): void;\n uninstall(widget: W): void;\n};\n\nexport const makeFactoryInstaller = <W extends GObject.Object>(\n setFactory: (widget: W, factory: Gtk.SignalListItemFactory | null) => void,\n): FactoryInstaller<W> => ({\n install: (widget, factory) => setFactory(widget, factory),\n uninstall: (widget) => setFactory(widget, null),\n});\n\ntype CellContainersOptions<W extends GObject.Object> = {\n object: ObjectProp<W>;\n installer: FactoryInstaller<W>;\n estimatedHeight?: number | undefined;\n estimatedWidth?: number | undefined;\n};\n\nconst applyEstimatedSize = (child: Gtk.Widget, height: number | undefined, width: number | undefined): void => {\n if (height === undefined && width === undefined) return;\n child.setSizeRequest(width ?? -1, height ?? -1);\n};\n\nexport const useCellContainers = <W extends GObject.Object>(options: CellContainersOptions<W>): CellContainerStore => {\n const { object, installer, estimatedHeight, estimatedWidth } = options;\n const storeRef = useRef<CellContainerStore | null>(null);\n if (storeRef.current === null) storeRef.current = new CellContainerStore();\n const store = storeRef.current;\n\n const installerRef = useRef(installer);\n installerRef.current = installer;\n\n const factoryRef = useRef<Gtk.SignalListItemFactory | null>(null);\n if (factoryRef.current === null) {\n const factory = Gtk.SignalListItemFactory.new();\n factory.on(\"setup\", (container) => {\n if (isChildContainer(container) && container.getChild() === null) {\n const placeholder = new Gtk.Box();\n applyEstimatedSize(placeholder, estimatedHeight, estimatedWidth);\n container.setChild(placeholder);\n }\n store.addContainer(container);\n });\n factory.on(\"bind\", (container) => {\n if (isChildContainer(container)) {\n const item = container.getItem();\n const treeRow = item instanceof Gtk.TreeListRow ? item : null;\n store.bind(container, positionOf(container), treeRow);\n }\n });\n factory.on(\"unbind\", (container) => {\n store.unbind(container);\n });\n factory.on(\"teardown\", (container) => {\n store.removeContainer(container);\n });\n factoryRef.current = factory;\n }\n const factory = factoryRef.current;\n\n useObjectAttachment<W, { widget: W }>(object, {\n attach: (widget) => {\n installerRef.current.install(widget, factory);\n return { widget };\n },\n detach: (attachment) => installerRef.current.uninstall(attachment.widget),\n isSame: (attachment, widget) => attachment.widget === widget,\n });\n\n return store;\n};\n"]}
@@ -1,26 +0,0 @@
1
- import type * as Gtk from "@gtkx/gi/gtk";
2
- import { type ReactNode } from "react";
3
- import type { ItemNode, SectionNode } from "../types.js";
4
- import { type ItemResolver } from "../utils/item-resolver.js";
5
- type CollectionModelInput<T, S> = {
6
- items: ItemNode<T>[] | undefined;
7
- sections: SectionNode<S, T>[] | undefined;
8
- selectionMode: Gtk.SelectionMode | null | undefined;
9
- selectedIds: string[] | null | undefined;
10
- onSelectionChanged: ((ids: string[]) => void) | null | undefined;
11
- expandedIds?: string[] | null | undefined;
12
- onExpandedChange?: ((ids: string[]) => void) | null | undefined;
13
- renderHeader: ((info: {
14
- section: S;
15
- }) => ReactNode) | null | undefined;
16
- };
17
- export type CollectionModelResult<T, S> = {
18
- resolver: ItemResolver<T, S>;
19
- headerResolver: ItemResolver<T, S>;
20
- installedModel: Gtk.SelectionModel;
21
- useHeader: boolean;
22
- rowId: (row: Gtk.TreeListRow) => string | undefined;
23
- };
24
- export declare const useCollectionModel: <T, S>(input: CollectionModelInput<T, S>) => CollectionModelResult<T, S>;
25
- export {};
26
- //# sourceMappingURL=use-collection-model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-collection-model.d.ts","sourceRoot":"","sources":["../../src/hooks/use-collection-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,KAAK,YAAY,EAAW,MAAM,2BAA2B,CAAC;AAKvE,KAAK,oBAAoB,CAAC,CAAC,EAAE,CAAC,IAAI;IAC9B,KAAK,EAAE,QAAQ,CAAC,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
3
- import { useExpansionModel } from "./use-expansion-model.js";
4
- import { useListModel } from "./use-list-model.js";
5
- import { useSelectionModel } from "./use-selection-model.js";
6
- export const useCollectionModel = (input) => {
7
- const listModel = useListModel({
8
- items: input.items,
9
- sections: input.sections,
10
- });
11
- useExpansionModel({
12
- treeModel: listModel.treeModel,
13
- rowValues: listModel.rowValues,
14
- expandedIds: input.expandedIds,
15
- onExpandedChange: input.onExpandedChange,
16
- });
17
- const installedModel = useSelectionModel({
18
- base: listModel.model,
19
- resolver: listModel.resolver,
20
- selectionMode: input.selectionMode,
21
- selectedIds: input.selectedIds,
22
- onSelectionChanged: input.onSelectionChanged,
23
- });
24
- const useHeader = typeof input.renderHeader === "function";
25
- const { rowValues } = listModel;
26
- const rowId = useCallback((row) => rowIdOf(rowValues, row), [rowValues]);
27
- return {
28
- resolver: listModel.resolver,
29
- headerResolver: listModel.headerResolver,
30
- installedModel,
31
- useHeader,
32
- rowId,
33
- };
34
- };
35
- //# sourceMappingURL=use-collection-model.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-collection-model.js","sourceRoot":"","sources":["../../src/hooks/use-collection-model.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAqB,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAqB7D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAO,KAAiC,EAA+B,EAAE;IACvG,MAAM,SAAS,GAAG,YAAY,CAAO;QACjC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KAC3B,CAAC,CAAC;IAEH,iBAAiB,CAAI;QACjB,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;KAC3C,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,iBAAiB,CAAO;QAC3C,IAAI,EAAE,SAAS,CAAC,KAAK;QACrB,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;KAC/C,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CAAC;IAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IAChC,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,GAAoB,EAAsB,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAE9G,OAAO;QACH,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,cAAc,EAAE,SAAS,CAAC,cAAc;QACxC,cAAc;QACd,SAAS;QACT,KAAK;KACR,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { type ReactNode, useCallback } from \"react\";\nimport type { ItemNode, SectionNode } from \"../types.js\";\nimport { type ItemResolver, rowIdOf } from \"../utils/item-resolver.js\";\nimport { useExpansionModel } from \"./use-expansion-model.js\";\nimport { useListModel } from \"./use-list-model.js\";\nimport { useSelectionModel } from \"./use-selection-model.js\";\n\ntype CollectionModelInput<T, S> = {\n items: ItemNode<T>[] | undefined;\n sections: SectionNode<S, T>[] | undefined;\n selectionMode: Gtk.SelectionMode | null | undefined;\n selectedIds: string[] | null | undefined;\n onSelectionChanged: ((ids: string[]) => void) | null | undefined;\n expandedIds?: string[] | null | undefined;\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n renderHeader: ((info: { section: S }) => ReactNode) | null | undefined;\n};\n\nexport type CollectionModelResult<T, S> = {\n resolver: ItemResolver<T, S>;\n headerResolver: ItemResolver<T, S>;\n installedModel: Gtk.SelectionModel;\n useHeader: boolean;\n rowId: (row: Gtk.TreeListRow) => string | undefined;\n};\n\nexport const useCollectionModel = <T, S>(input: CollectionModelInput<T, S>): CollectionModelResult<T, S> => {\n const listModel = useListModel<T, S>({\n items: input.items,\n sections: input.sections,\n });\n\n useExpansionModel<T>({\n treeModel: listModel.treeModel,\n rowValues: listModel.rowValues,\n expandedIds: input.expandedIds,\n onExpandedChange: input.onExpandedChange,\n });\n\n const installedModel = useSelectionModel<T, S>({\n base: listModel.model,\n resolver: listModel.resolver,\n selectionMode: input.selectionMode,\n selectedIds: input.selectedIds,\n onSelectionChanged: input.onSelectionChanged,\n });\n\n const useHeader = typeof input.renderHeader === \"function\";\n const { rowValues } = listModel;\n const rowId = useCallback((row: Gtk.TreeListRow): string | undefined => rowIdOf(rowValues, row), [rowValues]);\n\n return {\n resolver: listModel.resolver,\n headerResolver: listModel.headerResolver,\n installedModel,\n useHeader,\n rowId,\n };\n};\n"]}
@@ -1,28 +0,0 @@
1
- import type * as Gtk from "@gtkx/gi/gtk";
2
- import { type ReactNode, type Ref, type RefCallback, type RefObject } from "react";
3
- import type { ItemNode, SectionNode } from "../types.js";
4
- import { type CollectionModelResult } from "./use-collection-model.js";
5
- type CollectionWidget = Gtk.Widget & {
6
- setModel(model: Gtk.SelectionModel | null): void;
7
- };
8
- type CollectionWidgetInput<W extends CollectionWidget, T, S> = {
9
- ref?: Ref<W | null> | undefined;
10
- items?: ItemNode<T>[] | undefined;
11
- sections?: SectionNode<S, T>[] | undefined;
12
- selectionMode?: Gtk.SelectionMode | null | undefined;
13
- selectedIds?: string[] | null | undefined;
14
- onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
15
- expandedIds?: string[] | null | undefined;
16
- onExpandedChange?: ((ids: string[]) => void) | null | undefined;
17
- renderHeader?: ((info: {
18
- section: S;
19
- }) => ReactNode) | null | undefined;
20
- };
21
- type CollectionWidgetResult<W extends CollectionWidget, T, S> = {
22
- widgetRef: RefObject<W | null>;
23
- setRef: RefCallback<W>;
24
- collection: CollectionModelResult<T, S>;
25
- };
26
- export declare const useCollectionWidget: <W extends CollectionWidget, T, S>(props: CollectionWidgetInput<W, T, S>) => CollectionWidgetResult<W, T, S>;
27
- export {};
28
- //# sourceMappingURL=use-collection-widget.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-collection-widget.d.ts","sourceRoot":"","sources":["../../src/hooks/use-collection-widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC3F,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,KAAK,qBAAqB,EAAsB,MAAM,2BAA2B,CAAC;AAG3F,KAAK,gBAAgB,GAAG,GAAG,CAAC,MAAM,GAAG;IACjC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;CACpD,CAAC;AAEF,KAAK,qBAAqB,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,EAAE,CAAC,IAAI;IAC3D,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IAC3C,aAAa,CAAC,EAAE,GAAG,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,kBAAkB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAClE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,gBAAgB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAChE,YAAY,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,KAAK,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC3E,CAAC;AAEF,KAAK,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,EAAE,CAAC,IAAI;IAC5D,SAAS,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC/B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,UAAU,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,gBAAgB,EAAE,CAAC,EAAE,CAAC,SACzD,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACtC,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAehC,CAAC"}
@@ -1,21 +0,0 @@
1
- import { useMergeRefs } from "@gtkx/react/internal";
2
- import { useRef } from "react";
3
- import { useCollectionModel } from "./use-collection-model.js";
4
- import { useInstalledModel } from "./use-installed-model.js";
5
- export const useCollectionWidget = (props) => {
6
- const widgetRef = useRef(null);
7
- const setRef = useMergeRefs(props.ref, widgetRef);
8
- const collection = useCollectionModel({
9
- items: props.items,
10
- sections: props.sections,
11
- selectionMode: props.selectionMode,
12
- selectedIds: props.selectedIds,
13
- onSelectionChanged: props.onSelectionChanged,
14
- expandedIds: props.expandedIds,
15
- onExpandedChange: props.onExpandedChange,
16
- renderHeader: props.renderHeader,
17
- });
18
- useInstalledModel(widgetRef, collection.installedModel, (widget, model) => widget.setModel(model));
19
- return { widgetRef, setRef, collection };
20
- };
21
- //# sourceMappingURL=use-collection-widget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-collection-widget.js","sourceRoot":"","sources":["../../src/hooks/use-collection-widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAA8D,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3F,OAAO,EAA8B,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAwB7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAC/B,KAAqC,EACN,EAAE;IACjC,MAAM,SAAS,GAAG,MAAM,CAAW,IAAI,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,YAAY,CAAI,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,kBAAkB,CAAO;QACxC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,YAAY,EAAE,KAAK,CAAC,YAAY;KACnC,CAAC,CAAC;IACH,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACnG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { type ReactNode, type Ref, type RefCallback, type RefObject, useRef } from \"react\";\nimport type { ItemNode, SectionNode } from \"../types.js\";\nimport { type CollectionModelResult, useCollectionModel } from \"./use-collection-model.js\";\nimport { useInstalledModel } from \"./use-installed-model.js\";\n\ntype CollectionWidget = Gtk.Widget & {\n setModel(model: Gtk.SelectionModel | null): void;\n};\n\ntype CollectionWidgetInput<W extends CollectionWidget, T, S> = {\n ref?: Ref<W | null> | undefined;\n items?: ItemNode<T>[] | undefined;\n sections?: SectionNode<S, T>[] | undefined;\n selectionMode?: Gtk.SelectionMode | null | undefined;\n selectedIds?: string[] | null | undefined;\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n expandedIds?: string[] | null | undefined;\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n renderHeader?: ((info: { section: S }) => ReactNode) | null | undefined;\n};\n\ntype CollectionWidgetResult<W extends CollectionWidget, T, S> = {\n widgetRef: RefObject<W | null>;\n setRef: RefCallback<W>;\n collection: CollectionModelResult<T, S>;\n};\n\nexport const useCollectionWidget = <W extends CollectionWidget, T, S>(\n props: CollectionWidgetInput<W, T, S>,\n): CollectionWidgetResult<W, T, S> => {\n const widgetRef = useRef<W | null>(null);\n const setRef = useMergeRefs<W>(props.ref, widgetRef);\n const collection = useCollectionModel<T, S>({\n items: props.items,\n sections: props.sections,\n selectionMode: props.selectionMode,\n selectedIds: props.selectedIds,\n onSelectionChanged: props.onSelectionChanged,\n expandedIds: props.expandedIds,\n onExpandedChange: props.onExpandedChange,\n renderHeader: props.renderHeader,\n });\n useInstalledModel(widgetRef, collection.installedModel, (widget, model) => widget.setModel(model));\n return { widgetRef, setRef, collection };\n};\n"]}
@@ -1,16 +0,0 @@
1
- import type * as GObject from "@gtkx/gi/gobject";
2
- import { type ObjectProp } from "@gtkx/react/internal";
3
- import type { ItemResolver } from "../utils/item-resolver.js";
4
- type DropDownSelectionObject = GObject.Object & {
5
- getSelected(): number;
6
- setSelected(position: number): void;
7
- };
8
- type DropDownSelectionOptions<T, S> = {
9
- widget: ObjectProp<DropDownSelectionObject>;
10
- resolver: ItemResolver<T, S>;
11
- selectedId: string | null | undefined;
12
- onSelectionChanged: ((id: string) => void) | null | undefined;
13
- };
14
- export declare const useDropDownSelection: <T, S>(options: DropDownSelectionOptions<T, S>) => number;
15
- export {};
16
- //# sourceMappingURL=use-drop-down-selection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-drop-down-selection.d.ts","sourceRoot":"","sources":["../../src/hooks/use-drop-down-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,KAAK,UAAU,EAAqC,MAAM,sBAAsB,CAAC;AAE1F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,KAAK,uBAAuB,GAAG,OAAO,CAAC,MAAM,GAAG;IAC5C,WAAW,IAAI,MAAM,CAAC;IACtB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,KAAK,wBAAwB,CAAC,CAAC,EAAE,CAAC,IAAI;IAClC,MAAM,EAAE,UAAU,CAAC,uBAAuB,CAAC,CAAC;IAC5C,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACtC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CACjE,CAAC;AAKF,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,CAAC,WAAW,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MA6BpF,CAAC"}
@@ -1,35 +0,0 @@
1
- import * as Gtk from "@gtkx/gi/gtk";
2
- import { useSignal } from "@gtkx/react";
3
- import { resolveObjectProp, useObjectValue } from "@gtkx/react/internal";
4
- import { useLayoutEffect, useRef } from "react";
5
- const normalizeSelected = (position) => position === Gtk.INVALID_LIST_POSITION || position < 0 ? -1 : position;
6
- export const useDropDownSelection = (options) => {
7
- const { widget, resolver, selectedId, onSelectionChanged } = options;
8
- const resolved = resolveObjectProp(widget);
9
- const selectedPosition = useObjectValue(widget, "notify::selected", (object) => object === null ? -1 : normalizeSelected(object.getSelected()));
10
- const resolverRef = useRef(resolver);
11
- resolverRef.current = resolver;
12
- const onSelectionChangedRef = useRef(onSelectionChanged);
13
- onSelectionChangedRef.current = onSelectionChanged;
14
- useLayoutEffect(() => {
15
- if (resolved === null || selectedId === undefined || selectedId === null)
16
- return;
17
- const position = resolverRef.current.positionOfId(selectedId);
18
- if (position < 0)
19
- return;
20
- if (normalizeSelected(resolved.getSelected()) !== position)
21
- resolved.setSelected(position);
22
- }, [resolved, selectedId, resolver]);
23
- useSignal(widget, "notify::selected", () => {
24
- if (resolved === null)
25
- return;
26
- const position = normalizeSelected(resolved.getSelected());
27
- if (position < 0)
28
- return;
29
- const id = resolverRef.current.idOf(position);
30
- if (id !== undefined)
31
- onSelectionChangedRef.current?.(id);
32
- });
33
- return selectedPosition;
34
- };
35
- //# sourceMappingURL=use-drop-down-selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-drop-down-selection.js","sourceRoot":"","sources":["../../src/hooks/use-drop-down-selection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAmB,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,eAAe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C,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAErC,SAAS,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE;QACvC,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO;QAC9B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;QAC3D,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO;QACzB,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,EAAE,KAAK,SAAS;YAAE,qBAAqB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { type ObjectProp, resolveObjectProp, useObjectValue } from \"@gtkx/react/internal\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { ItemResolver } from \"../utils/item-resolver.js\";\n\ntype DropDownSelectionObject = GObject.Object & {\n getSelected(): number;\n setSelected(position: number): void;\n};\n\ntype DropDownSelectionOptions<T, S> = {\n widget: ObjectProp<DropDownSelectionObject>;\n resolver: ItemResolver<T, S>;\n selectedId: string | null | undefined;\n onSelectionChanged: ((id: string) => void) | null | undefined;\n};\n\nconst normalizeSelected = (position: number): number =>\n position === Gtk.INVALID_LIST_POSITION || position < 0 ? -1 : position;\n\nexport const useDropDownSelection = <T, S>(options: DropDownSelectionOptions<T, S>): number => {\n const { widget, resolver, selectedId, onSelectionChanged } = options;\n const resolved = resolveObjectProp(widget);\n\n const selectedPosition = useObjectValue(widget, \"notify::selected\", (object) =>\n object === null ? -1 : normalizeSelected(object.getSelected()),\n );\n\n const resolverRef = useRef(resolver);\n resolverRef.current = resolver;\n const onSelectionChangedRef = useRef(onSelectionChanged);\n onSelectionChangedRef.current = onSelectionChanged;\n\n useLayoutEffect(() => {\n if (resolved === null || selectedId === undefined || selectedId === null) return;\n const position = resolverRef.current.positionOfId(selectedId);\n if (position < 0) return;\n if (normalizeSelected(resolved.getSelected()) !== position) resolved.setSelected(position);\n }, [resolved, selectedId, resolver]);\n\n useSignal(widget, \"notify::selected\", () => {\n if (resolved === null) return;\n const position = normalizeSelected(resolved.getSelected());\n if (position < 0) return;\n const id = resolverRef.current.idOf(position);\n if (id !== undefined) onSelectionChangedRef.current?.(id);\n });\n\n return selectedPosition;\n};\n"]}