@gopherium/godmin 0.21.0 → 0.22.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 CHANGED
@@ -52,12 +52,12 @@ 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, `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`, `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
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 |
59
59
  | `@gopherium/godmin/router` | `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, the `canvas` route static data |
60
- | `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses`, `stubLayout` |
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` |
62
62
  | `@gopherium/godmin/stylelint` | The design system stylelint rules |
63
63
 
@@ -10,6 +10,14 @@ export declare const EDGE_BREAKPOINT = 782;
10
10
  * The viewport width below which the canvas gutter narrows to 16px.
11
11
  */
12
12
  export declare const DENSE_BREAKPOINT = 640;
13
+ /**
14
+ * The viewport width below which modals rise as sheets and toasts widen to the screen, the WordPress small breakpoint.
15
+ */
16
+ export declare const SHEET_BREAKPOINT = 600;
17
+ /**
18
+ * The viewport width below which an editor header drops its document title, as the WordPress editor does.
19
+ */
20
+ export declare const TITLE_BREAKPOINT = 404;
13
21
  /**
14
22
  * The media query the frame folds its rail at.
15
23
  */
@@ -10,6 +10,14 @@ export const EDGE_BREAKPOINT = 782;
10
10
  * The viewport width below which the canvas gutter narrows to 16px.
11
11
  */
12
12
  export const DENSE_BREAKPOINT = 640;
13
+ /**
14
+ * The viewport width below which modals rise as sheets and toasts widen to the screen, the WordPress small breakpoint.
15
+ */
16
+ export const SHEET_BREAKPOINT = 600;
17
+ /**
18
+ * The viewport width below which an editor header drops its document title, as the WordPress editor does.
19
+ */
20
+ export const TITLE_BREAKPOINT = 404;
13
21
  /**
14
22
  * The media query the frame folds its rail at.
15
23
  */
@@ -5,6 +5,8 @@ export interface ConfirmDialogProps {
5
5
  children: ReactNode;
6
6
  /** The title of a plain confirm, drawn in a header with a close button, none on a confirm that removes something. */
7
7
  title?: string;
8
+ /** The width of the card from 600px up, small at 400px or medium at 560px, the default. */
9
+ size?: 'small' | 'medium';
8
10
  /** The label of the button that carries the action out. */
9
11
  confirmLabel: string;
10
12
  /** The label of the button that closes the dialog. */
@@ -16,7 +18,7 @@ export interface ConfirmDialogProps {
16
18
  }
17
19
  /**
18
20
  * Renders a confirmation dialog for an action outside a list, as WordPress dialogs ask, Cancel focused.
19
- * @param props - The question, the title, the labels and the handlers.
21
+ * @param props - The question, the title, the size, the labels and the handlers.
20
22
  * @returns The dialog.
21
23
  */
22
- export declare function ConfirmDialog({ children, title, confirmLabel, cancelLabel, onConfirm, onClose }: ConfirmDialogProps): import("react").JSX.Element;
24
+ export declare function ConfirmDialog({ children, title, size, confirmLabel, cancelLabel, onConfirm, onClose, }: ConfirmDialogProps): import("react").JSX.Element;
@@ -5,10 +5,10 @@ import { useId, 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.
8
- * @param props - The question, the title, the labels and the handlers.
8
+ * @param props - The question, the title, the size, the labels and the handlers.
9
9
  * @returns The dialog.
10
10
  */
11
- export function ConfirmDialog({ children, title, confirmLabel, cancelLabel, onConfirm, onClose }) {
11
+ export function ConfirmDialog({ children, title, size = 'medium', confirmLabel, cancelLabel, onConfirm, onClose, }) {
12
12
  const [busy, setBusy] = useState(false);
13
13
  const [failure, setFailure] = useState();
14
14
  const question = useId();
@@ -28,5 +28,5 @@ export function ConfirmDialog({ children, title, confirmLabel, cancelLabel, onCo
28
28
  }
29
29
  setFailure(failed);
30
30
  };
31
- return (_jsx(Modal, { size: "medium", 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 }) }) }));
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 }) }) }));
32
32
  }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { AdminRoot } from './admin-root.js';
2
2
  export type { AdminRootProps } from './admin-root.js';
3
3
  export { InitialsAvatar } from './avatar.js';
4
4
  export type { InitialsAvatarProps } from './avatar.js';
5
- export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
5
+ export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SHEET_BREAKPOINT, SMALL_VIEWPORT, TITLE_BREAKPOINT, } from './breakpoints.js';
6
6
  export { useBulkRun } from './bulk-run.js';
7
7
  export type { BulkRun } from './bulk-run.js';
8
8
  export { bulkNotes, runEach } from './bulk.js';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  export { AdminRoot } from './admin-root.js';
3
3
  export { InitialsAvatar } from './avatar.js';
4
- export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SMALL_VIEWPORT } from './breakpoints.js';
4
+ export { DENSE_BREAKPOINT, EDGE_BREAKPOINT, RAIL_BREAKPOINT, SHEET_BREAKPOINT, SMALL_VIEWPORT, TITLE_BREAKPOINT, } from './breakpoints.js';
5
5
  export { useBulkRun } from './bulk-run.js';
6
6
  export { bulkNotes, runEach } from './bulk.js';
7
7
  export { ConfirmBody } from './confirm.js';
package/dist/testing.d.ts CHANGED
@@ -30,12 +30,18 @@ export type LoadModule = () => Promise<Record<string, unknown>>;
30
30
  */
31
31
  export declare function assertElementPatched(load?: LoadModule): Promise<void>;
32
32
  /**
33
- * Sets what every media query reports, and tells its listeners.
34
- * @param viewport - Whether queries should report a match.
33
+ * What the media queries report: one answer for every query, or each width query answered by a width in pixels.
35
34
  */
36
- export declare function setViewport(viewport: {
35
+ export type TestViewport = {
37
36
  matches: boolean;
38
- }): void;
37
+ } | {
38
+ width: number;
39
+ };
40
+ /**
41
+ * Sets what the media queries report, and tells their listeners.
42
+ * @param next - Whether every query reports a match, or the width in pixels the width queries are answered by.
43
+ */
44
+ export declare function setViewport(next: TestViewport): void;
39
45
  /**
40
46
  * Makes every element report one layout box until the test ends, as a browser does for an element on screen.
41
47
  */
package/dist/testing.js CHANGED
@@ -56,19 +56,27 @@ export async function assertElementPatched(load = () => import('@wordpress/eleme
56
56
  }
57
57
  }
58
58
  /**
59
- * Whether every media query currently reports a match.
59
+ * The viewport the media queries currently read.
60
60
  */
61
- let viewportMatches = false;
61
+ let viewport = { matches: false };
62
62
  /**
63
63
  * The listeners registered on the media query lists handed out so far.
64
64
  */
65
65
  const viewportListeners = new Set();
66
66
  /**
67
- * Sets what every media query reports, and tells its listeners.
68
- * @param viewport - Whether queries should report a match.
67
+ * One width condition of a media query, such as `(max-width: 599px)`.
69
68
  */
70
- export function setViewport(viewport) {
71
- viewportMatches = viewport.matches;
69
+ const WIDTH_CONDITION = /^\(\s*(min|max)-width\s*:\s*(\d+(?:\.\d+)?)px\s*\)$/;
70
+ /**
71
+ * The media types a screen matches, such as `screen` or `only all`.
72
+ */
73
+ const SCREEN_MEDIA = /^(?:only\s+)?(?:all|screen)$/;
74
+ /**
75
+ * Sets what the media queries report, and tells their listeners.
76
+ * @param next - Whether every query reports a match, or the width in pixels the width queries are answered by.
77
+ */
78
+ export function setViewport(next) {
79
+ viewport = next;
72
80
  for (const listener of [...viewportListeners]) {
73
81
  listener();
74
82
  }
@@ -77,9 +85,55 @@ export function setViewport(viewport) {
77
85
  * Returns every media query to reporting no match, with no listeners left.
78
86
  */
79
87
  function resetViewport() {
80
- viewportMatches = false;
88
+ viewport = { matches: false };
81
89
  viewportListeners.clear();
82
90
  }
91
+ /**
92
+ * Tells whether one condition of a media query holds at a width.
93
+ * @param condition - The condition, such as `screen` or `(max-width: 599px)`.
94
+ * @param width - The viewport width in pixels.
95
+ * @returns Whether it holds, always for a screen media type, never for a condition other than a width in pixels.
96
+ */
97
+ function conditionHolds(condition, width) {
98
+ const part = condition.trim();
99
+ if (SCREEN_MEDIA.test(part)) {
100
+ return true;
101
+ }
102
+ const found = WIDTH_CONDITION.exec(part);
103
+ if (found === null) {
104
+ return false;
105
+ }
106
+ const bound = Number(found[2]);
107
+ return found[1] === 'min' ? width >= bound : width <= bound;
108
+ }
109
+ /**
110
+ * Tells whether a media query list matches at a width.
111
+ * @param media - The media query text, queries parted by commas and conditions joined by and.
112
+ * @param width - The viewport width in pixels.
113
+ * @returns Whether every condition of any one query holds.
114
+ */
115
+ function matchesWidth(media, width) {
116
+ return media
117
+ .toLowerCase()
118
+ .split(',')
119
+ .some((query) => conditionsOf(query).every((condition) => conditionHolds(condition, width)));
120
+ }
121
+ /**
122
+ * Returns the conditions a media query joins with and, its spaces folded to one.
123
+ * @param query - One query of a media query list, in lower case.
124
+ * @returns The conditions, such as `screen` and `(max-width: 599px)`.
125
+ */
126
+ function conditionsOf(query) {
127
+ return query.trim().split(/\s+/).join(' ').split(' and ');
128
+ }
129
+ /**
130
+ * Answers a media query from the viewport this module controls.
131
+ * @param media - The media query text.
132
+ * @returns Whether the query matches.
133
+ */
134
+ function answer(media) {
135
+ return 'width' in viewport ? matchesWidth(media, viewport.width) : viewport.matches;
136
+ }
83
137
  /**
84
138
  * Returns a media query list reading the viewport this module controls.
85
139
  * @param media - The media query text.
@@ -89,7 +143,7 @@ function mediaQueryList(media) {
89
143
  return {
90
144
  media,
91
145
  get matches() {
92
- return viewportMatches;
146
+ return answer(media);
93
147
  },
94
148
  addEventListener: (_type, listener) => {
95
149
  viewportListeners.add(listener);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
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",