@gtkx/components 2.0.0-beta.4 → 2.0.0-beta.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"column-view.d.ts","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAQlD,OAAO,KAAK,EAAoB,eAAe,EAAmC,MAAM,YAAY,CAAC;AAgLrG;;;;GAIG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAiCrF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"column-view.d.ts","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAQlD,OAAO,KAAK,EAAoB,eAAe,EAAmC,MAAM,YAAY,CAAC;AAiLrG;;;;GAIG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAiCrF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -10,6 +10,7 @@ import { useWidgetRef } from "./internal/use-widget-ref.js";
10
10
  const COLUMN_VIEW_PROPS = [
11
11
  "items",
12
12
  "sections",
13
+ "isFlat",
13
14
  "renderHeader",
14
15
  "rowProps",
15
16
  "columns",
@@ -1 +1 @@
1
- {"version":3,"file":"column-view.js","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,wB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,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,mBAAmB,IAAI,CAAC,CAAC,EAAE,CAAC;IACpE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,YAAY,CAAiB,GAAG,CAAC,CAAC;IAC9D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,gBAAgB,CAAC,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,OAAoC,CAAC;IACxD,gBAAgB,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC;IAE7E,OAAO,CACH,8BACI,KAAC,aAAa,IACV,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,KACZ,MAAM,CAAC,YAAY,KACnB,IAAI,CAAC,YAAY,KACjB,IAAI,YAER,KAAC,UAAU,IACP,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,oBAAoB,EAAE,oBAAoB,EAC1C,IAAI,EAAE,IAAI,GACZ,GACU,EACf,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,OAAO,IACd,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { omit } from \"@gtkx/utils\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { CellSize } from \"./internal/cells.js\";\nimport type { Collection } from \"./internal/collection.js\";\nimport type { ColumnViewColumn, ColumnViewProps, ExpanderDescriptions, SortProps } from \"./types.js\";\nimport { ItemPortals, useItemCells, useRowProps, useSectionHeader } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };\n\ntype ColumnCellsProps = {\n column: ColumnViewColumn<never>;\n hasExpander: boolean;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\" | \"hasExpander\"> & {\n columns: ColumnViewColumn<never>[];\n};\n\nconst COLUMN_VIEW_PROPS = [\n \"items\",\n \"sections\",\n \"renderHeader\",\n \"rowProps\",\n \"columns\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"expandedIds\",\n \"onExpandedChange\",\n \"expanderDescriptions\",\n \"sortColumn\",\n \"sortOrder\",\n \"onSortChanged\",\n \"estimatedItemHeight\",\n \"children\",\n \"ref\",\n] as const satisfies (keyof ColumnViewProps)[];\n\nconst expanderIndexFor = (columns: ColumnViewColumn<never>[]): number =>\n columns.findIndex((column) => column.visible !== false);\n\nconst columnById = (view: Gtk.ColumnView, id: string): Gtk.ColumnViewColumn | null => {\n const columns = view.getColumns();\n\n for (let index = 0; index < columns.getNItems(); index++) {\n const column = columns.getItem(index);\n\n if (column instanceof Gtk.ColumnViewColumn && column.getId() === id) {\n return column;\n }\n }\n\n return null;\n};\n\nconst getSortTarget = (view: Gtk.ColumnView | null, sortColumn: string | null | undefined): SortTarget | null => {\n if (view === null || sortColumn === undefined) {\n return null;\n }\n\n if (sortColumn === null) {\n return { view, column: null };\n }\n\n const column = columnById(view, sortColumn);\n\n return column === null ? null : { view, column };\n};\n\nconst applySort = (\n sorting: RefObject<boolean>,\n view: Gtk.ColumnView,\n column: Gtk.ColumnViewColumn | null,\n order: Gtk.SortType | null | undefined,\n): void => {\n sorting.current = true;\n\n try {\n view.sortByColumn(column, order ?? Gtk.SortType.ASCENDING);\n } finally {\n sorting.current = false;\n }\n};\n\nconst emitSortChanged = (\n sorter: Gtk.ColumnViewSorter | null,\n sorting: RefObject<boolean>,\n sort: SortProps,\n): void => {\n if (sorter === null || sorting.current) {\n return;\n }\n\n sort.onSortChanged?.(sorter.getPrimarySortColumn()?.getId() ?? null, sorter.getPrimarySortOrder());\n};\n\nconst syncSort = (\n sorting: RefObject<boolean>,\n view: Gtk.ColumnView | null,\n sortColumn: string | null | undefined,\n sortOrder: Gtk.SortType | null | undefined,\n): void => {\n const target = getSortTarget(view, sortColumn);\n\n if (target === null) {\n return;\n }\n\n applySort(sorting, target.view, target.column, sortOrder);\n};\n\nconst useColumnSorting = (view: Gtk.ColumnView | null, sort: SortProps, columns: ColumnViewColumn<never>[]): void => {\n const sorting = useRef(false);\n const sorter = view?.getSorter() ?? null;\n const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;\n\n useSignal(columnSorter, \"changed\", (): void => {\n emitSortChanged(columnSorter, sorting, sort);\n });\n\n const { sortColumn, sortOrder } = sort;\n\n useLayoutEffect(() => {\n syncSort(sorting, view, sortColumn, sortOrder);\n }, [view, sortColumn, sortOrder, columns]);\n};\n\nconst ColumnCells = ({\n column,\n hasExpander,\n collection,\n expandedIds,\n expanderDescriptions,\n size,\n}: ColumnCellsProps): ReactNode => {\n const cells = useItemCells(size);\n const rest = omit(column, [\"id\", \"renderCell\", \"isSortable\"]);\n\n return (\n <>\n <GtkColumnViewColumn\n id={column.id}\n factory={<GtkSignalListItemFactory {...cells.handlers} />}\n sorter={column.isSortable === true ? <GtkCustomSorter /> : null}\n {...rest}\n />\n <ItemPortals\n registry={cells}\n render={column.renderCell}\n collection={collection}\n hasExpander={hasExpander}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }: ColumnListProps): ReactNode => {\n const expanderIndex = expanderIndexFor(columns);\n\n return columns.map((column, index) => (\n <ColumnCells\n key={column.id}\n column={column}\n hasExpander={index === expanderIndex}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n size={size}\n />\n ));\n};\n\n/**\n * Renders a Gtk.ColumnView from declarative items or sections and a columns array,\n * with controlled selection, expansion, and sorting, per-column header menus,\n * section header rendering, and per-row props such as a screen-reader label.\n */\nfunction ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode {\n const { renderHeader, rowProps, columns, expandedIds, expanderDescriptions } = props;\n const { sortColumn, sortOrder, onSortChanged, ref } = props;\n const rest = omit(props, COLUMN_VIEW_PROPS);\n const size = { width: -1, height: props.estimatedItemHeight ?? -1 };\n const [view, refCallback] = useWidgetRef<Gtk.ColumnView>(ref);\n const { collection, selection } = useCollection(props);\n const header = useSectionHeader(renderHeader, collection, size);\n const rows = useRowProps(rowProps, collection, expandedIds);\n const columnList = columns as ColumnViewColumn<never>[];\n useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);\n\n return (\n <>\n <GtkColumnView\n ref={refCallback}\n model={selection}\n {...header.factoryProps}\n {...rows.factoryProps}\n {...rest}\n >\n <ColumnList\n columns={columnList}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n size={size}\n />\n </GtkColumnView>\n {header.portals}\n {rows.portals}\n </>\n );\n}\n\nexport { ColumnView };\n"]}
1
+ {"version":3,"file":"column-view.js","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,wBAAwB,EAAE,MA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AAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,mBAAmB,IAAI,CAAC,CAAC,EAAE,CAAC;IACpE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,YAAY,CAAiB,GAAG,CAAC,CAAC;IAC9D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,gBAAgB,CAAC,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,OAAoC,CAAC;IACxD,gBAAgB,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC;IAE7E,OAAO,CACH,8BACI,KAAC,aAAa,IACV,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,KACZ,MAAM,CAAC,YAAY,KACnB,IAAI,CAAC,YAAY,KACjB,IAAI,YAER,KAAC,UAAU,IACP,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,oBAAoB,EAAE,oBAAoB,EAC1C,IAAI,EAAE,IAAI,GACZ,GACU,EACf,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,OAAO,IACd,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { omit } from \"@gtkx/utils\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { CellSize } from \"./internal/cells.js\";\nimport type { Collection } from \"./internal/collection.js\";\nimport type { ColumnViewColumn, ColumnViewProps, ExpanderDescriptions, SortProps } from \"./types.js\";\nimport { ItemPortals, useItemCells, useRowProps, useSectionHeader } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };\n\ntype ColumnCellsProps = {\n column: ColumnViewColumn<never>;\n hasExpander: boolean;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\" | \"hasExpander\"> & {\n columns: ColumnViewColumn<never>[];\n};\n\nconst COLUMN_VIEW_PROPS = [\n \"items\",\n \"sections\",\n \"isFlat\",\n \"renderHeader\",\n \"rowProps\",\n \"columns\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"expandedIds\",\n \"onExpandedChange\",\n \"expanderDescriptions\",\n \"sortColumn\",\n \"sortOrder\",\n \"onSortChanged\",\n \"estimatedItemHeight\",\n \"children\",\n \"ref\",\n] as const satisfies (keyof ColumnViewProps)[];\n\nconst expanderIndexFor = (columns: ColumnViewColumn<never>[]): number =>\n columns.findIndex((column) => column.visible !== false);\n\nconst columnById = (view: Gtk.ColumnView, id: string): Gtk.ColumnViewColumn | null => {\n const columns = view.getColumns();\n\n for (let index = 0; index < columns.getNItems(); index++) {\n const column = columns.getItem(index);\n\n if (column instanceof Gtk.ColumnViewColumn && column.getId() === id) {\n return column;\n }\n }\n\n return null;\n};\n\nconst getSortTarget = (view: Gtk.ColumnView | null, sortColumn: string | null | undefined): SortTarget | null => {\n if (view === null || sortColumn === undefined) {\n return null;\n }\n\n if (sortColumn === null) {\n return { view, column: null };\n }\n\n const column = columnById(view, sortColumn);\n\n return column === null ? null : { view, column };\n};\n\nconst applySort = (\n sorting: RefObject<boolean>,\n view: Gtk.ColumnView,\n column: Gtk.ColumnViewColumn | null,\n order: Gtk.SortType | null | undefined,\n): void => {\n sorting.current = true;\n\n try {\n view.sortByColumn(column, order ?? Gtk.SortType.ASCENDING);\n } finally {\n sorting.current = false;\n }\n};\n\nconst emitSortChanged = (\n sorter: Gtk.ColumnViewSorter | null,\n sorting: RefObject<boolean>,\n sort: SortProps,\n): void => {\n if (sorter === null || sorting.current) {\n return;\n }\n\n sort.onSortChanged?.(sorter.getPrimarySortColumn()?.getId() ?? null, sorter.getPrimarySortOrder());\n};\n\nconst syncSort = (\n sorting: RefObject<boolean>,\n view: Gtk.ColumnView | null,\n sortColumn: string | null | undefined,\n sortOrder: Gtk.SortType | null | undefined,\n): void => {\n const target = getSortTarget(view, sortColumn);\n\n if (target === null) {\n return;\n }\n\n applySort(sorting, target.view, target.column, sortOrder);\n};\n\nconst useColumnSorting = (view: Gtk.ColumnView | null, sort: SortProps, columns: ColumnViewColumn<never>[]): void => {\n const sorting = useRef(false);\n const sorter = view?.getSorter() ?? null;\n const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;\n\n useSignal(columnSorter, \"changed\", (): void => {\n emitSortChanged(columnSorter, sorting, sort);\n });\n\n const { sortColumn, sortOrder } = sort;\n\n useLayoutEffect(() => {\n syncSort(sorting, view, sortColumn, sortOrder);\n }, [view, sortColumn, sortOrder, columns]);\n};\n\nconst ColumnCells = ({\n column,\n hasExpander,\n collection,\n expandedIds,\n expanderDescriptions,\n size,\n}: ColumnCellsProps): ReactNode => {\n const cells = useItemCells(size);\n const rest = omit(column, [\"id\", \"renderCell\", \"isSortable\"]);\n\n return (\n <>\n <GtkColumnViewColumn\n id={column.id}\n factory={<GtkSignalListItemFactory {...cells.handlers} />}\n sorter={column.isSortable === true ? <GtkCustomSorter /> : null}\n {...rest}\n />\n <ItemPortals\n registry={cells}\n render={column.renderCell}\n collection={collection}\n hasExpander={hasExpander}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }: ColumnListProps): ReactNode => {\n const expanderIndex = expanderIndexFor(columns);\n\n return columns.map((column, index) => (\n <ColumnCells\n key={column.id}\n column={column}\n hasExpander={index === expanderIndex}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n size={size}\n />\n ));\n};\n\n/**\n * Renders a Gtk.ColumnView from declarative items or sections and a columns array,\n * with controlled selection, expansion, and sorting, per-column header menus,\n * section header rendering, and per-row props such as a screen-reader label.\n */\nfunction ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode {\n const { renderHeader, rowProps, columns, expandedIds, expanderDescriptions } = props;\n const { sortColumn, sortOrder, onSortChanged, ref } = props;\n const rest = omit(props, COLUMN_VIEW_PROPS);\n const size = { width: -1, height: props.estimatedItemHeight ?? -1 };\n const [view, refCallback] = useWidgetRef<Gtk.ColumnView>(ref);\n const { collection, selection } = useCollection(props);\n const header = useSectionHeader(renderHeader, collection, size);\n const rows = useRowProps(rowProps, collection, expandedIds);\n const columnList = columns as ColumnViewColumn<never>[];\n useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);\n\n return (\n <>\n <GtkColumnView\n ref={refCallback}\n model={selection}\n {...header.factoryProps}\n {...rows.factoryProps}\n {...rest}\n >\n <ColumnList\n columns={columnList}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n size={size}\n />\n </GtkColumnView>\n {header.portals}\n {rows.portals}\n </>\n );\n}\n\nexport { ColumnView };\n"]}
@@ -1,7 +1,7 @@
1
1
  import type * as GObject from "@gtkx/gi/gobject";
