@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,41 +1,31 @@
1
- import type * as Gio from "@gtkx/gi/gio";
2
- import type * as Gtk from "@gtkx/gi/gtk";
3
- import { type AdwComboRowProps } from "@gtkx/jsx/adw";
4
- import { type GtkDropDownProps } from "@gtkx/jsx/gtk";
5
- import { type ReactNode } from "react";
6
- import type { DropDownProps } from "./types.js";
7
- export interface DropDownWidget extends Gtk.Widget {
8
- getSelected(): number;
9
- setSelected(position: number): void;
10
- setModel(model: Gio.ListModel | null): void;
11
- setFactory(factory: Gtk.ListItemFactory | null): void;
12
- setListFactory(factory: Gtk.ListItemFactory | null): void;
13
- setHeaderFactory(factory: Gtk.ListItemFactory | null): void;
14
- }
1
+ import { GtkDropDown } from "@gtkx/jsx/gtk";
2
+ import { type ElementType, type ReactNode } from "react";
3
+ import type { ItemNode, RenderItemProps, SectionNode, WidgetProps } from "./types.js";
4
+ export type DropDownItemRenderer<T> = (props: RenderItemProps<T>) => ReactNode;
5
+ /** Declarative props for {@link DropDown}'s backing collection and cell rendering. */
6
+ export type DropDownDeclarativeProps<T = unknown, S = unknown> = {
7
+ items?: ItemNode<T>[] | undefined;
8
+ sections?: SectionNode<S, T>[] | undefined;
9
+ /** Id of the currently selected item, making the selection controlled. */
10
+ selectedId?: string | null | undefined;
11
+ onSelectionChanged?: ((id: string) => void) | null | undefined;
12
+ renderItem?: DropDownItemRenderer<T> | null | undefined;
13
+ /** Renderer for items in the open popup list, falling back to renderItem when omitted. */
14
+ renderListItem?: DropDownItemRenderer<T> | null | undefined;
15
+ /** Renderer for section headers in the popup list. */
16
+ renderHeader?: ((info: {
17
+ section: S;
18
+ }) => ReactNode) | null | undefined;
19
+ };
15
20
  /**
16
- * Props for the {@link DropDown} component: the raw `GtkDropDown` element
17
- * surface with its factory/model wiring replaced by the declarative
18
- * {@link DropDownProps} API.
21
+ * Props for {@link DropDown}. The backing widget is chosen through the `component` prop, defaulting to
22
+ * GtkDropDown, and its own props combine with {@link DropDownDeclarativeProps}.
19
23
  */
20
- export type DropDownComponentProps<T = unknown, S = unknown> = Omit<GtkDropDownProps, keyof DropDownProps<T, S>> & DropDownProps<T, S>;
24
+ export type DropDownProps<T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown> = WidgetProps<C, DropDownDeclarativeProps<T, S>, "model" | "factory" | "listFactory" | "headerFactory">;
21
25
  /**
22
- * Props for the {@link ComboRow} component: the raw `AdwComboRow` element
23
- * surface with its factory/model wiring replaced by the declarative
24
- * {@link DropDownProps} API.
26
+ * Renders a drop-down widget (Gtk.DropDown by default, or the widget given as `component`) backed by a
27
+ * collection model, with customizable rendering for the selected item, the popup list rows, and section
28
+ * headers.
25
29
  */
26
- export type ComboRowComponentProps<T = unknown, S = unknown> = Omit<AdwComboRowProps, keyof DropDownProps<T, S>> & DropDownProps<T, S>;
27
- /**
28
- * A `GtkDropDown` driven by a declarative `items` model with a controlled
29
- * `selectedId` and per-slot renderers for the selected face, the popup list,
30
- * and section headers. Supplying an external `model` switches to the
31
- * uncontrolled form.
32
- */
33
- export declare const DropDown: <T = unknown, S = unknown>(props: DropDownComponentProps<T, S>) => ReactNode;
34
- /**
35
- * An `AdwComboRow` driven by a declarative `items` model with a controlled
36
- * `selectedId` and per-slot renderers for the selected face, the popup list,
37
- * and section headers. Supplying an external `model` switches to the
38
- * uncontrolled form.
39
- */
40
- export declare const ComboRow: <T = unknown, S = unknown>(props: ComboRowComponentProps<T, S>) => ReactNode;
30
+ export declare const DropDown: <T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown>(props: DropDownProps<T, S, C>) => ReactNode;
41
31
  //# sourceMappingURL=drop-down.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAe,KAAK,gBAAgB,EAAY,MAAM,eAAe,CAAC;AAE7E,OAAO,EAIH,KAAK,SAAS,EAKjB,MAAM,OAAO,CAAC;AAOf,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,YAAY,CAAC;AAI1D,MAAM,WAAW,cAAe,SAAQ,GAAG,CAAC,MAAM;IAC9C,WAAW,IAAI,MAAM,CAAC;IACtB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAC5C,UAAU,CAAC,OAAO,EAAE,GAAG,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E,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,WAAW,GAAG,OAAO,WAAW,SAClF,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC9B,SA6CF,CAAC"}
