@wordpress/editor 13.24.1 → 13.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +1 -1
- package/build/components/document-bar/index.js +164 -0
- package/build/components/document-bar/index.js.map +1 -0
- package/build/components/document-outline/index.js +82 -1
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/document-tools/index.js +160 -0
- package/build/components/document-tools/index.js.map +1 -0
- package/build/components/editor-canvas/edit-template-blocks-notification.js +106 -0
- package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
- package/build/components/editor-canvas/index.js +298 -0
- package/build/components/editor-canvas/index.js.map +1 -0
- package/build/components/entities-saved-states/index.js +3 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/index.js +12 -2
- package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build/components/index.js +72 -8
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +9 -1
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter-sidebar/index.js +77 -0
- package/build/components/inserter-sidebar/index.js.map +1 -0
- package/build/components/list-view-sidebar/index.js +150 -0
- package/build/components/list-view-sidebar/index.js.map +1 -0
- package/build/components/list-view-sidebar/list-view-outline.js +28 -0
- package/build/components/list-view-sidebar/list-view-outline.js.map +1 -0
- package/build/components/offline-status/index.native.js +85 -0
- package/build/components/offline-status/index.native.js.map +1 -0
- package/build/components/page-attributes/panel.js +63 -0
- package/build/components/page-attributes/panel.js.map +1 -0
- package/build/components/post-discussion/panel.js +59 -0
- package/build/components/post-discussion/panel.js.map +1 -0
- package/build/components/post-excerpt/check.js +19 -0
- package/build/components/post-excerpt/check.js.map +1 -1
- package/build/components/post-excerpt/panel.js +55 -0
- package/build/components/post-excerpt/panel.js.map +1 -0
- package/build/components/post-excerpt/plugin.js +72 -0
- package/build/components/post-excerpt/plugin.js.map +1 -0
- package/build/components/post-featured-image/index.js +5 -8
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-featured-image/panel.js +60 -0
- package/build/components/post-featured-image/panel.js.map +1 -0
- package/build/components/post-last-revision/panel.js +27 -0
- package/build/components/post-last-revision/panel.js.map +1 -0
- package/build/components/post-publish-button/index.js +1 -0
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-panel/maybe-upload-media.js +2 -4
- package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build/components/post-saved-state/index.js +13 -8
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/panel.js +1 -1
- package/build/components/post-schedule/panel.js.map +1 -1
- package/build/components/post-taxonomies/panel.js +68 -0
- package/build/components/post-taxonomies/panel.js.map +1 -0
- package/build/components/post-template/block-theme.js +100 -0
- package/build/components/post-template/block-theme.js.map +1 -0
- package/build/components/post-template/classic-theme.js +171 -0
- package/build/components/post-template/classic-theme.js.map +1 -0
- package/build/components/post-template/create-new-template-modal.js +98 -0
- package/build/components/post-template/create-new-template-modal.js.map +1 -0
- package/build/components/post-template/create-new-template.js +55 -0
- package/build/components/post-template/create-new-template.js.map +1 -0
- package/build/components/post-template/hooks.js +88 -0
- package/build/components/post-template/hooks.js.map +1 -0
- package/build/components/post-template/panel.js +70 -0
- package/build/components/post-template/panel.js.map +1 -0
- package/build/components/post-template/reset-default-template.js +48 -0
- package/build/components/post-template/reset-default-template.js.map +1 -0
- package/build/components/post-template/swap-template-button.js +86 -0
- package/build/components/post-template/swap-template-button.js.map +1 -0
- package/build/components/post-title/index.native.js +25 -15
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-view-link/index.js +58 -0
- package/build/components/post-view-link/index.js.map +1 -0
- package/build/components/post-visibility/check.js +5 -17
- package/build/components/post-visibility/check.js.map +1 -1
- package/build/components/preview-dropdown/index.js +118 -0
- package/build/components/preview-dropdown/index.js.map +1 -0
- package/build/components/provider/index.js +24 -82
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +36 -8
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/navigation-block-editing-mode.js +40 -0
- package/build/components/provider/navigation-block-editing-mode.js.map +1 -0
- package/build/components/provider/use-block-editor-settings.js +38 -15
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/pattern-partial-syncing.js +49 -0
- package/build/hooks/pattern-partial-syncing.js.map +1 -0
- package/build/private-apis.js +14 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +161 -13
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +2 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +5 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +52 -0
- package/build/store/private-actions.js.map +1 -0
- package/build/store/private-selectors.js +52 -0
- package/build/store/private-selectors.js.map +1 -0
- package/build/store/reducer.js +109 -27
- package/build/store/reducer.js.map +1 -1
- package/build/store/reducer.native.js +0 -1
- package/build/store/reducer.native.js.map +1 -1
- package/build/store/selectors.js +104 -9
- package/build/store/selectors.js.map +1 -1
- package/build/utils/media-upload/index.js +8 -2
- package/build/utils/media-upload/index.js.map +1 -1
- package/build-module/components/document-bar/index.js +156 -0
- package/build-module/components/document-bar/index.js.map +1 -0
- package/build-module/components/document-outline/index.js +82 -1
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/document-tools/index.js +151 -0
- package/build-module/components/document-tools/index.js.map +1 -0
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js +100 -0
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
- package/build-module/components/editor-canvas/index.js +289 -0
- package/build-module/components/editor-canvas/index.js.map +1 -0
- package/build-module/components/entities-saved-states/index.js +3 -1
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/index.js +12 -2
- package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build-module/components/index.js +9 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -0
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter-sidebar/index.js +70 -0
- package/build-module/components/inserter-sidebar/index.js.map +1 -0
- package/build-module/components/list-view-sidebar/index.js +142 -0
- package/build-module/components/list-view-sidebar/index.js.map +1 -0
- package/build-module/components/list-view-sidebar/list-view-outline.js +20 -0
- package/build-module/components/list-view-sidebar/list-view-outline.js.map +1 -0
- package/build-module/components/offline-status/index.native.js +77 -0
- package/build-module/components/offline-status/index.native.js.map +1 -0
- package/build-module/components/page-attributes/panel.js +53 -0
- package/build-module/components/page-attributes/panel.js.map +1 -0
- package/build-module/components/post-discussion/panel.js +50 -0
- package/build-module/components/post-discussion/panel.js.map +1 -0
- package/build-module/components/post-excerpt/check.js +19 -0
- package/build-module/components/post-excerpt/check.js.map +1 -1
- package/build-module/components/post-excerpt/panel.js +48 -0
- package/build-module/components/post-excerpt/panel.js.map +1 -0
- package/build-module/components/post-excerpt/plugin.js +64 -0
- package/build-module/components/post-excerpt/plugin.js.map +1 -0
- package/build-module/components/post-featured-image/index.js +5 -8
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-featured-image/panel.js +51 -0
- package/build-module/components/post-featured-image/panel.js.map +1 -0
- package/build-module/components/post-last-revision/panel.js +18 -0
- package/build-module/components/post-last-revision/panel.js.map +1 -0
- package/build-module/components/post-publish-button/index.js +1 -0
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js +2 -4
- package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build-module/components/post-saved-state/index.js +13 -8
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/panel.js +1 -1
- package/build-module/components/post-schedule/panel.js.map +1 -1
- package/build-module/components/post-taxonomies/panel.js +59 -0
- package/build-module/components/post-taxonomies/panel.js.map +1 -0
- package/build-module/components/post-template/block-theme.js +92 -0
- package/build-module/components/post-template/block-theme.js.map +1 -0
- package/build-module/components/post-template/classic-theme.js +162 -0
- package/build-module/components/post-template/classic-theme.js.map +1 -0
- package/build-module/components/post-template/create-new-template-modal.js +91 -0
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -0
- package/build-module/components/post-template/create-new-template.js +47 -0
- package/build-module/components/post-template/create-new-template.js.map +1 -0
- package/build-module/components/post-template/hooks.js +78 -0
- package/build-module/components/post-template/hooks.js.map +1 -0
- package/build-module/components/post-template/panel.js +62 -0
- package/build-module/components/post-template/panel.js.map +1 -0
- package/build-module/components/post-template/reset-default-template.js +41 -0
- package/build-module/components/post-template/reset-default-template.js.map +1 -0
- package/build-module/components/post-template/swap-template-button.js +79 -0
- package/build-module/components/post-template/swap-template-button.js.map +1 -0
- package/build-module/components/post-title/index.native.js +26 -16
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-view-link/index.js +51 -0
- package/build-module/components/post-view-link/index.js.map +1 -0
- package/build-module/components/post-visibility/check.js +6 -16
- package/build-module/components/post-visibility/check.js.map +1 -1
- package/build-module/components/preview-dropdown/index.js +110 -0
- package/build-module/components/preview-dropdown/index.js.map +1 -0
- package/build-module/components/provider/index.js +25 -83
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +37 -9
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/navigation-block-editing-mode.js +34 -0
- package/build-module/components/provider/navigation-block-editing-mode.js.map +1 -0
- package/build-module/components/provider/use-block-editor-settings.js +38 -15
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/pattern-partial-syncing.js +46 -0
- package/build-module/hooks/pattern-partial-syncing.js.map +1 -0
- package/build-module/private-apis.js +14 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +147 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +2 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +5 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +44 -0
- package/build-module/store/private-actions.js.map +1 -0
- package/build-module/store/private-selectors.js +43 -0
- package/build-module/store/private-selectors.js.map +1 -0
- package/build-module/store/reducer.js +103 -26
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/reducer.native.js +1 -2
- package/build-module/store/reducer.native.js.map +1 -1
- package/build-module/store/selectors.js +93 -6
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/media-upload/index.js +8 -2
- package/build-module/utils/media-upload/index.js.map +1 -1
- package/build-style/style-rtl.css +433 -0
- package/build-style/style.css +433 -0
- package/package.json +32 -31
- package/src/components/document-bar/index.js +193 -0
- package/src/components/document-bar/style.scss +130 -0
- package/src/components/document-outline/index.js +48 -1
- package/src/components/document-outline/style.scss +12 -0
- package/src/components/document-tools/index.js +177 -0
- package/src/components/document-tools/style.scss +98 -0
- package/src/components/editor-canvas/edit-template-blocks-notification.js +108 -0
- package/src/components/editor-canvas/index.js +386 -0
- package/src/components/editor-canvas/style.scss +5 -0
- package/src/components/entities-saved-states/index.js +3 -1
- package/src/components/entities-saved-states/style.scss +4 -0
- package/src/components/global-keyboard-shortcuts/index.js +12 -2
- package/src/components/global-keyboard-shortcuts/register-shortcuts.js +10 -0
- package/src/components/index.js +9 -1
- package/src/components/index.native.js +1 -0
- package/src/components/inserter-sidebar/index.js +73 -0
- package/src/components/inserter-sidebar/style.scss +22 -0
- package/src/components/list-view-sidebar/index.js +169 -0
- package/src/components/list-view-sidebar/list-view-outline.js +37 -0
- package/src/components/list-view-sidebar/style.scss +84 -0
- package/src/components/offline-status/index.native.js +101 -0
- package/src/components/offline-status/style.native.scss +28 -0
- package/src/components/offline-status/test/index.native.js +108 -0
- package/src/components/page-attributes/panel.js +62 -0
- package/src/components/post-discussion/panel.js +57 -0
- package/src/components/post-excerpt/check.js +18 -0
- package/src/components/post-excerpt/panel.js +57 -0
- package/src/components/post-excerpt/plugin.js +61 -0
- package/src/components/post-excerpt/test/plugin.js +36 -0
- package/src/components/post-featured-image/index.js +3 -7
- package/src/components/post-featured-image/panel.js +55 -0
- package/src/components/post-last-revision/panel.js +22 -0
- package/src/components/post-last-revision/style.scss +10 -0
- package/src/components/post-publish-button/index.js +1 -0
- package/src/components/post-publish-panel/maybe-upload-media.js +3 -8
- package/src/components/post-saved-state/index.js +9 -8
- package/src/components/post-saved-state/test/__snapshots__/index.js.snap +2 -2
- package/src/components/post-schedule/panel.js +1 -1
- package/src/components/post-taxonomies/panel.js +66 -0
- package/src/components/post-template/block-theme.js +110 -0
- package/src/components/post-template/classic-theme.js +213 -0
- package/src/components/post-template/create-new-template-modal.js +139 -0
- package/src/components/post-template/create-new-template.js +50 -0
- package/src/components/post-template/hooks.js +95 -0
- package/src/components/post-template/panel.js +66 -0
- package/src/components/post-template/reset-default-template.js +43 -0
- package/src/components/post-template/style.scss +52 -0
- package/src/components/post-template/swap-template-button.js +86 -0
- package/src/components/post-title/index.native.js +32 -18
- package/src/components/post-title/style.scss +1 -0
- package/src/components/post-title/test/__snapshots__/index.native.js.snap +25 -0
- package/src/components/post-title/test/index.native.js +78 -0
- package/src/components/post-view-link/index.js +47 -0
- package/src/components/post-visibility/check.js +10 -15
- package/src/components/post-visibility/test/check.js +24 -13
- package/src/components/preview-dropdown/index.js +133 -0
- package/src/components/preview-dropdown/style.scss +5 -0
- package/src/components/provider/index.js +28 -118
- package/src/components/provider/index.native.js +55 -14
- package/src/components/provider/navigation-block-editing-mode.js +37 -0
- package/src/components/provider/use-block-editor-settings.js +42 -17
- package/src/hooks/index.js +1 -0
- package/src/hooks/pattern-partial-syncing.js +73 -0
- package/src/private-apis.js +14 -0
- package/src/store/actions.js +160 -9
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +5 -0
- package/src/store/private-actions.js +61 -0
- package/src/store/private-selectors.js +51 -0
- package/src/store/reducer.js +103 -26
- package/src/store/reducer.native.js +0 -2
- package/src/store/selectors.js +144 -42
- package/src/store/test/actions.js +56 -0
- package/src/store/test/reducer.js +98 -0
- package/src/store/test/selectors.js +137 -147
- package/src/style.scss +7 -0
- package/src/utils/media-upload/index.js +9 -2
- package/build/components/post-template/index.js +0 -66
- package/build/components/post-template/index.js.map +0 -1
- package/build-module/components/post-template/index.js +0 -57
- package/build-module/components/post-template/index.js.map +0 -1
- package/src/components/post-template/index.js +0 -64
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
BlockEditorProvider,
|
|
10
10
|
BlockContextProvider,
|
|
11
11
|
privateApis as blockEditorPrivateApis,
|
|
12
|
-
store as blockEditorStore,
|
|
13
12
|
} from '@wordpress/block-editor';
|
|
14
13
|
import { store as noticesStore } from '@wordpress/notices';
|
|
15
14
|
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
|
|
@@ -23,73 +22,13 @@ import { store as editorStore } from '../../store';
|
|
|
23
22
|
import useBlockEditorSettings from './use-block-editor-settings';
|
|
24
23
|
import { unlock } from '../../lock-unlock';
|
|
25
24
|
import DisableNonPageContentBlocks from './disable-non-page-content-blocks';
|
|
26
|
-
import
|
|
25
|
+
import NavigationBlockEditingMode from './navigation-block-editing-mode';
|
|
27
26
|
|
|
28
27
|
const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
|
|
29
28
|
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );
|
|
30
29
|
|
|
31
30
|
const noop = () => {};
|
|
32
31
|
|
|
33
|
-
/**
|
|
34
|
-
* For the Navigation block editor, we need to force the block editor to contentOnly for that block.
|
|
35
|
-
*
|
|
36
|
-
* Set block editing mode to contentOnly when entering Navigation focus mode.
|
|
37
|
-
* this ensures that non-content controls on the block will be hidden and thus
|
|
38
|
-
* the user can focus on editing the Navigation Menu content only.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} navigationBlockClientId ClientId.
|
|
41
|
-
*/
|
|
42
|
-
function useForceFocusModeForNavigation( navigationBlockClientId ) {
|
|
43
|
-
const { setBlockEditingMode, unsetBlockEditingMode } =
|
|
44
|
-
useDispatch( blockEditorStore );
|
|
45
|
-
|
|
46
|
-
useEffect( () => {
|
|
47
|
-
if ( ! navigationBlockClientId ) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setBlockEditingMode( navigationBlockClientId, 'contentOnly' );
|
|
52
|
-
|
|
53
|
-
return () => {
|
|
54
|
-
unsetBlockEditingMode( navigationBlockClientId );
|
|
55
|
-
};
|
|
56
|
-
}, [
|
|
57
|
-
navigationBlockClientId,
|
|
58
|
-
unsetBlockEditingMode,
|
|
59
|
-
setBlockEditingMode,
|
|
60
|
-
] );
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Helper method to extract the post content block types from a template.
|
|
65
|
-
*
|
|
66
|
-
* @param {Array} blocks Template blocks.
|
|
67
|
-
*
|
|
68
|
-
* @return {Array} Flattened object.
|
|
69
|
-
*/
|
|
70
|
-
function extractPageContentBlockTypesFromTemplateBlocks( blocks ) {
|
|
71
|
-
const result = [];
|
|
72
|
-
for ( let i = 0; i < blocks.length; i++ ) {
|
|
73
|
-
// Since the Query Block could contain PAGE_CONTENT_BLOCK_TYPES block types,
|
|
74
|
-
// we skip it because we only want to render stand-alone page content blocks in the block list.
|
|
75
|
-
if ( blocks[ i ].name === 'core/query' ) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if ( PAGE_CONTENT_BLOCK_TYPES.includes( blocks[ i ].name ) ) {
|
|
79
|
-
result.push( createBlock( blocks[ i ].name ) );
|
|
80
|
-
}
|
|
81
|
-
if ( blocks[ i ].innerBlocks.length ) {
|
|
82
|
-
result.push(
|
|
83
|
-
...extractPageContentBlockTypesFromTemplateBlocks(
|
|
84
|
-
blocks[ i ].innerBlocks
|
|
85
|
-
)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
32
|
/**
|
|
94
33
|
* Depending on the post, template and template mode,
|
|
95
34
|
* returns the appropriate blocks and change handlers for the block editor provider.
|
|
@@ -125,36 +64,6 @@ function useBlockEditorProps( post, template, mode ) {
|
|
|
125
64
|
}
|
|
126
65
|
}, [ post.type, post.id ] );
|
|
127
66
|
|
|
128
|
-
const maybePostOnlyBlocks = useMemo( () => {
|
|
129
|
-
if ( mode === 'post-only' ) {
|
|
130
|
-
const postContentBlocks =
|
|
131
|
-
extractPageContentBlockTypesFromTemplateBlocks(
|
|
132
|
-
templateBlocks
|
|
133
|
-
);
|
|
134
|
-
return [
|
|
135
|
-
createBlock(
|
|
136
|
-
'core/group',
|
|
137
|
-
{
|
|
138
|
-
layout: { type: 'constrained' },
|
|
139
|
-
style: {
|
|
140
|
-
spacing: {
|
|
141
|
-
margin: {
|
|
142
|
-
top: '4em', // Mimics the post editor.
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
postContentBlocks.length
|
|
148
|
-
? postContentBlocks
|
|
149
|
-
: [
|
|
150
|
-
createBlock( 'core/post-title' ),
|
|
151
|
-
createBlock( 'core/post-content' ),
|
|
152
|
-
]
|
|
153
|
-
),
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
|
-
}, [ templateBlocks, mode ] );
|
|
157
|
-
|
|
158
67
|
// It is important that we don't create a new instance of blocks on every change
|
|
159
68
|
// We should only create a new instance if the blocks them selves change, not a dependency of them.
|
|
160
69
|
const blocks = useMemo( () => {
|
|
@@ -162,33 +71,19 @@ function useBlockEditorProps( post, template, mode ) {
|
|
|
162
71
|
return maybeNavigationBlocks;
|
|
163
72
|
}
|
|
164
73
|
|
|
165
|
-
if ( maybePostOnlyBlocks ) {
|
|
166
|
-
return maybePostOnlyBlocks;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
74
|
if ( rootLevelPost === 'template' ) {
|
|
170
75
|
return templateBlocks;
|
|
171
76
|
}
|
|
172
77
|
|
|
173
78
|
return postBlocks;
|
|
174
|
-
}, [
|
|
175
|
-
maybeNavigationBlocks,
|
|
176
|
-
maybePostOnlyBlocks,
|
|
177
|
-
rootLevelPost,
|
|
178
|
-
templateBlocks,
|
|
179
|
-
postBlocks,
|
|
180
|
-
] );
|
|
79
|
+
}, [ maybeNavigationBlocks, rootLevelPost, templateBlocks, postBlocks ] );
|
|
181
80
|
|
|
182
81
|
// Handle fallback to postBlocks outside of the above useMemo, to ensure
|
|
183
82
|
// that constructed block templates that call `createBlock` are not generated
|
|
184
83
|
// too frequently. This ensures that clientIds are stable.
|
|
185
84
|
const disableRootLevelChanges =
|
|
186
85
|
( !! template && mode === 'template-locked' ) ||
|
|
187
|
-
post.type === 'wp_navigation'
|
|
188
|
-
mode === 'post-only';
|
|
189
|
-
const navigationBlockClientId =
|
|
190
|
-
post.type === 'wp_navigation' && blocks && blocks[ 0 ]?.clientId;
|
|
191
|
-
useForceFocusModeForNavigation( navigationBlockClientId );
|
|
86
|
+
post.type === 'wp_navigation';
|
|
192
87
|
if ( disableRootLevelChanges ) {
|
|
193
88
|
return [ blocks, noop, noop ];
|
|
194
89
|
}
|
|
@@ -269,11 +164,12 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
269
164
|
updatePostLock,
|
|
270
165
|
setupEditor,
|
|
271
166
|
updateEditorSettings,
|
|
272
|
-
|
|
273
|
-
|
|
167
|
+
setCurrentTemplateId,
|
|
168
|
+
setEditedPost,
|
|
169
|
+
setRenderingMode,
|
|
170
|
+
} = unlock( useDispatch( editorStore ) );
|
|
274
171
|
const { createWarningNotice } = useDispatch( noticesStore );
|
|
275
172
|
|
|
276
|
-
// Initialize and tear down the editor.
|
|
277
173
|
// Ideally this should be synced on each change and not just something you do once.
|
|
278
174
|
useLayoutEffect( () => {
|
|
279
175
|
// Assume that we don't need to initialize in the case of an error recovery.
|
|
@@ -299,17 +195,28 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
299
195
|
}
|
|
300
196
|
);
|
|
301
197
|
}
|
|
302
|
-
|
|
303
|
-
return () => {
|
|
304
|
-
__experimentalTearDownEditor();
|
|
305
|
-
};
|
|
306
198
|
}, [] );
|
|
307
199
|
|
|
200
|
+
// Synchronizes the active post with the state
|
|
201
|
+
useEffect( () => {
|
|
202
|
+
setEditedPost( post.type, post.id );
|
|
203
|
+
}, [ post.type, post.id ] );
|
|
204
|
+
|
|
308
205
|
// Synchronize the editor settings as they change.
|
|
309
206
|
useEffect( () => {
|
|
310
207
|
updateEditorSettings( settings );
|
|
311
208
|
}, [ settings, updateEditorSettings ] );
|
|
312
209
|
|
|
210
|
+
// Synchronizes the active template with the state.
|
|
211
|
+
useEffect( () => {
|
|
212
|
+
setCurrentTemplateId( template?.id );
|
|
213
|
+
}, [ template?.id, setCurrentTemplateId ] );
|
|
214
|
+
|
|
215
|
+
// Sets the right rendering mode when loading the editor.
|
|
216
|
+
useEffect( () => {
|
|
217
|
+
setRenderingMode( settings.defaultRenderingMode ?? 'post-only' );
|
|
218
|
+
}, [ settings.defaultRenderingMode, setRenderingMode ] );
|
|
219
|
+
|
|
313
220
|
if ( ! isReady ) {
|
|
314
221
|
return null;
|
|
315
222
|
}
|
|
@@ -332,9 +239,12 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
332
239
|
>
|
|
333
240
|
{ children }
|
|
334
241
|
<PatternsMenuItems />
|
|
335
|
-
{
|
|
336
|
-
|
|
337
|
-
)
|
|
242
|
+
{ mode === 'template-locked' && (
|
|
243
|
+
<DisableNonPageContentBlocks />
|
|
244
|
+
) }
|
|
245
|
+
{ type === 'wp_navigation' && (
|
|
246
|
+
<NavigationBlockEditingMode />
|
|
247
|
+
) }
|
|
338
248
|
</BlockEditorProviderComponent>
|
|
339
249
|
</BlockContextProvider>
|
|
340
250
|
</EntityProvider>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { BackHandler } from 'react-native';
|
|
4
5
|
import memize from 'memize';
|
|
5
6
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
6
7
|
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
parse,
|
|
28
29
|
serialize,
|
|
29
30
|
getUnregisteredTypeHandlerName,
|
|
31
|
+
getBlockType,
|
|
30
32
|
createBlock,
|
|
31
33
|
} from '@wordpress/blocks';
|
|
32
34
|
import { withDispatch, withSelect } from '@wordpress/data';
|
|
@@ -35,6 +37,7 @@ import { applyFilters } from '@wordpress/hooks';
|
|
|
35
37
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
36
38
|
import { getGlobalStyles, getColorsAndGradients } from '@wordpress/components';
|
|
37
39
|
import { NEW_BLOCK_TYPES } from '@wordpress/block-library';
|
|
40
|
+
import { __ } from '@wordpress/i18n';
|
|
38
41
|
|
|
39
42
|
const postTypeEntities = [
|
|
40
43
|
{ name: 'post', baseURL: '/wp/v2/posts' },
|
|
@@ -77,6 +80,8 @@ class NativeEditorProvider extends Component {
|
|
|
77
80
|
this.post
|
|
78
81
|
);
|
|
79
82
|
|
|
83
|
+
this.onHardwareBackPress = this.onHardwareBackPress.bind( this );
|
|
84
|
+
|
|
80
85
|
this.getEditorSettings = memize(
|
|
81
86
|
( settings, capabilities ) => ( {
|
|
82
87
|
...settings,
|
|
@@ -94,6 +99,7 @@ class NativeEditorProvider extends Component {
|
|
|
94
99
|
componentDidMount() {
|
|
95
100
|
const {
|
|
96
101
|
capabilities,
|
|
102
|
+
createErrorNotice,
|
|
97
103
|
locale,
|
|
98
104
|
hostAppNamespace,
|
|
99
105
|
updateEditorSettings,
|
|
@@ -136,17 +142,26 @@ class NativeEditorProvider extends Component {
|
|
|
136
142
|
this.subscriptionParentMediaAppend = subscribeMediaAppend(
|
|
137
143
|
( payload ) => {
|
|
138
144
|
const blockName = 'core/' + payload.mediaType;
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
const blockType = getBlockType( blockName );
|
|
146
|
+
|
|
147
|
+
if ( blockType && blockType?.name ) {
|
|
148
|
+
const newBlock = createBlock( blockType.name, {
|
|
149
|
+
id: payload.mediaId,
|
|
150
|
+
[ payload.mediaType === 'image' ? 'url' : 'src' ]:
|
|
151
|
+
payload.mediaUrl,
|
|
152
|
+
} );
|
|
153
|
+
|
|
154
|
+
const indexAfterSelected =
|
|
155
|
+
this.props.selectedBlockIndex + 1;
|
|
156
|
+
const insertionIndex =
|
|
157
|
+
indexAfterSelected || this.props.blockCount;
|
|
158
|
+
|
|
159
|
+
this.props.insertBlock( newBlock, insertionIndex );
|
|
160
|
+
} else {
|
|
161
|
+
createErrorNotice(
|
|
162
|
+
__( 'File type not supported as a media file.' )
|
|
163
|
+
);
|
|
164
|
+
}
|
|
150
165
|
}
|
|
151
166
|
);
|
|
152
167
|
|
|
@@ -179,6 +194,11 @@ class NativeEditorProvider extends Component {
|
|
|
179
194
|
this.setState( { isHelpVisible: true } );
|
|
180
195
|
} );
|
|
181
196
|
|
|
197
|
+
this.hardwareBackPressListener = BackHandler.addEventListener(
|
|
198
|
+
'hardwareBackPress',
|
|
199
|
+
this.onHardwareBackPress
|
|
200
|
+
);
|
|
201
|
+
|
|
182
202
|
// Request current block impressions from native app.
|
|
183
203
|
requestBlockTypeImpressions( ( storedImpressions ) => {
|
|
184
204
|
const impressions = { ...NEW_BLOCK_TYPES, ...storedImpressions };
|
|
@@ -238,6 +258,10 @@ class NativeEditorProvider extends Component {
|
|
|
238
258
|
if ( this.subscriptionParentShowEditorHelp ) {
|
|
239
259
|
this.subscriptionParentShowEditorHelp.remove();
|
|
240
260
|
}
|
|
261
|
+
|
|
262
|
+
if ( this.hardwareBackPressListener ) {
|
|
263
|
+
this.hardwareBackPressListener.remove();
|
|
264
|
+
}
|
|
241
265
|
}
|
|
242
266
|
|
|
243
267
|
getThemeColors( { rawStyles, rawFeatures } ) {
|
|
@@ -268,6 +292,16 @@ class NativeEditorProvider extends Component {
|
|
|
268
292
|
}
|
|
269
293
|
}
|
|
270
294
|
|
|
295
|
+
onHardwareBackPress() {
|
|
296
|
+
const { clearSelectedBlock, selectedBlockIndex } = this.props;
|
|
297
|
+
|
|
298
|
+
if ( selectedBlockIndex !== -1 ) {
|
|
299
|
+
clearSelectedBlock();
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
271
305
|
serializeToNativeAction() {
|
|
272
306
|
const title = this.props.title;
|
|
273
307
|
let html;
|
|
@@ -385,11 +419,16 @@ const ComposedNativeProvider = compose( [
|
|
|
385
419
|
withDispatch( ( dispatch ) => {
|
|
386
420
|
const { editPost, resetEditorBlocks, updateEditorSettings } =
|
|
387
421
|
dispatch( editorStore );
|
|
388
|
-
const {
|
|
389
|
-
|
|
422
|
+
const {
|
|
423
|
+
clearSelectedBlock,
|
|
424
|
+
updateSettings,
|
|
425
|
+
insertBlock,
|
|
426
|
+
replaceBlock,
|
|
427
|
+
} = dispatch( blockEditorStore );
|
|
390
428
|
const { switchEditorMode } = dispatch( editPostStore );
|
|
391
429
|
const { addEntities, receiveEntityRecords } = dispatch( coreStore );
|
|
392
|
-
const { createSuccessNotice } =
|
|
430
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
431
|
+
dispatch( noticesStore );
|
|
393
432
|
|
|
394
433
|
return {
|
|
395
434
|
updateBlockEditorSettings: updateSettings,
|
|
@@ -397,6 +436,8 @@ const ComposedNativeProvider = compose( [
|
|
|
397
436
|
addEntities,
|
|
398
437
|
insertBlock,
|
|
399
438
|
createSuccessNotice,
|
|
439
|
+
createErrorNotice,
|
|
440
|
+
clearSelectedBlock,
|
|
400
441
|
editTitle( title ) {
|
|
401
442
|
editPost( { title } );
|
|
402
443
|
},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from '@wordpress/element';
|
|
5
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* For the Navigation block editor, we need to force the block editor to contentOnly for that block.
|
|
10
|
+
*
|
|
11
|
+
* Set block editing mode to contentOnly when entering Navigation focus mode.
|
|
12
|
+
* this ensures that non-content controls on the block will be hidden and thus
|
|
13
|
+
* the user can focus on editing the Navigation Menu content only.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export default function NavigationBlockEditingMode() {
|
|
17
|
+
// In the navigation block editor,
|
|
18
|
+
// the navigation block is the only root block.
|
|
19
|
+
const blockClientId = useSelect(
|
|
20
|
+
( select ) => select( blockEditorStore ).getBlockOrder()?.[ 0 ],
|
|
21
|
+
[]
|
|
22
|
+
);
|
|
23
|
+
const { setBlockEditingMode, unsetBlockEditingMode } =
|
|
24
|
+
useDispatch( blockEditorStore );
|
|
25
|
+
|
|
26
|
+
useEffect( () => {
|
|
27
|
+
if ( ! blockClientId ) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setBlockEditingMode( blockClientId, 'contentOnly' );
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
unsetBlockEditingMode( blockClientId );
|
|
35
|
+
};
|
|
36
|
+
}, [ blockClientId, unsetBlockEditingMode, setBlockEditingMode ] );
|
|
37
|
+
}
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
__experimentalFetchUrlData as fetchUrlData,
|
|
10
10
|
} from '@wordpress/core-data';
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Internal dependencies
|
|
@@ -25,7 +27,6 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
25
27
|
'__experimentalFeatures',
|
|
26
28
|
'__experimentalGlobalStylesBaseStyles',
|
|
27
29
|
'__experimentalPreferredStyleVariations',
|
|
28
|
-
'__experimentalSetIsInserterOpened',
|
|
29
30
|
'__unstableGalleryWithImageBlocks',
|
|
30
31
|
'alignWide',
|
|
31
32
|
'allowedBlockTypes',
|
|
@@ -46,20 +47,16 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
46
47
|
'enableCustomSpacing',
|
|
47
48
|
'enableCustomUnits',
|
|
48
49
|
'enableOpenverseMediaCategory',
|
|
49
|
-
'focusMode',
|
|
50
|
-
'distractionFree',
|
|
51
50
|
'fontSizes',
|
|
52
51
|
'gradients',
|
|
53
52
|
'generateAnchors',
|
|
54
|
-
'
|
|
53
|
+
'getPostLinkProps',
|
|
55
54
|
'hasInlineToolbar',
|
|
56
|
-
'isDistractionFree',
|
|
57
55
|
'imageDefaultSize',
|
|
58
56
|
'imageDimensions',
|
|
59
57
|
'imageEditing',
|
|
60
58
|
'imageSizes',
|
|
61
59
|
'isRTL',
|
|
62
|
-
'keepCaretInsideBlock',
|
|
63
60
|
'locale',
|
|
64
61
|
'maxWidth',
|
|
65
62
|
'onUpdateDefaultBlockStyles',
|
|
@@ -88,7 +85,13 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
88
85
|
* @return {Object} Block Editor Settings.
|
|
89
86
|
*/
|
|
90
87
|
function useBlockEditorSettings( settings, postType, postId ) {
|
|
88
|
+
const isLargeViewport = useViewportMatch( 'medium' );
|
|
91
89
|
const {
|
|
90
|
+
allowRightClickOverrides,
|
|
91
|
+
focusMode,
|
|
92
|
+
hasFixedToolbar,
|
|
93
|
+
isDistractionFree,
|
|
94
|
+
keepCaretInsideBlock,
|
|
92
95
|
reusableBlocks,
|
|
93
96
|
hasUploadPermissions,
|
|
94
97
|
canUseUnfilteredHTML,
|
|
@@ -96,6 +99,8 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
96
99
|
pageOnFront,
|
|
97
100
|
pageForPosts,
|
|
98
101
|
userPatternCategories,
|
|
102
|
+
restBlockPatterns,
|
|
103
|
+
restBlockPatternCategories,
|
|
99
104
|
} = useSelect(
|
|
100
105
|
( select ) => {
|
|
101
106
|
const isWeb = Platform.OS === 'web';
|
|
@@ -105,18 +110,30 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
105
110
|
getEntityRecord,
|
|
106
111
|
getUserPatternCategories,
|
|
107
112
|
getEntityRecords,
|
|
113
|
+
getBlockPatterns,
|
|
114
|
+
getBlockPatternCategories,
|
|
108
115
|
} = select( coreStore );
|
|
116
|
+
const { get } = select( preferencesStore );
|
|
109
117
|
|
|
110
118
|
const siteSettings = canUser( 'read', 'settings' )
|
|
111
119
|
? getEntityRecord( 'root', 'site' )
|
|
112
120
|
: undefined;
|
|
113
121
|
|
|
114
122
|
return {
|
|
123
|
+
allowRightClickOverrides: get(
|
|
124
|
+
'core',
|
|
125
|
+
'allowRightClickOverrides'
|
|
126
|
+
),
|
|
115
127
|
canUseUnfilteredHTML: getRawEntityRecord(
|
|
116
128
|
'postType',
|
|
117
129
|
postType,
|
|
118
130
|
postId
|
|
119
131
|
)?._links?.hasOwnProperty( 'wp:action-unfiltered-html' ),
|
|
132
|
+
focusMode: get( 'core', 'focusMode' ),
|
|
133
|
+
hasFixedToolbar:
|
|
134
|
+
get( 'core', 'fixedToolbar' ) || ! isLargeViewport,
|
|
135
|
+
isDistractionFree: get( 'core', 'distractionFree' ),
|
|
136
|
+
keepCaretInsideBlock: get( 'core', 'keepCaretInsideBlock' ),
|
|
120
137
|
reusableBlocks: isWeb
|
|
121
138
|
? getEntityRecords( 'postType', 'wp_block', {
|
|
122
139
|
per_page: -1,
|
|
@@ -127,9 +144,11 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
127
144
|
pageOnFront: siteSettings?.page_on_front,
|
|
128
145
|
pageForPosts: siteSettings?.page_for_posts,
|
|
129
146
|
userPatternCategories: getUserPatternCategories(),
|
|
147
|
+
restBlockPatterns: getBlockPatterns(),
|
|
148
|
+
restBlockPatternCategories: getBlockPatternCategories(),
|
|
130
149
|
};
|
|
131
150
|
},
|
|
132
|
-
[ postType, postId ]
|
|
151
|
+
[ postType, postId, isLargeViewport ]
|
|
133
152
|
);
|
|
134
153
|
|
|
135
154
|
const settingsBlockPatterns =
|
|
@@ -139,15 +158,6 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
139
158
|
settings.__experimentalAdditionalBlockPatternCategories ?? // WP 6.0
|
|
140
159
|
settings.__experimentalBlockPatternCategories; // WP 5.9
|
|
141
160
|
|
|
142
|
-
const { restBlockPatterns, restBlockPatternCategories } = useSelect(
|
|
143
|
-
( select ) => ( {
|
|
144
|
-
restBlockPatterns: select( coreStore ).getBlockPatterns(),
|
|
145
|
-
restBlockPatternCategories:
|
|
146
|
-
select( coreStore ).getBlockPatternCategories(),
|
|
147
|
-
} ),
|
|
148
|
-
[]
|
|
149
|
-
);
|
|
150
|
-
|
|
151
161
|
const blockPatterns = useMemo(
|
|
152
162
|
() =>
|
|
153
163
|
[
|
|
@@ -180,7 +190,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
180
190
|
[ settingsBlockPatternCategories, restBlockPatternCategories ]
|
|
181
191
|
);
|
|
182
192
|
|
|
183
|
-
const { undo } = useDispatch( editorStore );
|
|
193
|
+
const { undo, setIsInserterOpened } = useDispatch( editorStore );
|
|
184
194
|
|
|
185
195
|
const { saveEntityRecord } = useDispatch( coreStore );
|
|
186
196
|
|
|
@@ -205,6 +215,8 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
205
215
|
[ saveEntityRecord, userCanCreatePages ]
|
|
206
216
|
);
|
|
207
217
|
|
|
218
|
+
const forceDisableFocusMode = settings.focusMode === false;
|
|
219
|
+
|
|
208
220
|
return useMemo(
|
|
209
221
|
() => ( {
|
|
210
222
|
...Object.fromEntries(
|
|
@@ -212,6 +224,11 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
212
224
|
BLOCK_EDITOR_SETTINGS.includes( key )
|
|
213
225
|
)
|
|
214
226
|
),
|
|
227
|
+
allowRightClickOverrides,
|
|
228
|
+
focusMode: focusMode && ! forceDisableFocusMode,
|
|
229
|
+
hasFixedToolbar,
|
|
230
|
+
isDistractionFree,
|
|
231
|
+
keepCaretInsideBlock,
|
|
215
232
|
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
|
|
216
233
|
__experimentalReusableBlocks: reusableBlocks,
|
|
217
234
|
__experimentalBlockPatterns: blockPatterns,
|
|
@@ -241,8 +258,15 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
241
258
|
postType === 'wp_navigation'
|
|
242
259
|
? [ [ 'core/navigation', {}, [] ] ]
|
|
243
260
|
: settings.template,
|
|
261
|
+
__experimentalSetIsInserterOpened: setIsInserterOpened,
|
|
244
262
|
} ),
|
|
245
263
|
[
|
|
264
|
+
allowRightClickOverrides,
|
|
265
|
+
focusMode,
|
|
266
|
+
forceDisableFocusMode,
|
|
267
|
+
hasFixedToolbar,
|
|
268
|
+
isDistractionFree,
|
|
269
|
+
keepCaretInsideBlock,
|
|
246
270
|
settings,
|
|
247
271
|
hasUploadPermissions,
|
|
248
272
|
reusableBlocks,
|
|
@@ -256,6 +280,7 @@ function useBlockEditorSettings( settings, postType, postId ) {
|
|
|
256
280
|
pageOnFront,
|
|
257
281
|
pageForPosts,
|
|
258
282
|
postType,
|
|
283
|
+
setIsInserterOpened,
|
|
259
284
|
]
|
|
260
285
|
);
|
|
261
286
|
}
|
package/src/hooks/index.js
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { addFilter } from '@wordpress/hooks';
|
|
5
|
+
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
6
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
7
|
+
import { useBlockEditingMode } from '@wordpress/block-editor';
|
|
8
|
+
import { hasBlockSupport } from '@wordpress/blocks';
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { store as editorStore } from '../store';
|
|
15
|
+
import { unlock } from '../lock-unlock';
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
PartialSyncingControls,
|
|
19
|
+
PATTERN_TYPES,
|
|
20
|
+
PARTIAL_SYNCING_SUPPORTED_BLOCKS,
|
|
21
|
+
} = unlock( patternsPrivateApis );
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Override the default edit UI to include a new block inspector control for
|
|
25
|
+
* assigning a partial syncing controls to supported blocks in the pattern editor.
|
|
26
|
+
* Currently, only the `core/paragraph` block is supported.
|
|
27
|
+
*
|
|
28
|
+
* @param {Component} BlockEdit Original component.
|
|
29
|
+
*
|
|
30
|
+
* @return {Component} Wrapped component.
|
|
31
|
+
*/
|
|
32
|
+
const withPartialSyncingControls = createHigherOrderComponent(
|
|
33
|
+
( BlockEdit ) => ( props ) => {
|
|
34
|
+
const blockEditingMode = useBlockEditingMode();
|
|
35
|
+
const hasCustomFieldsSupport = hasBlockSupport(
|
|
36
|
+
props.name,
|
|
37
|
+
'__experimentalConnections',
|
|
38
|
+
false
|
|
39
|
+
);
|
|
40
|
+
const isEditingPattern = useSelect(
|
|
41
|
+
( select ) =>
|
|
42
|
+
select( editorStore ).getCurrentPostType() ===
|
|
43
|
+
PATTERN_TYPES.user,
|
|
44
|
+
[]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const shouldShowPartialSyncingControls =
|
|
48
|
+
hasCustomFieldsSupport &&
|
|
49
|
+
props.isSelected &&
|
|
50
|
+
isEditingPattern &&
|
|
51
|
+
blockEditingMode === 'default' &&
|
|
52
|
+
Object.keys( PARTIAL_SYNCING_SUPPORTED_BLOCKS ).includes(
|
|
53
|
+
props.name
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<BlockEdit { ...props } />
|
|
59
|
+
{ shouldShowPartialSyncingControls && (
|
|
60
|
+
<PartialSyncingControls { ...props } />
|
|
61
|
+
) }
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if ( window.__experimentalPatternPartialSyncing ) {
|
|
68
|
+
addFilter(
|
|
69
|
+
'editor.BlockEdit',
|
|
70
|
+
'core/editor/with-partial-syncing-controls',
|
|
71
|
+
withPartialSyncingControls
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/private-apis.js
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
import EditorCanvas from './components/editor-canvas';
|
|
4
5
|
import { ExperimentalEditorProvider } from './components/provider';
|
|
5
6
|
import { lock } from './lock-unlock';
|
|
6
7
|
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
|
|
7
8
|
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
|
|
9
|
+
import DocumentTools from './components/document-tools';
|
|
10
|
+
import InserterSidebar from './components/inserter-sidebar';
|
|
11
|
+
import ListViewSidebar from './components/list-view-sidebar';
|
|
8
12
|
import PostPanelRow from './components/post-panel-row';
|
|
13
|
+
import PostViewLink from './components/post-view-link';
|
|
14
|
+
import PreviewDropdown from './components/preview-dropdown';
|
|
15
|
+
import PluginPostExcerpt from './components/post-excerpt/plugin';
|
|
9
16
|
|
|
10
17
|
export const privateApis = {};
|
|
11
18
|
lock( privateApis, {
|
|
19
|
+
DocumentTools,
|
|
20
|
+
EditorCanvas,
|
|
12
21
|
ExperimentalEditorProvider,
|
|
13
22
|
EntitiesSavedStatesExtensible,
|
|
23
|
+
InserterSidebar,
|
|
24
|
+
ListViewSidebar,
|
|
14
25
|
PostPanelRow,
|
|
26
|
+
PostViewLink,
|
|
27
|
+
PreviewDropdown,
|
|
28
|
+
PluginPostExcerpt,
|
|
15
29
|
|
|
16
30
|
// This is a temporary private API while we're updating the site editor to use EditorProvider.
|
|
17
31
|
useBlockEditorSettings,
|