@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/cell.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../src/cell.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAkB,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AA+B1F,MAAM,gBAAgB,GAAG,CAAC,EAAE,OAAO,EAAE,QAAQ,E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tkx/jsx/gtk\";\nimport { createPortal } from \"@gtkx/react\";\nimport { Fragment, memo, type ReactNode, useCallback, useSyncExternalStore } from \"react\";\nimport type { RenderItemProps } from \"./types.js\";\nimport type { CellContainerStore, CellEntry } from \"./utils/cell-container-store.js\";\nimport type { ItemResolver } from \"./utils/item-resolver.js\";\nimport type { TreeItemMetadata } from \"./utils/list-item-flatten.js\";\n\nexport type CellRenderer<T, S> = (\n value: T | S | undefined,\n treeRow: Gtk.TreeListRow | null,\n position: number,\n) => ReactNode;\n\ninterface CellProps<T, S> {\n container: GObject.Object;\n store: CellContainerStore;\n resolver: ItemResolver<T, S>;\n render: CellRenderer<T, S>;\n}\n\ninterface CellRenderHostProps<T, S> {\n store: CellContainerStore;\n resolver: ItemResolver<T, S>;\n render: CellRenderer<T, S>;\n}\n\ninterface TreeExpanderCellProps {\n treeRow: Gtk.TreeListRow;\n metadata: TreeItemMetadata;\n children: ReactNode;\n}\n\nconst TreeExpanderCell = ({ treeRow, metadata, children }: TreeExpanderCellProps): ReactNode => (\n <GtkTreeExpander\n ref={(expander: Gtk.TreeExpander | null) => {\n if (expander !== null) expander.setListRow(treeRow);\n }}\n hideExpander={metadata.hideExpander}\n indentForDepth={metadata.indentForDepth}\n indentForIcon={metadata.indentForIcon}\n >\n {children}\n </GtkTreeExpander>\n);\n\nconst Cell = memo(<T, S>({ container, store, resolver, render }: CellProps<T, S>): ReactNode => {\n const subscribe = useCallback(\n (onChange: () => void) => store.subscribePosition(container, onChange),\n [store, container],\n );\n const getSnapshot = useCallback((): CellEntry => store.getPosition(container), [store, container]);\n const entry = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n if (entry.position < 0) return null;\n const resolved = resolver.resolve(entry.position, entry.treeRow);\n if (!resolved.present) return null;\n const content = render(resolved.value, entry.treeRow, entry.position);\n const portalled =\n entry.treeRow !== null && !resolved.isHeader ? (\n <TreeExpanderCell treeRow={entry.treeRow} metadata={resolved.metadata}>\n {content}\n </TreeExpanderCell>\n ) : (\n content\n );\n return createPortal(portalled, container, store.keyFor(container));\n}) as <T, S>(props: CellProps<T, S>) => ReactNode;\n\nexport const CellRenderHost = <T, S>({ store, resolver, render }: CellRenderHostProps<T, S>): ReactNode => {\n const containers = useSyncExternalStore(\n store.subscribeSet,\n store.getContainersSnapshot,\n store.getContainersSnapshot,\n );\n return (\n <Fragment>\n {containers.map((container) => (\n <Cell\n key={store.keyFor(container)}\n container={container}\n store={store}\n resolver={resolver}\n render={render}\n />\n ))}\n </Fragment>\n );\n};\n\nexport type TreeRenderContext = {\n controlled: boolean;\n expandedIds: Set<string>;\n rowId: (row: Gtk.TreeListRow) => string | undefined;\n};\n\nexport const createTreeRenderContext = (\n expandedIds: string[] | null | undefined,\n rowId: (row: Gtk.TreeListRow) => string | undefined,\n): TreeRenderContext => ({\n controlled: expandedIds !== undefined && expandedIds !== null,\n expandedIds: new Set(expandedIds ?? []),\n rowId,\n});\n\nconst treeFields = (\n treeRow: Gtk.TreeListRow | null,\n context: TreeRenderContext | undefined,\n): { depth?: number; isExpanded?: boolean } => {\n if (treeRow === null) return {};\n const depth = treeRow.getDepth();\n if (context === undefined || !treeRow.isExpandable()) return { depth };\n const isExpanded = context.controlled\n ? context.expandedIds.has(context.rowId(treeRow) ?? \"\")\n : treeRow.getExpanded();\n return { depth, isExpanded };\n};\n\nexport const itemRenderer =\n <T, S>(render: (props: RenderItemProps<T>) => ReactNode, context?: TreeRenderContext): CellRenderer<T, S> =>\n (value, treeRow, position) =>\n render({ item: value as T, index: position, ...treeFields(treeRow, context) });\n\nconst headerRenderer =\n <T, S>(renderHeader: ((info: { section: S }) => ReactNode) | null | undefined): CellRenderer<T, S> =>\n (value) =>\n renderHeader ? renderHeader({ section: value as S }) : null;\n\ninterface HeaderRenderHostProps<T, S> {\n useHeader: boolean;\n store: CellContainerStore;\n resolver: ItemResolver<T, S>;\n renderHeader: ((info: { section: S }) => ReactNode) | null | undefined;\n}\n\nexport const HeaderRenderHost = <T, S>({\n useHeader,\n store,\n resolver,\n renderHeader,\n}: HeaderRenderHostProps<T, S>): ReactNode =>\n useHeader ? <CellRenderHost store={store} resolver={resolver} render={headerRenderer<T, S>(renderHeader)} /> : null;\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type GtkColumnViewColumnProps } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { type ReactNode } from "react";
|
|
4
|
-
import { type TreeRenderContext } from "./cell.js";
|
|
5
|
-
import type { RenderItemProps } from "./types.js";
|
|
6
|
-
import type { ItemResolver } from "./utils/item-resolver.js";
|
|
7
|
-
export type ColumnDefDeclarativeProps<T = unknown> = {
|
|
8
|
-
title: string;
|
|
9
|
-
expand?: boolean | undefined;
|
|
10
|
-
resizable?: boolean | undefined;
|
|
11
|
-
fixedWidth?: number | undefined;
|
|
12
|
-
id: string;
|
|
13
|
-
sortable?: boolean | undefined;
|
|
14
|
-
visible?: boolean | undefined;
|
|
15
|
-
renderCell: (props: RenderItemProps<T>) => ReactNode;
|
|
16
|
-
headerMenu?: ReactNode;
|
|
17
|
-
};
|
|
18
|
-
export type ColumnDef<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter"> & ColumnDefDeclarativeProps<T>;
|
|
19
|
-
type ColumnViewColumnProps<T = unknown> = ColumnDef<T> & {
|
|
20
|
-
resolver: ItemResolver<unknown, unknown>;
|
|
21
|
-
tree: TreeRenderContext;
|
|
22
|
-
estimatedItemHeight?: number | undefined;
|
|
23
|
-
onInstance: (id: string, column: Gtk.ColumnViewColumn | null) => void;
|
|
24
|
-
};
|
|
25
|
-
export declare const ColumnViewColumn: <T = unknown>(props: ColumnViewColumnProps<T>) => ReactNode;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=column-view-column.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"column-view-column.d.ts","sourceRoot":"","sources":["../src/column-view-column.tsx"],"names":[],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AE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC;CACzE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,CAAC,GAAG,OAAO,SAAS,qBAAqB,CAAC,CAAC,CAAC,KAAG,SA+C/E,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { GtkColumnViewColumn } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { useMergeRefs } from "@gtkx/react/internal";
|
|
4
|
-
import { useLayoutEffect, useRef, useState } from "react";
|
|
5
|
-
import { CellRenderHost, itemRenderer } from "./cell.js";
|
|
6
|
-
import { makeFactoryInstaller, useCellContainers } from "./hooks/use-cell-containers.js";
|
|
7
|
-
import { useHeaderMenu } from "./hooks/use-header-menu.js";
|
|
8
|
-
const factoryInstaller = makeFactoryInstaller((column, factory) => column.setFactory(factory));
|
|
9
|
-
export const ColumnViewColumn = (props) => {
|
|
10
|
-
const { id, title, sortable, renderCell, headerMenu, resolver, tree, estimatedItemHeight, onInstance, ref, ...intrinsicProps } = props;
|
|
11
|
-
const [column, setColumn] = useState(null);
|
|
12
|
-
const captureColumn = useMergeRefs(ref, setColumn);
|
|
13
|
-
const store = useCellContainers({
|
|
14
|
-
object: column,
|
|
15
|
-
installer: factoryInstaller,
|
|
16
|
-
estimatedHeight: estimatedItemHeight,
|
|
17
|
-
});
|
|
18
|
-
const onInstanceRef = useRef(onInstance);
|
|
19
|
-
onInstanceRef.current = onInstance;
|
|
20
|
-
useLayoutEffect(() => {
|
|
21
|
-
if (column === null)
|
|
22
|
-
return;
|
|
23
|
-
onInstanceRef.current(id, column);
|
|
24
|
-
return () => onInstanceRef.current(id, null);
|
|
25
|
-
}, [column, id]);
|
|
26
|
-
const headerMenuPortal = useHeaderMenu(column, headerMenu);
|
|
27
|
-
const cellRenderer = itemRenderer((cellProps) => renderCell({ ...cellProps, item: cellProps.item }), tree);
|
|
28
|
-
return (_jsxs(_Fragment, { children: [_jsx(GtkColumnViewColumn, { ...intrinsicProps, id: id, title: title, ref: captureColumn }), _jsx(CellRenderHost, { store: store, resolver: resolver, render: cellRenderer }), headerMenuPortal] }));
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=column-view-column.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"column-view-column.js","sourceRoot":"","sources":["../src/column-view-column.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,EAAiC,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAkB,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAqB,cAAc,EAAE,YAAY,EAA0B,MAAM,WAAW,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,MAAM,gBAAgB,GAAG,oBAAoB,CAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAwBrH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAc,KAA+B,EAAa,EAAE;IACxF,MAAM,EACF,EAAE,EACF,KAAK,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,mBAAmB,EACnB,UAAU,EACV,GAAG,EACH,GAAG,cAAc,EACpB,GAAG,KAA8D,CAAC;IACnE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA8B,IAAI,CAAC,CAAC;IAExE,MAAM,aAAa,GAAG,YAAY,CAAuB,GAAG,EAAE,SAAS,CAAC,CAAC;IAEzE,MAAM,KAAK,GAAG,iBAAiB,CAAuB;QAClD,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,gBAAgB;QAC3B,eAAe,EAAE,mBAAmB;KACvC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACzC,aAAa,CAAC,OAAO,GAAG,UAAU,CAAC;IAEnC,eAAe,CAAC,GAAG,EAAE;QACjB,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO;QAC5B,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;IAEjB,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAmC,YAAY,CAC7D,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,IAAS,EAAE,CAAC,EACtE,IAAI,CACP,CAAC;IAEF,OAAO,CACH,8BACI,KAAC,mBAAmB,OAAK,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAI,EACrF,KAAC,cAAc,IAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAI,EACzE,gBAAgB,IAClB,CACN,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkColumnViewColumn, type GtkColumnViewColumnProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { type ReactNode, useLayoutEffect, useRef, useState } from \"react\";\nimport { type CellRenderer, CellRenderHost, itemRenderer, type TreeRenderContext } from \"./cell.js\";\nimport { makeFactoryInstaller, useCellContainers } from \"./hooks/use-cell-containers.js\";\nimport { useHeaderMenu } from \"./hooks/use-header-menu.js\";\nimport type { RenderItemProps } from \"./types.js\";\nimport type { ItemResolver } from \"./utils/item-resolver.js\";\n\nconst factoryInstaller = makeFactoryInstaller<Gtk.ColumnViewColumn>((column, factory) => column.setFactory(factory));\n\nexport type ColumnDefDeclarativeProps<T = unknown> = {\n title: string;\n expand?: boolean | undefined;\n resizable?: boolean | undefined;\n fixedWidth?: number | undefined;\n id: string;\n sortable?: boolean | undefined;\n visible?: boolean | undefined;\n renderCell: (props: RenderItemProps<T>) => ReactNode;\n headerMenu?: ReactNode;\n};\n\nexport type ColumnDef<T = unknown> = Omit<GtkColumnViewColumnProps, \"factory\" | \"sorter\"> &\n ColumnDefDeclarativeProps<T>;\n\ntype ColumnViewColumnProps<T = unknown> = ColumnDef<T> & {\n resolver: ItemResolver<unknown, unknown>;\n tree: TreeRenderContext;\n estimatedItemHeight?: number | undefined;\n onInstance: (id: string, column: Gtk.ColumnViewColumn | null) => void;\n};\n\nexport const ColumnViewColumn = <T = unknown>(props: ColumnViewColumnProps<T>): ReactNode => {\n const {\n id,\n title,\n sortable,\n renderCell,\n headerMenu,\n resolver,\n tree,\n estimatedItemHeight,\n onInstance,\n ref,\n ...intrinsicProps\n } = props as ColumnViewColumnProps<T> & { [key: string]: unknown };\n const [column, setColumn] = useState<Gtk.ColumnViewColumn | null>(null);\n\n const captureColumn = useMergeRefs<Gtk.ColumnViewColumn>(ref, setColumn);\n\n const store = useCellContainers<Gtk.ColumnViewColumn>({\n object: column,\n installer: factoryInstaller,\n estimatedHeight: estimatedItemHeight,\n });\n\n const onInstanceRef = useRef(onInstance);\n onInstanceRef.current = onInstance;\n\n useLayoutEffect(() => {\n if (column === null) return;\n onInstanceRef.current(id, column);\n return () => onInstanceRef.current(id, null);\n }, [column, id]);\n\n const headerMenuPortal = useHeaderMenu(column, headerMenu);\n\n const cellRenderer: CellRenderer<unknown, unknown> = itemRenderer<unknown, unknown>(\n (cellProps) => renderCell({ ...cellProps, item: cellProps.item as T }),\n tree,\n );\n\n return (\n <>\n <GtkColumnViewColumn {...intrinsicProps} id={id} title={title} ref={captureColumn} />\n <CellRenderHost store={store} resolver={resolver} render={cellRenderer} />\n {headerMenuPortal}\n </>\n );\n};\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
/**
|
|
3
|
-
* Describes one constraint added by `<ConstraintLayout.Constraint>`, relating a
|
|
4
|
-
* target widget attribute to a source attribute of another widget or guide.
|
|
5
|
-
*/
|
|
6
|
-
export type ConstraintProps = {
|
|
7
|
-
/** Name of the target widget or guide. Use "super" or omit to reference the layout's own widget. */
|
|
8
|
-
target?: string;
|
|
9
|
-
targetAttribute: Gtk.ConstraintAttribute;
|
|
10
|
-
/** Relation between the target and source attributes (defaults to equality). */
|
|
11
|
-
relation?: Gtk.ConstraintRelation;
|
|
12
|
-
/** Name of the source widget or guide. Use "super" or omit for a constant constraint. */
|
|
13
|
-
source?: string;
|
|
14
|
-
sourceAttribute?: Gtk.ConstraintAttribute;
|
|
15
|
-
/** Factor applied to the source attribute (defaults to 1). */
|
|
16
|
-
multiplier?: number;
|
|
17
|
-
/** Constant offset added to the relation (defaults to 0). */
|
|
18
|
-
constant?: number;
|
|
19
|
-
/** Constraint strength, higher values winning conflicts (defaults to required). */
|
|
20
|
-
strength?: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Describes an invisible spacing guide added by `<ConstraintLayout.Guide>`,
|
|
24
|
-
* usable as a constraint target under its id.
|
|
25
|
-
*/
|
|
26
|
-
export type ConstraintGuideProps = {
|
|
27
|
-
/** Identifier used to reference this guide from constraints. */
|
|
28
|
-
id: string;
|
|
29
|
-
minWidth?: number;
|
|
30
|
-
minHeight?: number;
|
|
31
|
-
/** Preferred (natural) width. */
|
|
32
|
-
natWidth?: number;
|
|
33
|
-
/** Preferred (natural) height. */
|
|
34
|
-
natHeight?: number;
|
|
35
|
-
maxWidth?: number;
|
|
36
|
-
maxHeight?: number;
|
|
37
|
-
/** Strength of the guide's own size constraints. */
|
|
38
|
-
strength?: Gtk.ConstraintStrength;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Describes constraints authored with the Visual Format Language (VFL), applied by
|
|
42
|
-
* `<ConstraintLayout.Vfl>`.
|
|
43
|
-
*/
|
|
44
|
-
export type ConstraintVflProps = {
|
|
45
|
-
/** VFL lines describing the constraints between named widgets and guides. */
|
|
46
|
-
lines: string[];
|
|
47
|
-
/** Default horizontal spacing used by the layout operator (defaults to 0). */
|
|
48
|
-
hspacing?: number;
|
|
49
|
-
/** Default vertical spacing used by the layout operator (defaults to 0). */
|
|
50
|
-
vspacing?: number;
|
|
51
|
-
};
|
|
52
|
-
export declare function applyConstraint(layout: Gtk.ConstraintLayout, props: ConstraintProps): () => void;
|
|
53
|
-
export declare function applyVfl(layout: Gtk.ConstraintLayout, props: ConstraintVflProps): () => void;
|
|
54
|
-
export declare function applyGuide(layout: Gtk.ConstraintLayout, props: ConstraintGuideProps): () => void;
|
|
55
|
-
//# sourceMappingURL=constraint-layout-apply.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constraint-layout-apply.d.ts","sourceRoot":"","sources":["../src/constraint-layout-apply.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,oGAAoG;IACpG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,GAAG,CAAC,mBAAmB,CAAC;IACzC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,GAAG,CAAC,kBAAkB,CAAC;IAClC,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC;IAC1C,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k";
|
|
3
|
-
const SUPER_ID = "super";
|
|
4
|
-
const unknownIdMessage = (role, id) => `<ConstraintLayout.Constraint> references unknown id '${id}'. ` +
|
|
5
|
-
`Set name="${id}" on the ${role} widget, or add a <ConstraintLayout.Guide id="${id}">.`;
|
|
6
|
-
const guideRegistry = new WeakMap();
|
|
7
|
-
const guidesFor = (layout) => {
|
|
8
|
-
let map = guideRegistry.get(layout);
|
|
9
|
-
if (!map) {
|
|
10
|
-
map = new Map();
|
|
11
|
-
guideRegistry.set(layout, map);
|
|
12
|
-
}
|
|
13
|
-
return map;
|
|
14
|
-
};
|
|
15
|
-
const explicitWidgetName = (widget) => {
|
|
16
|
-
const value = new GObject.Value();
|
|
17
|
-
value.init(GObject.TYPE_STRING);
|
|
18
|
-
widget.getProperty("name", value);
|
|
19
|
-
const name = value.getString();
|
|
20
|
-
return name !== null && name.length > 0 ? name : null;
|
|
21
|
-
};
|
|
22
|
-
function* namedChildren(layout) {
|
|
23
|
-
const host = layout.getWidget();
|
|
24
|
-
if (!host)
|
|
25
|
-
return;
|
|
26
|
-
for (let child = host.getFirstChild(); child; child = child.getNextSibling()) {
|
|
27
|
-
const name = explicitWidgetName(child);
|
|
28
|
-
if (name !== null)
|
|
29
|
-
yield [name, child];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const findChildByName = (layout, id) => {
|
|
33
|
-
for (const [name, child] of namedChildren(layout)) {
|
|
34
|
-
if (name === id)
|
|
35
|
-
return child;
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
};
|
|
39
|
-
const resolveConstraintTarget = (layout, id) => {
|
|
40
|
-
if (id === undefined || id === SUPER_ID)
|
|
41
|
-
return null;
|
|
42
|
-
return findChildByName(layout, id) ?? guidesFor(layout).get(id);
|
|
43
|
-
};
|
|
44
|
-
const constraintViews = (layout) => {
|
|
45
|
-
const views = new Map();
|
|
46
|
-
for (const [name, child] of namedChildren(layout))
|
|
47
|
-
views.set(name, child);
|
|
48
|
-
for (const [name, guide] of guidesFor(layout)) {
|
|
49
|
-
if (!views.has(name))
|
|
50
|
-
views.set(name, guide);
|
|
51
|
-
}
|
|
52
|
-
return views;
|
|
53
|
-
};
|
|
54
|
-
const isLayoutLive = (layout) => layout.getWidget() !== null;
|
|
55
|
-
export function applyConstraint(layout, props) {
|
|
56
|
-
const target = resolveConstraintTarget(layout, props.target);
|
|
57
|
-
if (target === undefined)
|
|
58
|
-
throw new Error(unknownIdMessage("target", String(props.target)));
|
|
59
|
-
const source = resolveConstraintTarget(layout, props.source);
|
|
60
|
-
if (source === undefined)
|
|
61
|
-
throw new Error(unknownIdMessage("source", String(props.source)));
|
|
62
|
-
const constraint = new Gtk.Constraint({
|
|
63
|
-
target,
|
|
64
|
-
targetAttribute: props.targetAttribute,
|
|
65
|
-
relation: props.relation ?? Gtk.ConstraintRelation.EQ,
|
|
66
|
-
source,
|
|
67
|
-
sourceAttribute: props.sourceAttribute ?? Gtk.ConstraintAttribute.NONE,
|
|
68
|
-
multiplier: props.multiplier ?? 1,
|
|
69
|
-
constant: props.constant ?? 0,
|
|
70
|
-
strength: props.strength ?? Gtk.ConstraintStrength.REQUIRED,
|
|
71
|
-
});
|
|
72
|
-
layout.addConstraint(constraint);
|
|
73
|
-
return () => {
|
|
74
|
-
if (isLayoutLive(layout))
|
|
75
|
-
layout.removeConstraint(constraint);
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
export function applyVfl(layout, props) {
|
|
79
|
-
const views = constraintViews(layout);
|
|
80
|
-
const constraints = layout.addConstraintsFromDescription(props.lines, props.hspacing ?? 0, props.vspacing ?? 0, views);
|
|
81
|
-
return () => {
|
|
82
|
-
if (!isLayoutLive(layout))
|
|
83
|
-
return;
|
|
84
|
-
for (const constraint of constraints)
|
|
85
|
-
layout.removeConstraint(constraint);
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
export function applyGuide(layout, props) {
|
|
89
|
-
const guide = new Gtk.ConstraintGuide({
|
|
90
|
-
name: props.id,
|
|
91
|
-
minWidth: props.minWidth,
|
|
92
|
-
minHeight: props.minHeight,
|
|
93
|
-
natWidth: props.natWidth,
|
|
94
|
-
natHeight: props.natHeight,
|
|
95
|
-
maxWidth: props.maxWidth,
|
|
96
|
-
maxHeight: props.maxHeight,
|
|
97
|
-
strength: props.strength,
|
|
98
|
-
});
|
|
99
|
-
layout.addGuide(guide);
|
|
100
|
-
guidesFor(layout).set(props.id, guide);
|
|
101
|
-
return () => {
|
|
102
|
-
guidesFor(layout).delete(props.id);
|
|
103
|
-
if (isLayoutLive(layout))
|
|
104
|
-
layout.removeGuide(guide);
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=constraint-layout-apply.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constraint-layout-apply.js","sourceRoot":"","sources":["../src/constraint-layout-apply.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAuDpC,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAU,EAAU,EAAE,CAC1D,wDAAwD,EAAE,KAAK;IAC/D,aAAa,EAAE,YAAY,IAAI,iDAAiD,EAAE,KAAK,CAAC;AAE5F,MAAM,aAAa,GAAG,IAAI,OAAO,EAA0D,CAAC;AAE5F,MAAM,SAAS,GAAG,CAAC,MAA4B,EAAoC,EAAE;IACjF,IAAI,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,GAAG,GAAG,IAAI,GAAG,EAA+B,CAAC;QAC7C,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC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AE;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;KAC3B,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAEvC,OAAO,GAAG,EAAE;QACR,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,YAAY,CAAC,MAAM,CAAC;YAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import * as GObject from \"@gtkx/gi/gobject\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\n\n/**\n * Describes one constraint added by `<ConstraintLayout.Constraint>`, relating a\n * target widget attribute to a source attribute of another widget or guide.\n */\nexport type ConstraintProps = {\n /** Name of the target widget or guide. Use \"super\" or omit to reference the layout's own widget. */\n target?: string;\n targetAttribute: Gtk.ConstraintAttribute;\n /** Relation between the target and source attributes (defaults to equality). */\n relation?: Gtk.ConstraintRelation;\n /** Name of the source widget or guide. Use \"super\" or omit for a constant constraint. */\n source?: string;\n sourceAttribute?: Gtk.ConstraintAttribute;\n /** Factor applied to the source attribute (defaults to 1). */\n multiplier?: number;\n /** Constant offset added to the relation (defaults to 0). */\n constant?: number;\n /** Constraint strength, higher values winning conflicts (defaults to required). */\n strength?: number;\n};\n\n/**\n * Describes an invisible spacing guide added by `<ConstraintLayout.Guide>`,\n * usable as a constraint target under its id.\n */\nexport type ConstraintGuideProps = {\n /** Identifier used to reference this guide from constraints. */\n id: string;\n minWidth?: number;\n minHeight?: number;\n /** Preferred (natural) width. */\n natWidth?: number;\n /** Preferred (natural) height. */\n natHeight?: number;\n maxWidth?: number;\n maxHeight?: number;\n /** Strength of the guide's own size constraints. */\n strength?: Gtk.ConstraintStrength;\n};\n\n/**\n * Describes constraints authored with the Visual Format Language (VFL), applied by\n * `<ConstraintLayout.Vfl>`.\n */\nexport type ConstraintVflProps = {\n /** VFL lines describing the constraints between named widgets and guides. */\n lines: string[];\n /** Default horizontal spacing used by the layout operator (defaults to 0). */\n hspacing?: number;\n /** Default vertical spacing used by the layout operator (defaults to 0). */\n vspacing?: number;\n};\n\nconst SUPER_ID = \"super\";\n\nconst unknownIdMessage = (role: string, id: string): string =>\n `<ConstraintLayout.Constraint> references unknown id '${id}'. ` +\n `Set name=\"${id}\" on the ${role} widget, or add a <ConstraintLayout.Guide id=\"${id}\">.`;\n\nconst guideRegistry = new WeakMap<Gtk.ConstraintLayout, Map<string, Gtk.ConstraintGuide>>();\n\nconst guidesFor = (layout: Gtk.ConstraintLayout): Map<string, Gtk.ConstraintGuide> => {\n let map = guideRegistry.get(layout);\n if (!map) {\n map = new Map<string, Gtk.ConstraintGuide>();\n guideRegistry.set(layout, map);\n }\n return map;\n};\n\nconst explicitWidgetName = (widget: Gtk.Widget): string | null => {\n const value = new GObject.Value();\n value.init(GObject.TYPE_STRING);\n widget.getProperty(\"name\", value);\n const name = value.getString();\n return name !== null && name.length > 0 ? name : null;\n};\n\nfunction* namedChildren(layout: Gtk.ConstraintLayout): Generator<[string, Gtk.Widget]> {\n const host = layout.getWidget();\n if (!host) return;\n for (let child = host.getFirstChild(); child; child = child.getNextSibling()) {\n const name = explicitWidgetName(child);\n if (name !== null) yield [name, child];\n }\n}\n\nconst findChildByName = (layout: Gtk.ConstraintLayout, id: string): Gtk.Widget | undefined => {\n for (const [name, child] of namedChildren(layout)) {\n if (name === id) return child;\n }\n return undefined;\n};\n\nconst resolveConstraintTarget = (\n layout: Gtk.ConstraintLayout,\n id: string | undefined,\n): Gtk.ConstraintTarget | null | undefined => {\n if (id === undefined || id === SUPER_ID) return null;\n return findChildByName(layout, id) ?? guidesFor(layout).get(id);\n};\n\nconst constraintViews = (layout: Gtk.ConstraintLayout): Map<string, Gtk.ConstraintTarget> => {\n const views = new Map<string, Gtk.ConstraintTarget>();\n for (const [name, child] of namedChildren(layout)) views.set(name, child);\n for (const [name, guide] of guidesFor(layout)) {\n if (!views.has(name)) views.set(name, guide);\n }\n return views;\n};\n\nconst isLayoutLive = (layout: Gtk.ConstraintLayout): boolean => layout.getWidget() !== null;\n\nexport function applyConstraint(layout: Gtk.ConstraintLayout, props: ConstraintProps): () => void {\n const target = resolveConstraintTarget(layout, props.target);\n if (target === undefined) throw new Error(unknownIdMessage(\"target\", String(props.target)));\n const source = resolveConstraintTarget(layout, props.source);\n if (source === undefined) throw new Error(unknownIdMessage(\"source\", String(props.source)));\n\n const constraint = new Gtk.Constraint({\n target,\n targetAttribute: props.targetAttribute,\n relation: props.relation ?? Gtk.ConstraintRelation.EQ,\n source,\n sourceAttribute: props.sourceAttribute ?? Gtk.ConstraintAttribute.NONE,\n multiplier: props.multiplier ?? 1,\n constant: props.constant ?? 0,\n strength: props.strength ?? Gtk.ConstraintStrength.REQUIRED,\n });\n layout.addConstraint(constraint);\n\n return () => {\n if (isLayoutLive(layout)) layout.removeConstraint(constraint);\n };\n}\n\nexport function applyVfl(layout: Gtk.ConstraintLayout, props: ConstraintVflProps): () => void {\n const views = constraintViews(layout);\n const constraints = layout.addConstraintsFromDescription(\n props.lines,\n props.hspacing ?? 0,\n props.vspacing ?? 0,\n views,\n );\n\n return () => {\n if (!isLayoutLive(layout)) return;\n for (const constraint of constraints) layout.removeConstraint(constraint);\n };\n}\n\nexport function applyGuide(layout: Gtk.ConstraintLayout, props: ConstraintGuideProps): () => void {\n const guide = new Gtk.ConstraintGuide({\n name: props.id,\n minWidth: props.minWidth,\n minHeight: props.minHeight,\n natWidth: props.natWidth,\n natHeight: props.natHeight,\n maxWidth: props.maxWidth,\n maxHeight: props.maxHeight,\n strength: props.strength,\n });\n layout.addGuide(guide);\n guidesFor(layout).set(props.id, guide);\n\n return () => {\n guidesFor(layout).delete(props.id);\n if (isLayoutLive(layout)) layout.removeGuide(guide);\n };\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type ReactNode, type Ref } from "react";
|
|
3
|
-
import { type ConstraintGuideProps, type ConstraintProps, type ConstraintVflProps } from "./constraint-layout-apply.js";
|
|
4
|
-
/** Props for {@link ConstraintLayout}. */
|
|
5
|
-
export type ConstraintLayoutProps = {
|
|
6
|
-
children?: ReactNode;
|
|
7
|
-
ref?: Ref<Gtk.ConstraintLayout | null>;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Installs a Gtk.ConstraintLayout on a host widget and exposes child components to
|
|
11
|
-
* populate it: {@link ConstraintProps | ConstraintLayout.Constraint} for individual constraints,
|
|
12
|
-
* {@link ConstraintGuideProps | ConstraintLayout.Guide} for spacing guides, and {@link ConstraintVflProps | ConstraintLayout.Vfl}
|
|
13
|
-
* for constraints authored in the Visual Format Language.
|
|
14
|
-
*/
|
|
15
|
-
export declare const ConstraintLayout: ((props: ConstraintLayoutProps) => ReactNode) & {
|
|
16
|
-
Guide: (props: ConstraintGuideProps) => ReactNode;
|
|
17
|
-
Constraint: (props: ConstraintProps) => ReactNode;
|
|
18
|
-
Vfl: (props: ConstraintVflProps) => ReactNode;
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=constraint-layout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constraint-layout.d.ts","sourceRoot":"","sources":["../src/constraint-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAGzC,OAAO,EAGH,KAAK,SAAS,EACd,KAAK,GAAG,EAMX,MAAM,OAAO,CAAC;AACf,OAAO,EAIH,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAC1B,MAAM,8BAA8B,CAAC;AAatC,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG;IAChC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC1C,CAAC;AAqCF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,KAAK,EAAE,qBAAqB,KAAK,SAAS,CAAC,GAAG;IAC3E,KAAK,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,SAAS,CAAC;IAClD,UAAU,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,SAAS,CAAC;IAClD,GAAG,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,SAAS,CAAC;CAkDjD,CAAC"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { GtkConstraintLayout } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { useMergeRefs } from "@gtkx/react/internal";
|
|
4
|
-
import { createContext, useContext, useEffect, useLayoutEffect, useRef, } from "react";
|
|
5
|
-
import { applyConstraint, applyGuide, applyVfl, } from "./constraint-layout-apply.js";
|
|
6
|
-
const ORPHAN_MESSAGE = "<ConstraintLayout.Constraint> / <Guide> / <Vfl> must be a child of <ConstraintLayout>";
|
|
7
|
-
const ConstraintLayoutContext = createContext(null);
|
|
8
|
-
const useConstraintLayoutRef = () => {
|
|
9
|
-
const ref = useContext(ConstraintLayoutContext);
|
|
10
|
-
if (!ref)
|
|
11
|
-
throw new Error(ORPHAN_MESSAGE);
|
|
12
|
-
return ref;
|
|
13
|
-
};
|
|
14
|
-
const cleanupContribution = (cleanupRef) => {
|
|
15
|
-
const cleanup = cleanupRef.current;
|
|
16
|
-
if (!cleanup)
|
|
17
|
-
return;
|
|
18
|
-
cleanupRef.current = null;
|
|
19
|
-
cleanup();
|
|
20
|
-
};
|
|
21
|
-
const useLayoutContribution = (apply, deps) => {
|
|
22
|
-
const layoutRef = useConstraintLayoutRef();
|
|
23
|
-
useLayoutEffect(() => {
|
|
24
|
-
const layout = layoutRef.current;
|
|
25
|
-
if (!layout)
|
|
26
|
-
return;
|
|
27
|
-
return apply(layout);
|
|
28
|
-
}, deps);
|
|
29
|
-
};
|
|
30
|
-
const useDeferredContribution = (apply, deps) => {
|
|
31
|
-
const layoutRef = useConstraintLayoutRef();
|
|
32
|
-
const cleanupRef = useRef(null);
|
|
33
|
-
useLayoutEffect(() => () => cleanupContribution(cleanupRef), deps);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const layout = layoutRef.current;
|
|
36
|
-
if (!layout)
|
|
37
|
-
return;
|
|
38
|
-
const cleanup = apply(layout);
|
|
39
|
-
cleanupRef.current = cleanup;
|
|
40
|
-
return () => {
|
|
41
|
-
if (cleanupRef.current === cleanup)
|
|
42
|
-
cleanupContribution(cleanupRef);
|
|
43
|
-
};
|
|
44
|
-
}, deps);
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Installs a Gtk.ConstraintLayout on a host widget and exposes child components to
|
|
48
|
-
* populate it: {@link ConstraintProps | ConstraintLayout.Constraint} for individual constraints,
|
|
49
|
-
* {@link ConstraintGuideProps | ConstraintLayout.Guide} for spacing guides, and {@link ConstraintVflProps | ConstraintLayout.Vfl}
|
|
50
|
-
* for constraints authored in the Visual Format Language.
|
|
51
|
-
*/
|
|
52
|
-
export const ConstraintLayout = Object.assign(({ children, ref }) => {
|
|
53
|
-
const layoutRef = useRef(null);
|
|
54
|
-
const mergedRef = useMergeRefs(ref, layoutRef);
|
|
55
|
-
return (_jsxs(_Fragment, { children: [_jsx(GtkConstraintLayout, { ref: mergedRef }), _jsx(ConstraintLayoutContext.Provider, { value: layoutRef, children: children })] }));
|
|
56
|
-
}, {
|
|
57
|
-
Guide: (props) => {
|
|
58
|
-
useLayoutContribution((layout) => applyGuide(layout, props), [
|
|
59
|
-
props.id,
|
|
60
|
-
props.minWidth,
|
|
61
|
-
props.minHeight,
|
|
62
|
-
props.natWidth,
|
|
63
|
-
props.natHeight,
|
|
64
|
-
props.maxWidth,
|
|
65
|
-
props.maxHeight,
|
|
66
|
-
props.strength,
|
|
67
|
-
]);
|
|
68
|
-
return null;
|
|
69
|
-
},
|
|
70
|
-
Constraint: (props) => {
|
|
71
|
-
useDeferredContribution((layout) => applyConstraint(layout, props), [
|
|
72
|
-
props.target,
|
|
73
|
-
props.targetAttribute,
|
|
74
|
-
props.relation,
|
|
75
|
-
props.source,
|
|
76
|
-
props.sourceAttribute,
|
|
77
|
-
props.multiplier,
|
|
78
|
-
props.constant,
|
|
79
|
-
props.strength,
|
|
80
|
-
]);
|
|
81
|
-
return null;
|
|
82
|
-
},
|
|
83
|
-
Vfl: (props) => {
|
|
84
|
-
useDeferredContribution((layout) => applyVfl(layout, props), [props.lines, props.hspacing, props.vspacing]);
|
|
85
|
-
return null;
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=constraint-layout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constraint-layout.js","sourceRoot":"","sources":["../src/constraint-layout.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAEH,aAAa,EAIb,UAAU,EACV,SAAS,EACT,eAAe,EACf,MAAM,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EACH,eAAe,EACf,UAAU,EACV,QAAQ,GAIX,MAAM,8BAA8B,CAAC;AAEtC,MAAM,cAAc,GAAG,uFAAuF,CAAC;AAE/G,MAAM,uBAAuB,GACzB,aAA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AK,CAAC,MAAM;YACZ,KAAK,CAAC,eAAe;YACrB,KAAK,CAAC,UAAU;YAChB,KAAK,CAAC,QAAQ;YACd,KAAK,CAAC,QAAQ;SACjB,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,GAAG,EAAE,CAAC,KAAyB,EAAa,EAAE;QAC1C,uBAAuB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5G,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CACJ,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkConstraintLayout } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport {\n type Context,\n createContext,\n type ReactNode,\n type Ref,\n type RefObject,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from \"react\";\nimport {\n applyConstraint,\n applyGuide,\n applyVfl,\n type ConstraintGuideProps,\n type ConstraintProps,\n type ConstraintVflProps,\n} from \"./constraint-layout-apply.js\";\n\nconst ORPHAN_MESSAGE = \"<ConstraintLayout.Constraint> / <Guide> / <Vfl> must be a child of <ConstraintLayout>\";\n\nconst ConstraintLayoutContext: Context<RefObject<Gtk.ConstraintLayout | null> | null> =\n createContext<RefObject<Gtk.ConstraintLayout | null> | null>(null);\n\nconst useConstraintLayoutRef = (): RefObject<Gtk.ConstraintLayout | null> => {\n const ref = useContext(ConstraintLayoutContext);\n if (!ref) throw new Error(ORPHAN_MESSAGE);\n return ref;\n};\n\n/** Props for {@link ConstraintLayout}. */\nexport type ConstraintLayoutProps = {\n children?: ReactNode;\n ref?: Ref<Gtk.ConstraintLayout | null>;\n};\n\ntype ContributionCleanupRef = { current: (() => void) | null };\n\nconst cleanupContribution = (cleanupRef: ContributionCleanupRef): void => {\n const cleanup = cleanupRef.current;\n if (!cleanup) return;\n cleanupRef.current = null;\n cleanup();\n};\n\nconst useLayoutContribution = (apply: (layout: Gtk.ConstraintLayout) => () => void, deps: unknown[]): void => {\n const layoutRef = useConstraintLayoutRef();\n useLayoutEffect(() => {\n const layout = layoutRef.current;\n if (!layout) return;\n return apply(layout);\n }, deps);\n};\n\nconst useDeferredContribution = (apply: (layout: Gtk.ConstraintLayout) => () => void, deps: unknown[]): void => {\n const layoutRef = useConstraintLayoutRef();\n const cleanupRef = useRef<(() => void) | null>(null);\n\n useLayoutEffect(() => () => cleanupContribution(cleanupRef), deps);\n\n useEffect(() => {\n const layout = layoutRef.current;\n if (!layout) return;\n const cleanup = apply(layout);\n cleanupRef.current = cleanup;\n return () => {\n if (cleanupRef.current === cleanup) cleanupContribution(cleanupRef);\n };\n }, deps);\n};\n\n/**\n * Installs a Gtk.ConstraintLayout on a host widget and exposes child components to\n * populate it: {@link ConstraintProps | ConstraintLayout.Constraint} for individual constraints,\n * {@link ConstraintGuideProps | ConstraintLayout.Guide} for spacing guides, and {@link ConstraintVflProps | ConstraintLayout.Vfl}\n * for constraints authored in the Visual Format Language.\n */\nexport const ConstraintLayout: ((props: ConstraintLayoutProps) => ReactNode) & {\n Guide: (props: ConstraintGuideProps) => ReactNode;\n Constraint: (props: ConstraintProps) => ReactNode;\n Vfl: (props: ConstraintVflProps) => ReactNode;\n} = Object.assign(\n ({ children, ref }: ConstraintLayoutProps): ReactNode => {\n const layoutRef = useRef<Gtk.ConstraintLayout | null>(null);\n const mergedRef = useMergeRefs<Gtk.ConstraintLayout>(ref, layoutRef);\n return (\n <>\n <GtkConstraintLayout ref={mergedRef} />\n <ConstraintLayoutContext.Provider value={layoutRef}>{children}</ConstraintLayoutContext.Provider>\n </>\n );\n },\n {\n Guide: (props: ConstraintGuideProps): ReactNode => {\n useLayoutContribution(\n (layout) => applyGuide(layout, props),\n [\n props.id,\n props.minWidth,\n props.minHeight,\n props.natWidth,\n props.natHeight,\n props.maxWidth,\n props.maxHeight,\n props.strength,\n ],\n );\n return null;\n },\n Constraint: (props: ConstraintProps): ReactNode => {\n useDeferredContribution(\n (layout) => applyConstraint(layout, props),\n [\n props.target,\n props.targetAttribute,\n props.relation,\n props.source,\n props.sourceAttribute,\n props.multiplier,\n props.constant,\n props.strength,\n ],\n );\n return null;\n },\n Vfl: (props: ConstraintVflProps): ReactNode => {\n useDeferredContribution((layout) => applyVfl(layout, props), [props.lines, props.hspacing, props.vspacing]);\n return null;\n },\n },\n);\n"]}
|
package/dist/fixed.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as Gsk from "@gtkx/gi/gsk";
|
|
2
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
-
import { type GtkFixedProps } from "@gtkx/jsx/gtk";
|
|
4
|
-
import { type ElementType, type ReactNode, type Ref } from "react";
|
|
5
|
-
import type { ChildProps } from "./types.js";
|
|
6
|
-
/** Props for {@link Fixed}. */
|
|
7
|
-
export type FixedProps = GtkFixedProps & {
|
|
8
|
-
ref?: Ref<Gtk.Fixed | null>;
|
|
9
|
-
children?: ReactNode;
|
|
10
|
-
};
|
|
11
|
-
export type FixedPlacementProps = {
|
|
12
|
-
x?: number | null | undefined;
|
|
13
|
-
y?: number | null | undefined;
|
|
14
|
-
/** Full transform applied to the child, overriding x and y when provided. */
|
|
15
|
-
transform?: Gsk.Transform | null | undefined;
|
|
16
|
-
};
|
|
17
|
-
/** Positions a single child inside a {@link Fixed} at coordinates x and y, or by an explicit transform. */
|
|
18
|
-
export type FixedChildProps<C extends ElementType> = ChildProps<C, FixedPlacementProps>;
|
|
19
|
-
/**
|
|
20
|
-
* Renders a Gtk.Fixed container whose children are placed at explicit positions via
|
|
21
|
-
* {@link Fixed.Child}.
|
|
22
|
-
*/
|
|
23
|
-
export declare const Fixed: ((props: FixedProps) => ReactNode) & {
|
|
24
|
-
Child: <C extends ElementType>(props: FixedChildProps<C>) => ReactNode;
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E,CAAC"}
|
package/dist/fixed.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as Graphene from "@gtkx/gi/graphene";
|
|
3
|
-
import * as Gsk from "@gtkx/gi/gsk";
|
|
4
|
-
import { GtkFixed } from "@gtkx/jsx/gtk";
|
|
5
|
-
import { useMergeRefs } from "@gtkx/react/internal";
|
|
6
|
-
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState, } from "react";
|
|
7
|
-
const FixedContext = createContext(undefined);
|
|
8
|
-
const useFixedInstance = () => {
|
|
9
|
-
const fixed = useContext(FixedContext);
|
|
10
|
-
if (fixed === undefined)
|
|
11
|
-
throw new Error("<Fixed.Child> must be a child of <Fixed>");
|
|
12
|
-
return fixed;
|
|
13
|
-
};
|
|
14
|
-
const transformOf = (x, y, transform) => transform !== undefined ? transform : Gsk.Transform.new().translate(Graphene.Point.create(x, y));
|
|
15
|
-
const FixedChild = ({ component, x, y, transform, ref, ...rest }) => {
|
|
16
|
-
const fixed = useFixedInstance();
|
|
17
|
-
const Component = component;
|
|
18
|
-
const widgetRef = useRef(null);
|
|
19
|
-
const captureWidget = useCallback((node) => {
|
|
20
|
-
widgetRef.current = node;
|
|
21
|
-
}, []);
|
|
22
|
-
const setWidget = useMergeRefs(ref, captureWidget);
|
|
23
|
-
useLayoutEffect(() => {
|
|
24
|
-
const widget = widgetRef.current;
|
|
25
|
-
if (widget === null || fixed === null)
|
|
26
|
-
return;
|
|
27
|
-
fixed.setChildTransform(widget, transformOf(x ?? 0, y ?? 0, transform));
|
|
28
|
-
});
|
|
29
|
-
return _jsx(Component, { ...rest, ref: setWidget });
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Renders a Gtk.Fixed container whose children are placed at explicit positions via
|
|
33
|
-
* {@link Fixed.Child}.
|
|
34
|
-
*/
|
|
35
|
-
export const Fixed = Object.assign(({ children, ref, ...rest }) => {
|
|
36
|
-
const [fixed, setFixed] = useState(null);
|
|
37
|
-
const mergedRef = useMergeRefs(ref, setFixed);
|
|
38
|
-
return (_jsx(GtkFixed, { ...rest, ref: mergedRef, children: _jsx(FixedContext.Provider, { value: fixed, children: children }) }));
|
|
39
|
-
}, { Child: FixedChild });
|
|
40
|
-
//# sourceMappingURL=fixed.js.map
|
package/dist/fixed.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixed.js","sourceRoot":"","sources":["../src/fixed.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,aAAa,EAKb,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,EACN,QAAQ,GACX,MAAM,OAAO,CAAC;AAGf,MAAM,YAAY,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAE5E,MAAM,gBAAgB,GAAG,GAAqB,EAAE;IAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACrF,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAeF,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,SAA2C,EAAwB,EAAE,CAC5G,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAErG,MAAM,UAAU,GAAG,CAAwB,EACvC,SAAS,EACT,CAAC,EACD,CAAC,E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CAAC;AACN,CAAC,EACD,EAAE,KAAK,EAAE,UAAU,EAAE,CACxB,CAAC","sourcesContent":["import * as Graphene from \"@gtkx/gi/graphene\";\nimport * as Gsk from \"@gtkx/gi/gsk\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkFixed, type GtkFixedProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport {\n createContext,\n type ElementType,\n type ReactNode,\n type Ref,\n type RefCallback,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport type { ChildProps } from \"./types.js\";\n\nconst FixedContext = createContext<Gtk.Fixed | null | undefined>(undefined);\n\nconst useFixedInstance = (): Gtk.Fixed | null => {\n const fixed = useContext(FixedContext);\n if (fixed === undefined) throw new Error(\"<Fixed.Child> must be a child of <Fixed>\");\n return fixed;\n};\n\n/** Props for {@link Fixed}. */\nexport type FixedProps = GtkFixedProps & { ref?: Ref<Gtk.Fixed | null>; children?: ReactNode };\n\nexport type FixedPlacementProps = {\n x?: number | null | undefined;\n y?: number | null | undefined;\n /** Full transform applied to the child, overriding x and y when provided. */\n transform?: Gsk.Transform | null | undefined;\n};\n\n/** Positions a single child inside a {@link Fixed} at coordinates x and y, or by an explicit transform. */\nexport type FixedChildProps<C extends ElementType> = ChildProps<C, FixedPlacementProps>;\n\nconst transformOf = (x: number, y: number, transform: Gsk.Transform | null | undefined): Gsk.Transform | null =>\n transform !== undefined ? transform : Gsk.Transform.new().translate(Graphene.Point.create(x, y));\n\nconst FixedChild = <C extends ElementType>({\n component,\n x,\n y,\n transform,\n ref,\n ...rest\n}: FixedChildProps<C>): ReactNode => {\n const fixed = useFixedInstance();\n const Component: ElementType = component;\n const widgetRef = useRef<Gtk.Widget | null>(null);\n const captureWidget = useCallback<RefCallback<Gtk.Widget>>((node) => {\n widgetRef.current = node;\n }, []);\n const setWidget = useMergeRefs<Gtk.Widget>(ref, captureWidget);\n\n useLayoutEffect(() => {\n const widget = widgetRef.current;\n if (widget === null || fixed === null) return;\n fixed.setChildTransform(widget, transformOf(x ?? 0, y ?? 0, transform));\n });\n\n return <Component {...rest} ref={setWidget} />;\n};\n\n/**\n * Renders a Gtk.Fixed container whose children are placed at explicit positions via\n * {@link Fixed.Child}.\n */\nexport const Fixed: ((props: FixedProps) => ReactNode) & {\n Child: <C extends ElementType>(props: FixedChildProps<C>) => ReactNode;\n} = Object.assign(\n ({ children, ref, ...rest }: FixedProps): ReactNode => {\n const [fixed, setFixed] = useState<Gtk.Fixed | null>(null);\n const mergedRef = useMergeRefs<Gtk.Fixed>(ref, setFixed);\n return (\n <GtkFixed {...rest} ref={mergedRef}>\n <FixedContext.Provider value={fixed}>{children}</FixedContext.Provider>\n </GtkFixed>\n );\n },\n { Child: FixedChild },\n);\n"]}
|
package/dist/grid.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type GtkGridProps } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { type ElementType, type ReactNode, type Ref } from "react";
|
|
4
|
-
import type { ChildProps } from "./types.js";
|
|
5
|
-
/** Props for {@link Grid}. */
|
|
6
|
-
export type GridProps = GtkGridProps & {
|
|
7
|
-
ref?: Ref<Gtk.Grid | null>;
|
|
8
|
-
children?: ReactNode;
|
|
9
|
-
};
|
|
10
|
-
export type GridPlacement = {
|
|
11
|
-
column?: number | null | undefined;
|
|
12
|
-
row?: number | null | undefined;
|
|
13
|
-
/** Number of columns the child spans (defaults to 1). */
|
|
14
|
-
columnSpan?: number | null | undefined;
|
|
15
|
-
/** Number of rows the child spans (defaults to 1). */
|
|
16
|
-
rowSpan?: number | null | undefined;
|
|
17
|
-
};
|
|
18
|
-
/** Places a single child inside a {@link Grid} at a column and row, optionally spanning multiple cells. */
|
|
19
|
-
export type GridChildProps<C extends ElementType> = ChildProps<C, GridPlacement>;
|
|
20
|
-
/**
|
|
21
|
-
* Renders a Gtk.Grid whose children are attached at explicit column/row positions via
|
|
22
|
-
* {@link Grid.Child}.
|
|
23
|
-
*/
|
|
24
|
-
export declare const Grid: ((props: GridProps) => ReactNode) & {
|
|
25
|
-
Child: <C extends ElementType>(props: GridChildProps<C>) => ReactNode;
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=grid.d.ts.map
|
package/dist/grid.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../src/grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAY,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAU,MAAM,OAAO,CAAC;AAErF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7C,8BAA8B;AAC9B,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,aAAa,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAChC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC,CAAC;AAEF,2GAA2G;AAC3G,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;AA6CjF;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC,GAAG;IACnD,KAAK,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;CAazE,CAAC"}
|
package/dist/grid.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { GtkGrid } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { useMergeRefs } from "@gtkx/react/internal";
|
|
4
|
-
import { Children, useRef } from "react";
|
|
5
|
-
import { createParentContext, usePlacedChild } from "./hooks/use-placed-child.js";
|
|
6
|
-
const { Context: GridContext, useParentRef: useGridRef } = createParentContext("<Grid.Child> must be a child of <Grid>");
|
|
7
|
-
const placementOf = (props) => ({
|
|
8
|
-
column: props.column ?? 0,
|
|
9
|
-
row: props.row ?? 0,
|
|
10
|
-
columnSpan: props.columnSpan ?? 1,
|
|
11
|
-
rowSpan: props.rowSpan ?? 1,
|
|
12
|
-
});
|
|
13
|
-
const samePlacement = (a, b) => a.column === b.column && a.row === b.row && a.columnSpan === b.columnSpan && a.rowSpan === b.rowSpan;
|
|
14
|
-
const GridChild = ({ component, column, row, columnSpan, rowSpan, ref, ...rest }) => {
|
|
15
|
-
const gridRef = useGridRef();
|
|
16
|
-
const Component = component;
|
|
17
|
-
return usePlacedChild({
|
|
18
|
-
render: (placeRef) => _jsx(Component, { ...rest, ref: placeRef }),
|
|
19
|
-
ref,
|
|
20
|
-
placement: placementOf({ column, row, columnSpan, rowSpan }),
|
|
21
|
-
samePlacement,
|
|
22
|
-
place: (widget, placement, previous) => {
|
|
23
|
-
const grid = gridRef.current;
|
|
24
|
-
if (!grid)
|
|
25
|
-
return;
|
|
26
|
-
if (previous !== undefined && widget.getParent() === grid)
|
|
27
|
-
grid.remove(widget);
|
|
28
|
-
if (widget.getParent() !== grid) {
|
|
29
|
-
grid.attach(widget, placement.column, placement.row, placement.columnSpan, placement.rowSpan);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
release: (widget) => {
|
|
33
|
-
const grid = gridRef.current;
|
|
34
|
-
if (grid && widget.getParent() === grid)
|
|
35
|
-
grid.remove(widget);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Renders a Gtk.Grid whose children are attached at explicit column/row positions via
|
|
41
|
-
* {@link Grid.Child}.
|
|
42
|
-
*/
|
|
43
|
-
export const Grid = Object.assign(({ children, ref, ...rest }) => {
|
|
44
|
-
const gridRef = useRef(null);
|
|
45
|
-
const mergedRef = useMergeRefs(ref, gridRef);
|
|
46
|
-
return (_jsxs(_Fragment, { children: [_jsx(GtkGrid, { ...rest, ref: mergedRef }), _jsx(GridContext.Provider, { value: gridRef, children: Children.toArray(children) })] }));
|
|
47
|
-
}, { Child: GridChild });
|
|
48
|
-
//# sourceMappingURL=grid.js.map
|
package/dist/grid.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grid.js","sourceRoot":"","sources":["../src/grid.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAqB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAA8C,MAAM,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGlF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAC1E,wCAAwC,CAC3C,CAAC;AAmBF,MAAM,WAAW,GAAG,CAAC,KAAoB,EAAa,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC;IACzB,GAAG,EAAE,KAAK,CAAC,GAA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AAS,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;YAClG,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;YAChB,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;YAC7B,IAAI,IAAI,IAAI,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjE,CAAC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAEb,MAAM,CAAC,MAAM,CACb,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,EAAa,EAAa,EAAE;IACjD,MAAM,OAAO,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,YAAY,CAAW,GAAG,EAAE,OAAO,CAAC,CAAC;IACvD,OAAO,CACH,8BACI,KAAC,OAAO,OAAK,IAAI,EAAE,GAAG,EAAE,SAAS,GAAI,EACrC,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAwB,IAC1F,CACN,CAAC;AACN,CAAC,EACD,EAAE,KAAK,EAAE,SAAS,EAAE,CACvB,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkGrid, type GtkGridProps } from \"@gtkx/jsx/gtk\";\nimport { useMergeRefs } from \"@gtkx/react/internal\";\nimport { Children, type ElementType, type ReactNode, type Ref, useRef } from \"react\";\nimport { createParentContext, usePlacedChild } from \"./hooks/use-placed-child.js\";\nimport type { ChildProps } from \"./types.js\";\n\nconst { Context: GridContext, useParentRef: useGridRef } = createParentContext<Gtk.Grid>(\n \"<Grid.Child> must be a child of <Grid>\",\n);\n\n/** Props for {@link Grid}. */\nexport type GridProps = GtkGridProps & { ref?: Ref<Gtk.Grid | null>; children?: ReactNode };\n\nexport type GridPlacement = {\n column?: number | null | undefined;\n row?: number | null | undefined;\n /** Number of columns the child spans (defaults to 1). */\n columnSpan?: number | null | undefined;\n /** Number of rows the child spans (defaults to 1). */\n rowSpan?: number | null | undefined;\n};\n\n/** Places a single child inside a {@link Grid} at a column and row, optionally spanning multiple cells. */\nexport type GridChildProps<C extends ElementType> = ChildProps<C, GridPlacement>;\n\ntype Placement = { column: number; row: number; columnSpan: number; rowSpan: number };\n\nconst placementOf = (props: GridPlacement): Placement => ({\n column: props.column ?? 0,\n row: props.row ?? 0,\n columnSpan: props.columnSpan ?? 1,\n rowSpan: props.rowSpan ?? 1,\n});\n\nconst samePlacement = (a: Placement, b: Placement): boolean =>\n a.column === b.column && a.row === b.row && a.columnSpan === b.columnSpan && a.rowSpan === b.rowSpan;\n\nconst GridChild = <C extends ElementType>({\n component,\n column,\n row,\n columnSpan,\n rowSpan,\n ref,\n ...rest\n}: GridChildProps<C>): ReactNode => {\n const gridRef = useGridRef();\n const Component: ElementType = component;\n return usePlacedChild<Gtk.Widget, Placement>({\n render: (placeRef) => <Component {...rest} ref={placeRef} />,\n ref,\n placement: placementOf({ column, row, columnSpan, rowSpan }),\n samePlacement,\n place: (widget, placement, previous) => {\n const grid = gridRef.current;\n if (!grid) return;\n if (previous !== undefined && widget.getParent() === grid) grid.remove(widget);\n if (widget.getParent() !== grid) {\n grid.attach(widget, placement.column, placement.row, placement.columnSpan, placement.rowSpan);\n }\n },\n release: (widget) => {\n const grid = gridRef.current;\n if (grid && widget.getParent() === grid) grid.remove(widget);\n },\n });\n};\n\n/**\n * Renders a Gtk.Grid whose children are attached at explicit column/row positions via\n * {@link Grid.Child}.\n */\nexport const Grid: ((props: GridProps) => ReactNode) & {\n Child: <C extends ElementType>(props: GridChildProps<C>) => ReactNode;\n} = Object.assign(\n ({ children, ref, ...rest }: GridProps): ReactNode => {\n const gridRef = useRef<Gtk.Grid | null>(null);\n const mergedRef = useMergeRefs<Gtk.Grid>(ref, gridRef);\n return (\n <>\n <GtkGrid {...rest} ref={mergedRef} />\n <GridContext.Provider value={gridRef}>{Children.toArray(children)}</GridContext.Provider>\n </>\n );\n },\n { Child: GridChild },\n);\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
-
import { type ObjectProp } from "@gtkx/react/internal";
|
|
4
|
-
import { CellContainerStore } from "../utils/cell-container-store.js";
|
|
5
|
-
export type FactoryInstaller<W extends GObject.Object> = {
|
|
6
|
-
install(widget: W, factory: Gtk.SignalListItemFactory): void;
|
|
7
|
-
uninstall(widget: W): void;
|
|
8
|
-
};
|
|
9
|
-
export declare const makeFactoryInstaller: <W extends GObject.Object>(setFactory: (widget: W, factory: Gtk.SignalListItemFactory | null) => void) => FactoryInstaller<W>;
|
|
10
|
-
type CellContainersOptions<W extends GObject.Object> = {
|
|
11
|
-
object: ObjectProp<W>;
|
|
12
|
-
installer: FactoryInstaller<W>;
|
|
13
|
-
estimatedHeight?: number | undefined;
|
|
14
|
-
estimatedWidth?: number | undefined;
|
|
15
|
-
};
|
|
16
|
-
export declare const useCellContainers: <W extends GObject.Object>(options: CellContainersOptions<W>) => CellContainerStore;
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=use-cell-containers.d.ts.map
|