@gopherium/godmin 0.15.0 → 0.16.0

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.
@@ -0,0 +1,114 @@
1
+ /** The direction the rows of a list are sorted in. */
2
+ export type ListSortDirection = 'asc' | 'desc';
3
+ /** A filter narrowing the rows of a list, as a DataViews view holds it. */
4
+ export interface ListFilter {
5
+ /** The field the filter reads. */
6
+ field: string;
7
+ /** How the field is compared, such as isAny. */
8
+ operator: string;
9
+ /** The value the field is compared with. */
10
+ value?: unknown;
11
+ }
12
+ /** The parts of a list view the hook reads and writes, as a DataViews view holds them. */
13
+ export interface ListViewShape {
14
+ /** The layout the list is drawn in. */
15
+ type: string;
16
+ /** The words the list is searched for. */
17
+ search?: string;
18
+ /** The filters narrowing the rows. */
19
+ filters?: ListFilter[];
20
+ /** The field and direction the rows are sorted by. */
21
+ sort?: {
22
+ field: string;
23
+ direction: ListSortDirection;
24
+ };
25
+ /** The page shown, counted from one. */
26
+ page?: number;
27
+ /** How many rows a page holds. */
28
+ perPage?: number;
29
+ /** The fields shown beside the title. */
30
+ fields?: string[];
31
+ }
32
+ /** The part of a list view the address carries. */
33
+ export interface ListSearch {
34
+ /** The words the list is searched for. */
35
+ search?: string;
36
+ /** The page shown, counted from one. */
37
+ page?: number;
38
+ /** How many rows a page holds. */
39
+ perPage?: number;
40
+ /** The field the rows are sorted by. */
41
+ sort?: string;
42
+ /** The direction the rows are sorted in. */
43
+ order?: ListSortDirection;
44
+ /** The filters narrowing the rows. */
45
+ filters?: ListFilter[];
46
+ }
47
+ /** What one layout opens on, as DataViews takes it for each of its layouts. */
48
+ export interface LayoutDefaults {
49
+ /** The fields the layout shows, over the list fields. */
50
+ fields?: string[];
51
+ /** The settings of the layout, such as the preview size of a grid. */
52
+ layout?: Record<string, unknown>;
53
+ }
54
+ /** What a list opens on when the address says nothing. */
55
+ export interface ListDefaults {
56
+ /** The fields shown beside the title. */
57
+ fields: string[];
58
+ /** The fields the phone layout shows beside the title, the list fields when absent. */
59
+ phoneFields?: string[];
60
+ /** The field that links to the record. */
61
+ titleField?: string;
62
+ /** The field shown under the title, none when absent. */
63
+ descriptionField?: string;
64
+ /** The field drawn before the title, such as an avatar, none when absent. */
65
+ mediaField?: string;
66
+ /** The order a list opens in. */
67
+ sort: {
68
+ field: string;
69
+ direction: ListSortDirection;
70
+ };
71
+ /** How many rows a page holds when the address names none, every row while it is unknown. */
72
+ perPage?: number;
73
+ /** The one layout offered from 640px and the one below it, table and list when absent. */
74
+ layouts?: {
75
+ wide: string;
76
+ phone: string;
77
+ };
78
+ /** What each layout opens on, such as the preview size of a grid. */
79
+ layoutSettings?: Record<string, LayoutDefaults>;
80
+ }
81
+ /** The view the address holds beside the controls DataViews takes. */
82
+ export interface ListView<V extends ListViewShape> {
83
+ /** The view the address holds, laid out for the viewport. */
84
+ view: V;
85
+ /** Writes a changed view into the address, holding the parts it leaves out in memory. */
86
+ onChangeView: (view: V) => void;
87
+ /** The one layout the viewport takes, with what it opens on. */
88
+ defaultLayouts: Record<string, LayoutDefaults>;
89
+ /** The rows ticked in the wide layout, always none in the phone layout. */
90
+ selection: string[];
91
+ /** Holds the rows ticked in the wide layout, and drops the tap the phone layout reports. */
92
+ onChangeSelection: (selection: string[]) => void;
93
+ /** Whether the viewport takes the phone layout. */
94
+ phone: boolean;
95
+ }
96
+ /**
97
+ * Keeps the parts of a list view an address may carry, dropping anything malformed.
98
+ * @param raw - The search the router parsed from the address.
99
+ * @returns The list search.
100
+ */
101
+ export declare function listSearch(raw: Record<string, unknown>): ListSearch;
102
+ /**
103
+ * Holds a list view in the address, one layout per side of the phone breakpoint, and its columns in memory.
104
+ * @param defaults - What the list opens on.
105
+ * @returns The view beside the controls DataViews takes.
106
+ */
107
+ export declare function useListView<V extends ListViewShape>(defaults: ListDefaults): ListView<V>;
108
+ /**
109
+ * Returns the selection handler a list hands DataViews, opening the record a tap lands on in the phone layout.
110
+ * @param list - The list view the screen holds.
111
+ * @param open - Opens the record with the given id.
112
+ * @returns The handler.
113
+ */
114
+ export declare function openOnTap<V extends ListViewShape>(list: ListView<V>, open: (id: string) => void): (selection: string[]) => void;
@@ -0,0 +1,246 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useMatch, useNavigate, useSearch } from '@tanstack/react-router';
3
+ import { useState } from 'react';
4
+ import { DENSE_BREAKPOINT } from './breakpoints.js';
5
+ import { useMediaQuery } from './use-media-query.js';
6
+ /** The layouts a list takes when it names none. */
7
+ const TABLE_AND_LIST = { wide: 'table', phone: 'list' };
8
+ /** The selection a list opens on and the one a phone layout always holds. */
9
+ const NO_SELECTION = [];
10
+ /** The selection of a phone layout, always none and never changed. */
11
+ const INERT = { selection: NO_SELECTION, onChangeSelection: () => { } };
12
+ /** The viewports that take the phone layout. */
13
+ const PHONE_QUERY = `(max-width: ${DENSE_BREAKPOINT - 1}px)`;
14
+ /** The parts of a view the address or the viewport decides. */
15
+ const ADDRESSED = new Set(['type', 'search', 'filters', 'sort', 'page', 'perPage']);
16
+ /** The address keys a list view owns. */
17
+ const LIST_KEYS = new Set(['search', 'page', 'perPage', 'sort', 'order', 'filters']);
18
+ /** The shape each side holds before a reader changes one. */
19
+ const NO_SHAPES = { wide: {}, phone: {} };
20
+ /**
21
+ * Returns the part of a view the address leaves out.
22
+ * @param view - The view the list shows.
23
+ * @returns The columns, layout settings and every other part the reader changed.
24
+ */
25
+ function shapeOf(view) {
26
+ return Object.fromEntries(Object.entries(view).filter(([key]) => !ADDRESSED.has(key)));
27
+ }
28
+ /**
29
+ * Returns the value when it is a whole number above zero.
30
+ * @param value - The raw address value.
31
+ * @returns The number, or undefined.
32
+ */
33
+ function positive(value) {
34
+ return Number.isInteger(value) && value > 0 ? value : undefined;
35
+ }
36
+ /**
37
+ * Returns the value when it is a string holding something.
38
+ * @param value - The raw address value.
39
+ * @returns The string, or undefined.
40
+ */
41
+ function filled(value) {
42
+ return typeof value === 'string' && value !== '' ? value : undefined;
43
+ }
44
+ /**
45
+ * Returns the value when it names a sort direction.
46
+ * @param value - The raw address value.
47
+ * @returns The direction, or undefined.
48
+ */
49
+ function direction(value) {
50
+ return value === 'asc' || value === 'desc' ? value : undefined;
51
+ }
52
+ /**
53
+ * Reports whether one raw entry is a filter a list can apply.
54
+ * @param entry - One raw entry of the address filters.
55
+ * @returns Whether it names a field and an operator.
56
+ */
57
+ function isFilter(entry) {
58
+ const held = entry;
59
+ return typeof held?.field === 'string' && typeof held.operator === 'string';
60
+ }
61
+ /**
62
+ * Returns the filters an address value holds, keeping only the ones a list can apply.
63
+ * @param value - The raw address value.
64
+ * @returns The filters, or undefined when none remain.
65
+ */
66
+ function filtersOf(value) {
67
+ if (!Array.isArray(value)) {
68
+ return undefined;
69
+ }
70
+ const kept = value.filter(isFilter).map(({ field, operator, value: chosen }) => ({ field, operator, value: chosen }));
71
+ return kept.length > 0 ? kept : undefined;
72
+ }
73
+ /**
74
+ * Returns the search without its undefined entries.
75
+ * @param search - The search with possibly undefined entries.
76
+ * @returns The search holding only what was set.
77
+ */
78
+ function withoutGaps(search) {
79
+ return Object.fromEntries(Object.entries(search).filter(([, value]) => value !== undefined));
80
+ }
81
+ /**
82
+ * Keeps the parts of a list view an address may carry, dropping anything malformed.
83
+ * @param raw - The search the router parsed from the address.
84
+ * @returns The list search.
85
+ */
86
+ export function listSearch(raw) {
87
+ return withoutGaps({
88
+ search: filled(raw.search),
89
+ page: positive(raw.page),
90
+ perPage: positive(raw.perPage),
91
+ sort: filled(raw.sort),
92
+ order: direction(raw.order),
93
+ filters: filtersOf(raw.filters),
94
+ });
95
+ }
96
+ /**
97
+ * Returns what a layout opens on.
98
+ * @param defaults - What the list opens on.
99
+ * @param layout - The layout the viewport takes.
100
+ * @returns The fields and settings the list names for the layout, or nothing.
101
+ */
102
+ function settingsOf(defaults, layout) {
103
+ return defaults.layoutSettings?.[layout] ?? {};
104
+ }
105
+ /**
106
+ * Returns the fields a list opens on beside the title on one side of the phone breakpoint.
107
+ * @param defaults - What the list opens on.
108
+ * @param side - The side the viewport sits on.
109
+ * @returns The fields shown beside the title.
110
+ */
111
+ function fieldsFor(defaults, side) {
112
+ return side === 'phone' ? (defaults.phoneFields ?? defaults.fields) : defaults.fields;
113
+ }
114
+ /**
115
+ * Builds the view a list shows from its address, the reader's other changes and its defaults.
116
+ * @param search - The list search the address carries.
117
+ * @param defaults - What the list opens on.
118
+ * @param shape - The part of the view the reader changed that the address leaves out.
119
+ * @param side - The side of the phone breakpoint the viewport sits on.
120
+ * @param layout - The layout the viewport takes.
121
+ * @returns The view.
122
+ */
123
+ function viewOf(search, defaults, shape, side, layout) {
124
+ return {
125
+ fields: fieldsFor(defaults, side),
126
+ titleField: defaults.titleField,
127
+ descriptionField: defaults.descriptionField,
128
+ mediaField: defaults.mediaField,
129
+ ...settingsOf(defaults, layout),
130
+ ...shape,
131
+ type: layout,
132
+ search: search.search ?? '',
133
+ filters: search.filters ?? [],
134
+ sort: { field: search.sort ?? defaults.sort.field, direction: search.order ?? defaults.sort.direction },
135
+ page: search.page ?? 1,
136
+ perPage: search.perPage ?? defaults.perPage,
137
+ };
138
+ }
139
+ /**
140
+ * Returns the value unless it matches what the list opens on.
141
+ * @param value - The value the view holds.
142
+ * @param opening - The value the list opens on.
143
+ * @returns The value, or undefined when it is the opening one.
144
+ */
145
+ function unlessOpening(value, opening) {
146
+ return value === opening ? undefined : value;
147
+ }
148
+ /**
149
+ * Builds the address search a view is written to, leaving out what matches the defaults.
150
+ * @param view - The view the list shows.
151
+ * @param defaults - What the list opens on.
152
+ * @returns The list search.
153
+ */
154
+ function searchOf(view, defaults) {
155
+ const sort = view.sort ?? defaults.sort;
156
+ return withoutGaps({
157
+ search: filled(view.search),
158
+ page: unlessOpening(view.page, 1),
159
+ perPage: unlessOpening(view.perPage, defaults.perPage),
160
+ sort: unlessOpening(sort.field, defaults.sort.field),
161
+ order: unlessOpening(sort.direction, defaults.sort.direction),
162
+ filters: filtersOf(view.filters),
163
+ });
164
+ }
165
+ /**
166
+ * Returns the address search without the keys a list view owns.
167
+ * @param held - The search the address holds.
168
+ * @returns The choices of the screen around the list.
169
+ */
170
+ function besideList(held) {
171
+ return Object.fromEntries(Object.entries(held).filter(([key]) => !LIST_KEYS.has(key)));
172
+ }
173
+ /**
174
+ * Holds the rows ticked in the wide layout, none on a phone, and drops them when the layout or the list changes.
175
+ * @param phone - Whether the viewport takes the phone layout.
176
+ * @param list - The address of the list the screen shows.
177
+ * @returns The selection beside the control that changes it.
178
+ */
179
+ function useSelection(phone, list) {
180
+ const [ticked, setTicked] = useState(NO_SELECTION);
181
+ const [tickedFor, setTickedFor] = useState({ phone, list });
182
+ if (tickedFor.phone !== phone || tickedFor.list !== list) {
183
+ setTickedFor({ phone, list });
184
+ setTicked(NO_SELECTION);
185
+ }
186
+ return phone ? INERT : { selection: ticked, onChangeSelection: setTicked };
187
+ }
188
+ /**
189
+ * Holds the columns a reader picked on each side of the phone breakpoint, and forgets them when the list changes.
190
+ * @param list - The address of the list the screen shows.
191
+ * @returns The picked columns beside the setter that changes them.
192
+ */
193
+ function useShapes(list) {
194
+ const [shapes, setShapes] = useState(NO_SHAPES);
195
+ const [shapedFor, setShapedFor] = useState(list);
196
+ if (shapedFor !== list) {
197
+ setShapedFor(list);
198
+ setShapes(NO_SHAPES);
199
+ }
200
+ return [shapes, setShapes];
201
+ }
202
+ /**
203
+ * Holds a list view in the address, one layout per side of the phone breakpoint, and its columns in memory.
204
+ * @param defaults - What the list opens on.
205
+ * @returns The view beside the controls DataViews takes.
206
+ */
207
+ export function useListView(defaults) {
208
+ const raw = useSearch({ strict: false });
209
+ const navigate = useNavigate();
210
+ const phone = useMediaQuery(PHONE_QUERY);
211
+ const side = phone ? 'phone' : 'wide';
212
+ const layout = (defaults.layouts ?? TABLE_AND_LIST)[side];
213
+ const list = useMatch({ strict: false, select: (match) => match.pathname });
214
+ const [shapes, setShapes] = useShapes(list);
215
+ const selection = useSelection(phone, list);
216
+ return {
217
+ view: viewOf(listSearch(raw), defaults, shapes[side], side, layout),
218
+ onChangeView: (view) => {
219
+ setShapes((held) => ({ ...held, [side]: shapeOf(view) }));
220
+ void navigate({
221
+ to: '.',
222
+ search: (held) => ({ ...besideList(held), ...searchOf(view, defaults) }),
223
+ replace: true,
224
+ });
225
+ },
226
+ defaultLayouts: { [layout]: settingsOf(defaults, layout) },
227
+ phone,
228
+ ...selection,
229
+ };
230
+ }
231
+ /**
232
+ * Returns the selection handler a list hands DataViews, opening the record a tap lands on in the phone layout.
233
+ * @param list - The list view the screen holds.
234
+ * @param open - Opens the record with the given id.
235
+ * @returns The handler.
236
+ */
237
+ export function openOnTap(list, open) {
238
+ if (!list.phone) {
239
+ return list.onChangeSelection;
240
+ }
241
+ return ([id]) => {
242
+ if (id !== undefined) {
243
+ open(id);
244
+ }
245
+ };
246
+ }
@@ -6,7 +6,7 @@ export interface PageTabsProps {
6
6
  children: ReactNode;
7
7
  }
