@gtkx/components 1.0.0-rc.1 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adw/index.d.ts +3 -0
- package/dist/adw/index.d.ts.map +1 -0
- package/dist/adw/index.js +2 -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 +28 -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 +8 -27
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +112 -81
- 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/expansion.d.ts +9 -0
- package/dist/internal/expansion.d.ts.map +1 -0
- package/dist/internal/expansion.js +75 -0
- package/dist/internal/expansion.js.map +1 -0
- package/dist/internal/selection.d.ts +12 -0
- package/dist/internal/selection.d.ts.map +1 -0
- package/dist/internal/selection.js +99 -0
- package/dist/internal/selection.js.map +1 -0
- package/dist/internal/use-collection.d.ts +18 -0
- package/dist/internal/use-collection.d.ts.map +1 -0
- package/dist/internal/use-collection.js +42 -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 +97 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -6
- package/src/adw/index.ts +2 -0
- package/src/adw/toast.tsx +74 -0
- package/src/adw/types.ts +32 -0
- package/src/column-view.tsx +176 -160
- package/src/drop-down.tsx +180 -167
- package/src/grid-view.tsx +29 -73
- package/src/index.ts +18 -25
- 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/expansion.ts +123 -0
- package/src/internal/selection.tsx +159 -0
- package/src/internal/use-collection.tsx +70 -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 +155 -24
- 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/size-group.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size-group.d.ts","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"size-group.d.ts","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAoB,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAStE,KAAK,kBAAkB,GAAG,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,SAAS,CAAC,GAAG;IAC/D,KAAK,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CAC9E,CAAC;AAIF;;;GAGG;AACH,QAAA,MAAM,SAAS,EAAE,kBAA4E,CAAC;AAoD9F,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/size-group.js
CHANGED
|
@@ -1,57 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { GtkSizeGroup } from "@gtkx/jsx/gtk";
|
|
3
|
-
import {
|
|
4
|
-
import { createContext, useCallback, useContext,
|
|
3
|
+
import { useMergedRef } from "@gtkx/react/internal";
|
|
4
|
+
import { createContext, useCallback, useContext, useState } from "react";
|
|
5
5
|
const SizeGroupContext = createContext(null);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const SizeGroupChild = SizeGroupChildImpl;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`
|
|
9
|
+
* at a common size in the given mode, without contributing a widget of its own.
|
|
10
|
+
*/
|
|
11
|
+
const SizeGroup = Object.assign(SizeGroupRoot, { Child: SizeGroupChild });
|
|
12
|
+
const useRegister = () => {
|
|
13
|
+
const register = useContext(SizeGroupContext);
|
|
14
|
+
if (register === null) {
|
|
9
15
|
throw new Error("<SizeGroup.Child> must be a child of <SizeGroup>");
|
|
10
|
-
|
|
16
|
+
}
|
|
17
|
+
return register;
|
|
11
18
|
};
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
19
|
+
function SizeGroupChildImpl(props) {
|
|
20
|
+
const { component: Component, ref, ...rest } = props;
|
|
21
|
+
const refCallback = useMergedRef(ref, useRegister());
|
|
22
|
+
return _jsx(Component, { ...rest, ref: refCallback });
|
|
23
|
+
}
|
|
24
|
+
const addWidget = (widgets, widget) => widgets.includes(widget) ? widgets : [...widgets, widget];
|
|
25
|
+
const removeWidget = (widgets, widget) => widgets.filter((entry) => entry !== widget);
|
|
26
|
+
function SizeGroupRoot(props) {
|
|
27
|
+
const { mode, ref, children } = props;
|
|
28
|
+
const [widgets, setWidgets] = useState([]);
|
|
29
|
+
const register = useCallback((widget) => {
|
|
30
|
+
if (widget === null) {
|
|
16
31
|
return;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let group = null;
|
|
27
|
-
return {
|
|
28
|
-
addWidget: (widget) => {
|
|
29
|
-
members.add(widget);
|
|
30
|
-
group?.addWidget(widget);
|
|
31
|
-
},
|
|
32
|
-
removeWidget: (widget) => {
|
|
33
|
-
members.delete(widget);
|
|
34
|
-
group?.removeWidget(widget);
|
|
35
|
-
},
|
|
36
|
-
setGroup: (next) => {
|
|
37
|
-
group = next;
|
|
38
|
-
if (next)
|
|
39
|
-
for (const member of members)
|
|
40
|
-
next.addWidget(member);
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Creates a Gtk.SizeGroup that keeps its member widgets at a common size. Members join the group
|
|
46
|
-
* through {@link SizeGroup.Child}.
|
|
47
|
-
*/
|
|
48
|
-
export const SizeGroup = Object.assign(({ mode, ref, children }) => {
|
|
49
|
-
const registryRef = useRef(null);
|
|
50
|
-
if (registryRef.current === null)
|
|
51
|
-
registryRef.current = createRegistry();
|
|
52
|
-
const registry = registryRef.current;
|
|
53
|
-
const setGroup = useCallback((group) => registry.setGroup(group), [registry]);
|
|
54
|
-
const mergedRef = useMergeRefs(ref, setGroup);
|
|
55
|
-
return (_jsxs(_Fragment, { children: [_jsx(GtkSizeGroup, { ref: mergedRef, mode: mode }), _jsx(SizeGroupContext.Provider, { value: registry, children: children })] }));
|
|
56
|
-
}, { Child: SizeGroupChild });
|
|
32
|
+
}
|
|
33
|
+
setWidgets((previous) => addWidget(previous, widget));
|
|
34
|
+
return () => {
|
|
35
|
+
setWidgets((previous) => removeWidget(previous, widget));
|
|
36
|
+
};
|
|
37
|
+
}, [setWidgets]);
|
|
38
|
+
return (_jsxs(_Fragment, { children: [_jsx(GtkSizeGroup, { ref: ref, mode: mode, widgets: widgets }), _jsx(SizeGroupContext.Provider, { value: register, children: children })] }));
|
|
39
|
+
}
|
|
40
|
+
export { SizeGroup };
|
|
57
41
|
//# sourceMappingURL=size-group.js.map
|
package/dist/size-group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size-group.js","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"size-group.js","sourceRoot":"","sources":["../src/size-group.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAczE,MAAM,gBAAgB,GAAG,aAAa,CAAkB,IAAI,CAAC,CAAC;AAC9D,MAAM,cAAc,GAAG,kBAAyF,CAAC;AACjH;;;GAGG;AACH,MAAM,SAAS,GAAuB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;AAE9F,MAAM,WAAW,GAAG,GAAa,EAAE;IAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE9C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,QAAQ,CAAC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,CACf,CAAC;IAEF,OAAO,CACH,8BACI,KAAC,YAAY,IAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAI,EACxD,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAA6B,IACnF,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { ElementType, ReactNode, Ref, RefCallback } from \"react\";\nimport { GtkSizeGroup } from \"@gtkx/jsx/gtk\";\nimport { useMergedRef } from \"@gtkx/react/internal\";\nimport { createContext, useCallback, useContext, useState } from \"react\";\nimport type { SizeGroupChildProps, SizeGroupProps } from \"./types.js\";\n\ntype Register = RefCallback<Gtk.Widget | null>;\n\ntype SizeGroupChildRuntimeProps = {\n component: ElementType;\n ref?: Ref<Gtk.Widget | null> | undefined;\n} & Record<string, unknown>;\n\ntype SizeGroupComponent = ((props: SizeGroupProps) => ReactNode) & {\n Child: <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;\n};\n\nconst SizeGroupContext = createContext<Register | null>(null);\nconst SizeGroupChild = SizeGroupChildImpl as <C extends ElementType>(props: SizeGroupChildProps<C>) => ReactNode;\n/**\n * Creates a Gtk.SizeGroup that keeps widgets joined through `SizeGroup.Child`\n * at a common size in the given mode, without contributing a widget of its own.\n */\nconst SizeGroup: SizeGroupComponent = Object.assign(SizeGroupRoot, { Child: SizeGroupChild });\n\nconst useRegister = (): Register => {\n const register = useContext(SizeGroupContext);\n\n if (register === null) {\n throw new Error(\"<SizeGroup.Child> must be a child of <SizeGroup>\");\n }\n\n return register;\n};\n\nfunction SizeGroupChildImpl(props: SizeGroupChildRuntimeProps): ReactNode {\n const { component: Component, ref, ...rest } = props;\n const refCallback = useMergedRef<Gtk.Widget | null>(ref, useRegister());\n\n return <Component {...rest} ref={refCallback} />;\n}\n\nconst addWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>\n widgets.includes(widget) ? widgets : [...widgets, widget];\n\nconst removeWidget = (widgets: Gtk.Widget[], widget: Gtk.Widget): Gtk.Widget[] =>\n widgets.filter((entry) => entry !== widget);\n\nfunction SizeGroupRoot(props: SizeGroupProps): ReactNode {\n const { mode, ref, children } = props;\n const [widgets, setWidgets] = useState<Gtk.Widget[]>([]);\n\n const register = useCallback<Register>(\n (widget) => {\n if (widget === null) {\n return;\n }\n\n setWidgets((previous) => addWidget(previous, widget));\n\n return () => {\n setWidgets((previous) => removeWidget(previous, widget));\n };\n },\n [setWidgets],\n );\n\n return (\n <>\n <GtkSizeGroup ref={ref} mode={mode} widgets={widgets} />\n <SizeGroupContext.Provider value={register}>{children}</SizeGroupContext.Provider>\n </>\n );\n}\n\nexport { SizeGroup };\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { GtkColumnViewColumnProps, GtkColumnViewProps, GtkDropDown, GtkGridViewProps, GtkListViewProps } from "@gtkx/jsx/gtk";
|
|
3
|
+
import type { ComponentPropsWithRef, ElementType, ReactNode, Ref } from "react";
|
|
4
|
+
/** Props of a container's Child component: the widget to render and its own props. */
|
|
5
|
+
type ChildProps<C extends ElementType> = {
|
|
5
6
|
component: C;
|
|
6
|
-
} &
|
|
7
|
+
} & ComponentPropsWithRef<C>;
|
|
7
8
|
/** Props of a component whose backing widget defaults to one type but can be swapped through `component`. */
|
|
8
|
-
|
|
9
|
+
type WidgetProps<C extends ElementType, Own = unknown, ExtraOmit extends string = never> = Own & {
|
|
9
10
|
component?: C;
|
|
10
11
|
} & Omit<ComponentPropsWithRef<C>, ExtraOmit | keyof Own>;
|
|
11
12
|
/**
|
|
12
13
|
* A single item in a collection model, identified by a stable id and holding an
|
|
13
14
|
* arbitrary value. Nested items form a tree.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
type Item<T = unknown> = {
|
|
16
17
|
/** Stable identifier used to track the item across updates and selection. */
|
|
17
18
|
id: string;
|
|
18
19
|
value: T;
|
|
19
|
-
children?:
|
|
20
|
+
children?: Item<T>[] | undefined;
|
|
20
21
|
/** Hides the tree expander arrow even when the item has children. */
|
|
21
22
|
hideExpander?: boolean | undefined;
|
|
22
23
|
/** Adds indentation matching the item's depth in the tree. */
|
|
@@ -25,15 +26,15 @@ export type ItemNode<T = unknown> = {
|
|
|
25
26
|
indentForIcon?: boolean | undefined;
|
|
26
27
|
};
|
|
27
28
|
/** A group of items rendered under a shared section header. */
|
|
28
|
-
|
|
29
|
+
type Section<S = unknown, T = unknown> = {
|
|
29
30
|
/** Stable identifier used to track the section across updates. */
|
|
30
31
|
id: string;
|
|
31
32
|
value: S;
|
|
32
33
|
/** Items belonging to this section. */
|
|
33
|
-
data:
|
|
34
|
+
data: Item<T>[];
|
|
34
35
|
};
|
|
35
|
-
/**
|
|
36
|
-
|
|
36
|
+
/** Arguments passed to an {@link ItemRenderer} when rendering one cell. */
|
|
37
|
+
type RenderItemArgs<T> = {
|
|
37
38
|
item: T;
|
|
38
39
|
index: number;
|
|
39
40
|
/** Depth of the item within a tree, starting at zero for top-level items. */
|
|
@@ -41,28 +42,100 @@ export type RenderItemProps<T> = {
|
|
|
41
42
|
/** Whether the item is currently expanded in a tree view. */
|
|
42
43
|
isExpanded?: boolean | undefined;
|
|
43
44
|
};
|
|
44
|
-
|
|
45
|
+
/** Arguments passed to a {@link HeaderRenderer} when rendering one section header. */
|
|
46
|
+
type RenderHeaderArgs<S> = {
|
|
47
|
+
section: S;
|
|
48
|
+
};
|
|
49
|
+
/** Renders the contents of one cell of a collection view. */
|
|
50
|
+
type ItemRenderer<T> = (args: RenderItemArgs<T>) => ReactNode;
|
|
51
|
+
/** Renders the contents of one section header of a collection view. */
|
|
52
|
+
type HeaderRenderer<S> = (args: RenderHeaderArgs<S>) => ReactNode;
|
|
53
|
+
type ItemSizeProps = {
|
|
45
54
|
estimatedItemHeight?: number | undefined;
|
|
46
55
|
estimatedItemWidth?: number | undefined;
|
|
47
56
|
};
|
|
48
|
-
|
|
57
|
+
type SelectionProps = {
|
|
49
58
|
selectedIds?: string[] | null | undefined;
|
|
50
59
|
onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
|
|
51
60
|
selectionMode?: Gtk.SelectionMode | null | undefined;
|
|
52
61
|
};
|
|
53
|
-
|
|
62
|
+
type ExpansionProps = {
|
|
54
63
|
expandedIds?: string[] | null | undefined;
|
|
55
64
|
onExpandedChange?: ((ids: string[]) => void) | null | undefined;
|
|
56
65
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
type SourceProps<T, S> = {
|
|
67
|
+
items?: Item<T>[] | undefined;
|
|
68
|
+
sections?: Section<S, T>[] | undefined;
|
|
69
|
+
};
|
|
70
|
+
/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */
|
|
71
|
+
type Column<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter" | "id" | "title"> & {
|
|
72
|
+
/** Stable identifier, also used to address the column through sorting props. */
|
|
73
|
+
id: string;
|
|
74
|
+
title: string;
|
|
75
|
+
renderCell: ItemRenderer<T>;
|
|
76
|
+
/** Whether clicking the column header sorts by it. */
|
|
77
|
+
sortable?: boolean | undefined;
|
|
78
|
+
headerMenu?: ReactNode;
|
|
79
|
+
};
|
|
80
|
+
type ColumnViewOwnProps<T, S> = SelectionProps & ExpansionProps & SourceProps<T, S> & Omit<ItemSizeProps, "estimatedItemWidth"> & {
|
|
81
|
+
columns: Column<T>[];
|
|
82
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
83
|
+
/** Id of the column the view is sorted by, making sorting controlled. */
|
|
84
|
+
sortColumn?: string | null | undefined;
|
|
85
|
+
sortOrder?: Gtk.SortType | null | undefined;
|
|
86
|
+
onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with
|
|
90
|
+
* declarative collection props: flat items or grouped sections, controlled selection
|
|
91
|
+
* and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section
|
|
92
|
+
* header renderer, and the columns to render.
|
|
93
|
+
*/
|
|
94
|
+
type ColumnViewProps<T = unknown, S = unknown> = Omit<GtkColumnViewProps, "columns" | "model" | "headerFactory" | keyof ColumnViewOwnProps<T, S>> & ColumnViewOwnProps<T, S>;
|
|
95
|
+
type DropDownOwnProps<T, S> = SourceProps<T, S> & {
|
|
96
|
+
/** Id of the currently selected item, making the selection controlled. */
|
|
97
|
+
selectedId?: string | null | undefined;
|
|
98
|
+
onSelectionChanged?: ((id: string) => void) | null | undefined;
|
|
99
|
+
renderItem?: ItemRenderer<T> | null | undefined;
|
|
100
|
+
/** Renderer for items in the open popup list, falling back to renderItem when omitted. */
|
|
101
|
+
renderListItem?: ItemRenderer<T> | null | undefined;
|
|
102
|
+
/** Renderer for section headers in the popup list. */
|
|
103
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Props for {@link DropDown}. The backing widget is chosen through the `component` prop, defaulting to
|
|
107
|
+
* GtkDropDown, and its own props combine with the declarative collection props.
|
|
108
|
+
*/
|
|
109
|
+
type DropDownProps<T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown> = WidgetProps<C, DropDownOwnProps<T, S>, "model" | "factory" | "listFactory" | "headerFactory">;
|
|
110
|
+
type GridViewOwnProps<T> = ItemSizeProps & SelectionProps & {
|
|
111
|
+
items?: Item<T>[] | undefined;
|
|
112
|
+
renderItem: ItemRenderer<T>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Props for {@link GridView}. Combines the underlying Gtk.GridView props with
|
|
116
|
+
* declarative collection props: items, a per-cell renderItem, controlled selection,
|
|
117
|
+
* and estimated item sizing.
|
|
118
|
+
*/
|
|
119
|
+
type GridViewProps<T = unknown> = Omit<GtkGridViewProps, "model" | "factory" | keyof GridViewOwnProps<T>> & GridViewOwnProps<T>;
|
|
120
|
+
type ListViewOwnProps<T, S> = ItemSizeProps & SelectionProps & ExpansionProps & SourceProps<T, S> & {
|
|
121
|
+
renderItem: ItemRenderer<T>;
|
|
122
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Props for {@link ListView}. Combines the underlying Gtk.ListView props with
|
|
126
|
+
* declarative collection props: flat items or grouped sections, a per-row renderItem,
|
|
127
|
+
* an optional section header renderer, controlled selection and expansion, and
|
|
128
|
+
* estimated item sizing.
|
|
129
|
+
*/
|
|
130
|
+
type ListViewProps<T = unknown, S = unknown> = Omit<GtkListViewProps, "model" | "factory" | "headerFactory" | keyof ListViewOwnProps<T, S>> & ListViewOwnProps<T, S>;
|
|
131
|
+
/** Props for {@link SizeGroup}. */
|
|
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;
|
|
67
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, };
|
|
68
141
|
//# 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,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
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,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEhF,sFAAsF;AACtF,KAAK,UAAU,CAAC,CAAC,SAAS,WAAW,IAAI;IACrC,SAAS,EAAE,CAAC,CAAC;CAChB,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAE7B,6GAA6G;AAC7G,KAAK,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,GAAG,GAAG,OAAO,EAAE,SAAS,SAAS,MAAM,GAAG,KAAK,IAAI,GAAG,GAAG;IAC7F,SAAS,CAAC,EAAE,CAAC,CAAC;CACjB,GAAG,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC;AAE1D;;;GAGG;AACH,KAAK,IAAI,CAAC,CAAC,GAAG,OAAO,IAAI;IACrB,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IACjC,qEAAqE;IACr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5C,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC;AAEF,iGAAiG;AACjG,KAAK,mBAAmB,CAAC,CAAC,SAAS,WAAW,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAEhE,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GAC3B,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { ComponentPropsWithRef, ElementType } from \"react\";\n\n/** Props of a container's Child component: the widget to render
|
|
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"]}
|
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.2",
|
|
4
4
|
"description": "High-level GTKX components for declarative collection views, menus, and containers with attach-time placement",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./adw": {
|
|
34
|
+
"types": "./dist/adw/index.d.ts",
|
|
35
|
+
"default": "./dist/adw/index.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"sideEffects": false,
|
|
@@ -40,15 +44,22 @@
|
|
|
40
44
|
"node": ">=24"
|
|
41
45
|
},
|
|
42
46
|
"dependencies": {
|
|
43
|
-
"@gtkx/
|
|
44
|
-
"@gtkx/
|
|
47
|
+
"@gtkx/react": "1.0.0-rc.2",
|
|
48
|
+
"@gtkx/utils": "1.0.0-rc.2"
|
|
45
49
|
},
|
|
46
50
|
"peerDependencies": {
|
|
47
|
-
"react": "^19"
|
|
51
|
+
"react": "^19.2"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@codspeed/vitest-plugin": "^5.7.1",
|
|
55
|
+
"vitest": "^4.1.10",
|
|
56
|
+
"@gtkx/config": "1.0.0-rc.2",
|
|
57
|
+
"@gtkx/runtime": "1.0.0-rc.2",
|
|
58
|
+
"@gtkx/testing": "1.0.0-rc.2",
|
|
59
|
+
"@gtkx/vitest": "1.0.0-rc.2"
|
|
48
60
|
},
|
|
49
61
|
"scripts": {
|
|
50
|
-
"
|
|
51
|
-
"typecheck": "tsc -b --emitDeclarationOnly",
|
|
62
|
+
"bench": "NODE_ENV=production vitest bench --run --config vitest.bench.config.ts",
|
|
52
63
|
"release": "tsx ../../scripts/release-package.ts"
|
|
53
64
|
}
|
|
54
65
|
}
|
package/src/adw/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReactNode, RefObject } from "react";
|
|
2
|
+
import * as Adw from "@gtkx/gi/adw";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import type { ToastController, ToastOptions, ToastOverlayController, ToastProviderProps } from "./types.js";
|
|
5
|
+
|
|
6
|
+
type OverlayRef = RefObject<Adw.ToastOverlay | null>;
|
|
7
|
+
|
|
8
|
+
const ToastContext = createContext<OverlayRef | null>(null);
|
|
9
|
+
|
|
10
|
+
const useOverlayRef = (): OverlayRef => {
|
|
11
|
+
const overlayRef = useContext(ToastContext);
|
|
12
|
+
|
|
13
|
+
if (overlayRef === null) {
|
|
14
|
+
throw new Error("useToast and useToastOverlay must be used within a ToastProvider");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return overlayRef;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const buildToast = (options: ToastOptions): Adw.Toast => {
|
|
21
|
+
const { onButtonClicked, onDismissed, ...props } = options;
|
|
22
|
+
const toast = new Adw.Toast(props);
|
|
23
|
+
|
|
24
|
+
if (onButtonClicked != null) {
|
|
25
|
+
toast.on("button-clicked", onButtonClicked);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (onDismissed != null) {
|
|
29
|
+
toast.on("dismissed", onDismissed);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return toast;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Shares an Adw.ToastOverlay reference with the toast hooks in every descendant. */
|
|
36
|
+
function ToastProvider(props: ToastProviderProps): ReactNode {
|
|
37
|
+
return <ToastContext.Provider value={props.overlayRef}>{props.children}</ToastContext.Provider>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Returns a {@link ToastController} that shows and dismisses toasts on the nearest provider's overlay. */
|
|
41
|
+
function useToast(): ToastController {
|
|
42
|
+
const overlayRef = useOverlayRef();
|
|
43
|
+
|
|
44
|
+
return useMemo<ToastController>(
|
|
45
|
+
() => ({
|
|
46
|
+
show: (options?: ToastOptions) => {
|
|
47
|
+
const toast = buildToast(options ?? {});
|
|
48
|
+
overlayRef.current?.addToast(toast);
|
|
49
|
+
|
|
50
|
+
return toast;
|
|
51
|
+
},
|
|
52
|
+
dismiss: (toast: Adw.Toast) => {
|
|
53
|
+
toast.dismiss();
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
[overlayRef],
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Returns a {@link ToastOverlayController} for the nearest provider's overlay as a whole. */
|
|
61
|
+
function useToastOverlay(): ToastOverlayController {
|
|
62
|
+
const overlayRef = useOverlayRef();
|
|
63
|
+
|
|
64
|
+
return useMemo<ToastOverlayController>(
|
|
65
|
+
() => ({
|
|
66
|
+
dismissAll: () => {
|
|
67
|
+
overlayRef.current?.dismissAll();
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
[overlayRef],
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { ToastProvider, useToast, useToastOverlay };
|
package/src/adw/types.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as Adw from "@gtkx/gi/adw";
|
|
2
|
+
import type { AdwToastProps } from "@gtkx/jsx/adw";
|
|
3
|
+
import type { ReactNode, RefObject } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Describes a toast raised through {@link useToast}: the construct-time properties of an
|
|
7
|
+
* `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.
|
|
8
|
+
*/
|
|
9
|
+
type ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, "onButtonClicked" | "onDismissed">;
|
|
10
|
+
|
|
11
|
+
/** Imperative controls for individual toasts, returned by {@link useToast}. */
|
|
12
|
+
type ToastController = {
|
|
13
|
+
/** Builds a toast, shows it through the overlay, and returns it. */
|
|
14
|
+
show: (options?: ToastOptions) => Adw.Toast;
|
|
15
|
+
/** Dismisses a single toast, typically one returned by {@link ToastController.show}. */
|
|
16
|
+
dismiss: (toast: Adw.Toast) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */
|
|
20
|
+
type ToastOverlayController = {
|
|
21
|
+
/** Dismisses the shown toast and every queued one. */
|
|
22
|
+
dismissAll: () => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Props for {@link ToastProvider}. */
|
|
26
|
+
type ToastProviderProps = {
|
|
27
|
+
/** Ref also given to the `AdwToastOverlay` the toasts appear over. */
|
|
28
|
+
overlayRef: RefObject<Adw.ToastOverlay | null>;
|
|
29
|
+
children?: ReactNode | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { type ToastOptions, type ToastController, type ToastOverlayController, type ToastProviderProps };
|