@gtkx/components 0.21.0 → 1.0.0-rc.1
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/LICENSE +373 -0
- package/README.md +173 -0
- package/dist/cell.d.ts +30 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +45 -0
- package/dist/cell.js.map +1 -0
- package/dist/column-view-column.d.ts +24 -14
- package/dist/column-view-column.d.ts.map +1 -1
- package/dist/column-view-column.js +19 -40
- package/dist/column-view-column.js.map +1 -1
- package/dist/column-view.d.ts +25 -11
- package/dist/column-view.d.ts.map +1 -1
- package/dist/column-view.js +53 -83
- package/dist/column-view.js.map +1 -1
- package/dist/constraint-layout-apply.d.ts +50 -1
- package/dist/constraint-layout-apply.d.ts.map +1 -1
- package/dist/constraint-layout-apply.js.map +1 -1
- package/dist/constraint-layout.d.ts +8 -1
- package/dist/constraint-layout.d.ts.map +1 -1
- package/dist/constraint-layout.js +12 -9
- package/dist/constraint-layout.js.map +1 -1
- package/dist/drop-down.d.ts +26 -36
- package/dist/drop-down.d.ts.map +1 -1
- package/dist/drop-down.js +47 -87
- package/dist/drop-down.js.map +1 -1
- package/dist/fixed.d.ts +26 -0
- package/dist/fixed.d.ts.map +1 -0
- package/dist/fixed.js +40 -0
- package/dist/fixed.js.map +1 -0
- package/dist/grid-view.d.ts +13 -10
- package/dist/grid-view.d.ts.map +1 -1
- package/dist/grid-view.js +30 -16
- package/dist/grid-view.js.map +1 -1
- package/dist/grid.d.ts +27 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +48 -0
- package/dist/grid.js.map +1 -0
- package/dist/hooks/use-cell-containers.d.ts +18 -0
- package/dist/hooks/use-cell-containers.d.ts.map +1 -0
- package/dist/hooks/{use-realized-slots.js → use-cell-containers.js} +18 -17
- package/dist/hooks/use-cell-containers.js.map +1 -0
- package/dist/hooks/use-collection-model.d.ts +26 -0
- package/dist/hooks/use-collection-model.d.ts.map +1 -0
- package/dist/hooks/use-collection-model.js +35 -0
- package/dist/hooks/use-collection-model.js.map +1 -0
- package/dist/hooks/use-collection-widget.d.ts +28 -0
- package/dist/hooks/use-collection-widget.d.ts.map +1 -0
- package/dist/hooks/use-collection-widget.js +21 -0
- package/dist/hooks/use-collection-widget.js.map +1 -0
- package/dist/hooks/use-drop-down-selection.d.ts +7 -6
- package/dist/hooks/use-drop-down-selection.d.ts.map +1 -1
- package/dist/hooks/use-drop-down-selection.js +6 -6
- package/dist/hooks/use-drop-down-selection.js.map +1 -1
- package/dist/hooks/use-expansion-model.d.ts +12 -0
- package/dist/hooks/use-expansion-model.d.ts.map +1 -0
- package/dist/hooks/use-expansion-model.js +71 -0
- package/dist/hooks/use-expansion-model.js.map +1 -0
- package/dist/hooks/use-header-menu.d.ts.map +1 -1
- package/dist/hooks/use-header-menu.js +12 -24
- package/dist/hooks/use-header-menu.js.map +1 -1
- package/dist/hooks/use-installed-model.d.ts +4 -0
- package/dist/hooks/use-installed-model.d.ts.map +1 -0
- package/dist/hooks/use-installed-model.js +15 -0
- package/dist/hooks/use-installed-model.js.map +1 -0
- package/dist/hooks/use-list-model.d.ts +14 -15
- package/dist/hooks/use-list-model.d.ts.map +1 -1
- package/dist/hooks/use-list-model.js +61 -34
- package/dist/hooks/use-list-model.js.map +1 -1
- package/dist/hooks/use-placed-child.d.ts +18 -0
- package/dist/hooks/use-placed-child.d.ts.map +1 -0
- package/dist/hooks/use-placed-child.js +47 -0
- package/dist/hooks/use-placed-child.js.map +1 -0
- package/dist/hooks/use-selection-model.d.ts +4 -3
- package/dist/hooks/use-selection-model.d.ts.map +1 -1
- package/dist/hooks/use-selection-model.js +8 -16
- package/dist/hooks/use-selection-model.js.map +1 -1
- package/dist/hooks/use-sort-handler.d.ts +10 -5
- package/dist/hooks/use-sort-handler.d.ts.map +1 -1
- package/dist/hooks/use-sort-handler.js +2 -2
- package/dist/hooks/use-sort-handler.js.map +1 -1
- package/dist/index.d.ts +11 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -13
- package/dist/index.js.map +1 -1
- package/dist/list-view.d.ts +17 -9
- package/dist/list-view.d.ts.map +1 -1
- package/dist/list-view.js +49 -24
- package/dist/list-view.js.map +1 -1
- package/dist/menu-items.d.ts.map +1 -1
- package/dist/menu-items.js.map +1 -1
- package/dist/menu.d.ts +6 -10
- package/dist/menu.d.ts.map +1 -1
- package/dist/menu.js +7 -9
- package/dist/menu.js.map +1 -1
- package/dist/overlay.d.ts +24 -0
- package/dist/overlay.d.ts.map +1 -0
- package/dist/overlay.js +49 -0
- package/dist/overlay.js.map +1 -0
- package/dist/size-group.d.ts +20 -0
- package/dist/size-group.d.ts.map +1 -0
- package/dist/size-group.js +57 -0
- package/dist/size-group.js.map +1 -0
- package/dist/types.d.ts +43 -173
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/{realized-slot-store.d.ts → cell-container-store.d.ts} +7 -9
- package/dist/utils/cell-container-store.d.ts.map +1 -0
- package/dist/utils/{realized-slot-store.js → cell-container-store.js} +9 -14
- package/dist/utils/cell-container-store.js.map +1 -0
- package/dist/utils/item-models.d.ts +10 -0
- package/dist/utils/item-models.d.ts.map +1 -0
- package/dist/utils/{position-only-model.js → item-models.js} +13 -14
- package/dist/utils/item-models.js.map +1 -0
- package/dist/utils/item-resolver.d.ts +14 -17
- package/dist/utils/item-resolver.d.ts.map +1 -1
- package/dist/utils/item-resolver.js +34 -43
- package/dist/utils/item-resolver.js.map +1 -1
- package/dist/utils/list-item-flatten.d.ts +16 -24
- package/dist/utils/list-item-flatten.d.ts.map +1 -1
- package/dist/utils/list-item-flatten.js +16 -36
- package/dist/utils/list-item-flatten.js.map +1 -1
- package/package.json +52 -53
- package/src/cell.tsx +144 -0
- package/src/column-view-column.tsx +57 -48
- package/src/column-view.tsx +130 -146
- package/src/constraint-layout-apply.ts +53 -1
- package/src/constraint-layout.tsx +18 -13
- package/src/drop-down.tsx +129 -196
- package/src/fixed.tsx +86 -0
- package/src/grid-view.tsx +52 -44
- package/src/grid.tsx +88 -0
- package/src/hooks/{use-realized-slots.ts → use-cell-containers.ts} +30 -30
- package/src/hooks/use-collection-model.ts +60 -0
- package/src/hooks/use-collection-widget.ts +47 -0
- package/src/hooks/use-drop-down-selection.ts +12 -13
- package/src/hooks/use-expansion-model.ts +82 -0
- package/src/hooks/use-header-menu.ts +24 -23
- package/src/hooks/use-installed-model.ts +20 -0
- package/src/hooks/use-list-model.ts +103 -87
- package/src/hooks/use-placed-child.ts +79 -0
- package/src/hooks/use-selection-model.ts +11 -18
- package/src/hooks/use-sort-handler.ts +13 -8
- package/src/index.ts +25 -27
- package/src/list-view.tsx +120 -57
- package/src/menu.tsx +12 -14
- package/src/overlay.tsx +88 -0
- package/src/size-group.tsx +96 -0
- package/src/types.ts +55 -206
- package/src/utils/{realized-slot-store.ts → cell-container-store.ts} +13 -25
- package/src/utils/{position-only-model.ts → item-models.ts} +26 -28
- package/src/utils/item-resolver.ts +54 -59
- package/src/utils/list-item-flatten.ts +33 -56
- package/dist/collection-view.d.ts +0 -30
- package/dist/collection-view.d.ts.map +0 -1
- package/dist/collection-view.js +0 -52
- package/dist/collection-view.js.map +0 -1
- package/dist/contexts/column-view-context.d.ts +0 -17
- package/dist/contexts/column-view-context.d.ts.map +0 -1
- package/dist/contexts/column-view-context.js +0 -10
- package/dist/contexts/column-view-context.js.map +0 -1
- package/dist/hooks/use-model-installation.d.ts +0 -9
- package/dist/hooks/use-model-installation.d.ts.map +0 -1
- package/dist/hooks/use-model-installation.js +0 -20
- package/dist/hooks/use-model-installation.js.map +0 -1
- package/dist/hooks/use-realized-slots.d.ts +0 -20
- package/dist/hooks/use-realized-slots.d.ts.map +0 -1
- package/dist/hooks/use-realized-slots.js.map +0 -1
- package/dist/list-portal-host.d.ts +0 -11
- package/dist/list-portal-host.d.ts.map +0 -1
- package/dist/list-portal-host.js +0 -8
- package/dist/list-portal-host.js.map +0 -1
- package/dist/list-slot.d.ts +0 -14
- package/dist/list-slot.d.ts.map +0 -1
- package/dist/list-slot.js +0 -29
- package/dist/list-slot.js.map +0 -1
- package/dist/utils/position-only-model.d.ts +0 -10
- package/dist/utils/position-only-model.d.ts.map +0 -1
- package/dist/utils/position-only-model.js.map +0 -1
- package/dist/utils/realized-slot-store.d.ts.map +0 -1
- package/dist/utils/realized-slot-store.js.map +0 -1
- package/src/collection-view.tsx +0 -125
- package/src/contexts/column-view-context.ts +0 -28
- package/src/hooks/use-model-installation.ts +0 -25
- package/src/list-portal-host.tsx +0 -27
- package/src/list-slot.tsx +0 -56
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type Context, createContext, type RefObject, useContext } from "react";
|
|
3
|
-
import type { ItemResolver } from "../utils/item-resolver.js";
|
|
4
|
-
|
|
5
|
-
export interface ColumnRegistration {
|
|
6
|
-
id: string;
|
|
7
|
-
column: Gtk.ColumnViewColumn;
|
|
8
|
-
sortable: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ColumnViewContextValue {
|
|
12
|
-
columnView: RefObject<Gtk.ColumnView | null>;
|
|
13
|
-
resolver: ItemResolver<unknown, unknown>;
|
|
14
|
-
register(registration: ColumnRegistration): void;
|
|
15
|
-
unregister(id: string): void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const ColumnViewContext: Context<ColumnViewContextValue | null> = createContext<ColumnViewContextValue | null>(
|
|
19
|
-
null,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export const useColumnViewContext = (): ColumnViewContextValue => {
|
|
23
|
-
const context = useContext(ColumnViewContext);
|
|
24
|
-
if (context === null) {
|
|
25
|
-
throw new Error("<ColumnViewColumn> must be rendered inside a <ColumnView>.");
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
28
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { useTargetRegistration } from "@gtkx/react/internal";
|
|
3
|
-
import { type RefObject, useRef } from "react";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Installs `model` onto the realized GTK widget referenced by `target` through
|
|
7
|
-
* the `install` callback, re-running whenever the widget or model identity
|
|
8
|
-
* changes and tolerating the widget being realized after mount.
|
|
9
|
-
*/
|
|
10
|
-
export const useModelInstallation = <W extends Gtk.Widget, M>(
|
|
11
|
-
target: RefObject<W | null>,
|
|
12
|
-
model: M,
|
|
13
|
-
install: (widget: W, model: M) => void,
|
|
14
|
-
): void => {
|
|
15
|
-
const installRef = useRef(install);
|
|
16
|
-
installRef.current = install;
|
|
17
|
-
useTargetRegistration<W, { widget: W; model: M }>(target, {
|
|
18
|
-
attach: (widget) => {
|
|
19
|
-
installRef.current(widget, model);
|
|
20
|
-
return { widget, model };
|
|
21
|
-
},
|
|
22
|
-
detach: () => {},
|
|
23
|
-
isSame: (registration, widget) => registration.widget === widget && registration.model === model,
|
|
24
|
-
});
|
|
25
|
-
};
|
package/src/list-portal-host.tsx
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Fragment, type ReactNode, useSyncExternalStore } from "react";
|
|
2
|
-
import { ListSlot, type SlotRenderer } from "./list-slot.js";
|
|
3
|
-
import type { ItemResolver } from "./utils/item-resolver.js";
|
|
4
|
-
import type { RealizedSlotStore } from "./utils/realized-slot-store.js";
|
|
5
|
-
|
|
6
|
-
export interface ListPortalHostProps<T, S> {
|
|
7
|
-
store: RealizedSlotStore;
|
|
8
|
-
resolver: ItemResolver<T, S>;
|
|
9
|
-
render: SlotRenderer<T, S>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const ListPortalHost = <T, S>({ store, resolver, render }: ListPortalHostProps<T, S>): ReactNode => {
|
|
13
|
-
const containers = useSyncExternalStore(store.subscribeSet, store.getSlotsSnapshot, store.getSlotsSnapshot);
|
|
14
|
-
return (
|
|
15
|
-
<Fragment>
|
|
16
|
-
{containers.map((container) => (
|
|
17
|
-
<ListSlot
|
|
18
|
-
key={store.keyFor(container)}
|
|
19
|
-
container={container}
|
|
20
|
-
store={store}
|
|
21
|
-
resolver={resolver}
|
|
22
|
-
render={render}
|
|
23
|
-
/>
|
|
24
|
-
))}
|
|
25
|
-
</Fragment>
|
|
26
|
-
);
|
|
27
|
-
};
|
package/src/list-slot.tsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
-
import { GtkTreeExpander } from "@gtkx/jsx/gtk";
|
|
4
|
-
import { createPortal } from "@gtkx/react";
|
|
5
|
-
import { createElement, memo, type ReactNode, useCallback, useSyncExternalStore } from "react";
|
|
6
|
-
import type { ItemResolver } from "./utils/item-resolver.js";
|
|
7
|
-
import type { TreeItemMetadata } from "./utils/list-item-flatten.js";
|
|
8
|
-
import type { RealizedSlotStore, SlotEntry } from "./utils/realized-slot-store.js";
|
|
9
|
-
|
|
10
|
-
export type SlotRenderer<T, S> = (
|
|
11
|
-
value: T | S | undefined,
|
|
12
|
-
treeRow: Gtk.TreeListRow | null,
|
|
13
|
-
isHeader: boolean,
|
|
14
|
-
) => ReactNode;
|
|
15
|
-
|
|
16
|
-
export interface ListSlotProps<T, S> {
|
|
17
|
-
container: GObject.Object;
|
|
18
|
-
store: RealizedSlotStore;
|
|
19
|
-
resolver: ItemResolver<T, S>;
|
|
20
|
-
render: SlotRenderer<T, S>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const wrapInTreeExpander = (content: ReactNode, treeRow: Gtk.TreeListRow, metadata: TreeItemMetadata): ReactNode =>
|
|
24
|
-
createElement(
|
|
25
|
-
GtkTreeExpander,
|
|
26
|
-
{
|
|
27
|
-
ref: (expander: Gtk.TreeExpander | null) => {
|
|
28
|
-
if (expander !== null) expander.setListRow(treeRow);
|
|
29
|
-
},
|
|
30
|
-
hideExpander: metadata.hideExpander,
|
|
31
|
-
indentForDepth: metadata.indentForDepth,
|
|
32
|
-
indentForIcon: metadata.indentForIcon,
|
|
33
|
-
},
|
|
34
|
-
content,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const SlotImpl = <T, S>({ container, store, resolver, render }: ListSlotProps<T, S>): ReactNode => {
|
|
38
|
-
const subscribe = useCallback(
|
|
39
|
-
(onChange: () => void) => store.subscribePosition(container, onChange),
|
|
40
|
-
[store, container],
|
|
41
|
-
);
|
|
42
|
-
const getSnapshot = useCallback((): SlotEntry => store.getPosition(container), [store, container]);
|
|
43
|
-
const entry = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
44
|
-
|
|
45
|
-
if (entry.position < 0) return null;
|
|
46
|
-
const resolved = resolver.resolve(entry.position, entry.treeRow, entry.item);
|
|
47
|
-
if (!resolved.present) return null;
|
|
48
|
-
const content = render(resolved.value, resolved.treeRow, resolved.isHeader);
|
|
49
|
-
const portalled =
|
|
50
|
-
resolved.treeRow !== null && !resolved.isHeader
|
|
51
|
-
? wrapInTreeExpander(content, resolved.treeRow, resolved.metadata)
|
|
52
|
-
: content;
|
|
53
|
-
return createPortal(portalled, container, store.keyFor(container));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const ListSlot = memo(SlotImpl) as <T, S>(props: ListSlotProps<T, S>) => ReactNode;
|