8
8
  /**
9
- * Renders the tabs of a page as a navigation region of links.
9
+ * Renders the tabs of a page as a navigation region of links that scrolls to the current tab and fades a cut edge.
10
10
  * @param props - The navigation name and the tabs.
11
11
  * @returns The tab navigation element.
12
12
  */
package/dist/page-tabs.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { cloneElement } from 'react';
2
+ import { cloneElement, useLayoutEffect, useRef, useState } from 'react';
3
3
  /**
4
- * Renders the tabs of a page as a navigation region of links.
5
- * @param props - The navigation name and the tabs.
6
- * @returns The tab navigation element.
4
+ * The class every tab row carries.
7
5
  */
8
- export function PageTabs({ label, children }) {
9
- return (_jsx("nav", { className: "godmin-page-tabs", "aria-label": label, children: children }));
10
- }
6
+ const ROW_CLASS = 'godmin-page-tabs';
7
+ /**
8
+ * The class that fades the start edge of a tab row scrolled past its first tabs.
9
+ */
10
+ const FADES_START_CLASS = 'godmin-page-tabs--overflowing-first';
11
+ /**
12
+ * The class that fades the end edge of a tab row whose last tabs lie past it.
13
+ */
14
+ const FADES_END_CLASS = 'godmin-page-tabs--overflowing-last';
11
15
  /**
12
16
  * The class every page tab carries.
13
17
  */
