@gopherium/godmin 0.31.0 → 0.32.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 +2 -3
- package/dist/base.css +9 -16
- package/dist/breakpoints.d.ts +1 -1
- package/dist/breakpoints.js +1 -1
- package/dist/bulk-run.d.ts +10 -0
- package/dist/bulk-run.js +59 -10
- package/dist/bulk.d.ts +3 -0
- package/dist/confirm-dialog.d.ts +14 -14
- package/dist/confirm-dialog.js +8 -28
- package/dist/dialog-open.d.ts +63 -0
- package/dist/dialog-open.js +110 -0
- package/dist/form-dialog.d.ts +14 -16
- package/dist/form-dialog.js +53 -13
- package/dist/index.d.ts +9 -11
- package/dist/index.js +4 -6
- package/dist/list-chrome/fr-FR.js +1 -0
- package/dist/list-run.js +25 -44
- package/dist/rename-dialog.d.ts +24 -0
- package/dist/rename-dialog.js +16 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/toaster.js +21 -2
- package/dist/unsaved-changes-dialog.d.ts +19 -0
- package/dist/unsaved-changes-dialog.js +33 -0
- package/docs/build-and-versioning.md +90 -7
- package/docs/design-system/accessibility.md +5 -3
- package/docs/design-system/dialogs.md +240 -0
- package/docs/design-system/layout.md +1 -1
- package/docs/design-system/lists.md +3 -1
- package/docs/design-system/motion.md +3 -2
- package/docs/design-system/overview.md +4 -1
- package/docs/design-system/record-pages.md +4 -2
- package/docs/design-system/toasts.md +11 -7
- package/docs/lists.md +311 -432
- package/docs/loading-and-feedback.md +11 -6
- package/docs/overview.md +2 -3
- package/docs/screens.md +10 -2
- package/docs/testing.md +11 -9
- package/package.json +1 -9
- package/dist/close-while-open.d.ts +0 -6
- package/dist/close-while-open.js +0 -21
- package/dist/confirm.d.ts +0 -21
- package/dist/confirm.js +0 -11
- package/dist/dialogs.d.ts +0 -4
- package/dist/dialogs.js +0 -3
- package/dist/form.d.ts +0 -28
- package/dist/form.js +0 -23
- package/dist/rename.d.ts +0 -20
- package/dist/rename.js +0 -14
- package/dist/run-confirm.d.ts +0 -22
- package/dist/run-confirm.js +0 -23
package/dist/index.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
export { AdminRoot } from './admin-root.js';
|
|
3
3
|
export { InitialsAvatar } from './avatar.js';
|
|
4
4
|
export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, HUGE_BREAKPOINT, SHEET_BREAKPOINT, SIDEBAR_BREAKPOINT, SMALL_VIEWPORT, TITLE_BREAKPOINT, } from './breakpoints.js';
|
|
5
|
-
export { useBulkRun } from './bulk-run.js';
|
|
5
|
+
export { useBulkRun, useDialogRun } from './bulk-run.js';
|
|
6
6
|
export { bulkNotes, runEach } from './bulk.js';
|
|
7
|
-
export {
|
|
8
|
-
export { ConfirmBody } from './confirm.js';
|
|
7
|
+
export { ConfirmDialog } from './confirm-dialog.js';
|
|
9
8
|
export { FileButton } from './file-button.js';
|
|
10
9
|
export { focusedTrigger, useFocusBack } from './focus-back.js';
|
|
11
|
-
export {
|
|
10
|
+
export { FormDialog } from './form-dialog.js';
|
|
12
11
|
export { Frame } from './frame.js';
|
|
13
12
|
export { keyFromLabel } from './keys.js';
|
|
14
13
|
export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
|
|
@@ -22,10 +21,9 @@ export { openOnTap } from './open-on-tap.js';
|
|
|
22
21
|
export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js';
|
|
23
22
|
export { PageBreadcrumb, PageBreadcrumbs } from './page-breadcrumbs.js';
|
|
24
23
|
export { PageTab, PageTabs } from './page-tabs.js';
|
|
25
|
-
export {
|
|
24
|
+
export { RenameDialog } from './rename-dialog.js';
|
|
26
25
|
export { useRowKeys } from './row-keys.js';
|
|
27
26
|
export { RepeatRows, RowControls } from './rows.js';
|
|
28
|
-
export { RunConfirm } from './run-confirm.js';
|
|
29
27
|
export { offeredSize, pageWindow, paginationOf, sizedView, useServerPaging } from './server-page.js';
|
|
30
28
|
export { Toaster, useToaster } from './toaster.js';
|
|
31
29
|
export { markLatest, useUnsavedText } from './unsaved-text.js';
|
package/dist/list-run.js
CHANGED
|
@@ -5,14 +5,14 @@ import { HOLDERS, itemAt, triggerOnItem } from './focus-back.js';
|
|
|
5
5
|
const DIALOG_IN_FOCUS = '[role="dialog"]:focus-within, [role="alertdialog"]:focus-within';
|
|
6
6
|
/** Finds a part that turned inert while it holds the focus. */
|
|
7
7
|
const INERT_IN_FOCUS = '[inert]:focus-within';
|
|
8
|
-
/** Finds a dialog or an alert dialog
|
|
8
|
+
/** Finds a dialog or an alert dialog. */
|
|
9
9
|
const DIALOG = '[role="dialog"], [role="alertdialog"]';
|
|
10
|
+
/** Finds the toast region, which takes the focus a leaving toast held. */
|
|
11
|
+
const TOAST_REGION = '.godmin-toasts';
|
|
10
12
|
/** Finds every control a reader can focus inside a card or a row. */
|
|
11
13
|
const CONTROLS = 'a[href], button, input, select, textarea, [tabindex]';
|
|
12
14
|
/** Finds a button of a row that runs an action, never the actions menu button, which only opens a menu. */
|
|
13
15
|
const ACTION_BUTTON = '.dataviews-item-actions button:not(.dataviews-all-actions-button)';
|
|
14
|
-
/** Stops nothing, for a run that watches no focus. */
|
|
15
|
-
function stopNothing() { }
|
|
16
16
|
/**
|
|
17
17
|
* Counts the reloads a list has open, each ended once, and drops them all when the list changes.
|
|
18
18
|
* @returns Whether a reload is open, and how to start one or drop them all.
|
|
@@ -50,33 +50,13 @@ export function focusInDialog() {
|
|
|
50
50
|
return document.querySelector(DIALOG_IN_FOCUS) !== null;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Reports whether the dialog a run started in has left the page while the focus sits on the control that opened it.
|
|
54
54
|
* @param startedIn - The dialog that held the focus as the run started, none for a run started outside every dialog.
|
|
55
|
-
* @
|
|
55
|
+
* @param openedBy - The control that opened each dialog.
|
|
56
|
+
* @returns Whether that dialog has gone and the focus sits on that control.
|
|
56
57
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
if (startedIn === null) {
|
|
60
|
-
return landing;
|
|
61
|
-
}
|
|
62
|
-
const note = (event) => {
|
|
63
|
-
if (startedIn.isConnected && !startedIn.contains(event.target)) {
|
|
64
|
-
landing.element = event.target;
|
|
65
|
-
landing.stop();
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
document.addEventListener('focusin', note, true);
|
|
69
|
-
landing.stop = () => document.removeEventListener('focusin', note, true);
|
|
70
|
-
return landing;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Reports whether the dialog a run started in has closed while the focus stays where it first landed, in no dialog.
|
|
74
|
-
* @param startedIn - The dialog that held the focus as the run started, none for a run started outside every dialog.
|
|
75
|
-
* @param landed - The element the focus first landed on outside that dialog, none while it never did.
|
|
76
|
-
* @returns Whether that dialog has gone and the focus stays on the element it handed the focus back to.
|
|
77
|
-
*/
|
|
78
|
-
function stillWhereDialogLeftIt(startedIn, landed) {
|
|
79
|
-
return startedIn?.isConnected === false && document.activeElement === landed && !focusInDialog();
|
|
58
|
+
function stillWhereDialogLeftIt(startedIn, openedBy) {
|
|
59
|
+
return startedIn?.isConnected === false && document.activeElement === openedBy.get(startedIn);
|
|
80
60
|
}
|
|
81
61
|
/**
|
|
82
62
|
* Moves the focus to the list region, scrolling nothing, when it sits in a part of that list that turned inert.
|
|
@@ -138,32 +118,38 @@ function putBack(list, place) {
|
|
|
138
118
|
}
|
|
139
119
|
}
|
|
140
120
|
/**
|
|
141
|
-
* Notes the
|
|
121
|
+
* Notes what the focus leaves for a dialog: the control that opened it, and its place when it stands in the list.
|
|
142
122
|
* @param region - The list region, none while the screen draws no list.
|
|
143
|
-
* @param opener - Where the
|
|
123
|
+
* @param opener - Where the place goes, none once the focus leaves the list for anything but a dialog.
|
|
124
|
+
* @param openedBy - Where the control goes, the first one only for each dialog.
|
|
144
125
|
* @returns What stops noting.
|
|
145
126
|
*/
|
|
146
|
-
function noteOpener(region, opener) {
|
|
127
|
+
function noteOpener(region, opener, openedBy) {
|
|
147
128
|
const note = (event) => {
|
|
148
129
|
const list = region.current;
|
|
130
|
+
const dialog = event.relatedTarget?.closest(DIALOG);
|
|
149
131
|
if (list?.contains(event.target)) {
|
|
150
|
-
opener.current =
|
|
132
|
+
opener.current = dialog ? placeOf(list, event.target) : null;
|
|
133
|
+
}
|
|
134
|
+
if (dialog && !event.target.closest(DIALOG)) {
|
|
135
|
+
openedBy.set(dialog, openedBy.get(dialog) ?? event.target);
|
|
151
136
|
}
|
|
152
137
|
};
|
|
153
138
|
document.addEventListener('focusout', note, true);
|
|
154
139
|
return () => document.removeEventListener('focusout', note, true);
|
|
155
140
|
}
|
|
156
141
|
/**
|
|
157
|
-
* Reports whether the focus sits on the page,
|
|
142
|
+
* Reports whether the focus sits on the page, the toast region, the list, the dialog that ran, or where it left it.
|
|
158
143
|
* @param list - The list region, none while the screen draws no list.
|
|
159
144
|
* @param startedIn - The dialog that held the focus as the run started, none for a run started outside every dialog.
|
|
160
|
-
* @param
|
|
145
|
+
* @param openedBy - The control that opened each dialog.
|
|
161
146
|
* @returns Whether a finished run may move the focus to the list.
|
|
162
147
|
*/
|
|
163
|
-
function readerOnList(list, startedIn,
|
|
148
|
+
function readerOnList(list, startedIn, openedBy) {
|
|
164
149
|
const active = document.activeElement;
|
|
165
150
|
const holds = [list, startedIn].some((holder) => holder !== null && holder.contains(active));
|
|
166
|
-
|
|
151
|
+
const leftByToast = active?.matches(TOAST_REGION) === true;
|
|
152
|
+
return active === document.body || leftByToast || holds || stillWhereDialogLeftIt(startedIn, openedBy);
|
|
167
153
|
}
|
|
168
154
|
/**
|
|
169
155
|
* Holds the region a run focuses, gives its focus back once the list reloaded, and drops old runs on a list change.
|
|
@@ -174,15 +160,14 @@ function readerOnList(list, startedIn, landed) {
|
|
|
174
160
|
export function useListRun(scope, onChangeSelection) {
|
|
175
161
|
const region = useRef(null);
|
|
176
162
|
const latest = useRef(0);
|
|
177
|
-
const watching = useRef(stopNothing);
|
|
178
163
|
const committed = useRef(scope);
|
|
179
164
|
const place = useRef(null);
|
|
180
165
|
const opener = useRef(null);
|
|
166
|
+
const [openedBy] = useState(() => new WeakMap());
|
|
181
167
|
const [refreshing, reloads] = useReloads();
|
|
182
|
-
useLayoutEffect(() => noteOpener(region, opener), []);
|
|
168
|
+
useLayoutEffect(() => noteOpener(region, opener, openedBy), [openedBy]);
|
|
183
169
|
useLayoutEffect(() => {
|
|
184
170
|
latest.current += 1;
|
|
185
|
-
return () => watching.current();
|
|
186
171
|
}, [scope]);
|
|
187
172
|
useLayoutEffect(() => {
|
|
188
173
|
if (committed.current !== scope) {
|
|
@@ -202,15 +187,11 @@ export function useListRun(scope, onChangeSelection) {
|
|
|
202
187
|
}, [refreshing]);
|
|
203
188
|
const [run] = useState(() => ({
|
|
204
189
|
onStart: () => {
|
|
205
|
-
watching.current();
|
|
206
190
|
latest.current += 1;
|
|
207
191
|
const id = latest.current;
|
|
208
192
|
const startedIn = document.querySelector(DIALOG_IN_FOCUS);
|
|
209
193
|
place.current = startedIn === null ? null : opener.current;
|
|
210
|
-
const landing = watchLanding(startedIn);
|
|
211
|
-
watching.current = landing.stop;
|
|
212
194
|
return (moved) => {
|
|
213
|
-
landing.stop();
|
|
214
195
|
if (latest.current !== id) {
|
|
215
196
|
return;
|
|
216
197
|
}
|
|
@@ -218,7 +199,7 @@ export function useListRun(scope, onChangeSelection) {
|
|
|
218
199
|
place.current = null;
|
|
219
200
|
return;
|
|
220
201
|
}
|
|
221
|
-
if (readerOnList(region.current, startedIn,
|
|
202
|
+
if (readerOnList(region.current, startedIn, openedBy)) {
|
|
222
203
|
place.current ??= placeOf(region.current, document.activeElement);
|
|
223
204
|
region.current?.focus({ preventScroll: true });
|
|
224
205
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DialogAnswer } from './dialog-open.js';
|
|
2
|
+
/** The props of a dialog that asks for a new name for one item. */
|
|
3
|
+
export interface RenameDialogProps {
|
|
4
|
+
/** The title in the dialog header, the name of the dialog. */
|
|
5
|
+
title: string;
|
|
6
|
+
/** The text the field starts with, the name the item carries. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The label of the name field. */
|
|
9
|
+
fieldLabel: string;
|
|
10
|
+
/** The label of the button that writes the new name. */
|
|
11
|
+
submitLabel: string;
|
|
12
|
+
/** The label of the button that closes the dialog. */
|
|
13
|
+
cancelLabel: string;
|
|
14
|
+
/** Writes the name as typed. Return nothing to close at once, the write to hold the dialog, or an answer to stay. */
|
|
15
|
+
onSubmit: (name: string) => void | DialogAnswer | PromiseLike<unknown>;
|
|
16
|
+
/** Takes the dialog away, once its card has left the page. */
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders a dialog that asks for a new name, Save on at all times and the browser refusing a blank name.
|
|
21
|
+
* @param props - The title, the current name, the labels and the handlers.
|
|
22
|
+
* @returns The dialog.
|
|
23
|
+
*/
|
|
24
|
+
export declare function RenameDialog({ title, name, fieldLabel, submitLabel, cancelLabel, onSubmit, onClose, }: RenameDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { InputControl } from '@wordpress/ui';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { FormDialog } from './form-dialog.js';
|
|
6
|
+
/** The pattern a name must match: any text that holds more than spaces. */
|
|
7
|
+
const NOT_ONLY_SPACES = '.*\\S.*';
|
|
8
|
+
/**
|
|
9
|
+
* Renders a dialog that asks for a new name, Save on at all times and the browser refusing a blank name.
|
|
10
|
+
* @param props - The title, the current name, the labels and the handlers.
|
|
11
|
+
* @returns The dialog.
|
|
12
|
+
*/
|
|
13
|
+
export function RenameDialog({ title, name, fieldLabel, submitLabel, cancelLabel, onSubmit, onClose, }) {
|
|
14
|
+
const [value, setValue] = useState(name);
|
|
15
|
+
return (_jsx(FormDialog, { title: title, submitLabel: submitLabel, cancelLabel: cancelLabel, onSubmit: () => onSubmit(value), onClose: onClose, children: (busy) => (_jsx(InputControl, { label: fieldLabel, value: value, required: true, pattern: NOT_ONLY_SPACES, readOnly: busy, onChange: (event) => setValue(event.target.value) })) }));
|
|
16
|
+
}
|
package/dist/router.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export { NavigationItem } from './navigation-item.js';
|
|
|
12
12
|
export type { NavigationItemProps } from './navigation-item.js';
|
|
13
13
|
export { NavigationList } from './navigation-list.js';
|
|
14
14
|
export type { NavigationListProps } from './navigation-list.js';
|
|
15
|
+
export { UnsavedChangesDialog } from './unsaved-changes-dialog.js';
|
|
16
|
+
export type { UnsavedChangesDialogProps } from './unsaved-changes-dialog.js';
|
|
15
17
|
declare module '@tanstack/react-router' {
|
|
16
18
|
interface StaticDataRouteOption {
|
|
17
19
|
canvas?: CanvasMode;
|
package/dist/router.js
CHANGED
|
@@ -6,6 +6,7 @@ export { useCanAccess } from './menu-item.js';
|
|
|
6
6
|
export { Navigation } from './navigation.js';
|
|
7
7
|
export { NavigationItem } from './navigation-item.js';
|
|
8
8
|
export { NavigationList } from './navigation-list.js';
|
|
9
|
+
export { UnsavedChangesDialog } from './unsaved-changes-dialog.js';
|
|
9
10
|
/**
|
|
10
11
|
* Returns the canvas the deepest matching route asks for.
|
|
11
12
|
* @returns The canvas mode, padded when no route asks for one.
|
package/dist/toaster.js
CHANGED
|
@@ -117,6 +117,21 @@ function ToastItem({ toast, region, onGone, children }) {
|
|
|
117
117
|
const item = toast.leaving ? 'godmin-toasts__item godmin-toasts__item--leaving' : 'godmin-toasts__item';
|
|
118
118
|
return (_jsx("div", { ref: ref, className: item, children: _jsx("div", { className: "godmin-toasts__item-inner", children: children }) }));
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Keeps a press on a leaving toast from moving the focus onto it.
|
|
122
|
+
* @param event - The press.
|
|
123
|
+
*/
|
|
124
|
+
function holdFocus(event) {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns what a toast takes while it fades out.
|
|
129
|
+
* @param leaving - Whether the toast is fading out.
|
|
130
|
+
* @returns The props, none for a toast that stays.
|
|
131
|
+
*/
|
|
132
|
+
function leavingProps(leaving) {
|
|
133
|
+
return leaving ? { 'aria-hidden': true, tabIndex: -1, onMouseDown: holdFocus } : {};
|
|
134
|
+
}
|
|
120
135
|
/**
|
|
121
136
|
* Renders a toast with no action as one button that clears it, described by the dismiss hint.
|
|
122
137
|
* @param props - The toast, how long it stays, the id of the dismiss hint and the handler clearing it.
|
|
@@ -124,7 +139,7 @@ function ToastItem({ toast, region, onGone, children }) {
|
|
|
124
139
|
*/
|
|
125
140
|
function PlainToast({ toast, dismissAfter, hint, onLeave }) {
|
|
126
141
|
useExpiry(toast, dismissAfter, onLeave);
|
|
127
|
-
return (_jsx("button", { type: "button", className: toastClass('godmin-toast godmin-toast--plain', toast.leaving), "aria-describedby": hint,
|
|
142
|
+
return (_jsx("button", { type: "button", className: toastClass('godmin-toast godmin-toast--plain', toast.leaving), "aria-describedby": hint, ...leavingProps(toast.leaving), onClick: () => onLeave(toast.id), children: toast.message }));
|
|
128
143
|
}
|
|
129
144
|
/**
|
|
130
145
|
* Renders a toast with its action, cleared by a click anywhere on it, the action its only control.
|
|
@@ -133,7 +148,11 @@ function PlainToast({ toast, dismissAfter, hint, onLeave }) {
|
|
|
133
148
|
*/
|
|
134
149
|
function ActionToast({ toast, action, dismissAfter, onLeave }) {
|
|
135
150
|
useExpiry(toast, dismissAfter, onLeave);
|
|
136
|
-
|
|
151
|
+
const { tabIndex, ...hidden } = leavingProps(toast.leaving);
|
|
152
|
+
return (_jsxs("div", { className: toastClass('godmin-toast', toast.leaving), ...hidden, onClick: () => onLeave(toast.id), children: [_jsx("span", { className: "godmin-toast__message", children: toast.message }), _jsx("button", { type: "button", className: "godmin-toast__action", tabIndex: tabIndex, onClick: () => {
|
|
153
|
+
if (toast.leaving) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
137
156
|
onLeave(toast.id);
|
|
138
157
|
action.onAct();
|
|
139
158
|
}, children: action.label })] }));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The props of the dialog that asks before a move leaves a page holding unsaved work. */
|
|
2
|
+
export interface UnsavedChangesDialogProps {
|
|
3
|
+
/** Whether the page holds unsaved work, so a move away asks first. */
|
|
4
|
+
when: boolean;
|
|
5
|
+
/** The question, such as "Discard changes?". */
|
|
6
|
+
title: string;
|
|
7
|
+
/** What the reader loses, such as "Your changes are not saved.". */
|
|
8
|
+
description: string;
|
|
9
|
+
/** The label of the red button that drops the work and leaves. */
|
|
10
|
+
discardLabel: string;
|
|
11
|
+
/** The label of the button that stays with the work. */
|
|
12
|
+
keepLabel: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Renders an irreversible confirm while a move away from a page holding unsaved work waits on the reader.
|
|
16
|
+
* @param props - When to ask, and the words of the question and its buttons.
|
|
17
|
+
* @returns The confirm while a move waits, otherwise nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function UnsavedChangesDialog({ when, title, description, discardLabel, keepLabel }: UnsavedChangesDialogProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { useBlocker } from '@tanstack/react-router';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
import { ConfirmDialog } from './confirm-dialog.js';
|
|
6
|
+
/**
|
|
7
|
+
* Reports whether a move leaves the page, and not only changes its search.
|
|
8
|
+
* @param move - Where the reader is and where the move goes.
|
|
9
|
+
* @returns True when the move goes to another path.
|
|
10
|
+
*/
|
|
11
|
+
function leavesPage({ current, next }) {
|
|
12
|
+
return current.pathname !== next.pathname;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Renders an irreversible confirm while a move away from a page holding unsaved work waits on the reader.
|
|
16
|
+
* @param props - When to ask, and the words of the question and its buttons.
|
|
17
|
+
* @returns The confirm while a move waits, otherwise nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function UnsavedChangesDialog({ when, title, description, discardLabel, keepLabel }) {
|
|
20
|
+
const discarding = useRef(false);
|
|
21
|
+
const leaving = useBlocker({ shouldBlockFn: leavesPage, disabled: !when, withResolver: true });
|
|
22
|
+
if (leaving.status !== 'blocked') {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const { proceed, reset } = leaving;
|
|
26
|
+
return (_jsx(ConfirmDialog, { intent: "irreversible", title: title, description: description, confirmLabel: discardLabel, cancelLabel: keepLabel, onConfirm: () => {
|
|
27
|
+
discarding.current = true;
|
|
28
|
+
}, onClose: () => {
|
|
29
|
+
const settle = discarding.current ? proceed : reset;
|
|
30
|
+
discarding.current = false;
|
|
31
|
+
settle();
|
|
32
|
+
} }));
|
|
33
|
+
}
|
|
@@ -87,19 +87,102 @@ in the peer ranges of godmin's `package.json`.
|
|
|
87
87
|
|
|
88
88
|
`@wordpress/i18n` is a required peer, because the main entry
|
|
89
89
|
translates godmin's own words. `@wordpress/date` is an optional peer,
|
|
90
|
-
needed only by `@gopherium/godmin/dates`.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
you use its entry. Load the components stylesheet once in your
|
|
94
|
-
application, `@wordpress/components/build-style/style.css`, as
|
|
95
|
-
DataViews already asks. godmin never imports it. Their windows are in
|
|
96
|
-
the same peer ranges.
|
|
90
|
+
needed only by `@gopherium/godmin/dates`. Install it next to godmin
|
|
91
|
+
when you use that entry. Its window is in the same peer ranges.
|
|
92
|
+
godmin never imports `@wordpress/components`.
|
|
97
93
|
|
|
98
94
|
`@wordpress/dataviews` is an optional peer as well, in the window
|
|
99
95
|
`>=21.0.0 <22.0.0`. No godmin entry imports it, but `offeredView`
|
|
100
96
|
follows the filter rules of that DataViews release. A list built on
|
|
101
97
|
another release gets a peer warning when it installs godmin.
|
|
102
98
|
|
|
99
|
+
## Upgrading from godmin 0.31.0
|
|
100
|
+
|
|
101
|
+
godmin 0.32.0 draws `ConfirmDialog` on the alert dialog of the design
|
|
102
|
+
system and `FormDialog` on its dialog, a confirm or a form on a list
|
|
103
|
+
becomes a dialog your screen renders, and the dialogs move to the main
|
|
104
|
+
entry. Change your code in these places:
|
|
105
|
+
|
|
106
|
+
- `@gopherium/godmin/dialogs` is gone. Import `ConfirmDialog`,
|
|
107
|
+
`FormDialog`, `DialogAnswer` and their props types from
|
|
108
|
+
`@gopherium/godmin`. godmin no longer has `@wordpress/components` as
|
|
109
|
+
a peer. An app that draws DataViews keeps it, since DataViews needs
|
|
110
|
+
it.
|
|
111
|
+
- `ConfirmDialog` takes the question as `title` and what will happen
|
|
112
|
+
as `description`, in place of `children`. `size` is gone, since a
|
|
113
|
+
confirm has one width and is a card at every width. Pass
|
|
114
|
+
`intent="irreversible"` for an action that cannot be undone, which
|
|
115
|
+
draws its button red.
|
|
116
|
+
- `RunConfirm`, `ConfirmBody`, `RunConfirmProps` and
|
|
117
|
+
`ConfirmBodyProps` are gone. Give the list action a `callback` that
|
|
118
|
+
stores the rows, drop its `RenderModal`, `hideModalHeader` and
|
|
119
|
+
`modalFocusOnMount`, and render a `ConfirmDialog` from your screen
|
|
120
|
+
whose `onConfirm` returns the run, as
|
|
121
|
+
[running an action over the picked rows](./lists.md#running-an-action-over-the-picked-rows)
|
|
122
|
+
shows.
|
|
123
|
+
- `FormBody`, `FormKind`, `RenameBody`, `useCloseWhileOpen`,
|
|
124
|
+
`FormBodyProps` and `RenameBodyProps` are gone. Give the row action a
|
|
125
|
+
`callback` that stores the rows, drop its `RenderModal`,
|
|
126
|
+
`modalHeader`, `modalSize` and `modalFocusOnMount`, and render a
|
|
127
|
+
`FormDialog` or a `RenameDialog` from your screen whose `onSubmit`
|
|
128
|
+
returns the write of `useDialogRun`, as
|
|
129
|
+
[renaming an item](./lists.md#renaming-an-item) shows. Stop closing
|
|
130
|
+
the dialog before its write.
|
|
131
|
+
- A rename keeps Save on with a blank field, and the browser refuses
|
|
132
|
+
the send. A test that read Save off reads that a press on it sends
|
|
133
|
+
nothing.
|
|
134
|
+
- A confirm is now an `alertdialog`. A test that finds it by the role
|
|
135
|
+
`dialog` finds it by `alertdialog`.
|
|
136
|
+
- A confirm has no close button now, even with a `title`. A test that
|
|
137
|
+
pressed its close button presses Cancel instead.
|
|
138
|
+
- `onClose` runs once the card has left the page, not at the press.
|
|
139
|
+
A test that reads the dialog gone, or `onClose` called, right after
|
|
140
|
+
a press waits for it, such as with `waitFor`.
|
|
141
|
+
- Escape and Cancel close nothing while the write runs, and a click on
|
|
142
|
+
the dimmed page never closes a confirm. A test that dismissed a busy
|
|
143
|
+
confirm, or clicked outside one, lets the write end or presses
|
|
144
|
+
Cancel instead. Give a write that can hang a timeout.
|
|
145
|
+
- A promise that rejects, or a handler that throws, leaves the confirm
|
|
146
|
+
open, and the error still goes on to your app. To close it, catch
|
|
147
|
+
the failure inside `onConfirm` and show it in a toast, as
|
|
148
|
+
[a failure from a dialog](./lists.md#a-failure-from-a-dialog) shows.
|
|
149
|
+
- A handler that returns, or a promise that ends with, an object
|
|
150
|
+
whose `error` holds words, or whose `close` is `false`, now keeps
|
|
151
|
+
the confirm open. Turn such an answer into one that closes when your
|
|
152
|
+
app wants it to close.
|
|
153
|
+
- Any object with a `then` method now counts as a promise, so the
|
|
154
|
+
confirm waits for it. Before, it waited only for a real `Promise`
|
|
155
|
+
and closed at once for anything else.
|
|
156
|
+
- A stylesheet that styles `.godmin-modal-body`, its `--copy` and
|
|
157
|
+
`--create` forms, or `.godmin-modal-body__question` styles nothing
|
|
158
|
+
now.
|
|
159
|
+
- `FormDialog` has no `kind` and no `size`. It has one width, it is a
|
|
160
|
+
card at every width, and its footer sets the space above its
|
|
161
|
+
buttons.
|
|
162
|
+
- `FormDialog` closes itself. Return nothing from `onSubmit` to close
|
|
163
|
+
at once, or the write's promise to close when it ends, and stop
|
|
164
|
+
closing it from your handler. Take it away in `onClose`, which runs
|
|
165
|
+
once the card has left the page.
|
|
166
|
+
- A form write that fails shows inside the dialog. Answer `{ error }`
|
|
167
|
+
with words from `onSubmit`, in place of a toast, as
|
|
168
|
+
[a failure from a dialog](./lists.md#a-failure-from-a-dialog) shows.
|
|
169
|
+
A promise that rejects, or a handler that throws, leaves the form
|
|
170
|
+
dialog open, and the error still goes on to your app.
|
|
171
|
+
- Cancel, the close icon, Escape and a click on the dimmed page close
|
|
172
|
+
nothing while a form writes. A test that dismissed a busy form
|
|
173
|
+
dialog lets the write end instead.
|
|
174
|
+
- The close button of a form dialog is now a close icon named "Close"
|
|
175
|
+
beside the title, and Cancel draws an outline.
|
|
176
|
+
- The send button of a form dialog sits in the footer, outside the
|
|
177
|
+
form, and names it. user-event in jsdom finds no send button for
|
|
178
|
+
Enter there, so a test that typed Enter in a field presses the send
|
|
179
|
+
button instead, or runs in a browser.
|
|
180
|
+
|
|
181
|
+
TypeScript points at `children`, `size`, `kind`, `RunConfirm`,
|
|
182
|
+
`ConfirmBody`, `FormBody`, `RenameBody`, `useCloseWhileOpen` and each
|
|
183
|
+
import from `@gopherium/godmin/dialogs`. The rest changes what the
|
|
184
|
+
reader sees and when `onClose` runs.
|
|
185
|
+
|
|
103
186
|
## Upgrading from godmin 0.27.0
|
|
104
187
|
|
|
105
188
|
godmin 0.28.0 draws toasts as WordPress's new admin draws its
|
|
@@ -124,8 +124,8 @@ where they are and a screen reader has a control to name, or stays on
|
|
|
124
124
|
the region when that control is a primary action.
|
|
125
125
|
|
|
126
126
|
Dialogs move focus as they open and close, as
|
|
127
|
-
[
|
|
128
|
-
[a form dialog](../lists.md#a-form-dialog) explain. When the list
|
|
127
|
+
[keyboard and focus](./dialogs.md#keyboard-and-focus) on the dialogs
|
|
128
|
+
page and [a form dialog](../lists.md#a-form-dialog) explain. When the list
|
|
129
129
|
drew the row a dialog opened from anew while the dialog was open,
|
|
130
130
|
`useFocusBack` puts the focus back on that row, or on the list once
|
|
131
131
|
the row left it, as
|
|
@@ -167,7 +167,9 @@ its highlight from that mark, so what the eye sees and what a screen
|
|
|
167
167
|
reader hears always match. A page tab draws its underline from its
|
|
168
168
|
`current` prop, which sets the same mark. A router link can set the
|
|
169
169
|
mark on its own too, so [PageTabs](../screens.md#pagetabs) says how
|
|
170
|
-
to keep the underline and the mark in step.
|
|
170
|
+
to keep the underline and the mark in step. A breadcrumb never carries
|
|
171
|
+
the mark, and [PageBreadcrumbs](../screens.md#pagebreadcrumbs) says how
|
|
172
|
+
to keep a router link from setting it.
|
|
171
173
|
|
|
172
174
|
Some screen readers stop treating a list with no bullets as a list.
|
|
173
175
|
So the sidebar rows, the page tabs and a log list keep
|