@gtkx/components 1.0.0-rc.2 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adw/combo-row.d.ts +11 -0
- package/dist/adw/combo-row.d.ts.map +1 -0
- package/dist/adw/combo-row.js +14 -0
- package/dist/adw/combo-row.js.map +1 -0
- package/dist/adw/index.d.ts +2 -1
- package/dist/adw/index.d.ts.map +1 -1
- package/dist/adw/index.js +1 -0
- package/dist/adw/index.js.map +1 -1
- package/dist/adw/types.d.ts +9 -2
- package/dist/adw/types.d.ts.map +1 -1
- package/dist/adw/types.js.map +1 -1
- package/dist/column-view.js +2 -2
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +3 -5
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +5 -112
- package/dist/drop-down.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/drop-down.d.ts +16 -0
- package/dist/internal/drop-down.d.ts.map +1 -0
- package/dist/internal/drop-down.js +110 -0
- package/dist/internal/drop-down.js.map +1 -0
- package/dist/internal/expansion.d.ts +1 -1
- package/dist/internal/expansion.d.ts.map +1 -1
- package/dist/internal/expansion.js +3 -4
- package/dist/internal/expansion.js.map +1 -1
- package/dist/internal/selection.d.ts +1 -0
- package/dist/internal/selection.d.ts.map +1 -1
- package/dist/internal/selection.js +1 -0
- package/dist/internal/selection.js.map +1 -1
- package/dist/internal/use-collection.d.ts +1 -2
- package/dist/internal/use-collection.d.ts.map +1 -1
- package/dist/internal/use-collection.js +9 -17
- package/dist/internal/use-collection.js.map +1 -1
- package/dist/types.d.ts +7 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -7
- package/src/adw/combo-row.tsx +20 -0
- package/src/adw/index.ts +8 -1
- package/src/adw/types.ts +15 -2
- package/src/column-view.tsx +2 -2
- package/src/drop-down.tsx +9 -195
- package/src/index.ts +0 -1
- package/src/internal/drop-down.tsx +186 -0
- package/src/internal/expansion.ts +5 -6
- package/src/internal/selection.tsx +3 -0
- package/src/internal/use-collection.tsx +11 -24
- package/src/types.ts +13 -14
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ComboRowProps } from "./types.js";
|
|
3
|
+
type ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;
|
|
4
|
+
/**
|
|
5
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
6
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
7
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
8
|
+
*/
|
|
9
|
+
declare const ComboRow: ComboRowComponent;
|
|
10
|
+
export { ComboRow };
|
|
11
|
+
//# sourceMappingURL=combo-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combo-row.d.ts","sourceRoot":"","sources":["../../src/adw/combo-row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,iBAAiB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;AAE7F;;;;GAIG;AACH,QAAA,MAAM,QAAQ,EAAE,iBAAqD,CAAC;AAMtE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AdwComboRow } from "@gtkx/jsx/adw";
|
|
3
|
+
import { DropDownBase } from "../internal/drop-down.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
6
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
7
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
8
|
+
*/
|
|
9
|
+
const ComboRow = ComboRowImpl;
|
|
10
|
+
function ComboRowImpl(props) {
|
|
11
|
+
return _jsx(DropDownBase, { ...props, component: AdwComboRow });
|
|
12
|
+
}
|
|
13
|
+
export { ComboRow };
|
|
14
|
+
//# sourceMappingURL=combo-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combo-row.js","sourceRoot":"","sources":["../../src/adw/combo-row.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAIxD;;;;GAIG;AACH,MAAM,QAAQ,GAAsB,YAAiC,CAAC;AAEtE,SAAS,YAAY,CAAC,KAAwB;IAC1C,OAAO,KAAC,YAAY,OAAK,KAAK,EAAE,SAAS,EAAE,WAAW,GAAI,CAAC;AAC/D,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { AdwComboRow } from \"@gtkx/jsx/adw\";\nimport type { DropDownBaseProps } from \"../internal/drop-down.js\";\nimport type { ComboRowProps } from \"./types.js\";\nimport { DropDownBase } from \"../internal/drop-down.js\";\n\ntype ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;\n\n/**\n * Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a\n * `DropDown` in the shape of a preferences row, with customizable renderers for the row\n * display, popup rows, and popup section headers, and controlled selection.\n */\nconst ComboRow: ComboRowComponent = ComboRowImpl as ComboRowComponent;\n\nfunction ComboRowImpl(props: DropDownBaseProps): ReactNode {\n return <DropDownBase {...props} component={AdwComboRow} />;\n}\n\nexport { ComboRow };\n"]}
|
package/dist/adw/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ComboRow } from "./combo-row.js";
|
|
1
2
|
export { ToastProvider, useToast, useToastOverlay } from "./toast.js";
|
|
2
|
-
export type { ToastController, ToastOptions, ToastOverlayController, ToastProviderProps } from "./types.js";
|
|
3
|
+
export type { ComboRowProps, ToastController, ToastOptions, ToastOverlayController, ToastProviderProps, } from "./types.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/adw/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtE,YAAY,EACR,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/adw/index.js
CHANGED
package/dist/adw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { ToastProvider, useToast, useToastOverlay } from \"./toast.js\";\nexport type {
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { ComboRow } from \"./combo-row.js\";\nexport { ToastProvider, useToast, useToastOverlay } from \"./toast.js\";\nexport type {\n ComboRowProps,\n ToastController,\n ToastOptions,\n ToastOverlayController,\n ToastProviderProps,\n} from \"./types.js\";\n"]}
|
package/dist/adw/types.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type * as Adw from "@gtkx/gi/adw";
|
|
2
|
-
import type { AdwToastProps } from "@gtkx/jsx/adw";
|
|
2
|
+
import type { AdwComboRowProps, AdwToastProps } from "@gtkx/jsx/adw";
|
|
3
3
|
import type { ReactNode, RefObject } from "react";
|
|
4
|
+
import type { DropDownWidgetProps } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative
|
|
7
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
8
|
+
* for the row display, popup rows, and popup section headers.
|
|
9
|
+
*/
|
|
10
|
+
type ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;
|
|
4
11
|
/**
|
|
5
12
|
* Describes a toast raised through {@link useToast}: the construct-time properties of an
|
|
6
13
|
* `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.
|
|
@@ -24,5 +31,5 @@ type ToastProviderProps = {
|
|
|
24
31
|
overlayRef: RefObject<Adw.ToastOverlay | null>;
|
|
25
32
|
children?: ReactNode | undefined;
|
|
26
33
|
};
|
|
27
|
-
export { type ToastOptions, type ToastController, type ToastOverlayController, type ToastProviderProps };
|
|
34
|
+
export { type ComboRowProps, type ToastOptions, type ToastController, type ToastOverlayController, type ToastProviderProps, };
|
|
28
35
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/adw/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adw/types.ts"],"names":[],"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AAO,EACH,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,GAC1B,CAAC"}
|
package/dist/adw/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/adw/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/adw/types.ts"],"names":[],"mappings":"AAsCA,OAAO,EAMN,CAAC","sourcesContent":["import type * as Adw from \"@gtkx/gi/adw\";\nimport type { AdwComboRowProps, AdwToastProps } from \"@gtkx/jsx/adw\";\nimport type { ReactNode, RefObject } from \"react\";\nimport type { DropDownWidgetProps } from \"../types.js\";\n\n/**\n * Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the row display, popup rows, and popup section headers.\n */\ntype ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;\n/**\n * Describes a toast raised through {@link useToast}: the construct-time properties of an\n * `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.\n */\ntype ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, \"onButtonClicked\" | \"onDismissed\">;\n\n/** Imperative controls for individual toasts, returned by {@link useToast}. */\ntype ToastController = {\n /** Builds a toast, shows it through the overlay, and returns it. */\n show: (options?: ToastOptions) => Adw.Toast;\n /** Dismisses a single toast, typically one returned by {@link ToastController.show}. */\n dismiss: (toast: Adw.Toast) => void;\n};\n\n/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */\ntype ToastOverlayController = {\n /** Dismisses the shown toast and every queued one. */\n dismissAll: () => void;\n};\n\n/** Props for {@link ToastProvider}. */\ntype ToastProviderProps = {\n /** Ref also given to the `AdwToastOverlay` the toasts appear over. */\n overlayRef: RefObject<Adw.ToastOverlay | null>;\n children?: ReactNode | undefined;\n};\n\nexport {\n type ComboRowProps,\n type ToastOptions,\n type ToastController,\n type ToastOverlayController,\n type ToastProviderProps,\n};\n"]}
|
package/dist/column-view.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
3
|
import { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
|
|
4
|
-
import {
|
|
4
|
+
import { useSignal } from "@gtkx/react";
|
|
5
5
|
import { omit } from "@gtkx/utils";
|
|
6
6
|
import { useLayoutEffect, useRef } from "react";
|
|
7
7
|
import { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from "./internal/cells.js";
|
|
@@ -68,7 +68,7 @@ const syncSort = (sorting, view, sortColumn, sortOrder) => {
|
|
|
68
68
|
};
|
|
69
69
|
const useColumnSorting = (view, sort, columns) => {
|
|
70
70
|
const sorting = useRef(false);
|
|
71
|
-
const sorter =
|
|
71
|
+
const sorter = view?.getSorter() ?? null;
|
|
72
72
|
const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;
|
|
73
73
|
useSignal(columnSorter, "changed", () => {
|
|
74
74
|
emitSortChanged(columnSorter, sorting, sort);
|
package/dist/column-view.js.map
CHANGED
|
@@ -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,CAAC;AAC9G,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,O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B,aAAa,EAAE,KAAC,wBAAwB,OAAK,WAAW,CAAC,QAAQ,GAAI;iBACxE,CAAC,KACE,IAAI,YAER,KAAC,UAAU,IAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAI,GACrF,EACf,YAAY,IAAI,IAAI,IAAI,CACrB,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,GAAI,CACtF,IACF,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useProperty, 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 { Column, ColumnViewProps } from \"./types.js\";\nimport { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SortProps = {\n sortColumn?: string | null | undefined;\n sortOrder?: Gtk.SortType | null | undefined;\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\ntype SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };\n\ntype ColumnCellsProps = {\n column: Column<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\"> & {\n columns: Column<never>[];\n};\n\nconst COLUMN_VIEW_PROPS = [\n \"items\",\n \"sections\",\n \"renderHeader\",\n \"columns\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"expandedIds\",\n \"onExpandedChange\",\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: { current: 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: { current: 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: { current: 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: Column<never>[]): void => {\n const sorting = useRef(false);\n const sorter = useProperty(view, \"sorter\");\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, size }: ColumnCellsProps): ReactNode => {\n const cells = useItemCells(size);\n const rest = omit(column, [\"id\", \"renderCell\", \"sortable\"]);\n\n return (\n <>\n <GtkColumnViewColumn\n id={column.id}\n factory={<GtkSignalListItemFactory {...cells.handlers} />}\n sorter={column.sortable === true ? <GtkCustomSorter /> : null}\n {...rest}\n />\n <ItemPortals\n store={cells}\n render={column.renderCell}\n collection={collection}\n expandedIds={expandedIds}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, size }: ColumnListProps): ReactNode =>\n columns.map((column) => (\n <ColumnCells\n key={column.id}\n column={column}\n collection={collection}\n expandedIds={expandedIds}\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, and\n * section header rendering.\n */\nfunction ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode {\n const { renderHeader, columns, expandedIds, sortColumn, sortOrder, onSortChanged, estimatedItemHeight, ref } =\n props;\n\n const rest = omit(props, COLUMN_VIEW_PROPS);\n const [view, refCallback] = useWidgetRef<Gtk.ColumnView>(ref);\n const size = { width: -1, height: estimatedItemHeight ?? -1 };\n const { collection, selection } = useCollection(props);\n const headerCells = useHeaderCells(size);\n const columnList = columns as Column<never>[];\n useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);\n\n return (\n <>\n <GtkColumnView\n ref={refCallback}\n model={selection}\n {...(renderHeader != null && {\n headerFactory: <GtkSignalListItemFactory {...headerCells.handlers} />,\n })}\n {...rest}\n >\n <ColumnList columns={columnList} collection={collection} expandedIds={expandedIds} size={size} />\n </GtkColumnView>\n {renderHeader != null && (\n <HeaderPortals store={headerCells} render={renderHeader} collection={collection} />\n )}\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,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAqB5D,MAAM,iBAAiB,GAAG;IACtB,OAAO;IACP,UAAU;IACV,cAAc;IACd,SAAS;IACT,aAAa;IACb,oBAAoB;IACpB,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,YAAY;IACZ,WAAW;IACX,eAAe;IACf,qBAAqB;IACrB,UAAU;IACV,KAAK;CACqC,CAAC;AAE/C,MAAM,UAAU,GAAG,CAAC,IAAoB,EAAE,EAAU,EAA+B,EAAE;IACjF,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAElC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;QACvD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,MAAM,YAAY,GAAG,CAAC,gBAAgB,IAAI,MAAM,CAAC,KAAK,EAAE,KAAK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AAE,mBAAmB,IAAI,CAAC,CAAC,EAAE,CAAC;IAC9D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,OAA0B,CAAC;IAC9C,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,CAAC,YAAY,IAAI,IAAI,IAAI;oBACzB,aAAa,EAAE,KAAC,wBAAwB,OAAK,WAAW,CAAC,QAAQ,GAAI;iBACxE,CAAC,KACE,IAAI,YAER,KAAC,UAAU,IAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAI,GACrF,EACf,YAAY,IAAI,IAAI,IAAI,CACrB,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,GAAI,CACtF,IACF,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import type { ReactNode } 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 { Column, ColumnViewProps } from \"./types.js\";\nimport { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SortProps = {\n sortColumn?: string | null | undefined;\n sortOrder?: Gtk.SortType | null | undefined;\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\ntype SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };\n\ntype ColumnCellsProps = {\n column: Column<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\"> & {\n columns: Column<never>[];\n};\n\nconst COLUMN_VIEW_PROPS = [\n \"items\",\n \"sections\",\n \"renderHeader\",\n \"columns\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"expandedIds\",\n \"onExpandedChange\",\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: { current: 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: { current: 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: { current: 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: Column<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, size }: ColumnCellsProps): ReactNode => {\n const cells = useItemCells(size);\n const rest = omit(column, [\"id\", \"renderCell\", \"sortable\"]);\n\n return (\n <>\n <GtkColumnViewColumn\n id={column.id}\n factory={<GtkSignalListItemFactory {...cells.handlers} />}\n sorter={column.sortable === true ? <GtkCustomSorter /> : null}\n {...rest}\n />\n <ItemPortals\n store={cells}\n render={column.renderCell}\n collection={collection}\n expandedIds={expandedIds}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, size }: ColumnListProps): ReactNode =>\n columns.map((column) => (\n <ColumnCells\n key={column.id}\n column={column}\n collection={collection}\n expandedIds={expandedIds}\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, and\n * section header rendering.\n */\nfunction ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode {\n const { renderHeader, columns, expandedIds, sortColumn, sortOrder, onSortChanged, estimatedItemHeight, ref } =\n props;\n\n const rest = omit(props, COLUMN_VIEW_PROPS);\n const [view, refCallback] = useWidgetRef<Gtk.ColumnView>(ref);\n const size = { width: -1, height: estimatedItemHeight ?? -1 };\n const { collection, selection } = useCollection(props);\n const headerCells = useHeaderCells(size);\n const columnList = columns as Column<never>[];\n useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);\n\n return (\n <>\n <GtkColumnView\n ref={refCallback}\n model={selection}\n {...(renderHeader != null && {\n headerFactory: <GtkSignalListItemFactory {...headerCells.handlers} />,\n })}\n {...rest}\n >\n <ColumnList columns={columnList} collection={collection} expandedIds={expandedIds} size={size} />\n </GtkColumnView>\n {renderHeader != null && (\n <HeaderPortals store={headerCells} render={renderHeader} collection={collection} />\n )}\n </>\n );\n}\n\nexport { ColumnView };\n"]}
|
package/dist/drop-down.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { GtkDropDown } from "@gtkx/jsx/gtk";
|
|
1
|
+
import type { ReactNode } from "react";
|
|
3
2
|
import type { DropDownProps } from "./types.js";
|
|
4
|
-
type DropDownComponent = <T = unknown, S = unknown
|
|
3
|
+
type DropDownComponent = <T = unknown, S = unknown>(props: DropDownProps<T, S>) => ReactNode;
|
|
5
4
|
/**
|
|
6
|
-
* Renders a
|
|
5
|
+
* Renders a `Gtk.DropDown` backed by a collection model, with customizable renderers for the
|
|
7
6
|
* collapsed display, popup rows, and popup section headers, and controlled selection.
|
|
8
|
-
* The backing widget defaults to GtkDropDown and is swappable through `component`.
|
|
9
7
|
*/
|
|
10
8
|
declare const DropDown: DropDownComponent;
|
|
11
9
|
export { DropDown };
|
package/dist/drop-down.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,iBAAiB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;AAE7F;;;GAGG;AACH,QAAA,MAAM,QAAQ,EAAE,iBAAqD,CAAC;AAMtE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/drop-down.js
CHANGED
|
@@ -1,120 +1,13 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import { GtkDropDown
|
|
3
|
-
import {
|
|
4
|
-
import { omit } from "@gtkx/utils";
|
|
5
|
-
import { useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
6
|
-
import { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from "./internal/cells.js";
|
|
7
|
-
import { useCollectionData } from "./internal/use-collection.js";
|
|
8
|
-
import { useWidgetRef } from "./internal/use-widget-ref.js";
|
|
9
|
-
const DROP_DOWN_PROPS = [
|
|
10
|
-
"component",
|
|
11
|
-
"items",
|
|
12
|
-
"sections",
|
|
13
|
-
"selectedId",
|
|
14
|
-
"onSelectionChanged",
|
|
15
|
-
"renderItem",
|
|
16
|
-
"renderListItem",
|
|
17
|
-
"renderHeader",
|
|
18
|
-
"ref",
|
|
19
|
-
];
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { GtkDropDown } from "@gtkx/jsx/gtk";
|
|
3
|
+
import { DropDownBase } from "./internal/drop-down.js";
|
|
20
4
|
/**
|
|
21
|
-
* Renders a
|
|
5
|
+
* Renders a `Gtk.DropDown` backed by a collection model, with customizable renderers for the
|
|
22
6
|
* collapsed display, popup rows, and popup section headers, and controlled selection.
|
|
23
|
-
* The backing widget defaults to GtkDropDown and is swappable through `component`.
|
|
24
7
|
*/
|
|
25
8
|
const DropDown = DropDownImpl;
|
|
26
|
-
const describeValue = (value) => {
|
|
27
|
-
if (typeof value === "string") {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
return JSON.stringify(value);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return String(value);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const defaultItemContent = (value) => value == null ? null : _jsx(GtkLabel, { children: describeValue(value) });
|
|
38
|
-
const defaultRenderItem = ({ item }) => defaultItemContent(item);
|
|
39
|
-
const faceRenderer = (props) => props.renderItem ?? defaultRenderItem;
|
|
40
|
-
const listRenderer = (props) => props.renderListItem ?? props.renderItem ?? defaultRenderItem;
|
|
41
|
-
const resolvePosition = (widget, collection, selectedId) => {
|
|
42
|
-
const requested = selectedId == null ? -1 : collection.positionFor(selectedId);
|
|
43
|
-
return requested >= 0 ? requested : widget.getSelected();
|
|
44
|
-
};
|
|
45
|
-
const updateKnownSelection = (tracker, effectiveId, selectedId) => {
|
|
46
|
-
const { known, onSelectionChanged } = tracker;
|
|
47
|
-
const expectedId = selectedId ?? known.current;
|
|
48
|
-
const isNew = effectiveId !== known.current;
|
|
49
|
-
known.current = effectiveId;
|
|
50
|
-
if (expectedId !== null && effectiveId !== expectedId && isNew) {
|
|
51
|
-
onSelectionChanged?.(effectiveId);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const reportKnownSelection = (tracker, id) => {
|
|
55
|
-
const { known, onSelectionChanged } = tracker;
|
|
56
|
-
if (id === null || id === known.current) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
known.current = id;
|
|
60
|
-
onSelectionChanged?.(id);
|
|
61
|
-
};
|
|
62
|
-
const reportSelectedNotify = (options, tracker, applying) => {
|
|
63
|
-
const { widget, collection } = options;
|
|
64
|
-
if (widget === null || applying.current) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
reportKnownSelection(tracker, collection.idAt(widget.getSelected()));
|
|
68
|
-
};
|
|
69
|
-
const applySelectedPosition = (widget, position, applying) => {
|
|
70
|
-
applying.current = true;
|
|
71
|
-
try {
|
|
72
|
-
widget.selected = position;
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
applying.current = false;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const useDropDownSelection = (options) => {
|
|
79
|
-
const { widget, collection, applying } = options;
|
|
80
|
-
const { selectedId } = options.props;
|
|
81
|
-
const known = useRef(null);
|
|
82
|
-
const syncKnownSelection = useEffectEvent((position) => {
|
|
83
|
-
const effectiveId = collection.idAt(position);
|
|
84
|
-
if (effectiveId === null) {
|
|
85
|
-
known.current = null;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const { onSelectionChanged } = options.props;
|
|
89
|
-
updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);
|
|
90
|
-
});
|
|
91
|
-
useLayoutEffect(() => {
|
|
92
|
-
if (widget === null) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const position = resolvePosition(widget, collection, selectedId);
|
|
96
|
-
applySelectedPosition(widget, position, applying);
|
|
97
|
-
syncKnownSelection(position);
|
|
98
|
-
}, [widget, collection, selectedId, applying]);
|
|
99
|
-
useSignal(widget, "notify::selected", () => {
|
|
100
|
-
reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged }, applying);
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
9
|
function DropDownImpl(props) {
|
|
104
|
-
|
|
105
|
-
const rest = omit(props, DROP_DOWN_PROPS);
|
|
106
|
-
const [widget, refCallback] = useWidgetRef(ref);
|
|
107
|
-
const applying = useRef(false);
|
|
108
|
-
const collection = useCollectionData({ items, sections, applying });
|
|
109
|
-
const faceCells = useItemCells({ width: -1, height: -1 });
|
|
110
|
-
const listCells = useItemCells({ width: -1, height: -1 });
|
|
111
|
-
const headerCells = useHeaderCells({ width: -1, height: -1 });
|
|
112
|
-
useDropDownSelection({ widget, collection, applying, props });
|
|
113
|
-
const Component = component ?? GtkDropDown;
|
|
114
|
-
const hasHeader = typeof renderHeader === "function";
|
|
115
|
-
return (_jsxs(_Fragment, { children: [_jsx(Component, { ref: refCallback, model: collection.model, factory: _jsx(GtkSignalListItemFactory, { ...faceCells.handlers }), ...(renderListItem != null && {
|
|
116
|
-
listFactory: _jsx(GtkSignalListItemFactory, { ...listCells.handlers }),
|
|
117
|
-
}), ...(hasHeader && { headerFactory: _jsx(GtkSignalListItemFactory, { ...headerCells.handlers }) }), ...rest }), _jsx(ItemPortals, { store: faceCells, render: faceRenderer(props), collection: collection }), renderListItem != null && (_jsx(ItemPortals, { store: listCells, render: listRenderer(props), collection: collection })), hasHeader && _jsx(HeaderPortals, { store: headerCells, render: renderHeader, collection: collection })] }));
|
|
10
|
+
return _jsx(DropDownBase, { ...props, component: GtkDropDown });
|
|
118
11
|
}
|
|
119
12
|
export { DropDown };
|
|
120
13
|
//# sourceMappingURL=drop-down.js.map
|
package/dist/drop-down.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-down.js","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAyB5D,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,MAAM,SAAS,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC;IAErD,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,CAAC,SAAS,IAAI,EAAE,aAAa,EAAE,KAAC,wBAAwB,OAAK,WAAW,CAAC,QAAQ,GAAI,EAAE,CAAC,KACxF,IAAI,GACV,EACF,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,EACrF,cAAc,IAAI,IAAI,IAAI,CACvB,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,CACzF,EACA,SAAS,IAAI,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,GAAI,IAClG,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type { ElementType, ReactNode, Ref, RefObject } from \"react\";\nimport { GtkDropDown, GtkLabel, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { omit } from \"@gtkx/utils\";\nimport { useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { Collection } from \"./internal/collection.js\";\nimport type { DropDownProps, ItemRenderer, RenderItemArgs } from \"./types.js\";\nimport { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from \"./internal/cells.js\";\nimport { useCollectionData } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SelectableWidget = GObject.Object & { getSelected: () => number; selected: number };\n\ntype DropDownRuntimeProps = DropDownProps & {\n component?: ElementType | undefined;\n ref?: Ref<SelectableWidget | null> | undefined;\n} & Record<string, unknown>;\n\ntype SelectionOptions = {\n widget: SelectableWidget | null;\n collection: Collection;\n applying: RefObject<boolean>;\n props: DropDownRuntimeProps;\n};\n\ntype KnownSelection = {\n known: { current: string | null };\n onSelectionChanged: ((id: string) => void) | null | undefined;\n};\n\ntype DropDownComponent = <T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown>(\n props: DropDownProps<T, S, C>,\n) => ReactNode;\n\nconst DROP_DOWN_PROPS: string[] = [\n \"component\",\n \"items\",\n \"sections\",\n \"selectedId\",\n \"onSelectionChanged\",\n \"renderItem\",\n \"renderListItem\",\n \"renderHeader\",\n \"ref\",\n];\n\n/**\n * Renders a drop-down backed by a collection model, with customizable renderers for the\n * collapsed display, popup rows, and popup section headers, and controlled selection.\n * The backing widget defaults to GtkDropDown and is swappable through `component`.\n */\nconst DropDown: DropDownComponent = DropDownImpl as DropDownComponent;\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 }: RenderItemArgs<unknown>): ReactNode => defaultItemContent(item);\n\nconst faceRenderer = (props: DropDownRuntimeProps): ItemRenderer<never> =>\n props.renderItem ?? defaultRenderItem;\n\nconst listRenderer = (props: DropDownRuntimeProps): ItemRenderer<never> =>\n props.renderListItem ?? 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 = (\n options: SelectionOptions,\n tracker: KnownSelection,\n applying: RefObject<boolean>,\n): void => {\n const { widget, collection } = options;\n\n if (widget === null || applying.current) {\n return;\n }\n\n reportKnownSelection(tracker, collection.idAt(widget.getSelected()));\n};\n\nconst applySelectedPosition = (widget: SelectableWidget, position: number, applying: RefObject<boolean>): void => {\n applying.current = true;\n\n try {\n widget.selected = position;\n } finally {\n applying.current = false;\n }\n};\n\nconst useDropDownSelection = (options: SelectionOptions): void => {\n const { widget, collection, applying } = options;\n const { selectedId } = options.props;\n const known = useRef<string | null>(null);\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, applying);\n syncKnownSelection(position);\n }, [widget, collection, selectedId, applying]);\n\n useSignal(widget, \"notify::selected\", (): void => {\n reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged }, applying);\n });\n};\n\nfunction DropDownImpl(props: DropDownRuntimeProps): ReactNode {\n const { component, items, sections, renderListItem, renderHeader, ref } = props;\n const rest = omit(props, DROP_DOWN_PROPS);\n const [widget, refCallback] = useWidgetRef<SelectableWidget>(ref);\n const applying = useRef(false);\n const collection = useCollectionData({ items, sections, applying });\n const faceCells = useItemCells({ width: -1, height: -1 });\n const listCells = useItemCells({ width: -1, height: -1 });\n const headerCells = useHeaderCells({ width: -1, height: -1 });\n useDropDownSelection({ widget, collection, applying, props });\n const Component = component ?? GtkDropDown;\n const hasHeader = typeof renderHeader === \"function\";\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 {...(hasHeader && { headerFactory: <GtkSignalListItemFactory {...headerCells.handlers} /> })}\n {...rest}\n />\n <ItemPortals store={faceCells} render={faceRenderer(props)} collection={collection} />\n {renderListItem != null && (\n <ItemPortals store={listCells} render={listRenderer(props)} collection={collection} />\n )}\n {hasHeader && <HeaderPortals store={headerCells} render={renderHeader} collection={collection} />}\n </>\n );\n}\n\nexport { DropDown };\n"]}
|
|
1
|
+
{"version":3,"file":"drop-down.js","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD;;;GAGG;AACH,MAAM,QAAQ,GAAsB,YAAiC,CAAC;AAEtE,SAAS,YAAY,CAAC,KAAwB;IAC1C,OAAO,KAAC,YAAY,OAAK,KAAK,EAAE,SAAS,EAAE,WAAW,GAAI,CAAC;AAC/D,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { GtkDropDown } from \"@gtkx/jsx/gtk\";\nimport type { DropDownBaseProps } from \"./internal/drop-down.js\";\nimport type { DropDownProps } from \"./types.js\";\nimport { DropDownBase } from \"./internal/drop-down.js\";\n\ntype DropDownComponent = <T = unknown, S = unknown>(props: DropDownProps<T, S>) => ReactNode;\n\n/**\n * Renders a `Gtk.DropDown` backed by a collection model, with customizable renderers for the\n * collapsed display, popup rows, and popup section headers, and controlled selection.\n */\nconst DropDown: DropDownComponent = DropDownImpl as DropDownComponent;\n\nfunction DropDownImpl(props: DropDownBaseProps): ReactNode {\n return <DropDownBase {...props} component={GtkDropDown} />;\n}\n\nexport { DropDown };\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { DropDown } from "./drop-down.js";
|
|
|
3
3
|
export { GridView } from "./grid-view.js";
|
|
4
4
|
export { ListView } from "./list-view.js";
|
|
5
5
|
export { SizeGroup } from "./size-group.js";
|
|
6
|
-
export type { ChildProps, Column, ColumnViewProps, DropDownProps, GridViewProps, HeaderRenderer, Item, ItemRenderer, ListViewProps, RenderHeaderArgs, RenderItemArgs, Section, SizeGroupChildProps, SizeGroupProps,
|
|
6
|
+
export type { ChildProps, Column, ColumnViewProps, DropDownProps, GridViewProps, HeaderRenderer, Item, ItemRenderer, ListViewProps, RenderHeaderArgs, RenderItemArgs, Section, SizeGroupChildProps, SizeGroupProps, } from "./types.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EACR,UAAU,EACV,MAAM,EACN,eAAe,EACf,aAAa,EACb,aAAa,EACb,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EACR,UAAU,EACV,MAAM,EACN,eAAe,EACf,aAAa,EACb,aAAa,EACb,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,cAAc,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { ColumnView } from \"./column-view.js\";\nexport { DropDown } from \"./drop-down.js\";\nexport { GridView } from \"./grid-view.js\";\nexport { ListView } from \"./list-view.js\";\nexport { SizeGroup } from \"./size-group.js\";\nexport type {\n ChildProps,\n Column,\n ColumnViewProps,\n DropDownProps,\n GridViewProps,\n HeaderRenderer,\n Item,\n ItemRenderer,\n ListViewProps,\n RenderHeaderArgs,\n RenderItemArgs,\n Section,\n SizeGroupChildProps,\n SizeGroupProps,\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { ColumnView } from \"./column-view.js\";\nexport { DropDown } from \"./drop-down.js\";\nexport { GridView } from \"./grid-view.js\";\nexport { ListView } from \"./list-view.js\";\nexport { SizeGroup } from \"./size-group.js\";\nexport type {\n ChildProps,\n Column,\n ColumnViewProps,\n DropDownProps,\n GridViewProps,\n HeaderRenderer,\n Item,\n ItemRenderer,\n ListViewProps,\n RenderHeaderArgs,\n RenderItemArgs,\n Section,\n SizeGroupChildProps,\n SizeGroupProps,\n} from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import type { ElementType, ReactNode, Ref } from "react";
|
|
3
|
+
import type { DropDownOwnProps } from "../types.js";
|
|
4
|
+
type SelectableWidget = GObject.Object & {
|
|
5
|
+
getSelected: () => number;
|
|
6
|
+
selected: number;
|
|
7
|
+
};
|
|
8
|
+
type DropDownBaseProps = DropDownOwnProps<unknown, unknown> & {
|
|
9
|
+
onNotifySelected?: ((value: number | null, self: SelectableWidget) => void) | null | undefined;
|
|
10
|
+
ref?: Ref<SelectableWidget | null> | undefined;
|
|
11
|
+
} & Record<string, unknown>;
|
|
12
|
+
declare function DropDownBase(props: DropDownBaseProps & {
|
|
13
|
+
component: ElementType;
|
|
14
|
+
}): ReactNode;
|
|
15
|
+
export { DropDownBase, type DropDownBaseProps };
|
|
16
|
+
//# sourceMappingURL=drop-down.d.ts.map
|
|
@@ -0,0 +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;AAKzD,OAAO,KAAK,EAAE,gBAAgB,EAAgC,MAAM,aAAa,CAAC;AAMlF,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;AAuI5B,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG;IAAE,SAAS,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CA+BtF;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { GtkLabel, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
|
|
3
|
+
import { applyWrite } from "@gtkx/react/internal";
|
|
4
|
+
import { omit } from "@gtkx/utils";
|
|
5
|
+
import { useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
6
|
+
import { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from "./cells.js";
|
|
7
|
+
import { useCollectionData } from "./use-collection.js";
|
|
8
|
+
import { useWidgetRef } from "./use-widget-ref.js";
|
|
9
|
+
const DROP_DOWN_PROPS = [
|
|
10
|
+
"component",
|
|
11
|
+
"items",
|
|
12
|
+
"sections",
|
|
13
|
+
"selectedId",
|
|
14
|
+
"onSelectionChanged",
|
|
15
|
+
"onNotifySelected",
|
|
16
|
+
"renderItem",
|
|
17
|
+
"renderListItem",
|
|
18
|
+
"renderHeader",
|
|
19
|
+
"ref",
|
|
20
|
+
];
|
|
21
|
+
const describeValue = (value) => {
|
|
22
|
+
if (typeof value === "string") {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return JSON.stringify(value);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return String(value);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const defaultItemContent = (value) => value == null ? null : _jsx(GtkLabel, { children: describeValue(value) });
|
|
33
|
+
const defaultRenderItem = ({ item }) => defaultItemContent(item);
|
|
34
|
+
const faceRenderer = (props) => props.renderItem ?? defaultRenderItem;
|
|
35
|
+
const listRenderer = (props) => props.renderListItem ?? props.renderItem ?? defaultRenderItem;
|
|
36
|
+
const resolvePosition = (widget, collection, selectedId) => {
|
|
37
|
+
const requested = selectedId == null ? -1 : collection.positionFor(selectedId);
|
|
38
|
+
return requested >= 0 ? requested : widget.getSelected();
|
|
39
|
+
};
|
|
40
|
+
const updateKnownSelection = (tracker, effectiveId, selectedId) => {
|
|
41
|
+
const { known, onSelectionChanged } = tracker;
|
|
42
|
+
const expectedId = selectedId ?? known.current;
|
|
43
|
+
const isNew = effectiveId !== known.current;
|
|
44
|
+
known.current = effectiveId;
|
|
45
|
+
if (expectedId !== null && effectiveId !== expectedId && isNew) {
|
|
46
|
+
onSelectionChanged?.(effectiveId);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const reportKnownSelection = (tracker, id) => {
|
|
50
|
+
const { known, onSelectionChanged } = tracker;
|
|
51
|
+
if (id === null || id === known.current) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
known.current = id;
|
|
55
|
+
onSelectionChanged?.(id);
|
|
56
|
+
};
|
|
57
|
+
const reportSelectedNotify = (options, tracker) => {
|
|
58
|
+
const { widget, collection } = options;
|
|
59
|
+
if (widget === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
reportKnownSelection(tracker, collection.idAt(widget.getSelected()));
|
|
63
|
+
};
|
|
64
|
+
const applySelectedPosition = (widget, position) => {
|
|
65
|
+
applyWrite(() => {
|
|
66
|
+
widget.selected = position;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const useDropDownSelection = (options) => {
|
|
70
|
+
const { widget, collection } = options;
|
|
71
|
+
const { selectedId } = options.props;
|
|
72
|
+
const known = useRef(null);
|
|
73
|
+
const syncKnownSelection = useEffectEvent((position) => {
|
|
74
|
+
const effectiveId = collection.idAt(position);
|
|
75
|
+
if (effectiveId === null) {
|
|
76
|
+
known.current = null;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const { onSelectionChanged } = options.props;
|
|
80
|
+
updateKnownSelection({ known, onSelectionChanged }, effectiveId, selectedId);
|
|
81
|
+
});
|
|
82
|
+
useLayoutEffect(() => {
|
|
83
|
+
if (widget === null) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const position = resolvePosition(widget, collection, selectedId);
|
|
87
|
+
applySelectedPosition(widget, position);
|
|
88
|
+
syncKnownSelection(position);
|
|
89
|
+
}, [widget, collection, selectedId]);
|
|
90
|
+
return (value, self) => {
|
|
91
|
+
reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged });
|
|
92
|
+
options.props.onNotifySelected?.(value, self);
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
function DropDownBase(props) {
|
|
96
|
+
const { component: Component, items, sections, renderListItem, renderHeader, ref } = props;
|
|
97
|
+
const rest = omit(props, DROP_DOWN_PROPS);
|
|
98
|
+
const [widget, refCallback] = useWidgetRef(ref);
|
|
99
|
+
const collection = useCollectionData({ items, sections });
|
|
100
|
+
const faceCells = useItemCells({ width: -1, height: -1 });
|
|
101
|
+
const listCells = useItemCells({ width: -1, height: -1 });
|
|
102
|
+
const headerCells = useHeaderCells({ width: -1, height: -1 });
|
|
103
|
+
const handleNotifySelected = useDropDownSelection({ widget, collection, props });
|
|
104
|
+
const hasHeader = typeof renderHeader === "function";
|
|
105
|
+
return (_jsxs(_Fragment, { children: [_jsx(Component, { ref: refCallback, model: collection.model, factory: _jsx(GtkSignalListItemFactory, { ...faceCells.handlers }), ...(renderListItem != null && {
|
|
106
|
+
listFactory: _jsx(GtkSignalListItemFactory, { ...listCells.handlers }),
|
|
107
|
+
}), ...(hasHeader && { headerFactory: _jsx(GtkSignalListItemFactory, { ...headerCells.handlers }) }), ...rest, onNotifySelected: handleNotifySelected }), _jsx(ItemPortals, { store: faceCells, render: faceRenderer(props), collection: collection }), renderListItem != null && (_jsx(ItemPortals, { store: listCells, render: listRenderer(props), collection: collection })), hasHeader && _jsx(HeaderPortals, { store: headerCells, render: renderHeader, collection: collection })] }));
|
|
108
|
+
}
|
|
109
|
+
export { DropDownBase };
|
|
110
|
+
//# sourceMappingURL=drop-down.js.map
|
|
@@ -0,0 +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,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OA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AO,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,CAAC,SAAS,IAAI,EAAE,aAAa,EAAE,KAAC,wBAAwB,OAAK,WAAW,CAAC,QAAQ,GAAI,EAAE,CAAC,KACxF,IAAI,EACR,gBAAgB,EAAE,oBAAoB,GACxC,EACF,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,EACrF,cAAc,IAAI,IAAI,IAAI,CACvB,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,GAAI,CACzF,EACA,SAAS,IAAI,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,GAAI,IAClG,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 { applyWrite } from \"@gtkx/react/internal\";\nimport { omit } from \"@gtkx/utils\";\nimport { useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { DropDownOwnProps, ItemRenderer, RenderItemArgs } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } 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\"]>;\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\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 }: RenderItemArgs<unknown>): ReactNode => defaultItemContent(item);\nconst faceRenderer = (props: DropDownBaseProps): ItemRenderer<never> => props.renderItem ?? defaultRenderItem;\n\nconst listRenderer = (props: DropDownBaseProps): ItemRenderer<never> =>\n props.renderListItem ?? 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): void => {\n applyWrite(() => {\n widget.selected = position;\n });\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\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);\n syncKnownSelection(position);\n }, [widget, collection, selectedId]);\n\n return (value, self) => {\n reportSelectedNotify(options, { known, onSelectionChanged: options.props.onSelectionChanged });\n options.props.onNotifySelected?.(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 });\n const faceCells = useItemCells({ width: -1, height: -1 });\n const listCells = useItemCells({ width: -1, height: -1 });\n const headerCells = useHeaderCells({ width: -1, height: -1 });\n const handleNotifySelected = useDropDownSelection({ widget, collection, props });\n const hasHeader = typeof renderHeader === \"function\";\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 {...(hasHeader && { headerFactory: <GtkSignalListItemFactory {...headerCells.handlers} /> })}\n {...rest}\n onNotifySelected={handleNotifySelected}\n />\n <ItemPortals store={faceCells} render={faceRenderer(props)} collection={collection} />\n {renderListItem != null && (\n <ItemPortals store={listCells} render={listRenderer(props)} collection={collection} />\n )}\n {hasHeader && <HeaderPortals store={headerCells} render={renderHeader} collection={collection} />}\n </>\n );\n}\n\nexport { DropDownBase, type DropDownBaseProps };\n"]}
|
|
@@ -4,6 +4,6 @@ type ExpansionOptions = {
|
|
|
4
4
|
expandedIds?: string[] | null | undefined;
|
|
5
5
|
onExpandedChange?: ((ids: string[]) => void) | null | undefined;
|
|
6
6
|
};
|
|
7
|
-
declare function useExpansion(options: ExpansionOptions): void;
|
|
7
|
+
declare function useExpansion(options: ExpansionOptions): () => void;
|
|
8
8
|
export { useExpansion, type ExpansionOptions };
|
|
9
9
|
//# sourceMappingURL=expansion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expansion.d.ts","sourceRoot":"","sources":["../../src/internal/expansion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expansion.d.ts","sourceRoot":"","sources":["../../src/internal/expansion.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,gBAAgB,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,gBAAgB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CACnE,CAAC;AA6FF,iBAAS,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAgB3D;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useSignal } from "@gtkx/react";
|
|
2
1
|
import { useEffectEvent, useLayoutEffect, useRef, useState } from "react";
|
|
3
2
|
import { eachRow } from "./collection.js";
|
|
4
3
|
function newLastExpansion() {
|
|
@@ -64,12 +63,12 @@ function useExpansion(options) {
|
|
|
64
63
|
const report = useEffectEvent(() => {
|
|
65
64
|
reportWhenIdle(collection, last, expanding, onExpandedChange);
|
|
66
65
|
});
|
|
67
|
-
useSignal(collection.isTree ? collection.model : null, "items-changed", () => {
|
|
68
|
-
reportWhenIdle(collection, last, expanding, onExpandedChange);
|
|
69
|
-
});
|
|
70
66
|
useLayoutEffect(() => {
|
|
71
67
|
runControlledExpansion(collection, expandedIds, expanding, report);
|
|
72
68
|
}, [collection, expandedIds]);
|
|
69
|
+
return () => {
|
|
70
|
+
reportWhenIdle(collection, last, expanding, onExpandedChange);
|
|
71
|
+
};
|
|
73
72
|
}
|
|
74
73
|
export { useExpansion };
|
|
75
74
|
//# sourceMappingURL=expansion.js.map
|