@wordpress/edit-site 5.12.11 → 5.12.12
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/components/global-styles/screen-revisions/index.js +8 -2
- package/build/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js +31 -25
- package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
- package/build/components/keyboard-shortcuts/edit-mode.js +7 -5
- package/build/components/keyboard-shortcuts/edit-mode.js.map +1 -1
- package/build/components/layout/index.js +6 -0
- package/build/components/layout/index.js.map +1 -1
- package/build/components/page-template-parts/index.js +1 -2
- package/build/components/page-template-parts/index.js.map +1 -1
- package/build/components/resizable-frame/index.js +11 -19
- package/build/components/resizable-frame/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +15 -13
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +8 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pages/index.js +2 -0
- package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/index.js +0 -9
- package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates/index.js +1 -10
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +9 -0
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build/hooks/commands/use-edit-mode-commands.js +30 -0
- package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build/store/private-actions.js +2 -1
- package/build/store/private-actions.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/index.js +9 -3
- package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js +27 -21
- package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/edit-mode.js +7 -5
- package/build-module/components/keyboard-shortcuts/edit-mode.js.map +1 -1
- package/build-module/components/layout/index.js +6 -0
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/page-template-parts/index.js +1 -2
- package/build-module/components/page-template-parts/index.js.map +1 -1
- package/build-module/components/resizable-frame/index.js +12 -20
- package/build-module/components/resizable-frame/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +13 -13
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +7 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pages/index.js +2 -0
- package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/index.js +0 -7
- package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates/index.js +1 -8
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +7 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/hooks/commands/use-edit-mode-commands.js +29 -0
- package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build-module/store/private-actions.js +2 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-style/style-rtl.css +3 -0
- package/build-style/style.css +3 -0
- package/package.json +20 -20
- package/src/components/global-styles/screen-revisions/index.js +76 -58
- package/src/components/global-styles/screen-revisions/test/use-global-styles-revisions.js +14 -1
- package/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +63 -48
- package/src/components/keyboard-shortcuts/edit-mode.js +4 -5
- package/src/components/layout/index.js +6 -0
- package/src/components/page-patterns/style.scss +3 -0
- package/src/components/page-template-parts/index.js +0 -1
- package/src/components/resizable-frame/index.js +10 -25
- package/src/components/sidebar-navigation-screen/index.js +13 -15
- package/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +27 -15
- package/src/components/sidebar-navigation-screen-pages/index.js +9 -4
- package/src/components/sidebar-navigation-screen-patterns/index.js +0 -8
- package/src/components/sidebar-navigation-screen-templates/index.js +1 -9
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +10 -0
- package/src/hooks/commands/use-edit-mode-commands.js +34 -3
- package/src/store/private-actions.js +5 -1
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
__experimentalUseNavigator as useNavigator,
|
|
8
8
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
9
9
|
Spinner,
|
|
10
|
+
__experimentalSpacer as Spacer,
|
|
10
11
|
} from '@wordpress/components';
|
|
11
12
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
13
|
import { useContext, useState, useEffect } from '@wordpress/element';
|
|
@@ -87,6 +88,7 @@ function ScreenRevisions() {
|
|
|
87
88
|
const isLoadButtonEnabled =
|
|
88
89
|
!! globalStylesRevision?.id &&
|
|
89
90
|
! areGlobalStyleConfigsEqual( globalStylesRevision, userConfig );
|
|
91
|
+
const shouldShowRevisions = ! isLoading && revisions.length;
|
|
90
92
|
|
|
91
93
|
return (
|
|
92
94
|
<>
|
|
@@ -99,68 +101,84 @@ function ScreenRevisions() {
|
|
|
99
101
|
{ isLoading && (
|
|
100
102
|
<Spinner className="edit-site-global-styles-screen-revisions__loading" />
|
|
101
103
|
) }
|
|
102
|
-
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
104
|
+
{ shouldShowRevisions ? (
|
|
105
|
+
<>
|
|
106
|
+
<Revisions
|
|
107
|
+
blocks={ blocks }
|
|
108
|
+
userConfig={ globalStylesRevision }
|
|
109
|
+
onClose={ onCloseRevisions }
|
|
110
|
+
/>
|
|
111
|
+
<div className="edit-site-global-styles-screen-revisions">
|
|
112
|
+
<RevisionsButtons
|
|
113
|
+
onChange={ selectRevision }
|
|
114
|
+
selectedRevisionId={ selectedRevisionId }
|
|
115
|
+
userRevisions={ revisions }
|
|
116
|
+
/>
|
|
117
|
+
{ isLoadButtonEnabled && (
|
|
118
|
+
<SidebarFixedBottom>
|
|
119
|
+
<Button
|
|
120
|
+
variant="primary"
|
|
121
|
+
className="edit-site-global-styles-screen-revisions__button"
|
|
122
|
+
disabled={
|
|
123
|
+
! globalStylesRevision?.id ||
|
|
124
|
+
globalStylesRevision?.id === 'unsaved'
|
|
125
|
+
}
|
|
126
|
+
onClick={ () => {
|
|
127
|
+
if ( hasUnsavedChanges ) {
|
|
128
|
+
setIsLoadingRevisionWithUnsavedChanges(
|
|
129
|
+
true
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
restoreRevision(
|
|
133
|
+
globalStylesRevision
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
} }
|
|
137
|
+
>
|
|
138
|
+
{ __( 'Apply' ) }
|
|
139
|
+
</Button>
|
|
140
|
+
</SidebarFixedBottom>
|
|
141
|
+
) }
|
|
142
|
+
</div>
|
|
143
|
+
{ isLoadingRevisionWithUnsavedChanges && (
|
|
144
|
+
<ConfirmDialog
|
|
145
|
+
title={ __(
|
|
146
|
+
'Loading this revision will discard all unsaved changes.'
|
|
147
|
+
) }
|
|
148
|
+
isOpen={ isLoadingRevisionWithUnsavedChanges }
|
|
149
|
+
confirmButtonText={ __(
|
|
150
|
+
' Discard unsaved changes'
|
|
151
|
+
) }
|
|
152
|
+
onConfirm={ () =>
|
|
153
|
+
restoreRevision( globalStylesRevision )
|
|
154
|
+
}
|
|
155
|
+
onCancel={ () =>
|
|
156
|
+
setIsLoadingRevisionWithUnsavedChanges( false )
|
|
123
157
|
}
|
|
124
|
-
onClick={ () => {
|
|
125
|
-
if ( hasUnsavedChanges ) {
|
|
126
|
-
setIsLoadingRevisionWithUnsavedChanges(
|
|
127
|
-
true
|
|
128
|
-
);
|
|
129
|
-
} else {
|
|
130
|
-
restoreRevision( globalStylesRevision );
|
|
131
|
-
}
|
|
132
|
-
} }
|
|
133
158
|
>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
159
|
+
<>
|
|
160
|
+
<h2>
|
|
161
|
+
{ __(
|
|
162
|
+
'Loading this revision will discard all unsaved changes.'
|
|
163
|
+
) }
|
|
164
|
+
</h2>
|
|
165
|
+
<p>
|
|
166
|
+
{ __(
|
|
167
|
+
'Do you want to replace your unsaved changes in the editor?'
|
|
168
|
+
) }
|
|
169
|
+
</p>
|
|
170
|
+
</>
|
|
171
|
+
</ConfirmDialog>
|
|
143
172
|
) }
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
173
|
+
</>
|
|
174
|
+
) : (
|
|
175
|
+
<Spacer marginX={ 4 } data-testid="global-styles-no-revisions">
|
|
176
|
+
{
|
|
177
|
+
// Adding an existing translation here in case these changes are shipped to WordPress 6.3.
|
|
178
|
+
// Later we could update to something better, e.g., "There are currently no style revisions.".
|
|
179
|
+
__( 'No results found.' )
|
|
149
180
|
}
|
|
150
|
-
>
|
|
151
|
-
<>
|
|
152
|
-
<h2>
|
|
153
|
-
{ __(
|
|
154
|
-
'Loading this revision will discard all unsaved changes.'
|
|
155
|
-
) }
|
|
156
|
-
</h2>
|
|
157
|
-
<p>
|
|
158
|
-
{ __(
|
|
159
|
-
'Do you want to replace your unsaved changes in the editor?'
|
|
160
|
-
) }
|
|
161
|
-
</p>
|
|
162
|
-
</>
|
|
163
|
-
</ConfirmDialog>
|
|
181
|
+
</Spacer>
|
|
164
182
|
) }
|
|
165
183
|
</>
|
|
166
184
|
);
|
|
@@ -49,6 +49,7 @@ describe( 'useGlobalStylesRevisions', () => {
|
|
|
49
49
|
styles: {},
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
|
+
isLoadingGlobalStylesRevisions: false,
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
it( 'returns loaded revisions with no unsaved changes', () => {
|
|
@@ -117,11 +118,23 @@ describe( 'useGlobalStylesRevisions', () => {
|
|
|
117
118
|
const { result } = renderHook( () => useGlobalStylesRevisions() );
|
|
118
119
|
const { revisions, isLoading, hasUnsavedChanges } = result.current;
|
|
119
120
|
|
|
120
|
-
expect( isLoading ).toBe(
|
|
121
|
+
expect( isLoading ).toBe( false );
|
|
121
122
|
expect( hasUnsavedChanges ).toBe( false );
|
|
122
123
|
expect( revisions ).toEqual( [] );
|
|
123
124
|
} );
|
|
124
125
|
|
|
126
|
+
it( 'returns loading status when resolving global revisions', () => {
|
|
127
|
+
useSelect.mockImplementation( () => ( {
|
|
128
|
+
...selectValue,
|
|
129
|
+
isLoadingGlobalStylesRevisions: true,
|
|
130
|
+
} ) );
|
|
131
|
+
|
|
132
|
+
const { result } = renderHook( () => useGlobalStylesRevisions() );
|
|
133
|
+
const { isLoading } = result.current;
|
|
134
|
+
|
|
135
|
+
expect( isLoading ).toBe( true );
|
|
136
|
+
} );
|
|
137
|
+
|
|
125
138
|
it( 'returns empty revisions when authors are not yet available', () => {
|
|
126
139
|
useSelect.mockImplementation( () => ( {
|
|
127
140
|
...selectValue,
|
|
@@ -21,34 +21,40 @@ const EMPTY_ARRAY = [];
|
|
|
21
21
|
const { GlobalStylesContext } = unlock( blockEditorPrivateApis );
|
|
22
22
|
export default function useGlobalStylesRevisions() {
|
|
23
23
|
const { user: userConfig } = useContext( GlobalStylesContext );
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
const {
|
|
25
|
+
authors,
|
|
26
|
+
currentUser,
|
|
27
|
+
isDirty,
|
|
28
|
+
revisions,
|
|
29
|
+
isLoadingGlobalStylesRevisions,
|
|
30
|
+
} = useSelect( ( select ) => {
|
|
31
|
+
const {
|
|
32
|
+
__experimentalGetDirtyEntityRecords,
|
|
33
|
+
getCurrentUser,
|
|
34
|
+
getUsers,
|
|
35
|
+
getCurrentThemeGlobalStylesRevisions,
|
|
36
|
+
isResolving,
|
|
37
|
+
} = select( coreStore );
|
|
38
|
+
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
|
|
39
|
+
const _currentUser = getCurrentUser();
|
|
40
|
+
const _isDirty = dirtyEntityRecords.length > 0;
|
|
41
|
+
const globalStylesRevisions =
|
|
42
|
+
getCurrentThemeGlobalStylesRevisions() || EMPTY_ARRAY;
|
|
43
|
+
const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY;
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
return {
|
|
46
|
+
authors: _authors,
|
|
47
|
+
currentUser: _currentUser,
|
|
48
|
+
isDirty: _isDirty,
|
|
49
|
+
revisions: globalStylesRevisions,
|
|
50
|
+
isLoadingGlobalStylesRevisions: isResolving(
|
|
51
|
+
'getCurrentThemeGlobalStylesRevisions'
|
|
52
|
+
),
|
|
53
|
+
};
|
|
54
|
+
}, [] );
|
|
49
55
|
return useMemo( () => {
|
|
50
56
|
let _modifiedRevisions = [];
|
|
51
|
-
if ( ! authors.length ||
|
|
57
|
+
if ( ! authors.length || isLoadingGlobalStylesRevisions ) {
|
|
52
58
|
return {
|
|
53
59
|
revisions: _modifiedRevisions,
|
|
54
60
|
hasUnsavedChanges: isDirty,
|
|
@@ -66,30 +72,32 @@ export default function useGlobalStylesRevisions() {
|
|
|
66
72
|
};
|
|
67
73
|
} );
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_modifiedRevisions[ 0 ].
|
|
72
|
-
|
|
75
|
+
if ( _modifiedRevisions.length ) {
|
|
76
|
+
// Flags the most current saved revision.
|
|
77
|
+
if ( _modifiedRevisions[ 0 ].id !== 'unsaved' ) {
|
|
78
|
+
_modifiedRevisions[ 0 ].isLatest = true;
|
|
79
|
+
}
|
|
73
80
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
// Adds an item for unsaved changes.
|
|
82
|
+
if (
|
|
83
|
+
isDirty &&
|
|
84
|
+
userConfig &&
|
|
85
|
+
Object.keys( userConfig ).length > 0 &&
|
|
86
|
+
currentUser
|
|
87
|
+
) {
|
|
88
|
+
const unsavedRevision = {
|
|
89
|
+
id: 'unsaved',
|
|
90
|
+
styles: userConfig?.styles,
|
|
91
|
+
settings: userConfig?.settings,
|
|
92
|
+
author: {
|
|
93
|
+
name: currentUser?.name,
|
|
94
|
+
avatar_urls: currentUser?.avatar_urls,
|
|
95
|
+
},
|
|
96
|
+
modified: new Date(),
|
|
97
|
+
};
|
|
91
98
|
|
|
92
|
-
|
|
99
|
+
_modifiedRevisions.unshift( unsavedRevision );
|
|
100
|
+
}
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
return {
|
|
@@ -97,5 +105,12 @@ export default function useGlobalStylesRevisions() {
|
|
|
97
105
|
hasUnsavedChanges: isDirty,
|
|
98
106
|
isLoading: false,
|
|
99
107
|
};
|
|
100
|
-
}, [
|
|
108
|
+
}, [
|
|
109
|
+
isDirty,
|
|
110
|
+
revisions,
|
|
111
|
+
currentUser,
|
|
112
|
+
authors,
|
|
113
|
+
userConfig,
|
|
114
|
+
isLoadingGlobalStylesRevisions,
|
|
115
|
+
] );
|
|
101
116
|
}
|
|
@@ -33,10 +33,8 @@ function KeyboardShortcutsEditMode() {
|
|
|
33
33
|
);
|
|
34
34
|
const { redo, undo } = useDispatch( coreStore );
|
|
35
35
|
const {
|
|
36
|
-
isFeatureActive,
|
|
37
36
|
setIsListViewOpened,
|
|
38
37
|
switchEditorMode,
|
|
39
|
-
toggleFeature,
|
|
40
38
|
setIsInserterOpened,
|
|
41
39
|
closeGeneralSidebar,
|
|
42
40
|
} = useDispatch( editSiteStore );
|
|
@@ -47,7 +45,8 @@ function KeyboardShortcutsEditMode() {
|
|
|
47
45
|
const { getBlockName, getSelectedBlockClientId, getBlockAttributes } =
|
|
48
46
|
useSelect( blockEditorStore );
|
|
49
47
|
|
|
50
|
-
const {
|
|
48
|
+
const { get: getPreference } = useSelect( preferencesStore );
|
|
49
|
+
const { set: setPreference, toggle } = useDispatch( preferencesStore );
|
|
51
50
|
const { createInfoNotice } = useDispatch( noticesStore );
|
|
52
51
|
|
|
53
52
|
const toggleDistractionFree = () => {
|
|
@@ -135,9 +134,9 @@ function KeyboardShortcutsEditMode() {
|
|
|
135
134
|
|
|
136
135
|
useShortcut( 'core/edit-site/toggle-distraction-free', () => {
|
|
137
136
|
toggleDistractionFree();
|
|
138
|
-
|
|
137
|
+
toggle( 'core/edit-site', 'distractionFree' );
|
|
139
138
|
createInfoNotice(
|
|
140
|
-
|
|
139
|
+
getPreference( 'core/edit-site', 'distractionFree' )
|
|
141
140
|
? __( 'Distraction free mode turned on.' )
|
|
142
141
|
: __( 'Distraction free mode turned off.' ),
|
|
143
142
|
{
|
|
@@ -340,6 +340,12 @@ export default function Layout() {
|
|
|
340
340
|
! isEditorLoading
|
|
341
341
|
}
|
|
342
342
|
isFullWidth={ isEditing }
|
|
343
|
+
defaultSize={ {
|
|
344
|
+
width:
|
|
345
|
+
canvasSize.width -
|
|
346
|
+
24 /* $canvas-padding */,
|
|
347
|
+
height: canvasSize.height,
|
|
348
|
+
} }
|
|
343
349
|
isOversized={
|
|
344
350
|
isResizableFrameOversized
|
|
345
351
|
}
|
|
@@ -6,7 +6,7 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { useState, useRef
|
|
9
|
+
import { useState, useRef } from '@wordpress/element';
|
|
10
10
|
import {
|
|
11
11
|
ResizableBox,
|
|
12
12
|
Tooltip,
|
|
@@ -82,6 +82,8 @@ function ResizableFrame( {
|
|
|
82
82
|
setIsOversized,
|
|
83
83
|
isReady,
|
|
84
84
|
children,
|
|
85
|
+
/** The default (unresized) width/height of the frame, based on the space availalbe in the viewport. */
|
|
86
|
+
defaultSize,
|
|
85
87
|
innerContentStyle,
|
|
86
88
|
} ) {
|
|
87
89
|
const [ frameSize, setFrameSize ] = useState( INITIAL_FRAME_SIZE );
|
|
@@ -95,22 +97,13 @@ function ResizableFrame( {
|
|
|
95
97
|
[]
|
|
96
98
|
);
|
|
97
99
|
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
|
|
98
|
-
const initialAspectRatioRef = useRef( null );
|
|
99
|
-
// The width of the resizable frame on initial render.
|
|
100
|
-
const initialComputedWidthRef = useRef( null );
|
|
101
100
|
const FRAME_TRANSITION = { type: 'tween', duration: isResizing ? 0 : 0.5 };
|
|
102
101
|
const frameRef = useRef( null );
|
|
103
102
|
const resizableHandleHelpId = useInstanceId(
|
|
104
103
|
ResizableFrame,
|
|
105
104
|
'edit-site-resizable-frame-handle-help'
|
|
106
105
|
);
|
|
107
|
-
|
|
108
|
-
// Remember frame dimensions on initial render.
|
|
109
|
-
useEffect( () => {
|
|
110
|
-
const { offsetWidth, offsetHeight } = frameRef.current.resizable;
|
|
111
|
-
initialComputedWidthRef.current = offsetWidth;
|
|
112
|
-
initialAspectRatioRef.current = offsetWidth / offsetHeight;
|
|
113
|
-
}, [] );
|
|
106
|
+
const defaultAspectRatio = defaultSize.width / defaultSize.height;
|
|
114
107
|
|
|
115
108
|
const handleResizeStart = ( _event, _direction, ref ) => {
|
|
116
109
|
// Remember the starting width so we don't have to get `ref.offsetWidth` on
|
|
@@ -126,7 +119,7 @@ function ResizableFrame( {
|
|
|
126
119
|
const maxDoubledDelta =
|
|
127
120
|
delta.width < 0 // is shrinking
|
|
128
121
|
? deltaAbs
|
|
129
|
-
: (
|
|
122
|
+
: ( defaultSize.width - startingWidth ) / 2;
|
|
130
123
|
const deltaToDouble = Math.min( deltaAbs, maxDoubledDelta );
|
|
131
124
|
const doubleSegment = deltaAbs === 0 ? 0 : deltaToDouble / deltaAbs;
|
|
132
125
|
const singleSegment = 1 - doubleSegment;
|
|
@@ -135,17 +128,14 @@ function ResizableFrame( {
|
|
|
135
128
|
|
|
136
129
|
const updatedWidth = startingWidth + delta.width;
|
|
137
130
|
|
|
138
|
-
setIsOversized( updatedWidth >
|
|
131
|
+
setIsOversized( updatedWidth > defaultSize.width );
|
|
139
132
|
|
|
140
133
|
// Width will be controlled by the library (via `resizeRatio`),
|
|
141
134
|
// so we only need to update the height.
|
|
142
135
|
setFrameSize( {
|
|
143
136
|
height: isOversized
|
|
144
137
|
? '100%'
|
|
145
|
-
: calculateNewHeight(
|
|
146
|
-
updatedWidth,
|
|
147
|
-
initialAspectRatioRef.current
|
|
148
|
-
),
|
|
138
|
+
: calculateNewHeight( updatedWidth, defaultAspectRatio ),
|
|
149
139
|
} );
|
|
150
140
|
};
|
|
151
141
|
|
|
@@ -186,15 +176,12 @@ function ResizableFrame( {
|
|
|
186
176
|
FRAME_MIN_WIDTH,
|
|
187
177
|
frameRef.current.resizable.offsetWidth + delta
|
|
188
178
|
),
|
|
189
|
-
|
|
179
|
+
defaultSize.width
|
|
190
180
|
);
|
|
191
181
|
|
|
192
182
|
setFrameSize( {
|
|
193
183
|
width: newWidth,
|
|
194
|
-
height: calculateNewHeight(
|
|
195
|
-
newWidth,
|
|
196
|
-
initialAspectRatioRef.current
|
|
197
|
-
),
|
|
184
|
+
height: calculateNewHeight( newWidth, defaultAspectRatio ),
|
|
198
185
|
} );
|
|
199
186
|
};
|
|
200
187
|
|
|
@@ -291,9 +278,7 @@ function ResizableFrame( {
|
|
|
291
278
|
undefined
|
|
292
279
|
}
|
|
293
280
|
aria-valuemin={ FRAME_MIN_WIDTH }
|
|
294
|
-
aria-valuemax={
|
|
295
|
-
initialComputedWidthRef.current
|
|
296
|
-
}
|
|
281
|
+
aria-valuemax={ defaultSize.width }
|
|
297
282
|
onKeyDown={ handleResizableHandleKeyDown }
|
|
298
283
|
initial="hidden"
|
|
299
284
|
exit="hidden"
|
|
@@ -11,6 +11,7 @@ import { isRTL, __, sprintf } from '@wordpress/i18n';
|
|
|
11
11
|
import { chevronRight, chevronLeft } from '@wordpress/icons';
|
|
12
12
|
import { store as coreStore } from '@wordpress/core-data';
|
|
13
13
|
import { useSelect } from '@wordpress/data';
|
|
14
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Internal dependencies
|
|
@@ -23,6 +24,8 @@ import {
|
|
|
23
24
|
currentlyPreviewingTheme,
|
|
24
25
|
} from '../../utils/is-previewing-theme';
|
|
25
26
|
|
|
27
|
+
const { useLocation } = unlock( routerPrivateApis );
|
|
28
|
+
|
|
26
29
|
export default function SidebarNavigationScreen( {
|
|
27
30
|
isRoot,
|
|
28
31
|
title,
|
|
@@ -31,7 +34,7 @@ export default function SidebarNavigationScreen( {
|
|
|
31
34
|
content,
|
|
32
35
|
footer,
|
|
33
36
|
description,
|
|
34
|
-
backPath,
|
|
37
|
+
backPath: backPathProp,
|
|
35
38
|
} ) {
|
|
36
39
|
const { dashboardLink } = useSelect( ( select ) => {
|
|
37
40
|
const { getSettings } = unlock( select( editSiteStore ) );
|
|
@@ -40,6 +43,7 @@ export default function SidebarNavigationScreen( {
|
|
|
40
43
|
};
|
|
41
44
|
}, [] );
|
|
42
45
|
const { getTheme } = useSelect( coreStore );
|
|
46
|
+
const location = useLocation();
|
|
43
47
|
const navigator = useNavigator();
|
|
44
48
|
const theme = getTheme( currentlyPreviewingTheme() );
|
|
45
49
|
const icon = isRTL() ? chevronRight : chevronLeft;
|
|
@@ -56,13 +60,17 @@ export default function SidebarNavigationScreen( {
|
|
|
56
60
|
alignment="flex-start"
|
|
57
61
|
className="edit-site-sidebar-navigation-screen__title-icon"
|
|
58
62
|
>
|
|
59
|
-
{ ! isRoot &&
|
|
63
|
+
{ ! isRoot && (
|
|
60
64
|
<SidebarButton
|
|
61
65
|
onClick={ () => {
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
const backPath =
|
|
67
|
+
backPathProp ?? location.state?.backPath;
|
|
68
|
+
if ( backPath ) {
|
|
69
|
+
navigator.goTo( backPath, {
|
|
70
|
+
isBack: true,
|
|
71
|
+
} );
|
|
64
72
|
} else {
|
|
65
|
-
navigator.
|
|
73
|
+
navigator.goToParent();
|
|
66
74
|
}
|
|
67
75
|
} }
|
|
68
76
|
icon={ icon }
|
|
@@ -70,16 +78,6 @@ export default function SidebarNavigationScreen( {
|
|
|
70
78
|
showTooltip={ false }
|
|
71
79
|
/>
|
|
72
80
|
) }
|
|
73
|
-
{ ! isRoot && backPath && (
|
|
74
|
-
<SidebarButton
|
|
75
|
-
onClick={ () =>
|
|
76
|
-
navigator.goTo( backPath, { isBack: true } )
|
|
77
|
-
}
|
|
78
|
-
icon={ icon }
|
|
79
|
-
label={ __( 'Back' ) }
|
|
80
|
-
showTooltip={ false }
|
|
81
|
-
/>
|
|
82
|
-
) }
|
|
83
81
|
{ isRoot && (
|
|
84
82
|
<SidebarButton
|
|
85
83
|
icon={ icon }
|
|
@@ -23,10 +23,12 @@ import {
|
|
|
23
23
|
currentlyPreviewingTheme,
|
|
24
24
|
} from '../../utils/is-previewing-theme';
|
|
25
25
|
import { unlock } from '../../lock-unlock';
|
|
26
|
+
import { getPathFromURL } from '../sync-state-with-url/use-sync-path-with-url';
|
|
26
27
|
|
|
27
|
-
const { useHistory } = unlock( routerPrivateApis );
|
|
28
|
+
const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
28
29
|
|
|
29
30
|
export default function LeafMoreMenu( props ) {
|
|
31
|
+
const location = useLocation();
|
|
30
32
|
const history = useHistory();
|
|
31
33
|
const { block } = props;
|
|
32
34
|
const { clientId } = block;
|
|
@@ -63,22 +65,32 @@ export default function LeafMoreMenu( props ) {
|
|
|
63
65
|
attributes.type &&
|
|
64
66
|
history
|
|
65
67
|
) {
|
|
66
|
-
history.push(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
history.push(
|
|
69
|
+
{
|
|
70
|
+
postType: attributes.type,
|
|
71
|
+
postId: attributes.id,
|
|
72
|
+
...( isPreviewingTheme() && {
|
|
73
|
+
wp_theme_preview: currentlyPreviewingTheme(),
|
|
74
|
+
} ),
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
backPath: getPathFromURL( location.params ),
|
|
78
|
+
}
|
|
79
|
+
);
|
|
73
80
|
}
|
|
74
81
|
if ( name === 'core/page-list-item' && attributes.id && history ) {
|
|
75
|
-
history.push(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
history.push(
|
|
83
|
+
{
|
|
84
|
+
postType: 'page',
|
|
85
|
+
postId: attributes.id,
|
|
86
|
+
...( isPreviewingTheme() && {
|
|
87
|
+
wp_theme_preview: currentlyPreviewingTheme(),
|
|
88
|
+
} ),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
backPath: getPathFromURL( location.params ),
|
|
92
|
+
}
|
|
93
|
+
);
|
|
82
94
|
}
|
|
83
95
|
},
|
|
84
96
|
[ history ]
|
|
@@ -28,10 +28,15 @@ import { unlock } from '../../lock-unlock';
|
|
|
28
28
|
const { useHistory } = unlock( routerPrivateApis );
|
|
29
29
|
|
|
30
30
|
const PageItem = ( { postType = 'page', postId, ...props } ) => {
|
|
31
|
-
const linkInfo = useLink(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const linkInfo = useLink(
|
|
32
|
+
{
|
|
33
|
+
postType,
|
|
34
|
+
postId,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
backPath: '/page',
|
|
38
|
+
}
|
|
39
|
+
);
|
|
35
40
|
return <SidebarNavigationItem { ...linkInfo } { ...props } />;
|
|
36
41
|
};
|
|
37
42
|
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
__experimentalHeading as Heading,
|
|
11
11
|
} from '@wordpress/components';
|
|
12
12
|
import { useViewportMatch } from '@wordpress/compose';
|
|
13
|
-
import { useSelect } from '@wordpress/data';
|
|
14
13
|
import { getTemplatePartIcon } from '@wordpress/editor';
|
|
15
14
|
import { __ } from '@wordpress/i18n';
|
|
16
15
|
import { getQueryArgs } from '@wordpress/url';
|
|
@@ -24,7 +23,6 @@ import SidebarNavigationItem from '../sidebar-navigation-item';
|
|
|
24
23
|
import SidebarNavigationScreen from '../sidebar-navigation-screen';
|
|
25
24
|
import CategoryItem from './category-item';
|
|
26
25
|
import { DEFAULT_CATEGORY, DEFAULT_TYPE } from '../page-patterns/utils';
|
|
27
|
-
import { store as editSiteStore } from '../../store';
|
|
28
26
|
import { useLink } from '../routes/link';
|
|
29
27
|
import usePatternCategories from './use-pattern-categories';
|
|
30
28
|
import useMyPatterns from './use-my-patterns';
|
|
@@ -106,11 +104,6 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
106
104
|
const { patternCategories, hasPatterns } = usePatternCategories();
|
|
107
105
|
const { myPatterns } = useMyPatterns();
|
|
108
106
|
|
|
109
|
-
const isTemplatePartsMode = useSelect( ( select ) => {
|
|
110
|
-
const settings = select( editSiteStore ).getSettings();
|
|
111
|
-
return !! settings.supportsTemplatePartsMode;
|
|
112
|
-
}, [] );
|
|
113
|
-
|
|
114
107
|
const templatePartsLink = useLink( { path: '/wp_template_part/all' } );
|
|
115
108
|
const footer = ! isMobileViewport ? (
|
|
116
109
|
<ItemGroup>
|
|
@@ -129,7 +122,6 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
129
122
|
|
|
130
123
|
return (
|
|
131
124
|
<SidebarNavigationScreen
|
|
132
|
-
isRoot={ isTemplatePartsMode }
|
|
133
125
|
title={ __( 'Patterns' ) }
|
|
134
126
|
description={ __(
|
|
135
127
|
'Manage what patterns are available when editing the site.'
|