@gtkx/components 1.0.0-rc.2 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/dist/adw/combo-row.d.ts +12 -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 +11 -3
- package/dist/adw/types.d.ts.map +1 -1
- package/dist/adw/types.js.map +1 -1
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +4 -4
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +4 -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/grid-view.js +1 -1
- package/dist/grid-view.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +3 -3
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/collection-index.d.ts +5 -5
- package/dist/internal/collection-index.d.ts.map +1 -1
- package/dist/internal/collection-index.js +3 -3
- package/dist/internal/collection-index.js.map +1 -1
- package/dist/internal/collection-model.d.ts.map +1 -1
- package/dist/internal/collection-model.js +2 -5
- package/dist/internal/collection-model.js.map +1 -1
- package/dist/internal/collection.d.ts +2 -2
- package/dist/internal/collection.d.ts.map +1 -1
- package/dist/internal/collection.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 +5 -6
- package/dist/internal/use-collection.d.ts.map +1 -1
- package/dist/internal/use-collection.js +10 -18
- package/dist/internal/use-collection.js.map +1 -1
- package/dist/types.d.ts +70 -48
- 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 +21 -0
- package/src/adw/index.ts +8 -1
- package/src/adw/types.ts +17 -3
- package/src/column-view.tsx +13 -13
- package/src/drop-down.tsx +10 -195
- package/src/grid-view.tsx +1 -1
- package/src/index.ts +7 -12
- package/src/internal/cells.tsx +12 -12
- package/src/internal/collection-index.ts +16 -16
- package/src/internal/collection-model.ts +2 -5
- package/src/internal/collection.ts +2 -2
- 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 +16 -29
- package/src/types.ts +83 -66
- package/dist/size-group.d.ts +0 -12
- package/dist/size-group.d.ts.map +0 -1
- package/dist/size-group.js +0 -41
- package/dist/size-group.js.map +0 -1
- package/src/size-group.tsx +0 -77
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/internal/selection.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/internal/selection.tsx"],"names":[],"mappings":";AAEA,OAA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AC;QAClD,MAAM,EAAE,CAAC;IACb,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAEzC,OAAO,gBAAgB,CAAC,aAAa,EAAE;QACnC,GAAG,EAAE,YAAY;QACjB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,kBAAkB,EAAE,GAAG,EAAE;YACrB,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACrE,CAAC;QACD,cAAc,EAAE,OAAO,CAAC,cAAc;KACzC,CAAC,CAAC;AACP,CAAC;AAED,OAAO,EAAE,YAAY,EAAyB,CAAC","sourcesContent":["import type * as Gio from \"@gtkx/gi/gio\";\nimport type { ReactElement } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkMultiSelection, GtkNoSelection, GtkSingleSelection } from \"@gtkx/jsx/gtk\";\nimport { useEffectEvent, useLayoutEffect, useState } from \"react\";\nimport type { Collection } from \"./collection.js\";\n\ntype SelectionOptions = {\n collection: Collection;\n selectedIds?: string[] | null | undefined;\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n selectionMode?: Gtk.SelectionMode | null | undefined;\n onItemsChanged: () => void;\n};\n\ntype LastSelection = {\n selection: Gtk.SelectionModel | null;\n key: string | null;\n};\n\ntype SelectionElementProps = {\n ref: (value: Gtk.SelectionModel | null) => void;\n model: Gio.ListModel;\n onSelectionChanged: () => void;\n onItemsChanged: () => void;\n};\n\nfunction getSelectedIds(selection: Gtk.SelectionModel, collection: Collection): string[] {\n const bitset = selection.getSelection();\n const size = Number(bitset.getSize());\n const ids: string[] = [];\n\n for (let index = 0; index < size; index++) {\n pushId(collection.idAt(bitset.getNth(index)), ids);\n }\n\n return ids;\n}\n\nfunction pushId(id: string | null, ids: string[]): void {\n if (id !== null) {\n ids.push(id);\n }\n}\n\nfunction applySingleSelection(selection: Gtk.SingleSelection, positions: number[]): void {\n const [first] = positions;\n\n if (first === undefined) {\n selection.unselectAll();\n\n return;\n }\n\n selection.selectItem(first, true);\n}\n\nfunction applyMultiSelection(selection: Gtk.SelectionModel, positions: number[]): void {\n const selected = Gtk.Bitset.newEmpty();\n\n for (const position of positions) {\n selected.add(position);\n }\n\n selection.setSelection(selected, Gtk.Bitset.newRange(0, selection.getNItems()));\n}\n\nfunction applySelection(selection: Gtk.SelectionModel, collection: Collection, ids: string[]): void {\n if (selection instanceof Gtk.NoSelection) {\n return;\n }\n\n const positions = collection.positionsFor(ids);\n\n if (ids.length > 0 && positions.length === 0) {\n return;\n }\n\n if (selection instanceof Gtk.SingleSelection) {\n applySingleSelection(selection, positions);\n\n return;\n }\n\n applyMultiSelection(selection, positions);\n}\n\nfunction reportSelection(\n selection: Gtk.SelectionModel | null,\n collection: Collection,\n last: LastSelection,\n onSelectionChanged: ((ids: string[]) => void) | null | undefined,\n): void {\n if (selection === null) {\n return;\n }\n\n const ids = getSelectedIds(selection, collection);\n const key = ids.join(\" \");\n\n if (last.selection === selection && last.key === key) {\n return;\n }\n\n last.selection = selection;\n last.key = key;\n onSelectionChanged?.(ids);\n}\n\nfunction selectionElement(mode: Gtk.SelectionMode | null | undefined, props: SelectionElementProps): ReactElement {\n if (mode === Gtk.SelectionMode.MULTIPLE) {\n return <GtkMultiSelection {...props} />;\n }\n\n if (mode === Gtk.SelectionMode.NONE) {\n return <GtkNoSelection {...props} />;\n }\n\n return <GtkSingleSelection {...props} autoselect={false} canUnselect />;\n}\n\nfunction syncSelection(\n selection: Gtk.SelectionModel | null,\n collection: Collection,\n selectedIds: string[] | null | undefined,\n): void {\n if (selection === null || selectedIds == null) {\n return;\n }\n\n applySelection(selection, collection, selectedIds);\n}\n\nfunction newLastSelection(): LastSelection {\n return { selection: null, key: null };\n}\n\nfunction useSelection(options: SelectionOptions): ReactElement {\n const { collection, selectedIds, onSelectionChanged, selectionMode } = options;\n const [selection, setSelection] = useState<Gtk.SelectionModel | null>(null);\n const [last] = useState<LastSelection>(newLastSelection);\n\n const report = useEffectEvent((): void => {\n reportSelection(selection, collection, last, onSelectionChanged);\n });\n\n useLayoutEffect(() => {\n syncSelection(selection, collection, selectedIds);\n report();\n }, [selection, collection, selectedIds]);\n\n return selectionElement(selectionMode, {\n ref: setSelection,\n model: collection.model,\n onSelectionChanged: () => {\n reportSelection(selection, collection, last, onSelectionChanged);\n },\n onItemsChanged: options.onItemsChanged,\n });\n}\n\nexport { useSelection, type SelectionOptions };\n"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { ReactElement
|
|
2
|
-
import type { ExpansionProps,
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { ExpansionProps, ListItem, ListSection, SelectionProps } from "../types.js";
|
|
3
3
|
import type { Collection } from "./collection.js";
|
|
4
4
|
type CollectionDataOptions = {
|
|
5
|
-
items?:
|
|
6
|
-
sections?:
|
|
7
|
-
|
|
8
|
-
applying?: RefObject<boolean> | undefined;
|
|
5
|
+
items?: ListItem[] | undefined;
|
|
6
|
+
sections?: ListSection[] | undefined;
|
|
7
|
+
isFlat?: boolean | undefined;
|
|
9
8
|
};
|
|
10
9
|
type CollectionOptions = CollectionDataOptions & SelectionProps & ExpansionProps;
|
|
11
10
|
type CollectionResult = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-collection.d.ts","sourceRoot":"","sources":["../../src/internal/use-collection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"use-collection.d.ts","sourceRoot":"","sources":["../../src/internal/use-collection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOlD,KAAK,qBAAqB,GAAG;IACzB,KAAK,CAAC,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACrC,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,KAAK,iBAAiB,GAAG,qBAAqB,GAAG,cAAc,GAAG,cAAc,CAAC;AAEjF,KAAK,gBAAgB,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,iBAAS,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,UAAU,CAWrE;AAED,iBAAS,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAkBnE;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
|
|
@@ -4,37 +4,29 @@ import { createCollectionModel } from "./collection-model.js";
|
|
|
4
4
|
import { createCollection } from "./collection.js";
|
|
5
5
|
import { useExpansion } from "./expansion.js";
|
|
6
6
|
import { useSelection } from "./selection.js";
|
|
7
|
-
function runSync(gtk, index, applying) {
|
|
8
|
-
if (applying === undefined) {
|
|
9
|
-
gtk.sync(index);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
applying.current = true;
|
|
13
|
-
try {
|
|
14
|
-
gtk.sync(index);
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
applying.current = false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
7
|
function useCollectionData(options) {
|
|
21
|
-
const { items, sections,
|
|
8
|
+
const { items, sections, isFlat } = options;
|
|
22
9
|
const [gtk] = useState(createCollectionModel);
|
|
23
|
-
const index = useMemo(() => createCollectionIndex(items, sections,
|
|
10
|
+
const index = useMemo(() => createCollectionIndex(items, sections, isFlat === true), [items, sections, isFlat]);
|
|
24
11
|
const collection = useMemo(() => createCollection(gtk, index), [gtk, index]);
|
|
25
12
|
useLayoutEffect(() => {
|
|
26
|
-
|
|
27
|
-
}, [gtk, index
|
|
13
|
+
gtk.sync(index);
|
|
14
|
+
}, [gtk, index]);
|
|
28
15
|
return collection;
|
|
29
16
|
}
|
|
30
17
|
function useCollection(options) {
|
|
31
18
|
const collection = useCollectionData(options);
|
|
32
|
-
useExpansion({
|
|
19
|
+
const onItemsChanged = useExpansion({
|
|
20
|
+
collection,
|
|
21
|
+
expandedIds: options.expandedIds,
|
|
22
|
+
onExpandedChange: options.onExpandedChange,
|
|
23
|
+
});
|
|
33
24
|
const selection = useSelection({
|
|
34
25
|
collection,
|
|
35
26
|
selectedIds: options.selectedIds,
|
|
36
27
|
onSelectionChanged: options.onSelectionChanged,
|
|
37
28
|
selectionMode: options.selectionMode,
|
|
29
|
+
onItemsChanged,
|
|
38
30
|
});
|
|
39
31
|
return { collection, selection };
|
|
40
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-collection.js","sourceRoot":"","sources":["../../src/internal/use-collection.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-collection.js","sourceRoot":"","sources":["../../src/internal/use-collection.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAe9C,SAAS,iBAAiB,CAAC,OAA8B;IACrD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC5C,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IAChH,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAE7E,eAAe,CAAC,GAAG,EAAE;QACjB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAEjB,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,SAAS,aAAa,CAAC,OAA0B;IAC7C,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAE9C,MAAM,cAAc,GAAG,YAAY,CAAC;QAChC,UAAU;QACV,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,YAAY,CAAC;QAC3B,UAAU;QACV,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,cAAc;KACjB,CAAC,CAAC;IAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAsD,CAAC","sourcesContent":["import type { ReactElement } from \"react\";\nimport { useLayoutEffect, useMemo, useState } from \"react\";\nimport type { ExpansionProps, ListItem, ListSection, SelectionProps } from \"../types.js\";\nimport type { Collection } from \"./collection.js\";\nimport { createCollectionIndex } from \"./collection-index.js\";\nimport { createCollectionModel } from \"./collection-model.js\";\nimport { createCollection } from \"./collection.js\";\nimport { useExpansion } from \"./expansion.js\";\nimport { useSelection } from \"./selection.js\";\n\ntype CollectionDataOptions = {\n items?: ListItem[] | undefined;\n sections?: ListSection[] | undefined;\n isFlat?: boolean | undefined;\n};\n\ntype CollectionOptions = CollectionDataOptions & SelectionProps & ExpansionProps;\n\ntype CollectionResult = {\n collection: Collection;\n selection: ReactElement;\n};\n\nfunction useCollectionData(options: CollectionDataOptions): Collection {\n const { items, sections, isFlat } = options;\n const [gtk] = useState(createCollectionModel);\n const index = useMemo(() => createCollectionIndex(items, sections, isFlat === true), [items, sections, isFlat]);\n const collection = useMemo(() => createCollection(gtk, index), [gtk, index]);\n\n useLayoutEffect(() => {\n gtk.sync(index);\n }, [gtk, index]);\n\n return collection;\n}\n\nfunction useCollection(options: CollectionOptions): CollectionResult {\n const collection = useCollectionData(options);\n\n const onItemsChanged = useExpansion({\n collection,\n expandedIds: options.expandedIds,\n onExpandedChange: options.onExpandedChange,\n });\n\n const selection = useSelection({\n collection,\n selectedIds: options.selectedIds,\n onSelectionChanged: options.onSelectionChanged,\n selectionMode: options.selectionMode,\n onItemsChanged,\n });\n\n return { collection, selection };\n}\n\nexport { useCollection, useCollectionData, type CollectionDataOptions, type CollectionOptions };\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type { GtkColumnViewColumnProps, GtkColumnViewProps,
|
|
3
|
-
import type {
|
|
4
|
-
/** Props of a container's Child component: the widget to render and its own props. */
|
|
5
|
-
type ChildProps<C extends ElementType> = {
|
|
6
|
-
component: C;
|
|
7
|
-
} & ComponentPropsWithRef<C>;
|
|
8
|
-
/** Props of a component whose backing widget defaults to one type but can be swapped through `component`. */
|
|
9
|
-
type WidgetProps<C extends ElementType, Own = unknown, ExtraOmit extends string = never> = Own & {
|
|
10
|
-
component?: C;
|
|
11
|
-
} & Omit<ComponentPropsWithRef<C>, ExtraOmit | keyof Own>;
|
|
2
|
+
import type { GtkColumnViewColumnProps, GtkColumnViewProps, GtkDropDownProps, GtkGridViewProps, GtkListViewProps } from "@gtkx/jsx/gtk";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
12
4
|
/**
|
|
13
5
|
* A single item in a collection model, identified by a stable id and holding an
|
|
14
6
|
* arbitrary value. Nested items form a tree.
|
|
15
7
|
*/
|
|
16
|
-
type
|
|
8
|
+
type ListItem<T = unknown> = {
|
|
17
9
|
/** Stable identifier used to track the item across updates and selection. */
|
|
18
10
|
id: string;
|
|
11
|
+
/** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */
|
|
19
12
|
value: T;
|
|
20
|
-
|
|
13
|
+
/** Child items nested under this one, which turn a plain item list into a tree. */
|
|
14
|
+
children?: ListItem<T>[] | undefined;
|
|
21
15
|
/** Hides the tree expander arrow even when the item has children. */
|
|
22
16
|
hideExpander?: boolean | undefined;
|
|
23
17
|
/** Adds indentation matching the item's depth in the tree. */
|
|
@@ -26,63 +20,88 @@ type Item<T = unknown> = {
|
|
|
26
20
|
indentForIcon?: boolean | undefined;
|
|
27
21
|
};
|
|
28
22
|
/** A group of items rendered under a shared section header. */
|
|
29
|
-
type
|
|
23
|
+
type ListSection<S = unknown, T = unknown> = {
|
|
30
24
|
/** Stable identifier used to track the section across updates. */
|
|
31
25
|
id: string;
|
|
26
|
+
/** Payload handed to the section header renderer as `ListSectionRenderArgs.section`. */
|
|
32
27
|
value: S;
|
|
33
28
|
/** Items belonging to this section. */
|
|
34
|
-
data:
|
|
29
|
+
data: ListItem<T>[];
|
|
35
30
|
};
|
|
36
|
-
/** Arguments passed to
|
|
37
|
-
type
|
|
31
|
+
/** Arguments passed to a {@link ListItemRenderer} when rendering one cell. */
|
|
32
|
+
type ListItemRenderArgs<T> = {
|
|
33
|
+
/** Value of the `ListItem` being rendered. */
|
|
38
34
|
item: T;
|
|
35
|
+
/** Position of the item in the flattened item list, which excludes section headers and collapsed tree rows. */
|
|
39
36
|
index: number;
|
|
40
37
|
/** Depth of the item within a tree, starting at zero for top-level items. */
|
|
41
38
|
depth?: number | undefined;
|
|
42
39
|
/** Whether the item is currently expanded in a tree view. */
|
|
43
40
|
isExpanded?: boolean | undefined;
|
|
44
41
|
};
|
|
45
|
-
/** Arguments passed to a {@link
|
|
46
|
-
type
|
|
42
|
+
/** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */
|
|
43
|
+
type ListSectionRenderArgs<S> = {
|
|
44
|
+
/** Value of the `ListSection` whose header is being rendered. */
|
|
47
45
|
section: S;
|
|
48
46
|
};
|
|
49
47
|
/** Renders the contents of one cell of a collection view. */
|
|
50
|
-
type
|
|
48
|
+
type ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;
|
|
51
49
|
/** Renders the contents of one section header of a collection view. */
|
|
52
|
-
type
|
|
50
|
+
type ListSectionRenderer<S> = (args: ListSectionRenderArgs<S>) => ReactNode;
|
|
51
|
+
/** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */
|
|
53
52
|
type ItemSizeProps = {
|
|
53
|
+
/** Height in pixels every cell asks for until its contents render; unset lets each cell size itself. */
|
|
54
54
|
estimatedItemHeight?: number | undefined;
|
|
55
|
+
/** Width in pixels every cell asks for until its contents render; unset lets each cell size itself. */
|
|
55
56
|
estimatedItemWidth?: number | undefined;
|
|
56
57
|
};
|
|
58
|
+
/** Controlled selection shared by the multi-item collection views. */
|
|
57
59
|
type SelectionProps = {
|
|
60
|
+
/** Ids of the items to keep selected; omitting it leaves the view's own selection alone. */
|
|
58
61
|
selectedIds?: string[] | null | undefined;
|
|
62
|
+
/** Called with the ids of every selected item whenever the selection changes, and once on mount. */
|
|
59
63
|
onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
|
|
64
|
+
/** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */
|
|
60
65
|
selectionMode?: Gtk.SelectionMode | null | undefined;
|
|
61
66
|
};
|
|
67
|
+
/** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */
|
|
62
68
|
type ExpansionProps = {
|
|
69
|
+
/** Ids of the items to keep expanded; omitting it leaves the rows' own expanded state alone. */
|
|
63
70
|
expandedIds?: string[] | null | undefined;
|
|
71
|
+
/** Called with the ids of every expanded row whenever expansion changes. */
|
|
64
72
|
onExpandedChange?: ((ids: string[]) => void) | null | undefined;
|
|
65
73
|
};
|
|
74
|
+
/** The data a collection view renders, either as a plain item list or grouped into sections. */
|
|
66
75
|
type SourceProps<T, S> = {
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
/** Items to render, nesting through `ListItem.children` for a tree; ignored once `sections` is given. */
|
|
77
|
+
items?: ListItem<T>[] | undefined;
|
|
78
|
+
/** Items grouped under section headers, rendered in place of `items`. */
|
|
79
|
+
sections?: ListSection<S, T>[] | undefined;
|
|
69
80
|
};
|
|
70
81
|
/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */
|
|
71
|
-
type
|
|
82
|
+
type ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter" | "id" | "title"> & {
|
|
72
83
|
/** Stable identifier, also used to address the column through sorting props. */
|
|
73
84
|
id: string;
|
|
85
|
+
/** Text shown in the column header. */
|
|
74
86
|
title: string;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
/** Renders the contents of this column's cell for one item. */
|
|
88
|
+
renderCell: ListItemRenderer<T>;
|
|
89
|
+
/** Makes the column header clickable, reporting the choice through `onSortChanged`. */
|
|
90
|
+
isSortable?: boolean | undefined;
|
|
91
|
+
/** Menu element popped up as the column header's context menu, on a right-click. */
|
|
78
92
|
headerMenu?: ReactNode;
|
|
79
93
|
};
|
|
94
|
+
/** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */
|
|
80
95
|
type ColumnViewOwnProps<T, S> = SelectionProps & ExpansionProps & SourceProps<T, S> & Omit<ItemSizeProps, "estimatedItemWidth"> & {
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
/** Columns to render, in order; each carries its own cell renderer. */
|
|
97
|
+
columns: ColumnViewColumn<T>[];
|
|
98
|
+
/** Renders the header shown above each section. */
|
|
99
|
+
renderHeader?: ListSectionRenderer<S> | null | undefined;
|
|
83
100
|
/** Id of the column the view is sorted by, making sorting controlled. */
|
|
84
101
|
sortColumn?: string | null | undefined;
|
|
102
|
+
/** Direction `sortColumn` is sorted in, defaulting to ascending. */
|
|
85
103
|
sortOrder?: Gtk.SortType | null | undefined;
|
|
104
|
+
/** Called when the user sorts from a header, with the primary column's id, or null, and its order. */
|
|
86
105
|
onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
|
|
87
106
|
};
|
|
88
107
|
/**
|
|
@@ -92,24 +111,33 @@ type ColumnViewOwnProps<T, S> = SelectionProps & ExpansionProps & SourceProps<T,
|
|
|
92
111
|
* header renderer, and the columns to render.
|
|
93
112
|
*/
|
|
94
113
|
type ColumnViewProps<T = unknown, S = unknown> = Omit<GtkColumnViewProps, "columns" | "model" | "headerFactory" | keyof ColumnViewOwnProps<T, S>> & ColumnViewOwnProps<T, S>;
|
|
114
|
+
/** The declarative collection props {@link DropDown} and `ComboRow` add on top of their widget's own. */
|
|
95
115
|
type DropDownOwnProps<T, S> = SourceProps<T, S> & {
|
|
96
116
|
/** Id of the currently selected item, making the selection controlled. */
|
|
97
117
|
selectedId?: string | null | undefined;
|
|
118
|
+
/** Called with the id of the item that became selected. */
|
|
98
119
|
onSelectionChanged?: ((id: string) => void) | null | undefined;
|
|
99
|
-
|
|
120
|
+
/** Renders the collapsed display, and the popup rows too unless `renderListItem` is given. */
|
|
121
|
+
renderItem?: ListItemRenderer<T> | null | undefined;
|
|
100
122
|
/** Renderer for items in the open popup list, falling back to renderItem when omitted. */
|
|
101
|
-
renderListItem?:
|
|
123
|
+
renderListItem?: ListItemRenderer<T> | null | undefined;
|
|
102
124
|
/** Renderer for section headers in the popup list. */
|
|
103
|
-
renderHeader?:
|
|
125
|
+
renderHeader?: ListSectionRenderer<S> | null | undefined;
|
|
104
126
|
};
|
|
127
|
+
/** A drop-down-shaped widget's props with its model and factories swapped for the declarative collection props. */
|
|
128
|
+
type DropDownWidgetProps<Widget, T, S> = Omit<Widget, "model" | "factory" | "listFactory" | "headerFactory" | keyof DropDownOwnProps<T, S>> & DropDownOwnProps<T, S>;
|
|
105
129
|
/**
|
|
106
|
-
* Props for {@link DropDown}.
|
|
107
|
-
*
|
|
130
|
+
* Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative
|
|
131
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
132
|
+
* for the collapsed display, popup rows, and popup section headers.
|
|
108
133
|
*/
|
|
109
|
-
type DropDownProps<T = unknown, S = unknown
|
|
134
|
+
type DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;
|
|
135
|
+
/** The declarative collection props {@link GridView} adds on top of Gtk.GridView's own. */
|
|
110
136
|
type GridViewOwnProps<T> = ItemSizeProps & SelectionProps & {
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
/** Items to render as cells; a grid is always flat, so `ListItem.children` is ignored. */
|
|
138
|
+
items?: ListItem<T>[] | undefined;
|
|
139
|
+
/** Renders the contents of one cell. */
|
|
140
|
+
renderItem: ListItemRenderer<T>;
|
|
113
141
|
};
|
|
114
142
|
/**
|
|
115
143
|
* Props for {@link GridView}. Combines the underlying Gtk.GridView props with
|
|
@@ -117,9 +145,12 @@ type GridViewOwnProps<T> = ItemSizeProps & SelectionProps & {
|
|
|
117
145
|
* and estimated item sizing.
|
|
118
146
|
*/
|
|
119
147
|
type GridViewProps<T = unknown> = Omit<GtkGridViewProps, "model" | "factory" | keyof GridViewOwnProps<T>> & GridViewOwnProps<T>;
|
|
148
|
+
/** The declarative collection props {@link ListView} adds on top of Gtk.ListView's own. */
|
|
120
149
|
type ListViewOwnProps<T, S> = ItemSizeProps & SelectionProps & ExpansionProps & SourceProps<T, S> & {
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
/** Renders the contents of one row. */
|
|
151
|
+
renderItem: ListItemRenderer<T>;
|
|
152
|
+
/** Renders the header shown above each section. */
|
|
153
|
+
renderHeader?: ListSectionRenderer<S> | null | undefined;
|
|
123
154
|
};
|
|
124
155
|
/**
|
|
125
156
|
* Props for {@link ListView}. Combines the underlying Gtk.ListView props with
|
|
@@ -128,14 +159,5 @@ type ListViewOwnProps<T, S> = ItemSizeProps & SelectionProps & ExpansionProps &
|
|
|
128
159
|
* estimated item sizing.
|
|
129
160
|
*/
|
|
130
161
|
type ListViewProps<T = unknown, S = unknown> = Omit<GtkListViewProps, "model" | "factory" | "headerFactory" | keyof ListViewOwnProps<T, S>> & ListViewOwnProps<T, S>;
|
|
131
|
-
|
|
132
|
-
type SizeGroupProps = {
|
|
133
|
-
/** How the group equalizes sizes: horizontal, vertical, or both. */
|
|
134
|
-
mode?: Gtk.SizeGroupMode | null | undefined;
|
|
135
|
-
ref?: Ref<Gtk.SizeGroup | null>;
|
|
136
|
-
children?: ReactNode;
|
|
137
|
-
};
|
|
138
|
-
/** Adds a single widget, rendered by the given component, to the enclosing {@link SizeGroup}. */
|
|
139
|
-
type SizeGroupChildProps<C extends ElementType> = ChildProps<C>;
|
|
140
|
-
export { type SelectionProps, type ExpansionProps, type ChildProps, type WidgetProps, type Item, type Section, type RenderItemArgs, type RenderHeaderArgs, type ItemRenderer, type HeaderRenderer, type Column, type ColumnViewProps, type DropDownProps, type GridViewProps, type ListViewProps, type SizeGroupProps, type SizeGroupChildProps, };
|
|
162
|
+
export { type SelectionProps, type ExpansionProps, type DropDownOwnProps, type DropDownWidgetProps, type ListItem, type ListSection, type ListItemRenderArgs, type ListSectionRenderArgs, type ListItemRenderer, type ListSectionRenderer, type ColumnViewColumn, type ColumnViewProps, type DropDownProps, type GridViewProps, type ListViewProps, };
|
|
141
163
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EACR,wBAAwB,EACxB,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EACR,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;;GAGG;AACH,KAAK,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI;IACzB,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAC;IACX,wEAAwE;IACxE,KAAK,EAAE,CAAC,CAAC;IACT,mFAAmF;IACnF,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IACrC,qEAAqE;IACrE,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,8DAA8D;IAC9D,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,uDAAuD;IACvD,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC,CAAC;AAEF,+DAA+D;AAC/D,KAAK,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI;IACzC,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,wFAAwF;IACxF,KAAK,EAAE,CAAC,CAAC;IACT,uCAAuC;IACvC,IAAI,EAAE,QAAQ,CAAC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C/C,gBAAgB,EAChB,OAAO,GAAG,SAAS,GAAG,eAAe,GAAG,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CACvE,GACD,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvB,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,GACrB,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4LA,OAAO,EAkBN,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type {\n GtkColumnViewColumnProps,\n GtkColumnViewProps,\n GtkDropDown,\n GtkGridViewProps,\n GtkListViewProps,\n} from \"@gtkx/jsx/gtk\";\nimport type { ComponentPropsWithRef, ElementType, ReactNode, Ref } from \"react\";\n\n/** Props of a container's Child component: the widget to render and its own props. */\ntype ChildProps<C extends ElementType> = {\n component: C;\n} & ComponentPropsWithRef<C>;\n\n/** Props of a component whose backing widget defaults to one type but can be swapped through `component`. */\ntype WidgetProps<C extends ElementType, Own = unknown, ExtraOmit extends string = never> = Own & {\n component?: C;\n} & Omit<ComponentPropsWithRef<C>, ExtraOmit | keyof Own>;\n\n/**\n * A single item in a collection model, identified by a stable id and holding an\n * arbitrary value. Nested items form a tree.\n */\ntype Item<T = unknown> = {\n /** Stable identifier used to track the item across updates and selection. */\n id: string;\n value: T;\n children?: Item<T>[] | undefined;\n /** Hides the tree expander arrow even when the item has children. */\n hideExpander?: boolean | undefined;\n /** Adds indentation matching the item's depth in the tree. */\n indentForDepth?: boolean | undefined;\n /** Reserves indentation space for an expander icon. */\n indentForIcon?: boolean | undefined;\n};\n\n/** A group of items rendered under a shared section header. */\ntype Section<S = unknown, T = unknown> = {\n /** Stable identifier used to track the section across updates. */\n id: string;\n value: S;\n /** Items belonging to this section. */\n data: Item<T>[];\n};\n\n/** Arguments passed to an {@link ItemRenderer} when rendering one cell. */\ntype RenderItemArgs<T> = {\n item: T;\n index: number;\n /** Depth of the item within a tree, starting at zero for top-level items. */\n depth?: number | undefined;\n /** Whether the item is currently expanded in a tree view. */\n isExpanded?: boolean | undefined;\n};\n\n/** Arguments passed to a {@link HeaderRenderer} when rendering one section header. */\ntype RenderHeaderArgs<S> = {\n section: S;\n};\n\n/** Renders the contents of one cell of a collection view. */\ntype ItemRenderer<T> = (args: RenderItemArgs<T>) => ReactNode;\n/** Renders the contents of one section header of a collection view. */\ntype HeaderRenderer<S> = (args: RenderHeaderArgs<S>) => ReactNode;\n\ntype ItemSizeProps = {\n estimatedItemHeight?: number | undefined;\n estimatedItemWidth?: number | undefined;\n};\n\ntype SelectionProps = {\n selectedIds?: string[] | null | undefined;\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n selectionMode?: Gtk.SelectionMode | null | undefined;\n};\n\ntype ExpansionProps = {\n expandedIds?: string[] | null | undefined;\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n};\n\ntype SourceProps<T, S> = {\n items?: Item<T>[] | undefined;\n sections?: Section<S, T>[] | undefined;\n};\n\n/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */\ntype Column<T = unknown> = Omit<GtkColumnViewColumnProps, \"factory\" | \"sorter\" | \"id\" | \"title\"> & {\n /** Stable identifier, also used to address the column through sorting props. */\n id: string;\n title: string;\n renderCell: ItemRenderer<T>;\n /** Whether clicking the column header sorts by it. */\n sortable?: boolean | undefined;\n headerMenu?: ReactNode;\n};\n\ntype ColumnViewOwnProps<T, S> = SelectionProps &\n ExpansionProps &\n SourceProps<T, S> &\n Omit<ItemSizeProps, \"estimatedItemWidth\"> & {\n columns: Column<T>[];\n renderHeader?: HeaderRenderer<S> | null | undefined;\n /** Id of the column the view is sorted by, making sorting controlled. */\n sortColumn?: string | null | undefined;\n sortOrder?: Gtk.SortType | null | undefined;\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n };\n\n/**\n * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with\n * declarative collection props: flat items or grouped sections, controlled selection\n * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section\n * header renderer, and the columns to render.\n */\ntype ColumnViewProps<T = unknown, S = unknown> = Omit<\n GtkColumnViewProps,\n \"columns\" | \"model\" | \"headerFactory\" | keyof ColumnViewOwnProps<T, S>\n> &\nColumnViewOwnProps<T, S>;\n\ntype DropDownOwnProps<T, S> = SourceProps<T, S> & {\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?: ItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: ItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: HeaderRenderer<S> | 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 the declarative collection props.\n */\ntype DropDownProps<T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown> = WidgetProps<\n C,\n DropDownOwnProps<T, S>,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\"\n>;\n\ntype GridViewOwnProps<T> = ItemSizeProps &\n SelectionProps & {\n items?: Item<T>[] | undefined;\n renderItem: ItemRenderer<T>;\n };\n\n/**\n * Props for {@link GridView}. Combines the underlying Gtk.GridView props with\n * declarative collection props: items, a per-cell renderItem, controlled selection,\n * and estimated item sizing.\n */\ntype GridViewProps<T = unknown> = Omit<GtkGridViewProps, \"model\" | \"factory\" | keyof GridViewOwnProps<T>> &\n GridViewOwnProps<T>;\n\ntype ListViewOwnProps<T, S> = ItemSizeProps &\n SelectionProps &\n ExpansionProps &\n SourceProps<T, S> & {\n renderItem: ItemRenderer<T>;\n renderHeader?: HeaderRenderer<S> | null | undefined;\n };\n\n/**\n * Props for {@link ListView}. Combines the underlying Gtk.ListView props with\n * declarative collection props: flat items or grouped sections, a per-row renderItem,\n * an optional section header renderer, controlled selection and expansion, and\n * estimated item sizing.\n */\ntype ListViewProps<T = unknown, S = unknown> = Omit<\n GtkListViewProps,\n \"model\" | \"factory\" | \"headerFactory\" | keyof ListViewOwnProps<T, S>\n> &\nListViewOwnProps<T, S>;\n\n/** Props for {@link SizeGroup}. */\ntype SizeGroupProps = {\n /** How the group equalizes sizes: horizontal, vertical, or both. */\n mode?: Gtk.SizeGroupMode | null | undefined;\n ref?: Ref<Gtk.SizeGroup | null>;\n children?: ReactNode;\n};\n\n/** Adds a single widget, rendered by the given component, to the enclosing {@link SizeGroup}. */\ntype SizeGroupChildProps<C extends ElementType> = ChildProps<C>;\n\nexport {\n type SelectionProps,\n type ExpansionProps,\n type ChildProps,\n type WidgetProps,\n type Item,\n type Section,\n type RenderItemArgs,\n type RenderHeaderArgs,\n type ItemRenderer,\n type HeaderRenderer,\n type Column,\n type ColumnViewProps,\n type DropDownProps,\n type GridViewProps,\n type ListViewProps,\n type SizeGroupProps,\n type SizeGroupChildProps,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA+MA,OAAO,EAgBN,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type {\n GtkColumnViewColumnProps,\n GtkColumnViewProps,\n GtkDropDownProps,\n GtkGridViewProps,\n GtkListViewProps,\n} from \"@gtkx/jsx/gtk\";\nimport type { ReactNode } from \"react\";\n\n/**\n * A single item in a collection model, identified by a stable id and holding an\n * arbitrary value. Nested items form a tree.\n */\ntype ListItem<T = unknown> = {\n /** Stable identifier used to track the item across updates and selection. */\n id: string;\n /** Payload handed to the cell renderer as `ListItemRenderArgs.item`. */\n value: T;\n /** Child items nested under this one, which turn a plain item list into a tree. */\n children?: ListItem<T>[] | undefined;\n /** Hides the tree expander arrow even when the item has children. */\n hideExpander?: boolean | undefined;\n /** Adds indentation matching the item's depth in the tree. */\n indentForDepth?: boolean | undefined;\n /** Reserves indentation space for an expander icon. */\n indentForIcon?: boolean | undefined;\n};\n\n/** A group of items rendered under a shared section header. */\ntype ListSection<S = unknown, T = unknown> = {\n /** Stable identifier used to track the section across updates. */\n id: string;\n /** Payload handed to the section header renderer as `ListSectionRenderArgs.section`. */\n value: S;\n /** Items belonging to this section. */\n data: ListItem<T>[];\n};\n\n/** Arguments passed to a {@link ListItemRenderer} when rendering one cell. */\ntype ListItemRenderArgs<T> = {\n /** Value of the `ListItem` being rendered. */\n item: T;\n /** Position of the item in the flattened item list, which excludes section headers and collapsed tree rows. */\n index: number;\n /** Depth of the item within a tree, starting at zero for top-level items. */\n depth?: number | undefined;\n /** Whether the item is currently expanded in a tree view. */\n isExpanded?: boolean | undefined;\n};\n\n/** Arguments passed to a {@link ListSectionRenderer} when rendering one section header. */\ntype ListSectionRenderArgs<S> = {\n /** Value of the `ListSection` whose header is being rendered. */\n section: S;\n};\n\n/** Renders the contents of one cell of a collection view. */\ntype ListItemRenderer<T> = (args: ListItemRenderArgs<T>) => ReactNode;\n/** Renders the contents of one section header of a collection view. */\ntype ListSectionRenderer<S> = (args: ListSectionRenderArgs<S>) => ReactNode;\n\n/** Size a collection view requests for each cell before its contents render, keeping scroll estimates steady. */\ntype ItemSizeProps = {\n /** Height in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemHeight?: number | undefined;\n /** Width in pixels every cell asks for until its contents render; unset lets each cell size itself. */\n estimatedItemWidth?: number | undefined;\n};\n\n/** Controlled selection shared by the multi-item collection views. */\ntype SelectionProps = {\n /** Ids of the items to keep selected; omitting it leaves the view's own selection alone. */\n selectedIds?: string[] | null | undefined;\n /** Called with the ids of every selected item whenever the selection changes, and once on mount. */\n onSelectionChanged?: ((ids: string[]) => void) | null | undefined;\n /** How much the user may select, one item at a time unless `MULTIPLE` or `NONE` is given. */\n selectionMode?: Gtk.SelectionMode | null | undefined;\n};\n\n/** Controlled expansion for the views that turn nested `ListItem.children` into a tree. */\ntype ExpansionProps = {\n /** Ids of the items to keep expanded; omitting it leaves the rows' own expanded state alone. */\n expandedIds?: string[] | null | undefined;\n /** Called with the ids of every expanded row whenever expansion changes. */\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n};\n\n/** The data a collection view renders, either as a plain item list or grouped into sections. */\ntype SourceProps<T, S> = {\n /** Items to render, nesting through `ListItem.children` for a tree; ignored once `sections` is given. */\n items?: ListItem<T>[] | undefined;\n /** Items grouped under section headers, rendered in place of `items`. */\n sections?: ListSection<S, T>[] | undefined;\n};\n\n/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */\ntype ColumnViewColumn<T = unknown> = Omit<GtkColumnViewColumnProps, \"factory\" | \"sorter\" | \"id\" | \"title\"> & {\n /** Stable identifier, also used to address the column through sorting props. */\n id: string;\n /** Text shown in the column header. */\n title: string;\n /** Renders the contents of this column's cell for one item. */\n renderCell: ListItemRenderer<T>;\n /** Makes the column header clickable, reporting the choice through `onSortChanged`. */\n isSortable?: boolean | undefined;\n /** Menu element popped up as the column header's context menu, on a right-click. */\n headerMenu?: ReactNode;\n};\n\n/** The declarative collection props {@link ColumnView} adds on top of Gtk.ColumnView's own. */\ntype ColumnViewOwnProps<T, S> = SelectionProps &\n ExpansionProps &\n SourceProps<T, S> &\n Omit<ItemSizeProps, \"estimatedItemWidth\"> & {\n /** Columns to render, in order; each carries its own cell renderer. */\n columns: ColumnViewColumn<T>[];\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n /** Id of the column the view is sorted by, making sorting controlled. */\n sortColumn?: string | null | undefined;\n /** Direction `sortColumn` is sorted in, defaulting to ascending. */\n sortOrder?: Gtk.SortType | null | undefined;\n /** Called when the user sorts from a header, with the primary column's id, or null, and its order. */\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n };\n\n/**\n * Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with\n * declarative collection props: flat items or grouped sections, controlled selection\n * and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section\n * header renderer, and the columns to render.\n */\ntype ColumnViewProps<T = unknown, S = unknown> = Omit<\n GtkColumnViewProps,\n \"columns\" | \"model\" | \"headerFactory\" | keyof ColumnViewOwnProps<T, S>\n> &\nColumnViewOwnProps<T, S>;\n\n/** The declarative collection props {@link DropDown} and `ComboRow` add on top of their widget's own. */\ntype DropDownOwnProps<T, S> = SourceProps<T, S> & {\n /** Id of the currently selected item, making the selection controlled. */\n selectedId?: string | null | undefined;\n /** Called with the id of the item that became selected. */\n onSelectionChanged?: ((id: string) => void) | null | undefined;\n /** Renders the collapsed display, and the popup rows too unless `renderListItem` is given. */\n renderItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for items in the open popup list, falling back to renderItem when omitted. */\n renderListItem?: ListItemRenderer<T> | null | undefined;\n /** Renderer for section headers in the popup list. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n};\n\n/** A drop-down-shaped widget's props with its model and factories swapped for the declarative collection props. */\ntype DropDownWidgetProps<Widget, T, S> = Omit<\n Widget,\n \"model\" | \"factory\" | \"listFactory\" | \"headerFactory\" | keyof DropDownOwnProps<T, S>\n> &\nDropDownOwnProps<T, S>;\n\n/**\n * Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the collapsed display, popup rows, and popup section headers.\n */\ntype DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;\n\n/** The declarative collection props {@link GridView} adds on top of Gtk.GridView's own. */\ntype GridViewOwnProps<T> = ItemSizeProps &\n SelectionProps & {\n /** Items to render as cells; a grid is always flat, so `ListItem.children` is ignored. */\n items?: ListItem<T>[] | undefined;\n /** Renders the contents of one cell. */\n renderItem: ListItemRenderer<T>;\n };\n\n/**\n * Props for {@link GridView}. Combines the underlying Gtk.GridView props with\n * declarative collection props: items, a per-cell renderItem, controlled selection,\n * and estimated item sizing.\n */\ntype GridViewProps<T = unknown> = Omit<GtkGridViewProps, \"model\" | \"factory\" | keyof GridViewOwnProps<T>> &\n GridViewOwnProps<T>;\n\n/** The declarative collection props {@link ListView} adds on top of Gtk.ListView's own. */\ntype ListViewOwnProps<T, S> = ItemSizeProps &\n SelectionProps &\n ExpansionProps &\n SourceProps<T, S> & {\n /** Renders the contents of one row. */\n renderItem: ListItemRenderer<T>;\n /** Renders the header shown above each section. */\n renderHeader?: ListSectionRenderer<S> | null | undefined;\n };\n\n/**\n * Props for {@link ListView}. Combines the underlying Gtk.ListView props with\n * declarative collection props: flat items or grouped sections, a per-row renderItem,\n * an optional section header renderer, controlled selection and expansion, and\n * estimated item sizing.\n */\ntype ListViewProps<T = unknown, S = unknown> = Omit<\n GtkListViewProps,\n \"model\" | \"factory\" | \"headerFactory\" | keyof ListViewOwnProps<T, S>\n> &\nListViewOwnProps<T, S>;\n\nexport {\n type SelectionProps,\n type ExpansionProps,\n type DropDownOwnProps,\n type DropDownWidgetProps,\n type ListItem,\n type ListSection,\n type ListItemRenderArgs,\n type ListSectionRenderArgs,\n type ListItemRenderer,\n type ListSectionRenderer,\n type ColumnViewColumn,\n type ColumnViewProps,\n type DropDownProps,\n type GridViewProps,\n type ListViewProps,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/components",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
4
|
"description": "High-level GTKX components for declarative collection views, menus, and containers with attach-time placement",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"node": ">=24"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@gtkx/react": "1.0.0-rc.
|
|
48
|
-
"@gtkx/utils": "1.0.0-rc.
|
|
47
|
+
"@gtkx/react": "1.0.0-rc.4",
|
|
48
|
+
"@gtkx/utils": "1.0.0-rc.4"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^19.2"
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@codspeed/vitest-plugin": "^5.7.1",
|
|
55
55
|
"vitest": "^4.1.10",
|
|
56
|
-
"@gtkx/config": "1.0.0-rc.
|
|
57
|
-
"@gtkx/runtime": "1.0.0-rc.
|
|
58
|
-
"@gtkx/testing": "1.0.0-rc.
|
|
59
|
-
"@gtkx/vitest": "1.0.0-rc.
|
|
56
|
+
"@gtkx/config": "1.0.0-rc.4",
|
|
57
|
+
"@gtkx/runtime": "1.0.0-rc.4",
|
|
58
|
+
"@gtkx/testing": "1.0.0-rc.4",
|
|
59
|
+
"@gtkx/vitest": "1.0.0-rc.4"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"bench": "NODE_ENV=production vitest bench --run --config vitest.bench.config.ts",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { AdwComboRow } from "@gtkx/jsx/adw";
|
|
3
|
+
import type { DropDownBaseProps } from "../internal/drop-down.js";
|
|
4
|
+
import type { ComboRowProps } from "./types.js";
|
|
5
|
+
import { DropDownBase } from "../internal/drop-down.js";
|
|
6
|
+
|
|
7
|
+
/** Call signature of {@link ComboRow}, generic in the item and section value types. */
|
|
8
|
+
type ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
12
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
13
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
14
|
+
*/
|
|
15
|
+
const ComboRow: ComboRowComponent = ComboRowImpl as ComboRowComponent;
|
|
16
|
+
|
|
17
|
+
function ComboRowImpl(props: DropDownBaseProps): ReactNode {
|
|
18
|
+
return <DropDownBase {...props} component={AdwComboRow} />;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { ComboRow };
|
package/src/adw/index.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export { ComboRow } from "./combo-row.js";
|
|
1
2
|
export { ToastProvider, useToast, useToastOverlay } from "./toast.js";
|
|
2
|
-
export type {
|
|
3
|
+
export type {
|
|
4
|
+
ComboRowProps,
|
|
5
|
+
ToastController,
|
|
6
|
+
ToastOptions,
|
|
7
|
+
ToastOverlayController,
|
|
8
|
+
ToastProviderProps,
|
|
9
|
+
} from "./types.js";
|
package/src/adw/types.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
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";
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative
|
|
8
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
9
|
+
* for the row display, popup rows, and popup section headers.
|
|
10
|
+
*/
|
|
11
|
+
type ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;
|
|
5
12
|
/**
|
|
6
13
|
* Describes a toast raised through {@link useToast}: the construct-time properties of an
|
|
7
14
|
* `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.
|
|
@@ -12,7 +19,7 @@ type ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, "onButtonCli
|
|
|
12
19
|
type ToastController = {
|
|
13
20
|
/** Builds a toast, shows it through the overlay, and returns it. */
|
|
14
21
|
show: (options?: ToastOptions) => Adw.Toast;
|
|
15
|
-
/** Dismisses a single toast, typically one returned by
|
|
22
|
+
/** Dismisses a single toast, typically one returned by `ToastController.show`. */
|
|
16
23
|
dismiss: (toast: Adw.Toast) => void;
|
|
17
24
|
};
|
|
18
25
|
|
|
@@ -26,7 +33,14 @@ type ToastOverlayController = {
|
|
|
26
33
|
type ToastProviderProps = {
|
|
27
34
|
/** Ref also given to the `AdwToastOverlay` the toasts appear over. */
|
|
28
35
|
overlayRef: RefObject<Adw.ToastOverlay | null>;
|
|
36
|
+
/** Subtree whose `useToast` and `useToastOverlay` calls target that overlay. */
|
|
29
37
|
children?: ReactNode | undefined;
|
|
30
38
|
};
|
|
31
39
|
|
|
32
|
-
export {
|
|
40
|
+
export {
|
|
41
|
+
type ComboRowProps,
|
|
42
|
+
type ToastOptions,
|
|
43
|
+
type ToastController,
|
|
44
|
+
type ToastOverlayController,
|
|
45
|
+
type ToastProviderProps,
|
|
46
|
+
};
|