@gtkx/components 1.0.0-rc.4 → 1.1.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 (86) hide show
  1. package/README.md +5 -5
  2. package/dist/column-view.d.ts +2 -2
  3. package/dist/column-view.d.ts.map +1 -1
  4. package/dist/column-view.js +14 -12
  5. package/dist/column-view.js.map +1 -1
  6. package/dist/grid-view.js +1 -1
  7. package/dist/grid-view.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/cells.d.ts +31 -23
  12. package/dist/internal/cells.d.ts.map +1 -1
  13. package/dist/internal/cells.js +168 -77
  14. package/dist/internal/cells.js.map +1 -1
  15. package/dist/internal/collection-index.d.ts +8 -11
  16. package/dist/internal/collection-index.d.ts.map +1 -1
  17. package/dist/internal/collection-index.js +53 -73
  18. package/dist/internal/collection-index.js.map +1 -1
  19. package/dist/internal/collection-model.d.ts +24 -4
  20. package/dist/internal/collection-model.d.ts.map +1 -1
  21. package/dist/internal/collection-model.js +247 -96
  22. package/dist/internal/collection-model.js.map +1 -1
  23. package/dist/internal/collection.d.ts +8 -10
  24. package/dist/internal/collection.d.ts.map +1 -1
  25. package/dist/internal/collection.js +38 -48
  26. package/dist/internal/collection.js.map +1 -1
  27. package/dist/internal/controlled-sync.d.ts +11 -0
  28. package/dist/internal/controlled-sync.d.ts.map +1 -0
  29. package/dist/internal/controlled-sync.js +19 -0
  30. package/dist/internal/controlled-sync.js.map +1 -0
  31. package/dist/internal/drop-down.d.ts.map +1 -1
  32. package/dist/internal/drop-down.js +27 -15
  33. package/dist/internal/drop-down.js.map +1 -1
  34. package/dist/internal/expansion.d.ts +3 -2
  35. package/dist/internal/expansion.d.ts.map +1 -1
  36. package/dist/internal/expansion.js +73 -48
  37. package/dist/internal/expansion.js.map +1 -1
  38. package/dist/internal/keys.d.ts +5 -0
  39. package/dist/internal/keys.d.ts.map +1 -0
  40. package/dist/internal/keys.js +13 -0
  41. package/dist/internal/keys.js.map +1 -0
  42. package/dist/internal/selection.d.ts +3 -2
  43. package/dist/internal/selection.d.ts.map +1 -1
  44. package/dist/internal/selection.js +68 -35
  45. package/dist/internal/selection.js.map +1 -1
  46. package/dist/internal/slots.d.ts +10 -0
  47. package/dist/internal/slots.d.ts.map +1 -0
  48. package/dist/internal/slots.js +43 -0
  49. package/dist/internal/slots.js.map +1 -0
  50. package/dist/internal/tree-expansion.d.ts +19 -0
  51. package/dist/internal/tree-expansion.d.ts.map +1 -0
  52. package/dist/internal/tree-expansion.js +72 -0
  53. package/dist/internal/tree-expansion.js.map +1 -0
  54. package/dist/internal/tree-order.d.ts +26 -0
  55. package/dist/internal/tree-order.d.ts.map +1 -0
  56. package/dist/internal/tree-order.js +109 -0
  57. package/dist/internal/tree-order.js.map +1 -0
  58. package/dist/internal/use-collection.d.ts +1 -1
  59. package/dist/internal/use-collection.d.ts.map +1 -1
  60. package/dist/internal/use-collection.js +4 -4
  61. package/dist/internal/use-collection.js.map +1 -1
  62. package/dist/list-view.d.ts.map +1 -1
  63. package/dist/list-view.js +6 -6
  64. package/dist/list-view.js.map +1 -1
  65. package/dist/types.d.ts +72 -22
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js.map +1 -1
  68. package/package.json +17 -9
  69. package/src/column-view.tsx +28 -25
  70. package/src/grid-view.tsx +1 -1
  71. package/src/index.ts +3 -0
  72. package/src/internal/cells.tsx +339 -117
  73. package/src/internal/collection-index.ts +68 -92
  74. package/src/internal/collection-model.ts +327 -112
  75. package/src/internal/collection.ts +45 -65
  76. package/src/internal/controlled-sync.ts +34 -0
  77. package/src/internal/drop-down.tsx +41 -20
  78. package/src/internal/expansion.ts +95 -70
  79. package/src/internal/keys.ts +18 -0
  80. package/src/internal/selection.tsx +100 -51
  81. package/src/internal/slots.ts +67 -0
  82. package/src/internal/tree-expansion.ts +115 -0
  83. package/src/internal/tree-order.ts +208 -0
  84. package/src/internal/use-collection.tsx +5 -5
  85. package/src/list-view.tsx +14 -10
  86. package/src/types.ts +78 -20
package/src/types.ts CHANGED
@@ -13,18 +13,18 @@ import type { ReactNode } from "react";
13
13
  * arbitrary value. Nested items form a tree.
14
14
  */
15
15
  type ListItem<T = unknown> = {
16
- /** Stable identifier used to track the item across updates and selection. */
16
+ /** Stable identifier used to track the item across updates and selection, naming every row that carries it. */
17
17
  id: string;
18
18
  /** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */
19
19
  value: T;
20
- /** Child items nested under this one, which turn a plain item list into a tree. */
20
+ /** Child items nested under this one, which turn a plain item list into a tree, read only as rows are drawn. */
21
21
  children?: ListItem<T>[] | undefined;
22
- /** Hides the tree expander arrow even when the item has children. */
23
- hideExpander?: boolean | undefined;
24
- /** Adds indentation matching the item's depth in the tree. */
25
- indentForDepth?: boolean | undefined;
26
- /** Reserves indentation space for an expander icon. */
27
- indentForIcon?: boolean | 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;
28
28
  };