package/dist/drop-down.js CHANGED
@@ -1,50 +1,34 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { AdwComboRow } from "@gtkx/jsx/adw";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
2
  import { GtkDropDown, GtkLabel } from "@gtkx/jsx/gtk";
4
- import { useForwardedRef } from "@gtkx/react";
5
- import { createElement, useCallback, useRef, useState, } from "react";
3
+ import { useMergeRefs } from "@gtkx/react/internal";
4
+ import { useCallback, useRef, useState } from "react";
5
+ import { CellRenderHost, HeaderRenderHost, itemRenderer } from "./cell.js";
6
+ import { makeFactoryInstaller, useCellContainers } from "./hooks/use-cell-containers.js";
6
7
  import { useDropDownSelection } from "./hooks/use-drop-down-selection.js";
8
+ import { useInstalledModel } from "./hooks/use-installed-model.js";
7
9
  import { useListModel } from "./hooks/use-list-model.js";
8
- import { useModelInstallation } from "./hooks/use-model-installation.js";
9
- import { useRealizedSlots } from "./hooks/use-realized-slots.js";
10
- import { ListPortalHost } from "./list-portal-host.js";
11
- const itemFactoryBinding = {
12
- install: (widget, factory) => widget.setFactory(factory),
13
- uninstall: (widget) => widget.setFactory(null),
14
- };
15
- const listFactoryBinding = {
16
- install: (widget, factory) => widget.setListFactory(factory),
17
- uninstall: (widget) => widget.setListFactory(null),
18
- };
19
- const headerFactoryBinding = {
20
- install: (widget, factory) => widget.setHeaderFactory(factory),
21
- uninstall: (widget) => widget.setHeaderFactory(null),
22
- };
23
- const defaultRenderer = (value, _treeRow, isHeader) => {
24
- if (isHeader || value === undefined || value === null)
10
+ const itemFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setFactory(factory));
11
+ const listFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setListFactory(factory));
12
+ const headerFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setHeaderFactory(factory));
13
+ const defaultRenderer = (value) => {
14
+ if (value === undefined || value === null)
25
15
  return null;
26
- return createElement(GtkLabel, { label: String(value) });
16
+ return _jsx(GtkLabel, { children: String(value) });
27
17
  };
28
18
  const toItemRenderer = (renderItem) => {
29
19
  if (typeof renderItem !== "function")
30
20
  return defaultRenderer;
31
- return (value, _treeRow, isHeader) => (isHeader ? null : renderItem(value));
21
+ return itemRenderer(renderItem);
32
22
  };