@@ -16,6 +20,101 @@ const TAB_CLASS = 'godmin-page-tabs__tab';
16
20
  * The class that underlines the tab of the page on screen.
17
21
  */
18
22
  const CURRENT_CLASS = 'godmin-page-tabs__tab--current';
23
+ /**
24
+ * The scroll in pixels a tab row may sit off an edge and still rest on it, for sub-pixel rounding.
25
+ */
26
+ const SCROLL_EPSILON = 1;
27
+ /**
28
+ * Returns the classes of a tab row, fading each edge that tabs lie past.
29
+ * @param row - The tab row element.
30
+ * @returns The class list.
31
+ */
32
+ function rowClass(row) {
33
+ const travelled = Math.abs(row.scrollLeft);
34
+ const room = row.scrollWidth - row.clientWidth;
35
+ let classes = ROW_CLASS;
36
+ if (travelled > SCROLL_EPSILON) {
37
+ classes += ` ${FADES_START_CLASS}`;
38
+ }
39
+ if (travelled < room - SCROLL_EPSILON) {
40
+ classes += ` ${FADES_END_CLASS}`;
41
+ }
42
+ return classes;
43
+ }
44
+ /**
45
+ * Returns the classes of a tab row, measured again as the row scrolls, resizes or gains and loses tabs.
46
+ * @param ref - The tab row element.
47
+ * @returns The class list.
48
+ */
49
+ function useRowClass(ref) {
50
+ const [className, setClassName] = useState(ROW_CLASS);
51
+ useLayoutEffect(() => {
52
+ const row = ref.current;
53
+ const measure = () => setClassName(rowClass(row));
54
+ const resizes = new ResizeObserver(measure);
55
+ const watch = () => {
56
+ resizes.disconnect();
57
+ for (const box of [row, ...row.children]) {
58
+ resizes.observe(box);
59
+ }
60
+ measure();
61
+ };
62
+ const mutations = new MutationObserver(watch);
63
+ mutations.observe(row, { childList: true });
64
+ row.addEventListener('scroll', measure, { passive: true });
65
+ watch();
66
+ return () => {
67
+ row.removeEventListener('scroll', measure);
68
+ mutations.disconnect();
69
+ resizes.disconnect();
70
+ };
71
+ }, [ref]);
72
+ return className;
73
+ }
74
+ /**
75
+ * Scrolls a tab row the least that shows a tab whole, with the scroll margin the tab asks for.
76
+ * @param row - The tab row element.
77
+ * @param tab - The tab to show.
78
+ */
79
+ function reveal(row, tab) {
80
+ const style = getComputedStyle(tab);
81
+ const start = tab.offsetLeft - parseFloat(style.scrollMarginLeft);
82
+ const end = tab.offsetLeft + tab.offsetWidth + parseFloat(style.scrollMarginRight);
83
+ if (end > row.scrollLeft + row.clientWidth) {
84
+ row.scrollLeft = end - row.clientWidth;
85
+ }
86
+ if (start < row.scrollLeft) {
87
+ row.scrollLeft = start;
88
+ }
89
+ }
90
+ /**
91
+ * Scrolls a tab row to its current tab each time a tab becomes current, forgetting the last one while none is.
92
+ * @param ref - The tab row element.
93
+ */
94
+ function useRevealCurrent(ref) {
95
+ const shown = useRef(null);
96
+ useLayoutEffect(() => {
97
+ const row = ref.current;
98
+ const tab = row.querySelector(`.${CURRENT_CLASS}`);
99
+ const last = shown.current;
100
+ shown.current = tab;
101
+ if (tab === null || tab === last) {
102
+ return;
103
+ }
104
+ reveal(row, tab);
105
+ });
106
+ }
107
+ /**
108
+ * Renders the tabs of a page as a navigation region of links that scrolls to the current tab and fades a cut edge.
109
+ * @param props - The navigation name and the tabs.
110
+ * @returns The tab navigation element.
111
+ */
112
+ export function PageTabs({ label, children }) {
113
+ const ref = useRef(null);
114
+ useRevealCurrent(ref);
115
+ const className = useRowClass(ref);
116
+ return (_jsx("nav", { ref: ref, className: className, "aria-label": label, children: children }));
117
+ }
19
118
  /**
20
119
  * Renders one page tab as a link, marked and underlined as the current page when it leads to the page on screen.
21
120
  * @param props - The address or the link element, whether it is current, and the label.
@@ -0,0 +1,24 @@
1
+ export interface RenameBodyProps {
2
+ /** The name the item carries now, the first value of the field. */
3
+ name: string;
4
+ /** The label of the name field. */
5
+ fieldLabel: string;
6
+ /** The label of the button that writes the new name. */
7
+ submitLabel: string;
8
+ /** The label of the button that closes the modal. */
9
+ cancelLabel: string;
10
+ /** Whether the write is running, the submit button then busy and Cancel greyed out. */
11
+ busy?: boolean;
12
+ /** The failure of the last try, shown under the field. */
13
+ failure?: string;
14
+ /** Writes the name as typed. */
15
+ onSubmit: (name: string) => void;
16
+ /** Closes the modal. */
17
+ onCancel?: () => void;
18
+ }
19
+ /**
20
+ * Renders the body of a rename modal: the name field, a failure notice, a minimal Cancel and the submit button.
21
+ * @param props - The current name, the labels, the busy flag, the failure and the handlers.
22
+ * @returns The rename form.
23
+ */
24
+ export declare function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, busy, failure, onSubmit, onCancel, }: RenameBodyProps): import("react").JSX.Element;
package/dist/rename.js ADDED
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Button, InputControl, Stack } from '@wordpress/ui';
4
+ import { useState } from 'react';
5
+ import { ErrorNotice } from './page.js';
6
+ /**
7
+ * Renders the body of a rename modal: the name field, a failure notice, a minimal Cancel and the submit button.
8
+ * @param props - The current name, the labels, the busy flag, the failure and the handlers.
9
+ * @returns The rename form.
10
+ */
11
+ export function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, busy = false, failure, onSubmit, onCancel, }) {
12
+ const [value, setValue] = useState(name);
13
+ const writable = !busy && value.trim() !== '' && value !== name;
14
+ return (_jsx("form", { onSubmit: (event) => {
15
+ event.preventDefault();
16
+ if (writable) {
17
+ onSubmit(value);
18
+ }
19
+ }, children: _jsxs(Stack, { direction: "column", gap: "lg", children: [_jsx(InputControl, { label: fieldLabel, value: value, onChange: (event) => setValue(event.target.value) }), failure === undefined ? null : _jsx(ErrorNotice, { children: failure }), _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", disabled: busy, onClick: onCancel, children: cancelLabel }), _jsx(Button, { type: "submit", loading: busy, disabled: !writable, children: submitLabel })] })] }) }));
20
+ }
package/dist/router.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { CanvasMode } from './frame.js';
2
+ export { listSearch, openOnTap, useListView } from './list-view.js';
3
+ export type { LayoutDefaults, ListDefaults, ListFilter, ListSearch, ListSortDirection, ListView, ListViewShape, } from './list-view.js';
2
4
  declare module '@tanstack/react-router' {
3
5
  interface StaticDataRouteOption {
4
6
  canvas?: CanvasMode;
package/dist/router.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useRouterState } from '@tanstack/react-router';
2
+ export { listSearch, openOnTap, useListView } from './list-view.js';
2
3
  /**
3
4
  * Returns the canvas the deepest matching route asks for.
4
5
  * @returns The canvas mode, padded when no route asks for one.
package/dist/testing.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { RenderOptions, RenderResult } from '@testing-library/react';
2
- import type { ReactNode } from 'react';
2
+ import { Badge, Button, Text } from '@wordpress/ui';
3
+ import type { ComponentProps, ReactNode } from 'react';
3
4
  import type { AdminRootProps } from './admin-root.js';
4
5
  /**
5
6
  * The elements the design system announces through rather than displays.
@@ -39,6 +40,25 @@ export declare function setViewport(viewport: {
39
40
  * Prepares the test environment a design system application needs.
40
41
  */
41
42
  export declare function installTestEnvironment(): void;
43
+ /**
44
+ * Returns the classes a design system text draws at the given variant.
45
+ * @param variant - The text variant to sample.
46
+ * @returns The class names, in order.
47
+ */
48
+ export declare function textClasses(variant: ComponentProps<typeof Text>['variant']): string[];
49
+ /**
50
+ * Returns the classes a design system badge draws at the given intent.
51
+ * @param intent - The badge intent to sample.
52
+ * @returns The class names, in order.
53
+ */
54
+ export declare function badgeClasses(intent: ComponentProps<typeof Badge>['intent']): string[];
55
+ /**
56
+ * Returns the classes a design system button draws at the given variant and size.
57
+ * @param variant - The button variant to sample.
58
+ * @param size - The button size, the default one when absent.
59
+ * @returns The class names, in order.
60
+ */
61
+ export declare function buttonClasses(variant: ComponentProps<typeof Button>['variant'], size?: ComponentProps<typeof Button>['size']): string[];
42
62
  /**
43
63
  * Renders the given tree inside the design system host.
44
64
  * @param ui - The tree to render.
package/dist/testing.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { cleanup, configure, render } from '@testing-library/react';
4
+ import { Badge, Button, Text } from '@wordpress/ui';
4
5
  import { afterEach } from 'vitest';
5
6
  import { AdminRoot } from './admin-root.js';
6
7
  /**
@@ -156,6 +157,42 @@ export function installTestEnvironment() {
156
157
  afterEach(clearAnnouncements);
157
158
  afterEach(resetViewport);
158
159
  }
160
+ /**
161
+ * Returns the classes the outer element of a tree draws with, removing the tree once read.
162
+ * @param tree - The tree to sample.
163
+ * @returns The class names, in order.
164
+ */
165
+ function classesOf(tree) {
166
+ const { container, unmount } = render(tree);
167
+ const classes = [...container.firstElementChild.classList];
168
+ unmount();
169
+ return classes;
170
+ }
171
+ /**
172
+ * Returns the classes a design system text draws at the given variant.
173
+ * @param variant - The text variant to sample.
174
+ * @returns The class names, in order.
175
+ */
176
+ export function textClasses(variant) {
177
+ return classesOf(_jsx(Text, { variant: variant }));
178
+ }
179
+ /**
180
+ * Returns the classes a design system badge draws at the given intent.
181
+ * @param intent - The badge intent to sample.
182
+ * @returns The class names, in order.
183
+ */
184
+ export function badgeClasses(intent) {
185
+ return classesOf(_jsx(Badge, { intent: intent, children: "probe" }));
186
+ }
187
+ /**
188
+ * Returns the classes a design system button draws at the given variant and size.
189
+ * @param variant - The button variant to sample.
190
+ * @param size - The button size, the default one when absent.
191
+ * @returns The class names, in order.
192
+ */
193
+ export function buttonClasses(variant, size) {
194
+ return classesOf(_jsx(Button, { variant: variant, size: size, children: "probe" }));
195
+ }
159
196
  /**
160
197
  * Renders the given tree inside the design system host.
161
198
  * @param ui - The tree to render.
package/dist/toaster.d.ts CHANGED
@@ -5,6 +5,8 @@ export interface ToastAction {
5
5
  }
6
6
  export interface ToasterHandle {
7
7
  show: (message: string, action?: ToastAction) => void;
8
+ /** The title cut to the toaster's name length, with an ellipsis when cut. */
9
+ name: (title: string) => string;
8
10
  }
9
11
  /**
10
12
  * Returns the handle raising messages in the toast region.
@@ -20,10 +22,12 @@ export interface ToasterProps {
20
22
  dismissLabel?: string;
21
23
  /** How many toasts stay on screen at once, the oldest leaving first. */
22
24
  limit?: number;
25
+ /** How many characters of a name a toast shows before the ellipsis. */
26
+ nameLength?: number;
23
27
  }
24
28
  /**
25
29
  * Renders the region holding raised messages around the given tree.
26
- * @param props - The tree the region wraps, how long a toast stays, the dismiss control name and how many stay.
30
+ * @param props - The tree the region wraps, the toast time, the close button name, how many stay and the name length.
27
31
  * @returns The wrapped tree with its region.
28
32
  */
29
- export declare function Toaster({ children, dismissAfter, dismissLabel, limit, }: ToasterProps): import("react").JSX.Element;
33
+ export declare function Toaster({ children, dismissAfter, dismissLabel, limit, nameLength, }: ToasterProps): import("react").JSX.Element;