@gtkx/components 1.2.0 → 1.2.2

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;AAgKrG;;;;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;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"}
@@ -26,6 +26,7 @@ const COLUMN_VIEW_PROPS = [
26
26
  "children",
27
27
  "ref",
28
28
  ];
29
+ const expanderIndexFor = (columns) => columns.findIndex((column) => column.visible !== false);
29
30
  const columnById = (view, id) => {
30
31
  const columns = view.getColumns();
31
32
  for (let index = 0; index < columns.getNItems(); index++) {
@@ -80,12 +81,15 @@ const useColumnSorting = (view, sort, columns) => {
80
81
  syncSort(sorting, view, sortColumn, sortOrder);
81
82
  }, [view, sortColumn, sortOrder, columns]);
82
83
  };
83
- const ColumnCells = ({ column, collection, expandedIds, expanderDescriptions, size }) => {
84
+ const ColumnCells = ({ column, hasExpander, collection, expandedIds, expanderDescriptions, size, }) => {
84
85
  const cells = useItemCells(size);
85
86
  const rest = omit(column, ["id", "renderCell", "isSortable"]);
86
- return (_jsxs(_Fragment, { children: [_jsx(GtkColumnViewColumn, { id: column.id, factory: _jsx(GtkSignalListItemFactory, { ...cells.handlers }), sorter: column.isSortable === true ? _jsx(GtkCustomSorter, {}) : null, ...rest }), _jsx(ItemPortals, { registry: cells, render: column.renderCell, collection: collection, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions })] }));
87
+ return (_jsxs(_Fragment, { children: [_jsx(GtkColumnViewColumn, { id: column.id, factory: _jsx(GtkSignalListItemFactory, { ...cells.handlers }), sorter: column.isSortable === true ? _jsx(GtkCustomSorter, {}) : null, ...rest }), _jsx(ItemPortals, { registry: cells, render: column.renderCell, collection: collection, hasExpander: hasExpander, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions })] }));
88
+ };
89
+ const ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }) => {
90
+ const expanderIndex = expanderIndexFor(columns);
91
+ return columns.map((column, index) => (_jsx(ColumnCells, { column: column, hasExpander: index === expanderIndex, collection: collection, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions, size: size }, column.id)));
87
92
  };
