@wordpress/editor 13.30.0 → 13.32.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 +4 -0
- package/README.md +857 -0
- package/build/bindings/index.js +3 -1
- package/build/bindings/index.js.map +1 -1
- package/build/components/block-settings-menu/plugin-block-settings-menu-item.js +107 -0
- package/build/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -0
- package/build/components/commands/index.js +1 -1
- package/build/components/commands/index.js.map +1 -1
- package/build/components/deprecated.js +158 -0
- package/build/components/deprecated.js.map +1 -1
- package/build/components/document-bar/index.js +7 -10
- package/build/components/document-bar/index.js.map +1 -1
- package/build/components/document-outline/index.js +1 -1
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/editor-canvas/edit-template-blocks-notification.js +2 -39
- package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
- package/build/components/editor-canvas/index.js +3 -0
- package/build/components/editor-canvas/index.js.map +1 -1
- package/build/components/entities-saved-states/hooks/use-is-dirty.js +10 -16
- package/build/components/entities-saved-states/hooks/use-is-dirty.js.map +1 -1
- package/build/components/entities-saved-states/index.js +28 -88
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/error-boundary/index.native.js +133 -0
- package/build/components/error-boundary/index.native.js.map +1 -0
- package/build/components/index.js +33 -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 +5 -1
- package/build/components/inserter-sidebar/index.js.map +1 -1
- package/build/components/list-view-sidebar/index.js +2 -1
- package/build/components/list-view-sidebar/index.js.map +1 -1
- package/build/components/pattern-overrides-panel/index.js +30 -0
- package/build/components/pattern-overrides-panel/index.js.map +1 -0
- package/build/components/plugin-document-setting-panel/index.js +123 -0
- package/build/components/plugin-document-setting-panel/index.js.map +1 -0
- package/build/components/plugin-post-publish-panel/index.js +68 -0
- package/build/components/plugin-post-publish-panel/index.js.map +1 -0
- package/build/components/plugin-pre-publish-panel/index.js +71 -0
- package/build/components/plugin-pre-publish-panel/index.js.map +1 -0
- package/build/components/post-actions/actions.js +455 -0
- package/build/components/post-actions/actions.js.map +1 -0
- package/build/components/post-card-panel/index.js +93 -0
- package/build/components/post-card-panel/index.js.map +1 -0
- package/build/components/post-featured-image/index.js +3 -8
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-featured-image/panel.js +7 -3
- package/build/components/post-featured-image/panel.js.map +1 -1
- package/build/components/post-sync-status/index.js +0 -72
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +7 -3
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-title/index.native.js +1 -1
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/provider/disable-non-page-content-blocks.js +36 -20
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build/components/provider/index.js +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +8 -9
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/provider/use-hide-blocks-from-inserter.js +4 -3
- package/build/components/provider/use-hide-blocks-from-inserter.js.map +1 -1
- package/build/components/template-areas/index.js +70 -0
- package/build/components/template-areas/index.js.map +1 -0
- package/build/hooks/use-select-nearest-editable-block.js +87 -0
- package/build/hooks/use-select-nearest-editable-block.js.map +1 -0
- package/build/private-apis.js +6 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +46 -6
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +3 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/private-actions.js +80 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +56 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +14 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +21 -11
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils/get-filtered-template-parts.js +71 -0
- package/build/store/utils/get-filtered-template-parts.js.map +1 -0
- package/build-module/bindings/index.js +3 -1
- package/build-module/bindings/index.js.map +1 -1
- package/build-module/components/block-settings-menu/plugin-block-settings-menu-item.js +100 -0
- package/build-module/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -0
- package/build-module/components/commands/index.js +1 -1
- package/build-module/components/commands/index.js.map +1 -1
- package/build-module/components/deprecated.js +159 -0
- package/build-module/components/deprecated.js.map +1 -1
- package/build-module/components/document-bar/index.js +8 -11
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/components/document-outline/index.js +1 -1
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js +4 -41
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
- package/build-module/components/editor-canvas/index.js +3 -0
- package/build-module/components/editor-canvas/index.js.map +1 -1
- package/build-module/components/entities-saved-states/hooks/use-is-dirty.js +10 -16
- package/build-module/components/entities-saved-states/hooks/use-is-dirty.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +29 -89
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/error-boundary/index.native.js +125 -0
- package/build-module/components/error-boundary/index.native.js.map +1 -0
- package/build-module/components/index.js +5 -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 +5 -1
- package/build-module/components/inserter-sidebar/index.js.map +1 -1
- package/build-module/components/list-view-sidebar/index.js +2 -1
- package/build-module/components/list-view-sidebar/index.js.map +1 -1
- package/build-module/components/pattern-overrides-panel/index.js +23 -0
- package/build-module/components/pattern-overrides-panel/index.js.map +1 -0
- package/build-module/components/plugin-document-setting-panel/index.js +115 -0
- package/build-module/components/plugin-document-setting-panel/index.js.map +1 -0
- package/build-module/components/plugin-post-publish-panel/index.js +61 -0
- package/build-module/components/plugin-post-publish-panel/index.js.map +1 -0
- package/build-module/components/plugin-pre-publish-panel/index.js +64 -0
- package/build-module/components/plugin-pre-publish-panel/index.js.map +1 -0
- package/build-module/components/post-actions/actions.js +444 -0
- package/build-module/components/post-actions/actions.js.map +1 -0
- package/build-module/components/post-card-panel/index.js +85 -0
- package/build-module/components/post-card-panel/index.js.map +1 -0
- package/build-module/components/post-featured-image/index.js +4 -9
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-featured-image/panel.js +6 -2
- package/build-module/components/post-featured-image/panel.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +2 -73
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +7 -3
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-title/index.native.js +1 -1
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/provider/disable-non-page-content-blocks.js +36 -20
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build-module/components/provider/index.js +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +9 -10
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/provider/use-hide-blocks-from-inserter.js +4 -3
- package/build-module/components/provider/use-hide-blocks-from-inserter.js.map +1 -1
- package/build-module/components/template-areas/index.js +63 -0
- package/build-module/components/template-areas/index.js.map +1 -0
- package/build-module/hooks/use-select-nearest-editable-block.js +80 -0
- package/build-module/hooks/use-select-nearest-editable-block.js.map +1 -0
- package/build-module/private-apis.js +6 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +37 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js +2 -0
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/private-actions.js +78 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +54 -3
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +13 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +19 -10
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils/get-filtered-template-parts.js +64 -0
- package/build-module/store/utils/get-filtered-template-parts.js.map +1 -0
- package/build-style/style-rtl.css +76 -33
- package/build-style/style.css +76 -33
- package/package.json +35 -33
- package/src/bindings/index.js +4 -1
- package/src/components/block-settings-menu/plugin-block-settings-menu-item.js +108 -0
- package/src/components/commands/index.js +1 -1
- package/src/components/deprecated.js +157 -0
- package/src/components/document-bar/index.js +12 -17
- package/src/components/document-bar/style.scss +9 -12
- package/src/components/document-outline/index.js +2 -1
- package/src/components/document-tools/style.scss +4 -11
- package/src/components/editor-canvas/edit-template-blocks-notification.js +6 -56
- package/src/components/editor-canvas/index.js +4 -0
- package/src/components/entities-saved-states/hooks/use-is-dirty.js +18 -22
- package/src/components/entities-saved-states/index.js +45 -121
- package/src/components/entities-saved-states/test/use-is-dirty.js +3 -0
- package/src/components/error-boundary/index.native.js +192 -0
- package/src/components/error-boundary/style.native.scss +116 -0
- package/src/components/index.js +5 -4
- package/src/components/index.native.js +1 -0
- package/src/components/inserter-sidebar/index.js +7 -1
- package/src/components/list-view-sidebar/index.js +1 -0
- package/src/components/list-view-sidebar/style.scss +1 -1
- package/src/components/pattern-overrides-panel/index.js +26 -0
- package/src/components/plugin-document-setting-panel/index.js +121 -0
- package/src/components/plugin-post-publish-panel/index.js +64 -0
- package/src/components/plugin-post-publish-panel/test/__snapshots__/index.js.snap +39 -0
- package/src/components/plugin-post-publish-panel/test/index.js +33 -0
- package/src/components/plugin-pre-publish-panel/index.js +67 -0
- package/src/components/plugin-pre-publish-panel/test/index.js +33 -0
- package/src/components/post-actions/actions.js +582 -0
- package/src/components/post-card-panel/index.js +108 -0
- package/src/components/post-card-panel/style.scss +32 -0
- package/src/components/post-featured-image/index.js +6 -15
- package/src/components/post-featured-image/panel.js +9 -3
- package/src/components/post-featured-image/style.scss +9 -13
- package/src/components/post-sync-status/index.js +1 -94
- package/src/components/post-taxonomies/flat-term-selector.js +13 -8
- package/src/components/post-title/index.native.js +1 -1
- package/src/components/provider/disable-non-page-content-blocks.js +40 -20
- package/src/components/provider/index.js +1 -1
- package/src/components/provider/test/disable-non-page-content-blocks.js +35 -14
- package/src/components/provider/use-block-editor-settings.js +11 -11
- package/src/components/provider/use-hide-blocks-from-inserter.js +5 -3
- package/src/components/template-areas/index.js +85 -0
- package/src/components/template-areas/style.scss +23 -0
- package/src/hooks/use-select-nearest-editable-block.js +95 -0
- package/src/private-apis.js +6 -2
- package/src/store/actions.js +37 -3
- package/src/store/constants.js +2 -0
- package/src/store/private-actions.js +111 -0
- package/src/store/private-selectors.js +105 -17
- package/src/store/reducer.js +13 -0
- package/src/store/selectors.js +50 -40
- package/src/store/utils/get-filtered-template-parts.js +69 -0
- package/src/store/utils/test/get-filtered-template-parts.js +189 -0
- package/src/style.scss +2 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { unlock } from '../lock-unlock';
|
|
12
|
+
|
|
13
|
+
const DISTANCE_THRESHOLD = 500;
|
|
14
|
+
|
|
15
|
+
function clamp( value, min, max ) {
|
|
16
|
+
return Math.min( Math.max( value, min ), max );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function distanceFromRect( x, y, rect ) {
|
|
20
|
+
const dx = x - clamp( x, rect.left, rect.right );
|
|
21
|
+
const dy = y - clamp( y, rect.top, rect.bottom );
|
|
22
|
+
return Math.sqrt( dx * dx + dy * dy );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function useSelectNearestEditableBlock( {
|
|
26
|
+
isEnabled = true,
|
|
27
|
+
} = {} ) {
|
|
28
|
+
const { getEnabledClientIdsTree, getBlockName, getBlockOrder } = unlock(
|
|
29
|
+
useSelect( blockEditorStore )
|
|
30
|
+
);
|
|
31
|
+
const { selectBlock } = useDispatch( blockEditorStore );
|
|
32
|
+
|
|
33
|
+
return useRefEffect(
|
|
34
|
+
( element ) => {
|
|
35
|
+
if ( ! isEnabled ) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const selectNearestEditableBlock = ( x, y ) => {
|
|
40
|
+
const editableBlockClientIds =
|
|
41
|
+
getEnabledClientIdsTree().flatMap( ( { clientId } ) => {
|
|
42
|
+
const blockName = getBlockName( clientId );
|
|
43
|
+
if ( blockName === 'core/template-part' ) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
if ( blockName === 'core/post-content' ) {
|
|
47
|
+
const innerBlocks = getBlockOrder( clientId );
|
|
48
|
+
if ( innerBlocks.length ) {
|
|
49
|
+
return innerBlocks;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [ clientId ];
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
let nearestDistance = Infinity,
|
|
56
|
+
nearestClientId = null;
|
|
57
|
+
|
|
58
|
+
for ( const clientId of editableBlockClientIds ) {
|
|
59
|
+
const block = element.querySelector(
|
|
60
|
+
`[data-block="${ clientId }"]`
|
|
61
|
+
);
|
|
62
|
+
if ( ! block ) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const rect = block.getBoundingClientRect();
|
|
66
|
+
const distance = distanceFromRect( x, y, rect );
|
|
67
|
+
if (
|
|
68
|
+
distance < nearestDistance &&
|
|
69
|
+
distance < DISTANCE_THRESHOLD
|
|
70
|
+
) {
|
|
71
|
+
nearestDistance = distance;
|
|
72
|
+
nearestClientId = clientId;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if ( nearestClientId ) {
|
|
77
|
+
selectBlock( nearestClientId );
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleClick = ( event ) => {
|
|
82
|
+
const shouldSelect =
|
|
83
|
+
event.target === element ||
|
|
84
|
+
event.target.classList.contains( 'is-root-container' );
|
|
85
|
+
if ( shouldSelect ) {
|
|
86
|
+
selectNearestEditableBlock( event.clientX, event.clientY );
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
element.addEventListener( 'click', handleClick );
|
|
91
|
+
return () => element.removeEventListener( 'click', handleClick );
|
|
92
|
+
},
|
|
93
|
+
[ isEnabled ]
|
|
94
|
+
);
|
|
95
|
+
}
|
package/src/private-apis.js
CHANGED
|
@@ -4,34 +4,38 @@
|
|
|
4
4
|
import EditorCanvas from './components/editor-canvas';
|
|
5
5
|
import { ExperimentalEditorProvider } from './components/provider';
|
|
6
6
|
import { lock } from './lock-unlock';
|
|
7
|
-
import EnablePluginDocumentSettingPanelOption from './components/preferences-modal/enable-plugin-document-setting-panel';
|
|
8
7
|
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
|
|
9
8
|
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
|
|
10
9
|
import DocumentTools from './components/document-tools';
|
|
11
10
|
import InserterSidebar from './components/inserter-sidebar';
|
|
12
11
|
import ListViewSidebar from './components/list-view-sidebar';
|
|
13
12
|
import ModeSwitcher from './components/mode-switcher';
|
|
13
|
+
import PatternOverridesPanel from './components/pattern-overrides-panel';
|
|
14
14
|
import PluginPostExcerpt from './components/post-excerpt/plugin';
|
|
15
15
|
import PostPanelRow from './components/post-panel-row';
|
|
16
16
|
import PostViewLink from './components/post-view-link';
|
|
17
17
|
import PreviewDropdown from './components/preview-dropdown';
|
|
18
18
|
import PreferencesModal from './components/preferences-modal';
|
|
19
|
+
import { usePostActions } from './components/post-actions/actions';
|
|
20
|
+
import PostCardPanel from './components/post-card-panel';
|
|
19
21
|
|
|
20
22
|
export const privateApis = {};
|
|
21
23
|
lock( privateApis, {
|
|
22
24
|
DocumentTools,
|
|
23
25
|
EditorCanvas,
|
|
24
26
|
ExperimentalEditorProvider,
|
|
25
|
-
EnablePluginDocumentSettingPanelOption,
|
|
26
27
|
EntitiesSavedStatesExtensible,
|
|
27
28
|
InserterSidebar,
|
|
28
29
|
ListViewSidebar,
|
|
29
30
|
ModeSwitcher,
|
|
31
|
+
PatternOverridesPanel,
|
|
30
32
|
PluginPostExcerpt,
|
|
31
33
|
PostPanelRow,
|
|
32
34
|
PostViewLink,
|
|
33
35
|
PreviewDropdown,
|
|
34
36
|
PreferencesModal,
|
|
37
|
+
usePostActions,
|
|
38
|
+
PostCardPanel,
|
|
35
39
|
|
|
36
40
|
// This is a temporary private API while we're updating the site editor to use EditorProvider.
|
|
37
41
|
useBlockEditorSettings,
|
package/src/store/actions.js
CHANGED
|
@@ -406,7 +406,7 @@ export const enablePublishSidebar =
|
|
|
406
406
|
( { registry } ) => {
|
|
407
407
|
registry
|
|
408
408
|
.dispatch( preferencesStore )
|
|
409
|
-
.set( 'core
|
|
409
|
+
.set( 'core', 'isPublishSidebarEnabled', true );
|
|
410
410
|
};
|
|
411
411
|
|
|
412
412
|
/**
|
|
@@ -417,7 +417,7 @@ export const disablePublishSidebar =
|
|
|
417
417
|
( { registry } ) => {
|
|
418
418
|
registry
|
|
419
419
|
.dispatch( preferencesStore )
|
|
420
|
-
.set( 'core
|
|
420
|
+
.set( 'core', 'isPublishSidebarEnabled', false );
|
|
421
421
|
};
|
|
422
422
|
|
|
423
423
|
/**
|
|
@@ -583,7 +583,6 @@ export function updateEditorSettings( settings ) {
|
|
|
583
583
|
/**
|
|
584
584
|
* Returns an action used to set the rendering mode of the post editor. We support multiple rendering modes:
|
|
585
585
|
*
|
|
586
|
-
* - `all`: This is the default mode. It renders the post editor with all the features available. If a template is provided, it's preferred over the post.
|
|
587
586
|
* - `post-only`: This mode extracts the post blocks from the template and renders only those. The idea is to allow the user to edit the post/page in isolation without the wrapping template.
|
|
588
587
|
* - `template-locked`: This mode renders both the template and the post blocks but the template blocks are locked and can't be edited. The post blocks are editable.
|
|
589
588
|
*
|
|
@@ -820,6 +819,41 @@ export const switchEditorMode =
|
|
|
820
819
|
}
|
|
821
820
|
};
|
|
822
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Returns an action object used in signalling that the user opened the publish
|
|
824
|
+
* sidebar.
|
|
825
|
+
*
|
|
826
|
+
* @return {Object} Action object
|
|
827
|
+
*/
|
|
828
|
+
export function openPublishSidebar() {
|
|
829
|
+
return {
|
|
830
|
+
type: 'OPEN_PUBLISH_SIDEBAR',
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Returns an action object used in signalling that the user closed the
|
|
836
|
+
* publish sidebar.
|
|
837
|
+
*
|
|
838
|
+
* @return {Object} Action object.
|
|
839
|
+
*/
|
|
840
|
+
export function closePublishSidebar() {
|
|
841
|
+
return {
|
|
842
|
+
type: 'CLOSE_PUBLISH_SIDEBAR',
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Returns an action object used in signalling that the user toggles the publish sidebar.
|
|
848
|
+
*
|
|
849
|
+
* @return {Object} Action object
|
|
850
|
+
*/
|
|
851
|
+
export function togglePublishSidebar() {
|
|
852
|
+
return {
|
|
853
|
+
type: 'TOGGLE_PUBLISH_SIDEBAR',
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
823
857
|
/**
|
|
824
858
|
* Backward compatibility
|
|
825
859
|
*/
|
package/src/store/constants.js
CHANGED
|
@@ -18,3 +18,5 @@ export const TRASH_POST_NOTICE_ID = 'TRASH_POST_NOTICE_ID';
|
|
|
18
18
|
export const PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;
|
|
19
19
|
export const ONE_MINUTE_IN_MS = 60 * 1000;
|
|
20
20
|
export const AUTOSAVE_PROPERTIES = [ 'title', 'excerpt', 'content' ];
|
|
21
|
+
export const TEMPLATE_POST_TYPE = 'wp_template';
|
|
22
|
+
export const TEMPLATE_PART_POST_TYPE = 'wp_template_part';
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { store as coreStore } from '@wordpress/core-data';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { store as noticesStore } from '@wordpress/notices';
|
|
7
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
8
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -109,3 +110,113 @@ export const hideBlockTypes =
|
|
|
109
110
|
.dispatch( preferencesStore )
|
|
110
111
|
.set( 'core', 'hiddenBlockTypes', [ ...mergedBlockNames ] );
|
|
111
112
|
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Save entity records marked as dirty.
|
|
116
|
+
*
|
|
117
|
+
* @param {Object} options Options for the action.
|
|
118
|
+
* @param {Function} [options.onSave] Callback when saving happens.
|
|
119
|
+
* @param {object[]} [options.dirtyEntityRecords] Array of dirty entities.
|
|
120
|
+
* @param {object[]} [options.entitiesToSkip] Array of entities to skip saving.
|
|
121
|
+
* @param {Function} [options.close] Callback when the actions is called. It should be consolidated with `onSave`.
|
|
122
|
+
*/
|
|
123
|
+
export const saveDirtyEntities =
|
|
124
|
+
( { onSave, dirtyEntityRecords = [], entitiesToSkip = [], close } = {} ) =>
|
|
125
|
+
( { registry } ) => {
|
|
126
|
+
const PUBLISH_ON_SAVE_ENTITIES = [
|
|
127
|
+
{ kind: 'postType', name: 'wp_navigation' },
|
|
128
|
+
];
|
|
129
|
+
const saveNoticeId = 'site-editor-save-success';
|
|
130
|
+
const homeUrl = registry.select( coreStore ).getUnstableBase()?.home;
|
|
131
|
+
registry.dispatch( noticesStore ).removeNotice( saveNoticeId );
|
|
132
|
+
const entitiesToSave = dirtyEntityRecords.filter(
|
|
133
|
+
( { kind, name, key, property } ) => {
|
|
134
|
+
return ! entitiesToSkip.some(
|
|
135
|
+
( elt ) =>
|
|
136
|
+
elt.kind === kind &&
|
|
137
|
+
elt.name === name &&
|
|
138
|
+
elt.key === key &&
|
|
139
|
+
elt.property === property
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
if ( ! entitiesToSave.length ) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
close?.( entitiesToSave );
|
|
147
|
+
const siteItemsToSave = [];
|
|
148
|
+
const pendingSavedRecords = [];
|
|
149
|
+
entitiesToSave.forEach( ( { kind, name, key, property } ) => {
|
|
150
|
+
if ( 'root' === kind && 'site' === name ) {
|
|
151
|
+
siteItemsToSave.push( property );
|
|
152
|
+
} else {
|
|
153
|
+
if (
|
|
154
|
+
PUBLISH_ON_SAVE_ENTITIES.some(
|
|
155
|
+
( typeToPublish ) =>
|
|
156
|
+
typeToPublish.kind === kind &&
|
|
157
|
+
typeToPublish.name === name
|
|
158
|
+
)
|
|
159
|
+
) {
|
|
160
|
+
registry
|
|
161
|
+
.dispatch( coreStore )
|
|
162
|
+
.editEntityRecord( kind, name, key, {
|
|
163
|
+
status: 'publish',
|
|
164
|
+
} );
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
pendingSavedRecords.push(
|
|
168
|
+
registry
|
|
169
|
+
.dispatch( coreStore )
|
|
170
|
+
.saveEditedEntityRecord( kind, name, key )
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
} );
|
|
174
|
+
if ( siteItemsToSave.length ) {
|
|
175
|
+
pendingSavedRecords.push(
|
|
176
|
+
registry
|
|
177
|
+
.dispatch( coreStore )
|
|
178
|
+
.__experimentalSaveSpecifiedEntityEdits(
|
|
179
|
+
'root',
|
|
180
|
+
'site',
|
|
181
|
+
undefined,
|
|
182
|
+
siteItemsToSave
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
registry
|
|
187
|
+
.dispatch( blockEditorStore )
|
|
188
|
+
.__unstableMarkLastChangeAsPersistent();
|
|
189
|
+
Promise.all( pendingSavedRecords )
|
|
190
|
+
.then( ( values ) => {
|
|
191
|
+
return onSave ? onSave( values ) : values;
|
|
192
|
+
} )
|
|
193
|
+
.then( ( values ) => {
|
|
194
|
+
if (
|
|
195
|
+
values.some( ( value ) => typeof value === 'undefined' )
|
|
196
|
+
) {
|
|
197
|
+
registry
|
|
198
|
+
.dispatch( noticesStore )
|
|
199
|
+
.createErrorNotice( __( 'Saving failed.' ) );
|
|
200
|
+
} else {
|
|
201
|
+
registry
|
|
202
|
+
.dispatch( noticesStore )
|
|
203
|
+
.createSuccessNotice( __( 'Site updated.' ), {
|
|
204
|
+
type: 'snackbar',
|
|
205
|
+
id: saveNoticeId,
|
|
206
|
+
actions: [
|
|
207
|
+
{
|
|
208
|
+
label: __( 'View site' ),
|
|
209
|
+
url: homeUrl,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
} );
|
|
213
|
+
}
|
|
214
|
+
} )
|
|
215
|
+
.catch( ( error ) =>
|
|
216
|
+
registry
|
|
217
|
+
.dispatch( noticesStore )
|
|
218
|
+
.createErrorNotice(
|
|
219
|
+
`${ __( 'Saving failed.' ) } ${ error }`
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
};
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import createSelector from 'rememo';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
4
9
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
10
|
import { createRegistrySelector } from '@wordpress/data';
|
|
11
|
+
import {
|
|
12
|
+
layout,
|
|
13
|
+
symbol,
|
|
14
|
+
navigation,
|
|
15
|
+
page as pageIcon,
|
|
16
|
+
verse,
|
|
17
|
+
} from '@wordpress/icons';
|
|
18
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
19
|
|
|
7
20
|
/**
|
|
8
21
|
* Internal dependencies
|
|
9
22
|
*/
|
|
10
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getRenderingMode,
|
|
25
|
+
__experimentalGetDefaultTemplatePartAreas,
|
|
26
|
+
} from './selectors';
|
|
27
|
+
import { TEMPLATE_PART_POST_TYPE } from './constants';
|
|
28
|
+
import { getFilteredTemplatePartBlocks } from './utils/get-filtered-template-parts';
|
|
11
29
|
|
|
12
30
|
const EMPTY_INSERTION_POINT = {
|
|
13
31
|
rootClientId: undefined,
|
|
@@ -22,30 +40,100 @@ const EMPTY_INSERTION_POINT = {
|
|
|
22
40
|
*
|
|
23
41
|
* @return {Object} The root client ID, index to insert at and starting filter value.
|
|
24
42
|
*/
|
|
25
|
-
export const getInsertionPoint = createRegistrySelector(
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
export const getInsertionPoint = createRegistrySelector( ( select ) =>
|
|
44
|
+
createSelector(
|
|
45
|
+
( state ) => {
|
|
46
|
+
if ( typeof state.blockInserterPanel === 'object' ) {
|
|
47
|
+
return state.blockInserterPanel;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ( getRenderingMode( state ) === 'template-locked' ) {
|
|
51
|
+
const [ postContentClientId ] =
|
|
52
|
+
select( blockEditorStore ).getBlocksByName(
|
|
53
|
+
'core/post-content'
|
|
54
|
+
);
|
|
55
|
+
if ( postContentClientId ) {
|
|
56
|
+
return {
|
|
57
|
+
rootClientId: postContentClientId,
|
|
58
|
+
insertionIndex: undefined,
|
|
59
|
+
filterValue: undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
30
63
|
|
|
31
|
-
|
|
64
|
+
return EMPTY_INSERTION_POINT;
|
|
65
|
+
},
|
|
66
|
+
( state ) => {
|
|
32
67
|
const [ postContentClientId ] =
|
|
33
68
|
select( blockEditorStore ).getBlocksByName(
|
|
34
69
|
'core/post-content'
|
|
35
70
|
);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
}
|
|
71
|
+
return [
|
|
72
|
+
state.blockInserterPanel,
|
|
73
|
+
getRenderingMode( state ),
|
|
74
|
+
postContentClientId,
|
|
75
|
+
];
|
|
43
76
|
}
|
|
44
|
-
|
|
45
|
-
return EMPTY_INSERTION_POINT;
|
|
46
|
-
}
|
|
77
|
+
)
|
|
47
78
|
);
|
|
48
79
|
|
|
49
80
|
export function getListViewToggleRef( state ) {
|
|
50
81
|
return state.listViewToggleRef;
|
|
51
82
|
}
|
|
83
|
+
const CARD_ICONS = {
|
|
84
|
+
wp_block: symbol,
|
|
85
|
+
wp_navigation: navigation,
|
|
86
|
+
page: pageIcon,
|
|
87
|
+
post: verse,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const getPostIcon = createRegistrySelector(
|
|
91
|
+
( select ) => ( state, postType, options ) => {
|
|
92
|
+
{
|
|
93
|
+
if (
|
|
94
|
+
postType === 'wp_template_part' ||
|
|
95
|
+
postType === 'wp_template'
|
|
96
|
+
) {
|
|
97
|
+
return (
|
|
98
|
+
__experimentalGetDefaultTemplatePartAreas( state ).find(
|
|
99
|
+
( item ) => options.area === item.area
|
|
100
|
+
)?.icon || layout
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if ( CARD_ICONS[ postType ] ) {
|
|
104
|
+
return CARD_ICONS[ postType ];
|
|
105
|
+
}
|
|
106
|
+
const postTypeEntity = select( coreStore ).getPostType( postType );
|
|
107
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
108
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
109
|
+
// also supports urls and svg as values.
|
|
110
|
+
if ( postTypeEntity?.icon?.startsWith( 'dashicons-' ) ) {
|
|
111
|
+
return postTypeEntity.icon.slice( 10 );
|
|
112
|
+
}
|
|
113
|
+
return pageIcon;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns the template parts and their blocks for the current edited template.
|
|
120
|
+
*
|
|
121
|
+
* @param {Object} state Global application state.
|
|
122
|
+
* @return {Array} Template parts and their blocks in an array.
|
|
123
|
+
*/
|
|
124
|
+
export const getCurrentTemplateTemplateParts = createRegistrySelector(
|
|
125
|
+
( select ) => () => {
|
|
126
|
+
const templateParts = select( coreStore ).getEntityRecords(
|
|
127
|
+
'postType',
|
|
128
|
+
TEMPLATE_PART_POST_TYPE,
|
|
129
|
+
{ per_page: -1 }
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const clientIds =
|
|
133
|
+
select( blockEditorStore ).getBlocksByName( 'core/template-part' );
|
|
134
|
+
const blocks =
|
|
135
|
+
select( blockEditorStore ).getBlocksByClientId( clientIds );
|
|
136
|
+
|
|
137
|
+
return getFilteredTemplatePartBlocks( blocks, templateParts );
|
|
138
|
+
}
|
|
139
|
+
);
|
package/src/store/reducer.js
CHANGED
|
@@ -360,6 +360,18 @@ export function listViewToggleRef( state = { current: null } ) {
|
|
|
360
360
|
return state;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
export function publishSidebarActive( state = false, action ) {
|
|
364
|
+
switch ( action.type ) {
|
|
365
|
+
case 'OPEN_PUBLISH_SIDEBAR':
|
|
366
|
+
return true;
|
|
367
|
+
case 'CLOSE_PUBLISH_SIDEBAR':
|
|
368
|
+
return false;
|
|
369
|
+
case 'TOGGLE_PUBLISH_SIDEBAR':
|
|
370
|
+
return ! state;
|
|
371
|
+
}
|
|
372
|
+
return state;
|
|
373
|
+
}
|
|
374
|
+
|
|
363
375
|
export default combineReducers( {
|
|
364
376
|
postId,
|
|
365
377
|
postType,
|
|
@@ -377,4 +389,5 @@ export default combineReducers( {
|
|
|
377
389
|
blockInserterPanel,
|
|
378
390
|
listViewPanel,
|
|
379
391
|
listViewToggleRef,
|
|
392
|
+
publishSidebarActive,
|
|
380
393
|
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -105,16 +105,11 @@ export const isEditedPostDirty = createRegistrySelector(
|
|
|
105
105
|
// inferred to contain unsaved values.
|
|
106
106
|
const postType = getCurrentPostType( state );
|
|
107
107
|
const postId = getCurrentPostId( state );
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
108
|
+
return select( coreStore ).hasEditsForEntityRecord(
|
|
109
|
+
'postType',
|
|
110
|
+
postType,
|
|
111
|
+
postId
|
|
112
|
+
);
|
|
118
113
|
}
|
|
119
114
|
);
|
|
120
115
|
|
|
@@ -1112,10 +1107,7 @@ export function canUserUseUnfilteredHTML( state ) {
|
|
|
1112
1107
|
*/
|
|
1113
1108
|
export const isPublishSidebarEnabled = createRegistrySelector(
|
|
1114
1109
|
( select ) => () =>
|
|
1115
|
-
!! select( preferencesStore ).get(
|
|
1116
|
-
'core/edit-post',
|
|
1117
|
-
'isPublishSidebarEnabled'
|
|
1118
|
-
)
|
|
1110
|
+
!! select( preferencesStore ).get( 'core', 'isPublishSidebarEnabled' )
|
|
1119
1111
|
);
|
|
1120
1112
|
|
|
1121
1113
|
/**
|
|
@@ -1706,8 +1698,8 @@ export function __experimentalGetDefaultTemplateTypes( state ) {
|
|
|
1706
1698
|
export const __experimentalGetDefaultTemplatePartAreas = createSelector(
|
|
1707
1699
|
( state ) => {
|
|
1708
1700
|
const areas =
|
|
1709
|
-
getEditorSettings( state )?.defaultTemplatePartAreas
|
|
1710
|
-
return areas
|
|
1701
|
+
getEditorSettings( state )?.defaultTemplatePartAreas ?? [];
|
|
1702
|
+
return areas.map( ( item ) => {
|
|
1711
1703
|
return { ...item, icon: getTemplatePartIcon( item.icon ) };
|
|
1712
1704
|
} );
|
|
1713
1705
|
},
|
|
@@ -1735,7 +1727,7 @@ export const __experimentalGetDefaultTemplateType = createSelector(
|
|
|
1735
1727
|
) ?? EMPTY_OBJECT
|
|
1736
1728
|
);
|
|
1737
1729
|
},
|
|
1738
|
-
( state
|
|
1730
|
+
( state ) => [ __experimentalGetDefaultTemplateTypes( state ) ]
|
|
1739
1731
|
);
|
|
1740
1732
|
|
|
1741
1733
|
/**
|
|
@@ -1746,32 +1738,39 @@ export const __experimentalGetDefaultTemplateType = createSelector(
|
|
|
1746
1738
|
* @param {Object} template The template for which we need information.
|
|
1747
1739
|
* @return {Object} Information about the template, including title, description, and icon.
|
|
1748
1740
|
*/
|
|
1749
|
-
export
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1741
|
+
export const __experimentalGetTemplateInfo = createSelector(
|
|
1742
|
+
( state, template ) => {
|
|
1743
|
+
if ( ! template ) {
|
|
1744
|
+
return EMPTY_OBJECT;
|
|
1745
|
+
}
|
|
1753
1746
|
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1747
|
+
const { description, slug, title, area } = template;
|
|
1748
|
+
const { title: defaultTitle, description: defaultDescription } =
|
|
1749
|
+
__experimentalGetDefaultTemplateType( state, slug );
|
|
1757
1750
|
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
(
|
|
1764
|
-
|
|
1751
|
+
const templateTitle =
|
|
1752
|
+
typeof title === 'string' ? title : title?.rendered;
|
|
1753
|
+
const templateDescription =
|
|
1754
|
+
typeof description === 'string' ? description : description?.raw;
|
|
1755
|
+
const templateIcon =
|
|
1756
|
+
__experimentalGetDefaultTemplatePartAreas( state ).find(
|
|
1757
|
+
( item ) => area === item.area
|
|
1758
|
+
)?.icon || layout;
|
|
1765
1759
|
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
}
|
|
1760
|
+
return {
|
|
1761
|
+
title:
|
|
1762
|
+
templateTitle && templateTitle !== slug
|
|
1763
|
+
? templateTitle
|
|
1764
|
+
: defaultTitle || slug,
|
|
1765
|
+
description: templateDescription || defaultDescription,
|
|
1766
|
+
icon: templateIcon,
|
|
1767
|
+
};
|
|
1768
|
+
},
|
|
1769
|
+
( state ) => [
|
|
1770
|
+
__experimentalGetDefaultTemplateTypes( state ),
|
|
1771
|
+
__experimentalGetDefaultTemplatePartAreas( state ),
|
|
1772
|
+
]
|
|
1773
|
+
);
|
|
1775
1774
|
|
|
1776
1775
|
/**
|
|
1777
1776
|
* Returns a post type label depending on the current post.
|
|
@@ -1789,3 +1788,14 @@ export const getPostTypeLabel = createRegistrySelector(
|
|
|
1789
1788
|
return postType?.labels?.singular_name;
|
|
1790
1789
|
}
|
|
1791
1790
|
);
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Returns true if the publish sidebar is opened.
|
|
1794
|
+
*
|
|
1795
|
+
* @param {Object} state Global application state
|
|
1796
|
+
*
|
|
1797
|
+
* @return {boolean} Whether the publish sidebar is open.
|
|
1798
|
+
*/
|
|
1799
|
+
export function isPublishSidebarOpened( state ) {
|
|
1800
|
+
return state.publishSidebarActive;
|
|
1801
|
+
}
|