@gopherium/godmin 0.14.0 → 0.15.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 -2
- package/dist/base.css +3 -2
- package/dist/bulk.d.ts +23 -0
- package/dist/bulk.js +38 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -2
- package/dist/server-page.d.ts +63 -0
- package/dist/server-page.js +58 -0
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ two lines do for you.
|
|
|
47
47
|
|
|
48
48
|
| Entry point | Contents |
|
|
49
49
|
| --- | --- |
|
|
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` |
|
|
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`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `useMediaQuery`, `useTokenDocument`, the breakpoints, `SUPPORTED_WPDS` |
|
|
51
51
|
| `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
|
|
52
52
|
| `@gopherium/godmin/router` | `useCanvas`, `useFrameLocation`, the `canvas` route static data |
|
|
53
53
|
| `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport`, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR` |
|
|
@@ -66,7 +66,7 @@ render unthemed components with no error. Spread `godminDedupe` into
|
|
|
66
66
|
|
|
67
67
|
## Design system versions
|
|
68
68
|
|
|
69
|
-
Peer ranges are longhand and single window, for example `>=0.
|
|
69
|
+
Peer ranges are longhand and single window, for example `>=0.23.0 <0.24.0`.
|
|
70
70
|
The window moves with each design system release train and never widens, so no
|
|
71
71
|
release accepts two breaking generations at once. `SUPPORTED_WPDS` exports the
|
|
72
72
|
window this build was tested against.
|
package/dist/base.css
CHANGED
|
@@ -17,8 +17,9 @@ body {
|
|
|
17
17
|
inset-inline-start: calc(-1 * var(--godmin-canvas-gutter, 0px));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/* Keeps the sticky DataViews footer of a list page on the canvas bottom
|
|
21
|
-
.godmin-page > .godmin-page__list .dataviews-footer
|
|
20
|
+
/* Keeps the sticky DataViews footer of a list page or a list inside a page on the canvas bottom. */
|
|
21
|
+
.godmin-page > .godmin-page__list .dataviews-footer,
|
|
22
|
+
.godmin-list .dataviews-footer {
|
|
22
23
|
inset-block-end: calc(-1 * var(--godmin-canvas-gutter-block, 0px));
|
|
23
24
|
}
|
|
24
25
|
|
package/dist/bulk.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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>>;
|
package/dist/bulk.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ 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 { runEach } from './bulk.js';
|
|
7
|
+
export type { BulkFailure, BulkOutcome } from './bulk.js';
|
|
6
8
|
export { Frame } from './frame.js';
|
|
7
9
|
export type { CanvasMode, FrameCanvasProps, FrameRailProps, FrameRootProps, } from './frame.js';
|
|
8
10
|
export { keyFromLabel } from './keys.js';
|
|
@@ -22,6 +24,8 @@ export { useRowKeys } from './row-keys.js';
|
|
|
22
24
|
export type { RowBounds, RowKeys } from './row-keys.js';
|
|
23
25
|
export { RepeatRows, RowControls } from './rows.js';
|
|
24
26
|
export type { RepeatRowsProps, RowControlsProps, RowLabels } from './rows.js';
|
|
27
|
+
export { pageWindow, paginationOf, useServerPaging } from './server-page.js';
|
|
28
|
+
export type { PagedView, PageWindow, PaginationInfo, ServedPage, ServedSize, ServerPaging } from './server-page.js';
|
|
25
29
|
export { Toaster, useToaster } from './toaster.js';
|
|
26
30
|
export type { ToastAction, ToasterHandle, ToasterProps } from './toaster.js';
|
|
27
31
|
export { useMediaQuery } from './use-media-query.js';
|
|
@@ -30,6 +34,6 @@ export { useTokenDocument } from './use-token-document.js';
|
|
|
30
34
|
* The design system version window this build was tested against.
|
|
31
35
|
*/
|
|
32
36
|
export declare const SUPPORTED_WPDS: {
|
|
33
|
-
readonly '@wordpress/ui': ">=0.
|
|
34
|
-
readonly '@wordpress/theme': ">=2.
|
|
37
|
+
readonly '@wordpress/ui': ">=0.23.0 <0.24.0";
|
|
38
|
+
readonly '@wordpress/theme': ">=2.2.0 <3.0.0";
|
|
35
39
|
};
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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 { runEach } from './bulk.js';
|
|
5
6
|
export { Frame } from './frame.js';
|
|
6
7
|
export { keyFromLabel } from './keys.js';
|
|
7
8
|
export { LIST_CHROME_DOMAIN, listChromeCatalogFor } from './list-chrome.js';
|
|
@@ -12,6 +13,7 @@ export { ErrorNotice, LoadMore, Page, PageTitle, SectionTitle } from './page.js'
|
|
|
12
13
|
export { PageTab, PageTabs } from './page-tabs.js';
|
|
13
14
|
export { useRowKeys } from './row-keys.js';
|
|
14
15
|
export { RepeatRows, RowControls } from './rows.js';
|
|
16
|
+
export { pageWindow, paginationOf, useServerPaging } from './server-page.js';
|
|
15
17
|
export { Toaster, useToaster } from './toaster.js';
|
|
16
18
|
export { useMediaQuery } from './use-media-query.js';
|
|
17
19
|
export { useTokenDocument } from './use-token-document.js';
|
|
@@ -19,6 +21,6 @@ export { useTokenDocument } from './use-token-document.js';
|
|
|
19
21
|
* The design system version window this build was tested against.
|
|
20
22
|
*/
|
|
21
23
|
export const SUPPORTED_WPDS = {
|
|
22
|
-
'@wordpress/ui': '>=0.
|
|
23
|
-
'@wordpress/theme': '>=2.
|
|
24
|
+
'@wordpress/ui': '>=0.23.0 <0.24.0',
|
|
25
|
+
'@wordpress/theme': '>=2.2.0 <3.0.0',
|
|
24
26
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The part of a list view that names the page it shows, as a DataViews view holds it. */
|
|
2
|
+
export interface PagedView {
|
|
3
|
+
/** The page the view shows, counted from 1. */
|
|
4
|
+
page?: number;
|
|
5
|
+
/** How many rows a page holds. */
|
|
6
|
+
perPage?: number;
|
|
7
|
+
}
|
|
8
|
+
/** The rows a list asks the server for. */
|
|
9
|
+
export interface PageWindow {
|
|
10
|
+
/** How many rows to ask for, or null for the size the server serves by default. */
|
|
11
|
+
limit: number | null;
|
|
12
|
+
/** How many rows to skip before the first one. */
|
|
13
|
+
offset: number;
|
|
14
|
+
}
|
|
15
|
+
/** The part of a page the server served that says its size and its total. */
|
|
16
|
+
export interface ServedPage {
|
|
17
|
+
/** How many rows match, across every page. */
|
|
18
|
+
total: number;
|
|
19
|
+
/** The page size the server used, not the rows on this page. */
|
|
20
|
+
limit: number;
|
|
21
|
+
}
|
|
22
|
+
/** The totals a DataViews list pages through. */
|
|
23
|
+
export interface PaginationInfo {
|
|
24
|
+
/** How many rows match, across every page. */
|
|
25
|
+
totalItems: number;
|
|
26
|
+
/** How many pages those rows fill. */
|
|
27
|
+
totalPages: number;
|
|
28
|
+
}
|
|
29
|
+
/** The size the server last put on one page, and the size the request it answered asked for. */
|
|
30
|
+
export interface ServedSize {
|
|
31
|
+
/** The rows that request asked for, or null when it asked for the size the server serves by default. */
|
|
32
|
+
asked: number | null;
|
|
33
|
+
/** The rows the server put on the page. */
|
|
34
|
+
served: number;
|
|
35
|
+
}
|
|
36
|
+
/** The page a view asks the server for, and the recorder of each page the server serves. */
|
|
37
|
+
export interface ServerPaging {
|
|
38
|
+
/** The rows to ask the server for. */
|
|
39
|
+
window: PageWindow;
|
|
40
|
+
/** Records the page size the server used, when the request that got that page asked the limit the view asks now. */
|
|
41
|
+
record: (page: ServedPage | undefined, asked: number | null) => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the rows to ask the server for the page a view shows.
|
|
45
|
+
* @param view - The view the list shows.
|
|
46
|
+
* @param last - The size the server last served, absent before it served any.
|
|
47
|
+
* @param cap - The largest page the server serves.
|
|
48
|
+
* @returns The limit and offset of the page.
|
|
49
|
+
*/
|
|
50
|
+
export declare function pageWindow({ page, perPage }: PagedView, last?: ServedSize, cap?: number): PageWindow;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the totals a DataViews list pages through, counting pages by the size the server served.
|
|
53
|
+
* @param page - The page the server served, absent until it arrives.
|
|
54
|
+
* @returns The pagination info.
|
|
55
|
+
*/
|
|
56
|
+
export declare function paginationOf(page: ServedPage | undefined): PaginationInfo;
|
|
57
|
+
/**
|
|
58
|
+
* Holds the size the server last served and answers the rows to ask for the page a view shows.
|
|
59
|
+
* @param view - The view the list shows.
|
|
60
|
+
* @param cap - The largest page the server serves.
|
|
61
|
+
* @returns The page window and the recorder of each page the server serves.
|
|
62
|
+
*/
|
|
63
|
+
export declare function useServerPaging(view: PagedView, cap?: number): ServerPaging;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Returns how many rows each page before the shown one holds.
|
|
5
|
+
* @param limit - The rows asked for on one page, or null for the size the server serves by default.
|
|
6
|
+
* @param last - The size the server last served, absent before it served any.
|
|
7
|
+
* @returns The size served when it answered this same ask, the size asked otherwise.
|
|
8
|
+
*/
|
|
9
|
+
function stepOf(limit, last) {
|
|
10
|
+
if (last !== undefined && last.asked === limit && last.served > 0) {
|
|
11
|
+
return last.served;
|
|
12
|
+
}
|
|
13
|
+
return limit ?? 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the rows to ask the server for the page a view shows.
|
|
17
|
+
* @param view - The view the list shows.
|
|
18
|
+
* @param last - The size the server last served, absent before it served any.
|
|
19
|
+
* @param cap - The largest page the server serves.
|
|
20
|
+
* @returns The limit and offset of the page.
|
|
21
|
+
*/
|
|
22
|
+
export function pageWindow({ page = 1, perPage }, last, cap = Infinity) {
|
|
23
|
+
const limit = perPage === undefined ? null : Math.min(perPage, cap);
|
|
24
|
+
return { limit, offset: (page - 1) * stepOf(limit, last) };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the totals a DataViews list pages through, counting pages by the size the server served.
|
|
28
|
+
* @param page - The page the server served, absent until it arrives.
|
|
29
|
+
* @returns The pagination info.
|
|
30
|
+
*/
|
|
31
|
+
export function paginationOf(page) {
|
|
32
|
+
if (page === undefined) {
|
|
33
|
+
return { totalItems: 0, totalPages: 0 };
|
|
34
|
+
}
|
|
35
|
+
const totalPages = page.limit > 0 ? Math.ceil(page.total / page.limit) : Math.min(page.total, 1);
|
|
36
|
+
return { totalItems: page.total, totalPages };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Holds the size the server last served and answers the rows to ask for the page a view shows.
|
|
40
|
+
* @param view - The view the list shows.
|
|
41
|
+
* @param cap - The largest page the server serves.
|
|
42
|
+
* @returns The page window and the recorder of each page the server serves.
|
|
43
|
+
*/
|
|
44
|
+
export function useServerPaging(view, cap) {
|
|
45
|
+
const [last, setLast] = useState();
|
|
46
|
+
const window = pageWindow(view, last, cap);
|
|
47
|
+
return {
|
|
48
|
+
window,
|
|
49
|
+
record: (page, asked) => {
|
|
50
|
+
if (page === undefined || asked !== window.limit) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (page.limit !== last?.served || asked !== last.asked) {
|
|
54
|
+
setLast({ asked, served: page.limit });
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopherium/godmin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@tanstack/react-router": "^1.170.0",
|
|
60
60
|
"@testing-library/react": "^16.3.2",
|
|
61
|
-
"@wordpress/a11y": ">=4.
|
|
62
|
-
"@wordpress/icons": ">=
|
|
63
|
-
"@wordpress/style-runtime": ">=0.
|
|
64
|
-
"@wordpress/theme": ">=2.
|
|
65
|
-
"@wordpress/ui": ">=0.
|
|
61
|
+
"@wordpress/a11y": ">=4.56.0 <5.0.0",
|
|
62
|
+
"@wordpress/icons": ">=17.0.0 <18.0.0",
|
|
63
|
+
"@wordpress/style-runtime": ">=0.12.0 <0.13.0",
|
|
64
|
+
"@wordpress/theme": ">=2.2.0 <3.0.0",
|
|
65
|
+
"@wordpress/ui": ">=0.23.0 <0.24.0",
|
|
66
66
|
"react": "^19.2.0",
|
|
67
67
|
"stylelint": "^16 || ^17",
|
|
68
68
|
"vitest": "^4.1.10"
|
|
@@ -88,13 +88,13 @@
|
|
|
88
88
|
"@types/react": "^19.2.17",
|
|
89
89
|
"@vitejs/plugin-react": "^6.0.3",
|
|
90
90
|
"@vitest/coverage-v8": "^4.1.10",
|
|
91
|
-
"@wordpress/a11y": "4.
|
|
92
|
-
"@wordpress/dataviews": "19.
|
|
93
|
-
"@wordpress/element": "8.
|
|
94
|
-
"@wordpress/icons": "
|
|
95
|
-
"@wordpress/style-runtime": "0.
|
|
96
|
-
"@wordpress/theme": "2.
|
|
97
|
-
"@wordpress/ui": "0.
|
|
91
|
+
"@wordpress/a11y": "4.56.0",
|
|
92
|
+
"@wordpress/dataviews": "19.1.0",
|
|
93
|
+
"@wordpress/element": "8.8.0",
|
|
94
|
+
"@wordpress/icons": "17.0.0",
|
|
95
|
+
"@wordpress/style-runtime": "0.12.0",
|
|
96
|
+
"@wordpress/theme": "2.2.0",
|
|
97
|
+
"@wordpress/ui": "0.23.0",
|
|
98
98
|
"eslint": "^10.7.0",
|
|
99
99
|
"eslint-plugin-jsdoc": "^63.2.0",
|
|
100
100
|
"eslint-plugin-sonarjs": "^4.2.0",
|