@gopherium/godmin 0.14.1 → 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.
- package/README.md +9 -4
- package/dist/avatar.d.ts +4 -2
- package/dist/avatar.js +18 -3
- package/dist/base.css +48 -0
- package/dist/bulk.d.ts +45 -0
- package/dist/bulk.js +56 -0
- package/dist/confirm.d.ts +23 -0
- package/dist/confirm.js +12 -0
- package/dist/file-button.d.ts +24 -0
- package/dist/file-button.js +25 -0
- package/dist/frame.d.ts +2 -0
- package/dist/frame.js +9 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +8 -2
- package/dist/list-chrome/es-ES.js +48 -34
- package/dist/list-empty.d.ts +16 -0
- package/dist/list-empty.js +11 -0
- package/dist/list-view.d.ts +114 -0
- package/dist/list-view.js +246 -0
- package/dist/page-tabs.d.ts +1 -1
- package/dist/page-tabs.js +106 -7
- package/dist/rename.d.ts +24 -0
- package/dist/rename.js +20 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/server-page.d.ts +63 -0
- package/dist/server-page.js +58 -0
- package/dist/testing.d.ts +21 -1
- package/dist/testing.js +37 -0
- package/dist/toaster.d.ts +6 -2
- package/dist/toaster.js +26 -3
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -23,6 +23,11 @@ pnpm add @gopherium/godmin
|
|
|
23
23
|
The design system packages are peer dependencies, so your application resolves
|
|
24
24
|
and pins them. GodMin never redistributes them.
|
|
25
25
|
|
|
26
|
+
## Browsers
|
|
27
|
+
|
|
28
|
+
GodMin needs `Intl.Segmenter`, which every browser WordPress supports has:
|
|
29
|
+
Chrome and Edge 87, Safari 14.1 and Firefox 125 or newer.
|
|
30
|
+
|
|
26
31
|
## Setup
|
|
27
32
|
|
|
28
33
|
Import the stylesheet once at your entry point, then mount `AdminRoot` around
|
|
@@ -47,10 +52,10 @@ two lines do for you.
|
|
|
47
52
|
|
|
48
53
|
| Entry point | Contents |
|
|
49
54
|
| --- | --- |
|
|
50
|
-
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
|
|
55
|
+
| `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavScreen`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `LoadingRows`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ConfirmBody`, `RenameBody`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
|
|
51
56
|
| `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
|
|
52
|
-
| `@gopherium/godmin/router` | `useCanvas`, `useFrameLocation`, the `canvas` route static data |
|
|
53
|
-
| `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR` |
|
|
57
|
+
| `@gopherium/godmin/router` | `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, the `canvas` route static data |
|
|
58
|
+
| `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses` |
|
|
54
59
|
| `@gopherium/godmin/vite` | `godminDedupe`, `godminSingleCopy`, `godminStylesheetFirst`, `duplicateCopies`, `hoistStylesheet` |
|
|
55
60
|
| `@gopherium/godmin/stylelint` | The design system stylelint rules |
|
|
56
61
|
|
|
@@ -66,7 +71,7 @@ render unthemed components with no error. Spread `godminDedupe` into
|
|
|
66
71
|
|
|
67
72
|
## Design system versions
|
|
68
73
|
|
|
69
|
-
Peer ranges are longhand and single window, for example `>=0.
|
|
74
|
+
Peer ranges are longhand and single window, for example `>=0.23.0 <0.24.0`.
|
|
70
75
|
The window moves with each design system release train and never widens, so no
|
|
71
76
|
release accepts two breaking generations at once. `SUPPORTED_WPDS` exports the
|
|
72
77
|
window this build was tested against.
|
package/dist/avatar.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare const AVATAR_COLORS: readonly AvatarColor[];
|
|
|
12
12
|
export interface InitialsAvatarProps {
|
|
13
13
|
/** The name the avatar stands for, whose first letter it draws. */
|
|
14
14
|
name: string;
|
|
15
|
+
/** The avatar's width and height in pixels, the stylesheet size when absent. */
|
|
16
|
+
size?: number;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Renders a round avatar with the first letter of a name, in the letter colour of the circle colour the name picks.
|
|
18
|
-
* @param props - The name the avatar stands for.
|
|
20
|
+
* @param props - The name the avatar stands for and its size.
|
|
19
21
|
* @returns The avatar element.
|
|
20
22
|
*/
|
|
21
|
-
export declare function InitialsAvatar({ name }: InitialsAvatarProps): import("react").JSX.Element;
|
|
23
|
+
export declare function InitialsAvatar({ name, size }: InitialsAvatarProps): import("react").JSX.Element;
|
package/dist/avatar.js
CHANGED
|
@@ -31,12 +31,27 @@ function initialOf(name) {
|
|
|
31
31
|
const [first = ''] = Array.from(name.trim());
|
|
32
32
|
return first.toLocaleUpperCase();
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The share of the circle a letter takes, 12px in the 32px stylesheet circle.
|
|
36
|
+
*/
|
|
37
|
+
const LETTER_SHARE = 12 / 32;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the inline size of an avatar drawn at the given size, none for the stylesheet size.
|
|
40
|
+
* @param size - The width and height in pixels, absent for the stylesheet size.
|
|
41
|
+
* @returns The circle and letter sizes, or nothing.
|
|
42
|
+
*/
|
|
43
|
+
function sizedBy(size) {
|
|
44
|
+
if (size === undefined) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
return { inlineSize: size, blockSize: size, fontSize: size * LETTER_SHARE };
|
|
48
|
+
}
|
|
34
49
|
/**
|
|
35
50
|
* Renders a round avatar with the first letter of a name, in the letter colour of the circle colour the name picks.
|
|
36
|
-
* @param props - The name the avatar stands for.
|
|
51
|
+
* @param props - The name the avatar stands for and its size.
|
|
37
52
|
* @returns The avatar element.
|
|
38
53
|
*/
|
|
39
|
-
export function InitialsAvatar({ name }) {
|
|
54
|
+
export function InitialsAvatar({ name, size }) {
|
|
40
55
|
const { background, letter } = colorFor(name);
|
|
41
|
-
return (_jsx("span", { className: "godmin-avatar", "aria-hidden": "true", style: { backgroundColor: background, color: letter }, children: initialOf(name) }));
|
|
56
|
+
return (_jsx("span", { className: "godmin-avatar", "aria-hidden": "true", style: { backgroundColor: background, color: letter, ...sizedBy(size) }, children: initialOf(name) }));
|
|
42
57
|
}
|
package/dist/base.css
CHANGED
|
@@ -28,6 +28,13 @@ body {
|
|
|
28
28
|
text-decoration: none;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/* Ends a DataViews table title link wider than its column in an ellipsis, as WordPress cuts its titles. */
|
|
32
|
+
.dataviews-view-table tbody .dataviews-view-table__cell-content-wrapper.dataviews-title-field--clickable {
|
|
33
|
+
display: block;
|
|
34
|
+
align-content: center;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/* Draws a DataViews media link without an underline or the browser link colour. */
|
|
32
39
|
.dataviews-column-primary__media--clickable {
|
|
33
40
|
color: inherit;
|
|
@@ -377,6 +384,19 @@ body {
|
|
|
377
384
|
margin-inline: var(--wpds-dimension-padding-2xl);
|
|
378
385
|
}
|
|
379
386
|
|
|
387
|
+
.godmin-page__list:has(> .godmin-list-overlay),
|
|
388
|
+
.godmin-list:has(> .godmin-list-overlay) {
|
|
389
|
+
position: relative;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.godmin-page > .godmin-page__list > .godmin-list-overlay,
|
|
393
|
+
.godmin-page__main > .godmin-page__list > .godmin-list-overlay,
|
|
394
|
+
.godmin-list > .godmin-list-overlay {
|
|
395
|
+
position: absolute;
|
|
396
|
+
inset: 0;
|
|
397
|
+
margin: 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
380
400
|
.godmin-page__tabs {
|
|
381
401
|
margin-inline: calc(-1 * var(--godmin-canvas-gutter, 0px));
|
|
382
402
|
padding-inline: var(--godmin-canvas-gutter, 0px);
|
|
@@ -392,9 +412,36 @@ body {
|
|
|
392
412
|
}
|
|
393
413
|
|
|
394
414
|
.godmin-page-tabs {
|
|
415
|
+
--godmin-page-tabs-start: left;
|
|
416
|
+
--godmin-page-tabs-end: right;
|
|
417
|
+
--godmin-page-tabs-fade-width: 4rem;
|
|
418
|
+
--godmin-page-tabs-fade: transparent 0%, #000 var(--godmin-page-tabs-fade-width);
|
|
419
|
+
--godmin-page-tabs-fade-both: var(--godmin-page-tabs-fade), #000 60%, transparent 50%;
|
|
420
|
+
|
|
395
421
|
display: flex;
|
|
422
|
+
position: relative;
|
|
396
423
|
gap: var(--wpds-dimension-gap-lg);
|
|
397
424
|
overflow-x: auto;
|
|
425
|
+
overscroll-behavior-inline: none;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.godmin-page-tabs:dir(rtl) {
|
|
429
|
+
--godmin-page-tabs-start: right;
|
|
430
|
+
--godmin-page-tabs-end: left;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.godmin-page-tabs--overflowing-first {
|
|
434
|
+
mask-image: linear-gradient(to var(--godmin-page-tabs-end), var(--godmin-page-tabs-fade));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.godmin-page-tabs--overflowing-last {
|
|
438
|
+
mask-image: linear-gradient(to var(--godmin-page-tabs-start), var(--godmin-page-tabs-fade));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
.godmin-page-tabs--overflowing-first.godmin-page-tabs--overflowing-last {
|
|
442
|
+
mask-image:
|
|
443
|
+
linear-gradient(to right, var(--godmin-page-tabs-fade-both)),
|
|
444
|
+
linear-gradient(to left, var(--godmin-page-tabs-fade-both));
|
|
398
445
|
}
|
|
399
446
|
|
|
400
447
|
.godmin-page-tabs__tab {
|
|
@@ -403,6 +450,7 @@ body {
|
|
|
403
450
|
position: relative;
|
|
404
451
|
block-size: 48px;
|
|
405
452
|
padding: 0;
|
|
453
|
+
scroll-margin: 24px;
|
|
406
454
|
color: var(--wpds-color-foreground-interactive-neutral);
|
|
407
455
|
font-family: var(--wpds-typography-font-family-body);
|
|
408
456
|
font-size: var(--wpds-typography-font-size-md);
|
package/dist/bulk.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** An item a bulk run could not finish, with the error its call failed with. */
|
|
2
|
+
export interface BulkFailure<Item> {
|
|
3
|
+
/** The item the call was made for. */
|
|
4
|
+
item: Item;
|
|
5
|
+
/** What the call rejected with, threw, or answered as its error. */
|
|
6
|
+
error: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** What a bulk run reached. */
|
|
9
|
+
export interface BulkOutcome<Item> {
|
|
10
|
+
/** How many items the run was given. */
|
|
11
|
+
asked: number;
|
|
12
|
+
/** How many of them finished. */
|
|
13
|
+
done: number;
|
|
14
|
+
/** The items that failed, in the order they were given. */
|
|
15
|
+
failures: BulkFailure<Item>[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs one call for each item, all at once, and counts the calls that finished and the ones that failed.
|
|
19
|
+
* @param items - The items to act on, an empty slot left out.
|
|
20
|
+
* @param call - The action on one item, failing when it rejects, throws, or answers with an error.
|
|
21
|
+
* @returns How many items were asked, how many finished, and each failure with its item.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runEach<Item>(items: readonly Item[], call: (item: Item) => Promise<unknown>): Promise<BulkOutcome<Item>>;
|
|
24
|
+
/** The words a product turns a bulk outcome into. */
|
|
25
|
+
export interface BulkWords<Item> {
|
|
26
|
+
/** The toast for the items that finished, given their count and the one item when only one was asked. */
|
|
27
|
+
done: (count: number, only: Item | undefined) => string;
|
|
28
|
+
/** The notice for the items that failed, given every failure and how many items were asked. */
|
|
29
|
+
failed: (failures: BulkFailure<Item>[], asked: number) => string;
|
|
30
|
+
}
|
|
31
|
+
/** The messages a bulk outcome reads as, each absent when nothing calls for it. */
|
|
32
|
+
export interface BulkNotes {
|
|
33
|
+
/** The toast confirming the items that finished. */
|
|
34
|
+
toast?: string;
|
|
35
|
+
/** The notice naming the items that failed. */
|
|
36
|
+
notice?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the toast and the notice a bulk outcome reads as, in the product's words.
|
|
40
|
+
* @param items - The items the run was given.
|
|
41
|
+
* @param outcome - What the run reached.
|
|
42
|
+
* @param words - The words for the items that finished and for the ones that failed.
|
|
43
|
+
* @returns A toast when an item finished and a notice when one failed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function bulkNotes<Item>(items: readonly Item[], outcome: BulkOutcome<Item>, words: BulkWords<Item>): BulkNotes;
|
package/dist/bulk.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Returns the error an answer carries, or undefined when it carries none.
|
|
4
|
+
* @param answer - What a call resolved with.
|
|
5
|
+
* @returns The answer's error.
|
|
6
|
+
*/
|
|
7
|
+
function answeredError(answer) {
|
|
8
|
+
if (typeof answer !== 'object' || answer === null || !('error' in answer)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const error = answer.error;
|
|
12
|
+
return error === null ? undefined : error;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns the failure one settled call stands for, or none when it finished.
|
|
16
|
+
* @param settled - How the call settled.
|
|
17
|
+
* @param item - The item the call was made for.
|
|
18
|
+
* @returns The failure, or an empty list.
|
|
19
|
+
*/
|
|
20
|
+
function failureOf(settled, item) {
|
|
21
|
+
if (settled.status === 'rejected') {
|
|
22
|
+
return [{ item, error: settled.reason }];
|
|
23
|
+
}
|
|
24
|
+
const error = answeredError(settled.value);
|
|
25
|
+
return error === undefined ? [] : [{ item, error }];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Runs one call for each item, all at once, and counts the calls that finished and the ones that failed.
|
|
29
|
+
* @param items - The items to act on, an empty slot left out.
|
|
30
|
+
* @param call - The action on one item, failing when it rejects, throws, or answers with an error.
|
|
31
|
+
* @returns How many items were asked, how many finished, and each failure with its item.
|
|
32
|
+
*/
|
|
33
|
+
export async function runEach(items, call) {
|
|
34
|
+
const given = items.filter(() => true);
|
|
35
|
+
const settled = await Promise.allSettled(given.map(async (item) => call(item)));
|
|
36
|
+
const failures = settled.flatMap((result, at) => failureOf(result, given[at]));
|
|
37
|
+
return { asked: given.length, done: given.length - failures.length, failures };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the toast and the notice a bulk outcome reads as, in the product's words.
|
|
41
|
+
* @param items - The items the run was given.
|
|
42
|
+
* @param outcome - What the run reached.
|
|
43
|
+
* @param words - The words for the items that finished and for the ones that failed.
|
|
44
|
+
* @returns A toast when an item finished and a notice when one failed.
|
|
45
|
+
*/
|
|
46
|
+
export function bulkNotes(items, outcome, words) {
|
|
47
|
+
const only = outcome.asked === 1 ? items.filter(() => true)[0] : undefined;
|
|
48
|
+
const notes = {};
|
|
49
|
+
if (outcome.done > 0) {
|
|
50
|
+
notes.toast = words.done(outcome.done, only);
|
|
51
|
+
}
|
|
52
|
+
if (outcome.failures.length > 0) {
|
|
53
|
+
notes.notice = words.failed(outcome.failures, outcome.asked);
|
|
54
|
+
}
|
|
55
|
+
return notes;
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface ConfirmBodyProps {
|
|
3
|
+
/** The question the modal asks. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** The label of the button that carries the action out. */
|
|
6
|
+
confirmLabel: string;
|
|
7
|
+
/** The label of the button that closes the modal. */
|
|
8
|
+
cancelLabel: string;
|
|
9
|
+
/** Whether the action is running, the confirm button then busy and Cancel greyed out. */
|
|
10
|
+
busy?: boolean;
|
|
11
|
+
/** The failure of the last try, shown inside the modal. */
|
|
12
|
+
failure?: string;
|
|
13
|
+
/** Carries the action out. */
|
|
14
|
+
onConfirm: () => void;
|
|
15
|
+
/** Closes the modal. */
|
|
16
|
+
onCancel?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Renders the body of a confirmation modal: the question, a failure notice, a minimal Cancel and the confirm button.
|
|
20
|
+
* @param props - The question, the labels, the busy flag, the failure and the handlers.
|
|
21
|
+
* @returns The confirmation body.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ConfirmBody({ children, confirmLabel, cancelLabel, busy, failure, onConfirm, onCancel, }: ConfirmBodyProps): import("react").JSX.Element;
|
package/dist/confirm.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Button, Stack, Text } from '@wordpress/ui';
|
|
4
|
+
import { ErrorNotice } from './page.js';
|
|
5
|
+
/**
|
|
6
|
+
* Renders the body of a confirmation modal: the question, a failure notice, a minimal Cancel and the confirm button.
|
|
7
|
+
* @param props - The question, the labels, the busy flag, the failure and the handlers.
|
|
8
|
+
* @returns The confirmation body.
|
|
9
|
+
*/
|
|
10
|
+
export function ConfirmBody({ children, confirmLabel, cancelLabel, busy = false, failure, onConfirm, onCancel, }) {
|
|
11
|
+
return (_jsxs(Stack, { direction: "column", gap: "lg", children: [_jsx(Text, { children: children }), 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, { loading: busy, onClick: onConfirm, children: confirmLabel })] })] }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Button } from '@wordpress/ui';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
export interface FileButtonProps {
|
|
4
|
+
/** The file types the dialog offers, as the input `accept` attribute takes them. */
|
|
5
|
+
accept?: string;
|
|
6
|
+
/** Whether the reader may choose more than one file. */
|
|
7
|
+
multiple?: boolean;
|
|
8
|
+
/** Whether an upload is running, the button then busy. */
|
|
9
|
+
busy?: boolean;
|
|
10
|
+
/** The icon drawn before the label. */
|
|
11
|
+
icon?: ComponentProps<typeof Button.Icon>['icon'];
|
|
12
|
+
/** The name of the hidden file input. */
|
|
13
|
+
inputLabel?: string;
|
|
14
|
+
/** Takes the files the reader chose, never called for a dialog closed with none. */
|
|
15
|
+
onChoose: (files: File[]) => void;
|
|
16
|
+
/** The button label. */
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders a compact solid button that opens the file dialog of a hidden file input.
|
|
21
|
+
* @param props - The file types, the many flag, the busy flag, the icon, the input name, the handler and the label.
|
|
22
|
+
* @returns The button beside its hidden input.
|
|
23
|
+
*/
|
|
24
|
+
export declare function FileButton({ accept, multiple, busy, icon, inputLabel, onChoose, children, }: FileButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Button } from '@wordpress/ui';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Empties the input, then hands the files it held to the handler, none for a closed dialog.
|
|
7
|
+
* @param event - The change the input reported.
|
|
8
|
+
* @param onChoose - Takes the files the reader chose.
|
|
9
|
+
*/
|
|
10
|
+
function handOver(event, onChoose) {
|
|
11
|
+
const files = Array.from(event.target.files ?? []);
|
|
12
|
+
event.target.value = '';
|
|
13
|
+
if (files.length > 0) {
|
|
14
|
+
onChoose(files);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Renders a compact solid button that opens the file dialog of a hidden file input.
|
|
19
|
+
* @param props - The file types, the many flag, the busy flag, the icon, the input name, the handler and the label.
|
|
20
|
+
* @returns The button beside its hidden input.
|
|
21
|
+
*/
|
|
22
|
+
export function FileButton({ accept, multiple = false, busy = false, icon, inputLabel, onChoose, children, }) {
|
|
23
|
+
const input = useRef(null);
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Button, { variant: "solid", size: "compact", loading: busy, onClick: () => input.current.click(), children: [icon === undefined ? null : _jsx(Button.Icon, { icon: icon }), children] }), _jsx("input", { ref: input, type: "file", accept: accept, multiple: multiple, hidden: true, "aria-label": inputLabel, onChange: (event) => handOver(event, onChoose) })] }));
|
|
25
|
+
}
|
package/dist/frame.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ type ThemeColor = ComponentProps<typeof ThemeProvider>['color'];
|
|
|
4
4
|
export interface FrameRootProps {
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
location?: string;
|
|
7
|
+
/** The theme colour of the frame, a #26292b background when absent. */
|
|
7
8
|
chromeColor?: ThemeColor;
|
|
9
|
+
/** The theme colour of the canvas, a #fcfcfc background when absent. */
|
|
8
10
|
canvasColor?: ThemeColor;
|
|
9
11
|
}
|
|
10
12
|
/**
|
package/dist/frame.js
CHANGED
|
@@ -10,13 +10,21 @@ import { useMediaQuery } from './use-media-query.js';
|
|
|
10
10
|
* The glyph on the button that opens the rail drawer, drawn where the admin bar menu toggle draws its bars.
|
|
11
11
|
*/
|
|
12
12
|
const menuIcon = (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "52", height: "46", viewBox: "0 0 52 46", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M11 11h28v4H11zm0 10h28v4H11zm0 10h28v4H11z" }) }));
|
|
13
|
+
/**
|
|
14
|
+
* The chrome background seeded when an application names none.
|
|
15
|
+
*/
|
|
16
|
+
const CHROME_COLOR = { background: '#26292b' };
|
|
17
|
+
/**
|
|
18
|
+
* The canvas background seeded when an application names none, the design system default background.
|
|
19
|
+
*/
|
|
20
|
+
const CANVAS_COLOR = { background: '#fcfcfc' };
|
|
13
21
|
const FrameContext = createContext({ small: false, location: undefined, layout: null });
|
|
14
22
|
/**
|
|
15
23
|
* Frames an admin application, folding its rail away on a narrow viewport.
|
|
16
24
|
* @param props - The regions, the current location, and the region colors.
|
|
17
25
|
* @returns The frame element.
|
|
18
26
|
*/
|
|
19
|
-
function Root({ children, location, chromeColor, canvasColor }) {
|
|
27
|
+
function Root({ children, location, chromeColor = CHROME_COLOR, canvasColor = CANVAS_COLOR }) {
|
|
20
28
|
const small = useMediaQuery(SMALL_VIEWPORT);
|
|
21
29
|
const [layout, setLayout] = useState(null);
|
|
22
30
|
const classes = small ? 'godmin-layout godmin-layout--small' : 'godmin-layout';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ export type { AdminRootProps } from './admin-root.js';
|
|
|
3
3
|
export { InitialsAvatar } from './avatar.js';
|
|
4
4
|
export type { InitialsAvatarProps } from './avatar.js';
|
|
5
5
|
export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
|
|
6
|
+
export { bulkNotes, runEach } from './bulk.js';
|
|
7
|
+
export type { BulkFailure, BulkNotes, BulkOutcome, BulkWords } from './bulk.js';
|
|
8
|
+
export { ConfirmBody } from './confirm.js';
|
|
9
|
+
export type { ConfirmBodyProps } from './confirm.js';
|
|
10
|
+
export { FileButton } from './file-button.js';
|
|
11
|
+
export type { FileButtonProps } from './file-button.js';
|
|
6
12
|
export { Frame } from './frame.js';
|
|
7
13
|
export type { CanvasMode, FrameCanvasProps, FrameRailProps, FrameRootProps, } from './frame.js';
|
|
8
14
|
export { keyFromLabel } from './keys.js';
|
|
9
15
|
export type { KeyOptions, KeyStyle } from './keys.js';
|
|
10
16
|
export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
|
|
11
17
|
export type { ListChromeCatalog } from './list-chrome.js';
|
|
18
|
+
export { ListEmpty } from './list-empty.js';
|
|
19
|
+
export type { ListEmptyProps } from './list-empty.js';
|
|
12
20
|
export { LoadingRows, LoadingScreen } from './loading.js';
|
|
13
21
|
export { LogItem, LogList, LogTime } from './log-list.js';
|
|
14
22
|
export type { LogItemProps, LogListProps, LogTimeProps } from './log-list.js';
|
|
@@ -18,10 +26,14 @@ export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js'
|
|
|
18
26
|
export type { LoadMoreQuery, PageProps } from './page.js';
|
|
19
27
|
export { PageTab, PageTabs } from './page-tabs.js';
|
|
20
28
|
export type { PageTabProps, PageTabsProps } from './page-tabs.js';
|
|
29
|
+
export { RenameBody } from './rename.js';
|
|
30
|
+
export type { RenameBodyProps } from './rename.js';
|
|
21
31
|
export { useRowKeys } from './row-keys.js';
|
|
22
32
|
export type { RowBounds, RowKeys } from './row-keys.js';
|
|
23
33
|
export { RepeatRows, RowControls } from './rows.js';
|
|
24
34
|
export type { RepeatRowsProps, RowControlsProps, RowLabels } from './rows.js';
|
|
35
|
+
export { pageWindow, paginationOf, useServerPaging } from './server-page.js';
|
|
36
|
+
export type { PagedView, PageWindow, PaginationInfo, ServedPage, ServedSize, ServerPaging } from './server-page.js';
|
|
25
37
|
export { Toaster, useToaster } from './toaster.js';
|
|
26
38
|
export type { ToastAction, ToasterHandle, ToasterProps } from './toaster.js';
|
|
27
39
|
export { useMediaQuery } from './use-media-query.js';
|
|
@@ -30,6 +42,6 @@ export { useTokenDocument } from './use-token-document.js';
|
|
|
30
42
|
* The design system version window this build was tested against.
|
|
31
43
|
*/
|
|
32
44
|
export declare const SUPPORTED_WPDS: {
|
|
33
|
-
readonly '@wordpress/ui': ">=0.
|
|
34
|
-
readonly '@wordpress/theme': ">=2.
|
|
45
|
+
readonly '@wordpress/ui': ">=0.23.0 <0.24.0";
|
|
46
|
+
readonly '@wordpress/theme': ">=2.2.0 <3.0.0";
|
|
35
47
|
};
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,22 @@
|
|
|
2
2
|
export { AdminRoot } from './admin-root.js';
|
|
3
3
|
export { InitialsAvatar } from './avatar.js';
|
|
4
4
|
export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
|
|
5
|
+
export { bulkNotes, runEach } from './bulk.js';
|
|
6
|
+
export { ConfirmBody } from './confirm.js';
|
|
7
|
+
export { FileButton } from './file-button.js';
|
|
5
8
|
export { Frame } from './frame.js';
|
|
6
9
|
export { keyFromLabel } from './keys.js';
|
|
7
10
|
export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
|
|
11
|
+
export { ListEmpty } from './list-empty.js';
|
|
8
12
|
export { LoadingRows, LoadingScreen } from './loading.js';
|
|
9
13
|
export { LogItem, LogList, LogTime } from './log-list.js';
|
|
10
14
|
export { NavScreen } from './nav-screen.js';
|
|
11
15
|
export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
|
|
12
16
|
export { PageTab, PageTabs } from './page-tabs.js';
|
|
17
|
+
export { RenameBody } from './rename.js';
|
|
13
18
|
export { useRowKeys } from './row-keys.js';
|
|
14
19
|
export { RepeatRows, RowControls } from './rows.js';
|
|
20
|
+
export { pageWindow, paginationOf, useServerPaging } from './server-page.js';
|
|
15
21
|
export { Toaster, useToaster } from './toaster.js';
|
|
16
22
|
export { useMediaQuery } from './use-media-query.js';
|
|
17
23
|
export { useTokenDocument } from './use-token-document.js';
|
|
@@ -19,6 +25,6 @@ export { useTokenDocument } from './use-token-document.js';
|
|
|
19
25
|
* The design system version window this build was tested against.
|
|
20
26
|
*/
|
|
21
27
|
export const SUPPORTED_WPDS = {
|
|
22
|
-
'@wordpress/ui': '>=0.
|
|
23
|
-
'@wordpress/theme': '>=2.
|
|
28
|
+
'@wordpress/ui': '>=0.23.0 <0.24.0',
|
|
29
|
+
'@wordpress/theme': '>=2.2.0 <3.0.0',
|
|
24
30
|
};
|