@gopherium/godmin 0.22.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,10 +52,10 @@ two lines do for you.
52
52
 
53
53
  | Entry point | Contents |
54
54
  | --- | --- |
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`, `useListRun`, `useBulkRun`, `RunConfirm`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `RAIL_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `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`, `FormBody`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `RunConfirm`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `RAIL_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
56
56
  | `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
57
57
  | `@gopherium/godmin/dates` | `startListDates`, `listDate`, the only entry that loads `@wordpress/date` |
58
- | `@gopherium/godmin/dialogs` | `ConfirmDialog`, the only entry that loads `@wordpress/components`. Load `@wordpress/components/build-style/style.css` once in your app, as DataViews asks |
58
+ | `@gopherium/godmin/dialogs` | `ConfirmDialog`, `FormDialog`, the only entry that loads `@wordpress/components`. Load `@wordpress/components/build-style/style.css` once in your app, as DataViews asks |
59
59
  | `@gopherium/godmin/router` | `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, the `canvas` route static data |
60
60
  | `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport` and its `TestViewport` type, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses`, `stubLayout` |
61
61
  | `@gopherium/godmin/vite` | `godminDedupe`, `godminSingleCopy`, `godminStylesheetFirst`, `duplicateCopies`, `hoistStylesheet` |
package/dist/base.css CHANGED
@@ -510,6 +510,24 @@ body {
510
510
  align-self: flex-start;
511
511
  }
512
512
 
513
+ .godmin-modal-body {
514
+ display: flex;
515
+ flex-direction: column;
516
+ gap: calc(var(--wpds-dimension-gap-lg) + var(--wpds-dimension-gap-xs));
517
+ }
518
+
519
+ .godmin-modal-body--copy {
520
+ gap: var(--wpds-dimension-gap-md);
521
+ }
522
+
523
+ .godmin-modal-body--create {
524
+ gap: var(--wpds-dimension-gap-lg);
525
+ }
526
+
527
+ .godmin-modal-body__question {
528
+ line-height: 1.4;
529
+ }
530
+
513
531
  .godmin-form__row {
514
532
  display: flex;
515
533
  flex-wrap: wrap;
@@ -3,7 +3,7 @@ import type { ListRun } from './list-run.js';
3
3
  /** Runs one call over each item, refreshes the list and reports what the run reached in the given words. */
4
4
  export type BulkRun<Item> = (items: Item[], call: (item: Item) => Promise<unknown>, words: BulkWords<Item>) => Promise<void>;
5
5
  /**
6
- * Returns the handler that runs one call per item, refreshes the list, toasts what finished and settles the run.
6
+ * Returns the handler that runs one call per item, refreshes the list, shows one toast and settles the run.
7
7
  * @param list - What the list does around a run.
8
8
  * @param refresh - Reloads the list, given the items the run acted on.
9
9
  * @returns The run handler, the same while the list run and the refresh stay the same.
package/dist/bulk-run.js CHANGED
@@ -3,7 +3,18 @@ import { useCallback } from 'react';
3
3
  import { bulkNotes, runEach } from './bulk.js';
4
4
  import { useToaster } from './toaster.js';
5
5
  /**
6
- * Returns the handler that runs one call per item, refreshes the list, toasts what finished and settles the run.
6
+ * Returns the one message a bulk outcome shows: the failure words when an item failed, else the done words.
7
+ * @param items - The items the run was given.
8
+ * @param outcome - What the run reached.
9
+ * @param words - The words for the items that finished and for the ones that failed.
10
+ * @returns The message, none when the run was given no items.
11
+ */
12
+ function bulkToast(items, outcome, words) {
13
+ const notes = bulkNotes(items, outcome, words);
14
+ return notes.notice ?? notes.toast;
15
+ }
16
+ /**
17
+ * Returns the handler that runs one call per item, refreshes the list, shows one toast and settles the run.
7
18
  * @param list - What the list does around a run.
8
19
  * @param refresh - Reloads the list, given the items the run acted on.
9
20
  * @returns The run handler, the same while the list run and the refresh stay the same.
@@ -13,19 +24,18 @@ export function useBulkRun(list, refresh) {
13
24
  return useCallback(async (items, call, words) => {
14
25
  const settle = list.onStart();
15
26
  const outcome = await runEach(items, call);
16
- let notes = {};
17
27
  try {
18
28
  await refresh(items);
19
29
  }
20
30
  finally {
21
31
  try {
22
- notes = bulkNotes(items, outcome, words);
23
- if (notes.toast !== undefined) {
24
- toaster.show(notes.toast);
32
+ const message = bulkToast(items, outcome, words);
33
+ if (message !== undefined) {
34
+ toaster.show(message);
25
35
  }
26
36
  }
27
37
  finally {
28
- settle(notes.notice, outcome.done > 0);
38
+ settle(outcome.done > 0);
29
39
  }
30
40
  }
31
41
  }, [list, refresh, toaster]);
package/dist/bulk.d.ts CHANGED
@@ -25,14 +25,14 @@ export declare function runEach<Item>(items: readonly Item[], call: (item: Item)
25
25
  export interface BulkWords<Item> {
26
26
  /** The toast for the items that finished, given their count and the one item when only one was asked. */
27
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. */
28
+ /** The toast for the items that failed, shown instead of the done one, given each failure and how many were asked. */
29
29
  failed: (failures: BulkFailure<Item>[], asked: number) => string;
30
30
  }
