@wordpress/boot 0.26.0 → 0.28.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/build-module/components/app/index.mjs.map +1 -1
- package/build-module/components/app/router.mjs +24 -24
- package/build-module/components/app/router.mjs.map +1 -1
- package/build-module/components/app/use-route-focus.mjs +162 -0
- package/build-module/components/app/use-route-focus.mjs.map +1 -0
- package/build-module/components/app/use-route-title.mjs +6 -1
- package/build-module/components/app/use-route-title.mjs.map +1 -1
- package/build-module/components/canvas/index.mjs +1 -1
- package/build-module/components/canvas/index.mjs.map +1 -1
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs +20 -12
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs.map +1 -1
- package/build-module/components/error-boundary/index.mjs +2 -2
- package/build-module/components/error-boundary/index.mjs.map +1 -1
- package/build-module/components/navigation/drilldown-item/index.mjs +3 -3
- package/build-module/components/navigation/drilldown-item/index.mjs.map +1 -1
- package/build-module/components/navigation/dropdown-item/index.mjs +3 -3
- package/build-module/components/navigation/dropdown-item/index.mjs.map +1 -1
- package/build-module/components/navigation/navigation-item/index.mjs +3 -3
- package/build-module/components/navigation/navigation-item/index.mjs.map +1 -1
- package/build-module/components/navigation/navigation-screen/index.mjs +7 -7
- package/build-module/components/navigation/navigation-screen/index.mjs.map +1 -1
- package/build-module/components/navigation/router-link-item.mjs.map +1 -1
- package/build-module/components/plugin-area/index.mjs +5 -1
- package/build-module/components/plugin-area/index.mjs.map +1 -1
- package/build-module/components/root/index.mjs +31 -28
- package/build-module/components/root/index.mjs.map +1 -1
- package/build-module/components/root/single-page.mjs +28 -25
- package/build-module/components/root/single-page.mjs.map +1 -1
- package/build-module/components/save-button/index.mjs +8 -3
- package/build-module/components/save-button/index.mjs.map +1 -1
- package/build-module/components/save-panel/index.mjs +3 -1
- package/build-module/components/save-panel/index.mjs.map +1 -1
- package/build-module/components/sidebar/index.mjs +11 -11
- package/build-module/components/sidebar/index.mjs.map +1 -1
- package/build-types/components/app/use-route-focus.d.ts +14 -0
- package/build-types/components/app/use-route-focus.d.ts.map +1 -0
- package/build-types/components/canvas/use-navigate-to-entity-record.d.ts +3 -1
- package/build-types/components/canvas/use-navigate-to-entity-record.d.ts.map +1 -1
- package/build-types/components/root/index.d.ts.map +1 -1
- package/build-types/components/root/single-page.d.ts.map +1 -1
- package/build-types/components/save-button/index.d.ts.map +1 -1
- package/build-types/components/save-panel/index.d.ts.map +1 -1
- package/build-types/components/sidebar/index.d.ts.map +1 -1
- package/package.json +35 -28
- package/src/components/app/test/fixtures/own-focus.tsx +22 -0
- package/src/components/app/test/fixtures/settings-general.tsx +21 -0
- package/src/components/app/test/fixtures/settings.tsx +10 -0
- package/src/components/app/test/navigation-focus.browser.test.tsx +108 -0
- package/src/components/app/use-route-focus.ts +53 -0
- package/src/components/canvas/index.tsx +1 -1
- package/src/components/canvas/use-navigate-to-entity-record.ts +33 -16
- package/src/components/error-boundary/index.tsx +2 -2
- package/src/components/navigation/drilldown-item/index.tsx +3 -3
- package/src/components/navigation/dropdown-item/index.tsx +3 -3
- package/src/components/navigation/navigation-item/index.tsx +3 -3
- package/src/components/navigation/navigation-item/style.module.scss +13 -7
- package/src/components/navigation/navigation-screen/index.tsx +2 -2
- package/src/components/navigation/navigation-screen/style.module.scss +1 -1
- package/src/components/navigation/router-link-item.tsx +3 -3
- package/src/components/root/_layout.module.scss +8 -1
- package/src/components/root/index.tsx +11 -4
- package/src/components/root/single-page.tsx +4 -1
- package/src/components/root/test/admin-scheme-sidebar.browser.test.tsx +120 -0
- package/src/components/save-button/index.tsx +7 -2
- package/src/components/save-panel/index.tsx +4 -1
- package/src/components/sidebar/index.tsx +10 -6
- package/src/components/sidebar/style.module.scss +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useEffect, useRef, type RefObject } from '@wordpress/element';
|
|
2
|
+
import { privateApis as routePrivateApis } from '@wordpress/route';
|
|
3
|
+
import { unlock } from '../../lock-unlock';
|
|
4
|
+
import styles from '../root/style.module.scss';
|
|
5
|
+
|
|
6
|
+
const { useRouterState } = unlock( routePrivateApis );
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook that moves focus to the new page when a navigation removes the focused
|
|
10
|
+
* element, such as a breadcrumb link that becomes the new page's heading.
|
|
11
|
+
* Otherwise focus falls back to the document body, and keyboard and screen
|
|
12
|
+
* reader users lose their place.
|
|
13
|
+
*
|
|
14
|
+
* It runs in an effect after the route resolves. Effects of the page content
|
|
15
|
+
* run before it, so the page can move focus itself first.
|
|
16
|
+
*
|
|
17
|
+
* @param layoutRef Ref to the layout element that contains the stage.
|
|
18
|
+
*/
|
|
19
|
+
export default function useRouteFocus(
|
|
20
|
+
layoutRef: RefObject< HTMLElement | null >
|
|
21
|
+
) {
|
|
22
|
+
const href: string | undefined = useRouterState( {
|
|
23
|
+
select: ( state: { resolvedLocation?: { href: string } } ) =>
|
|
24
|
+
state.resolvedLocation?.href,
|
|
25
|
+
} );
|
|
26
|
+
const previousHrefRef = useRef( href );
|
|
27
|
+
|
|
28
|
+
useEffect( () => {
|
|
29
|
+
const previousHref = previousHrefRef.current;
|
|
30
|
+
previousHrefRef.current = href;
|
|
31
|
+
|
|
32
|
+
// The initial page load has no previous location.
|
|
33
|
+
if ( ! previousHref || href === previousHref ) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const layout = layoutRef.current;
|
|
38
|
+
if ( ! layout ) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { activeElement, body } = layout.ownerDocument;
|
|
43
|
+
if ( activeElement && activeElement !== body ) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
layout
|
|
48
|
+
.querySelector< HTMLElement >(
|
|
49
|
+
`.${ styles.stage } [role="region"]`
|
|
50
|
+
)
|
|
51
|
+
?.focus();
|
|
52
|
+
}, [ href, layoutRef ] );
|
|
53
|
+
}
|
|
@@ -29,7 +29,7 @@ export default function Canvas( { canvas }: CanvasProps ) {
|
|
|
29
29
|
const [ Editor, setEditor ] = useState< any >( null );
|
|
30
30
|
const navigate = useNavigate();
|
|
31
31
|
const { onNavigateToEntityRecord, onNavigateToPreviousEntityRecord } =
|
|
32
|
-
useNavigateToEntityRecord();
|
|
32
|
+
useNavigateToEntityRecord( canvas.postType, canvas.postId );
|
|
33
33
|
const onActionPerformed = useActionPerformed( canvas.postType );
|
|
34
34
|
|
|
35
35
|
/*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
2
2
|
import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
|
|
3
3
|
import { store as coreStore } from '@wordpress/core-data';
|
|
4
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
5
4
|
import { store as noticesStore } from '@wordpress/notices';
|
|
6
5
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
7
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
@@ -44,9 +43,14 @@ interface NavigateParams {
|
|
|
44
43
|
* gates the inspector's edit affordance and `onNavigateToPreviousEntityRecord`
|
|
45
44
|
* gates the document bar's back button.
|
|
46
45
|
*
|
|
46
|
+
* @param postType Post type rendered in the canvas, if the route names one.
|
|
47
|
+
* @param postId Post ID rendered in the canvas, if the route names one.
|
|
47
48
|
* @return The two callbacks, for spreading into the editor settings.
|
|
48
49
|
*/
|
|
49
|
-
export default function useNavigateToEntityRecord(
|
|
50
|
+
export default function useNavigateToEntityRecord(
|
|
51
|
+
postType?: string,
|
|
52
|
+
postId?: string
|
|
53
|
+
) {
|
|
50
54
|
const navigate = useNavigate() as Navigate;
|
|
51
55
|
const search = useSearch( { strict: false } ) as { focusMode?: unknown };
|
|
52
56
|
const registry = useRegistry();
|
|
@@ -63,20 +67,33 @@ export default function useNavigateToEntityRecord() {
|
|
|
63
67
|
* Stash the block selected in the entity being left, so returning to
|
|
64
68
|
* it can restore the user's place. The edits hold the external
|
|
65
69
|
* client ID, which `onChangeSelection` has already resolved.
|
|
70
|
+
*
|
|
71
|
+
* The entity being left is the one the canvas shows. A route that
|
|
72
|
+
* names none shows the homepage, which the editor resolves the same
|
|
73
|
+
* way.
|
|
66
74
|
*/
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const homePage =
|
|
76
|
+
postType || postId
|
|
77
|
+
? null
|
|
78
|
+
: ( unlock(
|
|
79
|
+
registry.select( coreStore )
|
|
80
|
+
).getHomePage() as {
|
|
81
|
+
postType?: string;
|
|
82
|
+
postId?: string;
|
|
83
|
+
} | null );
|
|
84
|
+
const currentPostType = postType || homePage?.postType;
|
|
85
|
+
const currentPostId = postId || homePage?.postId;
|
|
86
|
+
const edits = (
|
|
87
|
+
currentPostType && currentPostId
|
|
88
|
+
? registry
|
|
89
|
+
.select( coreStore )
|
|
90
|
+
.getEntityRecordEdits(
|
|
91
|
+
'postType',
|
|
92
|
+
currentPostType,
|
|
93
|
+
currentPostId
|
|
94
|
+
)
|
|
95
|
+
: undefined
|
|
96
|
+
) as { selection?: { selectionStart?: { clientId?: string } } };
|
|
80
97
|
const selectedBlock = edits?.selection?.selectionStart?.clientId;
|
|
81
98
|
|
|
82
99
|
if ( selectedBlock ) {
|
|
@@ -119,7 +136,7 @@ export default function useNavigateToEntityRecord() {
|
|
|
119
136
|
} );
|
|
120
137
|
}
|
|
121
138
|
},
|
|
122
|
-
[ navigate, registry, getEntityLink ]
|
|
139
|
+
[ navigate, registry, getEntityLink, postType, postId ]
|
|
123
140
|
);
|
|
124
141
|
|
|
125
142
|
/*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import { speak } from '@wordpress/a11y';
|
|
3
3
|
import { Component, useEffect, useState } from '@wordpress/element';
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
4
|
+
import { __, _x } from '@wordpress/i18n';
|
|
5
5
|
import { Button } from '@wordpress/components';
|
|
6
6
|
import { EmptyState } from '@wordpress/ui';
|
|
7
7
|
import { useCopyToClipboard } from '@wordpress/compose';
|
|
@@ -66,7 +66,7 @@ function CopyErrorButton( { error }: { error: Error } ) {
|
|
|
66
66
|
ref={ ref }
|
|
67
67
|
icon={ RESULT_ICON[ feedback.result ] }
|
|
68
68
|
>
|
|
69
|
-
{
|
|
69
|
+
{ _x( 'Copy error', 'button label' ) }
|
|
70
70
|
</Button>
|
|
71
71
|
);
|
|
72
72
|
}
|
|
@@ -2,7 +2,7 @@ import clsx from 'clsx';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
FlexBlock,
|
|
5
|
-
__experimentalItem as
|
|
5
|
+
__experimentalItem as WCItem,
|
|
6
6
|
__experimentalHStack as HStack,
|
|
7
7
|
Icon as WCIcon,
|
|
8
8
|
} from '@wordpress/components';
|
|
@@ -59,7 +59,7 @@ export default function DrilldownItem( {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
|
-
<
|
|
62
|
+
<WCItem
|
|
63
63
|
className={ clsx( styles.item, className ) }
|
|
64
64
|
onClick={ handleClick }
|
|
65
65
|
>
|
|
@@ -74,6 +74,6 @@ export default function DrilldownItem( {
|
|
|
74
74
|
icon={ isRTL() ? chevronLeftSmall : chevronRightSmall }
|
|
75
75
|
/>
|
|
76
76
|
</HStack>
|
|
77
|
-
</
|
|
77
|
+
</WCItem>
|
|
78
78
|
);
|
|
79
79
|
}
|
|
@@ -2,7 +2,7 @@ import clsx from 'clsx';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
FlexBlock,
|
|
5
|
-
__experimentalItem as
|
|
5
|
+
__experimentalItem as WCItem,
|
|
6
6
|
__experimentalHStack as HStack,
|
|
7
7
|
Icon as WCIcon,
|
|
8
8
|
__unstableMotion as motion,
|
|
@@ -69,7 +69,7 @@ export default function DropdownItem( {
|
|
|
69
69
|
const disableMotion = useReducedMotion();
|
|
70
70
|
return (
|
|
71
71
|
<div className={ styles.dropdown }>
|
|
72
|
-
<
|
|
72
|
+
<WCItem
|
|
73
73
|
className={ clsx( navigationItemStyles.item, className ) }
|
|
74
74
|
onClick={ ( e ) => {
|
|
75
75
|
e.preventDefault();
|
|
@@ -92,7 +92,7 @@ export default function DropdownItem( {
|
|
|
92
92
|
} ) }
|
|
93
93
|
/>
|
|
94
94
|
</HStack>
|
|
95
|
-
</
|
|
95
|
+
</WCItem>
|
|
96
96
|
<AnimatePresence initial={ false }>
|
|
97
97
|
{ isExpanded && (
|
|
98
98
|
<motion.div
|
|
@@ -2,7 +2,7 @@ import clsx from 'clsx';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
FlexBlock,
|
|
5
|
-
__experimentalItem as
|
|
5
|
+
__experimentalItem as WCItem,
|
|
6
6
|
__experimentalHStack as HStack,
|
|
7
7
|
} from '@wordpress/components';
|
|
8
8
|
import RouterLinkItem from '../router-link-item';
|
|
@@ -55,13 +55,13 @@ export default function NavigationItem( {
|
|
|
55
55
|
if ( isExternal ) {
|
|
56
56
|
// Render as a regular anchor tag for external URLs
|
|
57
57
|
return (
|
|
58
|
-
<
|
|
58
|
+
<WCItem
|
|
59
59
|
as="a"
|
|
60
60
|
href={ to }
|
|
61
61
|
className={ clsx( styles.item, className ) }
|
|
62
62
|
>
|
|
63
63
|
{ content }
|
|
64
|
-
</
|
|
64
|
+
</WCItem>
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -18,22 +18,28 @@
|
|
|
18
18
|
// Rounded focus ring
|
|
19
19
|
border-radius: var(--wpds-border-radius-sm);
|
|
20
20
|
|
|
21
|
-
&:hover,
|
|
22
|
-
&:focus,
|
|
23
|
-
&[aria-current="true"] {
|
|
24
|
-
color: var(--wpds-color-foreground-interactive-brand-active);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
21
|
svg:last-child {
|
|
28
22
|
padding: variables.$grid-unit-05;
|
|
29
23
|
}
|
|
30
24
|
|
|
25
|
+
// The current item is a persistent selection, so it uses the resting
|
|
26
|
+
// brand color. Hover and focus follow it to show the interaction state.
|
|
27
|
+
&[aria-current="true"],
|
|
28
|
+
&[aria-current="page"],
|
|
29
|
+
&[data-status="active"] {
|
|
30
|
+
color: var(--wpds-color-foreground-interactive-brand);
|
|
31
|
+
}
|
|
32
|
+
|
|
31
33
|
&[aria-current="page"],
|
|
32
34
|
&[data-status="active"] {
|
|
33
|
-
color: var(--wpds-color-foreground-interactive-brand-active);
|
|
34
35
|
font-weight: var(--wpds-typography-font-weight-emphasis);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
&:hover,
|
|
39
|
+
&:focus {
|
|
40
|
+
color: var(--wpds-color-foreground-interactive-brand-active);
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
// Make sure the focus style is drawn on top of the current item background.
|
|
38
44
|
&:focus-visible {
|
|
39
45
|
transform: translateZ(0);
|
|
@@ -14,7 +14,7 @@ import styles from './style.module.scss';
|
|
|
14
14
|
const ANIMATION_DURATION = 0.3;
|
|
15
15
|
const slideVariants = {
|
|
16
16
|
initial: ( direction: 'forward' | 'backward' ) => ( {
|
|
17
|
-
x: direction === 'forward' ? 100 : -100,
|
|
17
|
+
x: ( direction === 'forward' ? 100 : -100 ) * ( isRTL() ? -1 : 1 ),
|
|
18
18
|
opacity: 0,
|
|
19
19
|
} ),
|
|
20
20
|
animate: {
|
|
@@ -22,7 +22,7 @@ const slideVariants = {
|
|
|
22
22
|
opacity: 1,
|
|
23
23
|
},
|
|
24
24
|
exit: ( direction: 'forward' | 'backward' ) => ( {
|
|
25
|
-
x: direction === 'forward' ? 100 : -100,
|
|
25
|
+
x: ( direction === 'forward' ? 100 : -100 ) * ( isRTL() ? -1 : 1 ),
|
|
26
26
|
opacity: 0,
|
|
27
27
|
} ),
|
|
28
28
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { ForwardedRef } from 'react';
|
|
2
2
|
import { forwardRef } from '@wordpress/element';
|
|
3
|
-
import { __experimentalItem as
|
|
3
|
+
import { __experimentalItem as WCItem } from '@wordpress/components';
|
|
4
4
|
import { privateApis as routePrivateApis } from '@wordpress/route';
|
|
5
5
|
import { unlock } from '../../lock-unlock';
|
|
6
6
|
|
|
7
7
|
const { createLink } = unlock( routePrivateApis );
|
|
8
8
|
|
|
9
9
|
function AnchorOnlyItem(
|
|
10
|
-
props: React.ComponentProps< typeof
|
|
10
|
+
props: React.ComponentProps< typeof WCItem >,
|
|
11
11
|
forwardedRef: ForwardedRef< HTMLAnchorElement >
|
|
12
12
|
) {
|
|
13
|
-
return <
|
|
13
|
+
return <WCItem as="a" ref={ forwardedRef } { ...props } />;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const RouterLinkItem = createLink( forwardRef( AnchorOnlyItem ) );
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
max-width: 85vw;
|
|
71
71
|
background: var(--wpds-color-background-surface-neutral-weak);
|
|
72
72
|
z-index: 100003;
|
|
73
|
-
box-shadow:
|
|
73
|
+
box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -110,6 +110,13 @@
|
|
|
110
110
|
.layout-single-page & {
|
|
111
111
|
margin-top: 0;
|
|
112
112
|
margin-inline-start: 0;
|
|
113
|
+
|
|
114
|
+
// Keep the app pinned to the viewport instead of letting it
|
|
115
|
+
// scroll away when the wp-admin menu is taller than the window.
|
|
116
|
+
position: sticky;
|
|
117
|
+
top: variables.$admin-bar-height;
|
|
118
|
+
// Subtract the bottom margin so the page doesn't overflow.
|
|
119
|
+
height: calc(100vh - #{variables.$admin-bar-height} - #{variables.$grid-unit-10});
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import { privateApis as routePrivateApis } from '@wordpress/route';
|
|
3
|
+
import { privateApis as coreDataPrivateApis } from '@wordpress/core-data';
|
|
3
4
|
import { SnackbarNotices } from '@wordpress/notices';
|
|
4
5
|
import { useViewportMatch, useReducedMotion } from '@wordpress/compose';
|
|
5
6
|
import {
|
|
@@ -10,8 +11,7 @@ import {
|
|
|
10
11
|
} from '@wordpress/components';
|
|
11
12
|
import { menu } from '@wordpress/icons';
|
|
12
13
|
import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
|
-
import { UnsavedChangesWarning } from '@wordpress/editor';
|
|
14
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
15
15
|
import { Page, getAdminThemeColors } from '@wordpress/admin-ui';
|
|
16
16
|
import { Tooltip } from '@wordpress/ui';
|
|
17
17
|
import { ThemeProvider } from '@wordpress/theme';
|
|
@@ -21,12 +21,14 @@ import CanvasRenderer from '../canvas-renderer';
|
|
|
21
21
|
import ErrorBoundary from '../error-boundary';
|
|
22
22
|
import PluginArea from '../plugin-area';
|
|
23
23
|
import useRouteTitle from '../app/use-route-title';
|
|
24
|
+
import useRouteFocus from '../app/use-route-focus';
|
|
24
25
|
import { unlock } from '../../lock-unlock';
|
|
25
26
|
import type { CanvasData } from '../../store/types';
|
|
26
27
|
import useSyncBodyBackground from './use-sync-body-background';
|
|
27
28
|
import styles from './style.module.scss';
|
|
28
29
|
|
|
29
30
|
const { useLocation, useMatches, Outlet } = unlock( routePrivateApis );
|
|
31
|
+
const { UnsavedChangesWarning } = unlock( coreDataPrivateApis );
|
|
30
32
|
|
|
31
33
|
export default function Root() {
|
|
32
34
|
const matches = useMatches();
|
|
@@ -52,6 +54,7 @@ export default function Root() {
|
|
|
52
54
|
const themeColors = useMemo( getAdminThemeColors, [] );
|
|
53
55
|
|
|
54
56
|
const layoutRef = useSyncBodyBackground();
|
|
57
|
+
useRouteFocus( layoutRef );
|
|
55
58
|
|
|
56
59
|
return (
|
|
57
60
|
<SlotFillProvider>
|
|
@@ -130,9 +133,13 @@ export default function Root() {
|
|
|
130
133
|
isMobileSidebarOpen &&
|
|
131
134
|
! isFullScreen && (
|
|
132
135
|
<motion.div
|
|
133
|
-
initial={ {
|
|
136
|
+
initial={ {
|
|
137
|
+
x: isRTL() ? '100%' : '-100%',
|
|
138
|
+
} }
|
|
134
139
|
animate={ { x: 0 } }
|
|
135
|
-
exit={ {
|
|
140
|
+
exit={ {
|
|
141
|
+
x: isRTL() ? '100%' : '-100%',
|
|
142
|
+
} }
|
|
136
143
|
transition={ {
|
|
137
144
|
type: 'tween',
|
|
138
145
|
duration: disableMotion
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import { privateApis as routePrivateApis } from '@wordpress/route';
|
|
3
|
+
import { privateApis as coreDataPrivateApis } from '@wordpress/core-data';
|
|
3
4
|
import { SnackbarNotices } from '@wordpress/notices';
|
|
4
5
|
import { SlotFillProvider } from '@wordpress/components';
|
|
5
6
|
import { useMemo } from '@wordpress/element';
|
|
6
7
|
import { getAdminThemeColors } from '@wordpress/admin-ui';
|
|
7
8
|
import { ThemeProvider } from '@wordpress/theme';
|
|
8
|
-
import { UnsavedChangesWarning } from '@wordpress/editor';
|
|
9
9
|
import SavePanel from '../save-panel';
|
|
10
10
|
import CanvasRenderer from '../canvas-renderer';
|
|
11
11
|
import PluginArea from '../plugin-area';
|
|
@@ -14,8 +14,10 @@ import type { CanvasData } from '../../store/types';
|
|
|
14
14
|
import useSyncBodyBackground from './use-sync-body-background';
|
|
15
15
|
import styles from './style.module.scss';
|
|
16
16
|
import useRouteTitle from '../app/use-route-title';
|
|
17
|
+
import useRouteFocus from '../app/use-route-focus';
|
|
17
18
|
|
|
18
19
|
const { useMatches, Outlet } = unlock( routePrivateApis );
|
|
20
|
+
const { UnsavedChangesWarning } = unlock( coreDataPrivateApis );
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Root component for single page mode (no sidebar).
|
|
@@ -35,6 +37,7 @@ export default function RootSinglePage() {
|
|
|
35
37
|
const themeColors = useMemo( getAdminThemeColors, [] );
|
|
36
38
|
|
|
37
39
|
const layoutRef = useSyncBodyBackground();
|
|
40
|
+
useRouteFocus( layoutRef );
|
|
38
41
|
|
|
39
42
|
return (
|
|
40
43
|
<SlotFillProvider>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render } from 'vitest-browser-react';
|
|
3
|
+
import { getAdminThemeColors } from '@wordpress/admin-ui';
|
|
4
|
+
import { ThemeProvider } from '@wordpress/theme';
|
|
5
|
+
import styles from '../style.module.scss';
|
|
6
|
+
|
|
7
|
+
function hexToChannels( hex: string ) {
|
|
8
|
+
return [ 1, 3, 5 ].map( ( i ) => parseInt( hex.slice( i, i + 2 ), 16 ) );
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe( 'admin color scheme sidebar', () => {
|
|
12
|
+
afterEach( () => {
|
|
13
|
+
document.body.className = '';
|
|
14
|
+
} );
|
|
15
|
+
|
|
16
|
+
// The sidebar should stay close to the `$base-color` of the Core scheme in
|
|
17
|
+
// WordPress 7.1 and later. Ectoplasm matches its original Core color.
|
|
18
|
+
// `tolerance` is the largest difference allowed in each sRGB channel.
|
|
19
|
+
it.each( [
|
|
20
|
+
{ scheme: 'blue', core: '#245278', tolerance: 4 },
|
|
21
|
+
{ scheme: 'sunrise', core: '#8a312d', tolerance: 4 },
|
|
22
|
+
{ scheme: 'ectoplasm', core: '#523f6d', tolerance: 0 },
|
|
23
|
+
] )(
|
|
24
|
+
'matches the Core sidebar color in the $scheme scheme',
|
|
25
|
+
async ( { scheme, core, tolerance } ) => {
|
|
26
|
+
document.body.className = `admin-color-${ scheme }`;
|
|
27
|
+
|
|
28
|
+
const view = await render(
|
|
29
|
+
<ThemeProvider color={ getAdminThemeColors() }>
|
|
30
|
+
<div className={ styles.layout }>sidebar</div>
|
|
31
|
+
</ThemeProvider>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const sidebarColor = getComputedStyle(
|
|
35
|
+
view.getByText( 'sidebar' ).element()
|
|
36
|
+
).backgroundColor;
|
|
37
|
+
const actual = sidebarColor.match( /\d+/g )!.map( Number );
|
|
38
|
+
|
|
39
|
+
// An opaque color, `rgb( r, g, b )`, has no alpha channel.
|
|
40
|
+
expect( actual ).toHaveLength( 3 );
|
|
41
|
+
|
|
42
|
+
hexToChannels( core ).forEach( ( channel, index ) => {
|
|
43
|
+
expect(
|
|
44
|
+
Math.abs( channel - actual[ index ] )
|
|
45
|
+
).toBeLessThanOrEqual( tolerance );
|
|
46
|
+
} );
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
it.each( [ 'modern', 'fresh', 'midnight' ] )(
|
|
51
|
+
'keeps a white label on the brand fill in the %s scheme',
|
|
52
|
+
async ( scheme ) => {
|
|
53
|
+
document.body.className = `admin-color-${ scheme }`;
|
|
54
|
+
const onColorWarnings = vi.fn();
|
|
55
|
+
|
|
56
|
+
const view = await render(
|
|
57
|
+
<ThemeProvider
|
|
58
|
+
color={ getAdminThemeColors() }
|
|
59
|
+
onColorWarnings={ onColorWarnings }
|
|
60
|
+
>
|
|
61
|
+
<div
|
|
62
|
+
style={ {
|
|
63
|
+
color: 'var(--wpds-color-foreground-interactive-brand-strong)',
|
|
64
|
+
} }
|
|
65
|
+
>
|
|
66
|
+
label
|
|
67
|
+
</div>
|
|
68
|
+
</ThemeProvider>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const label = getComputedStyle(
|
|
72
|
+
view.getByText( 'label' ).element()
|
|
73
|
+
)
|
|
74
|
+
.color.match( /\d+/g )!
|
|
75
|
+
.map( Number );
|
|
76
|
+
|
|
77
|
+
// A light label, close to white.
|
|
78
|
+
label.slice( 0, 3 ).forEach( ( channel ) => {
|
|
79
|
+
expect( channel ).toBeGreaterThanOrEqual( 230 );
|
|
80
|
+
} );
|
|
81
|
+
// The label meets its contrast targets on the fill and its active state.
|
|
82
|
+
expect( onColorWarnings ).toHaveBeenCalledWith( [] );
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Ectoplasm's brand fill should stay close to Core's original lime.
|
|
87
|
+
it( 'keeps the Ectoplasm brand fill close to Core lime with a dark label', async () => {
|
|
88
|
+
document.body.className = 'admin-color-ectoplasm';
|
|
89
|
+
|
|
90
|
+
const view = await render(
|
|
91
|
+
<ThemeProvider color={ getAdminThemeColors() }>
|
|
92
|
+
<div
|
|
93
|
+
style={ {
|
|
94
|
+
background:
|
|
95
|
+
'var(--wpds-color-background-interactive-brand-strong)',
|
|
96
|
+
color: 'var(--wpds-color-foreground-interactive-brand-strong)',
|
|
97
|
+
} }
|
|
98
|
+
>
|
|
99
|
+
button
|
|
100
|
+
</div>
|
|
101
|
+
</ThemeProvider>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const { backgroundColor, color } = getComputedStyle(
|
|
105
|
+
view.getByText( 'button' ).element()
|
|
106
|
+
);
|
|
107
|
+
const fill = backgroundColor.match( /\d+/g )!.map( Number );
|
|
108
|
+
const label = color.match( /\d+/g )!.map( Number );
|
|
109
|
+
|
|
110
|
+
hexToChannels( '#a3b745' ).forEach( ( channel, index ) => {
|
|
111
|
+
expect( Math.abs( channel - fill[ index ] ) ).toBeLessThanOrEqual(
|
|
112
|
+
16
|
|
113
|
+
);
|
|
114
|
+
} );
|
|
115
|
+
// A dark label, close to black.
|
|
116
|
+
label.slice( 0, 3 ).forEach( ( channel ) => {
|
|
117
|
+
expect( channel ).toBeLessThanOrEqual( 40 );
|
|
118
|
+
} );
|
|
119
|
+
} );
|
|
120
|
+
} );
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useEffect, useState } from '@wordpress/element';
|
|
2
2
|
import { useSelect } from '@wordpress/data';
|
|
3
3
|
import { _n, __, sprintf } from '@wordpress/i18n';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
privateApis as coreDataPrivateApis,
|
|
6
|
+
store as coreStore,
|
|
7
|
+
} from '@wordpress/core-data';
|
|
5
8
|
import {
|
|
6
9
|
ariaKeyShortcut,
|
|
7
10
|
displayShortcut,
|
|
8
11
|
shortcutAriaLabel,
|
|
9
12
|
} from '@wordpress/keycodes';
|
|
10
13
|
import { check } from '@wordpress/icons';
|
|
11
|
-
import { EntitiesSavedStates } from '@wordpress/editor';
|
|
12
14
|
import { Button, Modal } from '@wordpress/components';
|
|
13
15
|
import {
|
|
14
16
|
KeyboardShortcutDescription,
|
|
@@ -18,6 +20,9 @@ import {
|
|
|
18
20
|
} from '@wordpress/ui';
|
|
19
21
|
import styles from './style.module.scss';
|
|
20
22
|
import useSaveShortcut from '../save-panel/use-save-shortcut';
|
|
23
|
+
import { unlock } from '../../lock-unlock';
|
|
24
|
+
|
|
25
|
+
const { EntitiesSavedStates } = unlock( coreDataPrivateApis );
|
|
21
26
|
|
|
22
27
|
export default function SaveButton() {
|
|
23
28
|
const [ isSaveViewOpen, setIsSaveViewOpened ] = useState( false );
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { useState } from '@wordpress/element';
|
|
2
2
|
import { Modal } from '@wordpress/components';
|
|
3
|
-
import {
|
|
3
|
+
import { privateApis as coreDataPrivateApis } from '@wordpress/core-data';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import useSaveShortcut from './use-save-shortcut';
|
|
6
|
+
import { unlock } from '../../lock-unlock';
|
|
6
7
|
import styles from './style.module.scss';
|
|
7
8
|
|
|
9
|
+
const { EntitiesSavedStates } = unlock( coreDataPrivateApis );
|
|
10
|
+
|
|
8
11
|
export default function SavePanel() {
|
|
9
12
|
const [ isOpen, setIsOpen ] = useState< boolean >( false );
|
|
10
13
|
useSaveShortcut( {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Button } from '@wordpress/components';
|
|
2
1
|
import { useSelect } from '@wordpress/data';
|
|
3
2
|
import { __, isRTL } from '@wordpress/i18n';
|
|
4
3
|
import { chevronLeft, chevronRight } from '@wordpress/icons';
|
|
4
|
+
import {
|
|
5
|
+
// eslint-disable-next-line @wordpress/use-recommended-components
|
|
6
|
+
ButtonLink,
|
|
7
|
+
} from '@wordpress/ui';
|
|
5
8
|
import Navigation from '../navigation';
|
|
6
9
|
import SaveButton from '../save-button';
|
|
7
10
|
import { store as bootStore } from '../../store';
|
|
@@ -13,15 +16,16 @@ function DashboardBackButton() {
|
|
|
13
16
|
[]
|
|
14
17
|
);
|
|
15
18
|
return (
|
|
16
|
-
<
|
|
17
|
-
|
|
19
|
+
<ButtonLink
|
|
20
|
+
variant="minimal"
|
|
21
|
+
tone="neutral"
|
|
18
22
|
className={ styles[ 'back-button' ] }
|
|
19
23
|
href={ dashboardLink || '/' }
|
|
20
|
-
|
|
21
|
-
label={ __( 'Go to the Dashboard' ) }
|
|
24
|
+
aria-label={ __( 'Go to the Dashboard' ) }
|
|
22
25
|
>
|
|
26
|
+
<ButtonLink.Icon icon={ isRTL() ? chevronRight : chevronLeft } />
|
|
23
27
|
{ __( 'Dashboard' ) }
|
|
24
|
-
</
|
|
28
|
+
</ButtonLink>
|
|
25
29
|
);
|
|
26
30
|
}
|
|
27
31
|
|