@gtkx/components 2.0.0-beta.5 → 2.0.0-beta.7
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/README.md +43 -40
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +1 -0
- package/dist/column-view.js.map +1 -1
- package/dist/internal/cells.d.ts +11 -1
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js +122 -24
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/collection-model.d.ts +5 -5
- package/dist/internal/collection-model.d.ts.map +1 -1
- package/dist/internal/collection-model.js +35 -35
- package/dist/internal/collection-model.js.map +1 -1
- package/dist/list-view.d.ts.map +1 -1
- package/dist/list-view.js +1 -0
- package/dist/list-view.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -8
- package/src/column-view.tsx +1 -0
- package/src/internal/cells.tsx +198 -38
- package/src/internal/collection-model.ts +41 -41
- package/src/list-view.tsx +1 -0
- package/src/types.ts +13 -1
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.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0-beta.7",
|
|
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,17 +53,17 @@
|
|
|
52
53
|
"node": ">=26.7.0"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@gtkx/react": "2.0.0-beta.
|
|
56
|
-
"@gtkx/runtime": "2.0.0-beta.
|
|
57
|
-
"@gtkx/utils": "2.0.0-beta.
|
|
56
|
+
"@gtkx/react": "2.0.0-beta.7",
|
|
57
|
+
"@gtkx/runtime": "2.0.0-beta.7",
|
|
58
|
+
"@gtkx/utils": "2.0.0-beta.7"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"react": "^19.2"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
|
-
"@gtkx/config": "2.0.0-beta.
|
|
64
|
-
"@gtkx/testing": "2.0.0-beta.
|
|
65
|
-
"@gtkx/vitest": "2.0.0-beta.
|
|
64
|
+
"@gtkx/config": "2.0.0-beta.7",
|
|
65
|
+
"@gtkx/testing": "2.0.0-beta.7",
|
|
66
|
+
"@gtkx/vitest": "2.0.0-beta.7",
|
|
66
67
|
"vitest": "^4.1.11"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
package/src/column-view.tsx
CHANGED
package/src/internal/cells.tsx
CHANGED
|
@@ -4,7 +4,7 @@ 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
6
|
import { setProperty, t } from "@gtkx/runtime";
|
|
7
|
-
import { memo, useLayoutEffect, useState, useSyncExternalStore } from "react";
|
|
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
|
-
|
|
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
|
-
|
|
113
|
-
|
|
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(
|
|
287
|
-
|
|
288
|
-
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
317
|
-
|
|
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,
|
|
@@ -405,35 +535,57 @@ function setRowText(host: Gtk.ColumnViewRow, name: string, value: string | null)
|
|
|
405
535
|
setProperty(host, name, ROW_TEXT_DESCRIPTOR, value);
|
|
406
536
|
}
|
|
407
537
|
|
|
408
|
-
function applyRowProps(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
567
|
+
state,
|
|
420
568
|
hasExpander,
|
|
421
|
-
expandedIds,
|
|
422
569
|
expanderDescriptions,
|
|
570
|
+
...identity
|
|
423
571
|
}: ItemCellProps): ReactNode {
|
|
424
|
-
const slot = useItemSlot(entry,
|
|
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,
|
|
431
|
-
const slot = useItemSlot(entry,
|
|
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)
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
481
|
-
|
|
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) => (
|
|
@@ -11,7 +11,7 @@ import { adoptIndex, createTreeExpansion, pruneSlots } from "./tree-expansion.js
|
|
|
11
11
|
type LevelStore = Gio.ListModel & LazyLevelStore;
|
|
12
12
|
|
|
13
13
|
type SlotRef = {
|
|
14
|
-
store:
|
|
14
|
+
store: LazyLevelStore;
|
|
15
15
|
slot: number;
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -93,22 +93,13 @@ function slotRefFor(value: GObject.Object | null): SlotRef | null {
|
|
|
93
93
|
return ref === undefined || ref.slot === -1 ? null : ref;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
function slotPathAt(store:
|
|
96
|
+
function slotPathAt(store: LazyLevelStore, slot: number): string {
|
|
97
97
|
return store.level.path + encodePart(String(slot));
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function growStore(store: LevelStore): void {
|
|
101
|
-
for (let slot = store.refs.length; slot < store.level.items.length; slot++) {
|
|
102
|
-
store.refs.push({ store, slot });
|
|
103
|
-
store.objects.push(null);
|
|
104
|
-
store.childStores.push(null);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
100
|
function newLevelStore(level: Level): LevelStore {
|
|
109
101
|
const store = new (registeredStoreClass())() as LevelStore;
|
|
110
102
|
store.level = level;
|
|
111
|
-
growStore(store);
|
|
112
103
|
|
|
113
104
|
return store;
|
|
114
105
|
}
|
|
@@ -116,6 +107,10 @@ function newLevelStore(level: Level): LevelStore {
|
|
|
116
107
|
function collectFlips(previous: Level, next: Level, overlap: number): Set<number> {
|
|
117
108
|
const flipped: Set<number> = new Set();
|
|
118
109
|
|
|
110
|
+
if (previous.expandableFlags.length === 0 && next.expandableFlags.length === 0) {
|
|
111
|
+
return flipped;
|
|
112
|
+
}
|
|
113
|
+
|
|
119
114
|
for (let slot = 0; slot < overlap; slot++) {
|
|
120
115
|
if ((previous.expandableFlags[slot] ?? false) !== (next.expandableFlags[slot] ?? false)) {
|
|
121
116
|
flipped.add(slot);
|
|
@@ -133,30 +128,30 @@ function pruneFlips(context: SyncContext, store: LevelStore, flipped: Set<number
|
|
|
133
128
|
pruneSlots(context.expansion, store.level.path, (slot) => flipped.has(slot));
|
|
134
129
|
|
|
135
130
|
for (const slot of flipped) {
|
|
136
|
-
store.childStores
|
|
131
|
+
store.childStores.delete(slot);
|
|
137
132
|
}
|
|
138
133
|
}
|
|
139
134
|
|
|
140
135
|
function detachRefs(store: LevelStore, nextLength: number): void {
|
|
141
|
-
for (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (ref !== undefined) {
|
|
145
|
-
ref.slot = -1;
|
|
136
|
+
for (const [slot, ref] of store.refs) {
|
|
137
|
+
if (slot < nextLength) {
|
|
138
|
+
continue;
|
|
146
139
|
}
|
|
140
|
+
|
|
141
|
+
ref.slot = -1;
|
|
142
|
+
store.refs.delete(slot);
|
|
143
|
+
store.objects.delete(slot);
|
|
144
|
+
store.childStores.delete(slot);
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
function shrinkStore(context: SyncContext, store: LevelStore, nextLength: number): void {
|
|
151
|
-
if (
|
|
148
|
+
function shrinkStore(context: SyncContext, store: LevelStore, previousLength: number, nextLength: number): void {
|
|
149
|
+
if (previousLength <= nextLength) {
|
|
152
150
|
return;
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
detachRefs(store, nextLength);
|
|
156
154
|
pruneSlots(context.expansion, store.level.path, (slot) => slot >= nextLength);
|
|
157
|
-
store.refs.length = nextLength;
|
|
158
|
-
store.objects.length = nextLength;
|
|
159
|
-
store.childStores.length = nextLength;
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
function emitTailSplice(store: LevelStore, previousLength: number, nextLength: number): void {
|
|
@@ -205,7 +200,7 @@ function childSync(
|
|
|
205
200
|
slot: number,
|
|
206
201
|
flipped: Set<number>,
|
|
207
202
|
): LevelSync | undefined {
|
|
208
|
-
const child = store.childStores
|
|
203
|
+
const child = store.childStores.get(slot) ?? null;
|
|
209
204
|
|
|
210
205
|
if (child === null || flipped.has(slot)) {
|
|
211
206
|
return undefined;
|
|
@@ -218,8 +213,13 @@ function childSync(
|
|
|
218
213
|
|
|
219
214
|
function childSyncs(context: SyncContext, store: LevelStore, overlap: number, flipped: Set<number>): LevelSync[] {
|
|
220
215
|
const syncs: LevelSync[] = [];
|
|
216
|
+
const slots = store.childStores.keys().toArray().toSorted((left, right) => left - right);
|
|
217
|
+
|
|
218
|
+
for (const slot of slots) {
|
|
219
|
+
if (slot >= overlap) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
221
222
|
|
|
222
|
-
for (let slot = 0; slot < overlap; slot++) {
|
|
223
223
|
const sync = childSync(context, store, slot, flipped);
|
|
224
224
|
|
|
225
225
|
if (sync !== undefined) {
|
|
@@ -232,13 +232,13 @@ function childSyncs(context: SyncContext, store: LevelStore, overlap: number, fl
|
|
|
232
232
|
|
|
233
233
|
function syncEntry(context: SyncContext, entry: LevelSync): LevelSync[] {
|
|
234
234
|
const { store, level } = entry;
|
|
235
|
-
const
|
|
235
|
+
const previous = store.level;
|
|
236
|
+
const previousLength = previous.items.length;
|
|
236
237
|
const overlap = Math.min(previousLength, level.items.length);
|
|
237
|
-
const flipped = collectFlips(
|
|
238
|
+
const flipped = collectFlips(previous, level, overlap);
|
|
238
239
|
store.level = level;
|
|
239
240
|
pruneFlips(context, store, flipped);
|
|
240
|
-
shrinkStore(context, store, level.items.length);
|
|
241
|
-
growStore(store);
|
|
241
|
+
shrinkStore(context, store, previousLength, level.items.length);
|
|
242
242
|
emitTailSplice(store, previousLength, level.items.length);
|
|
243
243
|
emitFlips(store, flipped);
|
|
244
244
|
|
|
@@ -257,8 +257,8 @@ function syncLevel(context: SyncContext, store: LevelStore, level: Level): void
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
function ensureChildStore(index: CollectionIndex, store:
|
|
261
|
-
const existing = store.childStores
|
|
260
|
+
function ensureChildStore(index: CollectionIndex, store: LazyLevelStore, slot: number): LevelStore | null {
|
|
261
|
+
const existing = store.childStores.get(slot) ?? null;
|
|
262
262
|
|
|
263
263
|
if (existing !== null || !(store.level.expandableFlags[slot] ?? false)) {
|
|
264
264
|
return existing;
|
|
@@ -271,7 +271,7 @@ function ensureChildStore(index: CollectionIndex, store: LevelStore, slot: numbe
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
const created = newLevelStore(level);
|
|
274
|
-
store.childStores
|
|
274
|
+
store.childStores.set(slot, created);
|
|
275
275
|
|
|
276
276
|
return created;
|
|
277
277
|
}
|
|
@@ -418,13 +418,15 @@ function createCollectionModel(): CollectionModel {
|
|
|
418
418
|
class LazyLevelStore extends GObject.Object implements Gio.ListModelImpl {
|
|
419
419
|
declare itemsChanged: Gio.ListModel["itemsChanged"];
|
|
420
420
|
level: Level = { path: "", items: [], expandableFlags: [] };
|
|
421
|
-
refs: SlotRef
|
|
422
|
-
objects:
|
|
423
|
-
childStores:
|
|
421
|
+
refs: Map<number, SlotRef> = new Map();
|
|
422
|
+
objects: Map<number, Gtk.StringObject> = new Map();
|
|
423
|
+
childStores: Map<number, LevelStore> = new Map();
|
|
424
424
|
|
|
425
|
-
private createItem(position: number
|
|
425
|
+
private createItem(position: number): Gtk.StringObject {
|
|
426
|
+
const ref = { store: this, slot: position };
|
|
426
427
|
const created = Gtk.StringObject.new("");
|
|
427
|
-
this.
|
|
428
|
+
this.refs.set(position, ref);
|
|
429
|
+
this.objects.set(position, created);
|
|
428
430
|
SLOTS.set(created, ref);
|
|
429
431
|
|
|
430
432
|
return created;
|
|
@@ -435,17 +437,15 @@ class LazyLevelStore extends GObject.Object implements Gio.ListModelImpl {
|
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
vfuncGetNItems(): number {
|
|
438
|
-
return this.
|
|
440
|
+
return this.level.items.length;
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
vfuncGetItem(position: number): GObject.Object | null {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if (ref === undefined) {
|
|
444
|
+
if (position < 0 || position >= this.level.items.length) {
|
|
445
445
|
return null;
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
return this.objects
|
|
448
|
+
return this.objects.get(position) ?? this.createItem(position);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
|