@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
package/src/types.ts
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
GtkColumnViewColumnProps,
|
|
4
|
+
GtkColumnViewProps,
|
|
5
|
+
GtkDropDownProps,
|
|
6
|
+
GtkGridViewProps,
|
|
7
|
+
GtkListViewProps,
|
|
8
|
+
} from "@gtkx/jsx/gtk";
|
|
9
|
+
import type { ComponentPropsWithRef, ElementType, ReactNode, Ref } from "react";
|
|
3
10
|
|
|
4
|
-
/** Props of a container's Child component: the widget to render
|
|
5
|
-
|
|
11
|
+
/** Props of a container's Child component: the widget to render and its own props. */
|
|
12
|
+
type ChildProps<C extends ElementType> = {
|
|
6
13
|
component: C;
|
|
7
|
-
} &
|
|
8
|
-
|
|
9
|
-
/** Props of a component whose backing widget defaults to one type but can be swapped through `component`. */
|
|
10
|
-
export type WidgetProps<C extends ElementType, Own = unknown, ExtraOmit extends string = never> = Own & {
|
|
11
|
-
component?: C;
|
|
12
|
-
} & Omit<ComponentPropsWithRef<C>, ExtraOmit | keyof Own>;
|
|
14
|
+
} & ComponentPropsWithRef<C>;
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* A single item in a collection model, identified by a stable id and holding an
|
|
16
18
|
* arbitrary value. Nested items form a tree.
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
type Item<T = unknown> = {
|
|
19
21
|
/** Stable identifier used to track the item across updates and selection. */
|
|
20
22
|
id: string;
|
|
21
23
|
value: T;
|
|
22
|
-
children?:
|
|
24
|
+
children?: Item<T>[] | undefined;
|
|
23
25
|
/** Hides the tree expander arrow even when the item has children. */
|
|
24
26
|
hideExpander?: boolean | undefined;
|
|
25
27
|
/** Adds indentation matching the item's depth in the tree. */
|
|
@@ -29,16 +31,16 @@ export type ItemNode<T = unknown> = {
|
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
/** A group of items rendered under a shared section header. */
|
|
32
|
-
|
|
34
|
+
type Section<S = unknown, T = unknown> = {
|
|
33
35
|
/** Stable identifier used to track the section across updates. */
|
|
34
36
|
id: string;
|
|
35
37
|
value: S;
|
|
36
38
|
/** Items belonging to this section. */
|
|
37
|
-
data:
|
|
39
|
+
data: Item<T>[];
|
|
38
40
|
};
|
|
39
41
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
+
/** Arguments passed to an {@link ItemRenderer} when rendering one cell. */
|
|
43
|
+
type RenderItemArgs<T> = {
|
|
42
44
|
item: T;
|
|
43
45
|
index: number;
|
|
44
46
|
/** Depth of the item within a tree, starting at zero for top-level items. */
|
|
@@ -47,30 +49,158 @@ export type RenderItemProps<T> = {
|
|
|
47
49
|
isExpanded?: boolean | undefined;
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
/** Arguments passed to a {@link HeaderRenderer} when rendering one section header. */
|
|
53
|
+
type RenderHeaderArgs<S> = {
|
|
54
|
+
section: S;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Renders the contents of one cell of a collection view. */
|
|
58
|
+
type ItemRenderer<T> = (args: RenderItemArgs<T>) => ReactNode;
|
|
59
|
+
/** Renders the contents of one section header of a collection view. */
|
|
60
|
+
type HeaderRenderer<S> = (args: RenderHeaderArgs<S>) => ReactNode;
|
|
61
|
+
|
|
62
|
+
type ItemSizeProps = {
|
|
51
63
|
estimatedItemHeight?: number | undefined;
|
|
52
64
|
estimatedItemWidth?: number | undefined;
|
|
53
65
|
};
|
|
54
66
|
|
|
55
|
-
|
|
67
|
+
type SelectionProps = {
|
|
56
68
|
selectedIds?: string[] | null | undefined;
|
|
57
69
|
onSelectionChanged?: ((ids: string[]) => void) | null | undefined;
|
|
58
70
|
selectionMode?: Gtk.SelectionMode | null | undefined;
|
|
59
71
|
};
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
type ExpansionProps = {
|
|
62
74
|
expandedIds?: string[] | null | undefined;
|
|
63
75
|
onExpandedChange?: ((ids: string[]) => void) | null | undefined;
|
|
64
76
|
};
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
type SourceProps<T, S> = {
|
|
79
|
+
items?: Item<T>[] | undefined;
|
|
80
|
+
sections?: Section<S, T>[] | undefined;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** One column of a {@link ColumnView}, pairing Gtk.ColumnViewColumn props with a cell renderer. */
|
|
84
|
+
type Column<T = unknown> = Omit<GtkColumnViewColumnProps, "factory" | "sorter" | "id" | "title"> & {
|
|
85
|
+
/** Stable identifier, also used to address the column through sorting props. */
|
|
86
|
+
id: string;
|
|
87
|
+
title: string;
|
|
88
|
+
renderCell: ItemRenderer<T>;
|
|
89
|
+
/** Whether clicking the column header sorts by it. */
|
|
90
|
+
sortable?: boolean | undefined;
|
|
91
|
+
headerMenu?: ReactNode;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type ColumnViewOwnProps<T, S> = SelectionProps &
|
|
95
|
+
ExpansionProps &
|
|
96
|
+
SourceProps<T, S> &
|
|
97
|
+
Omit<ItemSizeProps, "estimatedItemWidth"> & {
|
|
98
|
+
columns: Column<T>[];
|
|
99
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
100
|
+
/** Id of the column the view is sorted by, making sorting controlled. */
|
|
101
|
+
sortColumn?: string | null | undefined;
|
|
102
|
+
sortOrder?: Gtk.SortType | null | undefined;
|
|
103
|
+
onSortChanged?: ((column: string | null, order: Gtk.SortType) => void) | null | undefined;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Props for {@link ColumnView}. Combines the underlying Gtk.ColumnView props with
|
|
108
|
+
* declarative collection props: flat items or grouped sections, controlled selection
|
|
109
|
+
* and expansion, sorting (sortColumn, sortOrder, onSortChanged), an optional section
|
|
110
|
+
* header renderer, and the columns to render.
|
|
111
|
+
*/
|
|
112
|
+
type ColumnViewProps<T = unknown, S = unknown> = Omit<
|
|
113
|
+
GtkColumnViewProps,
|
|
114
|
+
"columns" | "model" | "headerFactory" | keyof ColumnViewOwnProps<T, S>
|
|
115
|
+
> &
|
|
116
|
+
ColumnViewOwnProps<T, S>;
|
|
117
|
+
|
|
118
|
+
type DropDownOwnProps<T, S> = SourceProps<T, S> & {
|
|
119
|
+
/** Id of the currently selected item, making the selection controlled. */
|
|
120
|
+
selectedId?: string | null | undefined;
|
|
121
|
+
onSelectionChanged?: ((id: string) => void) | null | undefined;
|
|
122
|
+
renderItem?: ItemRenderer<T> | null | undefined;
|
|
123
|
+
/** Renderer for items in the open popup list, falling back to renderItem when omitted. */
|
|
124
|
+
renderListItem?: ItemRenderer<T> | null | undefined;
|
|
125
|
+
/** Renderer for section headers in the popup list. */
|
|
126
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type DropDownWidgetProps<Widget, T, S> = Omit<
|
|
130
|
+
Widget,
|
|
131
|
+
"model" | "factory" | "listFactory" | "headerFactory" | keyof DropDownOwnProps<T, S>
|
|
132
|
+
> &
|
|
133
|
+
DropDownOwnProps<T, S>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Props for {@link DropDown}. Combines the underlying Gtk.DropDown props with the declarative
|
|
137
|
+
* collection props: flat items or grouped sections, controlled single selection, and renderers
|
|
138
|
+
* for the collapsed display, popup rows, and popup section headers.
|
|
139
|
+
*/
|
|
140
|
+
type DropDownProps<T = unknown, S = unknown> = DropDownWidgetProps<GtkDropDownProps, T, S>;
|
|
141
|
+
|
|
142
|
+
type GridViewOwnProps<T> = ItemSizeProps &
|
|
143
|
+
SelectionProps & {
|
|
144
|
+
items?: Item<T>[] | undefined;
|
|
145
|
+
renderItem: ItemRenderer<T>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Props for {@link GridView}. Combines the underlying Gtk.GridView props with
|
|
150
|
+
* declarative collection props: items, a per-cell renderItem, controlled selection,
|
|
151
|
+
* and estimated item sizing.
|
|
152
|
+
*/
|
|
153
|
+
type GridViewProps<T = unknown> = Omit<GtkGridViewProps, "model" | "factory" | keyof GridViewOwnProps<T>> &
|
|
154
|
+
GridViewOwnProps<T>;
|
|
155
|
+
|
|
156
|
+
type ListViewOwnProps<T, S> = ItemSizeProps &
|
|
157
|
+
SelectionProps &
|
|
158
|
+
ExpansionProps &
|
|
159
|
+
SourceProps<T, S> & {
|
|
160
|
+
renderItem: ItemRenderer<T>;
|
|
161
|
+
renderHeader?: HeaderRenderer<S> | null | undefined;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Props for {@link ListView}. Combines the underlying Gtk.ListView props with
|
|
166
|
+
* declarative collection props: flat items or grouped sections, a per-row renderItem,
|
|
167
|
+
* an optional section header renderer, controlled selection and expansion, and
|
|
168
|
+
* estimated item sizing.
|
|
169
|
+
*/
|
|
170
|
+
type ListViewProps<T = unknown, S = unknown> = Omit<
|
|
171
|
+
GtkListViewProps,
|
|
172
|
+
"model" | "factory" | "headerFactory" | keyof ListViewOwnProps<T, S>
|
|
173
|
+
> &
|
|
174
|
+
ListViewOwnProps<T, S>;
|
|
175
|
+
|
|
176
|
+
/** Props for {@link SizeGroup}. */
|
|
177
|
+
type SizeGroupProps = {
|
|
178
|
+
/** How the group equalizes sizes: horizontal, vertical, or both. */
|
|
179
|
+
mode?: Gtk.SizeGroupMode | null | undefined;
|
|
180
|
+
ref?: Ref<Gtk.SizeGroup | null>;
|
|
181
|
+
children?: ReactNode;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** Adds a single widget, rendered by the given component, to the enclosing {@link SizeGroup}. */
|
|
185
|
+
type SizeGroupChildProps<C extends ElementType> = ChildProps<C>;
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
type SelectionProps,
|
|
189
|
+
type ExpansionProps,
|
|
190
|
+
type ChildProps,
|
|
191
|
+
type DropDownOwnProps,
|
|
192
|
+
type DropDownWidgetProps,
|
|
193
|
+
type Item,
|
|
194
|
+
type Section,
|
|
195
|
+
type RenderItemArgs,
|
|
196
|
+
type RenderHeaderArgs,
|
|
197
|
+
type ItemRenderer,
|
|
198
|
+
type HeaderRenderer,
|
|
199
|
+
type Column,
|
|
200
|
+
type ColumnViewProps,
|
|
201
|
+
type DropDownProps,
|
|
202
|
+
type GridViewProps,
|
|
203
|
+
type ListViewProps,
|
|
204
|
+
type SizeGroupProps,
|
|
205
|
+
type SizeGroupChildProps,
|
|
76
206
|
};
|
package/dist/cell.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type ReactNode } from "react";
|
|
3
|
-
import type { RenderItemProps } from "./types.js";
|
|
4
|
-
import type { CellContainerStore } from "./utils/cell-container-store.js";
|
|
5
|
-
import type { ItemResolver } from "./utils/item-resolver.js";
|
|
6
|
-
export type CellRenderer<T, S> = (value: T | S | undefined, treeRow: Gtk.TreeListRow | null, position: number) => ReactNode;
|
|
7
|
-
interface CellRenderHostProps<T, S> {
|
|
8
|
-
store: CellContainerStore;
|
|
9
|
-
resolver: ItemResolver<T, S>;
|
|
10
|
-
render: CellRenderer<T, S>;
|
|
11
|
-
}
|
|
12
|
-
export declare const CellRenderHost: <T, S>({ store, resolver, render }: CellRenderHostProps<T, S>) => ReactNode;
|
|
13
|
-
export type TreeRenderContext = {
|
|
14
|
-
controlled: boolean;
|
|
15
|
-
expandedIds: Set<string>;
|
|
16
|
-
rowId: (row: Gtk.TreeListRow) => string | undefined;
|
|
17
|
-
};
|
|
18
|
-
export declare const createTreeRenderContext: (expandedIds: string[] | null | undefined, rowId: (row: Gtk.TreeListRow) => string | undefined) => TreeRenderContext;
|
|
19
|
-
export declare const itemRenderer: <T, S>(render: (props: RenderItemProps<T>) => ReactNode, context?: TreeRenderContext) => CellRenderer<T, S>;
|
|
20
|
-
interface HeaderRenderHostProps<T, S> {
|
|
21
|
-
useHeader: boolean;
|
|
22
|
-
store: CellContainerStore;
|
|
23
|
-
resolver: ItemResolver<T, S>;
|
|
24
|
-
renderHeader: ((info: {
|
|
25
|
-
section: S;
|
|
26
|
-
}) => ReactNode) | null | undefined;
|
|
27
|
-
}
|
|
28
|
-
export declare const HeaderRenderHost: <T, S>({ useHeader, store, resolver, renderHeader, }: HeaderRenderHostProps<T, S>) => ReactNode;
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=cell.d.ts.map
|
package/dist/cell.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../src/cell.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAkB,KAAK,SAAS,EAAqC,MAAM,OAAO,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAa,MAAM,iCAAiC,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,CAC7B,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,EACxB,OAAO,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,EAC/B,QAAQ,EAAE,MAAM,KACf,SAAS,CAAC;AASf,UAAU,mBAAmB,CAAC,CAAC,EAAE,CAAC;IAC9B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC9B;AA4CD,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,+BAA+B,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,SAmB7F,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC;CACvD,CAAC;AAEF,eAAO,MAAM,uBAAuB,gBACnB,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,SACjC,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,KAAK,MAAM,GAAG,SAAS,KACpD,iBAID,CAAC;AAeH,eAAO,MAAM,YAAY,GACpB,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,SAAS,YAAY,iBAAiB,KAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAEtB,CAAC;AAOvF,UAAU,qBAAqB,CAAC,CAAC,EAAE,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,YAAY,EAAE,CAAC,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,KAAK,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1E;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,iDAKlC,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,SACsF,CAAC"}
|
package/dist/cell.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { GtkTreeExpander } from "@gtkx/jsx/gtk";
|
|
3
|
-
import { createPortal } from "@gtkx/react";
|
|
4
|
-
import { Fragment, memo, useCallback, useSyncExternalStore } from "react";
|
|
5
|
-
const TreeExpanderCell = ({ treeRow, metadata, children }) => (_jsx(GtkTreeExpander, { ref: (expander) => {
|
|
6
|
-
if (expander !== null)
|
|
7
|
-
expander.setListRow(treeRow);
|
|
8
|
-
}, hideExpander: metadata.hideExpander, indentForDepth: metadata.indentForDepth, indentForIcon: metadata.indentForIcon, children: children }));
|
|
9
|
-
const Cell = memo(({ container, store, resolver, render }) => {
|
|
10
|
-
const subscribe = useCallback((onChange) => store.subscribePosition(container, onChange), [store, container]);
|
|
11
|
-
const getSnapshot = useCallback(() => store.getPosition(container), [store, container]);
|
|
12
|
-
const entry = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
13
|
-
if (entry.position < 0)
|
|
14
|
-
return null;
|
|
15
|
-
const resolved = resolver.resolve(entry.position, entry.treeRow);
|
|
16
|
-
if (!resolved.present)
|
|
17
|
-
return null;
|
|
18
|
-
const content = render(resolved.value, entry.treeRow, entry.position);
|
|
19
|
-
const portalled = entry.treeRow !== null && !resolved.isHeader ? (_jsx(TreeExpanderCell, { treeRow: entry.treeRow, metadata: resolved.metadata, children: content })) : (content);
|
|
20
|
-
return createPortal(portalled, container, store.keyFor(container));
|
|
21
|
-
});
|
|
22
|
-
export const CellRenderHost = ({ store, resolver, render }) => {
|
|
23
|
-
const containers = useSyncExternalStore(store.subscribeSet, store.getContainersSnapshot, store.getContainersSnapshot);
|
|
24
|
-
return (_jsx(Fragment, { children: containers.map((container) => (_jsx(Cell, { container: container, store: store, resolver: resolver, render: render }, store.keyFor(container)))) }));
|
|
25
|
-
};
|
|
26
|
-
export const createTreeRenderContext = (expandedIds, rowId) => ({
|
|
27
|
-
controlled: expandedIds !== undefined && expandedIds !== null,
|
|
28
|
-
expandedIds: new Set(expandedIds ?? []),
|
|
29
|
-
rowId,
|
|
30
|
-
});
|
|
31
|
-
const treeFields = (treeRow, context) => {
|
|
32
|
-
if (treeRow === null)
|
|
33
|
-
return {};
|
|
34
|
-
const depth = treeRow.getDepth();
|
|
35
|
-
if (context === undefined || !treeRow.isExpandable())
|
|
36
|
-
return { depth };
|
|
37
|
-
const isExpanded = context.controlled
|
|
38
|
-
? context.expandedIds.has(context.rowId(treeRow) ?? "")
|
|
39
|
-
: treeRow.getExpanded();
|
|
40
|
-
return { depth, isExpanded };
|
|
41
|
-
};
|
|
42
|
-
export const itemRenderer = (render, context) => (value, treeRow, position) => render({ item: value, index: position, ...treeFields(treeRow, context) });
|
|
43
|
-
const headerRenderer = (renderHeader) => (value) => renderHeader ? renderHeader({ section: value }) : null;
|
|
44
|
-
export const HeaderRenderHost = ({ useHeader, store, resolver, renderHeader, }) => useHeader ? _jsx(CellRenderHost, { store: store, resolver: resolver, render: headerRenderer(renderHeader) }) : null;
|
|
45
|
-
//# sourceMappingURL=cell.js.map
|
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,EAAE,QAAQ,EAAyB,EAAa,EAAE,CAAC,CAC5F,KAAC,eAAe,IACZ,GAAG,EAAE,CAAC,QAAiC,EAAE,EAAE;QACvC,IAAI,QAAQ,KAAK,IAAI;YAAE,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC,EACD,YAAY,EAAE,QAAQ,CAAC,YAAY,EACnC,cAAc,EAAE,QAAQ,CAAC,cAAc,EACvC,aAAa,EAAE,QAAQ,CAAC,aAAa,YAEpC,QAAQ,GACK,CACrB,CAAC;AAEF,MAAM,IAAI,GAAG,IAAI,CAAC,CAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAmB,EAAa,EAAE;IAC3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D,EAAE,OAA2B,EAAsB,EAAE,CAC5G,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,CACzB,MAAM,CAAC,EAAE,IAAI,EAAE,KAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAEvF,MAAM,cAAc,GAChB,CAAO,YAAsE,EAAsB,EAAE,CACrG,CAAC,KAAK,EAAE,EAAE,CACN,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,KAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AASpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAO,EACnC,SAAS,EACT,KAAK,EACL,QAAQ,EACR,YAAY,GACc,EAAa,EAAE,CACzC,SAAS,CAAC,CAAC,CAAC,KAAC,cAAc,IAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAO,YAAY,CAAC,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC","sourcesContent":["import type * as GObject from \"@gtkx/gi/gobject\";\nimport type * as Gtk from \"@gtkx/gi/gtk\";\nimport { GtkTreeExpander } from \"@gtkx/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":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAuB,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEnF,OAAO,EAAE,KAAK,SAAS,EAAqC,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAmD,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGpG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IACrD,UAAU,CAAC,EAAE,SAAS,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,wBAAwB,EAAE,SAAS,GAAG,QAAQ,CAAC,GACrF,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEjC,KAAK,qBAAqB,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG;IACrD,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,IAAI,EAAE,iBAAiB,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,UAAU,EAAE,CAAC,EAAE,EAAE,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,EA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C,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,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,gEAAgE;IAChE,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,GAAG,CAAC,kBAAkB,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,6EAA6E;IAC7E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AA8DF,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,IAAI,CAqBhG;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAa5F;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAkBhG"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import * as GObject from "@gtkx/gi/gobject";
|
|
2
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
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.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;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"}
|