@gtkx/components 1.0.0-rc.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +8 -9
  2. package/dist/adw/combo-row.d.ts +1 -0
  3. package/dist/adw/combo-row.d.ts.map +1 -1
  4. package/dist/adw/combo-row.js.map +1 -1
  5. package/dist/adw/types.d.ts +2 -1
  6. package/dist/adw/types.d.ts.map +1 -1
  7. package/dist/adw/types.js.map +1 -1
  8. package/dist/column-view.d.ts +2 -2
  9. package/dist/column-view.d.ts.map +1 -1
  10. package/dist/column-view.js +15 -13
  11. package/dist/column-view.js.map +1 -1
  12. package/dist/drop-down.d.ts +1 -0
  13. package/dist/drop-down.d.ts.map +1 -1
  14. package/dist/drop-down.js.map +1 -1
  15. package/dist/grid-view.js +2 -2
  16. package/dist/grid-view.js.map +1 -1
  17. package/dist/index.d.ts +1 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +0 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/internal/cells.d.ts +32 -24
  22. package/dist/internal/cells.d.ts.map +1 -1
  23. package/dist/internal/cells.js +168 -77
  24. package/dist/internal/cells.js.map +1 -1
  25. package/dist/internal/collection-index.d.ts +9 -13
  26. package/dist/internal/collection-index.d.ts.map +1 -1
  27. package/dist/internal/collection-index.js +33 -70
  28. package/dist/internal/collection-index.js.map +1 -1
  29. package/dist/internal/collection-model.d.ts +23 -2
  30. package/dist/internal/collection-model.d.ts.map +1 -1
  31. package/dist/internal/collection-model.js +210 -98
  32. package/dist/internal/collection-model.js.map +1 -1
  33. package/dist/internal/collection.d.ts +9 -12
  34. package/dist/internal/collection.d.ts.map +1 -1
  35. package/dist/internal/collection.js +38 -49
  36. package/dist/internal/collection.js.map +1 -1
  37. package/dist/internal/controlled-sync.d.ts +11 -0
  38. package/dist/internal/controlled-sync.d.ts.map +1 -0
  39. package/dist/internal/controlled-sync.js +19 -0
  40. package/dist/internal/controlled-sync.js.map +1 -0
  41. package/dist/internal/drop-down.d.ts.map +1 -1
  42. package/dist/internal/drop-down.js +27 -15
  43. package/dist/internal/drop-down.js.map +1 -1
  44. package/dist/internal/expansion.d.ts +3 -2
  45. package/dist/internal/expansion.d.ts.map +1 -1
  46. package/dist/internal/expansion.js +80 -47
  47. package/dist/internal/expansion.js.map +1 -1
  48. package/dist/internal/keys.d.ts +5 -0
  49. package/dist/internal/keys.d.ts.map +1 -0
  50. package/dist/internal/keys.js +13 -0
  51. package/dist/internal/keys.js.map +1 -0
  52. package/dist/internal/selection.d.ts +3 -2
  53. package/dist/internal/selection.d.ts.map +1 -1
  54. package/dist/internal/selection.js +68 -35
  55. package/dist/internal/selection.js.map +1 -1
  56. package/dist/internal/slots.d.ts +10 -0
  57. package/dist/internal/slots.d.ts.map +1 -0
  58. package/dist/internal/slots.js +43 -0
  59. package/dist/internal/slots.js.map +1 -0
  60. package/dist/internal/tree-expansion.d.ts +20 -0
  61. package/dist/internal/tree-expansion.d.ts.map +1 -0
  62. package/dist/internal/tree-expansion.js +68 -0
  63. package/dist/internal/tree-expansion.js.map +1 -0
  64. package/dist/internal/tree-order.d.ts +27 -0
  65. package/dist/internal/tree-order.d.ts.map +1 -0
  66. package/dist/internal/tree-order.js +71 -0
  67. package/dist/internal/tree-order.js.map +1 -0
  68. package/dist/internal/use-collection.d.ts +5 -5
  69. package/dist/internal/use-collection.d.ts.map +1 -1
  70. package/dist/internal/use-collection.js +6 -6
  71. package/dist/internal/use-collection.js.map +1 -1
  72. package/dist/list-view.d.ts.map +1 -1
  73. package/dist/list-view.js +6 -6
  74. package/dist/list-view.js.map +1 -1
  75. package/dist/types.d.ts +127 -54
  76. package/dist/types.d.ts.map +1 -1
  77. package/dist/types.js.map +1 -1
  78. package/package.json +7 -7
  79. package/src/adw/combo-row.tsx +1 -0
  80. package/src/adw/types.ts +2 -1
  81. package/src/column-view.tsx +38 -35
  82. package/src/drop-down.tsx +1 -0
  83. package/src/grid-view.tsx +2 -2
  84. package/src/index.ts +10 -11
  85. package/src/internal/cells.tsx +345 -123
  86. package/src/internal/collection-index.ts +51 -99
  87. package/src/internal/collection-model.ts +259 -110
  88. package/src/internal/collection.ts +46 -68
  89. package/src/internal/controlled-sync.ts +34 -0
  90. package/src/internal/drop-down.tsx +44 -23
  91. package/src/internal/expansion.ts +104 -67
  92. package/src/internal/keys.ts +18 -0
  93. package/src/internal/selection.tsx +100 -51
  94. package/src/internal/slots.ts +67 -0
  95. package/src/internal/tree-expansion.ts +110 -0
  96. package/src/internal/tree-order.ts +138 -0
  97. package/src/internal/use-collection.tsx +11 -11
  98. package/src/list-view.tsx +14 -10
  99. package/src/types.ts +140 -65
  100. package/dist/size-group.d.ts +0 -12
  101. package/dist/size-group.d.ts.map +0 -1
  102. package/dist/size-group.js +0 -41
  103. package/dist/size-group.js.map +0 -1
  104. package/src/size-group.tsx +0 -77
