@gtkx/components 1.0.0-rc.1 → 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 +4 -0
- package/dist/adw/index.d.ts.map +1 -0
- package/dist/adw/index.js +3 -0
- package/dist/adw/index.js.map +1 -0
- package/dist/adw/toast.d.ts +10 -0
- package/dist/adw/toast.d.ts.map +1 -0
- package/dist/adw/toast.js +51 -0
- package/dist/adw/toast.js.map +1 -0
- package/dist/adw/types.d.ts +35 -0
- package/dist/adw/types.d.ts.map +1 -0
- package/dist/adw/types.js +2 -0
- package/dist/adw/types.js.map +1 -0
- package/dist/column-view.d.ts +7 -29
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +98 -70
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +7 -28
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +10 -86
- package/dist/drop-down.js.map +1 -1
- package/dist/grid-view.d.ts +6 -16
- package/dist/grid-view.d.ts.map +1 -1
- package/dist/grid-view.js +25 -33
- package/dist/grid-view.js.map +1 -1
- package/dist/index.d.ts +6 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +50 -0
- package/dist/internal/cells.d.ts.map +1 -0
- package/dist/internal/cells.js +185 -0
- package/dist/internal/cells.js.map +1 -0
- package/dist/internal/collection-index.d.ts +21 -0
- package/dist/internal/collection-index.d.ts.map +1 -0
- package/dist/internal/collection-index.js +106 -0
- package/dist/internal/collection-index.js.map +1 -0
- package/dist/internal/collection-model.d.ts +12 -0
- package/dist/internal/collection-model.d.ts.map +1 -0
- package/dist/internal/collection-model.js +164 -0
- package/dist/internal/collection-model.js.map +1 -0
- package/dist/internal/collection.d.ts +18 -0
- package/dist/internal/collection.d.ts.map +1 -0
- package/dist/internal/collection.js +64 -0
- package/dist/internal/collection.js.map +1 -0
- 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 +9 -0
- package/dist/internal/expansion.d.ts.map +1 -0
- package/dist/internal/expansion.js +74 -0
- package/dist/internal/expansion.js.map +1 -0
- package/dist/internal/selection.d.ts +13 -0
- package/dist/internal/selection.d.ts.map +1 -0
- package/dist/internal/selection.js +100 -0
- package/dist/internal/selection.js.map +1 -0
- package/dist/internal/use-collection.d.ts +17 -0
- package/dist/internal/use-collection.d.ts.map +1 -0
- package/dist/internal/use-collection.js +34 -0
- package/dist/internal/use-collection.js.map +1 -0
- package/dist/internal/use-widget-ref.d.ts +4 -0
- package/dist/internal/use-widget-ref.d.ts.map +1 -0
- package/dist/internal/use-widget-ref.js +8 -0
- package/dist/internal/use-widget-ref.js.map +1 -0
- package/dist/list-view.d.ts +5 -20
- package/dist/list-view.d.ts.map +1 -1
- package/dist/list-view.js +32 -53
- package/dist/list-view.js.map +1 -1
- package/dist/size-group.d.ts +8 -16
- package/dist/size-group.d.ts.map +1 -1
- package/dist/size-group.js +35 -51
- package/dist/size-group.js.map +1 -1
- package/dist/types.d.ts +98 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -6
- package/src/adw/combo-row.tsx +20 -0
- package/src/adw/index.ts +9 -0
- package/src/adw/toast.tsx +74 -0
- package/src/adw/types.ts +45 -0
- package/src/column-view.tsx +176 -160
- package/src/drop-down.tsx +12 -185
- package/src/grid-view.tsx +29 -73
- package/src/index.ts +18 -26
- package/src/internal/cells.tsx +345 -0
- package/src/internal/collection-index.ts +168 -0
- package/src/internal/collection-model.ts +246 -0
- package/src/internal/collection.ts +104 -0
- package/src/internal/drop-down.tsx +186 -0
- package/src/internal/expansion.ts +122 -0
- package/src/internal/selection.tsx +162 -0
- package/src/internal/use-collection.tsx +57 -0
- package/src/internal/use-widget-ref.ts +11 -0
- package/src/list-view.tsx +43 -139
- package/src/size-group.tsx +63 -82
- package/src/types.ts +158 -28
- package/dist/cell.d.ts +0 -30
- package/dist/cell.d.ts.map +0 -1
- package/dist/cell.js +0 -45
- package/dist/cell.js.map +0 -1
- package/dist/column-view-column.d.ts +0 -27
- package/dist/column-view-column.d.ts.map +0 -1
- package/dist/column-view-column.js +0 -30
- package/dist/column-view-column.js.map +0 -1
- package/dist/constraint-layout-apply.d.ts +0 -55
- package/dist/constraint-layout-apply.d.ts.map +0 -1
- package/dist/constraint-layout-apply.js +0 -107
- package/dist/constraint-layout-apply.js.map +0 -1
- package/dist/constraint-layout.d.ts +0 -20
- package/dist/constraint-layout.d.ts.map +0 -1
- package/dist/constraint-layout.js +0 -88
- package/dist/constraint-layout.js.map +0 -1
- package/dist/fixed.d.ts +0 -26
- package/dist/fixed.d.ts.map +0 -1
- package/dist/fixed.js +0 -40
- package/dist/fixed.js.map +0 -1
- package/dist/grid.d.ts +0 -27
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js +0 -48
- package/dist/grid.js.map +0 -1
- package/dist/hooks/use-cell-containers.d.ts +0 -18
- package/dist/hooks/use-cell-containers.d.ts.map +0 -1
- package/dist/hooks/use-cell-containers.js +0 -67
- package/dist/hooks/use-cell-containers.js.map +0 -1
- package/dist/hooks/use-collection-model.d.ts +0 -26
- package/dist/hooks/use-collection-model.d.ts.map +0 -1
- package/dist/hooks/use-collection-model.js +0 -35
- package/dist/hooks/use-collection-model.js.map +0 -1
- package/dist/hooks/use-collection-widget.d.ts +0 -28
- package/dist/hooks/use-collection-widget.d.ts.map +0 -1
- package/dist/hooks/use-collection-widget.js +0 -21
- package/dist/hooks/use-collection-widget.js.map +0 -1
- package/dist/hooks/use-drop-down-selection.d.ts +0 -16
- package/dist/hooks/use-drop-down-selection.d.ts.map +0 -1
- package/dist/hooks/use-drop-down-selection.js +0 -35
- package/dist/hooks/use-drop-down-selection.js.map +0 -1
- package/dist/hooks/use-expansion-model.d.ts +0 -12
- package/dist/hooks/use-expansion-model.d.ts.map +0 -1
- package/dist/hooks/use-expansion-model.js +0 -71
- package/dist/hooks/use-expansion-model.js.map +0 -1
- package/dist/hooks/use-header-menu.d.ts +0 -4
- package/dist/hooks/use-header-menu.d.ts.map +0 -1
- package/dist/hooks/use-header-menu.js +0 -20
- package/dist/hooks/use-header-menu.js.map +0 -1
- package/dist/hooks/use-installed-model.d.ts +0 -4
- package/dist/hooks/use-installed-model.d.ts.map +0 -1
- package/dist/hooks/use-installed-model.js +0 -15
- package/dist/hooks/use-installed-model.js.map +0 -1
- package/dist/hooks/use-list-model.d.ts +0 -19
- package/dist/hooks/use-list-model.d.ts.map +0 -1
- package/dist/hooks/use-list-model.js +0 -97
- package/dist/hooks/use-list-model.js.map +0 -1
- package/dist/hooks/use-placed-child.d.ts +0 -18
- package/dist/hooks/use-placed-child.d.ts.map +0 -1
- package/dist/hooks/use-placed-child.js +0 -47
- package/dist/hooks/use-placed-child.js.map +0 -1
- package/dist/hooks/use-selection-model.d.ts +0 -13
- package/dist/hooks/use-selection-model.d.ts.map +0 -1
- package/dist/hooks/use-selection-model.js +0 -103
- package/dist/hooks/use-selection-model.js.map +0 -1
- package/dist/hooks/use-sort-handler.d.ts +0 -17
- package/dist/hooks/use-sort-handler.d.ts.map +0 -1
- package/dist/hooks/use-sort-handler.js +0 -87
- package/dist/hooks/use-sort-handler.js.map +0 -1
- package/dist/menu-items.d.ts +0 -5
- package/dist/menu-items.d.ts.map +0 -1
- package/dist/menu-items.js +0 -48
- package/dist/menu-items.js.map +0 -1
- package/dist/menu.d.ts +0 -14
- package/dist/menu.d.ts.map +0 -1
- package/dist/menu.js +0 -24
- package/dist/menu.js.map +0 -1
- package/dist/overlay.d.ts +0 -24
- package/dist/overlay.d.ts.map +0 -1
- package/dist/overlay.js +0 -49
- package/dist/overlay.js.map +0 -1
- package/dist/utils/cell-container-store.d.ts +0 -28
- package/dist/utils/cell-container-store.d.ts.map +0 -1
- package/dist/utils/cell-container-store.js +0 -98
- package/dist/utils/cell-container-store.js.map +0 -1
- package/dist/utils/item-models.d.ts +0 -10
- package/dist/utils/item-models.d.ts.map +0 -1
- package/dist/utils/item-models.js +0 -82
- package/dist/utils/item-models.js.map +0 -1
- package/dist/utils/item-resolver.d.ts +0 -25
- package/dist/utils/item-resolver.d.ts.map +0 -1
- package/dist/utils/item-resolver.js +0 -102
- package/dist/utils/item-resolver.js.map +0 -1
- package/dist/utils/list-item-flatten.d.ts +0 -24
- package/dist/utils/list-item-flatten.d.ts.map +0 -1
- package/dist/utils/list-item-flatten.js +0 -68
- package/dist/utils/list-item-flatten.js.map +0 -1
- package/src/cell.tsx +0 -144
- package/src/column-view-column.tsx +0 -82
- package/src/constraint-layout-apply.ts +0 -173
- package/src/constraint-layout.tsx +0 -135
- package/src/fixed.tsx +0 -86
- package/src/grid.tsx +0 -88
- package/src/hooks/use-cell-containers.ts +0 -93
- package/src/hooks/use-collection-model.ts +0 -60
- package/src/hooks/use-collection-widget.ts +0 -47
- package/src/hooks/use-drop-down-selection.ts +0 -52
- package/src/hooks/use-expansion-model.ts +0 -82
- package/src/hooks/use-header-menu.ts +0 -34
- package/src/hooks/use-installed-model.ts +0 -20
- package/src/hooks/use-list-model.ts +0 -161
- package/src/hooks/use-placed-child.ts +0 -79
- package/src/hooks/use-selection-model.ts +0 -114
- package/src/hooks/use-sort-handler.ts +0 -107
- package/src/menu-items.ts +0 -48
- package/src/menu.tsx +0 -32
- package/src/overlay.tsx +0 -88
- package/src/utils/cell-container-store.ts +0 -114
- package/src/utils/item-models.ts +0 -113
- package/src/utils/item-resolver.ts +0 -138
- package/src/utils/list-item-flatten.ts +0 -90
package/dist/drop-down.js
CHANGED
|
@@ -1,89 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GtkDropDown
|
|
3
|
-
import {
|
|
4
|
-
import { useCallback, useRef, useState } from "react";
|
|
5
|
-
import { CellRenderHost, HeaderRenderHost, itemRenderer } from "./cell.js";
|
|
6
|
-
import { makeFactoryInstaller, useCellContainers } from "./hooks/use-cell-containers.js";
|
|
7
|
-
import { useDropDownSelection } from "./hooks/use-drop-down-selection.js";
|
|
8
|
-
import { useInstalledModel } from "./hooks/use-installed-model.js";
|
|
9
|
-
import { useListModel } from "./hooks/use-list-model.js";
|
|
10
|
-
const itemFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setFactory(factory));
|
|
11
|
-
const listFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setListFactory(factory));
|
|
12
|
-
const headerFactoryInstaller = makeFactoryInstaller((widget, factory) => widget.setHeaderFactory(factory));
|
|
13
|
-
const defaultRenderer = (value) => {
|
|
14
|
-
if (value === undefined || value === null)
|
|
15
|
-
return null;
|
|
16
|
-
return _jsx(GtkLabel, { children: String(value) });
|
|
17
|
-
};
|
|
18
|
-
const toItemRenderer = (renderItem) => {
|
|
19
|
-
if (typeof renderItem !== "function")
|
|
20
|
-
return defaultRenderer;
|
|
21
|
-
return itemRenderer(renderItem);
|
|
22
|
-
};
|
|
23
|
-
const toListRenderer = (renderListItem, renderItem) => {
|
|
24
|
-
if (typeof renderListItem === "function")
|
|
25
|
-
return itemRenderer(renderListItem);
|
|
26
|
-
return toItemRenderer(renderItem);
|
|
27
|
-
};
|
|
28
|
-
const createSelectionResolver = (resolver, selectedPosition) => ({
|
|
29
|
-
positionOfId: (id) => resolver.positionOfId(id),
|
|
30
|
-
idOf: (position) => resolver.idOf(position),
|
|
31
|
-
resolve: (_position, treeRow) => resolver.resolve(selectedPosition, treeRow),
|
|
32
|
-
});
|
|
33
|
-
const useDropDownWiring = (props) => {
|
|
34
|
-
const widgetRef = useRef(null);
|
|
35
|
-
const [widget, setWidget] = useState(null);
|
|
36
|
-
const captureWidget = useCallback((value) => {
|
|
37
|
-
widgetRef.current = value;
|
|
38
|
-
setWidget(value);
|
|
39
|
-
}, []);
|
|
40
|
-
const setRef = useMergeRefs(props.ref, captureWidget);
|
|
41
|
-
const listModel = useListModel({ items: props.items, sections: props.sections });
|
|
42
|
-
const useHeader = typeof props.renderHeader === "function";
|
|
43
|
-
const selectionStore = useCellContainers({ object: widgetRef, installer: itemFactoryInstaller });
|
|
44
|
-
const listStore = useCellContainers({ object: widgetRef, installer: listFactoryInstaller });
|
|
45
|
-
const headerStore = useCellContainers({
|
|
46
|
-
object: useHeader ? widgetRef : null,
|
|
47
|
-
installer: headerFactoryInstaller,
|
|
48
|
-
});
|
|
49
|
-
useInstalledModel(widgetRef, listModel.model, (widget, value) => widget.setModel(value));
|
|
50
|
-
const selectedPosition = useDropDownSelection({
|
|
51
|
-
widget,
|
|
52
|
-
resolver: listModel.resolver,
|
|
53
|
-
selectedId: props.selectedId,
|
|
54
|
-
onSelectionChanged: props.onSelectionChanged,
|
|
55
|
-
});
|
|
56
|
-
const controlledPosition = props.selectedId === undefined || props.selectedId === null
|
|
57
|
-
? -1
|
|
58
|
-
: listModel.resolver.positionOfId(props.selectedId);
|
|
59
|
-
const selectionPosition = controlledPosition >= 0 ? controlledPosition : selectedPosition < 0 ? 0 : selectedPosition;
|
|
60
|
-
return {
|
|
61
|
-
setRef,
|
|
62
|
-
resolver: listModel.resolver,
|
|
63
|
-
selectionResolver: createSelectionResolver(listModel.resolver, selectionPosition),
|
|
64
|
-
headerResolver: listModel.headerResolver,
|
|
65
|
-
selectionStore,
|
|
66
|
-
listStore,
|
|
67
|
-
headerStore,
|
|
68
|
-
useHeader,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { GtkDropDown } from "@gtkx/jsx/gtk";
|
|
3
|
+
import { DropDownBase } from "./internal/drop-down.js";
|
|
71
4
|
/**
|
|
72
|
-
* Renders a
|
|
73
|
-
*
|
|
74
|
-
* headers.
|
|
5
|
+
* Renders a `Gtk.DropDown` backed by a collection model, with customizable renderers for the
|
|
6
|
+
* collapsed display, popup rows, and popup section headers, and controlled selection.
|
|
75
7
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
items,
|
|
82
|
-
sections,
|
|
83
|
-
selectedId,
|
|
84
|
-
onSelectionChanged,
|
|
85
|
-
renderHeader,
|
|
86
|
-
});
|
|
87
|
-
return (_jsxs(_Fragment, { children: [_jsx(Component, { ...intrinsicProps, ref: wiring.setRef }), _jsx(CellRenderHost, { store: wiring.selectionStore, resolver: wiring.selectionResolver, render: toItemRenderer(renderItem) }), _jsx(CellRenderHost, { store: wiring.listStore, resolver: wiring.resolver, render: toListRenderer(renderListItem, renderItem) }), _jsx(HeaderRenderHost, { useHeader: wiring.useHeader, store: wiring.headerStore, resolver: wiring.headerResolver, renderHeader: renderHeader })] }));
|
|
88
|
-
};
|
|
8
|
+
const DropDown = DropDownImpl;
|
|
9
|
+
function DropDownImpl(props) {
|
|
10
|
+
return _jsx(DropDownBase, { ...props, component: GtkDropDown });
|
|
11
|
+
}
|
|
12
|
+
export { DropDown };
|
|
89
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":";AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAA8C,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClG,OAAO,EAAqB,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAE,oBAAoB,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pB,GAAG,KAAK,CAAC;IACV,MAAM,SAAS,GAAgB,SAAS,IAAI,WAAW,CAAC;IAExD,MAAM,MAAM,GAAG,iBAAiB,CAAO;QACnC,GAAG;QACH,KAAK;QACL,QAAQ;QACR,UAAU;QACV,kBAAkB;QAClB,YAAY;KACf,CAAC,CAAC;IAEH,OAAO,CACH,8BACI,KAAC,SAAS,OAAK,cAAc,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,GAAI,EACrD,KAAC,cAAc,IACX,KAAK,EAAE,MAAM,CAAC,cAAc,EAC5B,QAAQ,EAAE,MAAM,CAAC,iBAAiB,EAClC,MAAM,EAAE,cAAc,CAAO,UAAU,CAAC,GAC1C,EACF,KAAC,cAAc,IACX,KAAK,EAAE,MAAM,CAAC,SAAS,EACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,MAAM,EAAE,cAAc,CAAO,cAAc,EAAE,UAAU,CAAC,GAC1D,EACF,KAAC,gBAAgB,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,KAAK,EAAE,MAAM,CAAC,WAAW,EACzB,QAAQ,EAAE,MAAM,CAAC,cAAc,EAC/B,YAAY,EAAE,YAAY,GAC5B,IACH,CACN,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkDropDown, GtkLabel } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { type ElementType, type ReactNode, type Ref, useCallback, useRef, useState } from \"react\";\nimport { type CellRenderer, CellRenderHost, HeaderRenderHost, itemRenderer } from \"./cell.js\";\nimport { makeFactoryInstaller, useCellContainers } from \"./hooks/use-cell-containers.js\";\nimport { useDropDownSelection } from \"./hooks/use-drop-down-selection.js\";\nimport { useInstalledModel } from \"./hooks/use-installed-model.js\";\nimport { useListModel } from \"./hooks/use-list-model.js\";\nimport type { ItemNode, RenderItemProps, SectionNode, WidgetProps } from \"./types.js\";\nimport type { CellContainerStore } from \"./utils/cell-container-store.js\";\nimport type { ItemResolver } from \"./utils/item-resolver.js\";\n\nexport type DropDownItemRenderer<T> = (props: RenderItemProps<T>) => ReactNode;\n\nconst itemFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) => widget.setFactory(factory));\n\nconst listFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) => widget.setListFactory(factory));\n\nconst headerFactoryInstaller = makeFactoryInstaller<Gtk.DropDown>((widget, factory) =>\n widget.setHeaderFactory(factory),\n);\n\nconst defaultRenderer: CellRenderer<unknown, unknown> = (value) => {\n if (value === undefined || value === null) return null;\n return <GtkLabel>{String(value)}</GtkLabel>;\n};\n\nconst toItemRenderer = <T, S>(renderItem: DropDownItemRenderer<T> | null | undefined): CellRenderer<T, S> => {\n if (typeof renderItem !== \"function\") return defaultRenderer as CellRenderer<T, S>;\n return itemRenderer<T, S>(renderItem);\n};\n\nconst toListRenderer = <T, S>(\n renderListItem: DropDownItemRenderer<T> | null | undefined,\n renderItem: DropDownItemRenderer<T> | null | undefined,\n): CellRenderer<T, S> => {\n if (typeof renderListItem === \"function\") return itemRenderer<T, S>(renderListItem);\n return toItemRenderer<T, S>(renderItem);\n};\n\nconst createSelectionResolver = <T, S>(resolver: ItemResolver<T, S>, selectedPosition: number): ItemResolver<T, S> => ({\n positionOfId: (id) => resolver.positionOfId(id),\n idOf: (position) => resolver.idOf(position),\n resolve: (_position, treeRow) => resolver.resolve(selectedPosition, treeRow),\n});\n\n/** Declarative props for {@link DropDown}'s backing collection and cell rendering. */\nexport type DropDownDeclarativeProps<T = unknown, S = unknown> = {\n items?: ItemNode<T>[] | undefined;\n sections?: SectionNode<S, T>[] | undefined;\n /** Id of the currently selected item, making the selection controlled. */\n selectedId?: string | null | undefined;\n onSelectionChanged?: ((id: string) => void) | null | undefined;\n renderItem?: DropDownItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: DropDownItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: ((info: { section: S }) => ReactNode) | null | undefined;\n};\n\n/**\n * Props for {@link DropDown}. The backing widget is chosen through the `component` prop, defaulting to\n * GtkDropDown, and its own props combine with {@link DropDownDeclarativeProps}.\n */\nexport type DropDownProps<T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown> = WidgetProps<\n C,\n DropDownDeclarativeProps<T, S>,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\"\n>;\n\ninterface NormalizedDropDownProps<T, S> {\n ref: Ref<Gtk.DropDown | null> | undefined;\n items: ItemNode<T>[] | undefined;\n sections: SectionNode<S, T>[] | undefined;\n selectedId: string | null | undefined;\n onSelectionChanged: ((id: string) => void) | null | undefined;\n renderHeader: ((info: { section: S }) => ReactNode) | null | undefined;\n}\n\ninterface DropDownWiring<T, S> {\n setRef: (value: Gtk.DropDown | null) => void;\n resolver: ItemResolver<T, S>;\n selectionResolver: ItemResolver<T, S>;\n headerResolver: ItemResolver<T, S>;\n selectionStore: CellContainerStore;\n listStore: CellContainerStore;\n headerStore: CellContainerStore;\n useHeader: boolean;\n}\n\nconst useDropDownWiring = <T, S>(props: NormalizedDropDownProps<T, S>): DropDownWiring<T, S> => {\n const widgetRef = useRef<Gtk.DropDown | null>(null);\n const [widget, setWidget] = useState<Gtk.DropDown | null>(null);\n const captureWidget = useCallback((value: Gtk.DropDown | null) => {\n widgetRef.current = value;\n setWidget(value);\n }, []);\n const setRef = useMergeRefs<Gtk.DropDown>(props.ref, captureWidget);\n\n const listModel = useListModel<T, S>({ items: props.items, sections: props.sections });\n\n const useHeader = typeof props.renderHeader === \"function\";\n\n const selectionStore = useCellContainers<Gtk.DropDown>({ object: widgetRef, installer: itemFactoryInstaller });\n const listStore = useCellContainers<Gtk.DropDown>({ object: widgetRef, installer: listFactoryInstaller });\n const headerStore = useCellContainers<Gtk.DropDown>({\n object: useHeader ? widgetRef : null,\n installer: headerFactoryInstaller,\n });\n\n useInstalledModel(widgetRef, listModel.model, (widget, value) => widget.setModel(value));\n\n const selectedPosition = useDropDownSelection<T, S>({\n widget,\n resolver: listModel.resolver,\n selectedId: props.selectedId,\n onSelectionChanged: props.onSelectionChanged,\n });\n\n const controlledPosition =\n props.selectedId === undefined || props.selectedId === null\n ? -1\n : listModel.resolver.positionOfId(props.selectedId);\n const selectionPosition =\n controlledPosition >= 0 ? controlledPosition : selectedPosition < 0 ? 0 : selectedPosition;\n\n return {\n setRef,\n resolver: listModel.resolver,\n selectionResolver: createSelectionResolver(listModel.resolver, selectionPosition),\n headerResolver: listModel.headerResolver,\n selectionStore,\n listStore,\n headerStore,\n useHeader,\n };\n};\n\n/**\n * Renders a drop-down widget (Gtk.DropDown by default, or the widget given as `component`) backed by a\n * collection model, with customizable rendering for the selected item, the popup list rows, and section\n * headers.\n */\nexport const DropDown = <T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown>(\n props: DropDownProps<T, S, C>,\n): ReactNode => {\n const {\n component,\n ref,\n items,\n sections,\n renderItem,\n renderListItem,\n renderHeader,\n selectedId,\n onSelectionChanged,\n ...intrinsicProps\n } = props;\n const Component: ElementType = component ?? GtkDropDown;\n\n const wiring = useDropDownWiring<T, S>({\n ref,\n items,\n sections,\n selectedId,\n onSelectionChanged,\n renderHeader,\n });\n\n return (\n <>\n <Component {...intrinsicProps} ref={wiring.setRef} />\n <CellRenderHost\n store={wiring.selectionStore}\n resolver={wiring.selectionResolver}\n render={toItemRenderer<T, S>(renderItem)}\n />\n <CellRenderHost\n store={wiring.listStore}\n resolver={wiring.resolver}\n render={toListRenderer<T, S>(renderListItem, renderItem)}\n />\n <HeaderRenderHost\n useHeader={wiring.useHeader}\n store={wiring.headerStore}\n resolver={wiring.headerResolver}\n renderHeader={renderHeader}\n />\n </>\n );\n};\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/grid-view.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { CollectionItemSizeProps, ControlledSelectionProps, ItemNode, RenderItemProps } from "./types.js";
|
|
4
|
-
export type GridViewDeclarativeProps<T = unknown> = CollectionItemSizeProps & ControlledSelectionProps & {
|
|
5
|
-
items?: ItemNode<T>[] | undefined;
|
|
6
|
-
renderItem: (props: RenderItemProps<T>) => ReactNode;
|
|
7
|
-
};
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { GridViewProps } from "./types.js";
|
|
8
3
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and estimated item sizing.
|
|
4
|
+
* Renders a Gtk.GridView of uniform cells from declarative items, with per-cell
|
|
5
|
+
* rendering, controlled selection, and estimated item sizing.
|
|
12
6
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Renders a Gtk.GridView: a scrollable grid of uniformly sized cells backed by a
|
|
16
|
-
* collection model, with each cell drawn by renderItem.
|
|
17
|
-
*/
|
|
18
|
-
export declare const GridView: <T = unknown>(props: GridViewProps<T>) => ReactNode;
|
|
7
|
+
declare function GridView<T = unknown>(props: GridViewProps<T>): ReactNode;
|
|
8
|
+
export { GridView };
|
|
19
9
|
//# sourceMappingURL=grid-view.d.ts.map
|
package/dist/grid-view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-view.d.ts","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grid-view.d.ts","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAchD;;;GAGG;AACH,iBAAS,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,CAajE;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/grid-view.js
CHANGED
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GtkGridView } from "@gtkx/jsx/gtk";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { GtkGridView, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
|
|
3
|
+
import { omit } from "@gtkx/utils";
|
|
4
|
+
import { ItemPortals, useItemCells } from "./internal/cells.js";
|
|
5
|
+
import { useCollection } from "./internal/use-collection.js";
|
|
6
|
+
const GRID_VIEW_PROPS = [
|
|
7
|
+
"items",
|
|
8
|
+
"renderItem",
|
|
9
|
+
"selectedIds",
|
|
10
|
+
"onSelectionChanged",
|
|
11
|
+
"selectionMode",
|
|
12
|
+
"estimatedItemHeight",
|
|
13
|
+
"estimatedItemWidth",
|
|
14
|
+
];
|
|
10
15
|
/**
|
|
11
|
-
* Renders a Gtk.GridView
|
|
12
|
-
*
|
|
16
|
+
* Renders a Gtk.GridView of uniform cells from declarative items, with per-cell
|
|
17
|
+
* rendering, controlled selection, and estimated item sizing.
|
|
13
18
|
*/
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
selectedIds,
|
|
24
|
-
onSelectionChanged,
|
|
25
|
-
renderHeader: undefined,
|
|
26
|
-
});
|
|
27
|
-
const itemStore = useCellContainers({
|
|
28
|
-
object: widgetRef,
|
|
29
|
-
installer: factoryInstaller,
|
|
30
|
-
estimatedHeight: estimatedItemHeight,
|
|
31
|
-
estimatedWidth: estimatedItemWidth,
|
|
32
|
-
});
|
|
33
|
-
useInstalledModel(widgetRef, collection.installedModel, (widget, value) => widget.setModel(value));
|
|
34
|
-
return (_jsxs(_Fragment, { children: [_jsx(GtkGridView, { ...intrinsicProps, ref: setRef }), _jsx(CellRenderHost, { store: itemStore, resolver: collection.resolver, render: cellRenderer })] }));
|
|
35
|
-
};
|
|
19
|
+
function GridView(props) {
|
|
20
|
+
const { renderItem, estimatedItemHeight, estimatedItemWidth } = props;
|
|
21
|
+
const rest = omit(props, GRID_VIEW_PROPS);
|
|
22
|
+
const size = { width: estimatedItemWidth ?? -1, height: estimatedItemHeight ?? -1 };
|
|
23
|
+
const { collection, selection } = useCollection({ ...props, flat: true });
|
|
24
|
+
const itemCells = useItemCells(size);
|
|
25
|
+
return (_jsxs(_Fragment, { children: [_jsx(GtkGridView, { model: selection, factory: _jsx(GtkSignalListItemFactory, { ...itemCells.handlers }), ...rest }), _jsx(ItemPortals, { store: itemCells, render: renderItem, collection: collection })] }));
|
|
26
|
+
}
|
|
27
|
+
export { GridView };
|
|
36
28
|
//# sourceMappingURL=grid-view.js.map
|
package/dist/grid-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-view.js","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"grid-view.js","sourceRoot":"","sources":["../src/grid-view.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,eAAe,GAAG;IACpB,OAAO;IACP,YAAY;IACZ,aAAa;IACb,oBAAoB;IACpB,eAAe;IACf,qBAAqB;IACrB,oBAAoB;CACoB,CAAC;AAE7C;;;GAGG;AACH,SAAS,QAAQ,CAAc,KAAuB;IAClD,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,kBAAkB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,IAAI,CAAC,CAAC,EAAE,CAAC;IACpF,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAErC,OAAO,CACH,8BACI,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAC,wBAAwB,OAAK,SAAS,CAAC,QAAQ,GAAI,KAAM,IAAI,GAAI,EAC1G,KAAC,WAAW,IAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAI,IAC9E,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { GtkGridView, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { omit } from \"@gtkx/utils\";\nimport type { GridViewProps } from \"./types.js\";\nimport { ItemPortals, useItemCells } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\n\nconst GRID_VIEW_PROPS = [\n \"items\",\n \"renderItem\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"estimatedItemHeight\",\n \"estimatedItemWidth\",\n] as const satisfies (keyof GridViewProps)[];\n\n/**\n * Renders a Gtk.GridView of uniform cells from declarative items, with per-cell\n * rendering, controlled selection, and estimated item sizing.\n */\nfunction GridView<T = unknown>(props: GridViewProps<T>): ReactNode {\n const { renderItem, estimatedItemHeight, estimatedItemWidth } = props;\n const rest = omit(props, GRID_VIEW_PROPS);\n const size = { width: estimatedItemWidth ?? -1, height: estimatedItemHeight ?? -1 };\n const { collection, selection } = useCollection({ ...props, flat: true });\n const itemCells = useItemCells(size);\n\n return (\n <>\n <GtkGridView model={selection} factory={<GtkSignalListItemFactory {...itemCells.handlers} />} {...rest} />\n <ItemPortals store={itemCells} render={renderItem} collection={collection} />\n </>\n );\n}\n\nexport { GridView };\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { GridView, type GridViewDeclarativeProps, type GridViewProps } from "./grid-view.js";
|
|
8
|
-
export { ListView, type ListViewDeclarativeProps, type ListViewProps } from "./list-view.js";
|
|
9
|
-
export { Menu, type MenuItemsProps, type MenuProps } from "./menu.js";
|
|
10
|
-
export { Overlay, type OverlayChildProps, type OverlayPlacementProps, type OverlayProps } from "./overlay.js";
|
|
11
|
-
export { SizeGroup, type SizeGroupChildProps, type SizeGroupProps } from "./size-group.js";
|
|
12
|
-
export type { ChildProps, CollectionItemSizeProps, ControlledExpansionProps, ControlledSelectionProps, ItemNode, MenuEntry, RenderItemProps, SectionNode, WidgetProps, } from "./types.js";
|
|
1
|
+
export { ColumnView } from "./column-view.js";
|
|
2
|
+
export { DropDown } from "./drop-down.js";
|
|
3
|
+
export { GridView } from "./grid-view.js";
|
|
4
|
+
export { ListView } from "./list-view.js";
|
|
5
|
+
export { SizeGroup } from "./size-group.js";
|
|
6
|
+
export type { ChildProps, Column, ColumnViewProps, DropDownProps, GridViewProps, HeaderRenderer, Item, ItemRenderer, ListViewProps, RenderHeaderArgs, RenderItemArgs, Section, SizeGroupChildProps, SizeGroupProps, } from "./types.js";
|
|
13
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,
|
|
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
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
export { ColumnView
|
|
2
|
-
export { ConstraintLayout } from "./constraint-layout.js";
|
|
1
|
+
export { ColumnView } from "./column-view.js";
|
|
3
2
|
export { DropDown } from "./drop-down.js";
|
|
4
|
-
export { Fixed } from "./fixed.js";
|
|
5
|
-
export { Grid } from "./grid.js";
|
|
6
3
|
export { GridView } from "./grid-view.js";
|
|
7
4
|
export { ListView } from "./list-view.js";
|
|
8
|
-
export { Menu } from "./menu.js";
|
|
9
|
-
export { Overlay } from "./overlay.js";
|
|
10
5
|
export { SizeGroup } from "./size-group.js";
|
|
11
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,50 @@
|
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
4
|
+
import type { HeaderRenderer, ItemRenderer } from "../types.js";
|
|
5
|
+
import type { Collection } from "./collection.js";
|
|
6
|
+
type CellSize = {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
type CellHost = GObject.Object & {
|
|
11
|
+
getChild: () => Gtk.Widget | null;
|
|
12
|
+
setChild: (child: Gtk.Widget | null) => void;
|
|
13
|
+
};
|
|
14
|
+
type CellEntry<C extends CellHost> = {
|
|
15
|
+
key: string;
|
|
16
|
+
cell: C;
|
|
17
|
+
item: GObject.Object | null;
|
|
18
|
+
listeners: Set<() => void>;
|
|
19
|
+
subscribe: (onChange: () => void) => () => void;
|
|
20
|
+
getItem: () => GObject.Object | null;
|
|
21
|
+
};
|
|
22
|
+
type FactoryHandlers = {
|
|
23
|
+
onSetup: (cell: GObject.Object) => void;
|
|
24
|
+
onBind: (cell: GObject.Object) => void;
|
|
25
|
+
onUnbind: (cell: GObject.Object) => void;
|
|
26
|
+
onTeardown: (cell: GObject.Object) => void;
|
|
27
|
+
};
|
|
28
|
+
type CellStore<C extends CellHost> = {
|
|
29
|
+
handlers: FactoryHandlers;
|
|
30
|
+
setSize: (size: CellSize) => void;
|
|
31
|
+
subscribe: (onChange: () => void) => () => void;
|
|
32
|
+
getSnapshot: () => CellEntry<C>[];
|
|
33
|
+
};
|
|
34
|
+
type ItemPortalsProps = {
|
|
35
|
+
store: CellStore<Gtk.ListItem>;
|
|
36
|
+
render: ItemRenderer<never>;
|
|
37
|
+
collection: Collection;
|
|
38
|
+
expandedIds?: string[] | null | undefined;
|
|
39
|
+
};
|
|
40
|
+
type HeaderPortalsProps = {
|
|
41
|
+
store: CellStore<Gtk.ListHeader>;
|
|
42
|
+
render: HeaderRenderer<never>;
|
|
43
|
+
collection: Collection;
|
|
44
|
+
};
|
|
45
|
+
declare function useItemCells(size: CellSize): CellStore<Gtk.ListItem>;
|
|
46
|
+
declare function useHeaderCells(size: CellSize): CellStore<Gtk.ListHeader>;
|
|
47
|
+
declare const ItemPortals: ({ store, render, collection, expandedIds }: ItemPortalsProps) => ReactNode;
|
|
48
|
+
declare const HeaderPortals: ({ store, render, collection }: HeaderPortalsProps) => ReactNode;
|
|
49
|
+
export { useItemCells, useHeaderCells, ItemPortals, HeaderPortals, type CellSize, type CellStore, };
|
|
50
|
+
//# sourceMappingURL=cells.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cells.d.ts","sourceRoot":"","sources":["../../src/internal/cells.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAQ,YAAY,EAAkB,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,QAAQ,GAAG;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG;IAC7B,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,KAAK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BAAkB,GAAG;IACtB,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACjC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;CAC1B,CAAC;AAyJF,iBAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAE7D;AAED,iBAAS,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAEjE;AAiFD,QAAA,MAAM,WAAW,GAAI,4CAA4C,gBAAgB,KAAG,SAG9E,CAAC;AAEP,QAAA,MAAM,aAAa,GAAI,+BAA+B,kBAAkB,KAAG,SAGrE,CAAC;AAEP,OAAO,EACH,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,KAAK,QAAQ,EACb,KAAK,SAAS,GACjB,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
+
import { GtkTreeExpander } from "@gtkx/jsx/gtk";
|
|
4
|
+
import { createPortal, useProperty } from "@gtkx/react";
|
|
5
|
+
import { memo, useLayoutEffect, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { getId } from "./collection-model.js";
|
|
7
|
+
const ItemCell = memo(ItemCellImpl);
|
|
8
|
+
const HeaderCell = memo(HeaderCellImpl);
|
|
9
|
+
const isListItem = (value) => value instanceof Gtk.ListItem;
|
|
10
|
+
const isListHeader = (value) => value instanceof Gtk.ListHeader;
|
|
11
|
+
const placeholder = (size) => new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });
|
|
12
|
+
function notifyEntry(entry) {
|
|
13
|
+
for (const listener of entry.listeners) {
|
|
14
|
+
listener();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function notifyRoster(state) {
|
|
18
|
+
state.snapshot = null;
|
|
19
|
+
for (const listener of state.listeners) {
|
|
20
|
+
listener();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function createEntry(state, cell) {
|
|
24
|
+
state.serial += 1;
|
|
25
|
+
const entry = {
|
|
26
|
+
key: `gtkx-cell-${String(state.serial)}`,
|
|
27
|
+
cell,
|
|
28
|
+
item: null,
|
|
29
|
+
listeners: new Set(),
|
|
30
|
+
subscribe: (onChange) => {
|
|
31
|
+
entry.listeners.add(onChange);
|
|
32
|
+
return () => {
|
|
33
|
+
entry.listeners.delete(onChange);
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
getItem: () => entry.item,
|
|
37
|
+
};
|
|
38
|
+
return entry;
|
|
39
|
+
}
|
|
40
|
+
function setupCell(state, cell) {
|
|
41
|
+
cell.setChild(placeholder(state.size));
|
|
42
|
+
state.entries.set(cell, createEntry(state, cell));
|
|
43
|
+
notifyRoster(state);
|
|
44
|
+
}
|
|
45
|
+
function teardownCell(state, cell) {
|
|
46
|
+
if (state.entries.delete(cell)) {
|
|
47
|
+
notifyRoster(state);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function writeBinding(state, cell, item) {
|
|
51
|
+
const entry = state.entries.get(cell);
|
|
52
|
+
if (entry === undefined) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
entry.item = item;
|
|
56
|
+
notifyEntry(entry);
|
|
57
|
+
}
|
|
58
|
+
function boundItem(cell) {
|
|
59
|
+
if (cell instanceof Gtk.ListItem) {
|
|
60
|
+
return cell.getItem();
|
|
61
|
+
}
|
|
62
|
+
return cell instanceof Gtk.ListHeader ? cell.getItem() : null;
|
|
63
|
+
}
|
|
64
|
+
function bindCell(state, cell) {
|
|
65
|
+
if (cell.getChild() === null) {
|
|
66
|
+
cell.setChild(placeholder(state.size));
|
|
67
|
+
}
|
|
68
|
+
writeBinding(state, cell, boundItem(cell));
|
|
69
|
+
}
|
|
70
|
+
function subscribeRoster(state, onChange) {
|
|
71
|
+
state.listeners.add(onChange);
|
|
72
|
+
return () => {
|
|
73
|
+
state.listeners.delete(onChange);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function rosterSnapshot(state) {
|
|
77
|
+
state.snapshot ??= state.entries.values().toArray();
|
|
78
|
+
return state.snapshot;
|
|
79
|
+
}
|
|
80
|
+
function guarded(isCell, run) {
|
|
81
|
+
return (cell) => {
|
|
82
|
+
if (isCell(cell)) {
|
|
83
|
+
run(cell);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createHandlers(state, isCell) {
|
|
88
|
+
return {
|
|
89
|
+
onSetup: guarded(isCell, (cell) => {
|
|
90
|
+
setupCell(state, cell);
|
|
91
|
+
}),
|
|
92
|
+
onBind: guarded(isCell, (cell) => {
|
|
93
|
+
bindCell(state, cell);
|
|
94
|
+
}),
|
|
95
|
+
onUnbind: guarded(isCell, (cell) => {
|
|
96
|
+
writeBinding(state, cell, null);
|
|
97
|
+
}),
|
|
98
|
+
onTeardown: guarded(isCell, (cell) => {
|
|
99
|
+
teardownCell(state, cell);
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function createCellStore(isCell, size) {
|
|
104
|
+
const state = {
|
|
105
|
+
size,
|
|
106
|
+
entries: new Map(),
|
|
107
|
+
snapshot: null,
|
|
108
|
+
listeners: new Set(),
|
|
109
|
+
serial: 0,
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
handlers: createHandlers(state, isCell),
|
|
113
|
+
setSize: (next) => {
|
|
114
|
+
state.size = next;
|
|
115
|
+
},
|
|
116
|
+
subscribe: (onChange) => subscribeRoster(state, onChange),
|
|
117
|
+
getSnapshot: () => rosterSnapshot(state),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function useCellStore(isCell, size) {
|
|
121
|
+
const [store] = useState(() => createCellStore(isCell, size));
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
store.setSize(size);
|
|
124
|
+
});
|
|
125
|
+
return store;
|
|
126
|
+
}
|
|
127
|
+
function useItemCells(size) {
|
|
128
|
+
return useCellStore(isListItem, size);
|
|
129
|
+
}
|
|
130
|
+
function useHeaderCells(size) {
|
|
131
|
+
return useCellStore(isListHeader, size);
|
|
132
|
+
}
|
|
133
|
+
function isRowWanted(options, item) {
|
|
134
|
+
const { expandedIds } = options;
|
|
135
|
+
return expandedIds == null ? options.isRowExpanded === true : expandedIds.includes(item.id);
|
|
136
|
+
}
|
|
137
|
+
function itemArgs(item, options) {
|
|
138
|
+
const args = { item: item.value, index: options.position ?? 0 };
|
|
139
|
+
const row = options.row;
|
|
140
|
+
if (row === null) {
|
|
141
|
+
return args;
|
|
142
|
+
}
|
|
143
|
+
args.depth = row.getDepth();
|
|
144
|
+
if (row.isExpandable()) {
|
|
145
|
+
args.isExpanded = isRowWanted(options, item);
|
|
146
|
+
}
|
|
147
|
+
return args;
|
|
148
|
+
}
|
|
149
|
+
function wrapExpander(item, row, content) {
|
|
150
|
+
const expander = row === null
|
|
151
|
+
? (content)
|
|
152
|
+
: (_jsx(GtkTreeExpander, { listRow: row, hideExpander: item.hideExpander ?? false, indentForDepth: item.indentForDepth ?? true, indentForIcon: item.indentForIcon ?? true, children: content }));
|
|
153
|
+
return expander;
|
|
154
|
+
}
|
|
155
|
+
function itemBody(options) {
|
|
156
|
+
const id = getId(options.item);
|
|
157
|
+
const item = id === null ? undefined : options.collection.itemFor(id);
|
|
158
|
+
if (item === undefined) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const render = options.render;
|
|
162
|
+
return wrapExpander(item, options.row, render(itemArgs(item, options)));
|
|
163
|
+
}
|
|
164
|
+
function ItemCellImpl({ entry, render, collection, expandedIds }) {
|
|
165
|
+
const item = useSyncExternalStore(entry.subscribe, entry.getItem);
|
|
166
|
+
const position = useProperty(entry.cell, "position");
|
|
167
|
+
const row = item instanceof Gtk.TreeListRow ? item : null;
|
|
168
|
+
const isRowExpanded = useProperty(row, "expanded");
|
|
169
|
+
const body = itemBody({ item, position, row, isRowExpanded, render, collection, expandedIds });
|
|
170
|
+
return createPortal(body, entry.cell, entry.key);
|
|
171
|
+
}
|
|
172
|
+
function HeaderCellImpl({ entry, render, collection }) {
|
|
173
|
+
const item = useSyncExternalStore(entry.subscribe, entry.getItem);
|
|
174
|
+
const id = getId(item);
|
|
175
|
+
const renderHeader = render;
|
|
176
|
+
const body = id === null ? null : renderHeader({ section: collection.sectionFor(id) });
|
|
177
|
+
return createPortal(body, entry.cell, entry.key);
|
|
178
|
+
}
|
|
179
|
+
function usePortalEntries(store) {
|
|
180
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
181
|
+
}
|
|
182
|
+
const ItemPortals = ({ store, render, collection, expandedIds }) => usePortalEntries(store).map((entry) => (_jsx(ItemCell, { entry: entry, render: render, collection: collection, expandedIds: expandedIds }, entry.key)));
|
|
183
|
+
const HeaderPortals = ({ store, render, collection }) => usePortalEntries(store).map((entry) => (_jsx(HeaderCell, { entry: entry, render: render, collection: collection }, entry.key)));
|
|
184
|
+
export { useItemCells, useHeaderCells, ItemPortals, HeaderPortals, };
|
|
185
|
+
//# sourceMappingURL=cells.js.map
|
|
@@ -0,0 +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,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAG9E,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAiF9C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;AACpC,MAAM,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\";\nimport type { ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkTreeExpander } from \"@gtkx/jsx/gtk\";\nimport { createPortal, useProperty } from \"@gtkx/react\";\nimport { memo, useLayoutEffect, useState, useSyncExternalStore } from \"react\";\nimport type { HeaderRenderer, Item, ItemRenderer, RenderItemArgs } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { getId } from \"./collection-model.js\";\n\ntype CellSize = {\n width: number;\n height: number;\n};\n\ntype CellHost = GObject.Object & {\n getChild: () => Gtk.Widget | null;\n setChild: (child: Gtk.Widget | null) => void;\n};\n\ntype CellEntry<C extends CellHost> = {\n key: string;\n cell: C;\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: (cell: GObject.Object) => void;\n onBind: (cell: GObject.Object) => void;\n onUnbind: (cell: GObject.Object) => void;\n onTeardown: (cell: GObject.Object) => void;\n};\n\ntype CellStore<C extends CellHost> = {\n handlers: FactoryHandlers;\n setSize: (size: CellSize) => void;\n subscribe: (onChange: () => void) => () => void;\n getSnapshot: () => CellEntry<C>[];\n};\n\ntype StoreState<C extends CellHost> = {\n size: CellSize;\n entries: Map<C, CellEntry<C>>;\n snapshot: CellEntry<C>[] | null;\n listeners: Set<() => void>;\n serial: number;\n};\n\ntype CellGuard<C extends CellHost> = (value: GObject.Object) => value is C;\n\ntype ItemBodyOptions = {\n item: GObject.Object | null;\n position: number | undefined;\n row: Gtk.TreeListRow | null;\n isRowExpanded: boolean | undefined;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype ItemCellProps = {\n entry: CellEntry<Gtk.ListItem>;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n};\n\ntype ItemPortalsProps = {\n store: CellStore<Gtk.ListItem>;\n render: ItemRenderer<never>;\n collection: Collection;\n expandedIds?: string[] | null | undefined;\n};\n\ntype HeaderCellProps = {\n entry: CellEntry<Gtk.ListHeader>;\n render: HeaderRenderer<never>;\n collection: Collection;\n};\n\ntype HeaderPortalsProps = {\n store: CellStore<Gtk.ListHeader>;\n render: HeaderRenderer<never>;\n collection: Collection;\n};\n\nconst ItemCell = memo(ItemCellImpl);\nconst HeaderCell = memo(HeaderCellImpl);\n\nconst isListItem = (value: GObject.Object): value is Gtk.ListItem => value instanceof Gtk.ListItem;\nconst isListHeader = (value: GObject.Object): value is Gtk.ListHeader => value instanceof Gtk.ListHeader;\n\nconst placeholder = (size: CellSize): Gtk.Widget =>\n new Gtk.Box({ widthRequest: size.width, heightRequest: size.height });\n\nfunction notifyEntry<C extends CellHost>(entry: CellEntry<C>): void {\n for (const listener of entry.listeners) {\n listener();\n }\n}\n\nfunction notifyRoster<C extends CellHost>(state: StoreState<C>): void {\n state.snapshot = null;\n\n for (const listener of state.listeners) {\n listener();\n }\n}\n\nfunction createEntry<C extends CellHost>(state: StoreState<C>, cell: C): CellEntry<C> {\n state.serial += 1;\n\n const entry: CellEntry<C> = {\n key: `gtkx-cell-${String(state.serial)}`,\n cell,\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 setupCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n cell.setChild(placeholder(state.size));\n state.entries.set(cell, createEntry(state, cell));\n notifyRoster(state);\n}\n\nfunction teardownCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n if (state.entries.delete(cell)) {\n notifyRoster(state);\n }\n}\n\nfunction writeBinding<C extends CellHost>(state: StoreState<C>, cell: C, item: GObject.Object | null): void {\n const entry = state.entries.get(cell);\n\n if (entry === undefined) {\n return;\n }\n\n entry.item = item;\n notifyEntry(entry);\n}\n\nfunction boundItem(cell: CellHost): GObject.Object | null {\n if (cell instanceof Gtk.ListItem) {\n return cell.getItem();\n }\n\n return cell instanceof Gtk.ListHeader ? cell.getItem() : null;\n}\n\nfunction bindCell<C extends CellHost>(state: StoreState<C>, cell: C): void {\n if (cell.getChild() === null) {\n cell.setChild(placeholder(state.size));\n }\n\n writeBinding(state, cell, boundItem(cell));\n}\n\nfunction subscribeRoster<C extends CellHost>(state: StoreState<C>, onChange: () => void): () => void {\n state.listeners.add(onChange);\n\n return () => {\n state.listeners.delete(onChange);\n };\n}\n\nfunction rosterSnapshot<C extends CellHost>(state: StoreState<C>): CellEntry<C>[] {\n state.snapshot ??= state.entries.values().toArray();\n\n return state.snapshot;\n}\n\nfunction guarded<C extends CellHost>(isCell: CellGuard<C>, run: (cell: C) => void): (cell: GObject.Object) => void {\n return (cell) => {\n if (isCell(cell)) {\n run(cell);\n }\n };\n}\n\nfunction createHandlers<C extends CellHost>(state: StoreState<C>, isCell: CellGuard<C>): FactoryHandlers {\n return {\n onSetup: guarded(isCell, (cell) => {\n setupCell(state, cell);\n }),\n onBind: guarded(isCell, (cell) => {\n bindCell(state, cell);\n }),\n onUnbind: guarded(isCell, (cell) => {\n writeBinding(state, cell, null);\n }),\n onTeardown: guarded(isCell, (cell) => {\n teardownCell(state, cell);\n }),\n };\n}\n\nfunction createCellStore<C extends CellHost>(isCell: CellGuard<C>, size: CellSize): CellStore<C> {\n const state: StoreState<C> = {\n size,\n entries: new Map(),\n snapshot: null,\n listeners: new Set(),\n serial: 0,\n };\n\n return {\n handlers: createHandlers(state, isCell),\n setSize: (next) => {\n state.size = next;\n },\n subscribe: (onChange) => subscribeRoster(state, onChange),\n getSnapshot: () => rosterSnapshot(state),\n };\n}\n\nfunction useCellStore<C extends CellHost>(isCell: CellGuard<C>, size: CellSize): CellStore<C> {\n const [store] = useState(() => createCellStore(isCell, size));\n\n useLayoutEffect(() => {\n store.setSize(size);\n });\n\n return store;\n}\n\nfunction useItemCells(size: CellSize): CellStore<Gtk.ListItem> {\n return useCellStore(isListItem, size);\n}\n\nfunction useHeaderCells(size: CellSize): CellStore<Gtk.ListHeader> {\n return useCellStore(isListHeader, size);\n}\n\nfunction isRowWanted(options: ItemBodyOptions, item: Item): boolean {\n const { expandedIds } = options;\n\n return expandedIds == null ? options.isRowExpanded === true : expandedIds.includes(item.id);\n}\n\nfunction itemArgs(item: Item, options: ItemBodyOptions): RenderItemArgs<unknown> {\n const args: RenderItemArgs<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 wrapExpander(item: Item, row: Gtk.TreeListRow | null, content: ReactNode): ReactNode {\n const expander: ReactNode =\n row === null\n ? (\n content\n )\n : (\n <GtkTreeExpander\n listRow={row}\n hideExpander={item.hideExpander ?? false}\n indentForDepth={item.indentForDepth ?? true}\n indentForIcon={item.indentForIcon ?? true}\n >\n {content}\n </GtkTreeExpander>\n );\n\n return expander;\n}\n\nfunction itemBody(options: ItemBodyOptions): ReactNode {\n const id = getId(options.item);\n const item = id === null ? undefined : options.collection.itemFor(id);\n\n if (item === undefined) {\n return null;\n }\n\n const render = options.render as ItemRenderer<unknown>;\n\n return wrapExpander(item, options.row, render(itemArgs(item, options)));\n}\n\nfunction ItemCellImpl({ entry, render, collection, expandedIds }: ItemCellProps): ReactNode {\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const position = useProperty(entry.cell, \"position\");\n const row = item instanceof Gtk.TreeListRow ? item : null;\n const isRowExpanded = useProperty(row, \"expanded\");\n const body = itemBody({ item, position, row, isRowExpanded, render, collection, expandedIds });\n\n return createPortal(body, entry.cell, entry.key);\n}\n\nfunction HeaderCellImpl({ entry, render, collection }: HeaderCellProps): ReactNode {\n const item = useSyncExternalStore(entry.subscribe, entry.getItem);\n const id = getId(item);\n const renderHeader = render as HeaderRenderer<unknown>;\n const body = id === null ? null : renderHeader({ section: collection.sectionFor(id) });\n\n return createPortal(body, entry.cell, entry.key);\n}\n\nfunction usePortalEntries<C extends CellHost>(store: CellStore<C>): CellEntry<C>[] {\n return useSyncExternalStore(store.subscribe, store.getSnapshot);\n}\n\nconst ItemPortals = ({ store, render, collection, expandedIds }: ItemPortalsProps): ReactNode =>\n usePortalEntries(store).map((entry) => (\n <ItemCell key={entry.key} entry={entry} render={render} collection={collection} expandedIds={expandedIds} />\n ));\n\nconst HeaderPortals = ({ store, render, collection }: HeaderPortalsProps): ReactNode =>\n usePortalEntries(store).map((entry) => (\n <HeaderCell key={entry.key} entry={entry} render={render} collection={collection} />\n ));\n\nexport {\n useItemCells,\n useHeaderCells,\n ItemPortals,\n HeaderPortals,\n type CellSize,\n type CellStore,\n};\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Item, Section } from "../types.js";
|
|
2
|
+
type Level = {
|
|
3
|
+
key: string;
|
|
4
|
+
ids: string[];
|
|
5
|
+
isExpandable: boolean[];
|
|
6
|
+
};
|
|
7
|
+
type CollectionIndex = {
|
|
8
|
+
isTree: boolean;
|
|
9
|
+
size: number;
|
|
10
|
+
groups: Level[];
|
|
11
|
+
children: Map<string, Level>;
|
|
12
|
+
has: (id: string) => boolean;
|
|
13
|
+
itemFor: (id: string) => Item | undefined;
|
|
14
|
+
sectionFor: (id: string) => unknown;
|
|
15
|
+
positionFor: (id: string) => number;
|
|
16
|
+
};
|
|
17
|
+
declare const ROOT_LEVEL_KEY = "";
|
|
18
|
+
declare const childLevelKey: (id: string) => string;
|
|
19
|
+
declare function createCollectionIndex(items: Item[] | undefined, sections: Section[] | undefined, isFlat: boolean): CollectionIndex;
|
|
20
|
+
export { createCollectionIndex, childLevelKey, ROOT_LEVEL_KEY, type CollectionIndex, type Level };
|
|
21
|
+
//# sourceMappingURL=collection-index.d.ts.map
|