29
29
 
30
30
  /** A group of items rendered under a shared section header. */
@@ -49,6 +49,24 @@ type ListItemRenderArgs<T> = {
49
49
  isExpanded?: boolean | undefined;
50
50
  };
51
51
 
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
+
52
70
  /** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */
53
71
  type ListSectionRenderArgs<S> = {
54
72
  /** Value of the `ListSection` whose header is being rendered. */
@@ -59,6 +77,8 @@ type ListSectionRenderArgs<S> = {
59
77
  type ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;
60
78
  /** Renders the contents of one section header of a collection view. */
61
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;
62
82
 
63
83
  /** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */
64
84
  type ItemSizeProps = {
@@ -70,20 +90,57 @@ type ItemSizeProps = {
70
90
 
71
91
  /** Controlled selection shared by the multi-item collection views. */
72
92
  type SelectionProps = {
73
- /** Ids of the items to keep selected; omitting it leaves the view's own selection alone. */
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
+ */
74
98
  selectedIds?: string[] | null | undefined;
75
- /** Called with the ids of every selected item whenever the selection changes, and once on mount. */
99
+ /** Called with one id per selected row whenever the selection changes, and once on mount. */
76
100
  onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
77
101
  /** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */
78
102
  selectionMode?: Gtk.SelectionMode | null | undefined;
79
103
  };
80
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
+
81
117
  /** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */
82
118
  type ExpansionProps = {
83
- /** Ids of the items to keep expanded; omitting it leaves the rows' own expanded state alone. */
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. An item whose children lead back to itself expands one level at a time, since a row
123
+ * repeating an item already expanded above it stays collapsed.
124
+ */
84
125
  expandedIds?: string[] | null | undefined;
85
- /** Called with the ids of every expanded row whenever expansion changes. */
126
+ /** Called with one id per expanded row, in visible order, whenever expansion changes. */
86
127
  onExpandedChange?: ((ids: string[]) => void) | null | undefined;
128
+ /**
129
+ * Wording announced for the expander of every row that can expand, describing what activating it does.
130
+ * Omitting it leaves those expanders described only by the row they carry, and rows that cannot expand or
131
+ * that hide their expander are never described.
132
+ */
133
+ expanderDescriptions?: ExpanderDescriptions | null | undefined;
134
+ };
135
+
136
+ /** Controlled sorting for the views whose headers can sort the collection. */
137
+ type SortProps = {
138
+ /** Id of the column the view is sorted by, making sorting controlled. */
139
+ sortColumn?: string | null | undefined;
140
+ /** Direction `sortColumn` is sorted in, defaulting to ascending. */
141
+ sortOrder?: Gtk.SortType | null | undefined;
142
+ /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */
143
+ onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
87
144
  };
88
145
 
89
146
  /** The data a collection view renders, either as a plain item list or grouped into sections. */
@@ -111,29 +168,26 @@ type ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" |
111
168
  /** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */
112
169
  type ColumnViewOwnProps<T, S> = SelectionProps &
113
170
  ExpansionProps &
171
+ SortProps &
114
172
  SourceProps<T, S> &
115
173
  Omit<ItemSizeProps, "estimatedItemWidth"> & {
116
174
  /** Columns to render, in order; each carries its own cell renderer. */
117
175
  columns: ColumnViewColumn<T>[];
118
176
  /** Renders the header shown above each section. */
119
177
  renderHeader?: ListSectionRenderer<S> | null | undefined;
120
- /** Id of the column the view is sorted by, making sorting controlled. */
121
- sortColumn?: string | null | undefined;
122
- /** Direction `sortColumn` is sorted in, defaulting to ascending. */
123
- sortOrder?: Gtk.SortType | null | undefined;
124
- /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */
125
- onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
178
+ /** Resolves the props of the row carrying one item's cells, such as its screen-reader label. */
179
+ rowProps?: ListRowPropsResolver<T> | null | undefined;
126
180
  };
127
181
 
128
182
  /**
129
183
  * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with
130
184
  * declarative collection props: flat items or grouped sections, controlled selection
131
185
  * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section
132
- * header renderer, and the columns to render.
186
+ * header renderer, per-row props, and the columns to render.
133
187
  */
134
188
  type ColumnViewProps<T = unknown, S = unknown> = Omit<
135
189
  GtkColumnViewProps,
136
- "columns" | "model" | "headerFactory" | keyof ColumnViewOwnProps<T, S>
190
+ "columns" | "model" | "headerFactory" | "rowFactory" | keyof ColumnViewOwnProps<T, S>
137
191
  > &
138
192
  ColumnViewOwnProps<T, S>;
139
193
 
@@ -207,14 +261,18 @@ ListViewOwnProps<T, S>;
207
261
 
208
262
  export {
209
263
  type SelectionProps,
264
+ type ExpanderDescriptions,
210
265
  type ExpansionProps,
266
+ type SortProps,
211
267
  type DropDownOwnProps,
212
268
  type DropDownWidgetProps,
213
269
  type ListItem,
214
270
  type ListSection,
215
271
  type ListItemRenderArgs,
272
+ type ListRowProps,
216
273
  type ListSectionRenderArgs,
217
274
  type ListItemRenderer,
275
+ type ListRowPropsResolver,
218
276
  type ListSectionRenderer,
219
277
  type ColumnViewColumn,
220
278
  type ColumnViewProps,