@gtkx/components 2.0.0-beta.1 → 2.0.0-beta.10

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.
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAySA,OAAO,EAwBN,CAAC","sourcesContent":["import type * as Adw from \"@gtkx/gi/adw\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { AdwComboRowProps, AdwToastProps } from \"@gtkx/jsx/adw\";\nimport type {\n GtkColumnViewColumnProps,\n GtkColumnViewProps,\n GtkDropDownProps,\n GtkGridViewProps,\n GtkListViewProps,\n} from \"@gtkx/jsx/gtk\";\nimport type { ReactNode, RefObject } from \"react\";\n\n/**\n * A single item in a collection model, identified by a stable id and holding an\n * arbitrary value. Nested items form a tree.\n */\ntype ListItem<T = unknown> = {\n /** Stable identifier used to track the item across updates and selection, naming every row that carries it. */\n id: string;\n /** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */\n value: T;\n /** Child items nested under this one, which turn a plain item list into a tree, read only as rows are drawn. */\n children?: ListItem<T>[] | undefined;\n /** Hides the tree expander arrow even when the item has children, through `hide-expander`. */\n shouldHideExpander?: boolean | undefined;\n /** Adds indentation matching the item's depth in the tree, through `indent-for-depth`. */\n shouldIndentForDepth?: boolean | undefined;\n /** Reserves indentation space for an expander icon, through `indent-for-icon`. */\n shouldIndentForIcon?: boolean | undefined;\n};\n\n/** A group of items rendered under a shared section header. */\ntype ListSection<S = unknown, T = unknown> = {\n /** Stable identifier used to track the section across updates. */\n id: string;\n /** Payload handed to the section header renderer as `ListSectionRenderArgs.section`. */\n value: S;\n /** Items belonging to this section. */\n data: ListItem<T>[];\n};\n\n/** Arguments passed to a {@link ListItemRenderer} when rendering one cell. */\ntype ListItemRenderArgs<T> = {\n /** Value of the `ListItem` being rendered. */\n item: T;\n /** Position of the item in the flattened item list, which excludes section headers and collapsed tree rows. */\n index: number;\n /** Depth of the item within a tree, starting at zero for top-level items. */\n depth?: number | undefined;\n /** Whether the item is currently expanded in a tree view. */\n isExpanded?: boolean | undefined;\n};\n\n/**\n * Properties applied to the row that carries one item's cells. A Gtk.ColumnViewRow is not a widget, so\n * these are the only handles it offers; anything omitted falls back to the row's own default, which\n * leaves the accessibility strings unset rather than setting them to an empty string.\n */\ntype ListRowProps = {\n /** Name a screen reader announces for the row, through `accessible-label`. */\n accessibleLabel?: string | undefined;\n /** Longer description a screen reader announces for the row, through `accessible-description`. */\n accessibleDescription?: string | undefined;\n /** Whether activating the row emits the view's `activate` signal; rows are activatable by default. */\n isActivatable?: boolean | undefined;\n /** Whether the row takes keyboard focus; rows are focusable by default. */\n isFocusable?: boolean | undefined;\n /** Whether clicking or keying the row tries to select it; rows are selectable by default. */\n isSelectable?: boolean | undefined;\n};\n\n/** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */\ntype ListSectionRenderArgs<S> = {\n /** Value of the `ListSection` whose header is being rendered. */\n section: S;\n};\n\n/** Renders the contents of one cell of a collection view. */\ntype ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;\n/** Renders the contents of one section header of a collection view. */\ntype ListSectionRenderer<S> = (args: ListSectionRenderArgs<S>) => ReactNode;\n/** Returns the {@link ListRowProps} to apply to the row displaying one item, re-run whenever the item renders. */\ntype ListRowPropsResolver<T> = (args: ListItemRenderArgs<T>) => ListRowProps;\n\n/** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */\ntype ItemSizeProps = {\n /** Height in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemHeight?: number | undefined;\n /** Width in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemWidth?: number | undefined;\n};\n\n/** Controlled selection shared by the multi-item collection views. */\ntype SelectionProps = {\n /**\n * Ids of the items to keep selected; omitting it keeps nothing selected, and `onSelectionChanged` is how a\n * user's selection is adopted into it. An id repeated in several branches of a tree names every matching row,\n * and a single-selection view takes the first of them.\n */\n selectedIds?: string[] | null | undefined;\n /** Called with one id per selected row whenever the selection changes, and once on mount. */\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n /** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */\n selectionMode?: Gtk.SelectionMode | null | undefined;\n};\n\n/**\n * Wording a screen reader announces for the control that expands and collapses a row. GTK names that control\n * after the row's own content and reports whether it is expanded, but says nothing about what activating it\n * does, so these strings supply that and belong in the application's own language.\n */\ntype ExpanderDescriptions = {\n /** Announced while the row is collapsed, such as \"Expand\". */\n expand: string;\n /** Announced while the row is expanded, such as \"Collapse\". */\n collapse: string;\n};\n\n/** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */\ntype ExpansionProps = {\n /**\n * Ids of the items to keep expanded; omitting it keeps every row collapsed, and `onExpandedChange` is how a\n * user's expansion is adopted into it. An id repeated in several branches names every matching row, so all of\n * them expand together. An item whose children lead back to itself expands one level at a time, since a row\n * repeating an item already expanded above it stays collapsed.\n */\n expandedIds?: string[] | null | undefined;\n /** Called with one id per expanded row, in visible order, whenever expansion changes. */\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n /**\n * Wording announced for the expander of every row that can expand, describing what activating it does.\n * Omitting it leaves those expanders described only by the row they carry, and rows that cannot expand or\n * that hide their expander are never described.\n */\n expanderDescriptions?: ExpanderDescriptions | null | undefined;\n};\n\n/** Controlled sorting for the views whose headers can sort the collection. */\ntype SortProps = {\n /** Id of the column the view is sorted by, making sorting controlled. */\n sortColumn?: string | null | undefined;\n /** Direction `sortColumn` is sorted in, defaulting to ascending. */\n sortOrder?: Gtk.SortType | null | undefined;\n /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\n/** The data a collection view renders, either as a plain item list or grouped into sections. */\ntype SourceProps<T, S> = {\n /** Items to render, nesting through `ListItem.children` for a tree; ignored once `sections` is given. */\n items?: ListItem<T>[] | undefined;\n /** Items grouped under section headers, rendered in place of `items`. */\n sections?: ListSection<S, T>[] | undefined;\n};\n\n/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */\ntype ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, \"factory\" | \"sorter\" | \"id\" | \"title\"> & {\n /** Stable identifier, also used to address the column through sorting props. */\n id: string;\n /** Text shown in the column header. */\n title: string;\n /** Renders the contents of this column's cell for one item. */\n renderCell: ListItemRenderer<T>;\n /** Makes the column header clickable, reporting the choice through `onSortChanged`. */\n isSortable?: boolean | undefined;\n /** Menu element popped up as the column header's context menu, on a right-click. */\n headerMenu?: ReactNode;\n};\n\n/** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */\ntype ColumnViewOwnProps<T, S> = SelectionProps &\n ExpansionProps &\n SortProps &\n SourceProps<T, S> &\n Omit<ItemSizeProps, \"estimatedItemWidth\"> & {\n /** Columns to render, in order; each carries its own cell renderer. */\n columns: ColumnViewColumn<T>[];\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n /** Resolves the props of the row carrying one item's cells, such as its screen-reader label. */\n rowProps?: ListRowPropsResolver<T> | null | undefined;\n };\n\n/**\n * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with\n * declarative collection props: flat items or grouped sections, controlled selection\n * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section\n * header renderer, per-row props, and the columns to render.\n */\ntype ColumnViewProps<T = unknown, S = unknown> = Omit<\n GtkColumnViewProps,\n \"columns\" | \"model\" | \"headerFactory\" | \"rowFactory\" | keyof ColumnViewOwnProps<T, S>\n> &\nColumnViewOwnProps<T, S>;\n\n/** The declarative collection props {@link DropDown} and `ComboRow` add on top of their widget's own. */\ntype DropDownOwnProps<T, S> = SourceProps<T, S> & {\n /** Id of the currently selected item, making the selection controlled. */\n selectedId?: string | null | undefined;\n /** Called with the id of the item that became selected. */\n onSelectionChanged?: ((id: string) => void) | null | undefined;\n /** Renders the collapsed display, and the popup rows too unless `renderListItem` is given. */\n renderItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n};\n\n/** A drop-down-shaped widget's props with its model and factories swapped for the declarative collection props. */\ntype DropDownWidgetProps<Widget, T, S> = Omit<\n Widget,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\" | keyof DropDownOwnProps<T, S>\n> &\nDropDownOwnProps<T, S>;\n\n/**\n * Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the collapsed display, popup rows, and popup section headers.\n */\ntype DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;\n\n/** The declarative collection props {@link GridView} adds on top of Gtk.GridView's own. */\ntype GridViewOwnProps<T> = ItemSizeProps &\n SelectionProps & {\n /** Items to render as cells; a grid is always flat, so `ListItem.children` is ignored. */\n items?: ListItem<T>[] | undefined;\n /** Renders the contents of one cell. */\n renderItem: ListItemRenderer<T>;\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 */\ntype GridViewProps<T = unknown> = Omit<GtkGridViewProps, \"model\" | \"factory\" | keyof GridViewOwnProps<T>> &\n GridViewOwnProps<T>;\n\n/** The declarative collection props {@link ListView} adds on top of Gtk.ListView's own. */\ntype ListViewOwnProps<T, S> = ItemSizeProps &\n SelectionProps &\n ExpansionProps &\n SourceProps<T, S> & {\n /** Renders the contents of one row. */\n renderItem: ListItemRenderer<T>;\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n };\n\n/**\n * Props for {@link ListView}. Combines the underlying Gtk.ListView props with\n * declarative collection props: flat items or grouped sections, a per-row renderItem,\n * an optional section header renderer, controlled selection and expansion, and\n * estimated item sizing.\n */\ntype ListViewProps<T = unknown, S = unknown> = Omit<\n GtkListViewProps,\n \"model\" | \"factory\" | \"headerFactory\" | keyof ListViewOwnProps<T, S>\n> &\nListViewOwnProps<T, S>;\n\n/**\n * Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the row display, popup rows, and popup section headers.\n */\ntype ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;\n/**\n * Describes a toast raised through {@link useToast}: the construct-time properties of an\n * `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.\n */\ntype ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, \"onButtonClicked\" | \"onDismissed\">;\n\n/** Imperative controls for individual toasts, returned by {@link useToast}. */\ntype ToastController = {\n /** Builds a toast, shows it through the overlay, and returns it. */\n show: (options?: ToastOptions) => Adw.Toast;\n /** Dismisses a single toast, typically one returned by `ToastController.show`. */\n dismiss: (toast: Adw.Toast) => void;\n};\n\n/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */\ntype ToastOverlayController = {\n /** Dismisses the shown toast and every queued one. */\n dismissAll: () => void;\n};\n\n/** Props for {@link ToastProvider}. */\ntype ToastProviderProps = {\n /** Ref also given to the `AdwToastOverlay` the toasts appear over. */\n overlayRef: RefObject<Adw.ToastOverlay | null>;\n /** Subtree whose `useToast` and `useToastOverlay` calls target that overlay. */\n children?: ReactNode | undefined;\n};\n\nexport {\n type SelectionProps,\n type ExpanderDescriptions,\n type ExpansionProps,\n type SortProps,\n type DropDownOwnProps,\n type ListItem,\n type ListSection,\n type ListItemRenderArgs,\n type ListRowProps,\n type ListSectionRenderArgs,\n type ListItemRenderer,\n type ListRowPropsResolver,\n type ListSectionRenderer,\n type ColumnViewColumn,\n type ColumnViewProps,\n type DropDownProps,\n type GridViewProps,\n type ListViewProps,\n type ComboRowProps,\n type ToastOptions,\n type ToastController,\n type ToastOverlayController,\n type ToastProviderProps,\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAqTA,OAAO,EAwBN,CAAC","sourcesContent":["import type * as Adw from \"@gtkx/gi/adw\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { AdwComboRowProps, AdwToastProps } from \"@gtkx/jsx/adw\";\nimport type {\n GtkColumnViewColumnProps,\n GtkColumnViewProps,\n GtkDropDownProps,\n GtkGridViewProps,\n GtkListViewProps,\n} from \"@gtkx/jsx/gtk\";\nimport type { ReactNode, RefObject } from \"react\";\n\n/**\n * A single item in a collection model, identified by a stable id and holding an\n * arbitrary value. Nested items form a tree.\n */\ntype ListItem<T = unknown> = {\n /** Stable identifier used to track the item across updates and selection, naming every row that carries it. */\n id: string;\n /** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */\n value: T;\n /** Child items nested under this one, which turn a plain item list into a tree, read only as rows are drawn. */\n children?: ListItem<T>[] | undefined;\n /** Hides the tree expander arrow even when the item has children, through `hide-expander`. */\n shouldHideExpander?: boolean | undefined;\n /** Adds indentation matching the item's depth in the tree, through `indent-for-depth`. */\n shouldIndentForDepth?: boolean | undefined;\n /** Reserves indentation space for an expander icon, through `indent-for-icon`. */\n shouldIndentForIcon?: boolean | undefined;\n};\n\n/** A group of items rendered under a shared section header. */\ntype ListSection<S = unknown, T = unknown> = {\n /** Stable identifier used to track the section across updates. */\n id: string;\n /** Payload handed to the section header renderer as `ListSectionRenderArgs.section`. */\n value: S;\n /** Items belonging to this section. */\n data: ListItem<T>[];\n};\n\n/** Arguments passed to a {@link ListItemRenderer} when rendering one cell. */\ntype ListItemRenderArgs<T> = {\n /** Value of the `ListItem` being rendered. */\n item: T;\n /** Position of the item in the flattened item list, which excludes section headers and collapsed tree rows. */\n index: number;\n /** Depth of the item within a tree, starting at zero for top-level items. */\n depth?: number | undefined;\n /** Whether the item is currently expanded in a tree view. */\n isExpanded?: boolean | undefined;\n};\n\n/**\n * Properties applied to the row that carries one item's cells. A Gtk.ColumnViewRow is not a widget, so\n * these are the only handles it offers; anything omitted falls back to the row's own default, which\n * leaves the accessibility strings unset rather than setting them to an empty string.\n */\ntype ListRowProps = {\n /** Name a screen reader announces for the row, through `accessible-label`. */\n accessibleLabel?: string | undefined;\n /** Longer description a screen reader announces for the row, through `accessible-description`. */\n accessibleDescription?: string | undefined;\n /** Whether activating the row emits the view's `activate` signal; rows are activatable by default. */\n isActivatable?: boolean | undefined;\n /** Whether the row takes keyboard focus; rows are focusable by default. */\n isFocusable?: boolean | undefined;\n /** Whether clicking or keying the row tries to select it; rows are selectable by default. */\n isSelectable?: boolean | undefined;\n};\n\n/** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */\ntype ListSectionRenderArgs<S> = {\n /** Value of the `ListSection` whose header is being rendered. */\n section: S;\n};\n\n/** Renders the contents of one cell of a collection view. */\ntype ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;\n/** Renders the contents of one section header of a collection view. */\ntype ListSectionRenderer<S> = (args: ListSectionRenderArgs<S>) => ReactNode;\n/** Returns the {@link ListRowProps} to apply to the row displaying one item, re-run whenever the item renders. */\ntype ListRowPropsResolver<T> = (args: ListItemRenderArgs<T>) => ListRowProps;\n\n/** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */\ntype ItemSizeProps = {\n /** Height in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemHeight?: number | undefined;\n /** Width in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemWidth?: number | undefined;\n};\n\n/** The flat-collection hint shared by {@link ListView} and {@link ColumnView}. */\ntype FlatnessProps = {\n /**\n * Declares every item a leaf, so the view skips tree discovery when synchronising a large collection\n * instead of scanning each item for `children`. Must not be set when any item has children: those\n * items would render as plain rows that never expand.\n */\n isFlat?: boolean | undefined;\n};\n\n/** Controlled selection shared by the multi-item collection views. */\ntype SelectionProps = {\n /**\n * Ids of the items to keep selected; omitting it keeps nothing selected, and `onSelectionChanged` is how a\n * user's selection is adopted into it. An id repeated in several branches of a tree names every matching row,\n * and a single-selection view takes the first of them.\n */\n selectedIds?: string[] | null | undefined;\n /** Called with one id per selected row whenever the selection changes, and once on mount. */\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n /** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */\n selectionMode?: Gtk.SelectionMode | null | undefined;\n};\n\n/**\n * Wording a screen reader announces for the control that expands and collapses a row. GTK names that control\n * after the row's own content and reports whether it is expanded, but says nothing about what activating it\n * does, so these strings supply that and belong in the application's own language.\n */\ntype ExpanderDescriptions = {\n /** Announced while the row is collapsed, such as \"Expand\". */\n expand: string;\n /** Announced while the row is expanded, such as \"Collapse\". */\n collapse: string;\n};\n\n/** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */\ntype ExpansionProps = {\n /**\n * Ids of the items to keep expanded; omitting it keeps every row collapsed, and `onExpandedChange` is how a\n * user's expansion is adopted into it. An id repeated in several branches names every matching row, so all of\n * them expand together. An item whose children lead back to itself expands one level at a time, since a row\n * repeating an item already expanded above it stays collapsed.\n */\n expandedIds?: string[] | null | undefined;\n /** Called with one id per expanded row, in visible order, whenever expansion changes. */\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n /**\n * Wording announced for the expander of every row that can expand, describing what activating it does.\n * Omitting it leaves those expanders described only by the row they carry, and rows that cannot expand or\n * that hide their expander are never described.\n */\n expanderDescriptions?: ExpanderDescriptions | null | undefined;\n};\n\n/** Controlled sorting for the views whose headers can sort the collection. */\ntype SortProps = {\n /** Id of the column the view is sorted by, making sorting controlled. */\n sortColumn?: string | null | undefined;\n /** Direction `sortColumn` is sorted in, defaulting to ascending. */\n sortOrder?: Gtk.SortType | null | undefined;\n /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\n/** The data a collection view renders, either as a plain item list or grouped into sections. */\ntype SourceProps<T, S> = {\n /** Items to render, nesting through `ListItem.children` for a tree; ignored once `sections` is given. */\n items?: ListItem<T>[] | undefined;\n /** Items grouped under section headers, rendered in place of `items`. */\n sections?: ListSection<S, T>[] | undefined;\n};\n\n/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */\ntype ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, \"factory\" | \"sorter\" | \"id\" | \"title\"> & {\n /** Stable identifier, also used to address the column through sorting props. */\n id: string;\n /** Text shown in the column header. */\n title: string;\n /** Renders the contents of this column's cell for one item. */\n renderCell: ListItemRenderer<T>;\n /** Makes the column header clickable, reporting the choice through `onSortChanged`. */\n isSortable?: boolean | undefined;\n /** Menu element popped up as the column header's context menu, on a right-click. */\n headerMenu?: ReactNode;\n};\n\n/** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */\ntype ColumnViewOwnProps<T, S> = SelectionProps &\n ExpansionProps &\n SortProps &\n SourceProps<T, S> &\n FlatnessProps &\n Omit<ItemSizeProps, \"estimatedItemWidth\"> & {\n /** Columns to render, in order; each carries its own cell renderer. */\n columns: ColumnViewColumn<T>[];\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n /** Resolves the props of the row carrying one item's cells, such as its screen-reader label. */\n rowProps?: ListRowPropsResolver<T> | null | undefined;\n };\n\n/**\n * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with\n * declarative collection props: flat items or grouped sections, controlled selection\n * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section\n * header renderer, per-row props, and the columns to render.\n */\ntype ColumnViewProps<T = unknown, S = unknown> = Omit<\n GtkColumnViewProps,\n \"columns\" | \"model\" | \"headerFactory\" | \"rowFactory\" | keyof ColumnViewOwnProps<T, S>\n> &\nColumnViewOwnProps<T, S>;\n\n/** The declarative collection props {@link DropDown} and `ComboRow` add on top of their widget's own. */\ntype DropDownOwnProps<T, S> = SourceProps<T, S> & {\n /** Id of the currently selected item, making the selection controlled. */\n selectedId?: string | null | undefined;\n /** Called with the id of the item that became selected. */\n onSelectionChanged?: ((id: string) => void) | null | undefined;\n /** Renders the collapsed display, and the popup rows too unless `renderListItem` is given. */\n renderItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n};\n\n/** A drop-down-shaped widget's props with its model and factories swapped for the declarative collection props. */\ntype DropDownWidgetProps<Widget, T, S> = Omit<\n Widget,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\" | keyof DropDownOwnProps<T, S>\n> &\nDropDownOwnProps<T, S>;\n\n/**\n * Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the collapsed display, popup rows, and popup section headers.\n */\ntype DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;\n\n/** The declarative collection props {@link GridView} adds on top of Gtk.GridView's own. */\ntype GridViewOwnProps<T> = ItemSizeProps &\n SelectionProps & {\n /** Items to render as cells; a grid is always flat, so `ListItem.children` is ignored. */\n items?: ListItem<T>[] | undefined;\n /** Renders the contents of one cell. */\n renderItem: ListItemRenderer<T>;\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 */\ntype GridViewProps<T = unknown> = Omit<GtkGridViewProps, \"model\" | \"factory\" | keyof GridViewOwnProps<T>> &\n GridViewOwnProps<T>;\n\n/** The declarative collection props {@link ListView} adds on top of Gtk.ListView's own. */\ntype ListViewOwnProps<T, S> = ItemSizeProps &\n SelectionProps &\n ExpansionProps &\n SourceProps<T, S> &\n FlatnessProps & {\n /** Renders the contents of one row. */\n renderItem: ListItemRenderer<T>;\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n };\n\n/**\n * Props for {@link ListView}. Combines the underlying Gtk.ListView props with\n * declarative collection props: flat items or grouped sections, a per-row renderItem,\n * an optional section header renderer, controlled selection and expansion, and\n * estimated item sizing.\n */\ntype ListViewProps<T = unknown, S = unknown> = Omit<\n GtkListViewProps,\n \"model\" | \"factory\" | \"headerFactory\" | keyof ListViewOwnProps<T, S>\n> &\nListViewOwnProps<T, S>;\n\n/**\n * Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the row display, popup rows, and popup section headers.\n */\ntype ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;\n/**\n * Describes a toast raised through {@link useToast}: the construct-time properties of an\n * `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.\n */\ntype ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, \"onButtonClicked\" | \"onDismissed\">;\n\n/** Imperative controls for individual toasts, returned by {@link useToast}. */\ntype ToastController = {\n /** Builds a toast, shows it through the overlay, and returns it. */\n show: (options?: ToastOptions) => Adw.Toast;\n /** Dismisses a single toast, typically one returned by `ToastController.show`. */\n dismiss: (toast: Adw.Toast) => void;\n};\n\n/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */\ntype ToastOverlayController = {\n /** Dismisses the shown toast and every queued one. */\n dismissAll: () => void;\n};\n\n/** Props for {@link ToastProvider}. */\ntype ToastProviderProps = {\n /** Ref also given to the `AdwToastOverlay` the toasts appear over. */\n overlayRef: RefObject<Adw.ToastOverlay | null>;\n /** Subtree whose `useToast` and `useToastOverlay` calls target that overlay. */\n children?: ReactNode | undefined;\n};\n\nexport {\n type SelectionProps,\n type ExpanderDescriptions,\n type ExpansionProps,\n type SortProps,\n type DropDownOwnProps,\n type ListItem,\n type ListSection,\n type ListItemRenderArgs,\n type ListRowProps,\n type ListSectionRenderArgs,\n type ListItemRenderer,\n type ListRowPropsResolver,\n type ListSectionRenderer,\n type ColumnViewColumn,\n type ColumnViewProps,\n type DropDownProps,\n type GridViewProps,\n type ListViewProps,\n type ComboRowProps,\n type ToastOptions,\n type ToastController,\n type ToastOverlayController,\n type ToastProviderProps,\n};\n"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@gtkx/components",
3
- "version": "2.0.0-beta.1",
4
- "description": "High-level GTK components: collection views, menus, containers.",
3
+ "version": "2.0.0-beta.10",
4
+ "description": "Adwaita and GTK collection views, dropdowns, combo rows, and toasts.",
5
5
  "keywords": [
6
6
  "gtkx",
7
7
  "gtk",
8
8
  "gtk4",
9
9
  "adwaita",
10
+ "gnome",
10
11
  "react",
11
12
  "components",
12
13
  "linux",
@@ -52,18 +53,18 @@
52
53
  "node": ">=26.7.0"
53
54
  },
54
55
  "dependencies": {
55
- "@gtkx/react": "2.0.0-beta.1",
56
- "@gtkx/runtime": "2.0.0-beta.1",
57
- "@gtkx/utils": "2.0.0-beta.1"
56
+ "@gtkx/react": "2.0.0-beta.10",
57
+ "@gtkx/runtime": "2.0.0-beta.10",
58
+ "@gtkx/utils": "2.0.0-beta.10"
58
59
  },
59
60
  "peerDependencies": {
60
61
  "react": "^19.2"
61
62
  },
62
63
  "devDependencies": {
63
- "@gtkx/config": "2.0.0-beta.1",
64
- "@gtkx/testing": "2.0.0-beta.1",
65
- "@gtkx/vitest": "2.0.0-beta.1",
66
- "vitest": "^4.1.11"
64
+ "@gtkx/config": "2.0.0-beta.10",
65
+ "@gtkx/testing": "2.0.0-beta.10",
66
+ "@gtkx/vitest": "2.0.0-beta.10",
67
+ "vitest": "^5.0.0"
67
68
  },
68
69
  "scripts": {
69
70
  "release": "tsx ../../scripts/release-package.ts"
@@ -29,6 +29,7 @@ type ColumnListProps = Omit<ColumnCellsProps, "column" | "hasExpander"> & {
29
29
  const COLUMN_VIEW_PROPS = [
30
30
  "items",
31
31
  "sections",
32
+ "isFlat",
32
33
  "renderHeader",
33
34
  "rowProps",
34
35
  "columns",
@@ -3,8 +3,8 @@ import type { ReactElement, ReactNode } from "react";
3
3
  import * as Gtk from "@gtkx/gi/gtk";
4
4
  import { GtkSignalListItemFactory, GtkTreeExpander } from "@gtkx/jsx/gtk";
5
5
  import { createPortal, useProperty } from "@gtkx/react";
6
- import { setObjectProperty, t } from "@gtkx/runtime";
7
- import { memo, useLayoutEffect, useState, useSyncExternalStore } from "react";
6
+ import { setProperty, t } from "@gtkx/runtime";
7
+ import { memo, useInsertionEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
8
8
  import type {
9
9
  ExpanderDescriptions,
10
10
  ListItem,
@@ -34,6 +34,7 @@ type CellHost = FactoryHost & {
34
34
  type CellEntry<H extends FactoryHost> = {
35
35
  key: string;
36
36
  host: H;
37
+ identity: ItemIdentityStore;
37
38
  };
38
39
 
39
40
  type FactoryHandlers = {
@@ -88,14 +89,34 @@ type ItemSlot = {
88
89
  args: ListItemRenderArgs<unknown>;
89
90
  };
90
91
 
92
+ type CollectionState = {
93
+ collection: Collection;
94
+ expandedIds: string[] | null | undefined;
95
+ };
96
+
97
+ type CollectionStateStore = {
98
+ read: () => CollectionState;
99
+ write: (state: CollectionState) => void;
100
+ };
101
+
102
+ type ItemIdentity = {
103
+ item: ListItem | undefined;
104
+ position: number;
105
+ isExpanded: boolean;
106
+ };
107
+
108
+ type ItemIdentityStore = {
109
+ read: () => ItemIdentity | null;
110
+ write: (identity: ItemIdentity) => void;
111
+ };
112
+
91
113
  type ItemCellProps = {
92
114
  entry: CellEntry<Gtk.ListItem>;
93
115
  render: ListItemRenderer<never>;
94
- collection: Collection;
116
+ state: CollectionStateStore;
95
117
  hasExpander: boolean;
96
- expandedIds: string[] | null | undefined;
97
118
  expanderDescriptions: ExpanderDescriptions | null | undefined;
98
- };
119
+ } & ItemIdentity;
99
120
 
100
121
  type ItemPortalsProps = {
101
122
  registry: CellRegistry<Gtk.ListItem>;
@@ -109,9 +130,8 @@ type ItemPortalsProps = {
109
130
  type ItemRowProps = {
110
131
  entry: CellEntry<Gtk.ColumnViewRow>;
111
132
  rowProps: ListRowPropsResolver<never>;
112
- collection: Collection;
113
- expandedIds: string[] | null | undefined;
114
- };
133
+ state: CollectionStateStore;
134
+ } & ItemIdentity;
115
135
 
116
136
  type RowPortalsProps = {
117
137
  registry: CellRegistry<Gtk.ColumnViewRow>;
@@ -142,8 +162,8 @@ type RowSlot = {
142
162
  portals: ReactNode;
143
163
  };
144
164
 
145
- const ItemCell = memo(ItemCellImpl);
146
- const ItemRow = memo(ItemRowImpl);
165
+ const ItemCell = memo(ItemCellImpl, isSameItemCell);
166
+ const ItemRow = memo(ItemRowImpl, isSameItemRow);
147
167
  const HeaderCell = memo(HeaderCellImpl);
148
168
  const CELL_OPTIONS: CellRegistryOptions<Gtk.ListItem> = { isHost: isListItem, prepare: prepareCell };
149
169
  const HEADER_OPTIONS: CellRegistryOptions<Gtk.ListHeader> = { isHost: isListHeader, prepare: prepareCell };
@@ -184,7 +204,7 @@ function notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): voi
184
204
  function createEntry<H extends FactoryHost>(state: CellRegistryState<H>, host: H): CellEntry<H> {
185
205
  state.serial += 1;
186
206
 
187
- return { key: `gtkx-cell-${String(state.serial)}`, host };
207
+ return { key: `gtkx-cell-${String(state.serial)}`, host, identity: createItemIdentityStore() };
188
208
  }
189
209
 
190
210
  function setupHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {
@@ -283,9 +303,13 @@ function isRowWanted(options: ItemSlotOptions, item: ListItem): boolean {
283
303
  return options.expandedIds?.includes(item.id) ?? false;
284
304
  }
285
305
 
286
- function itemArgs(item: ListItem, options: ItemSlotOptions): ListItemRenderArgs<unknown> {
287
- const args: ListItemRenderArgs<unknown> = { item: item.value, index: options.position ?? 0 };
288
- const row = options.row;
306
+ function itemArgs(
307
+ item: ListItem,
308
+ position: number | undefined,
309
+ row: Gtk.TreeListRow | null,
310
+ isExpanded: boolean,
311
+ ): ListItemRenderArgs<unknown> {
312
+ const args: ListItemRenderArgs<unknown> = { item: item.value, index: position ?? 0 };
289
313
 
290
314
  if (row === null) {
291
315
  return args;
@@ -294,7 +318,7 @@ function itemArgs(item: ListItem, options: ItemSlotOptions): ListItemRenderArgs<
294
318
  args.depth = row.getDepth();
295
319
 
296
320
  if (row.isExpandable()) {
297
- args.isExpanded = isRowWanted(options, item);
321
+ args.isExpanded = isExpanded;
298
322
  }
299
323
 
300
324
  return args;
@@ -308,21 +332,127 @@ function slotFor(options: ItemSlotOptions): ItemSlot | null {
308
332
  return null;
309
333
  }
310
334
 
311
- return { item, row: options.row, args: itemArgs(item, options) };
335
+ return {
336
+ item,
337
+ row: options.row,
338
+ args: itemArgs(item, options.position, options.row, isRowWanted(options, item)),
339
+ };
312
340
  }
313
341
 
314
342
  function useItemSlot(
315
343
  entry: CellEntry<PositionedHost>,
316
- collection: Collection,
317
- expandedIds: string[] | null | undefined,
344
+ state: CollectionStateStore,
345
+ identity: ItemIdentity,
318
346
  ): ItemSlot | null {
319
347
  const position = useProperty(entry.host, "position");
320
348
  const item = useProperty(entry.host, "item") ?? null;
321
349
  const row = item instanceof Gtk.TreeListRow ? item : null;
322
350
 
351
+ if (position === identity.position) {
352
+ return identity.item === undefined
353
+ ? null
354
+ : {
355
+ item: identity.item,
356
+ row,
357
+ args: itemArgs(identity.item, position, row, identity.isExpanded),
358
+ };
359
+ }
360
+
361
+ const { collection, expandedIds } = state.read();
362
+
323
363
  return slotFor({ item, position, row, collection, expandedIds });
324
364
  }
325
365
 
366
+ function itemIdentity(
367
+ entry: CellEntry<PositionedHost>,
368
+ collection: Collection,
369
+ expandedIds: string[] | null | undefined,
370
+ ): ItemIdentity {
371
+ const ref = slotRefFor(entry.host.getItem());
372
+ const item = ref === null ? undefined : collection.itemAt(ref);
373
+
374
+ return {
375
+ item,
376
+ position: entry.host.getPosition(),
377
+ isExpanded: item === undefined ? false : (expandedIds?.includes(item.id) ?? false),
378
+ };
379
+ }
380
+
381
+ function isSameItemIdentity(previous: ItemIdentity, next: ItemIdentity): boolean {
382
+ return (
383
+ previous.item === next.item &&
384
+ previous.position === next.position &&
385
+ previous.isExpanded === next.isExpanded
386
+ );
387
+ }
388
+
389
+ function isSameItemCell(previous: ItemCellProps, next: ItemCellProps): boolean {
390
+ const identity = previous.entry.identity.read() ?? previous;
391
+
392
+ return (
393
+ previous.entry === next.entry &&
394
+ previous.render === next.render &&
395
+ previous.hasExpander === next.hasExpander &&
396
+ previous.expanderDescriptions === next.expanderDescriptions &&
397
+ isSameItemIdentity(identity, next)
398
+ );
399
+ }
400
+
401
+ function isSameItemRow(previous: ItemRowProps, next: ItemRowProps): boolean {
402
+ const identity = previous.entry.identity.read() ?? previous;
403
+
404
+ return previous.entry === next.entry && previous.rowProps === next.rowProps && isSameItemIdentity(identity, next);
405
+ }
406
+
407
+ function createItemIdentityStore(): ItemIdentityStore {
408
+ let current: ItemIdentity | null = null;
409
+
410
+ return {
411
+ read: () => current,
412
+ write: (identity) => {
413
+ current = identity;
414
+ },
415
+ };
416
+ }
417
+
418
+ function renderedIdentity(entry: CellEntry<PositionedHost>, slot: ItemSlot | null): ItemIdentity {
419
+ return {
420
+ item: slot?.item,
421
+ position: slot?.args.index ?? entry.host.getPosition(),
422
+ isExpanded: slot?.args.isExpanded ?? false,
423
+ };
424
+ }
425
+
426
+ function useRememberIdentity(entry: CellEntry<PositionedHost>, slot: ItemSlot | null): void {
427
+ useLayoutEffect(() => {
428
+ entry.identity.write(renderedIdentity(entry, slot));
429
+ });
430
+ }
431
+
432
+ function createCollectionStateStore(initial: CollectionState): CollectionStateStore {
433
+ let current = initial;
434
+
435
+ return {
436
+ read: () => current,
437
+ write: (state) => {
438
+ current = state;
439
+ },
440
+ };
441
+ }
442
+
443
+ function useCollectionState(
444
+ collection: Collection,
445
+ expandedIds: string[] | null | undefined,
446
+ ): CollectionStateStore {
447
+ const [state] = useState(() => createCollectionStateStore({ collection, expandedIds }));
448
+
449
+ useInsertionEffect(() => {
450
+ state.write({ collection, expandedIds });
451
+ }, [state, collection, expandedIds]);
452
+
453
+ return state;
454
+ }
455
+
326
456
  function expanderDescriptionFor(
327
457
  slot: ItemSlot,
328
458
  descriptions: ExpanderDescriptions | null | undefined,
@@ -402,38 +532,60 @@ function rowPropsFor(slot: ItemSlot | null, rowProps: ListRowPropsResolver<never
402
532
  }
403
533
 
404
534
  function setRowText(host: Gtk.ColumnViewRow, name: string, value: string | null): void {
405
- setObjectProperty(host, name, ROW_TEXT_DESCRIPTOR, value);
535
+ setProperty(host, name, ROW_TEXT_DESCRIPTOR, value);
406
536
  }
407
537
 
408
- function applyRowProps(host: Gtk.ColumnViewRow, props: ResolvedRowProps): void {
409
- setRowText(host, "accessible-label", props.accessibleLabel);
410
- setRowText(host, "accessible-description", props.accessibleDescription);
411
- host.setActivatable(props.isActivatable);
412
- host.setFocusable(props.isFocusable);
413
- host.setSelectable(props.isSelectable);
538
+ function applyRowProps(
539
+ host: Gtk.ColumnViewRow,
540
+ props: ResolvedRowProps,
541
+ previous: ResolvedRowProps | null,
542
+ ): void {
543
+ if (previous?.accessibleLabel !== props.accessibleLabel) {
544
+ setRowText(host, "accessible-label", props.accessibleLabel);
545
+ }
546
+
547
+ if (previous?.accessibleDescription !== props.accessibleDescription) {
548
+ setRowText(host, "accessible-description", props.accessibleDescription);
549
+ }
550
+
551
+ if (previous?.isActivatable !== props.isActivatable) {
552
+ host.setActivatable(props.isActivatable);
553
+ }
554
+
555
+ if (previous?.isFocusable !== props.isFocusable) {
556
+ host.setFocusable(props.isFocusable);
557
+ }
558
+
559
+ if (previous?.isSelectable !== props.isSelectable) {
560
+ host.setSelectable(props.isSelectable);
561
+ }
414
562
  }
415
563
 
416
564
  function ItemCellImpl({
417
565
  entry,
418
566
  render,
419
- collection,
567
+ state,
420
568
  hasExpander,
421
- expandedIds,
422
569
  expanderDescriptions,
570
+ ...identity
423
571
  }: ItemCellProps): ReactNode {
424
- const slot = useItemSlot(entry, collection, expandedIds);
572
+ const slot = useItemSlot(entry, state, identity);
573
+ useRememberIdentity(entry, slot);
425
574
  const body = itemBody(slot, render, hasExpander, expanderDescriptions);
426
575
 
427
576
  return createPortal(body, entry.host, entry.key);
428
577
  }
429
578
 
430
- function ItemRowImpl({ entry, rowProps, collection, expandedIds }: ItemRowProps): ReactNode {
431
- const slot = useItemSlot(entry, collection, expandedIds);
579
+ function ItemRowImpl({ entry, rowProps, state, ...identity }: ItemRowProps): ReactNode {
580
+ const slot = useItemSlot(entry, state, identity);
581
+ useRememberIdentity(entry, slot);
432
582
  const props = rowPropsFor(slot, rowProps);
583
+ const previous = useRef<ResolvedRowProps | null>(null);
433
584
 
434
585
  useLayoutEffect(() => {
435
- applyRowProps(entry.host, props);
436
- });
586
+ applyRowProps(entry.host, props, previous.current);
587
+ previous.current = props;
588
+ }, [entry.host, props]);
437
589
 
438
590
  return null;
439
591
  }
@@ -458,29 +610,37 @@ const ItemPortals = ({
458
610
  hasExpander,
459
611
  expandedIds,
460
612
  expanderDescriptions,
461
- }: ItemPortalsProps): ReactNode =>
462
- usePortalEntries(registry).map((entry) => (
613
+ }: ItemPortalsProps): ReactNode => {
614
+ const entries = usePortalEntries(registry);
615
+ const state = useCollectionState(collection, expandedIds);
616
+
617
+ return entries.map((entry) => (
463
618
  <ItemCell
464
619
  key={entry.key}
465
620
  entry={entry}
466
621
  render={render}
467
- collection={collection}
622
+ state={state}
468
623
  hasExpander={hasExpander ?? true}
469
- expandedIds={expandedIds}
470
624
  expanderDescriptions={expanderDescriptions}
625
+ {...itemIdentity(entry, collection, expandedIds)}
471
626
  />
472
627
  ));
628
+ };
473
629
 
474
- const RowPortals = ({ registry, rowProps, collection, expandedIds }: RowPortalsProps): ReactNode =>
475
- usePortalEntries(registry).map((entry) => (
630
+ const RowPortals = ({ registry, rowProps, collection, expandedIds }: RowPortalsProps): ReactNode => {
631
+ const entries = usePortalEntries(registry);
632
+ const state = useCollectionState(collection, expandedIds);
633
+
634
+ return entries.map((entry) => (
476
635
  <ItemRow
477
636
  key={entry.key}
478
637
  entry={entry}
479
638
  rowProps={rowProps}
480
- collection={collection}
481
- expandedIds={expandedIds}
639
+ state={state}
640
+ {...itemIdentity(entry, collection, expandedIds)}
482
641
  />
483
642
  ));
643
+ };
484
644
 
485
645
  const HeaderPortals = ({ registry, render, collection }: HeaderPortalsProps): ReactNode =>
486
646
  usePortalEntries(registry).map((entry) => (