@gtkx/components 1.0.0-rc.2 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adw/combo-row.d.ts +11 -0
- package/dist/adw/combo-row.d.ts.map +1 -0
- package/dist/adw/combo-row.js +14 -0
- package/dist/adw/combo-row.js.map +1 -0
- package/dist/adw/index.d.ts +2 -1
- package/dist/adw/index.d.ts.map +1 -1
- package/dist/adw/index.js +1 -0
- package/dist/adw/index.js.map +1 -1
- package/dist/adw/types.d.ts +9 -2
- package/dist/adw/types.d.ts.map +1 -1
- package/dist/adw/types.js.map +1 -1
- package/dist/column-view.js +2 -2
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +3 -5
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +5 -112
- package/dist/drop-down.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/drop-down.d.ts +16 -0
- package/dist/internal/drop-down.d.ts.map +1 -0
- package/dist/internal/drop-down.js +110 -0
- package/dist/internal/drop-down.js.map +1 -0
- package/dist/internal/expansion.d.ts +1 -1
- package/dist/internal/expansion.d.ts.map +1 -1
- package/dist/internal/expansion.js +3 -4
- package/dist/internal/expansion.js.map +1 -1
- package/dist/internal/selection.d.ts +1 -0
- package/dist/internal/selection.d.ts.map +1 -1
- package/dist/internal/selection.js +1 -0
- package/dist/internal/selection.js.map +1 -1
- package/dist/internal/use-collection.d.ts +1 -2
- package/dist/internal/use-collection.d.ts.map +1 -1
- package/dist/internal/use-collection.js +9 -17
- package/dist/internal/use-collection.js.map +1 -1
- package/dist/types.d.ts +7 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -7
- package/src/adw/combo-row.tsx +20 -0
- package/src/adw/index.ts +8 -1
- package/src/adw/types.ts +15 -2
- package/src/column-view.tsx +2 -2
- package/src/drop-down.tsx +9 -195
- package/src/index.ts +0 -1
- package/src/internal/drop-down.tsx +186 -0
- package/src/internal/expansion.ts +5 -6
- package/src/internal/selection.tsx +3 -0
- package/src/internal/use-collection.tsx +11 -24
- package/src/types.ts +13 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expansion.js","sourceRoot":"","sources":["../../src/internal/expansion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"expansion.js","sourceRoot":"","sources":["../../src/internal/expansion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAU1C,SAAS,gBAAgB;IACrB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACvB,CAAC;AAED,SAAS,eAAe,CAAC,GAAoB,EAAE,EAAiB,EAAE,GAAa;IAC3E,IAAI,EAAE,KAAK,IAAI,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC;QACnC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,GAAoB,EAAE,EAAiB,EAAE,MAAmB;IAC3E,MAAM,SAAS,GAAG,EAAE,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhD,IAAI,GAAG,CAAC,YAAY,EAAE,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;QACxD,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,IAAuB,EAAE,WAAqB;IAClE,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAEpC,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAA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IAAI,EAAE,WAAW,CAAC,CAAC;IACtC,CAAC;YAAS,CAAC;QACP,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED,MAAM,EAAE,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAC,OAAyB;IAC3C,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAgB,gBAAgB,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEhC,MAAM,MAAM,GAAG,cAAc,CAAC,GAAS,EAAE;QACrC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,eAAe,CAAC,GAAG,EAAE;QACjB,sBAAsB,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAE9B,OAAO,GAAG,EAAE;QACR,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAClE,CAAC,CAAC;AACN,CAAC;AAED,OAAO,EAAE,YAAY,EAAyB,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { RefObject } from \"react\";\nimport { useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type { Collection } from \"./collection.js\";\nimport { eachRow } from \"./collection.js\";\n\ntype ExpansionOptions = {\n collection: Collection;\n expandedIds?: string[] | null | undefined;\n onExpandedChange?: ((ids: string[]) => void) | null | undefined;\n};\n\ntype LastExpansion = { key: string };\n\nfunction newLastExpansion(): LastExpansion {\n return { key: \"\" };\n}\n\nfunction collectExpanded(row: Gtk.TreeListRow, id: string | null, ids: string[]): void {\n if (id !== null && row.getExpanded()) {\n ids.push(id);\n }\n}\n\nfunction expandRow(row: Gtk.TreeListRow, id: string | null, wanted: Set<string>): void {\n const isDesired = id !== null && wanted.has(id);\n\n if (row.isExpandable() && row.getExpanded() !== isDesired) {\n row.setExpanded(isDesired);\n }\n}\n\nfunction applyExpansion(tree: Gtk.TreeListModel, expandedIds: string[]): void {\n const wanted = new Set(expandedIds);\n\n eachRow(tree, (row, id) => {\n expandRow(row, id, wanted);\n });\n}\n\nfunction reportExpansion(\n collection: Collection,\n last: LastExpansion,\n onExpandedChange: ((ids: string[]) => void) | null | undefined,\n): void {\n const tree = collection.treeModel();\n\n if (tree === null) {\n return;\n }\n\n const ids: string[] = [];\n\n eachRow(tree, (row, id) => {\n collectExpanded(row, id, ids);\n });\n\n const key = ids.join(\" \");\n\n if (last.key === key) {\n return;\n }\n\n last.key = key;\n onExpandedChange?.(ids);\n}\n\nfunction reportWhenIdle(\n collection: Collection,\n last: LastExpansion,\n expanding: RefObject<boolean>,\n onExpandedChange: ((ids: string[]) => void) | null | undefined,\n): void {\n if (expanding.current) {\n return;\n }\n\n reportExpansion(collection, last, onExpandedChange);\n}\n\nfunction runControlledExpansion(\n collection: Collection,\n expandedIds: string[] | null | undefined,\n expanding: RefObject<boolean>,\n report: () => void,\n): void {\n const tree = collection.treeModel();\n\n if (tree === null || expandedIds == null) {\n return;\n }\n\n expanding.current = true;\n\n try {\n applyExpansion(tree, expandedIds);\n } finally {\n expanding.current = false;\n }\n\n report();\n}\n\nfunction useExpansion(options: ExpansionOptions): () => void {\n const { collection, expandedIds, onExpandedChange } = options;\n const [last] = useState<LastExpansion>(newLastExpansion);\n const expanding = useRef(false);\n\n const report = useEffectEvent((): void => {\n reportWhenIdle(collection, last, expanding, onExpandedChange);\n });\n\n useLayoutEffect(() => {\n runControlledExpansion(collection, expandedIds, expanding, report);\n }, [collection, expandedIds]);\n\n return () => {\n reportWhenIdle(collection, last, expanding, onExpandedChange);\n };\n}\n\nexport { useExpansion, type ExpansionOptions };\n"]}
|
|
@@ -6,6 +6,7 @@ type SelectionOptions = {
|
|
|
6
6
|
selectedIds?: string[] | null | undefined;
|
|
7
7
|
onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
|
|
8
8
|
selectionMode?: Gtk.SelectionMode | null | undefined;
|
|
9
|
+
onItemsChanged: () => void;
|
|
9
10
|
};
|
|
10
11
|
declare function useSelection(options: SelectionOptions): ReactElement;
|
|
11
12
|
export { useSelection, type SelectionOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/internal/selection.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,gBAAgB,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,kBAAkB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAClE,aAAa,CAAC,EAAE,GAAG,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/internal/selection.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,gBAAgB,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,kBAAkB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAClE,aAAa,CAAC,EAAE,GAAG,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,cAAc,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AA4HF,iBAAS,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,YAAY,CAsB7D;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,CAAC"}
|
|
@@ -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,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;AAuBlE,SAAS,cAAc,CAAC,SAA6B,EAAE,UAAsB;IACzE,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,UAAU,CAAC,IAAI,C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iSelection, 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
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
2
|
import type { ExpansionProps, Item, Section, SelectionProps } from "../types.js";
|
|
3
3
|
import type { Collection } from "./collection.js";
|
|
4
4
|
type CollectionDataOptions = {
|
|
5
5
|
items?: Item[] | undefined;
|
|
6
6
|
sections?: Section[] | undefined;
|
|
7
7
|
flat?: boolean | undefined;
|
|
8
|
-
applying?: RefObject<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,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOlD,KAAK,qBAAqB,GAAG;IACzB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,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, flat
|
|
8
|
+
const { items, sections, flat } = options;
|
|
22
9
|
const [gtk] = useState(createCollectionModel);
|
|
23
10
|
const index = useMemo(() => createCollectionIndex(items, sections, flat === true), [items, sections, flat]);
|
|
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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AU,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, Item, Section, 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?: Item[] | undefined;\n sections?: Section[] | undefined;\n flat?: 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, flat } = options;\n const [gtk] = useState(createCollectionModel);\n const index = useMemo(() => createCollectionIndex(items, sections, flat === true), [items, sections, flat]);\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,14 +1,10 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type { GtkColumnViewColumnProps, GtkColumnViewProps,
|
|
2
|
+
import type { GtkColumnViewColumnProps, GtkColumnViewProps, GtkDropDownProps, GtkGridViewProps, GtkListViewProps } from "@gtkx/jsx/gtk";
|
|
3
3
|
import type { ComponentPropsWithRef, ElementType, ReactNode, Ref } from "react";
|
|
4
4
|
/** Props of a container's Child component: the widget to render and its own props. */
|
|
5
5
|
type ChildProps<C extends ElementType> = {
|
|
6
6
|
component: C;
|
|
7
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>;
|
|
12
8
|
/**
|
|
13
9
|
* A single item in a collection model, identified by a stable id and holding an
|
|
14
10
|
* arbitrary value. Nested items form a tree.
|
|
@@ -102,11 +98,13 @@ type DropDownOwnProps<T, S> = SourceProps<T, S> & {
|
|
|
102
98
|
/** Renderer for section headers in the popup list. */
|
|
103
99
|
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
104
100
|
};
|
|
101
|
+
type DropDownWidgetProps<Widget, T, S> = Omit<Widget, "model" | "factory" | "listFactory" | "headerFactory" | keyof DropDownOwnProps<T, S>> & DropDownOwnProps<T, S>;
|
|
105
102
|
/**
|
|
106
|
-
* Props for {@link DropDown}.
|
|
107
|
-
*
|
|
103
|
+
* Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative
|
|
104
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
105
|
+
* for the collapsed display, popup rows, and popup section headers.
|
|
108
106
|
*/
|
|
109
|
-
type DropDownProps<T = unknown, S = unknown
|
|
107
|
+
type DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;
|
|
110
108
|
type GridViewOwnProps<T> = ItemSizeProps & SelectionProps & {
|
|
111
109
|
items?: Item<T>[] | undefined;
|
|
112
110
|
renderItem: ItemRenderer<T>;
|
|
@@ -137,5 +135,5 @@ type SizeGroupProps = {
|
|
|
137
135
|
};
|
|
138
136
|
/** Adds a single widget, rendered by the given component, to the enclosing {@link SizeGroup}. */
|
|
139
137
|
type SizeGroupChildProps<C extends ElementType> = ChildProps<C>;
|
|
140
|
-
export { type SelectionProps, type ExpansionProps, type ChildProps, type
|
|
138
|
+
export { type SelectionProps, type ExpansionProps, type ChildProps, type DropDownOwnProps, type DropDownWidgetProps, 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, };
|
|
141
139
|
//# 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,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.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA0LA,OAAO,EAmBN,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 { 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/**\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\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\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 DropDownOwnProps,\n type DropDownWidgetProps,\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"]}
|
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.3",
|
|
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.3",
|
|
48
|
+
"@gtkx/utils": "1.0.0-rc.3"
|
|
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.3",
|
|
57
|
+
"@gtkx/runtime": "1.0.0-rc.3",
|
|
58
|
+
"@gtkx/testing": "1.0.0-rc.3",
|
|
59
|
+
"@gtkx/vitest": "1.0.0-rc.3"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"bench": "NODE_ENV=production vitest bench --run --config vitest.bench.config.ts",
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
type ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
11
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
12
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
13
|
+
*/
|
|
14
|
+
const ComboRow: ComboRowComponent = ComboRowImpl as ComboRowComponent;
|
|
15
|
+
|
|
16
|
+
function ComboRowImpl(props: DropDownBaseProps): ReactNode {
|
|
17
|
+
return <DropDownBase {...props} component={AdwComboRow} />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
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.
|
|
@@ -29,4 +36,10 @@ type ToastProviderProps = {
|
|
|
29
36
|
children?: ReactNode | undefined;
|
|
30
37
|
};
|
|
31
38
|
|
|
32
|
-
export {
|
|
39
|
+
export {
|
|
40
|
+
type ComboRowProps,
|
|
41
|
+
type ToastOptions,
|
|
42
|
+
type ToastController,
|
|
43
|
+
type ToastOverlayController,
|
|
44
|
+
type ToastProviderProps,
|
|
45
|
+
};
|
package/src/column-view.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
3
|
import { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
|
|
4
|
-
import {
|
|
4
|
+
import { useSignal } from "@gtkx/react";
|
|
5
5
|
import { omit } from "@gtkx/utils";
|
|
6
6
|
import { useLayoutEffect, useRef } from "react";
|
|
7
7
|
import type { CellSize } from "./internal/cells.js";
|
|
@@ -120,7 +120,7 @@ const syncSort = (
|
|
|
120
120
|
|
|
121
121
|
const useColumnSorting = (view: Gtk.ColumnView | null, sort: SortProps, columns: Column<never>[]): void => {
|
|
122
122
|
const sorting = useRef(false);
|
|
123
|
-
const sorter =
|
|
123
|
+
const sorter = view?.getSorter() ?? null;
|
|
124
124
|
const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;
|
|
125
125
|
|
|
126
126
|
useSignal(columnSorter, "changed", (): void => {
|