@gtkx/components 1.0.0-rc.1 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adw/combo-row.d.ts +11 -0
- package/dist/adw/combo-row.d.ts.map +1 -0
- package/dist/adw/combo-row.js +14 -0
- package/dist/adw/combo-row.js.map +1 -0
- package/dist/adw/index.d.ts +4 -0
- package/dist/adw/index.d.ts.map +1 -0
- package/dist/adw/index.js +3 -0
- package/dist/adw/index.js.map +1 -0
- package/dist/adw/toast.d.ts +10 -0
- package/dist/adw/toast.d.ts.map +1 -0
- package/dist/adw/toast.js +51 -0
- package/dist/adw/toast.js.map +1 -0
- package/dist/adw/types.d.ts +35 -0
- package/dist/adw/types.d.ts.map +1 -0
- package/dist/adw/types.js +2 -0
- package/dist/adw/types.js.map +1 -0
- package/dist/column-view.d.ts +7 -29
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +98 -70
- package/dist/column-view.js.map +1 -1
- package/dist/drop-down.d.ts +7 -28
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +10 -86
- package/dist/drop-down.js.map +1 -1
- package/dist/grid-view.d.ts +6 -16
- package/dist/grid-view.d.ts.map +1 -1
- package/dist/grid-view.js +25 -33
- package/dist/grid-view.js.map +1 -1
- package/dist/index.d.ts +6 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +50 -0
- package/dist/internal/cells.d.ts.map +1 -0
- package/dist/internal/cells.js +185 -0
- package/dist/internal/cells.js.map +1 -0
- package/dist/internal/collection-index.d.ts +21 -0
- package/dist/internal/collection-index.d.ts.map +1 -0
- package/dist/internal/collection-index.js +106 -0
- package/dist/internal/collection-index.js.map +1 -0
- package/dist/internal/collection-model.d.ts +12 -0
- package/dist/internal/collection-model.d.ts.map +1 -0
- package/dist/internal/collection-model.js +164 -0
- package/dist/internal/collection-model.js.map +1 -0
- package/dist/internal/collection.d.ts +18 -0
- package/dist/internal/collection.d.ts.map +1 -0
- package/dist/internal/collection.js +64 -0
- package/dist/internal/collection.js.map +1 -0
- package/dist/internal/drop-down.d.ts +16 -0
- package/dist/internal/drop-down.d.ts.map +1 -0
- package/dist/internal/drop-down.js +110 -0
- package/dist/internal/drop-down.js.map +1 -0
- package/dist/internal/expansion.d.ts +9 -0
- package/dist/internal/expansion.d.ts.map +1 -0
- package/dist/internal/expansion.js +74 -0
- package/dist/internal/expansion.js.map +1 -0
- package/dist/internal/selection.d.ts +13 -0
- package/dist/internal/selection.d.ts.map +1 -0
- package/dist/internal/selection.js +100 -0
- package/dist/internal/selection.js.map +1 -0
- package/dist/internal/use-collection.d.ts +17 -0
- package/dist/internal/use-collection.d.ts.map +1 -0
- package/dist/internal/use-collection.js +34 -0
- package/dist/internal/use-collection.js.map +1 -0
- package/dist/internal/use-widget-ref.d.ts +4 -0
- package/dist/internal/use-widget-ref.d.ts.map +1 -0
- package/dist/internal/use-widget-ref.js +8 -0
- package/dist/internal/use-widget-ref.js.map +1 -0
- package/dist/list-view.d.ts +5 -20
- package/dist/list-view.d.ts.map +1 -1
- package/dist/list-view.js +32 -53
- package/dist/list-view.js.map +1 -1
- package/dist/size-group.d.ts +8 -16
- package/dist/size-group.d.ts.map +1 -1
- package/dist/size-group.js +35 -51
- package/dist/size-group.js.map +1 -1
- package/dist/types.d.ts +98 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -6
- package/src/adw/combo-row.tsx +20 -0
- package/src/adw/index.ts +9 -0
- package/src/adw/toast.tsx +74 -0
- package/src/adw/types.ts +45 -0
- package/src/column-view.tsx +176 -160
- package/src/drop-down.tsx +12 -185
- package/src/grid-view.tsx +29 -73
- package/src/index.ts +18 -26
- package/src/internal/cells.tsx +345 -0
- package/src/internal/collection-index.ts +168 -0
- package/src/internal/collection-model.ts +246 -0
- package/src/internal/collection.ts +104 -0
- package/src/internal/drop-down.tsx +186 -0
- package/src/internal/expansion.ts +122 -0
- package/src/internal/selection.tsx +162 -0
- package/src/internal/use-collection.tsx +57 -0
- package/src/internal/use-widget-ref.ts +11 -0
- package/src/list-view.tsx +43 -139
- package/src/size-group.tsx +63 -82
- package/src/types.ts +158 -28
- package/dist/cell.d.ts +0 -30
- package/dist/cell.d.ts.map +0 -1
- package/dist/cell.js +0 -45
- package/dist/cell.js.map +0 -1
- package/dist/column-view-column.d.ts +0 -27
- package/dist/column-view-column.d.ts.map +0 -1
- package/dist/column-view-column.js +0 -30
- package/dist/column-view-column.js.map +0 -1
- package/dist/constraint-layout-apply.d.ts +0 -55
- package/dist/constraint-layout-apply.d.ts.map +0 -1
- package/dist/constraint-layout-apply.js +0 -107
- package/dist/constraint-layout-apply.js.map +0 -1
- package/dist/constraint-layout.d.ts +0 -20
- package/dist/constraint-layout.d.ts.map +0 -1
- package/dist/constraint-layout.js +0 -88
- package/dist/constraint-layout.js.map +0 -1
- package/dist/fixed.d.ts +0 -26
- package/dist/fixed.d.ts.map +0 -1
- package/dist/fixed.js +0 -40
- package/dist/fixed.js.map +0 -1
- package/dist/grid.d.ts +0 -27
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js +0 -48
- package/dist/grid.js.map +0 -1
- package/dist/hooks/use-cell-containers.d.ts +0 -18
- package/dist/hooks/use-cell-containers.d.ts.map +0 -1
- package/dist/hooks/use-cell-containers.js +0 -67
- package/dist/hooks/use-cell-containers.js.map +0 -1
- package/dist/hooks/use-collection-model.d.ts +0 -26
- package/dist/hooks/use-collection-model.d.ts.map +0 -1
- package/dist/hooks/use-collection-model.js +0 -35
- package/dist/hooks/use-collection-model.js.map +0 -1
- package/dist/hooks/use-collection-widget.d.ts +0 -28
- package/dist/hooks/use-collection-widget.d.ts.map +0 -1
- package/dist/hooks/use-collection-widget.js +0 -21
- package/dist/hooks/use-collection-widget.js.map +0 -1
- package/dist/hooks/use-drop-down-selection.d.ts +0 -16
- package/dist/hooks/use-drop-down-selection.d.ts.map +0 -1
- package/dist/hooks/use-drop-down-selection.js +0 -35
- package/dist/hooks/use-drop-down-selection.js.map +0 -1
- package/dist/hooks/use-expansion-model.d.ts +0 -12
- package/dist/hooks/use-expansion-model.d.ts.map +0 -1
- package/dist/hooks/use-expansion-model.js +0 -71
- package/dist/hooks/use-expansion-model.js.map +0 -1
- package/dist/hooks/use-header-menu.d.ts +0 -4
- package/dist/hooks/use-header-menu.d.ts.map +0 -1
- package/dist/hooks/use-header-menu.js +0 -20
- package/dist/hooks/use-header-menu.js.map +0 -1
- package/dist/hooks/use-installed-model.d.ts +0 -4
- package/dist/hooks/use-installed-model.d.ts.map +0 -1
- package/dist/hooks/use-installed-model.js +0 -15
- package/dist/hooks/use-installed-model.js.map +0 -1
- package/dist/hooks/use-list-model.d.ts +0 -19
- package/dist/hooks/use-list-model.d.ts.map +0 -1
- package/dist/hooks/use-list-model.js +0 -97
- package/dist/hooks/use-list-model.js.map +0 -1
- package/dist/hooks/use-placed-child.d.ts +0 -18
- package/dist/hooks/use-placed-child.d.ts.map +0 -1
- package/dist/hooks/use-placed-child.js +0 -47
- package/dist/hooks/use-placed-child.js.map +0 -1
- package/dist/hooks/use-selection-model.d.ts +0 -13
- package/dist/hooks/use-selection-model.d.ts.map +0 -1
- package/dist/hooks/use-selection-model.js +0 -103
- package/dist/hooks/use-selection-model.js.map +0 -1
- package/dist/hooks/use-sort-handler.d.ts +0 -17
- package/dist/hooks/use-sort-handler.d.ts.map +0 -1
- package/dist/hooks/use-sort-handler.js +0 -87
- package/dist/hooks/use-sort-handler.js.map +0 -1
- package/dist/menu-items.d.ts +0 -5
- package/dist/menu-items.d.ts.map +0 -1
- package/dist/menu-items.js +0 -48
- package/dist/menu-items.js.map +0 -1
- package/dist/menu.d.ts +0 -14
- package/dist/menu.d.ts.map +0 -1
- package/dist/menu.js +0 -24
- package/dist/menu.js.map +0 -1
- package/dist/overlay.d.ts +0 -24
- package/dist/overlay.d.ts.map +0 -1
- package/dist/overlay.js +0 -49
- package/dist/overlay.js.map +0 -1
- package/dist/utils/cell-container-store.d.ts +0 -28
- package/dist/utils/cell-container-store.d.ts.map +0 -1
- package/dist/utils/cell-container-store.js +0 -98
- package/dist/utils/cell-container-store.js.map +0 -1
- package/dist/utils/item-models.d.ts +0 -10
- package/dist/utils/item-models.d.ts.map +0 -1
- package/dist/utils/item-models.js +0 -82
- package/dist/utils/item-models.js.map +0 -1
- package/dist/utils/item-resolver.d.ts +0 -25
- package/dist/utils/item-resolver.d.ts.map +0 -1
- package/dist/utils/item-resolver.js +0 -102
- package/dist/utils/item-resolver.js.map +0 -1
- package/dist/utils/list-item-flatten.d.ts +0 -24
- package/dist/utils/list-item-flatten.d.ts.map +0 -1
- package/dist/utils/list-item-flatten.js +0 -68
- package/dist/utils/list-item-flatten.js.map +0 -1
- package/src/cell.tsx +0 -144
- package/src/column-view-column.tsx +0 -82
- package/src/constraint-layout-apply.ts +0 -173
- package/src/constraint-layout.tsx +0 -135
- package/src/fixed.tsx +0 -86
- package/src/grid.tsx +0 -88
- package/src/hooks/use-cell-containers.ts +0 -93
- package/src/hooks/use-collection-model.ts +0 -60
- package/src/hooks/use-collection-widget.ts +0 -47
- package/src/hooks/use-drop-down-selection.ts +0 -52
- package/src/hooks/use-expansion-model.ts +0 -82
- package/src/hooks/use-header-menu.ts +0 -34
- package/src/hooks/use-installed-model.ts +0 -20
- package/src/hooks/use-list-model.ts +0 -161
- package/src/hooks/use-placed-child.ts +0 -79
- package/src/hooks/use-selection-model.ts +0 -114
- package/src/hooks/use-sort-handler.ts +0 -107
- package/src/menu-items.ts +0 -48
- package/src/menu.tsx +0 -32
- package/src/overlay.tsx +0 -88
- package/src/utils/cell-container-store.ts +0 -114
- package/src/utils/item-models.ts +0 -113
- package/src/utils/item-resolver.ts +0 -138
- package/src/utils/list-item-flatten.ts +0 -90
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ComboRowProps } from "./types.js";
|
|
3
|
+
type ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;
|
|
4
|
+
/**
|
|
5
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
6
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
7
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
8
|
+
*/
|
|
9
|
+
declare const ComboRow: ComboRowComponent;
|
|
10
|
+
export { ComboRow };
|
|
11
|
+
//# sourceMappingURL=combo-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combo-row.d.ts","sourceRoot":"","sources":["../../src/adw/combo-row.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,iBAAiB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;AAE7F;;;;GAIG;AACH,QAAA,MAAM,QAAQ,EAAE,iBAAqD,CAAC;AAMtE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AdwComboRow } from "@gtkx/jsx/adw";
|
|
3
|
+
import { DropDownBase } from "../internal/drop-down.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a
|
|
6
|
+
* `DropDown` in the shape of a preferences row, with customizable renderers for the row
|
|
7
|
+
* display, popup rows, and popup section headers, and controlled selection.
|
|
8
|
+
*/
|
|
9
|
+
const ComboRow = ComboRowImpl;
|
|
10
|
+
function ComboRowImpl(props) {
|
|
11
|
+
return _jsx(DropDownBase, { ...props, component: AdwComboRow });
|
|
12
|
+
}
|
|
13
|
+
export { ComboRow };
|
|
14
|
+
//# sourceMappingURL=combo-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combo-row.js","sourceRoot":"","sources":["../../src/adw/combo-row.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAIxD;;;;GAIG;AACH,MAAM,QAAQ,GAAsB,YAAiC,CAAC;AAEtE,SAAS,YAAY,CAAC,KAAwB;IAC1C,OAAO,KAAC,YAAY,OAAK,KAAK,EAAE,SAAS,EAAE,WAAW,GAAI,CAAC;AAC/D,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { AdwComboRow } from \"@gtkx/jsx/adw\";\nimport type { DropDownBaseProps } from \"../internal/drop-down.js\";\nimport type { ComboRowProps } from \"./types.js\";\nimport { DropDownBase } from \"../internal/drop-down.js\";\n\ntype ComboRowComponent = <T = unknown, S = unknown>(props: ComboRowProps<T, S>) => ReactNode;\n\n/**\n * Renders an `Adw.ComboRow` backed by a collection model, presenting the same choice as a\n * `DropDown` in the shape of a preferences row, with customizable renderers for the row\n * display, popup rows, and popup section headers, and controlled selection.\n */\nconst ComboRow: ComboRowComponent = ComboRowImpl as ComboRowComponent;\n\nfunction ComboRowImpl(props: DropDownBaseProps): ReactNode {\n return <DropDownBase {...props} component={AdwComboRow} />;\n}\n\nexport { ComboRow };\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ComboRow } from "./combo-row.js";
|
|
2
|
+
export { ToastProvider, useToast, useToastOverlay } from "./toast.js";
|
|
3
|
+
export type { ComboRowProps, ToastController, ToastOptions, ToastOverlayController, ToastProviderProps, } from "./types.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtE,YAAY,EACR,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adw/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { ComboRow } from \"./combo-row.js\";\nexport { ToastProvider, useToast, useToastOverlay } from \"./toast.js\";\nexport type {\n ComboRowProps,\n ToastController,\n ToastOptions,\n ToastOverlayController,\n ToastProviderProps,\n} from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ToastController, ToastOverlayController, ToastProviderProps } from "./types.js";
|
|
3
|
+
/** Shares an Adw.ToastOverlay reference with the toast hooks in every descendant. */
|
|
4
|
+
declare function ToastProvider(props: ToastProviderProps): ReactNode;
|
|
5
|
+
/** Returns a {@link ToastController} that shows and dismisses toasts on the nearest provider's overlay. */
|
|
6
|
+
declare function useToast(): ToastController;
|
|
7
|
+
/** Returns a {@link ToastOverlayController} for the nearest provider's overlay as a whole. */
|
|
8
|
+
declare function useToastOverlay(): ToastOverlayController;
|
|
9
|
+
export { ToastProvider, useToast, useToastOverlay };
|
|
10
|
+
//# sourceMappingURL=toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../src/adw/toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAGlD,OAAO,KAAK,EAAE,eAAe,EAAgB,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA+B5G,qFAAqF;AACrF,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAE3D;AAED,2GAA2G;AAC3G,iBAAS,QAAQ,IAAI,eAAe,CAiBnC;AAED,8FAA8F;AAC9F,iBAAS,eAAe,IAAI,sBAAsB,CAWjD;AAED,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as Adw from "@gtkx/gi/adw";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
const ToastContext = createContext(null);
|
|
5
|
+
const useOverlayRef = () => {
|
|
6
|
+
const overlayRef = useContext(ToastContext);
|
|
7
|
+
if (overlayRef === null) {
|
|
8
|
+
throw new Error("useToast and useToastOverlay must be used within a ToastProvider");
|
|
9
|
+
}
|
|
10
|
+
return overlayRef;
|
|
11
|
+
};
|
|
12
|
+
const buildToast = (options) => {
|
|
13
|
+
const { onButtonClicked, onDismissed, ...props } = options;
|
|
14
|
+
const toast = new Adw.Toast(props);
|
|
15
|
+
if (onButtonClicked != null) {
|
|
16
|
+
toast.on("button-clicked", onButtonClicked);
|
|
17
|
+
}
|
|
18
|
+
if (onDismissed != null) {
|
|
19
|
+
toast.on("dismissed", onDismissed);
|
|
20
|
+
}
|
|
21
|
+
return toast;
|
|
22
|
+
};
|
|
23
|
+
/** Shares an Adw.ToastOverlay reference with the toast hooks in every descendant. */
|
|
24
|
+
function ToastProvider(props) {
|
|
25
|
+
return _jsx(ToastContext.Provider, { value: props.overlayRef, children: props.children });
|
|
26
|
+
}
|
|
27
|
+
/** Returns a {@link ToastController} that shows and dismisses toasts on the nearest provider's overlay. */
|
|
28
|
+
function useToast() {
|
|
29
|
+
const overlayRef = useOverlayRef();
|
|
30
|
+
return useMemo(() => ({
|
|
31
|
+
show: (options) => {
|
|
32
|
+
const toast = buildToast(options ?? {});
|
|
33
|
+
overlayRef.current?.addToast(toast);
|
|
34
|
+
return toast;
|
|
35
|
+
},
|
|
36
|
+
dismiss: (toast) => {
|
|
37
|
+
toast.dismiss();
|
|
38
|
+
},
|
|
39
|
+
}), [overlayRef]);
|
|
40
|
+
}
|
|
41
|
+
/** Returns a {@link ToastOverlayController} for the nearest provider's overlay as a whole. */
|
|
42
|
+
function useToastOverlay() {
|
|
43
|
+
const overlayRef = useOverlayRef();
|
|
44
|
+
return useMemo(() => ({
|
|
45
|
+
dismissAll: () => {
|
|
46
|
+
overlayRef.current?.dismissAll();
|
|
47
|
+
},
|
|
48
|
+
}), [overlayRef]);
|
|
49
|
+
}
|
|
50
|
+
export { ToastProvider, useToast, useToastOverlay };
|
|
51
|
+
//# sourceMappingURL=toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.js","sourceRoot":"","sources":["../../src/adw/toast.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAK3D,MAAM,YAAY,GAAG,aAAa,CAAoB,IAAI,CAAC,CAAC;AAE5D,MAAM,aAAa,GAAG,GAAe,EAAE;IACnC,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAE5C,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,OAAqB,EAAa,EAAE;IACpD,MAAM,EAAE,eAAe,EAAE,WA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E,CAAC;QACrC,CAAC;KACJ,CAAC,EACF,CAAC,UAAU,CAAC,CACf,CAAC;AACN,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\nimport * as Adw from \"@gtkx/gi/adw\";\nimport { createContext, useContext, useMemo } from \"react\";\nimport type { ToastController, ToastOptions, ToastOverlayController, ToastProviderProps } from \"./types.js\";\n\ntype OverlayRef = RefObject<Adw.ToastOverlay | null>;\n\nconst ToastContext = createContext<OverlayRef | null>(null);\n\nconst useOverlayRef = (): OverlayRef => {\n const overlayRef = useContext(ToastContext);\n\n if (overlayRef === null) {\n throw new Error(\"useToast and useToastOverlay must be used within a ToastProvider\");\n }\n\n return overlayRef;\n};\n\nconst buildToast = (options: ToastOptions): Adw.Toast => {\n const { onButtonClicked, onDismissed, ...props } = options;\n const toast = new Adw.Toast(props);\n\n if (onButtonClicked != null) {\n toast.on(\"button-clicked\", onButtonClicked);\n }\n\n if (onDismissed != null) {\n toast.on(\"dismissed\", onDismissed);\n }\n\n return toast;\n};\n\n/** Shares an Adw.ToastOverlay reference with the toast hooks in every descendant. */\nfunction ToastProvider(props: ToastProviderProps): ReactNode {\n return <ToastContext.Provider value={props.overlayRef}>{props.children}</ToastContext.Provider>;\n}\n\n/** Returns a {@link ToastController} that shows and dismisses toasts on the nearest provider's overlay. */\nfunction useToast(): ToastController {\n const overlayRef = useOverlayRef();\n\n return useMemo<ToastController>(\n () => ({\n show: (options?: ToastOptions) => {\n const toast = buildToast(options ?? {});\n overlayRef.current?.addToast(toast);\n\n return toast;\n },\n dismiss: (toast: Adw.Toast) => {\n toast.dismiss();\n },\n }),\n [overlayRef],\n );\n}\n\n/** Returns a {@link ToastOverlayController} for the nearest provider's overlay as a whole. */\nfunction useToastOverlay(): ToastOverlayController {\n const overlayRef = useOverlayRef();\n\n return useMemo<ToastOverlayController>(\n () => ({\n dismissAll: () => {\n overlayRef.current?.dismissAll();\n },\n }),\n [overlayRef],\n );\n}\n\nexport { ToastProvider, useToast, useToastOverlay };\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as Adw from "@gtkx/gi/adw";
|
|
2
|
+
import type { AdwComboRowProps, AdwToastProps } from "@gtkx/jsx/adw";
|
|
3
|
+
import type { ReactNode, RefObject } from "react";
|
|
4
|
+
import type { DropDownWidgetProps } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative
|
|
7
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
8
|
+
* for the row display, popup rows, and popup section headers.
|
|
9
|
+
*/
|
|
10
|
+
type ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;
|
|
11
|
+
/**
|
|
12
|
+
* Describes a toast raised through {@link useToast}: the construct-time properties of an
|
|
13
|
+
* `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.
|
|
14
|
+
*/
|
|
15
|
+
type ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, "onButtonClicked" | "onDismissed">;
|
|
16
|
+
/** Imperative controls for individual toasts, returned by {@link useToast}. */
|
|
17
|
+
type ToastController = {
|
|
18
|
+
/** Builds a toast, shows it through the overlay, and returns it. */
|
|
19
|
+
show: (options?: ToastOptions) => Adw.Toast;
|
|
20
|
+
/** Dismisses a single toast, typically one returned by {@link ToastController.show}. */
|
|
21
|
+
dismiss: (toast: Adw.Toast) => void;
|
|
22
|
+
};
|
|
23
|
+
/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */
|
|
24
|
+
type ToastOverlayController = {
|
|
25
|
+
/** Dismisses the shown toast and every queued one. */
|
|
26
|
+
dismissAll: () => void;
|
|
27
|
+
};
|
|
28
|
+
/** Props for {@link ToastProvider}. */
|
|
29
|
+
type ToastProviderProps = {
|
|
30
|
+
/** Ref also given to the `AdwToastOverlay` the toasts appear over. */
|
|
31
|
+
overlayRef: RefObject<Adw.ToastOverlay | null>;
|
|
32
|
+
children?: ReactNode | undefined;
|
|
33
|
+
};
|
|
34
|
+
export { type ComboRowProps, type ToastOptions, type ToastController, type ToastOverlayController, type ToastProviderProps, };
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adw/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;GAIG;AACH,KAAK,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3F;;;GAGG;AACH,KAAK,YAAY,GAAG,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAAC,aAAa,EAAE,iBAAiB,GAAG,aAAa,CAAC,CAAC;AAEvG,+EAA+E;AAC/E,KAAK,eAAe,GAAG;IACnB,oEAAoE;IACpE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,GAAG,CAAC,KAAK,CAAC;IAC5C,wFAAwF;IACxF,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,2FAA2F;AAC3F,KAAK,sBAAsB,GAAG;IAC1B,sDAAsD;IACtD,UAAU,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAEF,uCAAuC;AACvC,KAAK,kBAAkB,GAAG;IACtB,sEAAsE;IACtE,UAAU,EAAE,SAAS,CAAC,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/C,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACpC,CAAC;AAEF,OAAO,EACH,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,GAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/adw/types.ts"],"names":[],"mappings":"AAsCA,OAAO,EAMN,CAAC","sourcesContent":["import type * as Adw from \"@gtkx/gi/adw\";\nimport type { AdwComboRowProps, AdwToastProps } from \"@gtkx/jsx/adw\";\nimport type { ReactNode, RefObject } from \"react\";\nimport type { DropDownWidgetProps } from \"../types.js\";\n\n/**\n * Props for {@link ComboRow}. Combines the underlying Adw.ComboRow props with the declarative\n * collection props: flat items or grouped sections, controlled single selection, and renderers\n * for the row display, popup rows, and popup section headers.\n */\ntype ComboRowProps<T = unknown, S = unknown> = DropDownWidgetProps<AdwComboRowProps, T, S>;\n/**\n * Describes a toast raised through {@link useToast}: the construct-time properties of an\n * `Adw.Toast` plus its `button-clicked` and `dismissed` handlers.\n */\ntype ToastOptions = Adw.ToastConstructorProps & Pick<AdwToastProps, \"onButtonClicked\" | \"onDismissed\">;\n\n/** Imperative controls for individual toasts, returned by {@link useToast}. */\ntype ToastController = {\n /** Builds a toast, shows it through the overlay, and returns it. */\n show: (options?: ToastOptions) => Adw.Toast;\n /** Dismisses a single toast, typically one returned by {@link ToastController.show}. */\n dismiss: (toast: Adw.Toast) => void;\n};\n\n/** Imperative controls for the overlay as a whole, returned by {@link useToastOverlay}. */\ntype ToastOverlayController = {\n /** Dismisses the shown toast and every queued one. */\n dismissAll: () => void;\n};\n\n/** Props for {@link ToastProvider}. */\ntype ToastProviderProps = {\n /** Ref also given to the `AdwToastOverlay` the toasts appear over. */\n overlayRef: RefObject<Adw.ToastOverlay | null>;\n children?: ReactNode | undefined;\n};\n\nexport {\n type ComboRowProps,\n type ToastOptions,\n type ToastController,\n type ToastOverlayController,\n type ToastProviderProps,\n};\n"]}
|
package/dist/column-view.d.ts
CHANGED
|
@@ -1,32 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import { type ReactNode } from "react";
|
|
4
|
-
import { type ColumnDef } from "./column-view-column.js";
|
|
5
|
-
import type { CollectionItemSizeProps, ControlledExpansionProps, ControlledSelectionProps, ItemNode, SectionNode } from "./types.js";
|
|
6
|
-
export type { ColumnDef, ColumnDefDeclarativeProps } from "./column-view-column.js";
|
|
7
|
-
export type ColumnViewSortProps = {
|
|
8
|
-
sortColumn?: string | null | undefined;
|
|
9
|
-
sortOrder?: Gtk.SortType | null | undefined;
|
|
10
|
-
onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
|
|
11
|
-
};
|
|
12
|
-
export type ColumnViewDeclarativeProps<T = unknown, S = unknown> = ColumnViewSortProps & Omit<CollectionItemSizeProps, "estimatedItemWidth"> & ControlledSelectionProps & ControlledExpansionProps & {
|
|
13
|
-
items?: ItemNode<T>[] | undefined;
|
|
14
|
-
sections?: SectionNode<S, T>[] | undefined;
|
|
15
|
-
renderHeader?: ((info: {
|
|
16
|
-
section: S;
|
|
17
|
-
}) => ReactNode) | null | undefined;
|
|
18
|
-
columns: ColumnDef<T>[];
|
|
19
|
-
};
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ColumnViewProps } from "./types.js";
|
|
20
3
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* header renderer, and the columns to render.
|
|
4
|
+
* Renders a Gtk.ColumnView from declarative items or sections and a columns array,
|
|
5
|
+
* with controlled selection, expansion, and sorting, per-column header menus, and
|
|
6
|
+
* section header rendering.
|
|
25
7
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Renders a Gtk.ColumnView: a multi-column, scrollable list backed by a collection
|
|
29
|
-
* model. Columns are declared through the columns prop, each a {@link ColumnDef}.
|
|
30
|
-
*/
|
|
31
|
-
export declare const ColumnView: <T = unknown, S = unknown>(props: ColumnViewProps<T, S>) => ReactNode;
|
|
8
|
+
declare function ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode;
|
|
9
|
+
export { ColumnView };
|
|
32
10
|
//# sourceMappingURL=column-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-view.d.ts","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"column-view.d.ts","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,OAAO,KAAK,EAAU,eAAe,EAAE,MAAM,YAAY,CAAC;AAiK1D;;;;GAIG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CA6BrF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/column-view.js
CHANGED
|
@@ -1,78 +1,106 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
+
import { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from "@gtkx/jsx/gtk";
|
|
4
|
+
import { useSignal } from "@gtkx/react";
|
|
5
|
+
import { omit } from "@gtkx/utils";
|
|
6
|
+
import { useLayoutEffect, useRef } from "react";
|
|
7
|
+
import { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from "./internal/cells.js";
|
|
8
|
+
import { useCollection } from "./internal/use-collection.js";
|
|
9
|
+
import { useWidgetRef } from "./internal/use-widget-ref.js";
|
|
10
|
+
const COLUMN_VIEW_PROPS = [
|
|
11
|
+
"items",
|
|
12
|
+
"sections",
|
|
13
|
+
"renderHeader",
|
|
14
|
+
"columns",
|
|
15
|
+
"selectedIds",
|
|
16
|
+
"onSelectionChanged",
|
|
17
|
+
"selectionMode",
|
|
18
|
+
"expandedIds",
|
|
19
|
+
"onExpandedChange",
|
|
20
|
+
"sortColumn",
|
|
21
|
+
"sortOrder",
|
|
22
|
+
"onSortChanged",
|
|
23
|
+
"estimatedItemHeight",
|
|
24
|
+
"children",
|
|
25
|
+
"ref",
|
|
26
|
+
];
|
|
27
|
+
const columnById = (view, id) => {
|
|
28
|
+
const columns = view.getColumns();
|
|
29
|
+
for (let index = 0; index < columns.getNItems(); index++) {
|
|
30
|
+
const column = columns.getItem(index);
|
|
31
|
+
if (column instanceof Gtk.ColumnViewColumn && column.getId() === id) {
|
|
32
|
+
return column;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
29
36
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const getSortTarget = (view, sortColumn) => {
|
|
38
|
+
if (view === null || sortColumn === undefined) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (sortColumn === null) {
|
|
42
|
+
return { view, column: null };
|
|
36
43
|
}
|
|
37
|
-
|
|
44
|
+
const column = columnById(view, sortColumn);
|
|
45
|
+
return column === null ? null : { view, column };
|
|
38
46
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const applySort = (sorting, view, column, order) => {
|
|
48
|
+
sorting.current = true;
|
|
49
|
+
try {
|
|
50
|
+
view.sortByColumn(column, order ?? Gtk.SortType.ASCENDING);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
sorting.current = false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const emitSortChanged = (sorter, sorting, sort) => {
|
|
57
|
+
if (sorter === null || sorting.current) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
sort.onSortChanged?.(sorter.getPrimarySortColumn()?.getId() ?? null, sorter.getPrimarySortOrder());
|
|
61
|
+
};
|
|
62
|
+
const syncSort = (sorting, view, sortColumn, sortOrder) => {
|
|
63
|
+
const target = getSortTarget(view, sortColumn);
|
|
64
|
+
if (target === null) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
applySort(sorting, target.view, target.column, sortOrder);
|
|
68
|
+
};
|
|
69
|
+
const useColumnSorting = (view, sort, columns) => {
|
|
70
|
+
const sorting = useRef(false);
|
|
71
|
+
const sorter = view?.getSorter() ?? null;
|
|
72
|
+
const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;
|
|
73
|
+
useSignal(columnSorter, "changed", () => {
|
|
74
|
+
emitSortChanged(columnSorter, sorting, sort);
|
|
55
75
|
});
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
setInstance,
|
|
66
|
-
};
|
|
76
|
+
const { sortColumn, sortOrder } = sort;
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
syncSort(sorting, view, sortColumn, sortOrder);
|
|
79
|
+
}, [view, sortColumn, sortOrder, columns]);
|
|
80
|
+
};
|
|
81
|
+
const ColumnCells = ({ column, collection, expandedIds, size }) => {
|
|
82
|
+
const cells = useItemCells(size);
|
|
83
|
+
const rest = omit(column, ["id", "renderCell", "sortable"]);
|
|
84
|
+
return (_jsxs(_Fragment, { children: [_jsx(GtkColumnViewColumn, { id: column.id, factory: _jsx(GtkSignalListItemFactory, { ...cells.handlers }), sorter: column.sortable === true ? _jsx(GtkCustomSorter, {}) : null, ...rest }), _jsx(ItemPortals, { store: cells, render: column.renderCell, collection: collection, expandedIds: expandedIds })] }));
|
|
67
85
|
};
|
|
86
|
+
const ColumnList = ({ columns, collection, expandedIds, size }) => columns.map((column) => (_jsx(ColumnCells, { column: column, collection: collection, expandedIds: expandedIds, size: size }, column.id)));
|
|
68
87
|
/**
|
|
69
|
-
* Renders a Gtk.ColumnView
|
|
70
|
-
*
|
|
88
|
+
* Renders a Gtk.ColumnView from declarative items or sections and a columns array,
|
|
89
|
+
* with controlled selection, expansion, and sorting, per-column header menus, and
|
|
90
|
+
* section header rendering.
|
|
71
91
|
*/
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
};
|
|
92
|
+
function ColumnView(props) {
|
|
93
|
+
const { renderHeader, columns, expandedIds, sortColumn, sortOrder, onSortChanged, estimatedItemHeight, ref } = props;
|
|
94
|
+
const rest = omit(props, COLUMN_VIEW_PROPS);
|
|
95
|
+
const [view, refCallback] = useWidgetRef(ref);
|
|
96
|
+
const size = { width: -1, height: estimatedItemHeight ?? -1 };
|
|
97
|
+
const { collection, selection } = useCollection(props);
|
|
98
|
+
const headerCells = useHeaderCells(size);
|
|
99
|
+
const columnList = columns;
|
|
100
|
+
useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);
|
|
101
|
+
return (_jsxs(_Fragment, { children: [_jsx(GtkColumnView, { ref: refCallback, model: selection, ...(renderHeader != null && {
|
|
102
|
+
headerFactory: _jsx(GtkSignalListItemFactory, { ...headerCells.handlers }),
|
|
103
|
+
}), ...rest, children: _jsx(ColumnList, { columns: columnList, collection: collection, expandedIds: expandedIds, size: size }) }), renderHeader != null && (_jsx(HeaderPortals, { store: headerCells, render: renderHeader, collection: collection }))] }));
|
|
104
|
+
}
|
|
105
|
+
export { ColumnView };
|
|
78
106
|
//# sourceMappingURL=column-view.js.map
|
package/dist/column-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-view.js","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAA2B,MAAM,eAAe,CAAC;AACvE,OAAO,EAA4B,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAA0B,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAkB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAA2B,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAatF,MAAM,sBAAsB,GAAG,oBAAoB,CAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CACpF,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CACnC,CAAC;AA6CF,MAAM,kBAAkB,GAAG,GAGzB,EAAE;IACA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAoC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAC/F,MAAM,WAAW,GAAG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E;IAC5F,MAAM,UAAU,GAAG,KAAwC,CAAC;IAC5D,MAAM,MAAM,GAAG,mBAAmB,CAAO,UAAU,CAAC,CAAC;IACrD,MAAM,EACF,GAAG,EACH,KAAK,EACL,QAAQ,EACR,OAAO,EACP,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,GAAG,cAAc,EACpB,GAAG,UAAU,CAAC;IAEf,OAAO,CACH,8BACI,KAAC,aAAa,OAAK,cAAc,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,YAChD,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACrB,KAAC,gBAAgB,OAET,MAAM,EACV,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,MAAM,CAAC,WAAW,IALzB,MAAM,CAAC,EAAE,CAMhB,CACL,CAAC,GACU,EAChB,KAAC,gBAAgB,IACb,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,KAAK,EAAE,MAAM,CAAC,WAAW,EACzB,QAAQ,EAAE,MAAM,CAAC,cAAc,EAC/B,YAAY,EAAE,YAAY,GAC5B,IACH,CACN,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnView, type GtkColumnViewProps } from \"@gtkx/jsx/gtk\";\nimport { type ReactNode, type Ref, useCallback, useMemo, useState } from \"react\";\nimport { createTreeRenderContext, HeaderRenderHost, type TreeRenderContext } from \"./cell.js\";\nimport { type ColumnDef, ColumnViewColumn } from \"./column-view-column.js\";\nimport { makeFactoryInstaller, useCellContainers } from \"./hooks/use-cell-containers.js\";\nimport { useCollectionWidget } from \"./hooks/use-collection-widget.js\";\nimport { type ColumnRegistration, useSortHandler } from \"./hooks/use-sort-handler.js\";\nimport type {\n CollectionItemSizeProps,\n ControlledExpansionProps,\n ControlledSelectionProps,\n ItemNode,\n SectionNode,\n} from \"./types.js\";\nimport type { CellContainerStore } from \"./utils/cell-container-store.js\";\nimport type { ItemResolver } from \"./utils/item-resolver.js\";\n\nexport type { ColumnDef, ColumnDefDeclarativeProps } from \"./column-view-column.js\";\n\nconst headerFactoryInstaller = makeFactoryInstaller<Gtk.ColumnView>((widget, factory) =>\n widget.setHeaderFactory(factory),\n);\n\nexport type ColumnViewSortProps = {\n sortColumn?: string | null | undefined;\n sortOrder?: Gtk.SortType | null | undefined;\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\nexport type ColumnViewDeclarativeProps<T = unknown, S = unknown> = ColumnViewSortProps &\n Omit<CollectionItemSizeProps, \"estimatedItemWidth\"> &\n ControlledSelectionProps &\n ControlledExpansionProps & {\n items?: ItemNode<T>[] | undefined;\n sections?: SectionNode<S, T>[] | undefined;\n renderHeader?: ((info: { section: S }) => ReactNode) | null | undefined;\n columns: ColumnDef<T>[];\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 */\nexport type ColumnViewProps<T = unknown, S = unknown> = Omit<\n GtkColumnViewProps,\n \"columns\" | \"model\" | \"headerFactory\" | keyof ColumnViewDeclarativeProps<T, S>\n> &\n ColumnViewDeclarativeProps<T, S>;\n\ntype NormalizedColumnViewProps<T, S> = ColumnViewDeclarativeProps<T, S> & {\n ref?: Ref<Gtk.ColumnView | null>;\n [key: string]: unknown;\n};\n\ninterface ColumnViewWiring<T, S> {\n setRef: (value: Gtk.ColumnView | null) => void;\n useHeader: boolean;\n headerStore: CellContainerStore;\n headerResolver: ItemResolver<T, S>;\n resolver: ItemResolver<unknown, unknown>;\n tree: TreeRenderContext;\n setInstance: (id: string, column: Gtk.ColumnViewColumn | null) => void;\n}\n\nconst useColumnInstances = (): {\n instances: Map<string, Gtk.ColumnViewColumn>;\n setInstance: (id: string, column: Gtk.ColumnViewColumn | null) => void;\n} => {\n const [instances, setInstances] = useState<Map<string, Gtk.ColumnViewColumn>>(() => new Map());\n const setInstance = useCallback((id: string, column: Gtk.ColumnViewColumn | null): void => {\n setInstances((current) => {\n if (column === null) {\n if (!current.has(id)) return current;\n const next = new Map(current);\n next.delete(id);\n return next;\n }\n if (current.get(id) === column) return current;\n const next = new Map(current);\n next.set(id, column);\n return next;\n });\n }, []);\n return { instances, setInstance };\n};\n\nconst buildRegistrations = <T,>(\n columns: ColumnDef<T>[],\n instances: Map<string, Gtk.ColumnViewColumn>,\n): ColumnRegistration[] => {\n const result: ColumnRegistration[] = [];\n for (const column of columns) {\n const instance = instances.get(column.id);\n if (instance) result.push({ id: column.id, column: instance, sortable: column.sortable ?? false });\n }\n return result;\n};\n\nconst useColumnViewWiring = <T, S>(props: NormalizedColumnViewProps<T, S>): ColumnViewWiring<T, S> => {\n const { widgetRef, setRef, collection } = useCollectionWidget<Gtk.ColumnView, T, S>(props);\n\n const useHeader = collection.useHeader;\n const headerStore = useCellContainers<Gtk.ColumnView>({\n object: useHeader ? widgetRef : null,\n installer: headerFactoryInstaller,\n estimatedHeight: props.estimatedItemHeight,\n });\n\n const { instances, setInstance } = useColumnInstances();\n const registrations = useMemo<ColumnRegistration[]>(\n () => buildRegistrations(props.columns, instances),\n [props.columns, instances],\n );\n\n useSortHandler({\n columnView: widgetRef,\n sortColumn: props.sortColumn,\n sortOrder: props.sortOrder,\n onSortChanged: props.onSortChanged,\n columns: registrations,\n });\n\n const expandedIds = props.expandedIds;\n const tree = useMemo<TreeRenderContext>(\n () => createTreeRenderContext(expandedIds, collection.rowId),\n [expandedIds, collection.rowId],\n );\n\n return {\n setRef,\n useHeader,\n headerStore,\n headerResolver: collection.headerResolver,\n resolver: collection.resolver as ItemResolver<unknown, unknown>,\n tree,\n setInstance,\n };\n};\n\n/**\n * Renders a Gtk.ColumnView: a multi-column, scrollable list backed by a collection\n * model. Columns are declared through the columns prop, each a {@link ColumnDef}.\n */\nexport const ColumnView = <T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode => {\n const normalized = props as NormalizedColumnViewProps<T, S>;\n const wiring = useColumnViewWiring<T, S>(normalized);\n const {\n ref,\n items,\n sections,\n columns,\n selectedIds,\n selectionMode,\n onSelectionChanged,\n expandedIds,\n onExpandedChange,\n sortColumn,\n sortOrder,\n onSortChanged,\n renderHeader,\n estimatedItemHeight,\n ...intrinsicProps\n } = normalized;\n\n return (\n <>\n <GtkColumnView {...intrinsicProps} ref={wiring.setRef}>\n {columns.map((column) => (\n <ColumnViewColumn\n key={column.id}\n {...column}\n resolver={wiring.resolver}\n tree={wiring.tree}\n estimatedItemHeight={estimatedItemHeight}\n onInstance={wiring.setInstance}\n />\n ))}\n </GtkColumnView>\n <HeaderRenderHost\n useHeader={wiring.useHeader}\n store={wiring.headerStore}\n resolver={wiring.headerResolver}\n renderHeader={renderHeader}\n />\n </>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"column-view.js","sourceRoot":"","sources":["../src/column-view.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CA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I,GACrF,EACf,YAAY,IAAI,IAAI,IAAI,CACrB,KAAC,aAAa,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,GAAI,CACtF,IACF,CACN,CAAC;AACN,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnView, GtkColumnViewColumn, GtkCustomSorter, GtkSignalListItemFactory } from \"@gtkx/jsx/gtk\";\nimport { useSignal } from \"@gtkx/react\";\nimport { omit } from \"@gtkx/utils\";\nimport { useLayoutEffect, useRef } from \"react\";\nimport type { CellSize } from \"./internal/cells.js\";\nimport type { Collection } from \"./internal/collection.js\";\nimport type { Column, ColumnViewProps } from \"./types.js\";\nimport { HeaderPortals, ItemPortals, useHeaderCells, useItemCells } from \"./internal/cells.js\";\nimport { useCollection } from \"./internal/use-collection.js\";\nimport { useWidgetRef } from \"./internal/use-widget-ref.js\";\n\ntype SortProps = {\n sortColumn?: string | null | undefined;\n sortOrder?: Gtk.SortType | null | undefined;\n onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;\n};\n\ntype SortTarget = { view: Gtk.ColumnView; column: Gtk.ColumnViewColumn | null };\n\ntype ColumnCellsProps = {\n column: Column<never>;\n collection: Collection;\n expandedIds: string[] | null | undefined;\n size: CellSize;\n};\n\ntype ColumnListProps = Omit<ColumnCellsProps, \"column\"> & {\n columns: Column<never>[];\n};\n\nconst COLUMN_VIEW_PROPS = [\n \"items\",\n \"sections\",\n \"renderHeader\",\n \"columns\",\n \"selectedIds\",\n \"onSelectionChanged\",\n \"selectionMode\",\n \"expandedIds\",\n \"onExpandedChange\",\n \"sortColumn\",\n \"sortOrder\",\n \"onSortChanged\",\n \"estimatedItemHeight\",\n \"children\",\n \"ref\",\n] as const satisfies (keyof ColumnViewProps)[];\n\nconst columnById = (view: Gtk.ColumnView, id: string): Gtk.ColumnViewColumn | null => {\n const columns = view.getColumns();\n\n for (let index = 0; index < columns.getNItems(); index++) {\n const column = columns.getItem(index);\n\n if (column instanceof Gtk.ColumnViewColumn && column.getId() === id) {\n return column;\n }\n }\n\n return null;\n};\n\nconst getSortTarget = (view: Gtk.ColumnView | null, sortColumn: string | null | undefined): SortTarget | null => {\n if (view === null || sortColumn === undefined) {\n return null;\n }\n\n if (sortColumn === null) {\n return { view, column: null };\n }\n\n const column = columnById(view, sortColumn);\n\n return column === null ? null : { view, column };\n};\n\nconst applySort = (\n sorting: { current: boolean },\n view: Gtk.ColumnView,\n column: Gtk.ColumnViewColumn | null,\n order: Gtk.SortType | null | undefined,\n): void => {\n sorting.current = true;\n\n try {\n view.sortByColumn(column, order ?? Gtk.SortType.ASCENDING);\n } finally {\n sorting.current = false;\n }\n};\n\nconst emitSortChanged = (\n sorter: Gtk.ColumnViewSorter | null,\n sorting: { current: boolean },\n sort: SortProps,\n): void => {\n if (sorter === null || sorting.current) {\n return;\n }\n\n sort.onSortChanged?.(sorter.getPrimarySortColumn()?.getId() ?? null, sorter.getPrimarySortOrder());\n};\n\nconst syncSort = (\n sorting: { current: boolean },\n view: Gtk.ColumnView | null,\n sortColumn: string | null | undefined,\n sortOrder: Gtk.SortType | null | undefined,\n): void => {\n const target = getSortTarget(view, sortColumn);\n\n if (target === null) {\n return;\n }\n\n applySort(sorting, target.view, target.column, sortOrder);\n};\n\nconst useColumnSorting = (view: Gtk.ColumnView | null, sort: SortProps, columns: Column<never>[]): void => {\n const sorting = useRef(false);\n const sorter = view?.getSorter() ?? null;\n const columnSorter = sorter instanceof Gtk.ColumnViewSorter ? sorter : null;\n\n useSignal(columnSorter, \"changed\", (): void => {\n emitSortChanged(columnSorter, sorting, sort);\n });\n\n const { sortColumn, sortOrder } = sort;\n\n useLayoutEffect(() => {\n syncSort(sorting, view, sortColumn, sortOrder);\n }, [view, sortColumn, sortOrder, columns]);\n};\n\nconst ColumnCells = ({ column, collection, expandedIds, size }: ColumnCellsProps): ReactNode => {\n const cells = useItemCells(size);\n const rest = omit(column, [\"id\", \"renderCell\", \"sortable\"]);\n\n return (\n <>\n <GtkColumnViewColumn\n id={column.id}\n factory={<GtkSignalListItemFactory {...cells.handlers} />}\n sorter={column.sortable === true ? <GtkCustomSorter /> : null}\n {...rest}\n />\n <ItemPortals\n store={cells}\n render={column.renderCell}\n collection={collection}\n expandedIds={expandedIds}\n />\n </>\n );\n};\n\nconst ColumnList = ({ columns, collection, expandedIds, size }: ColumnListProps): ReactNode =>\n columns.map((column) => (\n <ColumnCells\n key={column.id}\n column={column}\n collection={collection}\n expandedIds={expandedIds}\n size={size}\n />\n ));\n\n/**\n * Renders a Gtk.ColumnView from declarative items or sections and a columns array,\n * with controlled selection, expansion, and sorting, per-column header menus, and\n * section header rendering.\n */\nfunction ColumnView<T = unknown, S = unknown>(props: ColumnViewProps<T, S>): ReactNode {\n const { renderHeader, columns, expandedIds, sortColumn, sortOrder, onSortChanged, estimatedItemHeight, ref } =\n props;\n\n const rest = omit(props, COLUMN_VIEW_PROPS);\n const [view, refCallback] = useWidgetRef<Gtk.ColumnView>(ref);\n const size = { width: -1, height: estimatedItemHeight ?? -1 };\n const { collection, selection } = useCollection(props);\n const headerCells = useHeaderCells(size);\n const columnList = columns as Column<never>[];\n useColumnSorting(view, { sortColumn, sortOrder, onSortChanged }, columnList);\n\n return (\n <>\n <GtkColumnView\n ref={refCallback}\n model={selection}\n {...(renderHeader != null && {\n headerFactory: <GtkSignalListItemFactory {...headerCells.handlers} />,\n })}\n {...rest}\n >\n <ColumnList columns={columnList} collection={collection} expandedIds={expandedIds} size={size} />\n </GtkColumnView>\n {renderHeader != null && (\n <HeaderPortals store={headerCells} render={renderHeader} collection={collection} />\n )}\n </>\n );\n}\n\nexport { ColumnView };\n"]}
|
package/dist/drop-down.d.ts
CHANGED
|
@@ -1,31 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export type DropDownItemRenderer<T> = (props: RenderItemProps<T>) => ReactNode;
|
|
5
|
-
/** Declarative props for {@link DropDown}'s backing collection and cell rendering. */
|
|
6
|
-
export type DropDownDeclarativeProps<T = unknown, S = unknown> = {
|
|
7
|
-
items?: ItemNode<T>[] | undefined;
|
|
8
|
-
sections?: SectionNode<S, T>[] | undefined;
|
|
9
|
-
/** Id of the currently selected item, making the selection controlled. */
|
|
10
|
-
selectedId?: string | null | undefined;
|
|
11
|
-
onSelectionChanged?: ((id: string) => void) | null | undefined;
|
|
12
|
-
renderItem?: DropDownItemRenderer<T> | null | undefined;
|
|
13
|
-
/** Renderer for items in the open popup list, falling back to renderItem when omitted. */
|
|
14
|
-
renderListItem?: DropDownItemRenderer<T> | null | undefined;
|
|
15
|
-
/** Renderer for section headers in the popup list. */
|
|
16
|
-
renderHeader?: ((info: {
|
|
17
|
-
section: S;
|
|
18
|
-
}) => ReactNode) | null | undefined;
|
|
19
|
-
};
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { DropDownProps } from "./types.js";
|
|
3
|
+
type DropDownComponent = <T = unknown, S = unknown>(props: DropDownProps<T, S>) => ReactNode;
|
|
20
4
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
5
|
+
* Renders a `Gtk.DropDown` backed by a collection model, with customizable renderers for the
|
|
6
|
+
* collapsed display, popup rows, and popup section headers, and controlled selection.
|
|
23
7
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Renders a drop-down widget (Gtk.DropDown by default, or the widget given as `component`) backed by a
|
|
27
|
-
* collection model, with customizable rendering for the selected item, the popup list rows, and section
|
|
28
|
-
* headers.
|
|
29
|
-
*/
|
|
30
|
-
export declare const DropDown: <T = unknown, S = unknown, C extends ElementType = typeof GtkDropDown>(props: DropDownProps<T, S, C>) => ReactNode;
|
|
8
|
+
declare const DropDown: DropDownComponent;
|
|
9
|
+
export { DropDown };
|
|
31
10
|
//# sourceMappingURL=drop-down.d.ts.map
|
package/dist/drop-down.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"drop-down.d.ts","sourceRoot":"","sources":["../src/drop-down.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,iBAAiB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;AAE7F;;;GAGG;AACH,QAAA,MAAM,QAAQ,EAAE,iBAAqD,CAAC;AAMtE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|