88
- const ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }) => columns.map((column) => (_jsx(ColumnCells, { column: column, collection: collection, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions, size: size }, column.id)));
89
93
  /**
90
94
  * Renders a Gtk.ColumnView from declarative items or sections and a columns array,
91
95
  * with controlled selection, expansion, and sorting, per-column header menus,
@@ -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,wBAAwB,EAAE,MAAM,eAAe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AC,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 collection: Collection;\n expandedIds: string[] | null | undefined;\n expanderDescriptions: ExpanderDescriptions | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\"> & {\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 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 = ({ column, collection, expandedIds, expanderDescriptions, size }: 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 expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }: ColumnListProps): ReactNode =>\n columns.map((column) => (\n <ColumnCells\n key={column.id}\n column={column}\n collection={collection}\n expandedIds={expandedIds}\n expanderDescriptions={expanderDescriptions}\n size={size}\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,MAAM,eAAe,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiB5D,MAAM,iBAAiB,GAAG;IACtB,OAAO;IACP,UAAU;IACV,cAAc;IACd,UAAU;IACV,SAAS;IACT,aAAa;IACb,oBAAoB;IACpB,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,sBAAsB;IACtB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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"]}
@@ -35,6 +35,7 @@ type ItemPortalsProps = {
35
35
  registry: CellRegistry<Gtk.ListItem>;
36
36
  render: ListItemRenderer<never>;
37
37
  collection: Collection;
38
+ hasExpander?: boolean | undefined;
38
39
  expandedIds?: string[] | null | undefined;
39
40
  expanderDescriptions?: ExpanderDescriptions | null | undefined;
40
41
  };
@@ -51,7 +52,7 @@ type RowSlot = {
51
52
  portals: ReactNode;
52
53
  };
53
54
  declare function useItemCells(size: CellSize): CellRegistry<Gtk.ListItem>;
54
- declare const ItemPortals: ({ registry, render, collection, expandedIds, expanderDescriptions, }: ItemPortalsProps) => ReactNode;
55
+ declare const ItemPortals: ({ registry, render, collection, hasExpander, expandedIds, expanderDescriptions, }: ItemPortalsProps) => ReactNode;
55
56
  declare const useSectionHeader: (render: ListSectionRenderer<never> | null | undefined, collection: Collection, size: CellSize) => SectionHeaderSlot;
56
57
  declare const useRowProps: (rowProps: ListRowPropsResolver<never> | null | undefined, collection: Collection, expandedIds: string[] | null | undefined) => RowSlot;
57
58
  export { useItemCells, useRowProps, useSectionHeader, ItemPortals, type CellSize, };
@@ -1 +1 @@
1
- {"version":3,"file":"cells.d.ts","sourceRoot":"","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AE,YAAY,CAAA;KAAE,CAAC;IAC5C,OAAO,EAAE,SAAS,CAAC;CACtB,CAAC;AA0KF,iBAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAEhE;AAoLD,QAAA,MAAM,WAAW,GAAI,mFAOlB,gBAAgB,KAAG,SAWhB,CAAC;AAkBP,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"}
@@ -190,12 +190,13 @@ function wrapExpander(slot, content, descriptions) {
190
190
  : (_jsx(GtkTreeExpander, { listRow: row, hideExpander: item.shouldHideExpander ?? false, indentForDepth: item.shouldIndentForDepth ?? true, indentForIcon: item.shouldIndentForIcon ?? true, accessibleDescription: expanderDescriptionFor(slot, descriptions), children: content }));
191
191
  return expander;
192
192
  }
193
- function itemBody(slot, render, descriptions) {
193
+ function itemBody(slot, render, hasExpander, descriptions) {
194
194
  if (slot === null) {
195
195
  return null;
196
196
  }
197
197
  const renderItem = render;
198
- return wrapExpander(slot, renderItem(slot.args), descriptions);
198
+ const content = renderItem(slot.args);
199
+ return hasExpander ? wrapExpander(slot, content, descriptions) : content;
199
200
  }
200
201
  function rowText(value) {
201
202
  return value ?? null;
@@ -225,9 +226,9 @@ function applyRowProps(host, props) {
225
226
  host.setFocusable(props.isFocusable);
226
227
  host.setSelectable(props.isSelectable);
227
228
  }
228
- function ItemCellImpl({ entry, render, collection, expandedIds, expanderDescriptions }) {
229
+ function ItemCellImpl({ entry, render, collection, hasExpander, expandedIds, expanderDescriptions, }) {
229
230
  const slot = useItemSlot(entry, collection, expandedIds);
230
- const body = itemBody(slot, render, expanderDescriptions);
231
+ const body = itemBody(slot, render, hasExpander, expanderDescriptions);
231
232
  return createPortal(body, entry.host, entry.key);
232
233
  }
233
234
  function ItemRowImpl({ entry, rowProps, collection, expandedIds }) {
@@ -249,7 +250,7 @@ function usePortalEntries(registry) {
249
250
  useSyncExternalStore(registry.subscribe, registry.getVersion);
250
251
  return registry.getEntries();
251
252
  }
252
- const ItemPortals = ({ registry, render, collection, expandedIds, expanderDescriptions, }) => usePortalEntries(registry).map((entry) => (_jsx(ItemCell, { entry: entry, render: render, collection: collection, expandedIds: expandedIds, expanderDescriptions: expanderDescriptions }, entry.key)));
253
+ 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)));
253
254
  const RowPortals = ({ registry, rowProps, collection, expandedIds }) => usePortalEntries(registry).map((entry) => (_jsx(ItemRow, { entry: entry, rowProps: rowProps, collection: collection, expandedIds: expandedIds }, entry.key)));
254
255
  const HeaderPortals = ({ registry, render, collection }) => usePortalEntries(registry).map((entry) => (_jsx(HeaderCell, { entry: entry, render: render, collection: collection }, entry.key)));
255
256
  const useSectionHeader = (render, collection, 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,iBAAiB,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E,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 { setObjectProperty, 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 item: GObject.Object | null;\n listeners: Set<() => void>;\n subscribe: (onChange: () => void) => () => void;\n getItem: () => GObject.Object | null;\n};\n\ntype FactoryHandlers = {\n onSetup: (host: GObject.Object) => void;\n onBind: (host: GObject.Object) => void;\n onUnbind: (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 getVersion: () => number;\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 version: 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 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 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 notifyEntry<H extends FactoryHost>(entry: CellEntry<H>): void {\n for (const listener of entry.listeners) {\n listener();\n }\n}\n\nfunction notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): void {\n state.snapshot = null;\n state.version += 1;\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 const entry: CellEntry<H> = {\n key: `gtkx-cell-${String(state.serial)}`,\n host,\n item: null,\n listeners: new Set(),\n subscribe: (onChange) => {\n entry.listeners.add(onChange);\n\n return () => {\n entry.listeners.delete(onChange);\n };\n },\n getItem: () => entry.item,\n };\n\n return entry;\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 writeBinding<H extends FactoryHost>(state: CellRegistryState<H>, host: H, item: GObject.Object | null): void {\n const entry = state.entries.get(host);\n\n if (entry === undefined) {\n return;\n }\n\n entry.item = item;\n notifyEntry(entry);\n}\n\nfunction bindHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n writeBinding(state, host, host.getItem());\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 onUnbind: guarded(isHost, (host) => {\n writeBinding(state, host, null);\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 version: 0,\n };\n\n return {\n handlers: createHandlers(state),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRegistry(state, onChange),\n getVersion: () => state.version,\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 = useSyncExternalStore(entry.subscribe, entry.getItem);\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 descriptions: ExpanderDescriptions | null | undefined,\n): ReactNode {\n if (slot === null) {\n return null;\n }\n\n const renderItem = render as ListItemRenderer<unknown>;\n\n return wrapExpander(slot, renderItem(slot.args), descriptions);\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 setObjectProperty(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({ entry, render, collection, expandedIds, expanderDescriptions }: ItemCellProps): ReactNode {\n const slot = useItemSlot(entry, collection, expandedIds);\n const body = itemBody(slot, render, 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 = useSyncExternalStore(entry.subscribe, entry.getItem);\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 useSyncExternalStore(registry.subscribe, registry.getVersion);\n\n return registry.getEntries();\n}\n\nconst ItemPortals = ({\n registry,\n render,\n collection,\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 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,iBAAiB,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAW9E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAsInD,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,MAAM,WAAW,GAAG,CAAC,IAAc,EAAc,EAAE,CAC/C,IAAI,GAAG,CAAC,GAAG,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,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 { setObjectProperty, 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 item: GObject.Object | null;\n listeners: Set<() => void>;\n subscribe: (onChange: () => void) => () => void;\n getItem: () => GObject.Object | null;\n};\n\ntype FactoryHandlers = {\n onSetup: (host: GObject.Object) => void;\n onBind: (host: GObject.Object) => void;\n onUnbind: (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 getVersion: () => number;\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 version: 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 notifyEntry<H extends FactoryHost>(entry: CellEntry<H>): void {\n for (const listener of entry.listeners) {\n listener();\n }\n}\n\nfunction notifyRegistry<H extends FactoryHost>(state: CellRegistryState<H>): void {\n state.snapshot = null;\n state.version += 1;\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 const entry: CellEntry<H> = {\n key: `gtkx-cell-${String(state.serial)}`,\n host,\n item: null,\n listeners: new Set(),\n subscribe: (onChange) => {\n entry.listeners.add(onChange);\n\n return () => {\n entry.listeners.delete(onChange);\n };\n },\n getItem: () => entry.item,\n };\n\n return entry;\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 writeBinding<H extends FactoryHost>(state: CellRegistryState<H>, host: H, item: GObject.Object | null): void {\n const entry = state.entries.get(host);\n\n if (entry === undefined) {\n return;\n }\n\n entry.item = item;\n notifyEntry(entry);\n}\n\nfunction bindHost<H extends FactoryHost>(state: CellRegistryState<H>, host: H): void {\n state.prepare?.(host, state.size);\n writeBinding(state, host, host.getItem());\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 onUnbind: guarded(isHost, (host) => {\n writeBinding(state, host, null);\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 version: 0,\n };\n\n return {\n handlers: createHandlers(state),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRegistry(state, onChange),\n getVersion: () => state.version,\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 = useSyncExternalStore(entry.subscribe, entry.getItem);\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 setObjectProperty(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 = useSyncExternalStore(entry.subscribe, entry.getItem);\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 useSyncExternalStore(registry.subscribe, registry.getVersion);\n\n return 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 +1 @@
1
- {"version":3,"file":"controlled-sync.d.ts","sourceRoot":"","sources":["../../src/internal/controlled-sync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,aAAa,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAEjD,KAAK,qBAAqB,GAAG;IACzB,GAAG,EAAE,aAAa,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,iBAAS,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,IAAI,CAmBrE;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"controlled-sync.d.ts","sourceRoot":"","sources":["../../src/internal/controlled-sync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,aAAa,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAEjD,KAAK,qBAAqB,GAAG;IACzB,GAAG,EAAE,aAAa,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,iBAAS,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,IAAI,CAiBrE;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,4 +1,5 @@
1
- import { startTransition, useEffectEvent, useLayoutEffect, useState } from "react";
1
+ import { useLatestRef } from "@gtkx/react/internal";
2
+ import { startTransition, useLayoutEffect, useState } from "react";
2
3
  function useControlledSync(options) {
3
4
  const { ids, collection, widget } = options;
4
5
  const [drift, setDrift] = useState(0);
@@ -7,12 +8,10 @@ function useControlledSync(options) {
7
8
  setDrift((count) => count + 1);
8
9
  });
9
10
  };
10
- const apply = useEffectEvent((next) => {
11
- options.apply(next);
12
- });
11
+ const applyRef = useLatestRef(options.apply);
13
12
  useLayoutEffect(() => {
14
- apply(ids);
15
- }, [widget, collection, ids, drift]);
13
+ applyRef.current(ids);
14
+ }, [applyRef, widget, collection, ids, drift]);
16
15
  return markDrift;
17
16
  }
18
17
  export { useControlledSync };
@@ -1 +1 @@
1
- {"version":3,"file":"controlled-sync.js","sourceRoot":"","sources":["../../src/internal/controlled-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAYnF,SAAS,iBAAiB,CAAC,OAA8B;IACrD,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,MAAM,SAAS,GAAG,GAAS,EAAE;QACzB,eAAe,CAAC,GAAG,EAAE;YACjB,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,IAAmB,EAAQ,EAAE;QACvD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,eAAe,CAAC,GAAG,EAAE;QACjB,KAAK,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAErC,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { startTransition, useEffectEvent, useLayoutEffect, useState } from \"react\";\nimport type { Collection } from \"./collection.js\";\n\ntype ControlledIds = string[] | null | undefined;\n\ntype ControlledSyncOptions = {\n ids: ControlledIds;\n collection: Collection;\n widget?: object | null | undefined;\n apply: (ids: ControlledIds) => void;\n};\n\nfunction useControlledSync(options: ControlledSyncOptions): () => void {\n const { ids, collection, widget } = options;\n const [drift, setDrift] = useState(0);\n\n const markDrift = (): void => {\n startTransition(() => {\n setDrift((count) => count + 1);\n });\n };\n\n const apply = useEffectEvent((next: ControlledIds): void => {\n options.apply(next);\n });\n\n useLayoutEffect(() => {\n apply(ids);\n }, [widget, collection, ids, drift]);\n\n return markDrift;\n}\n\nexport { useControlledSync };\n"]}
1
+ {"version":3,"file":"controlled-sync.js","sourceRoot":"","sources":["../../src/internal/controlled-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAYnE,SAAS,iBAAiB,CAAC,OAA8B;IACrD,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,MAAM,SAAS,GAAG,GAAS,EAAE;QACzB,eAAe,CAAC,GAAG,EAAE;YACjB,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE7C,eAAe,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAE/C,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { useLatestRef } from \"@gtkx/react/internal\";\nimport { startTransition, useLayoutEffect, useState } from \"react\";\nimport type { Collection } from \"./collection.js\";\n\ntype ControlledIds = string[] | null | undefined;\n\ntype ControlledSyncOptions = {\n ids: ControlledIds;\n collection: Collection;\n widget?: object | null | undefined;\n apply: (ids: ControlledIds) => void;\n};\n\nfunction useControlledSync(options: ControlledSyncOptions): () => void {\n const { ids, collection, widget } = options;\n const [drift, setDrift] = useState(0);\n\n const markDrift = (): void => {\n startTransition(() => {\n setDrift((count) => count + 1);\n });\n };\n\n const applyRef = useLatestRef(options.apply);\n\n useLayoutEffect(() => {\n applyRef.current(ids);\n }, [applyRef, widget, collection, ids, drift]);\n\n return markDrift;\n}\n\nexport { useControlledSync };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../../src/internal/drop-down.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAIzD,OAAO,KAAK,EAAE,gBAAgB,EAAwC,MAAM,aAAa,CAAC;AAM1F,KAAK,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzF,KAAK,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG;IAC1D,gBAAgB,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/F,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;CAClD,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA8J5B,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG;IAAE,SAAS,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CA8BtF;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../../src/internal/drop-down.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAKzD,OAAO,KAAK,EAAE,gBAAgB,EAAwC,MAAM,aAAa,CAAC;AAM1F,KAAK,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzF,KAAK,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG;IAC1D,gBAAgB,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/F,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;CAClD,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAgK5B,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG;IAAE,SAAS,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CA8BtF;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { GtkLabel, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
3
+ import { useLatestRef } from "@gtkx/react/internal";
3
4
  import { omit } from "@gtkx/utils";
4
- import { useEffectEvent, useLayoutEffect, useRef, useState } from "react";
5
+ import { useLayoutEffect, useRef, useState } from "react";
5
6
  import { ItemPortals, useItemCells, useSectionHeader } from "./cells.js";
6
7
  import { useCollectionData } from "./use-collection.js";
7
8
  import { useWidgetRef } from "./use-widget-ref.js";
@@ -84,7 +85,7 @@ const useDropDownSelection = (options) => {
84
85
  const { selectedId } = options.props;
85
86
  const known = useRef(null);
86
87
  const [applyState] = useState(newApplyState);
87
- const syncKnownSelection = useEffectEvent((position) => {
88
+ const syncKnownSelection = (position) => {
88
89
  const effectiveId = collection.idAt(position);
89
90
  if (effectiveId === null) {
90
91
  known.current = null;
@@ -92,15 +93,16 @@ const useDropDownSelection = (options) => {
92
93
  }
93
94
  const { onSelectionChanged } = options.props;
94
95
  updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);
95
- });
96
+ };
97
+ const syncRef = useLatestRef(syncKnownSelection);
96
98
  useLayoutEffect(() => {
97
99
  if (widget === null) {
98
100
  return;
99
101
  }
100
102
  const position = resolvePosition(widget, collection, selectedId);
101
103
  applySelectedPosition(widget, position, applyState);
102
- syncKnownSelection(position);
103
- }, [widget, collection, selectedId, applyState]);
104
+ syncRef.current(position);
105
+ }, [syncRef, widget, collection, selectedId, applyState]);
104
106
  return (value, self) => {
105
107
  dispatchSelectedNotify({ options, known, state: applyState }, value, self);
106
108
  };
@@ -1 +1 @@
1
- {"version":3,"file":"drop-down.js","sourceRoot":"","sources":["../../src/internal/drop-down.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AA6BnD,MAAM,eAAe,GAAa;IAC9B,WAAW;IACX,OAAO;IACP,UAAU;IACV,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,KAAK;CACR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,CAAC,CAAC,EAAE,CAAC,CAAC;IACrF,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAEjF,OAAO,CACH,8BACI,KAAC,SAAS,IACN,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,UAAU,CAAC,KAAK,EACvB,OAAO,EAAE,KAAC,wBAAwB,OAAK,SAAS,CAAC,QAAQ,GAAI,KACzD,CAAC,cAAc,IAAI,IAAI,IAAI;oBAC3B,WAAW,EAAE,KAAC,wBAAwB,OAAK,SAAS,CAAC,QAAQ,GAAI;iBACpE,CAAC,KACE,MAAM,CAAC,YAAY,KACnB,IAAI,EACR,gBAAgB,EAAE,oBAAoB,GACxC,EACF,KAAC,WAAW,IAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,EACxF,cAAc,IAAI,IAAI,IAAI,CACvB,KAAC,WAAW,IAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAI,CACvF,EACA,MAAM,CAAC,OAAO,IAChB,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,YAAY,EAA0B,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ElementType, ReactNode, Ref } from \"react\";\nimport { GtkLabel, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { omit } from \"@gtkx/utils\";\nimport { useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type { DropDownOwnProps, ListItemRenderArgs, ListItemRenderer } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { ItemPortals, useItemCells, useSectionHeader } from \"./cells.js\";\nimport { useCollectionData } from \"./use-collection.js\";\nimport { useWidgetRef } from \"./use-widget-ref.js\";\n\ntype SelectableWidget = GObject.Object & { getSelected: () => number; selected: number };\n\ntype DropDownBaseProps = DropDownOwnProps<unknown, unknown> & {\n onNotifySelected?: ((value: number | null, self: SelectableWidget) => void) | null | undefined;\n ref?: Ref<SelectableWidget | null> | undefined;\n} & Record<string, unknown>;\n\ntype SelectionOptions = {\n widget: SelectableWidget | null;\n collection: Collection;\n props: DropDownBaseProps;\n};\n\ntype NotifySelectedHandler = NonNullable<DropDownBaseProps[\"onNotifySelected\"]>;\ntype ApplyState = { isApplying: boolean };\n\ntype NotifyContext = {\n options: SelectionOptions;\n known: { current: string | null };\n state: ApplyState;\n};\n\ntype KnownSelection = {\n known: { current: string | null };\n onSelectionChanged: ((id: string) => void) | null | undefined;\n};\n\nconst DROP_DOWN_PROPS: string[] = [\n \"component\",\n \"items\",\n \"sections\",\n \"selectedId\",\n \"onSelectionChanged\",\n \"onNotifySelected\",\n \"renderItem\",\n \"renderListItem\",\n \"renderHeader\",\n \"ref\",\n];\n\nfunction newApplyState(): ApplyState {\n return { isApplying: false };\n}\n\nconst describeValue = (value: unknown): string => {\n if (typeof value === \"string\") {\n return value;\n }\n\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst defaultItemContent = (value: unknown): ReactNode =>\n value == null ? null : <GtkLabel>{describeValue(value)}</GtkLabel>;\n\nconst defaultRenderItem = ({ item }: ListItemRenderArgs<unknown>): ReactNode => defaultItemContent(item);\nconst faceRenderer = (props: DropDownBaseProps): ListItemRenderer<never> => props.renderItem ?? defaultRenderItem;\n\nconst resolvePosition = (\n widget: SelectableWidget,\n collection: Collection,\n selectedId: string | null | undefined,\n): number => {\n const requested = selectedId == null ? -1 : collection.positionFor(selectedId);\n\n return requested >= 0 ? requested : widget.getSelected();\n};\n\nconst updateKnownSelection = (\n tracker: KnownSelection,\n effectiveId: string,\n selectedId: string | null | undefined,\n): void => {\n const { known, onSelectionChanged } = tracker;\n const expectedId = selectedId ?? known.current;\n const isNew = effectiveId !== known.current;\n known.current = effectiveId;\n\n if (expectedId !== null && effectiveId !== expectedId && isNew) {\n onSelectionChanged?.(effectiveId);\n }\n};\n\nconst reportKnownSelection = (tracker: KnownSelection, id: string | null): void => {\n const { known, onSelectionChanged } = tracker;\n\n if (id === null || id === known.current) {\n return;\n }\n\n known.current = id;\n onSelectionChanged?.(id);\n};\n\nconst reportSelectedNotify = (options: SelectionOptions, tracker: KnownSelection): void => {\n const { widget, collection } = options;\n\n if (widget === null) {\n return;\n }\n\n reportKnownSelection(tracker, collection.idAt(widget.getSelected()));\n};\n\nconst applySelectedPosition = (widget: SelectableWidget, position: number, state: ApplyState): void => {\n state.isApplying = true;\n\n try {\n widget.selected = position;\n } finally {\n state.isApplying = false;\n }\n};\n\nconst dispatchSelectedNotify = (context: NotifyContext, value: number | null, self: SelectableWidget): void => {\n const { options, known, state } = context;\n\n if (state.isApplying) {\n return;\n }\n\n reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged });\n options.props.onNotifySelected?.(value, self);\n};\n\nconst useDropDownSelection = (options: SelectionOptions): NotifySelectedHandler => {\n const { widget, collection } = options;\n const { selectedId } = options.props;\n const known = useRef<string | null>(null);\n const [applyState] = useState<ApplyState>(newApplyState);\n\n const syncKnownSelection = useEffectEvent((position: number): void => {\n const effectiveId = collection.idAt(position);\n\n if (effectiveId === null) {\n known.current = null;\n\n return;\n }\n\n const { onSelectionChanged } = options.props;\n updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);\n });\n\n useLayoutEffect(() => {\n if (widget === null) {\n return;\n }\n\n const position = resolvePosition(widget, collection, selectedId);\n applySelectedPosition(widget, position, applyState);\n syncKnownSelection(position);\n }, [widget, collection, selectedId, applyState]);\n\n return (value, self) => {\n dispatchSelectedNotify({ options, known, state: applyState }, value, self);\n };\n};\n\nfunction DropDownBase(props: DropDownBaseProps & { component: ElementType }): ReactNode {\n const { component: Component, items, sections, renderListItem, renderHeader, ref } = props;\n const rest = omit(props, DROP_DOWN_PROPS);\n const [widget, refCallback] = useWidgetRef<SelectableWidget>(ref);\n const collection = useCollectionData({ items, sections, isFlat: true });\n const faceCells = useItemCells({ width: -1, height: -1 });\n const listCells = useItemCells({ width: -1, height: -1 });\n const header = useSectionHeader(renderHeader, collection, { width: -1, height: -1 });\n const handleNotifySelected = useDropDownSelection({ widget, collection, props });\n\n return (\n <>\n <Component\n ref={refCallback}\n model={collection.model}\n factory={<GtkSignalListItemFactory {...faceCells.handlers} />}\n {...(renderListItem != null && {\n listFactory: <GtkSignalListItemFactory {...listCells.handlers} />,\n })}\n {...header.factoryProps}\n {...rest}\n onNotifySelected={handleNotifySelected}\n />\n <ItemPortals registry={faceCells} render={faceRenderer(props)} collection={collection} />\n {renderListItem != null && (\n <ItemPortals registry={listCells} render={renderListItem} collection={collection} />\n )}\n {header.portals}\n </>\n );\n}\n\nexport { DropDownBase, type DropDownBaseProps };\n"]}
1
+ {"version":3,"file":"drop-down.js","sourceRoot":"","sources":["../../src/internal/drop-down.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AA6BnD,MAAM,eAAe,GAAa;IAC9B,WAAW;IACX,OAAO;IACP,UAAU;IACV,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,KAAK;CACR,CAAC;AAEF,SAAS,aAAa;IAClB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AA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CAAC;IACrF,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAEjF,OAAO,CACH,8BACI,KAAC,SAAS,IACN,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,UAAU,CAAC,KAAK,EACvB,OAAO,EAAE,KAAC,wBAAwB,OAAK,SAAS,CAAC,QAAQ,GAAI,KACzD,CAAC,cAAc,IAAI,IAAI,IAAI;oBAC3B,WAAW,EAAE,KAAC,wBAAwB,OAAK,SAAS,CAAC,QAAQ,GAAI;iBACpE,CAAC,KACE,MAAM,CAAC,YAAY,KACnB,IAAI,EACR,gBAAgB,EAAE,oBAAoB,GACxC,EACF,KAAC,WAAW,IAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,EACxF,cAAc,IAAI,IAAI,IAAI,CACvB,KAAC,WAAW,IAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAI,CACvF,EACA,MAAM,CAAC,OAAO,IAChB,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,YAAY,EAA0B,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ElementType, ReactNode, Ref } from \"react\";\nimport { GtkLabel, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useLatestRef } from \"@gtkx/react/internal\";\nimport { omit } from \"@gtkx/utils\";\nimport { useLayoutEffect, useRef, useState } from \"react\";\nimport type { DropDownOwnProps, ListItemRenderArgs, ListItemRenderer } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { ItemPortals, useItemCells, useSectionHeader } from \"./cells.js\";\nimport { useCollectionData } from \"./use-collection.js\";\nimport { useWidgetRef } from \"./use-widget-ref.js\";\n\ntype SelectableWidget = GObject.Object & { getSelected: () => number; selected: number };\n\ntype DropDownBaseProps = DropDownOwnProps<unknown, unknown> & {\n onNotifySelected?: ((value: number | null, self: SelectableWidget) => void) | null | undefined;\n ref?: Ref<SelectableWidget | null> | undefined;\n} & Record<string, unknown>;\n\ntype SelectionOptions = {\n widget: SelectableWidget | null;\n collection: Collection;\n props: DropDownBaseProps;\n};\n\ntype NotifySelectedHandler = NonNullable<DropDownBaseProps[\"onNotifySelected\"]>;\ntype ApplyState = { isApplying: boolean };\n\ntype NotifyContext = {\n options: SelectionOptions;\n known: { current: string | null };\n state: ApplyState;\n};\n\ntype KnownSelection = {\n known: { current: string | null };\n onSelectionChanged: ((id: string) => void) | null | undefined;\n};\n\nconst DROP_DOWN_PROPS: string[] = [\n \"component\",\n \"items\",\n \"sections\",\n \"selectedId\",\n \"onSelectionChanged\",\n \"onNotifySelected\",\n \"renderItem\",\n \"renderListItem\",\n \"renderHeader\",\n \"ref\",\n];\n\nfunction newApplyState(): ApplyState {\n return { isApplying: false };\n}\n\nconst describeValue = (value: unknown): string => {\n if (typeof value === \"string\") {\n return value;\n }\n\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst defaultItemContent = (value: unknown): ReactNode =>\n value == null ? null : <GtkLabel>{describeValue(value)}</GtkLabel>;\n\nconst defaultRenderItem = ({ item }: ListItemRenderArgs<unknown>): ReactNode => defaultItemContent(item);\nconst faceRenderer = (props: DropDownBaseProps): ListItemRenderer<never> => props.renderItem ?? defaultRenderItem;\n\nconst resolvePosition = (\n widget: SelectableWidget,\n collection: Collection,\n selectedId: string | null | undefined,\n): number => {\n const requested = selectedId == null ? -1 : collection.positionFor(selectedId);\n\n return requested >= 0 ? requested : widget.getSelected();\n};\n\nconst updateKnownSelection = (\n tracker: KnownSelection,\n effectiveId: string,\n selectedId: string | null | undefined,\n): void => {\n const { known, onSelectionChanged } = tracker;\n const expectedId = selectedId ?? known.current;\n const isNew = effectiveId !== known.current;\n known.current = effectiveId;\n\n if (expectedId !== null && effectiveId !== expectedId && isNew) {\n onSelectionChanged?.(effectiveId);\n }\n};\n\nconst reportKnownSelection = (tracker: KnownSelection, id: string | null): void => {\n const { known, onSelectionChanged } = tracker;\n\n if (id === null || id === known.current) {\n return;\n }\n\n known.current = id;\n onSelectionChanged?.(id);\n};\n\nconst reportSelectedNotify = (options: SelectionOptions, tracker: KnownSelection): void => {\n const { widget, collection } = options;\n\n if (widget === null) {\n return;\n }\n\n reportKnownSelection(tracker, collection.idAt(widget.getSelected()));\n};\n\nconst applySelectedPosition = (widget: SelectableWidget, position: number, state: ApplyState): void => {\n state.isApplying = true;\n\n try {\n widget.selected = position;\n } finally {\n state.isApplying = false;\n }\n};\n\nconst dispatchSelectedNotify = (context: NotifyContext, value: number | null, self: SelectableWidget): void => {\n const { options, known, state } = context;\n\n if (state.isApplying) {\n return;\n }\n\n reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged });\n options.props.onNotifySelected?.(value, self);\n};\n\nconst useDropDownSelection = (options: SelectionOptions): NotifySelectedHandler => {\n const { widget, collection } = options;\n const { selectedId } = options.props;\n const known = useRef<string | null>(null);\n const [applyState] = useState<ApplyState>(newApplyState);\n\n const syncKnownSelection = (position: number): void => {\n const effectiveId = collection.idAt(position);\n\n if (effectiveId === null) {\n known.current = null;\n\n return;\n }\n\n const { onSelectionChanged } = options.props;\n updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);\n };\n\n const syncRef = useLatestRef(syncKnownSelection);\n\n useLayoutEffect(() => {\n if (widget === null) {\n return;\n }\n\n const position = resolvePosition(widget, collection, selectedId);\n applySelectedPosition(widget, position, applyState);\n syncRef.current(position);\n }, [syncRef, widget, collection, selectedId, applyState]);\n\n return (value, self) => {\n dispatchSelectedNotify({ options, known, state: applyState }, value, self);\n };\n};\n\nfunction DropDownBase(props: DropDownBaseProps & { component: ElementType }): ReactNode {\n const { component: Component, items, sections, renderListItem, renderHeader, ref } = props;\n const rest = omit(props, DROP_DOWN_PROPS);\n const [widget, refCallback] = useWidgetRef<SelectableWidget>(ref);\n const collection = useCollectionData({ items, sections, isFlat: true });\n const faceCells = useItemCells({ width: -1, height: -1 });\n const listCells = useItemCells({ width: -1, height: -1 });\n const header = useSectionHeader(renderHeader, collection, { width: -1, height: -1 });\n const handleNotifySelected = useDropDownSelection({ widget, collection, props });\n\n return (\n <>\n <Component\n ref={refCallback}\n model={collection.model}\n factory={<GtkSignalListItemFactory {...faceCells.handlers} />}\n {...(renderListItem != null && {\n listFactory: <GtkSignalListItemFactory {...listCells.handlers} />,\n })}\n {...header.factoryProps}\n {...rest}\n onNotifySelected={handleNotifySelected}\n />\n <ItemPortals registry={faceCells} render={faceRenderer(props)} collection={collection} />\n {renderListItem != null && (\n <ItemPortals registry={listCells} render={renderListItem} collection={collection} />\n )}\n {header.portals}\n </>\n );\n}\n\nexport { DropDownBase, type DropDownBaseProps };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/components",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "High-level GTKX components for declarative collection views, menus, and containers with attach-time placement",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -54,18 +54,18 @@
54
54
  "node": ">=24"
55
55
  },
56
56
  "dependencies": {
57
- "@gtkx/react": "1.2.0",
58
- "@gtkx/runtime": "1.2.0",
59
- "@gtkx/utils": "1.2.0"
57
+ "@gtkx/react": "1.2.2",
58
+ "@gtkx/runtime": "1.2.2",
59
+ "@gtkx/utils": "1.2.2"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "react": "^19.2"
63
63
  },
64
64
  "devDependencies": {
65
65
  "vitest": "^4.1.10",
66
- "@gtkx/config": "1.2.0",
67
- "@gtkx/testing": "1.2.0",
68
- "@gtkx/vitest": "1.2.0"
66
+ "@gtkx/config": "1.2.2",
67
+ "@gtkx/testing": "1.2.2",
68
+ "@gtkx/vitest": "1.2.2"
69
69
  },
70
70
  "scripts": {
71
71
  "release": "tsx ../../scripts/release-package.ts"
@@ -15,13 +15,14 @@ type SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };
15
15
 
16
16
  type ColumnCellsProps = {
17
17
  column: ColumnViewColumn<never>;
18
+ hasExpander: boolean;
18
19
  collection: Collection;
19
20
  expandedIds: string[] | null | undefined;
20
21
  expanderDescriptions: ExpanderDescriptions | null | undefined;
21
22
  size: CellSize;
22
23
  };
23
24
 
24
- type ColumnListProps = Omit<ColumnCellsProps, "column"> & {
25
+ type ColumnListProps = Omit<ColumnCellsProps, "column" | "hasExpander"> & {
25
26
  columns: ColumnViewColumn<never>[];
26
27
  };
27
28
 
@@ -45,6 +46,9 @@ const COLUMN_VIEW_PROPS = [
45
46
  "ref",
46
47
  ] as const satisfies (keyof ColumnViewProps)[];
47
48
 
49
+ const expanderIndexFor = (columns: ColumnViewColumn<never>[]): number =>
50
+ columns.findIndex((column) => column.visible !== false);
51
+
48
52
  const columnById = (view: Gtk.ColumnView, id: string): Gtk.ColumnViewColumn | null => {
49
53
  const columns = view.getColumns();
50
54
 
@@ -131,7 +135,14 @@ const useColumnSorting = (view: Gtk.ColumnView | null, sort: SortProps, columns:
131
135
  }, [view, sortColumn, sortOrder, columns]);
132
136
  };
133
137
 
134
- const ColumnCells = ({ column, collection, expandedIds, expanderDescriptions, size }: ColumnCellsProps): ReactNode => {
138
+ const ColumnCells = ({
139
+ column,
140
+ hasExpander,
141
+ collection,
142
+ expandedIds,
143
+ expanderDescriptions,
144
+ size,
145
+ }: ColumnCellsProps): ReactNode => {
135
146
  const cells = useItemCells(size);
136
147
  const rest = omit(column, ["id", "renderCell", "isSortable"]);
137
148
 
@@ -147,6 +158,7 @@ const ColumnCells = ({ column, collection, expandedIds, expanderDescriptions, si
147
158
  registry={cells}
148
159
  render={column.renderCell}
149
160
  collection={collection}
161
+ hasExpander={hasExpander}
150
162
  expandedIds={expandedIds}
151
163
  expanderDescriptions={expanderDescriptions}
152
164
  />
@@ -154,17 +166,21 @@ const ColumnCells = ({ column, collection, expandedIds, expanderDescriptions, si
154
166
  );
155
167
  };
156
168
 
157
- const ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }: ColumnListProps): ReactNode =>
158
- columns.map((column) => (
169
+ const ColumnList = ({ columns, collection, expandedIds, expanderDescriptions, size }: ColumnListProps): ReactNode => {
170
+ const expanderIndex = expanderIndexFor(columns);
171
+
172
+ return columns.map((column, index) => (
159
173
  <ColumnCells
160
174
  key={column.id}
161
175
  column={column}
176
+ hasExpander={index === expanderIndex}
162
177
  collection={collection}
163
178
  expandedIds={expandedIds}
164
179
  expanderDescriptions={expanderDescriptions}
165
180
  size={size}
166
181
  />
167
182
  ));
183
+ };
168
184
 
169
185
  /**
170
186
  * Renders a Gtk.ColumnView from declarative items or sections and a columns array,
@@ -99,6 +99,7 @@ type ItemCellProps = {
99
99
  entry: CellEntry<Gtk.ListItem>;
100
100
  render: ListItemRenderer<never>;
101
101
  collection: Collection;
102
+ hasExpander: boolean;
102
103
  expandedIds: string[] | null | undefined;
103
104
  expanderDescriptions: ExpanderDescriptions | null | undefined;
104
105
  };
@@ -107,6 +108,7 @@ type ItemPortalsProps = {
107
108
  registry: CellRegistry<Gtk.ListItem>;
108
109
  render: ListItemRenderer<never>;
109
110
  collection: Collection;
111
+ hasExpander?: boolean | undefined;
110
112
  expandedIds?: string[] | null | undefined;
111
113
  expanderDescriptions?: ExpanderDescriptions | null | undefined;
112
114
  };
@@ -410,6 +412,7 @@ function wrapExpander(
410
412
  function itemBody(
411
413
  slot: ItemSlot | null,
412
414
  render: ListItemRenderer<never>,
415
+ hasExpander: boolean,
413
416
  descriptions: ExpanderDescriptions | null | undefined,
414
417
  ): ReactNode {
415
418
  if (slot === null) {
@@ -417,8 +420,9 @@ function itemBody(
417
420
  }
418
421
 
419
422
  const renderItem = render as ListItemRenderer<unknown>;
423
+ const content = renderItem(slot.args);
420
424
 
421
- return wrapExpander(slot, renderItem(slot.args), descriptions);
425
+ return hasExpander ? wrapExpander(slot, content, descriptions) : content;
422
426
  }
423
427
 
424
428
  function rowText(value: string | undefined): string | null {
@@ -455,9 +459,16 @@ function applyRowProps(host: Gtk.ColumnViewRow, props: ResolvedRowProps): void {
455
459
  host.setSelectable(props.isSelectable);
456
460
  }
457
461
 
458
- function ItemCellImpl({ entry, render, collection, expandedIds, expanderDescriptions }: ItemCellProps): ReactNode {
462
+ function ItemCellImpl({
463
+ entry,
464
+ render,
465
+ collection,
466
+ hasExpander,
467
+ expandedIds,
468
+ expanderDescriptions,
469
+ }: ItemCellProps): ReactNode {
459
470
  const slot = useItemSlot(entry, collection, expandedIds);
460
- const body = itemBody(slot, render, expanderDescriptions);
471
+ const body = itemBody(slot, render, hasExpander, expanderDescriptions);
461
472
 
462
473
  return createPortal(body, entry.host, entry.key);
463
474
  }
@@ -492,6 +503,7 @@ const ItemPortals = ({
492
503
  registry,
493
504
  render,
494
505
  collection,
506
+ hasExpander,
495
507
  expandedIds,
496
508
  expanderDescriptions,
497
509
  }: ItemPortalsProps): ReactNode =>
@@ -501,6 +513,7 @@ const ItemPortals = ({
501
513
  entry={entry}
502
514
  render={render}
503
515
  collection={collection}
516
+ hasExpander={hasExpander ?? true}
504
517
  expandedIds={expandedIds}
505
518
  expanderDescriptions={expanderDescriptions}
506
519
  />
@@ -1,4 +1,5 @@
1
- import { startTransition, useEffectEvent, useLayoutEffect, useState } from "react";
1
+ import { useLatestRef } from "@gtkx/react/internal";
2
+ import { startTransition, useLayoutEffect, useState } from "react";
2
3
  import type { Collection } from "./collection.js";
3
4
 
4
5
  type ControlledIds = string[] | null | undefined;
@@ -20,13 +21,11 @@ function useControlledSync(options: ControlledSyncOptions): () => void {
20
21
  });
21
22
  };
22
23
 
23
- const apply = useEffectEvent((next: ControlledIds): void => {
24
- options.apply(next);
25
- });
24
+ const applyRef = useLatestRef(options.apply);
26
25
 
27
26
  useLayoutEffect(() => {
28
- apply(ids);
29
- }, [widget, collection, ids, drift]);
27
+ applyRef.current(ids);
28
+ }, [applyRef, widget, collection, ids, drift]);
30
29
 
31
30
  return markDrift;
32
31
  }
@@ -1,8 +1,9 @@
1
1
  import type * as GObject from "@gtkx/gi/gobject";
2
2
  import type { ElementType, ReactNode, Ref } from "react";
3
3
  import { GtkLabel, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
4
+ import { useLatestRef } from "@gtkx/react/internal";
4
5
  import { omit } from "@gtkx/utils";
5
- import { useEffectEvent, useLayoutEffect, useRef, useState } from "react";
6
+ import { useLayoutEffect, useRef, useState } from "react";
6
7
  import type { DropDownOwnProps, ListItemRenderArgs, ListItemRenderer } from "../types.js";
7
8
  import type { Collection } from "./collection.js";
8
9
  import { ItemPortals, useItemCells, useSectionHeader } from "./cells.js";
@@ -144,7 +145,7 @@ const useDropDownSelection = (options: SelectionOptions): NotifySelectedHandler
144
145
  const known = useRef<string | null>(null);
145
146
  const [applyState] = useState<ApplyState>(newApplyState);
146
147
 
147
- const syncKnownSelection = useEffectEvent((position: number): void => {
148
+ const syncKnownSelection = (position: number): void => {
148
149
  const effectiveId = collection.idAt(position);
149
150
 
150
151
  if (effectiveId === null) {
@@ -155,7 +156,9 @@ const useDropDownSelection = (options: SelectionOptions): NotifySelectedHandler
155
156
 
156
157
  const { onSelectionChanged } = options.props;
157
158
  updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);
158
- });
159
+ };
160
+
161
+ const syncRef = useLatestRef(syncKnownSelection);
159
162
 
160
163
  useLayoutEffect(() => {
161
164
  if (widget === null) {
@@ -164,8 +167,8 @@ const useDropDownSelection = (options: SelectionOptions): NotifySelectedHandler
164
167
 
165
168
  const position = resolvePosition(widget, collection, selectedId);
166
169
  applySelectedPosition(widget, position, applyState);
167
- syncKnownSelection(position);
168
- }, [widget, collection, selectedId, applyState]);
170
+ syncRef.current(position);
171
+ }, [syncRef, widget, collection, selectedId, applyState]);
169
172
 
170
173
  return (value, self) => {
171
174
  dispatchSelectedNotify({ options, known, state: applyState }, value, self);