package/src/types.ts CHANGED
@@ -6,42 +6,42 @@ import type {
6
6
  GtkGridViewProps,
7
7
  GtkListViewProps,
8
8
  } from "@gtkx/jsx/gtk";
9
- import type { ComponentPropsWithRef, ElementType, ReactNode, Ref } from "react";
10
-
11
- /** Props of a container's Child component: the widget to render and its own props. */
12
- type ChildProps<C extends ElementType> = {
13
- component: C;
14
- } & ComponentPropsWithRef<C>;
9
+ import type { ReactNode } from "react";
15
10
 
16
11
  /**
17
12
  * A single item in a collection model, identified by a stable id and holding an
18
13
  * arbitrary value. Nested items form a tree.
19
14
  */
20
- type Item<T = unknown> = {
21
- /** Stable identifier used to track the item across updates and selection. */
15
+ type ListItem<T = unknown> = {
16
+ /** Stable identifier used to track the item across updates and selection, naming every row that carries it. */
22
17
  id: string;
18
+ /** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */
23
19
  value: T;
24
- children?: Item<T>[] | undefined;
25
- /** Hides the tree expander arrow even when the item has children. */
26
- hideExpander?: boolean | undefined;
27
- /** Adds indentation matching the item's depth in the tree. */
28
- indentForDepth?: boolean | undefined;
29
- /** Reserves indentation space for an expander icon. */
30
- indentForIcon?: boolean | undefined;
20
+ /** Child items nested under this one, which turn a plain item list into a tree. */
21
+ children?: ListItem<T>[] | undefined;
22
+ /** Hides the tree expander arrow even when the item has children, through `hide-expander`. */
23
+ shouldHideExpander?: boolean | undefined;
24
+ /** Adds indentation matching the item's depth in the tree, through `indent-for-depth`. */
25
+ shouldIndentForDepth?: boolean | undefined;
26
+ /** Reserves indentation space for an expander icon, through `indent-for-icon`. */
27
+ shouldIndentForIcon?: boolean | undefined;
31
28
  };
32
29
 
33
30
  /** A group of items rendered under a shared section header. */
34
- type Section<S = unknown, T = unknown> = {
31
+ type ListSection<S = unknown, T = unknown> = {
35
32
  /** Stable identifier used to track the section across updates. */
36
33
  id: string;
34
+ /** Payload handed to the section header renderer as `ListSectionRenderArgs.section`. */
37
35
  value: S;
38
36
  /** Items belonging to this section. */
39
- data: Item<T>[];
37
+ data: ListItem<T>[];
40
38
  };
41
39
 
42
- /** Arguments passed to an {@link ItemRenderer} when rendering one cell. */
43
- type RenderItemArgs<T> = {
40
+ /** Arguments passed to a {@link ListItemRenderer} when rendering one cell. */
41
+ type ListItemRenderArgs<T> = {
42
+ /** Value of the `ListItem` being rendered. */
44
43
  item: T;
44
+ /** Position of the item in the flattened item list, which excludes section headers and collapsed tree rows. */
45
45
  index: number;
46
46
  /** Depth of the item within a tree, starting at zero for top-level items. */
47
47
  depth?: number | undefined;
@@ -49,83 +49,162 @@ type RenderItemArgs<T> = {
49
49
  isExpanded?: boolean | undefined;
50
50
  };
51
51
 
52
- /** Arguments passed to a {@link HeaderRenderer} when rendering one section header. */
53
- type RenderHeaderArgs<S> = {
52
+ /**
53
+ * Properties applied to the row that carries one item's cells. A Gtk.ColumnViewRow is not a widget, so
54
+ * these are the only handles it offers; anything omitted falls back to the row's own default, which
55
+ * leaves the accessibility strings unset rather than setting them to an empty string.
56
+ */
57
+ type ListRowProps = {
58
+ /** Name a screen reader announces for the row, through `accessible-label`. */
59
+ accessibleLabel?: string | undefined;
60
+ /** Longer description a screen reader announces for the row, through `accessible-description`. */
61
+ accessibleDescription?: string | undefined;
62
+ /** Whether activating the row emits the view's `activate` signal; rows are activatable by default. */
63
+ isActivatable?: boolean | undefined;
64
+ /** Whether the row takes keyboard focus; rows are focusable by default. */
65
+ isFocusable?: boolean | undefined;
66
+ /** Whether clicking or keying the row tries to select it; rows are selectable by default. */
67
+ isSelectable?: boolean | undefined;
68
+ };
69
+
70
+ /** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */
71
+ type ListSectionRenderArgs<S> = {
72
+ /** Value of the `ListSection` whose header is being rendered. */
54
73
  section: S;
55
74
  };
56
75
 
57
76
  /** Renders the contents of one cell of a collection view. */
58
- type ItemRenderer<T> = (args: RenderItemArgs<T>) => ReactNode;
77
+ type ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;
59
78
  /** Renders the contents of one section header of a collection view. */
60
- type HeaderRenderer<S> = (args: RenderHeaderArgs<S>) => ReactNode;
79
+ type ListSectionRenderer<S> = (args: ListSectionRenderArgs<S>) => ReactNode;
80
+ /** Returns the {@link ListRowProps} to apply to the row displaying one item, re-run whenever the item renders. */
81
+ type ListRowPropsResolver<T> = (args: ListItemRenderArgs<T>) => ListRowProps;
61
82
 
83
+ /** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */
62
84
  type ItemSizeProps = {
85
+ /** Height in pixels every cell asks for until its contents render; unset lets each cell size itself. */
63
86
  estimatedItemHeight?: number | undefined;
87
+ /** Width in pixels every cell asks for until its contents render; unset lets each cell size itself. */
64
88
  estimatedItemWidth?: number | undefined;
65
89
  };
66
90
 
91
+ /** Controlled selection shared by the multi-item collection views. */
67
92
  type SelectionProps = {
93
+ /**
94
+ * Ids of the items to keep selected; omitting it keeps nothing selected, and `onSelectionChanged` is how a
95
+ * user's selection is adopted into it. An id repeated in several branches of a tree names every matching row,
96
+ * and a single-selection view takes the first of them.
97
+ */
68
98
  selectedIds?: string[] | null | undefined;
99
+ /** Called with one id per selected row whenever the selection changes, and once on mount. */
69
100
  onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
101
+ /** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */
70
102
  selectionMode?: Gtk.SelectionMode | null | undefined;
71
103
  };
72
104
 
105
+ /**
106
+ * Wording a screen reader announces for the control that expands and collapses a row. GTK names that control
107
+ * after the row's own content and reports whether it is expanded, but says nothing about what activating it
108
+ * does, so these strings supply that and belong in the application's own language.
109
+ */
110
+ type ExpanderDescriptions = {
111
+ /** Announced while the row is collapsed, such as "Expand". */
112
+ expand: string;
113
+ /** Announced while the row is expanded, such as "Collapse". */
114
+ collapse: string;
115
+ };
116
+
117
+ /** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */
73
118
  type ExpansionProps = {
119
+ /**
120
+ * Ids of the items to keep expanded; omitting it keeps every row collapsed, and `onExpandedChange` is how a
121
+ * user's expansion is adopted into it. An id repeated in several branches names every matching row, so all of
122
+ * them expand together.
123
+ */
74
124
  expandedIds?: string[] | null | undefined;
125
+ /** Called with one id per expanded row, in visible order, whenever expansion changes. */
75
126
  onExpandedChange?: ((ids: string[]) => void) | null | undefined;
127
+ /**
128
+ * Wording announced for the expander of every row that can expand, describing what activating it does.
129
+ * Omitting it leaves those expanders described only by the row they carry, and rows that cannot expand or
130
+ * that hide their expander are never described.
131
+ */
132
+ expanderDescriptions?: ExpanderDescriptions | null | undefined;
133
+ };
134
+
135
+ /** Controlled sorting for the views whose headers can sort the collection. */
136
+ type SortProps = {
137
+ /** Id of the column the view is sorted by, making sorting controlled. */
138
+ sortColumn?: string | null | undefined;
139
+ /** Direction `sortColumn` is sorted in, defaulting to ascending. */
140
+ sortOrder?: Gtk.SortType | null | undefined;
141
+ /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */
142
+ onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
76
143
  };
77
144
 
145
+ /** The data a collection view renders, either as a plain item list or grouped into sections. */
78
146
  type SourceProps<T, S> = {
79
- items?: Item<T>[] | undefined;
80
- sections?: Section<S, T>[] | undefined;
147
+ /** Items to render, nesting through `ListItem.children` for a tree; ignored once `sections` is given. */
148
+ items?: ListItem<T>[] | undefined;
149
+ /** Items grouped under section headers, rendered in place of `items`. */
150
+ sections?: ListSection<S, T>[] | undefined;
81
151
  };
82
152
 
83
153
  /** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */
84
- type Column<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter" | "id" | "title"> & {
154
+ type ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter" | "id" | "title"> & {
85
155
  /** Stable identifier, also used to address the column through sorting props. */
86
156
  id: string;
157
+ /** Text shown in the column header. */
87
158
  title: string;
88
- renderCell: ItemRenderer<T>;
89
- /** Whether clicking the column header sorts by it. */
90
- sortable?: boolean | undefined;
159
+ /** Renders the contents of this column's cell for one item. */
160
+ renderCell: ListItemRenderer<T>;
161
+ /** Makes the column header clickable, reporting the choice through `onSortChanged`. */
162
+ isSortable?: boolean | undefined;
163
+ /** Menu element popped up as the column header's context menu, on a right-click. */
91
164
  headerMenu?: ReactNode;
92
165
  };
93
166
 
167
+ /** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */
94
168
  type ColumnViewOwnProps<T, S> = SelectionProps &
95
169
  ExpansionProps &
170
+ SortProps &
96
171
  SourceProps<T, S> &
97
172
  Omit<ItemSizeProps, "estimatedItemWidth"> & {
98
- columns: Column<T>[];
99
- renderHeader?: HeaderRenderer<S> | null | undefined;
100
- /** Id of the column the view is sorted by, making sorting controlled. */
101
- sortColumn?: string | null | undefined;
102
- sortOrder?: Gtk.SortType | null | undefined;
103
- onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
173
+ /** Columns to render, in order; each carries its own cell renderer. */
174
+ columns: ColumnViewColumn<T>[];
175
+ /** Renders the header shown above each section. */
176
+ renderHeader?: ListSectionRenderer<S> | null | undefined;
177
+ /** Resolves the props of the row carrying one item's cells, such as its screen-reader label. */
178
+ rowProps?: ListRowPropsResolver<T> | null | undefined;
104
179
  };
105
180
 
106
181
  /**
107
182
  * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with
108
183
  * declarative collection props: flat items or grouped sections, controlled selection
109
184
  * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section
110
- * header renderer, and the columns to render.
185
+ * header renderer, per-row props, and the columns to render.
111
186
  */
112
187
  type ColumnViewProps<T = unknown, S = unknown> = Omit<
113
188
  GtkColumnViewProps,
114
- "columns" | "model" | "headerFactory" | keyof ColumnViewOwnProps<T, S>
189
+ "columns" | "model" | "headerFactory" | "rowFactory" | keyof ColumnViewOwnProps<T, S>
115
190
  > &
116
191
  ColumnViewOwnProps<T, S>;
117
192
 
193
+ /** The declarative collection props {@link DropDown} and `ComboRow` add on top of their widget's own. */
118
194
  type DropDownOwnProps<T, S> = SourceProps<T, S> & {
119
195
  /** Id of the currently selected item, making the selection controlled. */
120
196
  selectedId?: string | null | undefined;
197
+ /** Called with the id of the item that became selected. */
121
198
  onSelectionChanged?: ((id: string) => void) | null | undefined;
122
- renderItem?: ItemRenderer<T> | null | undefined;
199
+ /** Renders the collapsed display, and the popup rows too unless `renderListItem` is given. */
200
+ renderItem?: ListItemRenderer<T> | null | undefined;
123
201
  /** Renderer for items in the open popup list, falling back to renderItem when omitted. */
124
- renderListItem?: ItemRenderer<T> | null | undefined;
202
+ renderListItem?: ListItemRenderer<T> | null | undefined;
125
203
  /** Renderer for section headers in the popup list. */
126
- renderHeader?: HeaderRenderer<S> | null | undefined;
204
+ renderHeader?: ListSectionRenderer<S> | null | undefined;
127
205
  };
128
206
 
207
+ /** A drop-down-shaped widget's props with its model and factories swapped for the declarative collection props. */
129
208
  type DropDownWidgetProps<Widget, T, S> = Omit<
130
209
  Widget,
131
210
  "model" | "factory" | "listFactory" | "headerFactory" | keyof DropDownOwnProps<T, S>
@@ -139,10 +218,13 @@ DropDownOwnProps<T, S>;
139
218
  */
140
219
  type DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;
141
220
 
221
+ /** The declarative collection props {@link GridView} adds on top of Gtk.GridView's own. */
142
222
  type GridViewOwnProps<T> = ItemSizeProps &
143
223
  SelectionProps & {
144
- items?: Item<T>[] | undefined;
145
- renderItem: ItemRenderer<T>;
224
+ /** Items to render as cells; a grid is always flat, so `ListItem.children` is ignored. */
225
+ items?: ListItem<T>[] | undefined;
226
+ /** Renders the contents of one cell. */
227
+ renderItem: ListItemRenderer<T>;
146
228
  };
147
229
 
148
230
  /**
@@ -153,12 +235,15 @@ type GridViewOwnProps<T> = ItemSizeProps &
153
235
  type GridViewProps<T = unknown> = Omit<GtkGridViewProps, "model" | "factory" | keyof GridViewOwnProps<T>> &
154
236
  GridViewOwnProps<T>;
155
237
 
238
+ /** The declarative collection props {@link ListView} adds on top of Gtk.ListView's own. */
156
239
  type ListViewOwnProps<T, S> = ItemSizeProps &
157
240
  SelectionProps &
158
241
  ExpansionProps &
159
242
  SourceProps<T, S> & {
160
- renderItem: ItemRenderer<T>;
161
- renderHeader?: HeaderRenderer<S> | null | undefined;
243
+ /** Renders the contents of one row. */
244
+ renderItem: ListItemRenderer<T>;
245
+ /** Renders the header shown above each section. */
246
+ renderHeader?: ListSectionRenderer<S> | null | undefined;
162
247
  };
163
248
 
164
249
  /**
@@ -173,34 +258,24 @@ type ListViewProps<T = unknown, S = unknown> = Omit<
173
258
  > &
174
259
  ListViewOwnProps<T, S>;
175
260
 
176
- /** Props for {@link SizeGroup}. */
177
- type SizeGroupProps = {
178
- /** How the group equalizes sizes: horizontal, vertical, or both. */
179
- mode?: Gtk.SizeGroupMode | null | undefined;
180
- ref?: Ref<Gtk.SizeGroup | null>;
181
- children?: ReactNode;
182
- };
183
-
184
- /** Adds a single widget, rendered by the given component, to the enclosing {@link SizeGroup}. */
185
- type SizeGroupChildProps<C extends ElementType> = ChildProps<C>;
186
-
187
261
  export {
188
262
  type SelectionProps,
263
+ type ExpanderDescriptions,
189
264
  type ExpansionProps,
190
- type ChildProps,
265
+ type SortProps,
191
266
  type DropDownOwnProps,
192
267
  type DropDownWidgetProps,
193
- type Item,
194
- type Section,
195
- type RenderItemArgs,
196
- type RenderHeaderArgs,
197
- type ItemRenderer,
198
- type HeaderRenderer,
199
- type Column,
268
+ type ListItem,
269
+ type ListSection,
270
+ type ListItemRenderArgs,
271
+ type ListRowProps,
272
+ type ListSectionRenderArgs,
273
+ type ListItemRenderer,
274
+ type ListRowPropsResolver,
275
+ type ListSectionRenderer,
276
+ type ColumnViewColumn,
200
277
  type ColumnViewProps,
201
278
  type DropDownProps,
202
279
  type GridViewProps,
203
280
  type ListViewProps,
204
- type SizeGroupProps,
205
- type SizeGroupChildProps,
206
281
  };
@@ -1,12 +0,0 @@
1
- import type { ElementType, ReactNode } from "react";
2
- import type { SizeGroupChildProps, SizeGroupProps } from "./types.js";
3
- type SizeGroupComponent = ((props: SizeGroupProps) => ReactNode) & {
4
- Child: <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;
5
- };
6
- /**
7
- * Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`
8
- * at a common size in the given mode, without contributing a widget of its own.
9
- */
10
- declare const SizeGroup: SizeGroupComponent;
11
- export { SizeGroup };
12
- //# sourceMappingURL=size-group.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"size-group.d.ts","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAoB,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAStE,KAAK,kBAAkB,GAAG,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,SAAS,CAAC,GAAG;IAC/D,KAAK,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CAC9E,CAAC;AAIF;;;GAGG;AACH,QAAA,MAAM,SAAS,EAAE,kBAA4E,CAAC;AAoD9F,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,41 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { GtkSizeGroup } from "@gtkx/jsx/gtk";
3
- import { useMergedRef } from "@gtkx/react/internal";
4
- import { createContext, useCallback, useContext, useState } from "react";
5
- const SizeGroupContext = createContext(null);
6
- const SizeGroupChild = SizeGroupChildImpl;
7
- /**
8
- * Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`
9
- * at a common size in the given mode, without contributing a widget of its own.
10
- */
11
- const SizeGroup = Object.assign(SizeGroupRoot, { Child: SizeGroupChild });
12
- const useRegister = () => {
13
- const register = useContext(SizeGroupContext);
14
- if (register === null) {
15
- throw new Error("<SizeGroup.Child> must be a child of <SizeGroup>");
16
- }
17
- return register;
18
- };
19
- function SizeGroupChildImpl(props) {
20
- const { component: Component, ref, ...rest } = props;
21
- const refCallback = useMergedRef(ref, useRegister());
22
- return _jsx(Component, { ...rest, ref: refCallback });
23
- }
24
- const addWidget = (widgets, widget) => widgets.includes(widget) ? widgets : [...widgets, widget];
25
- const removeWidget = (widgets, widget) => widgets.filter((entry) => entry !== widget);
26
- function SizeGroupRoot(props) {
27
- const { mode, ref, children } = props;
28
- const [widgets, setWidgets] = useState([]);
29
- const register = useCallback((widget) => {
30
- if (widget === null) {
31
- return;
32
- }
33
- setWidgets((previous) => addWidget(previous, widget));
34
- return () => {
35
- setWidgets((previous) => removeWidget(previous, widget));
36
- };
37
- }, [setWidgets]);
38
- return (_jsxs(_Fragment, { children: [_jsx(GtkSizeGroup, { ref: ref, mode: mode, widgets: widgets }), _jsx(SizeGroupContext.Provider, { value: register, children: children })] }));
39
- }
40
- export { SizeGroup };
41
- //# sourceMappingURL=size-group.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"size-group.js","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAczE,MAAM,gBAAgB,GAAG,aAAa,CAAkB,IAAI,CAAC,CAAC;AAC9D,MAAM,cAAc,GAAG,kBAAyF,CAAC;AACjH;;;GAGG;AACH,MAAM,SAAS,GAAuB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;AAE9F,MAAM,WAAW,GAAG,GAAa,EAAE;IAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE9C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEF,SAAS,kBAAkB,CAAC,KAAiC;IACzD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACrD,MAAM,WAAW,GAAG,YAAY,CAAoB,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAExE,OAAO,KAAC,SAAS,OAAK,IAAI,EAAE,GAAG,EAAE,WAAW,GAAI,CAAC;AACrD,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,OAAqB,EAAE,MAAkB,EAAgB,EAAE,CAC1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC;AAE9D,MAAM,YAAY,GAAG,CAAC,OAAqB,EAAE,MAAkB,EAAgB,EAAE,CAC7E,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;AAEhD,SAAS,aAAa,CAAC,KAAqB;IACxC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACtC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAe,EAAE,CAAC,CAAC;IAEzD,MAAM,QAAQ,GAAG,WAAW,CACxB,CAAC,MAAM,EAAE,EAAE;QACP,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO;QACX,CAAC;QAED,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAEtD,OAAO,GAAG,EAAE;YACR,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC;IACN,CAAC,EACD,CAAC,UAAU,CAAC,CACf,CAAC;IAEF,OAAO,CACH,8BACI,KAAC,YAAY,IAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAI,EACxD,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAA6B,IACnF,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { ElementType, ReactNode, Ref, RefCallback } from \"react\";\nimport { GtkSizeGroup } from \"@gtkx/jsx/gtk\";\nimport { useMergedRef } from \"@gtkx/react/internal\";\nimport { createContext, useCallback, useContext, useState } from \"react\";\nimport type { SizeGroupChildProps, SizeGroupProps } from \"./types.js\";\n\ntype Register = RefCallback<Gtk.Widget | null>;\n\ntype SizeGroupChildRuntimeProps = {\n component: ElementType;\n ref?: Ref<Gtk.Widget | null> | undefined;\n} & Record<string, unknown>;\n\ntype SizeGroupComponent = ((props: SizeGroupProps) => ReactNode) & {\n Child: <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;\n};\n\nconst SizeGroupContext = createContext<Register | null>(null);\nconst SizeGroupChild = SizeGroupChildImpl as <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;\n/**\n * Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`\n * at a common size in the given mode, without contributing a widget of its own.\n */\nconst SizeGroup: SizeGroupComponent = Object.assign(SizeGroupRoot, { Child: SizeGroupChild });\n\nconst useRegister = (): Register => {\n const register = useContext(SizeGroupContext);\n\n if (register === null) {\n throw new Error(\"<SizeGroup.Child> must be a child of <SizeGroup>\");\n }\n\n return register;\n};\n\nfunction SizeGroupChildImpl(props: SizeGroupChildRuntimeProps): ReactNode {\n const { component: Component, ref, ...rest } = props;\n const refCallback = useMergedRef<Gtk.Widget | null>(ref, useRegister());\n\n return <Component {...rest} ref={refCallback} />;\n}\n\nconst addWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>\n widgets.includes(widget) ? widgets : [...widgets, widget];\n\nconst removeWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>\n widgets.filter((entry) => entry !== widget);\n\nfunction SizeGroupRoot(props: SizeGroupProps): ReactNode {\n const { mode, ref, children } = props;\n const [widgets, setWidgets] = useState<Gtk.Widget[]>([]);\n\n const register = useCallback<Register>(\n (widget) => {\n if (widget === null) {\n return;\n }\n\n setWidgets((previous) => addWidget(previous, widget));\n\n return () => {\n setWidgets((previous) => removeWidget(previous, widget));\n };\n },\n [setWidgets],\n );\n\n return (\n <>\n <GtkSizeGroup ref={ref} mode={mode} widgets={widgets} />\n <SizeGroupContext.Provider value={register}>{children}</SizeGroupContext.Provider>\n </>\n );\n}\n\nexport { SizeGroup };\n"]}
@@ -1,77 +0,0 @@
1
- import type * as Gtk from "@gtkx/gi/gtk";
2
- import type { ElementType, ReactNode, Ref, RefCallback } from "react";
3
- import { GtkSizeGroup } from "@gtkx/jsx/gtk";
4
- import { useMergedRef } from "@gtkx/react/internal";
5
- import { createContext, useCallback, useContext, useState } from "react";
6
- import type { SizeGroupChildProps, SizeGroupProps } from "./types.js";
7
-
8
- type Register = RefCallback<Gtk.Widget | null>;
9
-
10
- type SizeGroupChildRuntimeProps = {
11
- component: ElementType;
12
- ref?: Ref<Gtk.Widget | null> | undefined;
13
- } & Record<string, unknown>;
14
-
15
- type SizeGroupComponent = ((props: SizeGroupProps) => ReactNode) & {
16
- Child: <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;
17
- };
18
-
19
- const SizeGroupContext = createContext<Register | null>(null);
20
- const SizeGroupChild = SizeGroupChildImpl as <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;
21
- /**
22
- * Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`
23
- * at a common size in the given mode, without contributing a widget of its own.
24
- */
25
- const SizeGroup: SizeGroupComponent = Object.assign(SizeGroupRoot, { Child: SizeGroupChild });
26
-
27
- const useRegister = (): Register => {
28
- const register = useContext(SizeGroupContext);
29
-
30
- if (register === null) {
31
- throw new Error("<SizeGroup.Child> must be a child of <SizeGroup>");
32
- }
33
-
34
- return register;
35
- };
36
-
37
- function SizeGroupChildImpl(props: SizeGroupChildRuntimeProps): ReactNode {
38
- const { component: Component, ref, ...rest } = props;
39
- const refCallback = useMergedRef<Gtk.Widget | null>(ref, useRegister());
40
-
41
- return <Component {...rest} ref={refCallback} />;
42
- }
43
-
44
- const addWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>
45
- widgets.includes(widget) ? widgets : [...widgets, widget];
46
-
47
- const removeWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>
48
- widgets.filter((entry) => entry !== widget);
49
-
50
- function SizeGroupRoot(props: SizeGroupProps): ReactNode {
51
- const { mode, ref, children } = props;
52
- const [widgets, setWidgets] = useState<Gtk.Widget[]>([]);
53
-
54
- const register = useCallback<Register>(
55
- (widget) => {
56
- if (widget === null) {
57
- return;
58
- }
59
-
60
- setWidgets((previous) => addWidget(previous, widget));
61
-
62
- return () => {
63
- setWidgets((previous) => removeWidget(previous, widget));
64
- };
65
- },
66
- [setWidgets],
67
- );
68
-
69
- return (
70
- <>
71
- <GtkSizeGroup ref={ref} mode={mode} widgets={widgets} />
72
- <SizeGroupContext.Provider value={register}>{children}</SizeGroupContext.Provider>
73
- </>
74
- );
75
- }
76
-
77
- export { SizeGroup };