2
2
  import type { ReactElement, ReactNode } from "react";
3
3
  import * as Gtk from "@gtkx/gi/gtk";
4
- import type { ExpanderDescriptions, ListItemRenderer, ListRowPropsResolver, ListSectionRenderer } from "../types.js";
4
+ import type { ExpanderDescriptions, ListItem, ListItemRenderer, ListRowPropsResolver, ListSectionRenderer } from "../types.js";
5
5
  import type { Collection } from "./collection.js";
6
6
  type CellSize = {
7
7
  width: number;
@@ -13,6 +13,7 @@ type FactoryHost = GObject.Object & {
13
13
  type CellEntry<H extends FactoryHost> = {
14
14
  key: string;
15
15
  host: H;
16
+ identity: ItemIdentityStore;
16
17
  };
17
18
  type FactoryHandlers = {
18
19
  onSetup: (host: GObject.Object) => void;
@@ -25,6 +26,15 @@ type CellRegistry<H extends FactoryHost> = {
25
26
  subscribe: (onChange: () => void) => () => void;
26
27
  getEntries: () => CellEntry<H>[];
27
28
  };
29
+ type ItemIdentity = {
30
+ item: ListItem | undefined;
31
+ position: number;
32
+ isExpanded: boolean;
33
+ };
34
+ type ItemIdentityStore = {
35
+ read: () => ItemIdentity | null;
36
+ write: (identity: ItemIdentity) => void;
37
+ };
28
38
  type ItemPortalsProps = {
29
39
  registry: CellRegistry<Gtk.ListItem>;
30
40
  render: ListItemRenderer<never>;
@@ -1 +1 @@
1
- {"version":3,"file":"cells.d.ts","sourceRoot":"","sources":["../../src/internal/cells.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAKpC,OAAO,KAAK,EACR,oBAAoB,EAGpB,gBAAgB,EAEhB,oBAAoB,EACpB,mBAAmB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,QAAQ,GAAG;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG;IAChC,OAAO,EAAE,MAAM,OAAO,CA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AAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,oBAAoB,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC;CAClE,CAAC;AA2BF,KAAK,iBAAiB,GAAG;IACrB,YAAY,EAAE;QAAE,aAAa,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC;IAC/C,OAAO,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,KAAK,OAAO,GAAG;IACX,YAAY,EAAE;QAAE,UAAU,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC;IAC5C,OAAO,EAAE,SAAS,CAAC;CACtB,CAAC;AAmIF,iBAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAEhE;AAsTD,QAAA,MAAM,WAAW,GAAI,mFAOlB,gBAAgB,KAAG,SAerB,CAAC;AAsBF,QAAA,MAAM,gBAAgB,GAClB,QAAQ,mBAAmB,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,EACrD,YAAY,UAAU,EACtB,MAAM,QAAQ,KACf,iBAWF,CAAC;AAEF,QAAA,MAAM,WAAW,GACb,UAAU,oBAAoB,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,EACxD,YAAY,UAAU,EACtB,aAAa,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,KACzC,OAaF,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,KAAK,QAAQ,GAChB,CAAC"}
@@ -3,10 +3,10 @@ import * as Gtk from "@gtkx/gi/gtk";
3
3
  import { GtkSignalListItemFactory, GtkTreeExpander } from "@gtkx/jsx/gtk";
4
4
  import { createPortal, useProperty } from "@gtkx/react";
5
5
  import { setProperty, t } from "@gtkx/runtime";
6
- import { memo, useLayoutEffect, useState, useSyncExternalStore } from "react";
6
+ import { memo, useInsertionEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
7
7
  import { slotRefFor } from "./collection-model.js";
8
- const ItemCell = memo(ItemCellImpl);
9
- const ItemRow = memo(ItemRowImpl);
8
+ const ItemCell = memo(ItemCellImpl, isSameItemCell);
9
+ const ItemRow = memo(ItemRowImpl, isSameItemRow);
10
10
  const HeaderCell = memo(HeaderCellImpl);
11
11
  const CELL_OPTIONS = { isHost: isListItem, prepare: prepareCell };
12
12
  const HEADER_OPTIONS = { isHost: isListHeader, prepare: prepareCell };
@@ -37,7 +37,7 @@ function notifyRegistry(state) {
37
37
  }
38
38
  function createEntry(state, host) {
39
39
  state.serial += 1;
40
- return { key: `gtkx-cell-${String(state.serial)}`, host };
40
+ return { key: `gtkx-cell-${String(state.serial)}`, host, identity: createItemIdentityStore() };
41
41
  }
42
42
  function setupHost(state, host) {
43
43
  state.prepare?.(host, state.size);
@@ -117,15 +117,14 @@ function useHeaderCells(size) {
117
117
  function isRowWanted(options, item) {
118
118
  return options.expandedIds?.includes(item.id) ?? false;
119
119
  }
120
- function itemArgs(item, options) {
121
- const args = { item: item.value, index: options.position ?? 0 };
122
- const row = options.row;
120
+ function itemArgs(item, position, row, isExpanded) {
121
+ const args = { item: item.value, index: position ?? 0 };
123
122
  if (row === null) {
124
123
  return args;
125
124
  }
126
125
  args.depth = row.getDepth();
127
126
  if (row.isExpandable()) {
128
- args.isExpanded = isRowWanted(options, item);
127
+ args.isExpanded = isExpanded;
129
128
  }
130
129
  return args;
131
130
  }
@@ -135,14 +134,91 @@ function slotFor(options) {
135
134
  if (item === undefined) {
136
135
  return null;
137
136
  }
138
- return { item, row: options.row, args: itemArgs(item, options) };
137
+ return {
138
+ item,
139
+ row: options.row,
140
+ args: itemArgs(item, options.position, options.row, isRowWanted(options, item)),
141
+ };
139
142
  }
140
- function useItemSlot(entry, collection, expandedIds) {
143
+ function useItemSlot(entry, state, identity) {
141
144
  const position = useProperty(entry.host, "position");
142
145
  const item = useProperty(entry.host, "item") ?? null;
143
146
  const row = item instanceof Gtk.TreeListRow ? item : null;
147
+ if (position === identity.position) {
148
+ return identity.item === undefined
149
+ ? null
150
+ : {
151
+ item: identity.item,
152
+ row,
153
+ args: itemArgs(identity.item, position, row, identity.isExpanded),
154
+ };
155
+ }
156
+ const { collection, expandedIds } = state.read();
144
157
  return slotFor({ item, position, row, collection, expandedIds });
145
158
  }
159
+ function itemIdentity(entry, collection, expandedIds) {
160
+ const ref = slotRefFor(entry.host.getItem());
161
+ const item = ref === null ? undefined : collection.itemAt(ref);
162
+ return {
163
+ item,
164
+ position: entry.host.getPosition(),
165
+ isExpanded: item === undefined ? false : (expandedIds?.includes(item.id) ?? false),
166
+ };
167
+ }
168
+ function isSameItemIdentity(previous, next) {
169
+ return (previous.item === next.item &&
170
+ previous.position === next.position &&
171
+ previous.isExpanded === next.isExpanded);
172
+ }
173
+ function isSameItemCell(previous, next) {
174
+ const identity = previous.entry.identity.read() ?? previous;
175
+ return (previous.entry === next.entry &&
176
+ previous.render === next.render &&
177
+ previous.hasExpander === next.hasExpander &&
178
+ previous.expanderDescriptions === next.expanderDescriptions &&
179
+ isSameItemIdentity(identity, next));
180
+ }
181
+ function isSameItemRow(previous, next) {
182
+ const identity = previous.entry.identity.read() ?? previous;
183
+ return previous.entry === next.entry && previous.rowProps === next.rowProps && isSameItemIdentity(identity, next);
184
+ }
185
+ function createItemIdentityStore() {
186
+ let current = null;
187
+ return {
188
+ read: () => current,
189
+ write: (identity) => {
190
+ current = identity;
191
+ },
192
+ };
193
+ }
194
+ function renderedIdentity(entry, slot) {
195
+ return {
196
+ item: slot?.item,
197
+ position: slot?.args.index ?? entry.host.getPosition(),
198
+ isExpanded: slot?.args.isExpanded ?? false,
199
+ };
200
+ }
201
+ function useRememberIdentity(entry, slot) {
202
+ useLayoutEffect(() => {
203
+ entry.identity.write(renderedIdentity(entry, slot));
204
+ });
205
+ }
206
+ function createCollectionStateStore(initial) {
207
+ let current = initial;
208
+ return {
209
+ read: () => current,
210
+ write: (state) => {
211
+ current = state;
212
+ },
213
+ };
214
+ }
215
+ function useCollectionState(collection, expandedIds) {
216
+ const [state] = useState(() => createCollectionStateStore({ collection, expandedIds }));
217
+ useInsertionEffect(() => {
218
+ state.write({ collection, expandedIds });
219
+ }, [state, collection, expandedIds]);
220
+ return state;
221
+ }
146
222
  function expanderDescriptionFor(slot, descriptions) {
147
223
  const { isExpanded } = slot.args;
148
224
  if (isExpanded === undefined || descriptions == null) {
@@ -186,24 +262,38 @@ function rowPropsFor(slot, rowProps) {
186
262
  function setRowText(host, name, value) {
187
263
  setProperty(host, name, ROW_TEXT_DESCRIPTOR, value);
188
264
  }
189
- function applyRowProps(host, props) {
190
- setRowText(host, "accessible-label", props.accessibleLabel);
191
- setRowText(host, "accessible-description", props.accessibleDescription);
192
- host.setActivatable(props.isActivatable);
193
- host.setFocusable(props.isFocusable);
194
- host.setSelectable(props.isSelectable);
265
+ function applyRowProps(host, props, previous) {
266
+ if (previous?.accessibleLabel !== props.accessibleLabel) {
267
+ setRowText(host, "accessible-label", props.accessibleLabel);
268
+ }
269
+ if (previous?.accessibleDescription !== props.accessibleDescription) {
270
+ setRowText(host, "accessible-description", props.accessibleDescription);
271
+ }
272
+ if (previous?.isActivatable !== props.isActivatable) {
273
+ host.setActivatable(props.isActivatable);
274
+ }
275
+ if (previous?.isFocusable !== props.isFocusable) {
276
+ host.setFocusable(props.isFocusable);
277
+ }
278
+ if (previous?.isSelectable !== props.isSelectable) {
279
+ host.setSelectable(props.isSelectable);
280
+ }
195
281
  }
196
- function ItemCellImpl({ entry, render, collection, hasExpander, expandedIds, expanderDescriptions, }) {
197
- const slot = useItemSlot(entry, collection, expandedIds);
282
+ function ItemCellImpl({ entry, render, state, hasExpander, expanderDescriptions, ...identity }) {
283
+ const slot = useItemSlot(entry, state, identity);
284
+ useRememberIdentity(entry, slot);
198
285
  const body = itemBody(slot, render, hasExpander, expanderDescriptions);
199
286
  return createPortal(body, entry.host, entry.key);
200
287
  }
201
- function ItemRowImpl({ entry, rowProps, collection, expandedIds }) {
202
- const slot = useItemSlot(entry, collection, expandedIds);
288
+ function ItemRowImpl({ entry, rowProps, state, ...identity }) {
289
+ const slot = useItemSlot(entry, state, identity);
290
+ useRememberIdentity(entry, slot);
203
291
  const props = rowPropsFor(slot, rowProps);
292
+ const previous = useRef(null);
204
293
  useLayoutEffect(() => {
205
- applyRowProps(entry.host, props);
206
- });
294
+ applyRowProps(entry.host, props, previous.current);
295
+ previous.current = props;
296
+ }, [entry.host, props]);
207
297
  return null;
208
298
  }
209
299
  function HeaderCellImpl({ entry, render, collection }) {
@@ -216,8 +306,16 @@ function HeaderCellImpl({ entry, render, collection }) {
216
306
  function usePortalEntries(registry) {
217
307
  return useSyncExternalStore(registry.subscribe, registry.getEntries);
218
308
  }
219
- const ItemPortals = ({ registry, render, collection, hasExpander, expandedIds, expanderDescriptions, }) => usePortalEntries(registry).map((entry) => (_jsx(ItemCell, { entry: entry, render: render, collection: collection, hasExpander: hasExpander ?? true, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions }, entry.key)));
220
- const RowPortals = ({ registry, rowProps, collection, expandedIds }) => usePortalEntries(registry).map((entry) => (_jsx(ItemRow, { entry: entry, rowProps: rowProps, collection: collection, expandedIds: expandedIds }, entry.key)));
309
+ const ItemPortals = ({ registry, render, collection, hasExpander, expandedIds, expanderDescriptions, }) => {
310
+ const entries = usePortalEntries(registry);
311
+ const state = useCollectionState(collection, expandedIds);
312
+ return entries.map((entry) => (_jsx(ItemCell, { entry: entry, render: render, state: state, hasExpander: hasExpander ?? true, expanderDescriptions: expanderDescriptions, ...itemIdentity(entry, collection, expandedIds) }, entry.key)));
313
+ };
314
+ const RowPortals = ({ registry, rowProps, collection, expandedIds }) => {
315
+ const entries = usePortalEntries(registry);
316
+ const state = useCollectionState(collection, expandedIds);
317
+ return entries.map((entry) => (_jsx(ItemRow, { entry: entry, rowProps: rowProps, state: state, ...itemIdentity(entry, collection, expandedIds) }, entry.key)));
318
+ };
221
319
  const HeaderPortals = ({ registry, render, collection }) => usePortalEntries(registry).map((entry) => (_jsx(HeaderCell, { entry: entry, render: render, collection: collection }, entry.key)));
222
320
  const useSectionHeader = (render, collection, size) => {
223
321
  const registry = useHeaderCells(size);
@@ -1 +1 @@
1
- {"version":3,"file":"cells.js","sourceRoot":"","sources":["../../src/internal/cells.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAW9E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA+HnD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;AACpC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;AAClC,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;AACxC,MAAM,YAAY,GAAsC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AACrG,MAAM,cAAc,GAAwC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAC3G,MAAM,WAAW,GAA2C,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;AACxF,MAAM,OAAO,GAAa,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AACpD,MAAM,YAAY,GAAiB,EAAE,CAAC;AACtC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAEjD,MA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CAAC;IAC/C,CAAC;IAED,OAAO;QACH,YAAY,EAAE,EAAE,UAAU,EAAE,KAAC,wBAAwB,OAAK,QAAQ,CAAC,QAAQ,GAAI,EAAE;QACjF,OAAO,EAAE,CACL,KAAC,UAAU,IAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAI,CAC3G;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,GAEd,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkSignalListItemFactory, GtkTreeExpander } from \"@gtkx/jsx/gtk\";\nimport { createPortal, useProperty } from \"@gtkx/react\";\nimport { setProperty, t } from \"@gtkx/runtime\";\nimport { memo, useLayoutEffect, useState, useSyncExternalStore } from \"react\";\nimport type {\n ExpanderDescriptions,\n ListItem,\n ListItemRenderArgs,\n ListItemRenderer,\n ListRowProps,\n ListRowPropsResolver,\n ListSectionRenderer,\n} from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { slotRefFor } from \"./collection-model.js\";\n\ntype CellSize = {\n width: number;\n height: number;\n};\n\ntype FactoryHost = GObject.Object & {\n getItem: () => GObject.Object | null;\n};\n\ntype CellHost = FactoryHost & {\n getChild: () => Gtk.Widget | null;\n setChild: (child: Gtk.Widget | null) => void;\n};\n\ntype CellEntry<H extends FactoryHost> = {\n key: string;\n host: H;\n};\n\ntype FactoryHandlers = {\n onSetup: (host: GObject.Object) => void;\n onBind: (host: GObject.Object) => void;\n onTeardown: (host: GObject.Object) => void;\n};\n\ntype CellRegistry<H extends FactoryHost> = {\n handlers: FactoryHandlers;\n setSize: (size: CellSize) => void;\n subscribe: (onChange: () => void) => () => void;\n getEntries: () => CellEntry<H>[];\n};\n\ntype HostGuard<H extends FactoryHost> = (value: GObject.Object) => value is H;\n\ntype CellRegistryOptions<H extends FactoryHost> = {\n isHost: HostGuard<H>;\n prepare?: ((host: H, size: CellSize) => void) | undefined;\n};\n\ntype CellRegistryState<H extends FactoryHost> = CellRegistryOptions<H> & {\n size: CellSize;\n entries: Map<H, CellEntry<H>>;\n snapshot: CellEntry<H>[] | null;\n listeners: Set<() => void>;\n serial: number;\n};\n\ntype ResolvedRowProps = {\n accessibleLabel: string | null;\n accessibleDescription: string | null;\n isActivatable: boolean;\n isFocusable: boolean;\n isSelectable: boolean;\n};\n\ntype ItemSlotOptions = {\n item: GObject.Object | null;\n position: number | undefined;\n row: Gtk.TreeListRow | null;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype PositionedHost = Gtk.ListItem | Gtk.ColumnViewRow;\n\ntype ItemSlot = {\n item: ListItem;\n row: Gtk.TreeListRow | null;\n args: ListItemRenderArgs<unknown>;\n};\n\ntype ItemCellProps = {\n entry: CellEntry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n collection: Collection;\n hasExpander: boolean;\n expandedIds: string[] | null | undefined;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n};\n\ntype ItemPortalsProps = {\n registry: CellRegistry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n collection: Collection;\n hasExpander?: boolean | undefined;\n expandedIds?: string[] | null | undefined;\n expanderDescriptions?: ExpanderDescriptions | null | undefined;\n};\n\ntype ItemRowProps = {\n entry: CellEntry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype RowPortalsProps = {\n registry: CellRegistry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype HeaderCellProps = {\n entry: CellEntry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype HeaderPortalsProps = {\n registry: CellRegistry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype SectionHeaderSlot = {\n factoryProps: { headerFactory?: ReactElement };\n portals: ReactNode;\n};\n\ntype RowSlot = {\n factoryProps: { rowFactory?: ReactElement };\n portals: ReactNode;\n};\n\nconst ItemCell = memo(ItemCellImpl);\nconst ItemRow = memo(ItemRowImpl);\nconst HeaderCell = memo(HeaderCellImpl);\nconst CELL_OPTIONS: CellRegistryOptions<Gtk.ListItem> = { isHost: isListItem, prepare: prepareCell };\nconst HEADER_OPTIONS: CellRegistryOptions<Gtk.ListHeader> = { isHost: isListHeader, prepare: prepareCell };\nconst ROW_OPTIONS: CellRegistryOptions<Gtk.ColumnViewRow> = { isHost: isColumnViewRow };\nconst NO_SIZE: CellSize = { width: -1, height: -1 };\nconst NO_ROW_PROPS: ListRowProps = {};\nconst ROW_TEXT_DESCRIPTOR = t.string(\"borrowed\");\n\nconst placeholder = (size: CellSize): Gtk.Widget =>\n new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });\n\nfunction isListItem(value: GObject.Object): value is Gtk.ListItem {\n return value instanceof Gtk.ListItem;\n}\n\nfunction isListHeader(value: GObject.Object): value is Gtk.ListHeader {\n return value instanceof Gtk.ListHeader;\n}\n\nfunction isColumnViewRow(value: GObject.Object): value is Gtk.ColumnViewRow {\n return value instanceof Gtk.ColumnViewRow;\n}\n\nfunction prepareCell(host: CellHost, size: CellSize): void {\n if (host.getChild() === null) {\n host.setChild(placeholder(size));\n }\n}\n\nfunction notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): void {\n state.snapshot = null;\n\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction createEntry<H extends FactoryHost>(state: CellRegistryState<H>, host: H): CellEntry<H> {\n state.serial += 1;\n\n return { key: `gtkx-cell-${String(state.serial)}`, host };\n}\n\nfunction setupHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n state.entries.set(host, createEntry(state, host));\n notifyRegistry(state);\n}\n\nfunction teardownHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n if (state.entries.delete(host)) {\n notifyRegistry(state);\n }\n}\n\nfunction bindHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n}\n\nfunction subscribeRegistry<H extends FactoryHost>(state: CellRegistryState<H>, onChange: () => void): () => void {\n state.listeners.add(onChange);\n\n return () => {\n state.listeners.delete(onChange);\n };\n}\n\nfunction getRegistryEntries<H extends FactoryHost>(state: CellRegistryState<H>): CellEntry<H>[] {\n state.snapshot ??= state.entries.values().toArray();\n\n return state.snapshot;\n}\n\nfunction guarded<H extends FactoryHost>(isHost: HostGuard<H>, run: (host: H) => void): (host: GObject.Object) => void {\n return (host) => {\n if (isHost(host)) {\n run(host);\n }\n };\n}\n\nfunction createHandlers<H extends FactoryHost>(state: CellRegistryState<H>): FactoryHandlers {\n const { isHost } = state;\n\n return {\n onSetup: guarded(isHost, (host) => {\n setupHost(state, host);\n }),\n onBind: guarded(isHost, (host) => {\n bindHost(state, host);\n }),\n onTeardown: guarded(isHost, (host) => {\n teardownHost(state, host);\n }),\n };\n}\n\nfunction createCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const state: CellRegistryState<H> = {\n ...options,\n size,\n entries: new Map(),\n snapshot: null,\n listeners: new Set(),\n serial: 0,\n };\n\n return {\n handlers: createHandlers(state),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRegistry(state, onChange),\n getEntries: () => getRegistryEntries(state),\n };\n}\n\nfunction useCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const [registry] = useState(() => createCellRegistry(options, size));\n\n useLayoutEffect(() => {\n registry.setSize(size);\n });\n\n return registry;\n}\n\nfunction useItemCells(size: CellSize): CellRegistry<Gtk.ListItem> {\n return useCellRegistry(CELL_OPTIONS, size);\n}\n\nfunction useHeaderCells(size: CellSize): CellRegistry<Gtk.ListHeader> {\n return useCellRegistry(HEADER_OPTIONS, size);\n}\n\nfunction isRowWanted(options: ItemSlotOptions, item: ListItem): boolean {\n return options.expandedIds?.includes(item.id) ?? false;\n}\n\nfunction itemArgs(item: ListItem, options: ItemSlotOptions): ListItemRenderArgs<unknown> {\n const args: ListItemRenderArgs<unknown> = { item: item.value, index: options.position ?? 0 };\n const row = options.row;\n\n if (row === null) {\n return args;\n }\n\n args.depth = row.getDepth();\n\n if (row.isExpandable()) {\n args.isExpanded = isRowWanted(options, item);\n }\n\n return args;\n}\n\nfunction slotFor(options: ItemSlotOptions): ItemSlot | null {\n const ref = slotRefFor(options.item);\n const item = ref === null ? undefined : options.collection.itemAt(ref);\n\n if (item === undefined) {\n return null;\n }\n\n return { item, row: options.row, args: itemArgs(item, options) };\n}\n\nfunction useItemSlot(\n entry: CellEntry<PositionedHost>,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): ItemSlot | null {\n const position = useProperty(entry.host, \"position\");\n const item = useProperty(entry.host, \"item\") ?? null;\n const row = item instanceof Gtk.TreeListRow ? item : null;\n\n return slotFor({ item, position, row, collection, expandedIds });\n}\n\nfunction expanderDescriptionFor(\n slot: ItemSlot,\n descriptions: ExpanderDescriptions | null | undefined,\n): string | undefined {\n const { isExpanded } = slot.args;\n\n if (isExpanded === undefined || descriptions == null) {\n return undefined;\n }\n\n return isExpanded ? descriptions.collapse : descriptions.expand;\n}\n\nfunction wrapExpander(\n slot: ItemSlot,\n content: ReactNode,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n const { item, row } = slot;\n\n const expander: ReactNode =\n row === null\n ? (\n content\n )\n : (\n <GtkTreeExpander\n listRow={row}\n hideExpander={item.shouldHideExpander ?? false}\n indentForDepth={item.shouldIndentForDepth ?? true}\n indentForIcon={item.shouldIndentForIcon ?? true}\n accessibleDescription={expanderDescriptionFor(slot, descriptions)}\n >\n {content}\n </GtkTreeExpander>\n );\n\n return expander;\n}\n\nfunction itemBody(\n slot: ItemSlot | null,\n render: ListItemRenderer<never>,\n hasExpander: boolean,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n if (slot === null) {\n return null;\n }\n\n const renderItem = render as ListItemRenderer<unknown>;\n const content = renderItem(slot.args);\n\n return hasExpander ? wrapExpander(slot, content, descriptions) : content;\n}\n\nfunction rowText(value: string | undefined): string | null {\n return value ?? null;\n}\n\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- reads the flag off a row, paired with rowText */\nfunction rowFlag(value: boolean | undefined): boolean {\n return value ?? true;\n}\n\nfunction rowPropsFor(slot: ItemSlot | null, rowProps: ListRowPropsResolver<never>): ResolvedRowProps {\n const resolve = rowProps as ListRowPropsResolver<unknown>;\n const props = slot === null ? NO_ROW_PROPS : resolve(slot.args);\n\n return {\n accessibleLabel: rowText(props.accessibleLabel),\n accessibleDescription: rowText(props.accessibleDescription),\n isActivatable: rowFlag(props.isActivatable),\n isFocusable: rowFlag(props.isFocusable),\n isSelectable: rowFlag(props.isSelectable),\n };\n}\n\nfunction setRowText(host: Gtk.ColumnViewRow, name: string, value: string | null): void {\n setProperty(host, name, ROW_TEXT_DESCRIPTOR, value);\n}\n\nfunction applyRowProps(host: Gtk.ColumnViewRow, props: ResolvedRowProps): void {\n setRowText(host, \"accessible-label\", props.accessibleLabel);\n setRowText(host, \"accessible-description\", props.accessibleDescription);\n host.setActivatable(props.isActivatable);\n host.setFocusable(props.isFocusable);\n host.setSelectable(props.isSelectable);\n}\n\nfunction ItemCellImpl({\n entry,\n render,\n collection,\n hasExpander,\n expandedIds,\n expanderDescriptions,\n}: ItemCellProps): ReactNode {\n const slot = useItemSlot(entry, collection, expandedIds);\n const body = itemBody(slot, render, hasExpander, expanderDescriptions);\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction ItemRowImpl({ entry, rowProps, collection, expandedIds }: ItemRowProps): ReactNode {\n const slot = useItemSlot(entry, collection, expandedIds);\n const props = rowPropsFor(slot, rowProps);\n\n useLayoutEffect(() => {\n applyRowProps(entry.host, props);\n });\n\n return null;\n}\n\nfunction HeaderCellImpl({ entry, render, collection }: HeaderCellProps): ReactNode {\n const item = useProperty(entry.host, \"item\") ?? null;\n const ref = slotRefFor(item);\n const renderHeader = render as ListSectionRenderer<unknown>;\n const body = ref === null ? null : renderHeader({ section: collection.sectionFor(ref.store.level.path) });\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction usePortalEntries<H extends FactoryHost>(registry: CellRegistry<H>): CellEntry<H>[] {\n return useSyncExternalStore(registry.subscribe, registry.getEntries);\n}\n\nconst ItemPortals = ({\n registry,\n render,\n collection,\n hasExpander,\n expandedIds,\n expanderDescriptions,\n}: ItemPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <ItemCell\n key={entry.key}\n entry={entry}\n render={render}\n collection={collection}\n hasExpander={hasExpander ?? true}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n />\n ));\n\nconst RowPortals = ({ registry, rowProps, collection, expandedIds }: RowPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <ItemRow\n key={entry.key}\n entry={entry}\n rowProps={rowProps}\n collection={collection}\n expandedIds={expandedIds}\n />\n ));\n\nconst HeaderPortals = ({ registry, render, collection }: HeaderPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <HeaderCell key={entry.key} entry={entry} render={render} collection={collection} />\n ));\n\nconst useSectionHeader = (\n render: ListSectionRenderer<never> | null | undefined,\n collection: Collection,\n size: CellSize,\n): SectionHeaderSlot => {\n const registry = useHeaderCells(size);\n\n if (render == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { headerFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: <HeaderPortals registry={registry} render={render} collection={collection} />,\n };\n};\n\nconst useRowProps = (\n rowProps: ListRowPropsResolver<never> | null | undefined,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): RowSlot => {\n const registry = useCellRegistry(ROW_OPTIONS, NO_SIZE);\n\n if (rowProps == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { rowFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: (\n <RowPortals registry={registry} rowProps={rowProps} collection={collection} expandedIds={expandedIds} />\n ),\n };\n};\n\nexport {\n useItemCells,\n useRowProps,\n useSectionHeader,\n ItemPortals,\n type CellSize,\n};\n"]}
1
+ {"version":3,"file":"cells.js","sourceRoot":"","sources":["../../src/internal/cells.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAW1G,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAmJnD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AACpD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AACjD,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;AACxC,MAAM,YAAY,GAAsC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AACrG,MAAM,cAAc,GAAwC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAC3G,MAAM,WAAW,GAA2C,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;AACxF,MAAM,OAAO,GAAa,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,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G,CACrB,MAAqD,EACrD,UAAsB,EACtB,IAAc,EACG,EAAE;IACnB,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAEtC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACjB,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO;QACH,YAAY,EAAE,EAAE,aAAa,EAAE,KAAC,wBAAwB,OAAK,QAAQ,CAAC,QAAQ,GAAI,EAAE;QACpF,OAAO,EAAE,KAAC,aAAa,IAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAI;KACzF,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAChB,QAAwD,EACxD,UAAsB,EACtB,WAAwC,EACjC,EAAE;IACT,MAAM,QAAQ,GAAG,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEvD,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO;QACH,YAAY,EAAE,EAAE,UAAU,EAAE,KAAC,wBAAwB,OAAK,QAAQ,CAAC,QAAQ,GAAI,EAAE;QACjF,OAAO,EAAE,CACL,KAAC,UAAU,IAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAI,CAC3G;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,GAEd,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkSignalListItemFactory, GtkTreeExpander } from \"@gtkx/jsx/gtk\";\nimport { createPortal, useProperty } from \"@gtkx/react\";\nimport { setProperty, t } from \"@gtkx/runtime\";\nimport { memo, useInsertionEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type {\n ExpanderDescriptions,\n ListItem,\n ListItemRenderArgs,\n ListItemRenderer,\n ListRowProps,\n ListRowPropsResolver,\n ListSectionRenderer,\n} from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { slotRefFor } from \"./collection-model.js\";\n\ntype CellSize = {\n width: number;\n height: number;\n};\n\ntype FactoryHost = GObject.Object & {\n getItem: () => GObject.Object | null;\n};\n\ntype CellHost = FactoryHost & {\n getChild: () => Gtk.Widget | null;\n setChild: (child: Gtk.Widget | null) => void;\n};\n\ntype CellEntry<H extends FactoryHost> = {\n key: string;\n host: H;\n identity: ItemIdentityStore;\n};\n\ntype FactoryHandlers = {\n onSetup: (host: GObject.Object) => void;\n onBind: (host: GObject.Object) => void;\n onTeardown: (host: GObject.Object) => void;\n};\n\ntype CellRegistry<H extends FactoryHost> = {\n handlers: FactoryHandlers;\n setSize: (size: CellSize) => void;\n subscribe: (onChange: () => void) => () => void;\n getEntries: () => CellEntry<H>[];\n};\n\ntype HostGuard<H extends FactoryHost> = (value: GObject.Object) => value is H;\n\ntype CellRegistryOptions<H extends FactoryHost> = {\n isHost: HostGuard<H>;\n prepare?: ((host: H, size: CellSize) => void) | undefined;\n};\n\ntype CellRegistryState<H extends FactoryHost> = CellRegistryOptions<H> & {\n size: CellSize;\n entries: Map<H, CellEntry<H>>;\n snapshot: CellEntry<H>[] | null;\n listeners: Set<() => void>;\n serial: number;\n};\n\ntype ResolvedRowProps = {\n accessibleLabel: string | null;\n accessibleDescription: string | null;\n isActivatable: boolean;\n isFocusable: boolean;\n isSelectable: boolean;\n};\n\ntype ItemSlotOptions = {\n item: GObject.Object | null;\n position: number | undefined;\n row: Gtk.TreeListRow | null;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype PositionedHost = Gtk.ListItem | Gtk.ColumnViewRow;\n\ntype ItemSlot = {\n item: ListItem;\n row: Gtk.TreeListRow | null;\n args: ListItemRenderArgs<unknown>;\n};\n\ntype CollectionState = {\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype CollectionStateStore = {\n read: () => CollectionState;\n write: (state: CollectionState) => void;\n};\n\ntype ItemIdentity = {\n item: ListItem | undefined;\n position: number;\n isExpanded: boolean;\n};\n\ntype ItemIdentityStore = {\n read: () => ItemIdentity | null;\n write: (identity: ItemIdentity) => void;\n};\n\ntype ItemCellProps = {\n entry: CellEntry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n state: CollectionStateStore;\n hasExpander: boolean;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n} & ItemIdentity;\n\ntype ItemPortalsProps = {\n registry: CellRegistry<Gtk.ListItem>;\n render: ListItemRenderer<never>;\n collection: Collection;\n hasExpander?: boolean | undefined;\n expandedIds?: string[] | null | undefined;\n expanderDescriptions?: ExpanderDescriptions | null | undefined;\n};\n\ntype ItemRowProps = {\n entry: CellEntry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n state: CollectionStateStore;\n} & ItemIdentity;\n\ntype RowPortalsProps = {\n registry: CellRegistry<Gtk.ColumnViewRow>;\n rowProps: ListRowPropsResolver<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype HeaderCellProps = {\n entry: CellEntry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype HeaderPortalsProps = {\n registry: CellRegistry<Gtk.ListHeader>;\n render: ListSectionRenderer<never>;\n collection: Collection;\n};\n\ntype SectionHeaderSlot = {\n factoryProps: { headerFactory?: ReactElement };\n portals: ReactNode;\n};\n\ntype RowSlot = {\n factoryProps: { rowFactory?: ReactElement };\n portals: ReactNode;\n};\n\nconst ItemCell = memo(ItemCellImpl, isSameItemCell);\nconst ItemRow = memo(ItemRowImpl, isSameItemRow);\nconst HeaderCell = memo(HeaderCellImpl);\nconst CELL_OPTIONS: CellRegistryOptions<Gtk.ListItem> = { isHost: isListItem, prepare: prepareCell };\nconst HEADER_OPTIONS: CellRegistryOptions<Gtk.ListHeader> = { isHost: isListHeader, prepare: prepareCell };\nconst ROW_OPTIONS: CellRegistryOptions<Gtk.ColumnViewRow> = { isHost: isColumnViewRow };\nconst NO_SIZE: CellSize = { width: -1, height: -1 };\nconst NO_ROW_PROPS: ListRowProps = {};\nconst ROW_TEXT_DESCRIPTOR = t.string(\"borrowed\");\n\nconst placeholder = (size: CellSize): Gtk.Widget =>\n new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });\n\nfunction isListItem(value: GObject.Object): value is Gtk.ListItem {\n return value instanceof Gtk.ListItem;\n}\n\nfunction isListHeader(value: GObject.Object): value is Gtk.ListHeader {\n return value instanceof Gtk.ListHeader;\n}\n\nfunction isColumnViewRow(value: GObject.Object): value is Gtk.ColumnViewRow {\n return value instanceof Gtk.ColumnViewRow;\n}\n\nfunction prepareCell(host: CellHost, size: CellSize): void {\n if (host.getChild() === null) {\n host.setChild(placeholder(size));\n }\n}\n\nfunction notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): void {\n state.snapshot = null;\n\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction createEntry<H extends FactoryHost>(state: CellRegistryState<H>, host: H): CellEntry<H> {\n state.serial += 1;\n\n return { key: `gtkx-cell-${String(state.serial)}`, host, identity: createItemIdentityStore() };\n}\n\nfunction setupHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n state.entries.set(host, createEntry(state, host));\n notifyRegistry(state);\n}\n\nfunction teardownHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n if (state.entries.delete(host)) {\n notifyRegistry(state);\n }\n}\n\nfunction bindHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n}\n\nfunction subscribeRegistry<H extends FactoryHost>(state: CellRegistryState<H>, onChange: () => void): () => void {\n state.listeners.add(onChange);\n\n return () => {\n state.listeners.delete(onChange);\n };\n}\n\nfunction getRegistryEntries<H extends FactoryHost>(state: CellRegistryState<H>): CellEntry<H>[] {\n state.snapshot ??= state.entries.values().toArray();\n\n return state.snapshot;\n}\n\nfunction guarded<H extends FactoryHost>(isHost: HostGuard<H>, run: (host: H) => void): (host: GObject.Object) => void {\n return (host) => {\n if (isHost(host)) {\n run(host);\n }\n };\n}\n\nfunction createHandlers<H extends FactoryHost>(state: CellRegistryState<H>): FactoryHandlers {\n const { isHost } = state;\n\n return {\n onSetup: guarded(isHost, (host) => {\n setupHost(state, host);\n }),\n onBind: guarded(isHost, (host) => {\n bindHost(state, host);\n }),\n onTeardown: guarded(isHost, (host) => {\n teardownHost(state, host);\n }),\n };\n}\n\nfunction createCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const state: CellRegistryState<H> = {\n ...options,\n size,\n entries: new Map(),\n snapshot: null,\n listeners: new Set(),\n serial: 0,\n };\n\n return {\n handlers: createHandlers(state),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRegistry(state, onChange),\n getEntries: () => getRegistryEntries(state),\n };\n}\n\nfunction useCellRegistry<H extends FactoryHost>(options: CellRegistryOptions<H>, size: CellSize): CellRegistry<H> {\n const [registry] = useState(() => createCellRegistry(options, size));\n\n useLayoutEffect(() => {\n registry.setSize(size);\n });\n\n return registry;\n}\n\nfunction useItemCells(size: CellSize): CellRegistry<Gtk.ListItem> {\n return useCellRegistry(CELL_OPTIONS, size);\n}\n\nfunction useHeaderCells(size: CellSize): CellRegistry<Gtk.ListHeader> {\n return useCellRegistry(HEADER_OPTIONS, size);\n}\n\nfunction isRowWanted(options: ItemSlotOptions, item: ListItem): boolean {\n return options.expandedIds?.includes(item.id) ?? false;\n}\n\nfunction itemArgs(\n item: ListItem,\n position: number | undefined,\n row: Gtk.TreeListRow | null,\n isExpanded: boolean,\n): ListItemRenderArgs<unknown> {\n const args: ListItemRenderArgs<unknown> = { item: item.value, index: position ?? 0 };\n\n if (row === null) {\n return args;\n }\n\n args.depth = row.getDepth();\n\n if (row.isExpandable()) {\n args.isExpanded = isExpanded;\n }\n\n return args;\n}\n\nfunction slotFor(options: ItemSlotOptions): ItemSlot | null {\n const ref = slotRefFor(options.item);\n const item = ref === null ? undefined : options.collection.itemAt(ref);\n\n if (item === undefined) {\n return null;\n }\n\n return {\n item,\n row: options.row,\n args: itemArgs(item, options.position, options.row, isRowWanted(options, item)),\n };\n}\n\nfunction useItemSlot(\n entry: CellEntry<PositionedHost>,\n state: CollectionStateStore,\n identity: ItemIdentity,\n): ItemSlot | null {\n const position = useProperty(entry.host, \"position\");\n const item = useProperty(entry.host, \"item\") ?? null;\n const row = item instanceof Gtk.TreeListRow ? item : null;\n\n if (position === identity.position) {\n return identity.item === undefined\n ? null\n : {\n item: identity.item,\n row,\n args: itemArgs(identity.item, position, row, identity.isExpanded),\n };\n }\n\n const { collection, expandedIds } = state.read();\n\n return slotFor({ item, position, row, collection, expandedIds });\n}\n\nfunction itemIdentity(\n entry: CellEntry<PositionedHost>,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): ItemIdentity {\n const ref = slotRefFor(entry.host.getItem());\n const item = ref === null ? undefined : collection.itemAt(ref);\n\n return {\n item,\n position: entry.host.getPosition(),\n isExpanded: item === undefined ? false : (expandedIds?.includes(item.id) ?? false),\n };\n}\n\nfunction isSameItemIdentity(previous: ItemIdentity, next: ItemIdentity): boolean {\n return (\n previous.item === next.item &&\n previous.position === next.position &&\n previous.isExpanded === next.isExpanded\n );\n}\n\nfunction isSameItemCell(previous: ItemCellProps, next: ItemCellProps): boolean {\n const identity = previous.entry.identity.read() ?? previous;\n\n return (\n previous.entry === next.entry &&\n previous.render === next.render &&\n previous.hasExpander === next.hasExpander &&\n previous.expanderDescriptions === next.expanderDescriptions &&\n isSameItemIdentity(identity, next)\n );\n}\n\nfunction isSameItemRow(previous: ItemRowProps, next: ItemRowProps): boolean {\n const identity = previous.entry.identity.read() ?? previous;\n\n return previous.entry === next.entry && previous.rowProps === next.rowProps && isSameItemIdentity(identity, next);\n}\n\nfunction createItemIdentityStore(): ItemIdentityStore {\n let current: ItemIdentity | null = null;\n\n return {\n read: () => current,\n write: (identity) => {\n current = identity;\n },\n };\n}\n\nfunction renderedIdentity(entry: CellEntry<PositionedHost>, slot: ItemSlot | null): ItemIdentity {\n return {\n item: slot?.item,\n position: slot?.args.index ?? entry.host.getPosition(),\n isExpanded: slot?.args.isExpanded ?? false,\n };\n}\n\nfunction useRememberIdentity(entry: CellEntry<PositionedHost>, slot: ItemSlot | null): void {\n useLayoutEffect(() => {\n entry.identity.write(renderedIdentity(entry, slot));\n });\n}\n\nfunction createCollectionStateStore(initial: CollectionState): CollectionStateStore {\n let current = initial;\n\n return {\n read: () => current,\n write: (state) => {\n current = state;\n },\n };\n}\n\nfunction useCollectionState(\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): CollectionStateStore {\n const [state] = useState(() => createCollectionStateStore({ collection, expandedIds }));\n\n useInsertionEffect(() => {\n state.write({ collection, expandedIds });\n }, [state, collection, expandedIds]);\n\n return state;\n}\n\nfunction expanderDescriptionFor(\n slot: ItemSlot,\n descriptions: ExpanderDescriptions | null | undefined,\n): string | undefined {\n const { isExpanded } = slot.args;\n\n if (isExpanded === undefined || descriptions == null) {\n return undefined;\n }\n\n return isExpanded ? descriptions.collapse : descriptions.expand;\n}\n\nfunction wrapExpander(\n slot: ItemSlot,\n content: ReactNode,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n const { item, row } = slot;\n\n const expander: ReactNode =\n row === null\n ? (\n content\n )\n : (\n <GtkTreeExpander\n listRow={row}\n hideExpander={item.shouldHideExpander ?? false}\n indentForDepth={item.shouldIndentForDepth ?? true}\n indentForIcon={item.shouldIndentForIcon ?? true}\n accessibleDescription={expanderDescriptionFor(slot, descriptions)}\n >\n {content}\n </GtkTreeExpander>\n );\n\n return expander;\n}\n\nfunction itemBody(\n slot: ItemSlot | null,\n render: ListItemRenderer<never>,\n hasExpander: boolean,\n descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n if (slot === null) {\n return null;\n }\n\n const renderItem = render as ListItemRenderer<unknown>;\n const content = renderItem(slot.args);\n\n return hasExpander ? wrapExpander(slot, content, descriptions) : content;\n}\n\nfunction rowText(value: string | undefined): string | null {\n return value ?? null;\n}\n\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- reads the flag off a row, paired with rowText */\nfunction rowFlag(value: boolean | undefined): boolean {\n return value ?? true;\n}\n\nfunction rowPropsFor(slot: ItemSlot | null, rowProps: ListRowPropsResolver<never>): ResolvedRowProps {\n const resolve = rowProps as ListRowPropsResolver<unknown>;\n const props = slot === null ? NO_ROW_PROPS : resolve(slot.args);\n\n return {\n accessibleLabel: rowText(props.accessibleLabel),\n accessibleDescription: rowText(props.accessibleDescription),\n isActivatable: rowFlag(props.isActivatable),\n isFocusable: rowFlag(props.isFocusable),\n isSelectable: rowFlag(props.isSelectable),\n };\n}\n\nfunction setRowText(host: Gtk.ColumnViewRow, name: string, value: string | null): void {\n setProperty(host, name, ROW_TEXT_DESCRIPTOR, value);\n}\n\nfunction applyRowProps(\n host: Gtk.ColumnViewRow,\n props: ResolvedRowProps,\n previous: ResolvedRowProps | null,\n): void {\n if (previous?.accessibleLabel !== props.accessibleLabel) {\n setRowText(host, \"accessible-label\", props.accessibleLabel);\n }\n\n if (previous?.accessibleDescription !== props.accessibleDescription) {\n setRowText(host, \"accessible-description\", props.accessibleDescription);\n }\n\n if (previous?.isActivatable !== props.isActivatable) {\n host.setActivatable(props.isActivatable);\n }\n\n if (previous?.isFocusable !== props.isFocusable) {\n host.setFocusable(props.isFocusable);\n }\n\n if (previous?.isSelectable !== props.isSelectable) {\n host.setSelectable(props.isSelectable);\n }\n}\n\nfunction ItemCellImpl({\n entry,\n render,\n state,\n hasExpander,\n expanderDescriptions,\n ...identity\n}: ItemCellProps): ReactNode {\n const slot = useItemSlot(entry, state, identity);\n useRememberIdentity(entry, slot);\n const body = itemBody(slot, render, hasExpander, expanderDescriptions);\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction ItemRowImpl({ entry, rowProps, state, ...identity }: ItemRowProps): ReactNode {\n const slot = useItemSlot(entry, state, identity);\n useRememberIdentity(entry, slot);\n const props = rowPropsFor(slot, rowProps);\n const previous = useRef<ResolvedRowProps | null>(null);\n\n useLayoutEffect(() => {\n applyRowProps(entry.host, props, previous.current);\n previous.current = props;\n }, [entry.host, props]);\n\n return null;\n}\n\nfunction HeaderCellImpl({ entry, render, collection }: HeaderCellProps): ReactNode {\n const item = useProperty(entry.host, \"item\") ?? null;\n const ref = slotRefFor(item);\n const renderHeader = render as ListSectionRenderer<unknown>;\n const body = ref === null ? null : renderHeader({ section: collection.sectionFor(ref.store.level.path) });\n\n return createPortal(body, entry.host, entry.key);\n}\n\nfunction usePortalEntries<H extends FactoryHost>(registry: CellRegistry<H>): CellEntry<H>[] {\n return useSyncExternalStore(registry.subscribe, registry.getEntries);\n}\n\nconst ItemPortals = ({\n registry,\n render,\n collection,\n hasExpander,\n expandedIds,\n expanderDescriptions,\n}: ItemPortalsProps): ReactNode => {\n const entries = usePortalEntries(registry);\n const state = useCollectionState(collection, expandedIds);\n\n return entries.map((entry) => (\n <ItemCell\n key={entry.key}\n entry={entry}\n render={render}\n state={state}\n hasExpander={hasExpander ?? true}\n expanderDescriptions={expanderDescriptions}\n {...itemIdentity(entry, collection, expandedIds)}\n />\n ));\n};\n\nconst RowPortals = ({ registry, rowProps, collection, expandedIds }: RowPortalsProps): ReactNode => {\n const entries = usePortalEntries(registry);\n const state = useCollectionState(collection, expandedIds);\n\n return entries.map((entry) => (\n <ItemRow\n key={entry.key}\n entry={entry}\n rowProps={rowProps}\n state={state}\n {...itemIdentity(entry, collection, expandedIds)}\n />\n ));\n};\n\nconst HeaderPortals = ({ registry, render, collection }: HeaderPortalsProps): ReactNode =>\n usePortalEntries(registry).map((entry) => (\n <HeaderCell key={entry.key} entry={entry} render={render} collection={collection} />\n ));\n\nconst useSectionHeader = (\n render: ListSectionRenderer<never> | null | undefined,\n collection: Collection,\n size: CellSize,\n): SectionHeaderSlot => {\n const registry = useHeaderCells(size);\n\n if (render == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { headerFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: <HeaderPortals registry={registry} render={render} collection={collection} />,\n };\n};\n\nconst useRowProps = (\n rowProps: ListRowPropsResolver<never> | null | undefined,\n collection: Collection,\n expandedIds: string[] | null | undefined,\n): RowSlot => {\n const registry = useCellRegistry(ROW_OPTIONS, NO_SIZE);\n\n if (rowProps == null) {\n return { factoryProps: {}, portals: null };\n }\n\n return {\n factoryProps: { rowFactory: <GtkSignalListItemFactory {...registry.handlers} /> },\n portals: (\n <RowPortals registry={registry} rowProps={rowProps} collection={collection} expandedIds={expandedIds} />\n ),\n };\n};\n\nexport {\n useItemCells,\n useRowProps,\n useSectionHeader,\n ItemPortals,\n type CellSize,\n};\n"]}
@@ -5,7 +5,7 @@ import type { CollectionIndex, Level } from "./collection-index.js";
5
5
  import type { TreeExpansion } from "./tree-expansion.js";
6
6
  type LevelStore = Gio.ListModel & LazyLevelStore;
7
7
  type SlotRef = {
8
- store: LevelStore;
8
+ store: LazyLevelStore;
9
9
  slot: number;
10
10
  };
11
11
  type CollectionModel = {
@@ -15,14 +15,14 @@ type CollectionModel = {
15
15
  sync: (index: CollectionIndex) => void;
16
16
  };
17
17
  declare function slotRefFor(value: GObject.Object | null): SlotRef | null;
18
- declare function slotPathAt(store: LevelStore, slot: number): string;
18
+ declare function slotPathAt(store: LazyLevelStore, slot: number): string;
19
19
  declare function createCollectionModel(): CollectionModel;
20
20
  declare class LazyLevelStore extends GObject.Object implements Gio.ListModelImpl {
21
21
  itemsChanged: Gio.ListModel["itemsChanged"];
22
22
  level: Level;
23
- refs: SlotRef[];
24
- objects: (Gtk.StringObject | null)[];
25
- childStores: (LevelStore | null)[];
23
+ refs: Map<number, SlotRef>;
24
+ objects: Map<number, Gtk.StringObject>;
25
+ childStores: Map<number, LevelStore>;
26
26
  private createItem;
27
27
  vfuncGetItemType(): bigint;
28
28
  vfuncGetNItems(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"collection-model.d.ts","sourceRoot":"","sources":["../../src/internal/collection-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD,KAAK,UAAU,GAAG,GAAG,CAAC,SAAS,GAAG,cAAc,CAAC;AAEjD,KAAK,OAAO,GAAG;IACX,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AA4BF,KAAK,eAAe,GAAG;IACnB,KAAK,EAAE,GAAG,CAAC,gBAAgB,CAAC;IAC5B,SAAS,EAAE,aAAa,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;IACpD,IAAI,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CAC1C,CAAC;AAmCF,iBAAS,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAUhE;AAED,iBAAS,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAuSD,iBAAS,qBAAqB,IAAI,eAAe,CAuBhD;AAED,cAAM,cAAe,SAAQ,OAAO,CAAC,MAAO,YA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