31
31
  /** The messages a bulk outcome reads as, each absent when nothing calls for it. */
32
32
  export interface BulkNotes {
33
33
  /** The toast confirming the items that finished. */
34
34
  toast?: string;
35
- /** The notice naming the items that failed. */
35
+ /** The words naming the items that failed, which a bulk run toasts in place of the confirming toast. */
36
36
  notice?: string;
37
37
  }
38
38
  /**
package/dist/bulk.js CHANGED
@@ -1,11 +1,19 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Tells whether an answer is an object with an error field.
4
+ * @param answer - What a call resolved with.
5
+ * @returns Whether the answer names an error, null included.
6
+ */
7
+ function namesError(answer) {
8
+ return typeof answer === 'object' && answer !== null && 'error' in answer;
9
+ }
2
10
  /**
3
11
  * Returns the error an answer carries, or undefined when it carries none.
4
12
  * @param answer - What a call resolved with.
5
13
  * @returns The answer's error.
6
14
  */
7
15
  function answeredError(answer) {
8
- if (typeof answer !== 'object' || answer === null || !('error' in answer)) {
16
+ if (!namesError(answer)) {
9
17
  return undefined;
10
18
  }
11
19
  const error = answer.error;
@@ -11,8 +11,8 @@ export interface ConfirmDialogProps {
11
11
  confirmLabel: string;
12
12
  /** The label of the button that closes the dialog. */
13
13
  cancelLabel: string;
14
- /** Carries the action out, resolving with the failure to show, or with nothing once it is done. */
15
- onConfirm: () => Promise<string | undefined>;
14
+ /** Carries the action out. Return nothing to close at once, or the write's promise to stay busy until it ends. */
15
+ onConfirm: () => void | Promise<unknown>;
16
16
  /** Takes the dialog away after Cancel, Escape, a click outside it, its close button or a confirm that finished. */
17
17
  onClose: () => void;
18
18
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Modal } from '@wordpress/components';
4
- import { useId, useState } from 'react';
4
+ import { useId, useRef, useState } from 'react';
5
5
  import { ConfirmBody } from './confirm.js';
6
6
  /**
7
7
  * Renders a confirmation dialog for an action outside a list, as WordPress dialogs ask, Cancel focused.
@@ -10,23 +10,25 @@ import { ConfirmBody } from './confirm.js';
10
10
  */
11
11
  export function ConfirmDialog({ children, title, size = 'medium', confirmLabel, cancelLabel, onConfirm, onClose, }) {
12
12
  const [busy, setBusy] = useState(false);
13
- const [failure, setFailure] = useState();
13
+ const open = useRef(true);
14
14
  const question = useId();
15
- const confirm = async () => {
16
- setBusy(true);
17
- setFailure(undefined);
18
- let failed;
19
- try {
20
- failed = await onConfirm();
21
- }
22
- finally {
23
- setBusy(false);
24
- }
25
- if (failed === undefined) {
15
+ const close = () => {
16
+ if (open.current) {
17
+ open.current = false;
26
18
  onClose();
19
+ }
20
+ };
21
+ const confirm = () => {
22
+ const running = onConfirm();
23
+ if (!(running instanceof Promise)) {
24
+ close();
27
25
  return;
28
26
  }
29
- setFailure(failed);
27
+ setBusy(true);
28
+ void running.finally(() => {
29
+ setBusy(false);
30
+ close();
31
+ });
30
32
  };
31
- return (_jsx(Modal, { size: size, focusOnMount: "firstContentElement", title: title, __experimentalHideHeader: title === undefined, aria: { labelledby: question, describedby: title === undefined ? undefined : question }, isDismissible: !busy, shouldCloseOnEsc: !busy, shouldCloseOnClickOutside: !busy, onRequestClose: onClose, children: _jsx(ConfirmBody, { confirmLabel: confirmLabel, cancelLabel: cancelLabel, busy: busy, failure: failure, onConfirm: () => void confirm(), onCancel: onClose, children: _jsx("span", { id: question, children: children }) }) }));
33
+ return (_jsx(Modal, { size: size, focusOnMount: "firstContentElement", title: title, __experimentalHideHeader: title === undefined, aria: { labelledby: question, describedby: title === undefined ? undefined : question }, onRequestClose: close, children: _jsx(ConfirmBody, { confirmLabel: confirmLabel, cancelLabel: cancelLabel, busy: busy, onConfirm: confirm, onCancel: close, children: _jsx("span", { id: question, children: children }) }) }));
32
34
  }
package/dist/confirm.d.ts CHANGED
@@ -8,16 +8,14 @@ export interface ConfirmBodyProps {
8
8
  cancelLabel: string;
9
9
  /** Whether the action is running, the confirm button then busy and Cancel greyed out. */
10
10
  busy?: boolean;
11
- /** The failure of the last try, shown inside the modal. */
12
- failure?: string;
13
11
  /** Carries the action out. */
14
12
  onConfirm: () => void;
15
13
  /** Closes the modal. */
16
14
  onCancel?: () => void;
17
15
  }
18
16
  /**
19
- * Renders a confirmation modal body: the question, a failure notice, an accent text Cancel and the confirm button.
20
- * @param props - The question, the labels, the busy flag, the failure and the handlers.
17
+ * Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
18
+ * @param props - The question, the labels, the busy flag and the handlers.
21
19
  * @returns The confirmation body.
22
20
  */
23
- export declare function ConfirmBody({ children, confirmLabel, cancelLabel, busy, failure, onConfirm, onCancel, }: ConfirmBodyProps): import("react").JSX.Element;
21
+ export declare function ConfirmBody({ children, confirmLabel, cancelLabel, busy, onConfirm, onCancel, }: ConfirmBodyProps): import("react").JSX.Element;
package/dist/confirm.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Button, Stack, Text } from '@wordpress/ui';
4
- import { ErrorNotice } from './page.js';
5
4
  /**
6
- * Renders a confirmation modal body: the question, a failure notice, an accent text Cancel and the confirm button.
7
- * @param props - The question, the labels, the busy flag, the failure and the handlers.
5
+ * Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
6
+ * @param props - The question, the labels, the busy flag and the handlers.
8
7
  * @returns The confirmation body.
9
8
  */
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 })] })] }));
9
+ export function ConfirmBody({ children, confirmLabel, cancelLabel, busy = false, onConfirm, onCancel, }) {
10
+ return (_jsxs("div", { className: "godmin-modal-body", children: [_jsx(Text, { className: "godmin-modal-body__question", children: children }), _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
11
  }
package/dist/dialogs.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { ConfirmDialog } from './confirm-dialog.js';
2
2
  export type { ConfirmDialogProps } from './confirm-dialog.js';
3
+ export { FormDialog } from './form-dialog.js';
4
+ export type { FormDialogProps } from './form-dialog.js';
package/dist/dialogs.js CHANGED
@@ -1,2 +1,3 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  export { ConfirmDialog } from './confirm-dialog.js';
3
+ export { FormDialog } from './form-dialog.js';
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { FormKind } from './form.js';
3
+ /** The props of a form dialog opened from a button outside a list row. */
4
+ export interface FormDialogProps {
5
+ /** The fields, and any help sentence before them, in the order the reader meets them. */
6
+ children: ReactNode;
7
+ /** The title in the dialog header, beside its close button. */
8
+ title: string;
9
+ /** The width from 600px up: small at 400px, the default, or medium at 560px when a control needs the room. */
10
+ size?: 'small' | 'medium';
11
+ /** The label of the button that sends the form. */
12
+ submitLabel: string;
13
+ /** The label of the button that closes the dialog. */
14
+ cancelLabel: string;
15
+ /** Whether the form may be sent now, false while a needed field is empty, true when left out. */
16
+ canSubmit?: boolean;
17
+ /** What the form does: 16px above the buttons for a create, the default, 20px for an edit, 12px for a copy. */
18
+ kind?: FormKind;
19
+ /** Sends the form. Return the write's promise to keep the button busy until it ends. */
20
+ onSubmit: () => void | Promise<unknown>;
21
+ /** Takes the dialog away after Cancel, Escape, a click on the dimmed page or the close button. */
22
+ onClose: () => void;
23
+ }
24
+ /**
25
+ * Renders a form dialog opened from a button outside a list row, as WordPress opens Add Page, the first field focused.
26
+ * @param props - The fields, the title, the size, the labels, the send gate, the kind and the handlers.
27
+ * @returns The dialog.
28
+ */
29
+ export declare function FormDialog({ children, title, size, submitLabel, cancelLabel, canSubmit, kind, onSubmit, onClose, }: FormDialogProps): import("react").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Modal } from '@wordpress/components';
4
+ import { useState } from 'react';
5
+ import { FormBody } from './form.js';
6
+ /**
7
+ * Renders a form dialog opened from a button outside a list row, as WordPress opens Add Page, the first field focused.
8
+ * @param props - The fields, the title, the size, the labels, the send gate, the kind and the handlers.
9
+ * @returns The dialog.
10
+ */
11
+ export function FormDialog({ children, title, size = 'small', submitLabel, cancelLabel, canSubmit, kind = 'create', onSubmit, onClose, }) {
12
+ const [busy, setBusy] = useState(false);
13
+ const send = () => {
14
+ const sending = onSubmit();
15
+ if (sending instanceof Promise) {
16
+ setBusy(true);
17
+ void sending.finally(() => setBusy(false));
18
+ }
19
+ };
20
+ return (_jsx(Modal, { title: title, size: size, focusOnMount: "firstContentElement", onRequestClose: onClose, children: _jsx(FormBody, { submitLabel: submitLabel, cancelLabel: cancelLabel, canSubmit: canSubmit, busy: busy, kind: kind, onSubmit: send, onCancel: onClose, children: children }) }));
21
+ }
package/dist/form.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { ReactNode } from 'react';
2
+ /** What a form does, which sets the space above its buttons as WordPress spaces it. */
3
+ export type FormKind = 'edit' | 'copy' | 'create';
4
+ /** The props of the body of a form modal. */
5
+ export interface FormBodyProps {
6
+ /** The fields, and any help sentence before them, in the order the reader meets them. */
7
+ children: ReactNode;
8
+ /** The label of the button that sends the form. */
9
+ submitLabel: string;
10
+ /** The label of the button that closes the modal. */
11
+ cancelLabel: string;
12
+ /** Whether the form may be sent now, false while a needed field is empty, true when left out. */
13
+ canSubmit?: boolean;
14
+ /** Whether the write runs, the submit button then busy and a second send ignored. */
15
+ busy?: boolean;
16
+ /** What the form does: 20px above the buttons for an edit, the default, 12px for a copy, 16px for a create. */
17
+ kind?: FormKind;
18
+ /** Sends the form, from the submit button or Enter in a field. */
19
+ onSubmit: () => void;
20
+ /** Closes the modal. */
21
+ onCancel?: () => void;
22
+ }
23
+ /**
24
+ * Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
25
+ * @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
26
+ * @returns The form.
27
+ */
28
+ export declare function FormBody({ children, submitLabel, cancelLabel, canSubmit, busy, kind, onSubmit, onCancel, }: FormBodyProps): import("react").JSX.Element;
package/dist/form.js ADDED
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Button, Stack } from '@wordpress/ui';
4
+ /** The classes of a form body of each kind. */
5
+ const KIND_CLASSES = {
6
+ edit: 'godmin-modal-body',
7
+ copy: 'godmin-modal-body godmin-modal-body--copy',
8
+ create: 'godmin-modal-body godmin-modal-body--create',
9
+ };
10
+ /**
11
+ * Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
12
+ * @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
13
+ * @returns The form.
14
+ */
15
+ export function FormBody({ children, submitLabel, cancelLabel, canSubmit = true, busy = false, kind = 'edit', onSubmit, onCancel, }) {
16
+ const sendable = canSubmit && !busy;
17
+ return (_jsxs("form", { className: KIND_CLASSES[kind], onSubmit: (event) => {
18
+ event.preventDefault();
19
+ if (sendable) {
20
+ onSubmit();
21
+ }
22
+ }, children: [children, _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", onClick: onCancel, children: cancelLabel }), _jsx(Button, { type: "submit", loading: busy, disabled: !sendable, children: submitLabel })] })] }));
23
+ }
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ export { ConfirmBody } from './confirm.js';
11
11
  export type { ConfirmBodyProps } from './confirm.js';
12
12
  export { FileButton } from './file-button.js';
13
13
  export type { FileButtonProps } from './file-button.js';
14
+ export { FormBody } from './form.js';
15
+ export type { FormBodyProps, FormKind } from './form.js';
14
16
  export { Frame } from './frame.js';
15
17
  export type { CanvasMode, FrameCanvasProps, FrameRailProps, FrameRootProps, } from './frame.js';
16
18
  export { keyFromLabel } from './keys.js';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { useBulkRun } from './bulk-run.js';
6
6
  export { bulkNotes, runEach } from './bulk.js';
7
7
  export { ConfirmBody } from './confirm.js';
8
8
  export { FileButton } from './file-button.js';
9
+ export { FormBody } from './form.js';
9
10
  export { Frame } from './frame.js';
10
11
  export { keyFromLabel } from './keys.js';
11
12
  export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
@@ -1,24 +1,22 @@
1
1
  import type { RefObject } from 'react';
2
- /** Settles a run on its list: shows its failure, none when all finished, and focuses the list once an item moved. */
3
- export type RunSettled = (failure: string | undefined, moved: boolean) => void;
2
+ /** Settles a run on its list, focusing the list once an item moved. */
3
+ export type RunSettled = (moved: boolean) => void;
4
4
  /** What a list does around a run over its items. */
5
5
  export interface ListRun {
6
- /** Clears the failure the last run left above the list and returns what settles this run. */
6
+ /** Starts a run on this list and returns what settles it. */
7
7
  onStart: () => RunSettled;
8
8
  }
9
- /** The failure a list shows above its rows, the run its actions start and the region a finished run focuses. */
9
+ /** The run a list's actions start and the region a finished run focuses. */
10
10
  export interface ListRunState {
11
- /** The failure of the last run on this list, absent while none failed. */
12
- failure?: string;
13
- /** What the list does around a run, the same object while the list stays the same. */
11
+ /** What the list does around a run, the same object for as long as the screen stays. */
14
12
  run: ListRun;
15
13
  /** The list region a finished run focuses, handed to `Page` as `listRef`. */
16
14
  region: RefObject<HTMLDivElement | null>;
17
15
  }
18
16
  /**
19
- * Holds the failure shown above one list and the region a finished run focuses, and forgets both when the list changes.
17
+ * Holds the region a finished run focuses, and drops older runs and the ticked rows when the list changes.
20
18
  * @param scope - Names the list on show.
21
19
  * @param onChangeSelection - Replaces the ticked rows, emptied when the list changes.
22
- * @returns The failure on show, the run and the region.
20
+ * @returns The run and the region.
23
21
  */
24
22
  export declare function useListRun(scope: string, onChangeSelection: (selection: string[]) => void): ListRunState;
package/dist/list-run.js CHANGED
@@ -1,13 +1,12 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- import { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
+ import { useLayoutEffect, useRef, useState } from 'react';
3
3
  /**
4
- * Holds the failure shown above one list and the region a finished run focuses, and forgets both when the list changes.
4
+ * Holds the region a finished run focuses, and drops older runs and the ticked rows when the list changes.
5
5
  * @param scope - Names the list on show.
6
6
  * @param onChangeSelection - Replaces the ticked rows, emptied when the list changes.
7
- * @returns The failure on show, the run and the region.
7
+ * @returns The run and the region.
8
8
  */
9
9
  export function useListRun(scope, onChangeSelection) {
10
- const [shown, setShown] = useState({ scope });
11
10
  const region = useRef(null);
12
11
  const latest = useRef(0);
13
12
  const committed = useRef(scope);
@@ -20,24 +19,16 @@ export function useListRun(scope, onChangeSelection) {
20
19
  onChangeSelection([]);
21
20
  }
22
21
  }, [scope, onChangeSelection]);
23
- if (shown.scope !== scope) {
24
- setShown({ scope });
25
- }
26
- const run = useMemo(() => ({
22
+ const [run] = useState(() => ({
27
23
  onStart: () => {
28
24
  latest.current += 1;
29
25
  const id = latest.current;
30
- setShown({ scope });
31
- return (failure, moved) => {
32
- if (latest.current !== id) {
33
- return;
34
- }
35
- setShown({ scope, failure });
36
- if (moved) {
26
+ return (moved) => {
27
+ if (latest.current === id && moved) {
37
28
  region.current?.focus();
38
29
  }
39
30
  };
40
31
  },
41
- }), [scope]);
42
- return { failure: shown.failure, run, region };
32
+ }));
33
+ return { run, region };
43
34
  }
package/dist/rename.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export interface RenameBodyProps {
2
- /** The name the item carries now, the first value of the field. */
2
+ /** The text the field starts with: the name the item carries, or the name a failed write turned away. */
3
3
  name: string;
4
4
  /** The label of the name field. */
5
5
  fieldLabel: string;
@@ -7,18 +7,14 @@ export interface RenameBodyProps {
7
7
  submitLabel: string;
8
8
  /** The label of the button that closes the modal. */
9
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. */
10
+ /** Writes the name as typed, the one the item already has included. */
15
11
  onSubmit: (name: string) => void;
16
12
  /** Closes the modal. */
17
13
  onCancel?: () => void;
18
14
  }
19
15
  /**
20
- * Renders the body of a rename modal: the name field, a failure notice, an accent text Cancel and the submit button.
21
- * @param props - The current name, the labels, the busy flag, the failure and the handlers.
16
+ * Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
17
+ * @param props - The first name, the labels and the handlers.
22
18
  * @returns The rename form.
23
19
  */
24
- export declare function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, busy, failure, onSubmit, onCancel, }: RenameBodyProps): import("react").JSX.Element;
20
+ export declare function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }: RenameBodyProps): import("react").JSX.Element;
package/dist/rename.js CHANGED
@@ -1,20 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Button, InputControl, Stack } from '@wordpress/ui';
3
+ import { InputControl } from '@wordpress/ui';
4
4
  import { useState } from 'react';
5
- import { ErrorNotice } from './page.js';
5
+ import { FormBody } from './form.js';
6
6
  /**
7
- * Renders the body of a rename modal: the name field, a failure notice, an accent text Cancel and the submit button.
8
- * @param props - The current name, the labels, the busy flag, the failure and the handlers.
7
+ * Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
8
+ * @param props - The first name, the labels and the handlers.
9
9
  * @returns The rename form.
10
10
  */
11
- export function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, busy = false, failure, onSubmit, onCancel, }) {
11
+ export function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }) {
12
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 })] })] }) }));
13
+ return (_jsx(FormBody, { submitLabel: submitLabel, cancelLabel: cancelLabel, canSubmit: value.trim() !== '', onSubmit: () => onSubmit(value), onCancel: onCancel, children: _jsx(InputControl, { label: fieldLabel, value: value, onChange: (event) => setValue(event.target.value) }) }));
20
14
  }
@@ -12,7 +12,7 @@ export interface RunConfirmProps<Item> {
12
12
  /** The label of the button that closes the modal. */
13
13
  cancelLabel: string;
14
14
  /** Runs the action over the items, settling once the list shows how it went. */
15
- run: (items: Item[]) => Promise<void>;
15
+ run: (items: Item[]) => Promise<unknown>;
16
16
  }
17
17
  /**
18
18
  * Renders a confirmation that runs the action, keeps Cancel inert while it runs and closes once it settles.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "description": "The admin kit for Gopherium projects: host layer for React admin applications on the WordPress Design System.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",