@wordpress/edit-site 5.5.0 → 5.6.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/CHANGELOG.md +2 -0
- package/build/components/add-new-template/new-template.js +16 -10
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/app/index.js +4 -2
- package/build/components/app/index.js.map +1 -1
- package/build/components/block-editor/editor-canvas.js +2 -1
- package/build/components/block-editor/editor-canvas.js.map +1 -1
- package/build/components/editor/index.js +2 -4
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/border-panel.js +20 -159
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/context-menu.js +2 -3
- package/build/components/global-styles/context-menu.js.map +1 -1
- package/build/components/global-styles/hooks.js +11 -26
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +2 -3
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-border.js +13 -5
- package/build/components/global-styles/screen-border.js.map +1 -1
- package/build/components/global-styles/screen-root.js +2 -1
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-style-variations.js +2 -1
- package/build/components/global-styles/screen-style-variations.js.map +1 -1
- package/build/components/layout/index.js +7 -0
- package/build/components/layout/index.js.map +1 -1
- package/build/components/list/added-by.js +128 -136
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/list/index.js +2 -1
- package/build/components/list/index.js.map +1 -1
- package/build/components/list/table.js +6 -5
- package/build/components/list/table.js.map +1 -1
- package/build/components/routes/link.js +4 -1
- package/build/components/routes/link.js.map +1 -1
- package/build/components/save-button/index.js +2 -5
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/save-hub/index.js +82 -0
- package/build/components/save-hub/index.js.map +1 -0
- package/build/components/sidebar/index.js +2 -4
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +5 -2
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-main/index.js +13 -13
- package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-item/index.js +9 -14
- package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js +87 -10
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
- package/build/components/sidebar-navigation-screen-template/index.js +59 -10
- package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates/index.js +5 -2
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build/components/site-hub/index.js +3 -1
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/style-book/index.js +134 -19
- package/build/components/style-book/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
- package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build/components/template-details/index.js +0 -3
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-part-converter/convert-to-regular.js +8 -12
- package/build/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +2 -2
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/components/template-part-converter/index.js +19 -14
- package/build/components/template-part-converter/index.js.map +1 -1
- package/build/components/use-edited-entity-record/index.js +6 -6
- package/build/components/use-edited-entity-record/index.js.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/utils/history.js +8 -2
- package/build/utils/history.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +18 -11
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/app/index.js +3 -2
- package/build-module/components/app/index.js.map +1 -1
- package/build-module/components/block-editor/editor-canvas.js +2 -1
- package/build-module/components/block-editor/editor-canvas.js.map +1 -1
- package/build-module/components/editor/index.js +2 -3
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +21 -157
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/context-menu.js +2 -2
- package/build-module/components/global-styles/context-menu.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +11 -26
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +2 -2
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-border.js +11 -2
- package/build-module/components/global-styles/screen-border.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +2 -1
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-style-variations.js +2 -1
- package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
- package/build-module/components/layout/index.js +7 -0
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/list/added-by.js +126 -137
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/list/index.js +2 -1
- package/build-module/components/list/index.js.map +1 -1
- package/build-module/components/list/table.js +6 -5
- package/build-module/components/list/table.js.map +1 -1
- package/build-module/components/routes/link.js +5 -2
- package/build-module/components/routes/link.js.map +1 -1
- package/build-module/components/save-button/index.js +2 -5
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/save-hub/index.js +68 -0
- package/build-module/components/save-hub/index.js.map +1 -0
- package/build-module/components/sidebar/index.js +2 -4
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +5 -2
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-main/index.js +13 -13
- package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +13 -18
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +81 -10
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-template/index.js +60 -13
- package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -2
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/components/site-hub/index.js +3 -1
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/style-book/index.js +135 -22
- package/build-module/components/style-book/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
- package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/components/template-details/index.js +0 -3
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-regular.js +9 -13
- package/build-module/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +3 -3
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/components/template-part-converter/index.js +20 -15
- package/build-module/components/template-part-converter/index.js.map +1 -1
- package/build-module/components/use-edited-entity-record/index.js +6 -6
- package/build-module/components/use-edited-entity-record/index.js.map +1 -1
- package/build-module/index.js +4 -1
- package/build-module/index.js.map +1 -1
- package/build-module/utils/history.js +9 -3
- package/build-module/utils/history.js.map +1 -1
- package/build-style/style-rtl.css +168 -111
- package/build-style/style.css +168 -111
- package/package.json +31 -31
- package/src/components/add-new-template/new-template.js +57 -32
- package/src/components/add-new-template/style.scss +12 -1
- package/src/components/app/index.js +9 -6
- package/src/components/block-editor/editor-canvas.js +2 -1
- package/src/components/editor/index.js +61 -65
- package/src/components/global-styles/border-panel.js +24 -199
- package/src/components/global-styles/context-menu.js +2 -2
- package/src/components/global-styles/hooks.js +12 -36
- package/src/components/global-styles/screen-block-list.js +2 -2
- package/src/components/global-styles/screen-border.js +9 -2
- package/src/components/global-styles/screen-root.js +1 -1
- package/src/components/global-styles/screen-style-variations.js +5 -1
- package/src/components/global-styles/style.scss +10 -0
- package/src/components/layout/index.js +15 -0
- package/src/components/layout/style.scss +1 -3
- package/src/components/list/added-by.js +144 -140
- package/src/components/list/index.js +3 -1
- package/src/components/list/table.js +7 -4
- package/src/components/routes/link.js +9 -2
- package/src/components/save-button/index.js +2 -2
- package/src/components/save-hub/index.js +78 -0
- package/src/components/save-hub/style.scss +15 -0
- package/src/components/sidebar/index.js +2 -3
- package/src/components/sidebar/style.scss +4 -3
- package/src/components/sidebar-button/style.scss +2 -1
- package/src/components/sidebar-navigation-item/style.scss +1 -23
- package/src/components/sidebar-navigation-screen/index.js +6 -0
- package/src/components/sidebar-navigation-screen/style.scss +15 -0
- package/src/components/sidebar-navigation-screen-main/index.js +21 -8
- package/src/components/sidebar-navigation-screen-navigation-item/index.js +30 -21
- package/src/components/sidebar-navigation-screen-navigation-menus/index.js +92 -9
- package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
- package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
- package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +108 -1
- package/src/components/sidebar-navigation-screen-template/index.js +82 -11
- package/src/components/sidebar-navigation-screen-template/style.scss +25 -0
- package/src/components/sidebar-navigation-screen-templates/index.js +7 -0
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
- package/src/components/site-hub/index.js +5 -1
- package/src/components/site-hub/style.scss +5 -1
- package/src/components/style-book/index.js +209 -54
- package/src/components/style-book/style.scss +1 -45
- package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
- package/src/components/sync-state-with-url/use-sync-path-with-url.js +12 -7
- package/src/components/template-details/index.js +0 -3
- package/src/components/template-part-converter/convert-to-regular.js +10 -17
- package/src/components/template-part-converter/convert-to-template-part.js +9 -16
- package/src/components/template-part-converter/index.js +28 -12
- package/src/components/use-edited-entity-record/index.js +26 -18
- package/src/index.js +5 -1
- package/src/store/test/actions.js +0 -2
- package/src/style.scss +2 -1
- package/src/utils/history.js +13 -9
- package/build/components/navigation-inspector/index.js +0 -161
- package/build/components/navigation-inspector/index.js.map +0 -1
- package/build/components/navigation-inspector/navigation-menu.js +0 -79
- package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
- package/build-module/components/navigation-inspector/index.js +0 -146
- package/build-module/components/navigation-inspector/index.js.map +0 -1
- package/build-module/components/navigation-inspector/navigation-menu.js +0 -69
- package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
- package/src/components/navigation-inspector/index.js +0 -191
- package/src/components/navigation-inspector/navigation-menu.js +0 -84
- package/src/components/navigation-inspector/style.scss +0 -46
|
@@ -8,6 +8,10 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
10
|
Button,
|
|
11
|
+
__unstableComposite as Composite,
|
|
12
|
+
__unstableUseCompositeState as useCompositeState,
|
|
13
|
+
__unstableCompositeItem as CompositeItem,
|
|
14
|
+
Disabled,
|
|
11
15
|
TabPanel,
|
|
12
16
|
createSlotFill,
|
|
13
17
|
__experimentalUseSlotFills as useSlotFills,
|
|
@@ -20,9 +24,13 @@ import {
|
|
|
20
24
|
createBlock,
|
|
21
25
|
} from '@wordpress/blocks';
|
|
22
26
|
import {
|
|
23
|
-
|
|
27
|
+
BlockList,
|
|
24
28
|
privateApis as blockEditorPrivateApis,
|
|
29
|
+
store as blockEditorStore,
|
|
30
|
+
__unstableEditorStyles as EditorStyles,
|
|
31
|
+
__unstableIframe as Iframe,
|
|
25
32
|
} from '@wordpress/block-editor';
|
|
33
|
+
import { useSelect } from '@wordpress/data';
|
|
26
34
|
import { closeSmall } from '@wordpress/icons';
|
|
27
35
|
import {
|
|
28
36
|
useResizeObserver,
|
|
@@ -38,12 +46,84 @@ import { ESCAPE } from '@wordpress/keycodes';
|
|
|
38
46
|
*/
|
|
39
47
|
import { unlock } from '../../private-apis';
|
|
40
48
|
|
|
41
|
-
const { useGlobalStyle } = unlock(
|
|
49
|
+
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
|
|
50
|
+
blockEditorPrivateApis
|
|
51
|
+
);
|
|
42
52
|
|
|
43
53
|
const SLOT_FILL_NAME = 'EditSiteStyleBook';
|
|
44
54
|
const { Slot: StyleBookSlot, Fill: StyleBookFill } =
|
|
45
55
|
createSlotFill( SLOT_FILL_NAME );
|
|
46
56
|
|
|
57
|
+
// The content area of the Style Book is rendered within an iframe so that global styles
|
|
58
|
+
// are applied to elements within the entire content area. To support elements that are
|
|
59
|
+
// not part of the block previews, such as headings and layout for the block previews,
|
|
60
|
+
// additional CSS rules need to be passed into the iframe. These are hard-coded below.
|
|
61
|
+
// Note that button styles are unset, and then focus rules from the `Button` component are
|
|
62
|
+
// applied to the `button` element, targeted via `.edit-site-style-book__example`.
|
|
63
|
+
// This is to ensure that browser default styles for buttons are not applied to the previews.
|
|
64
|
+
const STYLE_BOOK_IFRAME_STYLES = `
|
|
65
|
+
.edit-site-style-book__examples {
|
|
66
|
+
max-width: 900px;
|
|
67
|
+
margin: 0 auto;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.edit-site-style-book__example {
|
|
71
|
+
border-radius: 2px;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
gap: 40px;
|
|
76
|
+
margin-bottom: 40px;
|
|
77
|
+
padding: 16px;
|
|
78
|
+
width: 100%;
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.edit-site-style-book__example.is-selected {
|
|
83
|
+
box-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.edit-site-style-book__example:focus:not(:disabled) {
|
|
87
|
+
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
88
|
+
outline: 3px solid transparent;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example {
|
|
92
|
+
flex-direction: row;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.edit-site-style-book__example-title {
|
|
96
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
97
|
+
font-size: 11px;
|
|
98
|
+
font-weight: 500;
|
|
99
|
+
line-height: normal;
|
|
100
|
+
margin: 0;
|
|
101
|
+
text-align: left;
|
|
102
|
+
text-transform: uppercase;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example-title {
|
|
106
|
+
text-align: right;
|
|
107
|
+
width: 120px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.edit-site-style-book__example-preview {
|
|
111
|
+
width: 100%;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.edit-site-style-book__example-preview .block-editor-block-list__insertion-point,
|
|
115
|
+
.edit-site-style-book__example-preview .block-list-appender {
|
|
116
|
+
display: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:first-child {
|
|
120
|
+
margin-top: 0;
|
|
121
|
+
}
|
|
122
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:last-child {
|
|
123
|
+
margin-bottom: 0;
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
|
|
47
127
|
function getExamples() {
|
|
48
128
|
// Use our own example for the Heading block so that we can show multiple
|
|
49
129
|
// heading levels.
|
|
@@ -118,6 +198,15 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
118
198
|
[ examples ]
|
|
119
199
|
);
|
|
120
200
|
|
|
201
|
+
const originalSettings = useSelect(
|
|
202
|
+
( select ) => select( blockEditorStore ).getSettings(),
|
|
203
|
+
[]
|
|
204
|
+
);
|
|
205
|
+
const settings = useMemo(
|
|
206
|
+
() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),
|
|
207
|
+
[ originalSettings ]
|
|
208
|
+
);
|
|
209
|
+
|
|
121
210
|
function closeOnEscape( event ) {
|
|
122
211
|
if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
|
|
123
212
|
event.preventDefault();
|
|
@@ -156,12 +245,47 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
156
245
|
tabs={ tabs }
|
|
157
246
|
>
|
|
158
247
|
{ ( tab ) => (
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
248
|
+
<Iframe
|
|
249
|
+
className="edit-site-style-book__iframe"
|
|
250
|
+
head={
|
|
251
|
+
<>
|
|
252
|
+
<EditorStyles styles={ settings.styles } />
|
|
253
|
+
<style>
|
|
254
|
+
{
|
|
255
|
+
// Forming a "block formatting context" to prevent margin collapsing.
|
|
256
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
|
|
257
|
+
`.is-root-container { display: flow-root; }
|
|
258
|
+
body { position: relative; padding: 32px !important; }` +
|
|
259
|
+
STYLE_BOOK_IFRAME_STYLES
|
|
260
|
+
}
|
|
261
|
+
</style>
|
|
262
|
+
</>
|
|
263
|
+
}
|
|
264
|
+
name="style-book-canvas"
|
|
265
|
+
tabIndex={ 0 }
|
|
266
|
+
>
|
|
267
|
+
{ /* Filters need to be rendered before children to avoid Safari rendering issues. */ }
|
|
268
|
+
{ settings.svgFilters }
|
|
269
|
+
<Examples
|
|
270
|
+
className={ classnames(
|
|
271
|
+
'edit-site-style-book__examples',
|
|
272
|
+
{
|
|
273
|
+
'is-wide': sizes.width > 600,
|
|
274
|
+
}
|
|
275
|
+
) }
|
|
276
|
+
examples={ examples }
|
|
277
|
+
category={ tab.name }
|
|
278
|
+
label={ sprintf(
|
|
279
|
+
// translators: %s: Category of blocks, e.g. Text.
|
|
280
|
+
__(
|
|
281
|
+
'Examples of blocks in the %s category'
|
|
282
|
+
),
|
|
283
|
+
tab.title
|
|
284
|
+
) }
|
|
285
|
+
isSelected={ isSelected }
|
|
286
|
+
onSelect={ onSelect }
|
|
287
|
+
/>
|
|
288
|
+
</Iframe>
|
|
165
289
|
) }
|
|
166
290
|
</TabPanel>
|
|
167
291
|
</section>
|
|
@@ -169,52 +293,83 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
169
293
|
);
|
|
170
294
|
}
|
|
171
295
|
|
|
172
|
-
const Examples = memo(
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
296
|
+
const Examples = memo(
|
|
297
|
+
( { className, examples, category, label, isSelected, onSelect } ) => {
|
|
298
|
+
const composite = useCompositeState( { orientation: 'vertical' } );
|
|
299
|
+
return (
|
|
300
|
+
<Composite
|
|
301
|
+
{ ...composite }
|
|
302
|
+
className={ className }
|
|
303
|
+
aria-label={ label }
|
|
304
|
+
>
|
|
305
|
+
{ examples
|
|
306
|
+
.filter( ( example ) => example.category === category )
|
|
307
|
+
.map( ( example ) => (
|
|
308
|
+
<Example
|
|
309
|
+
key={ example.name }
|
|
310
|
+
id={ `example-${ example.name }` }
|
|
311
|
+
composite={ composite }
|
|
312
|
+
title={ example.title }
|
|
313
|
+
blocks={ example.blocks }
|
|
314
|
+
isSelected={ isSelected( example.name ) }
|
|
315
|
+
onClick={ () => {
|
|
316
|
+
onSelect( example.name );
|
|
317
|
+
} }
|
|
318
|
+
/>
|
|
319
|
+
) ) }
|
|
320
|
+
</Composite>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const Example = ( { composite, id, title, blocks, isSelected, onClick } ) => {
|
|
326
|
+
const originalSettings = useSelect(
|
|
327
|
+
( select ) => select( blockEditorStore ).getSettings(),
|
|
328
|
+
[]
|
|
329
|
+
);
|
|
330
|
+
const settings = useMemo(
|
|
331
|
+
() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),
|
|
332
|
+
[ originalSettings ]
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
// Cache the list of blocks to avoid additional processing when the component is re-rendered.
|
|
336
|
+
const renderedBlocks = useMemo(
|
|
337
|
+
() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),
|
|
338
|
+
[ blocks ]
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<CompositeItem
|
|
343
|
+
{ ...composite }
|
|
344
|
+
className={ classnames( 'edit-site-style-book__example', {
|
|
345
|
+
'is-selected': isSelected,
|
|
346
|
+
} ) }
|
|
347
|
+
id={ id }
|
|
348
|
+
aria-label={ sprintf(
|
|
349
|
+
// translators: %s: Title of a block, e.g. Heading.
|
|
350
|
+
__( 'Open %s styles in Styles panel' ),
|
|
351
|
+
title
|
|
352
|
+
) }
|
|
353
|
+
onClick={ onClick }
|
|
354
|
+
role="button"
|
|
355
|
+
as="div"
|
|
356
|
+
>
|
|
357
|
+
<span className="edit-site-style-book__example-title">
|
|
358
|
+
{ title }
|
|
359
|
+
</span>
|
|
360
|
+
<div className="edit-site-style-book__example-preview" aria-hidden>
|
|
361
|
+
<Disabled className="edit-site-style-book__example-preview__content">
|
|
362
|
+
<ExperimentalBlockEditorProvider
|
|
363
|
+
value={ renderedBlocks }
|
|
364
|
+
settings={ settings }
|
|
365
|
+
>
|
|
366
|
+
<BlockList renderAppender={ false } />
|
|
367
|
+
</ExperimentalBlockEditorProvider>
|
|
368
|
+
</Disabled>
|
|
369
|
+
</div>
|
|
370
|
+
</CompositeItem>
|
|
371
|
+
);
|
|
372
|
+
};
|
|
218
373
|
|
|
219
374
|
function useHasStyleBook() {
|
|
220
375
|
const fills = useSlotFills( SLOT_FILL_NAME );
|
|
@@ -26,53 +26,9 @@
|
|
|
26
26
|
bottom: 0;
|
|
27
27
|
left: 0;
|
|
28
28
|
overflow: auto;
|
|
29
|
-
padding:
|
|
29
|
+
padding: 0;
|
|
30
30
|
position: absolute;
|
|
31
31
|
right: 0;
|
|
32
32
|
top: $grid-unit-60; // Height of tabs.
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
.edit-site-style-book__examples {
|
|
37
|
-
max-width: 900px;
|
|
38
|
-
margin: 0 auto;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.edit-site-style-book__example {
|
|
42
|
-
background: none;
|
|
43
|
-
border-radius: $radius-block-ui;
|
|
44
|
-
border: none;
|
|
45
|
-
color: inherit;
|
|
46
|
-
cursor: pointer;
|
|
47
|
-
display: flex;
|
|
48
|
-
flex-direction: column;
|
|
49
|
-
gap: $grid-unit-50;
|
|
50
|
-
margin-bottom: $grid-unit-50;
|
|
51
|
-
padding: $grid-unit-20;
|
|
52
|
-
width: 100%;
|
|
53
|
-
|
|
54
|
-
&.is-selected {
|
|
55
|
-
box-shadow: 0 0 0 1px var(--wp-admin-theme-color);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.edit-site-style-book.is-wide & {
|
|
59
|
-
flex-direction: row;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.edit-site-style-book__example-title {
|
|
64
|
-
font-size: 11px;
|
|
65
|
-
font-weight: 500;
|
|
66
|
-
margin: 0;
|
|
67
|
-
text-align: left;
|
|
68
|
-
text-transform: uppercase;
|
|
69
|
-
|
|
70
|
-
.edit-site-style-book.is-wide & {
|
|
71
|
-
text-align: right;
|
|
72
|
-
width: 120px;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.edit-site-style-book__example-preview {
|
|
77
|
-
width: 100%;
|
|
78
|
-
}
|
|
@@ -20,22 +20,52 @@ export default function useSyncCanvasModeWithURL() {
|
|
|
20
20
|
);
|
|
21
21
|
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
|
|
22
22
|
const currentCanvasMode = useRef( canvasMode );
|
|
23
|
-
const { canvas: canvasInUrl
|
|
23
|
+
const { canvas: canvasInUrl } = params;
|
|
24
24
|
const currentCanvasInUrl = useRef( canvasInUrl );
|
|
25
|
+
const currentUrlParams = useRef( params );
|
|
26
|
+
useEffect( () => {
|
|
27
|
+
currentUrlParams.current = params;
|
|
28
|
+
}, [ params ] );
|
|
29
|
+
|
|
25
30
|
useEffect( () => {
|
|
26
31
|
currentCanvasMode.current = canvasMode;
|
|
27
|
-
if (
|
|
32
|
+
if ( canvasMode === 'init' ) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
canvasMode === 'edit' &&
|
|
38
|
+
currentCanvasInUrl.current !== canvasMode
|
|
39
|
+
) {
|
|
40
|
+
history.push( {
|
|
41
|
+
...currentUrlParams.current,
|
|
42
|
+
canvas: 'edit',
|
|
43
|
+
} );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
canvasMode === 'view' &&
|
|
48
|
+
currentCanvasInUrl.current !== undefined
|
|
49
|
+
) {
|
|
28
50
|
history.push( {
|
|
29
|
-
...
|
|
30
|
-
canvas:
|
|
51
|
+
...currentUrlParams.current,
|
|
52
|
+
canvas: undefined,
|
|
31
53
|
} );
|
|
32
54
|
}
|
|
33
|
-
}, [ canvasMode ] );
|
|
55
|
+
}, [ canvasMode, history ] );
|
|
34
56
|
|
|
35
57
|
useEffect( () => {
|
|
36
58
|
currentCanvasInUrl.current = canvasInUrl;
|
|
37
|
-
if (
|
|
38
|
-
|
|
59
|
+
if (
|
|
60
|
+
canvasInUrl === undefined &&
|
|
61
|
+
currentCanvasMode.current !== 'view'
|
|
62
|
+
) {
|
|
63
|
+
setCanvasMode( 'view' );
|
|
64
|
+
} else if (
|
|
65
|
+
canvasInUrl === 'edit' &&
|
|
66
|
+
currentCanvasMode.current !== 'edit'
|
|
67
|
+
) {
|
|
68
|
+
setCanvasMode( 'edit' );
|
|
39
69
|
}
|
|
40
|
-
}, [ canvasInUrl ] );
|
|
70
|
+
}, [ canvasInUrl, setCanvasMode ] );
|
|
41
71
|
}
|
|
@@ -41,8 +41,16 @@ export default function useSyncPathWithURL() {
|
|
|
41
41
|
} = useNavigator();
|
|
42
42
|
const currentUrlParams = useRef( urlParams );
|
|
43
43
|
const currentPath = useRef( navigatorLocation.path );
|
|
44
|
+
const isMounting = useRef( true );
|
|
44
45
|
|
|
45
46
|
useEffect( () => {
|
|
47
|
+
// The navigatorParams are only initially filled properly when the
|
|
48
|
+
// navigator screens mount. so we ignore the first synchronisation.
|
|
49
|
+
if ( isMounting.current ) {
|
|
50
|
+
isMounting.current = false;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
function updateUrlParams( newUrlParams ) {
|
|
47
55
|
if (
|
|
48
56
|
Object.entries( newUrlParams ).every( ( [ key, value ] ) => {
|
|
@@ -65,17 +73,14 @@ export default function useSyncPathWithURL() {
|
|
|
65
73
|
postId: navigatorParams?.postId,
|
|
66
74
|
path: undefined,
|
|
67
75
|
} );
|
|
68
|
-
} else if ( navigatorParams?.postType && ! navigatorParams?.postId ) {
|
|
69
|
-
updateUrlParams( {
|
|
70
|
-
postType: navigatorParams?.postType,
|
|
71
|
-
path: navigatorLocation.path,
|
|
72
|
-
postId: undefined,
|
|
73
|
-
} );
|
|
74
76
|
} else {
|
|
75
77
|
updateUrlParams( {
|
|
76
78
|
postType: undefined,
|
|
77
79
|
postId: undefined,
|
|
78
|
-
path:
|
|
80
|
+
path:
|
|
81
|
+
navigatorLocation.path === '/'
|
|
82
|
+
? undefined
|
|
83
|
+
: navigatorLocation.path,
|
|
79
84
|
} );
|
|
80
85
|
}
|
|
81
86
|
}, [ navigatorLocation?.path, navigatorParams, history ] );
|
|
@@ -32,9 +32,6 @@ export default function TemplateDetails( { template, onClose } ) {
|
|
|
32
32
|
|
|
33
33
|
// TODO: We should update this to filter by template part's areas as well.
|
|
34
34
|
const browseAllLinkProps = useLink( {
|
|
35
|
-
canvas: 'view',
|
|
36
|
-
postType: template.type,
|
|
37
|
-
postId: undefined,
|
|
38
35
|
path: '/' + template.type + '/all',
|
|
39
36
|
} );
|
|
40
37
|
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
BlockSettingsMenuControls,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { MenuItem } from '@wordpress/components';
|
|
10
7
|
import { __ } from '@wordpress/i18n';
|
|
11
8
|
|
|
12
|
-
export default function ConvertToRegularBlocks( { clientId } ) {
|
|
9
|
+
export default function ConvertToRegularBlocks( { clientId, onClose } ) {
|
|
13
10
|
const { getBlocks } = useSelect( blockEditorStore );
|
|
14
11
|
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
15
12
|
|
|
@@ -23,17 +20,13 @@ export default function ConvertToRegularBlocks( { clientId } ) {
|
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
return (
|
|
26
|
-
<
|
|
27
|
-
{ (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{ __( 'Detach blocks from template part' ) }
|
|
35
|
-
</MenuItem>
|
|
36
|
-
) }
|
|
37
|
-
</BlockSettingsMenuControls>
|
|
23
|
+
<MenuItem
|
|
24
|
+
onClick={ () => {
|
|
25
|
+
replaceBlocks( clientId, getBlocks( clientId ) );
|
|
26
|
+
onClose();
|
|
27
|
+
} }
|
|
28
|
+
>
|
|
29
|
+
{ __( 'Detach blocks from template part' ) }
|
|
30
|
+
</MenuItem>
|
|
38
31
|
);
|
|
39
32
|
}
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
BlockSettingsMenuControls,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { MenuItem } from '@wordpress/components';
|
|
10
7
|
import { createBlock, serialize } from '@wordpress/blocks';
|
|
11
8
|
import { __ } from '@wordpress/i18n';
|
|
@@ -78,18 +75,14 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
|
|
|
78
75
|
|
|
79
76
|
return (
|
|
80
77
|
<>
|
|
81
|
-
<
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{ __( 'Create Template part' ) }
|
|
90
|
-
</MenuItem>
|
|
91
|
-
) }
|
|
92
|
-
</BlockSettingsMenuControls>
|
|
78
|
+
<MenuItem
|
|
79
|
+
icon={ symbolFilled }
|
|
80
|
+
onClick={ () => {
|
|
81
|
+
setIsModalOpen( true );
|
|
82
|
+
} }
|
|
83
|
+
>
|
|
84
|
+
{ __( 'Create Template part' ) }
|
|
85
|
+
</MenuItem>
|
|
93
86
|
{ isModalOpen && (
|
|
94
87
|
<CreateTemplatePartModal
|
|
95
88
|
closeModal={ () => {
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BlockSettingsMenuControls,
|
|
7
|
+
store as blockEditorStore,
|
|
8
|
+
} from '@wordpress/block-editor';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Internal dependencies
|
|
@@ -11,20 +14,33 @@ import ConvertToRegularBlocks from './convert-to-regular';
|
|
|
11
14
|
import ConvertToTemplatePart from './convert-to-template-part';
|
|
12
15
|
|
|
13
16
|
export default function TemplatePartConverter() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return (
|
|
18
|
+
<BlockSettingsMenuControls>
|
|
19
|
+
{ ( { selectedClientIds, onClose } ) => (
|
|
20
|
+
<TemplatePartConverterMenuItem
|
|
21
|
+
clientIds={ selectedClientIds }
|
|
22
|
+
onClose={ onClose }
|
|
23
|
+
/>
|
|
24
|
+
) }
|
|
25
|
+
</BlockSettingsMenuControls>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function TemplatePartConverterMenuItem( { clientIds, onClose } ) {
|
|
30
|
+
const blocks = useSelect(
|
|
31
|
+
( select ) =>
|
|
32
|
+
select( blockEditorStore ).getBlocksByClientId( clientIds ),
|
|
33
|
+
[ clientIds ]
|
|
34
|
+
);
|
|
23
35
|
|
|
24
36
|
// Allow converting a single template part to standard blocks.
|
|
25
37
|
if ( blocks.length === 1 && blocks[ 0 ]?.name === 'core/template-part' ) {
|
|
26
|
-
return
|
|
38
|
+
return (
|
|
39
|
+
<ConvertToRegularBlocks
|
|
40
|
+
clientId={ clientIds[ 0 ] }
|
|
41
|
+
onClose={ onClose }
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
27
44
|
}
|
|
28
|
-
|
|
29
45
|
return <ConvertToTemplatePart clientIds={ clientIds } blocks={ blocks } />;
|
|
30
46
|
}
|
|
@@ -11,25 +11,33 @@ import { decodeEntities } from '@wordpress/html-entities';
|
|
|
11
11
|
*/
|
|
12
12
|
import { store as editSiteStore } from '../../store';
|
|
13
13
|
|
|
14
|
-
export default function useEditedEntityRecord() {
|
|
15
|
-
const { record, title, description, isLoaded } = useSelect(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
select(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
export default function useEditedEntityRecord( postType, postId ) {
|
|
15
|
+
const { record, title, description, isLoaded } = useSelect(
|
|
16
|
+
( select ) => {
|
|
17
|
+
const { getEditedPostType, getEditedPostId } =
|
|
18
|
+
select( editSiteStore );
|
|
19
|
+
const { getEditedEntityRecord } = select( coreStore );
|
|
20
|
+
const { __experimentalGetTemplateInfo: getTemplateInfo } =
|
|
21
|
+
select( editorStore );
|
|
22
|
+
const usedPostType = postType ?? getEditedPostType();
|
|
23
|
+
const usedPostId = postId ?? getEditedPostId();
|
|
24
|
+
const _record = getEditedEntityRecord(
|
|
25
|
+
'postType',
|
|
26
|
+
usedPostType,
|
|
27
|
+
usedPostId
|
|
28
|
+
);
|
|
29
|
+
const _isLoaded = !! usedPostId;
|
|
30
|
+
const templateInfo = getTemplateInfo( _record );
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
return {
|
|
33
|
+
record: _record,
|
|
34
|
+
title: templateInfo.title,
|
|
35
|
+
description: templateInfo.description,
|
|
36
|
+
isLoaded: _isLoaded,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
[ postType, postId ]
|
|
40
|
+
);
|
|
33
41
|
|
|
34
42
|
return {
|
|
35
43
|
isLoaded,
|