@gopherium/godmin 0.24.0 → 0.26.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 +27 -2
- package/dist/base.css +292 -29
- package/dist/breakpoints.d.ts +7 -3
- package/dist/breakpoints.js +8 -4
- package/dist/drilldown-item.d.ts +19 -0
- package/dist/drilldown-item.js +31 -0
- package/dist/frame.d.ts +16 -8
- package/dist/frame.js +44 -23
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/list-chrome/es-ES.d.ts +1 -1
- package/dist/list-chrome/es-ES.js +5 -1
- package/dist/list-chrome/fr-FR.d.ts +1 -1
- package/dist/list-chrome/fr-FR.js +5 -1
- package/dist/list-chrome.d.ts +1 -1
- package/dist/list-chrome.js +1 -1
- package/dist/list-empty.d.ts +1 -1
- package/dist/list-empty.js +4 -2
- package/dist/menu-item.d.ts +36 -0
- package/dist/menu-item.js +33 -0
- package/dist/navigation-item.d.ts +53 -0
- package/dist/navigation-item.js +58 -0
- package/dist/navigation-list.d.ts +14 -0
- package/dist/navigation-list.js +72 -0
- package/dist/navigation-screen.d.ts +24 -0
- package/dist/navigation-screen.js +47 -0
- package/dist/navigation-state.d.ts +83 -0
- package/dist/navigation-state.js +88 -0
- package/dist/navigation.d.ts +23 -0
- package/dist/navigation.js +133 -0
- package/dist/page-tabs.d.ts +5 -4
- package/dist/page-tabs.js +12 -3
- package/dist/page.d.ts +20 -6
- package/dist/page.js +32 -10
- package/dist/path-matching.d.ts +68 -0
- package/dist/path-matching.js +126 -0
- package/dist/router.d.ts +24 -2
- package/dist/router.js +16 -3
- package/package.json +3 -6
- package/dist/nav-screen.d.ts +0 -17
- package/dist/nav-screen.js +0 -31
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/** The answer for an address that leaves the site, which opens no route. */
|
|
3
|
+
const offSite = { drilldownParent: undefined, capabilities: [] };
|
|
4
|
+
/** A URL scheme at the start of an address. */
|
|
5
|
+
const scheme = /^[a-z][a-z\d+.-]*:/i;
|
|
6
|
+
/** The lookups kept for each location a router has been on. */
|
|
7
|
+
const kept = new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* Finds the deepest match whose route declares a Sidebar.
|
|
10
|
+
* @param matches - The matched routes, outermost first.
|
|
11
|
+
* @returns That match, or undefined when no route declares one.
|
|
12
|
+
*/
|
|
13
|
+
export function findSidebarMatch(matches) {
|
|
14
|
+
return matches.findLast((match) => match.staticData.Sidebar !== undefined);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the pathname and search of a location, the form a frame watches its location in.
|
|
18
|
+
* @param location - The location.
|
|
19
|
+
* @returns The pathname followed by the search.
|
|
20
|
+
*/
|
|
21
|
+
export function locationAddress(location) {
|
|
22
|
+
return location.pathname + location.searchStr;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the lookups kept for the location a router is on now.
|
|
26
|
+
* @param router - The router the addresses resolve on.
|
|
27
|
+
* @returns The lookups of that location.
|
|
28
|
+
*/
|
|
29
|
+
function keptOn(router) {
|
|
30
|
+
let found = kept.get(router.latestLocation);
|
|
31
|
+
if (found === undefined) {
|
|
32
|
+
found = { rows: new Map(), routes: new Map() };
|
|
33
|
+
kept.set(router.latestLocation, found);
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the to of an address that names nothing else, the key its row is kept under.
|
|
39
|
+
* @param address - Where the row goes.
|
|
40
|
+
* @returns The to, or undefined when the address also names a from, params, a search or a hash.
|
|
41
|
+
*/
|
|
42
|
+
function plainTo(address) {
|
|
43
|
+
const { to, from, params, search, hash } = address;
|
|
44
|
+
return from === undefined && params === undefined && search === undefined && hash === undefined ? to : undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Works out what the routes of a pathname declare, once per pathname and location.
|
|
48
|
+
* @param router - The router the pathname resolves on.
|
|
49
|
+
* @param routes - The answers kept for the location.
|
|
50
|
+
* @param location - The pathname and the search of the built address.
|
|
51
|
+
* @returns The deepest route with a Sidebar and the capability of every route.
|
|
52
|
+
*/
|
|
53
|
+
function routesOfPath(router, routes, location) {
|
|
54
|
+
const known = routes.get(location.pathname);
|
|
55
|
+
if (known !== undefined) {
|
|
56
|
+
return known;
|
|
57
|
+
}
|
|
58
|
+
const matches = router.matchRoutes(location.pathname, location.search);
|
|
59
|
+
const answer = {
|
|
60
|
+
drilldownParent: findSidebarMatch(matches)?.routeId,
|
|
61
|
+
capabilities: matches.flatMap((match) => match.staticData.capability ?? []),
|
|
62
|
+
};
|
|
63
|
+
routes.set(location.pathname, answer);
|
|
64
|
+
return answer;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Builds an address and works out what the routes it opens declare.
|
|
68
|
+
* @param router - The router the address resolves on.
|
|
69
|
+
* @param found - The lookups kept for the location.
|
|
70
|
+
* @param address - Where the row goes.
|
|
71
|
+
* @returns The row.
|
|
72
|
+
*/
|
|
73
|
+
function buildRow(router, found, address) {
|
|
74
|
+
const built = router.buildLocation(address);
|
|
75
|
+
return { href: built.href, address: locationAddress(built), ...routesOfPath(router, found.routes, built) };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Finds where a row goes and what the routes it opens declare, once per address and location.
|
|
79
|
+
* @param router - The router the address resolves on.
|
|
80
|
+
* @param address - Where the row goes.
|
|
81
|
+
* @returns The row, with no route for an address that leaves the site.
|
|
82
|
+
*/
|
|
83
|
+
export function findRowRoutes(router, address) {
|
|
84
|
+
if (typeof address.to === 'string' && scheme.test(address.to)) {
|
|
85
|
+
return { ...offSite, href: address.to, address: address.to };
|
|
86
|
+
}
|
|
87
|
+
const found = keptOn(router);
|
|
88
|
+
const key = plainTo(address);
|
|
89
|
+
const known = key === undefined ? undefined : found.rows.get(key);
|
|
90
|
+
if (known !== undefined) {
|
|
91
|
+
return known;
|
|
92
|
+
}
|
|
93
|
+
const row = buildRow(router, found, address);
|
|
94
|
+
if (key !== undefined) {
|
|
95
|
+
found.rows.set(key, row);
|
|
96
|
+
}
|
|
97
|
+
return row;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Finds the sub menu screen a row's address opens, the deepest route it matches that declares a Sidebar.
|
|
101
|
+
* @param router - The router the address resolves on.
|
|
102
|
+
* @param address - Where the row goes.
|
|
103
|
+
* @returns That route's id, or undefined when no route declares one or the address leaves the site.
|
|
104
|
+
*/
|
|
105
|
+
export function findDrilldownParent(router, address) {
|
|
106
|
+
return findRowRoutes(router, address).drilldownParent;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the capability of every route a row's address opens, parents included.
|
|
110
|
+
* @param router - The router the address resolves on.
|
|
111
|
+
* @param address - Where the row goes.
|
|
112
|
+
* @returns The capabilities, outermost route first, none when the address leaves the site.
|
|
113
|
+
*/
|
|
114
|
+
export function findRouteCapabilities(router, address) {
|
|
115
|
+
return findRowRoutes(router, address).capabilities;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Finds the pathname and search a link moves the reader to.
|
|
119
|
+
* @param router - The router the address resolves on.
|
|
120
|
+
* @param address - Where the link goes.
|
|
121
|
+
* @returns That address, or undefined when it is the one already open.
|
|
122
|
+
*/
|
|
123
|
+
export function findMoveTarget(router, address) {
|
|
124
|
+
const target = findRowRoutes(router, address).address;
|
|
125
|
+
return target === locationAddress(router.latestLocation) ? undefined : target;
|
|
126
|
+
}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
1
2
|
import type { CanvasMode } from './frame.js';
|
|
3
|
+
export { DrilldownItem } from './drilldown-item.js';
|
|
4
|
+
export type { DrilldownItemProps } from './drilldown-item.js';
|
|
2
5
|
export { listSearch, openOnTap, useListView } from './list-view.js';
|
|
3
6
|
export type { LayoutDefaults, ListDefaults, ListFilter, ListSearch, ListSortDirection, ListView, ListViewShape, } from './list-view.js';
|
|
7
|
+
export { useCanAccess } from './menu-item.js';
|
|
8
|
+
export type { MenuItem } from './menu-item.js';
|
|
9
|
+
export { Navigation } from './navigation.js';
|
|
10
|
+
export type { NavigationProps } from './navigation.js';
|
|
11
|
+
export { NavigationItem } from './navigation-item.js';
|
|
12
|
+
export type { NavigationItemProps } from './navigation-item.js';
|
|
13
|
+
export { NavigationList } from './navigation-list.js';
|
|
14
|
+
export type { NavigationListProps } from './navigation-list.js';
|
|
4
15
|
declare module '@tanstack/react-router' {
|
|
5
16
|
interface StaticDataRouteOption {
|
|
6
17
|
canvas?: CanvasMode;
|
|
18
|
+
/** The sidebar screen every page under this route shows, a NavigationScreen. */
|
|
19
|
+
Sidebar?: ComponentType;
|
|
20
|
+
/** The capability a reader must hold to open the route. */
|
|
21
|
+
capability?: string;
|
|
7
22
|
}
|
|
8
23
|
}
|
|
9
24
|
/**
|
|
@@ -12,7 +27,14 @@ declare module '@tanstack/react-router' {
|
|
|
12
27
|
*/
|
|
13
28
|
export declare function useCanvas(): CanvasMode;
|
|
14
29
|
/**
|
|
15
|
-
* Returns the current pathname, for a frame to close its drawer on.
|
|
16
|
-
* @returns The pathname of the active location.
|
|
30
|
+
* Returns the current pathname and search, for a frame to close its drawer on.
|
|
31
|
+
* @returns The pathname of the active location followed by its search.
|
|
17
32
|
*/
|
|
18
33
|
export declare function useFrameLocation(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the options a router spreads into createRouter, as WordPress's new admin sets them.
|
|
36
|
+
* @returns Preload on intent, and no pending screen.
|
|
37
|
+
*/
|
|
38
|
+
export declare function routerDefaults(): {
|
|
39
|
+
defaultPreload: 'intent';
|
|
40
|
+
};
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { useRouterState } from '@tanstack/react-router';
|
|
2
|
+
import { locationAddress } from './path-matching.js';
|
|
3
|
+
export { DrilldownItem } from './drilldown-item.js';
|
|
2
4
|
export { listSearch, openOnTap, useListView } from './list-view.js';
|
|
5
|
+
export { useCanAccess } from './menu-item.js';
|
|
6
|
+
export { Navigation } from './navigation.js';
|
|
7
|
+
export { NavigationItem } from './navigation-item.js';
|
|
8
|
+
export { NavigationList } from './navigation-list.js';
|
|
3
9
|
/**
|
|
4
10
|
* Returns the canvas the deepest matching route asks for.
|
|
5
11
|
* @returns The canvas mode, padded when no route asks for one.
|
|
@@ -13,9 +19,16 @@ export function useCanvas() {
|
|
|
13
19
|
});
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
|
-
* Returns the current pathname, for a frame to close its drawer on.
|
|
17
|
-
* @returns The pathname of the active location.
|
|
22
|
+
* Returns the current pathname and search, for a frame to close its drawer on.
|
|
23
|
+
* @returns The pathname of the active location followed by its search.
|
|
18
24
|
*/
|
|
19
25
|
export function useFrameLocation() {
|
|
20
|
-
return useRouterState({ select: (state) => state.location
|
|
26
|
+
return useRouterState({ select: (state) => locationAddress(state.location) });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the options a router spreads into createRouter, as WordPress's new admin sets them.
|
|
30
|
+
* @returns Preload on intent, and no pending screen.
|
|
31
|
+
*/
|
|
32
|
+
export function routerDefaults() {
|
|
33
|
+
return { defaultPreload: 'intent' };
|
|
21
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopherium/godmin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tanstack/react-router": "^1.170.
|
|
67
|
+
"@tanstack/react-router": "^1.170.44",
|
|
68
68
|
"@testing-library/react": "^16.3.2",
|
|
69
69
|
"@wordpress/a11y": ">=4.57.0 <5.0.0",
|
|
70
70
|
"@wordpress/components": ">=42.0.0 <43.0.0",
|
|
@@ -95,9 +95,6 @@
|
|
|
95
95
|
"@wordpress/date": {
|
|
96
96
|
"optional": true
|
|
97
97
|
},
|
|
98
|
-
"@wordpress/i18n": {
|
|
99
|
-
"optional": true
|
|
100
|
-
},
|
|
101
98
|
"stylelint": {
|
|
102
99
|
"optional": true
|
|
103
100
|
},
|
|
@@ -106,7 +103,7 @@
|
|
|
106
103
|
}
|
|
107
104
|
},
|
|
108
105
|
"devDependencies": {
|
|
109
|
-
"@tanstack/react-router": "
|
|
106
|
+
"@tanstack/react-router": "1.170.45",
|
|
110
107
|
"@testing-library/react": "^16.3.2",
|
|
111
108
|
"@testing-library/user-event": "^14.6.7",
|
|
112
109
|
"@types/node": "^26.1.2",
|
package/dist/nav-screen.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
-
export interface NavScreenProps {
|
|
3
|
-
title: string;
|
|
4
|
-
back?: ReactElement<Record<string, unknown>>;
|
|
5
|
-
backLabel?: string;
|
|
6
|
-
description?: ReactNode;
|
|
7
|
-
actions?: ReactNode;
|
|
8
|
-
footer?: ReactNode;
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Renders a drill-down navigation screen: a way back to the parent layer, the
|
|
13
|
-
* title, optional description and actions, the content, and an optional footer.
|
|
14
|
-
* @param props - The title, the back affordance and label, and the regions.
|
|
15
|
-
* @returns The navigation screen element.
|
|
16
|
-
*/
|
|
17
|
-
export declare function NavScreen({ title, back, backLabel, description, actions, footer, children, }: NavScreenProps): import("react").JSX.Element;
|
package/dist/nav-screen.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Icon, Link, Stack, Text } from '@wordpress/ui';
|
|
3
|
-
import { useEffect, useRef } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* The glyph on the affordance returning to the parent layer.
|
|
6
|
-
*/
|
|
7
|
-
const chevronLeft = (_jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", children: _jsx("path", { d: "M14.6 7l-1.2-1L8 12l5.4 6 1.2-1-4.6-5z" }) }));
|
|
8
|
-
/**
|
|
9
|
-
* Renders a region in its own element, or nothing when a screen gives none.
|
|
10
|
-
* @param props - The region content and the class naming it.
|
|
11
|
-
* @returns The region element, or null.
|
|
12
|
-
*/
|
|
13
|
-
function Region({ content, className }) {
|
|
14
|
-
if (content === undefined) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return _jsx("div", { className: className, children: content });
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Renders a drill-down navigation screen: a way back to the parent layer, the
|
|
21
|
-
* title, optional description and actions, the content, and an optional footer.
|
|
22
|
-
* @param props - The title, the back affordance and label, and the regions.
|
|
23
|
-
* @returns The navigation screen element.
|
|
24
|
-
*/
|
|
25
|
-
export function NavScreen({ title, back, backLabel = 'Back', description, actions, footer, children, }) {
|
|
26
|
-
const titleRef = useRef(null);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
titleRef.current?.focus();
|
|
29
|
-
}, []);
|
|
30
|
-
return (_jsxs(Stack, { direction: "column", gap: "md", className: "godmin-nav-screen", children: [_jsxs(Stack, { direction: "row", align: "flex-start", gap: "sm", children: [back !== undefined && (_jsx(Link, { render: back, "aria-label": backLabel, className: "godmin-nav-screen__back", children: _jsx(Icon, { icon: chevronLeft, size: 24, "aria-hidden": true }) })), _jsx(Text, { ref: titleRef, variant: "heading-md", render: _jsx("h2", { tabIndex: -1 }), className: "godmin-nav-screen__title", children: title }), _jsx(Region, { content: actions, className: "godmin-nav-screen__actions" })] }), _jsxs(Stack, { direction: "column", gap: "sm", children: [_jsx(Region, { content: description, className: "godmin-nav-screen__description" }), children] }), _jsx(Region, { content: footer, className: "godmin-nav-screen__footer" })] }));
|
|
31
|
-
}
|