33
- const toPopupRenderer = (renderListItem, renderItem) => {
23
+ const toListRenderer = (renderListItem, renderItem) => {
34
24
  if (typeof renderListItem === "function")
35
- return (value, _treeRow, isHeader) => (isHeader ? null : renderListItem(value));
25
+ return itemRenderer(renderListItem);
36
26
  return toItemRenderer(renderItem);
37
27
  };
38
- const toHeaderRenderer = (renderHeader) => {
39
- if (typeof renderHeader !== "function")
40
- return () => null;
41
- return (value) => renderHeader(value);
42
- };
43
- const createFaceResolver = (resolver, selectedPosition) => ({
44
- count: resolver.count,
45
- positionOf: (id) => resolver.positionOf(id),
28
+ const createSelectionResolver = (resolver, selectedPosition) => ({
29
+ positionOfId: (id) => resolver.positionOfId(id),
46
30
  idOf: (position) => resolver.idOf(position),
47
- resolve: (_position, treeRow) => resolver.resolve(selectedPosition, treeRow, null),
31
+ resolve: (_position, treeRow) => resolver.resolve(selectedPosition, treeRow),
48
32
  });
49
33
  const useDropDownWiring = (props) => {
50
34
  const widgetRef = useRef(null);
@@ -53,17 +37,16 @@ const useDropDownWiring = (props) => {
53
37
  widgetRef.current = value;
54
38
  setWidget(value);
55
39
  }, []);
56
- const [, setRef] = useForwardedRef(props.ref, captureWidget);
57
- const externalModel = props.model;
58
- const listModel = useListModel(externalModel === undefined ? { items: props.items ?? undefined } : { model: externalModel });
59
- const useHeader = externalModel === undefined && typeof props.renderHeader === "function";
60
- const face = useRealizedSlots({ target: widgetRef, binding: itemFactoryBinding });
61
- const popup = useRealizedSlots({ target: widgetRef, binding: listFactoryBinding });
62
- const header = useRealizedSlots({
63
- target: useHeader ? widgetRef : null,
64
- binding: headerFactoryBinding,
40
+ const setRef = useMergeRefs(props.ref, captureWidget);
41
+ const listModel = useListModel({ items: props.items, sections: props.sections });
42
+ const useHeader = typeof props.renderHeader === "function";
43
+ const selectionStore = useCellContainers({ object: widgetRef, installer: itemFactoryInstaller });
44
+ const listStore = useCellContainers({ object: widgetRef, installer: listFactoryInstaller });
45
+ const headerStore = useCellContainers({
46
+ object: useHeader ? widgetRef : null,
47
+ installer: headerFactoryInstaller,
65
48
  });
66
- useModelInstallation(widgetRef, listModel.model, (widget, model) => widget.setModel(model));
49
+ useInstalledModel(widgetRef, listModel.model, (widget, value) => widget.setModel(value));
67
50
  const selectedPosition = useDropDownSelection({
68
51
  widget,
69
52
  resolver: listModel.resolver,
@@ -72,58 +55,35 @@ const useDropDownWiring = (props) => {
72
55
  });
73
56
  const controlledPosition = props.selectedId === undefined || props.selectedId === null
74
57
  ? -1
75
- : listModel.resolver.positionOf(props.selectedId);
76
- const facePosition = controlledPosition >= 0 ? controlledPosition : selectedPosition < 0 ? 0 : selectedPosition;
58
+ : listModel.resolver.positionOfId(props.selectedId);
59
+ const selectionPosition = controlledPosition >= 0 ? controlledPosition : selectedPosition < 0 ? 0 : selectedPosition;
77
60
  return {
78
61
  setRef,
79
62
  resolver: listModel.resolver,
80
- faceResolver: createFaceResolver(listModel.resolver, facePosition),
63
+ selectionResolver: createSelectionResolver(listModel.resolver, selectionPosition),
81
64
  headerResolver: listModel.headerResolver,
82
- faceStore: face.store,
83
- popupStore: popup.store,
84
- headerStore: header.store,
65
+ selectionStore,
66
+ listStore,
67
+ headerStore,
85
68
  useHeader,
86
69
  };
87
70
  };
88
- const DropDownImpl = (props) => {
89
- const { setRef, resolver, faceResolver, headerResolver, faceStore, popupStore, headerStore, useHeader } = useDropDownWiring(props);
90
- const intrinsic = createElement(props.element, { ...props.intrinsicProps, ref: setRef });
91
- return (_jsxs(_Fragment, { children: [intrinsic, _jsx(ListPortalHost, { store: faceStore, resolver: faceResolver, render: toItemRenderer(props.renderItem) }), _jsx(ListPortalHost, { store: popupStore, resolver: resolver, render: toPopupRenderer(props.renderListItem, props.renderItem) }), useHeader ? (_jsx(ListPortalHost, { store: headerStore, resolver: headerResolver, render: toHeaderRenderer(props.renderHeader) })) : null] }));
92
- };
93
- const extractDropDownProps = (props) => {
94
- const { ref, items, model, renderItem, renderListItem, renderHeader, selectedId, onSelectionChanged, ...intrinsicProps } = props;
95
- return {
96
- impl: {
97
- ref,
98
- items: items,
99
- model: model,
100
- renderItem: renderItem,
101
- renderListItem: renderListItem,
102
- renderHeader: renderHeader,
103
- selectedId: selectedId,
104
- onSelectionChanged: onSelectionChanged,
105
- },
106
- intrinsicProps: intrinsicProps,
107
- };
108
- };
109
71
  /**
110
- * A `GtkDropDown` driven by a declarative `items` model with a controlled
111
- * `selectedId` and per-slot renderers for the selected face, the popup list,
112
- * and section headers. Supplying an external `model` switches to the
113
- * uncontrolled form.
72
+ * Renders a drop-down widget (Gtk.DropDown by default, or the widget given as `component`) backed by a
73
+ * collection model, with customizable rendering for the selected item, the popup list rows, and section
74
+ * headers.
114
75
  */
115
76
  export const DropDown = (props) => {
116
- const { impl, intrinsicProps } = extractDropDownProps(props);
117
- return _jsx(DropDownImpl, { element: GtkDropDown, intrinsicProps: intrinsicProps, ...impl });
118
- };
119
- /**
120
- * An `AdwComboRow` driven by a declarative `items` model with a controlled
121
- * `selectedId` and per-slot renderers for the selected face, the popup list,
122
- * and section headers. Supplying an external `model` switches to the
123
- * uncontrolled form.
124
- */
125
- export const ComboRow = (props) => {
126
- const { impl, intrinsicProps } = extractDropDownProps(props);
127
- return _jsx(DropDownImpl, { element: AdwComboRow, intrinsicProps: intrinsicProps, ...impl });
77
+ const { component, ref, items, sections, renderItem, renderListItem, renderHeader, selectedId, onSelectionChanged, ...intrinsicProps } = props;
78
+ const Component = component ?? GtkDropDown;
79
+ const wiring = useDropDownWiring({
80
+ ref,
81
+ items,
82
+ sections,
83
+ selectedId,
84
+ onSelectionChanged,
85
+ renderHeader,
86
+ });
87
+ return (_jsxs(_Fragment, { children: [_jsx(Component, { ...intrinsicProps, ref: wiring.setRef }), _jsx(CellRenderHost, { store: wiring.selectionStore, resolver: wiring.selectionResolver, render: toItemRenderer(renderItem) }), _jsx(CellRenderHost, { store: wiring.listStore, resolver: wiring.resolver, render: toListRenderer(renderListItem, renderItem) }), _jsx(HeaderRenderHost, { useHeader: wiring.useHeader, store: wiring.headerStore, resolver: wiring.headerResolver, renderHeader: renderHeader })] }));
128
88
  };
129
89
  //# sourceMappingURL=drop-down.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"drop-down.js","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,WAAW,EAAyB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACH,aAAa,EAKb,WAAW,EACX,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAuB,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAevD,MAAM,kBAAkB,GAAmC;IACvD,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;IACxD,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;CACjD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nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { type ElementType, type ReactNode, type Ref, useCallback, useRef, useState } from \"react\";\nimport { type CellRenderer, CellRenderHost, HeaderRenderHost, itemRenderer } from \"./cell.js\";\nimport { makeFactoryInstaller, useCellContainers } from \"./hooks/use-cell-containers.js\";\nimport { useDropDownSelection } from \"./hooks/use-drop-down-selection.js\";\nimport { useInstalledModel } from \"./hooks/use-installed-model.js\";\nimport { useListModel } from \"./hooks/use-list-model.js\";\nimport type { ItemNode, RenderItemProps, SectionNode, WidgetProps } from \"./types.js\";\nimport type { CellContainerStore } from \"./utils/cell-container-store.js\";\nimport type { ItemResolver } from \"./utils/item-resolver.js\";\n\nexport type DropDownItemRenderer<T> = (props: RenderItemProps<T>) => ReactNode;\n\nconst itemFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) => widget.setFactory(factory));\n\nconst listFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) => widget.setListFactory(factory));\n\nconst headerFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) =>\n widget.setHeaderFactory(factory),\n);\n\nconst defaultRenderer: CellRenderer<unknown, unknown> = (value) => {\n if (value === undefined || value === null) return null;\n return <GtkLabel>{String(value)}</GtkLabel>;\n};\n\nconst toItemRenderer = <T, S>(renderItem: DropDownItemRenderer<T> | null | undefined): CellRenderer<T, S> => {\n if (typeof renderItem !== \"function\") return defaultRenderer as CellRenderer<T, S>;\n return itemRenderer<T, S>(renderItem);\n};\n\nconst toListRenderer = <T, S>(\n renderListItem: DropDownItemRenderer<T> | null | undefined,\n renderItem: DropDownItemRenderer<T> | null | undefined,\n): CellRenderer<T, S> => {\n if (typeof renderListItem === \"function\") return itemRenderer<T, S>(renderListItem);\n return toItemRenderer<T, S>(renderItem);\n};\n\nconst createSelectionResolver = <T, S>(resolver: ItemResolver<T, S>, selectedPosition: number): ItemResolver<T, S> => ({\n positionOfId: (id) => resolver.positionOfId(id),\n idOf: (position) => resolver.idOf(position),\n resolve: (_position, treeRow) => resolver.resolve(selectedPosition, treeRow),\n});\n\n/** Declarative props for {@link DropDown}'s backing collection and cell rendering. */\nexport type DropDownDeclarativeProps<T = unknown, S = unknown> = {\n items?: ItemNode<T>[] | undefined;\n sections?: SectionNode<S, T>[] | undefined;\n /** Id of the currently selected item, making the selection controlled. */\n selectedId?: string | null | undefined;\n onSelectionChanged?: ((id: string) => void) | null | undefined;\n renderItem?: DropDownItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: DropDownItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: ((info: { section: S }) => ReactNode) | null | undefined;\n};\n\n/**\n * Props for {@link DropDown}. The backing widget is chosen through the `component` prop, defaulting to\n * GtkDropDown, and its own props combine with {@link DropDownDeclarativeProps}.\n */\nexport type DropDownProps<T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown> = WidgetProps<\n C,\n DropDownDeclarativeProps<T, S>,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\"\n>;\n\ninterface NormalizedDropDownProps<T, S> {\n ref: Ref<Gtk.DropDown | null> | undefined;\n items: ItemNode<T>[] | undefined;\n sections: SectionNode<S, T>[] | undefined;\n selectedId: string | null | undefined;\n onSelectionChanged: ((id: string) => void) | null | undefined;\n renderHeader: ((info: { section: S }) => ReactNode) | null | undefined;\n}\n\ninterface DropDownWiring<T, S> {\n setRef: (value: Gtk.DropDown | null) => void;\n resolver: ItemResolver<T, S>;\n selectionResolver: ItemResolver<T, S>;\n headerResolver: ItemResolver<T, S>;\n selectionStore: CellContainerStore;\n listStore: CellContainerStore;\n headerStore: CellContainerStore;\n useHeader: boolean;\n}\n\nconst useDropDownWiring = <T, S>(props: NormalizedDropDownProps<T, S>): DropDownWiring<T, S> => {\n const widgetRef = useRef<Gtk.DropDown | null>(null);\n const [widget, setWidget] = useState<Gtk.DropDown | null>(null);\n const captureWidget = useCallback((value: Gtk.DropDown | null) => {\n widgetRef.current = value;\n setWidget(value);\n }, []);\n const setRef = useMergeRefs<Gtk.DropDown>(props.ref, captureWidget);\n\n const listModel = useListModel<T, S>({ items: props.items, sections: props.sections });\n\n const useHeader = typeof props.renderHeader === \"function\";\n\n const selectionStore = useCellContainers<Gtk.DropDown>({ object: widgetRef, installer: itemFactoryInstaller });\n const listStore = useCellContainers<Gtk.DropDown>({ object: widgetRef, installer: listFactoryInstaller });\n const headerStore = useCellContainers<Gtk.DropDown>({\n object: useHeader ? widgetRef : null,\n installer: headerFactoryInstaller,\n });\n\n useInstalledModel(widgetRef, listModel.model, (widget, value) => widget.setModel(value));\n\n const selectedPosition = useDropDownSelection<T, S>({\n widget,\n resolver: listModel.resolver,\n selectedId: props.selectedId,\n onSelectionChanged: props.onSelectionChanged,\n });\n\n const controlledPosition =\n props.selectedId === undefined || props.selectedId === null\n ? -1\n : listModel.resolver.positionOfId(props.selectedId);\n const selectionPosition =\n controlledPosition >= 0 ? controlledPosition : selectedPosition < 0 ? 0 : selectedPosition;\n\n return {\n setRef,\n resolver: listModel.resolver,\n selectionResolver: createSelectionResolver(listModel.resolver, selectionPosition),\n headerResolver: listModel.headerResolver,\n selectionStore,\n listStore,\n headerStore,\n useHeader,\n };\n};\n\n/**\n * Renders a drop-down widget (Gtk.DropDown by default, or the widget given as `component`) backed by a\n * collection model, with customizable rendering for the selected item, the popup list rows, and section\n * headers.\n */\nexport const DropDown = <T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown>(\n props: DropDownProps<T, S, C>,\n): ReactNode => {\n const {\n component,\n ref,\n items,\n sections,\n renderItem,\n renderListItem,\n renderHeader,\n selectedId,\n onSelectionChanged,\n ...intrinsicProps\n } = props;\n const Component: ElementType = component ?? GtkDropDown;\n\n const wiring = useDropDownWiring<T, S>({\n ref,\n items,\n sections,\n selectedId,\n onSelectionChanged,\n renderHeader,\n });\n\n return (\n <>\n <Component {...intrinsicProps} ref={wiring.setRef} />\n <CellRenderHost\n store={wiring.selectionStore}\n resolver={wiring.selectionResolver}\n render={toItemRenderer<T, S>(renderItem)}\n />\n <CellRenderHost\n store={wiring.listStore}\n resolver={wiring.resolver}\n render={toListRenderer<T, S>(renderListItem, renderItem)}\n />\n <HeaderRenderHost\n useHeader={wiring.useHeader}\n store={wiring.headerStore}\n resolver={wiring.headerResolver}\n renderHeader={renderHeader}\n />\n </>\n );\n};\n"]}
@@ -0,0 +1,26 @@
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
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,40 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixed.js","sourceRoot":"","sources":["../src/fixed.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,aAAa,EAKb,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAC;AAGf,MAAM,YAAY,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAE5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AC,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"]}
@@ -1,16 +1,19 @@
1
1
  import { type GtkGridViewProps } from "@gtkx/jsx/gtk";
2
- import type { ReactNode } from "react";
3
- import type { GridViewProps } from "./types.js";
2
+ import { type ReactNode } from "react";
3
+ import type { CollectionItemSizeProps, ControlledSelectionProps, ItemNode, RenderItemProps } from "./types.js";
4
+ export type GridViewDeclarativeProps<T = unknown> = CollectionItemSizeProps & ControlledSelectionProps & {
5
+ items?: ItemNode<T>[] | undefined;
6
+ renderItem: (props: RenderItemProps<T>) => ReactNode;
7
+ };
4
8
  /**
5
- * Props for the {@link GridView} component: the raw `GtkGridView` element
6
- * surface with its factory/model wiring replaced by the declarative
7
- * {@link GridViewProps} API.
9
+ * Props for {@link GridView}. Combines the underlying Gtk.GridView props with
10
+ * declarative collection props: items, a per-cell renderItem, controlled selection,
11
+ * and estimated item sizing.
8
12
  */
9
- export type GridViewComponentProps<T = unknown> = Omit<GtkGridViewProps, keyof GridViewProps<T>> & GridViewProps<T>;
13
+ export type GridViewProps<T = unknown> = Omit<GtkGridViewProps, "model" | "factory" | keyof GridViewDeclarativeProps<T>> & GridViewDeclarativeProps<T>;
10
14
  /**
11
- * A `GtkGridView` driven by a declarative `items`/`renderItem` API with
12
- * optional controlled selection. Supplying an external `model` switches to the
13
- * uncontrolled form.
15
+ * Renders a Gtk.GridView: a scrollable grid of uniformly sized cells backed by a
16
+ * collection model, with each cell drawn by renderItem.
14
17
  */
15
- export declare const GridView: <T = unknown>(props: GridViewComponentProps<T>) => ReactNode;
18
+ export declare const GridView: <T = unknown>(props: GridViewProps<T>) => ReactNode;
16
19
  //# sourceMappingURL=grid-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grid-view.d.ts","sourceRoot":"","sources":["../src/grid-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;AAWhD;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,gBAAgB,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAEpH;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,GAAG,OAAO,EAAE,OAAO,sBAAsB,CAAC,CAAC,CAAC,KAAG,SA2CxE,CAAC"}
1
+ {"version":3,"file":"grid-view.d.ts","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,OAAO,CAAC;AAKzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI/G,MAAM,MAAM,wBAAwB,CAAC,CAAC,GAAG,OAAO,IAAI,uBAAuB,GACvE,wBAAwB,GAAG;IACvB,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CACxD,CAAC;AAEN;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CACzC,gBAAgB,EAChB,OAAO,GAAG,SAAS,GAAG,MAAM,wBAAwB,CAAC,CAAC,CAAC,CAC1D,GACG,wBAAwB,CAAC,CAAC,CAAC,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,GAAG,OAAO,SAAS,aAAa,CAAC,CAAC,CAAC,KAAG,SA+C/D,CAAC"}
package/dist/grid-view.js CHANGED
@@ -1,22 +1,36 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { GtkGridView } from "@gtkx/jsx/gtk";
3
- import { CollectionView } from "./collection-view.js";
4
- const factoryBinding = {
5
- install: (widget, factory) => widget.setFactory(factory),
6
- uninstall: (widget) => widget.setFactory(null),
7
- };
8
- const modelBinding = {
9
- install: (widget, model) => widget.setModel(model),
10
- };
3
+ import { useMergeRefs } from "@gtkx/react/internal";
4
+ import { useRef } from "react";
5
+ import { CellRenderHost, itemRenderer } from "./cell.js";
6
+ import { makeFactoryInstaller, useCellContainers } from "./hooks/use-cell-containers.js";
7
+ import { useCollectionModel } from "./hooks/use-collection-model.js";
8
+ import { useInstalledModel } from "./hooks/use-installed-model.js";
9
+ const factoryInstaller = makeFactoryInstaller((widget, factory) => widget.setFactory(factory));
11
10
  /**
12
- * A `GtkGridView` driven by a declarative `items`/`renderItem` API with
13
- * optional controlled selection. Supplying an external `model` switches to the
14
- * uncontrolled form.
11
+ * Renders a Gtk.GridView: a scrollable grid of uniformly sized cells backed by a
12
+ * collection model, with each cell drawn by renderItem.
15
13
  */
16
14
  export const GridView = (props) => {
17
- const { ref, items, model, renderItem, selected, selectionMode, onSelectionChanged, estimatedItemHeight, estimatedItemWidth, ...intrinsicProps } = props;
18
- const renderItemFn = renderItem;
19
- const slotRenderer = (value, _treeRow, isHeader) => isHeader ? null : renderItemFn(value);
20
- return (_jsx(CollectionView, { element: GtkGridView, intrinsicProps: intrinsicProps, ref: ref, items: model === undefined ? items : undefined, model: model, renderItem: slotRenderer, autoexpand: undefined, renderHeader: undefined, estimatedHeight: estimatedItemHeight, estimatedWidth: estimatedItemWidth, selected: selected, selectionMode: selectionMode, onSelectionChanged: onSelectionChanged, factoryBinding: factoryBinding, headerFactoryBinding: undefined, modelBinding: modelBinding }));
15
+ const { ref, items, renderItem, selectedIds, selectionMode, onSelectionChanged, estimatedItemHeight, estimatedItemWidth, ...intrinsicProps } = props;
16
+ const cellRenderer = itemRenderer(renderItem);
17
+ const widgetRef = useRef(null);
18
+ const setRef = useMergeRefs(ref, widgetRef);
19
+ const collection = useCollectionModel({
20
+ items,
21
+ sections: undefined,
22
+ selectionMode,
23
+ selectedIds,
24
+ onSelectionChanged,
25
+ renderHeader: undefined,
26
+ });
27
+ const itemStore = useCellContainers({
28
+ object: widgetRef,
29
+ installer: factoryInstaller,
30
+ estimatedHeight: estimatedItemHeight,
31
+ estimatedWidth: estimatedItemWidth,
32
+ });
33
+ useInstalledModel(widgetRef, collection.installedModel, (widget, value) => widget.setModel(value));
34
+ return (_jsxs(_Fragment, { children: [_jsx(GtkGridView, { ...intrinsicProps, ref: setRef }), _jsx(CellRenderHost, { store: itemStore, resolver: collection.resolver, render: cellRenderer })] }));
21
35
  };
22
36
  //# sourceMappingURL=grid-view.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grid-view.js","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAqB,MAAM,sBAAsB,CAAC;AAIzE,MAAM,cAAc,GAAG;IACnB,OAAO,EAAE,CAAC,MAAoB,EAAE,OAAkC,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;IACjG,SAAS,EAAE,CAAC,MAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,YAAY,GAA+B;IAC7C,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAA2B,CAAC;CAC3E,CAAC;AASF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAc,KAAgC,EAAa,EAAE;IACjF,MAAM,EACF,GAAG,EACH,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,GAAG,cAAc,EACpB,GAAG,KAKH,CAAC;IAEF,MAAM,YAAY,GAAG,UAAoC,CAAC;IAC1D,MAAM,YAAY,GAA6B,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAA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,CAAC,MAAM,QAAQ,GAAG,CAAc,KAAuB,EAAa,EAAE;IACxE,MAAM,EACF,GAAG,EACH,KAAK,EACL,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,GAAG,cAAc,EACpB,GAAG,KAKH,CAAC;IAEF,MAAM,YAAY,GAA6B,YAAY,CAAa,UAAU,CAAC,CAAC;IAEpF,MAAM,SAAS,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,YAAY,CAAe,GAAG,EAAE,SAAS,CAAC,CAAC;IAE1D,MAAM,UAAU,GAAG,kBAAkB,CAAa;QAC9C,KAAK;QACL,QAAQ,EAAE,SAAS;QACnB,aAAa;QACb,WAAW;QACX,kBAAkB;QAClB,YAAY,EAAE,SAAS;KAC1B,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,iBAAiB,CAAe;QAC9C,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,gBAAgB;QAC3B,eAAe,EAAE,mBAAmB;QACpC,cAAc,EAAE,kBAAkB;KACrC,CAAC,CAAC;IAEH,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnG,OAAO,CACH,8BACI,KAAC,WAAW,OAAK,cAAc,EAAE,GAAG,EAAE,MAAM,GAAI,EAChD,KAAC,cAAc,IAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAI,IAC1F,CACN,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkGridView, type GtkGridViewProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { type ReactNode, type Ref, useRef } from \"react\";\nimport { type CellRenderer, CellRenderHost, itemRenderer } from \"./cell.js\";\nimport { makeFactoryInstaller, useCellContainers } from \"./hooks/use-cell-containers.js\";\nimport { useCollectionModel } from \"./hooks/use-collection-model.js\";\nimport { useInstalledModel } from \"./hooks/use-installed-model.js\";\nimport type { CollectionItemSizeProps, ControlledSelectionProps, ItemNode, RenderItemProps } from \"./types.js\";\n\nconst factoryInstaller = makeFactoryInstaller<Gtk.GridView>((widget, factory) => widget.setFactory(factory));\n\nexport type GridViewDeclarativeProps<T = unknown> = CollectionItemSizeProps &\n ControlledSelectionProps & {\n items?: ItemNode<T>[] | undefined;\n renderItem: (props: RenderItemProps<T>) => ReactNode;\n };\n\n/**\n * Props for {@link GridView}. Combines the underlying Gtk.GridView props with\n * declarative collection props: items, a per-cell renderItem, controlled selection,\n * and estimated item sizing.\n */\nexport type GridViewProps<T = unknown> = Omit<\n GtkGridViewProps,\n \"model\" | \"factory\" | keyof GridViewDeclarativeProps<T>\n> &\n GridViewDeclarativeProps<T>;\n\n/**\n * Renders a Gtk.GridView: a scrollable grid of uniformly sized cells backed by a\n * collection model, with each cell drawn by renderItem.\n */\nexport const GridView = <T = unknown>(props: GridViewProps<T>): ReactNode => {\n const {\n ref,\n items,\n renderItem,\n selectedIds,\n selectionMode,\n onSelectionChanged,\n estimatedItemHeight,\n estimatedItemWidth,\n ...intrinsicProps\n } = props as GridViewDeclarativeProps<T> & {\n ref?: Ref<Gtk.GridView | null>;\n estimatedItemHeight?: number;\n estimatedItemWidth?: number;\n [key: string]: unknown;\n };\n\n const cellRenderer: CellRenderer<T, unknown> = itemRenderer<T, unknown>(renderItem);\n\n const widgetRef = useRef<Gtk.GridView | null>(null);\n const setRef = useMergeRefs<Gtk.GridView>(ref, widgetRef);\n\n const collection = useCollectionModel<T, unknown>({\n items,\n sections: undefined,\n selectionMode,\n selectedIds,\n onSelectionChanged,\n renderHeader: undefined,\n });\n\n const itemStore = useCellContainers<Gtk.GridView>({\n object: widgetRef,\n installer: factoryInstaller,\n estimatedHeight: estimatedItemHeight,\n estimatedWidth: estimatedItemWidth,\n });\n\n useInstalledModel(widgetRef, collection.installedModel, (widget, value) => widget.setModel(value));\n\n return (\n <>\n <GtkGridView {...intrinsicProps} ref={setRef} />\n <CellRenderHost store={itemStore} resolver={collection.resolver} render={cellRenderer} />\n </>\n );\n};\n"]}
package/dist/grid.d.ts ADDED
@@ -0,0 +1,27 @@
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
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,48 @@
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
@@ -0,0 +1 @@
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,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i/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"]}