@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo, useState, useCallback } from '@wordpress/element';
|
|
5
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
6
|
+
import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
|
|
7
|
+
import { MenuItem, Modal } from '@wordpress/components';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
9
|
+
import { useDispatch } from '@wordpress/data';
|
|
10
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
11
|
+
import { parse } from '@wordpress/blocks';
|
|
12
|
+
import { useAsyncList } from '@wordpress/compose';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { useAvailableTemplates, useEditedPostContext } from './hooks';
|
|
18
|
+
|
|
19
|
+
export default function SwapTemplateButton( { onClick } ) {
|
|
20
|
+
const [ showModal, setShowModal ] = useState( false );
|
|
21
|
+
const onClose = useCallback( () => {
|
|
22
|
+
setShowModal( false );
|
|
23
|
+
}, [] );
|
|
24
|
+
const { postType, postId } = useEditedPostContext();
|
|
25
|
+
const availableTemplates = useAvailableTemplates( postType );
|
|
26
|
+
const { editEntityRecord } = useDispatch( coreStore );
|
|
27
|
+
if ( ! availableTemplates?.length ) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const onTemplateSelect = async ( template ) => {
|
|
31
|
+
editEntityRecord(
|
|
32
|
+
'postType',
|
|
33
|
+
postType,
|
|
34
|
+
postId,
|
|
35
|
+
{ template: template.name },
|
|
36
|
+
{ undoIgnore: true }
|
|
37
|
+
);
|
|
38
|
+
onClose(); // Close the template suggestions modal first.
|
|
39
|
+
onClick();
|
|
40
|
+
};
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<MenuItem onClick={ () => setShowModal( true ) }>
|
|
44
|
+
{ __( 'Swap template' ) }
|
|
45
|
+
</MenuItem>
|
|
46
|
+
{ showModal && (
|
|
47
|
+
<Modal
|
|
48
|
+
title={ __( 'Choose a template' ) }
|
|
49
|
+
onRequestClose={ onClose }
|
|
50
|
+
overlayClassName="editor-post-template__swap-template-modal"
|
|
51
|
+
isFullScreen
|
|
52
|
+
>
|
|
53
|
+
<div className="editor-post-template__swap-template-modal-content">
|
|
54
|
+
<TemplatesList
|
|
55
|
+
postType={ postType }
|
|
56
|
+
onSelect={ onTemplateSelect }
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</Modal>
|
|
60
|
+
) }
|
|
61
|
+
</>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function TemplatesList( { postType, onSelect } ) {
|
|
66
|
+
const availableTemplates = useAvailableTemplates( postType );
|
|
67
|
+
const templatesAsPatterns = useMemo(
|
|
68
|
+
() =>
|
|
69
|
+
availableTemplates.map( ( template ) => ( {
|
|
70
|
+
name: template.slug,
|
|
71
|
+
blocks: parse( template.content.raw ),
|
|
72
|
+
title: decodeEntities( template.title.rendered ),
|
|
73
|
+
id: template.id,
|
|
74
|
+
} ) ),
|
|
75
|
+
[ availableTemplates ]
|
|
76
|
+
);
|
|
77
|
+
const shownTemplates = useAsyncList( templatesAsPatterns );
|
|
78
|
+
return (
|
|
79
|
+
<BlockPatternsList
|
|
80
|
+
label={ __( 'Templates' ) }
|
|
81
|
+
blockPatterns={ templatesAsPatterns }
|
|
82
|
+
shownPatterns={ shownTemplates }
|
|
83
|
+
onClickPattern={ onSelect }
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -7,7 +7,7 @@ import { View } from 'react-native';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { Component } from '@wordpress/element';
|
|
10
|
-
import { create, insert } from '@wordpress/rich-text';
|
|
10
|
+
import { create, toHTMLString, insert } from '@wordpress/rich-text';
|
|
11
11
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
12
12
|
import { withDispatch, withSelect } from '@wordpress/data';
|
|
13
13
|
import { withFocusOutside } from '@wordpress/components';
|
|
@@ -16,6 +16,7 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
16
16
|
import { pasteHandler } from '@wordpress/blocks';
|
|
17
17
|
import { store as blockEditorStore, RichText } from '@wordpress/block-editor';
|
|
18
18
|
import { store as editorStore } from '@wordpress/editor';
|
|
19
|
+
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Internal dependencies
|
|
@@ -57,7 +58,7 @@ class PostTitle extends Component {
|
|
|
57
58
|
this.props.onSelect();
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
onPaste( { value,
|
|
61
|
+
onPaste( { value, plainText, html } ) {
|
|
61
62
|
const { title, onInsertBlockAfter, onUpdate } = this.props;
|
|
62
63
|
|
|
63
64
|
const content = pasteHandler( {
|
|
@@ -65,23 +66,37 @@ class PostTitle extends Component {
|
|
|
65
66
|
plainText,
|
|
66
67
|
} );
|
|
67
68
|
|
|
68
|
-
if ( content.length ) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if ( ! content.length ) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if ( typeof content !== 'string' ) {
|
|
74
|
+
const [ firstBlock ] = content;
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
! title &&
|
|
78
|
+
( firstBlock.name === 'core/heading' ||
|
|
79
|
+
firstBlock.name === 'core/paragraph' )
|
|
80
|
+
) {
|
|
81
|
+
// Strip HTML to avoid unwanted HTML being added to the title.
|
|
82
|
+
// In the majority of cases it is assumed that HTML in the title
|
|
83
|
+
// is undesirable.
|
|
84
|
+
const contentNoHTML = stripHTML(
|
|
85
|
+
firstBlock.attributes.content
|
|
86
|
+
);
|
|
87
|
+
onUpdate( contentNoHTML );
|
|
88
|
+
onInsertBlockAfter( content.slice( 1 ) );
|
|
72
89
|
} else {
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
! title &&
|
|
76
|
-
( firstBlock.name === 'core/heading' ||
|
|
77
|
-
firstBlock.name === 'core/paragraph' )
|
|
78
|
-
) {
|
|
79
|
-
onUpdate( firstBlock.attributes.content );
|
|
80
|
-
onInsertBlockAfter( content.slice( 1 ) );
|
|
81
|
-
} else {
|
|
82
|
-
onInsertBlockAfter( content );
|
|
83
|
-
}
|
|
90
|
+
onInsertBlockAfter( content );
|
|
84
91
|
}
|
|
92
|
+
} else {
|
|
93
|
+
// Strip HTML to avoid unwanted HTML being added to the title.
|
|
94
|
+
// In the majority of cases it is assumed that HTML in the title
|
|
95
|
+
// is undesirable.
|
|
96
|
+
const contentNoHTML = stripHTML( content );
|
|
97
|
+
|
|
98
|
+
const newValue = insert( value, create( { html: contentNoHTML } ) );
|
|
99
|
+
onUpdate( toHTMLString( { value: newValue } ) );
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
102
|
|
|
@@ -155,7 +170,6 @@ class PostTitle extends Component {
|
|
|
155
170
|
tagsToEliminate={ [ 'strong' ] }
|
|
156
171
|
unstableOnFocus={ this.props.onSelect }
|
|
157
172
|
onBlur={ this.props.onBlur } // Always assign onBlur as a props.
|
|
158
|
-
multiline={ false }
|
|
159
173
|
style={ titleStyles }
|
|
160
174
|
styles={ styles }
|
|
161
175
|
fontSize={ 24 }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`PostTitle does not update title with existing content when pasting HTML 1`] = `
|
|
4
|
+
"<!-- wp:heading -->
|
|
5
|
+
<h2 class="wp-block-heading">Howdy</h2>
|
|
6
|
+
<!-- /wp:heading -->
|
|
7
|
+
|
|
8
|
+
<!-- wp:heading -->
|
|
9
|
+
<h2 class="wp-block-heading">This is a heading.</h2>
|
|
10
|
+
<!-- /wp:heading -->
|
|
11
|
+
|
|
12
|
+
<!-- wp:paragraph -->
|
|
13
|
+
<p>This is a paragraph.</p>
|
|
14
|
+
<!-- /wp:paragraph -->"
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`PostTitle populates empty title with first block content when pasting HTML 1`] = `
|
|
18
|
+
"<!-- wp:heading -->
|
|
19
|
+
<h2 class="wp-block-heading">This is a heading.</h2>
|
|
20
|
+
<!-- /wp:heading -->
|
|
21
|
+
|
|
22
|
+
<!-- wp:paragraph -->
|
|
23
|
+
<p>This is a paragraph.</p>
|
|
24
|
+
<!-- /wp:paragraph -->"
|
|
25
|
+
`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
getEditorHtml,
|
|
6
|
+
getEditorTitle,
|
|
7
|
+
initializeEditor,
|
|
8
|
+
pasteIntoRichText,
|
|
9
|
+
selectRangeInRichText,
|
|
10
|
+
screen,
|
|
11
|
+
setupCoreBlocks,
|
|
12
|
+
within,
|
|
13
|
+
} from 'test/helpers';
|
|
14
|
+
|
|
15
|
+
setupCoreBlocks();
|
|
16
|
+
|
|
17
|
+
const HTML_MULTIPLE_TAGS = `<h2>Howdy</h2>
|
|
18
|
+
<h2>This is a heading.</h2>
|
|
19
|
+
<p>This is a paragraph.</p>`;
|
|
20
|
+
|
|
21
|
+
describe( 'PostTitle', () => {
|
|
22
|
+
it( 'populates empty title with first block content when pasting HTML', async () => {
|
|
23
|
+
await initializeEditor( { initialTitle: '' } );
|
|
24
|
+
|
|
25
|
+
const postTitle = within(
|
|
26
|
+
screen.getByTestId( 'post-title' )
|
|
27
|
+
).getByPlaceholderText( 'Add title' );
|
|
28
|
+
pasteIntoRichText( postTitle, { html: HTML_MULTIPLE_TAGS } );
|
|
29
|
+
|
|
30
|
+
expect( console ).toHaveLogged();
|
|
31
|
+
expect( getEditorTitle() ).toBe( 'Howdy' );
|
|
32
|
+
expect( getEditorHtml() ).toMatchSnapshot();
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
it( 'does not update title with existing content when pasting HTML', async () => {
|
|
36
|
+
const initialTitle = 'Hello';
|
|
37
|
+
await initializeEditor( { initialTitle } );
|
|
38
|
+
|
|
39
|
+
const postTitle = within(
|
|
40
|
+
screen.getByTestId( 'post-title' )
|
|
41
|
+
).getByPlaceholderText( 'Add title' );
|
|
42
|
+
selectRangeInRichText( postTitle, 0 );
|
|
43
|
+
pasteIntoRichText( postTitle, { html: HTML_MULTIPLE_TAGS } );
|
|
44
|
+
|
|
45
|
+
expect( console ).toHaveLogged();
|
|
46
|
+
expect( getEditorTitle() ).toBe( initialTitle );
|
|
47
|
+
expect( getEditorHtml() ).toMatchSnapshot();
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
it( 'updates title with existing content when pasting text', async () => {
|
|
51
|
+
await initializeEditor( { initialTitle: 'World' } );
|
|
52
|
+
|
|
53
|
+
const postTitle = within(
|
|
54
|
+
screen.getByTestId( 'post-title' )
|
|
55
|
+
).getByPlaceholderText( 'Add title' );
|
|
56
|
+
selectRangeInRichText( postTitle, 0 );
|
|
57
|
+
pasteIntoRichText( postTitle, { text: 'Hello' } );
|
|
58
|
+
|
|
59
|
+
expect( console ).toHaveLogged();
|
|
60
|
+
expect( getEditorTitle() ).toBe( 'HelloWorld' );
|
|
61
|
+
expect( getEditorHtml() ).toBe( '' );
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
it( 'does not add HTML to title when pasting span tag', async () => {
|
|
65
|
+
const pasteHTML = `<span style="border: 1px solid black">l</span>`;
|
|
66
|
+
await initializeEditor( { initialTitle: 'Helo' } );
|
|
67
|
+
|
|
68
|
+
const postTitle = within(
|
|
69
|
+
screen.getByTestId( 'post-title' )
|
|
70
|
+
).getByPlaceholderText( 'Add title' );
|
|
71
|
+
selectRangeInRichText( postTitle, 2 );
|
|
72
|
+
pasteIntoRichText( postTitle, { html: pasteHTML } );
|
|
73
|
+
|
|
74
|
+
expect( console ).toHaveLogged();
|
|
75
|
+
expect( getEditorTitle() ).toBe( 'Hello' );
|
|
76
|
+
expect( getEditorHtml() ).toBe( '' );
|
|
77
|
+
} );
|
|
78
|
+
} );
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { Button } from '@wordpress/components';
|
|
6
|
+
import { external } from '@wordpress/icons';
|
|
7
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
|
+
import { useSelect } from '@wordpress/data';
|
|
9
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { store as editorStore } from '../../store';
|
|
15
|
+
|
|
16
|
+
export default function PostViewLink() {
|
|
17
|
+
const { hasLoaded, permalink, isPublished, label, showIconLabels } =
|
|
18
|
+
useSelect( ( select ) => {
|
|
19
|
+
// Grab post type to retrieve the view_item label.
|
|
20
|
+
const postTypeSlug = select( editorStore ).getCurrentPostType();
|
|
21
|
+
const postType = select( coreStore ).getPostType( postTypeSlug );
|
|
22
|
+
const { get } = select( preferencesStore );
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
permalink: select( editorStore ).getPermalink(),
|
|
26
|
+
isPublished: select( editorStore ).isCurrentPostPublished(),
|
|
27
|
+
label: postType?.labels.view_item,
|
|
28
|
+
hasLoaded: !! postType,
|
|
29
|
+
showIconLabels: get( 'core', 'showIconLabels' ),
|
|
30
|
+
};
|
|
31
|
+
}, [] );
|
|
32
|
+
|
|
33
|
+
// Only render the view button if the post is published and has a permalink.
|
|
34
|
+
if ( ! isPublished || ! permalink || ! hasLoaded ) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Button
|
|
40
|
+
icon={ external }
|
|
41
|
+
label={ label || __( 'View post' ) }
|
|
42
|
+
href={ permalink }
|
|
43
|
+
target="_blank"
|
|
44
|
+
showTooltip={ ! showIconLabels }
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { withSelect } from '@wordpress/data';
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
9
8
|
*/
|
|
10
9
|
import { store as editorStore } from '../../store';
|
|
11
10
|
|
|
12
|
-
export function PostVisibilityCheck( {
|
|
13
|
-
const canEdit =
|
|
11
|
+
export default function PostVisibilityCheck( { render } ) {
|
|
12
|
+
const canEdit = useSelect( ( select ) => {
|
|
13
|
+
return (
|
|
14
|
+
select( editorStore ).getCurrentPost()._links?.[
|
|
15
|
+
'wp:action-publish'
|
|
16
|
+
] ?? false
|
|
17
|
+
);
|
|
18
|
+
} );
|
|
19
|
+
|
|
14
20
|
return render( { canEdit } );
|
|
15
21
|
}
|
|
16
|
-
|
|
17
|
-
export default compose( [
|
|
18
|
-
withSelect( ( select ) => {
|
|
19
|
-
const { getCurrentPost, getCurrentPostType } = select( editorStore );
|
|
20
|
-
return {
|
|
21
|
-
hasPublishAction:
|
|
22
|
-
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
|
|
23
|
-
postType: getCurrentPostType(),
|
|
24
|
-
};
|
|
25
|
-
} ),
|
|
26
|
-
] )( PostVisibilityCheck );
|
|
@@ -3,32 +3,43 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
|
|
11
|
+
jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
14
|
* Internal dependencies
|
|
8
15
|
*/
|
|
9
|
-
import
|
|
16
|
+
import PostVisibilityCheck from '../check';
|
|
17
|
+
|
|
18
|
+
function setupMockSelect( hasPublishAction ) {
|
|
19
|
+
useSelect.mockImplementation( ( mapSelect ) => {
|
|
20
|
+
return mapSelect( () => ( {
|
|
21
|
+
getCurrentPost: () => ( {
|
|
22
|
+
_links: {
|
|
23
|
+
'wp:action-publish': hasPublishAction,
|
|
24
|
+
},
|
|
25
|
+
} ),
|
|
26
|
+
} ) );
|
|
27
|
+
} );
|
|
28
|
+
}
|
|
10
29
|
|
|
11
30
|
describe( 'PostVisibilityCheck', () => {
|
|
12
31
|
const renderProp = ( { canEdit } ) => ( canEdit ? 'yes' : 'no' );
|
|
13
32
|
|
|
14
33
|
it( "should not render the edit link if the user doesn't have the right capability", () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
hasPublishAction={ false }
|
|
18
|
-
render={ renderProp }
|
|
19
|
-
/>
|
|
20
|
-
);
|
|
34
|
+
setupMockSelect( false );
|
|
35
|
+
render( <PostVisibilityCheck render={ renderProp } /> );
|
|
21
36
|
expect( screen.queryByText( 'yes' ) ).not.toBeInTheDocument();
|
|
22
37
|
expect( screen.getByText( 'no' ) ).toBeVisible();
|
|
23
38
|
} );
|
|
24
39
|
|
|
25
40
|
it( 'should render if the user has the correct capability', () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
hasPublishAction={ true }
|
|
29
|
-
render={ renderProp }
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
41
|
+
setupMockSelect( true );
|
|
42
|
+
render( <PostVisibilityCheck render={ renderProp } /> );
|
|
32
43
|
expect( screen.queryByText( 'no' ) ).not.toBeInTheDocument();
|
|
33
44
|
expect( screen.getByText( 'yes' ) ).toBeVisible();
|
|
34
45
|
} );
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
5
|
+
import {
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
MenuGroup,
|
|
8
|
+
MenuItem,
|
|
9
|
+
VisuallyHidden,
|
|
10
|
+
Icon,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { check, desktop, mobile, tablet, external } from '@wordpress/icons';
|
|
14
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
15
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
16
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { store as editorStore } from '../../store';
|
|
22
|
+
import PostPreviewButton from '../post-preview-button';
|
|
23
|
+
|
|
24
|
+
export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
|
|
25
|
+
const { deviceType, homeUrl, isTemplate, isViewable, showIconLabels } =
|
|
26
|
+
useSelect( ( select ) => {
|
|
27
|
+
const { getDeviceType, getCurrentPostType } = select( editorStore );
|
|
28
|
+
const { getUnstableBase, getPostType } = select( coreStore );
|
|
29
|
+
const { get } = select( preferencesStore );
|
|
30
|
+
const _currentPostType = getCurrentPostType();
|
|
31
|
+
return {
|
|
32
|
+
deviceType: getDeviceType(),
|
|
33
|
+
homeUrl: getUnstableBase()?.home,
|
|
34
|
+
isTemplate: _currentPostType === 'wp_template',
|
|
35
|
+
isViewable: getPostType( _currentPostType )?.viewable ?? false,
|
|
36
|
+
showIconLabels: get( 'core', 'showIconLabels' ),
|
|
37
|
+
};
|
|
38
|
+
}, [] );
|
|
39
|
+
const { setDeviceType } = useDispatch( editorStore );
|
|
40
|
+
const isMobile = useViewportMatch( 'medium', '<' );
|
|
41
|
+
if ( isMobile ) return null;
|
|
42
|
+
|
|
43
|
+
const popoverProps = {
|
|
44
|
+
placement: 'bottom-end',
|
|
45
|
+
};
|
|
46
|
+
const toggleProps = {
|
|
47
|
+
className: 'editor-preview-dropdown__toggle',
|
|
48
|
+
size: 'compact',
|
|
49
|
+
showTooltip: ! showIconLabels,
|
|
50
|
+
disabled,
|
|
51
|
+
__experimentalIsFocusable: disabled,
|
|
52
|
+
};
|
|
53
|
+
const menuProps = {
|
|
54
|
+
'aria-label': __( 'View options' ),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const deviceIcons = {
|
|
58
|
+
mobile,
|
|
59
|
+
tablet,
|
|
60
|
+
desktop,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<DropdownMenu
|
|
65
|
+
className="editor-preview-dropdown"
|
|
66
|
+
popoverProps={ popoverProps }
|
|
67
|
+
toggleProps={ toggleProps }
|
|
68
|
+
menuProps={ menuProps }
|
|
69
|
+
icon={ deviceIcons[ deviceType.toLowerCase() ] }
|
|
70
|
+
label={ __( 'View' ) }
|
|
71
|
+
disableOpenOnArrowDown={ disabled }
|
|
72
|
+
>
|
|
73
|
+
{ ( { onClose } ) => (
|
|
74
|
+
<>
|
|
75
|
+
<MenuGroup>
|
|
76
|
+
<MenuItem
|
|
77
|
+
onClick={ () => setDeviceType( 'Desktop' ) }
|
|
78
|
+
icon={ deviceType === 'Desktop' && check }
|
|
79
|
+
>
|
|
80
|
+
{ __( 'Desktop' ) }
|
|
81
|
+
</MenuItem>
|
|
82
|
+
<MenuItem
|
|
83
|
+
onClick={ () => setDeviceType( 'Tablet' ) }
|
|
84
|
+
icon={ deviceType === 'Tablet' && check }
|
|
85
|
+
>
|
|
86
|
+
{ __( 'Tablet' ) }
|
|
87
|
+
</MenuItem>
|
|
88
|
+
<MenuItem
|
|
89
|
+
onClick={ () => setDeviceType( 'Mobile' ) }
|
|
90
|
+
icon={ deviceType === 'Mobile' && check }
|
|
91
|
+
>
|
|
92
|
+
{ __( 'Mobile' ) }
|
|
93
|
+
</MenuItem>
|
|
94
|
+
</MenuGroup>
|
|
95
|
+
{ isTemplate && (
|
|
96
|
+
<MenuGroup>
|
|
97
|
+
<MenuItem
|
|
98
|
+
href={ homeUrl }
|
|
99
|
+
target="_blank"
|
|
100
|
+
icon={ external }
|
|
101
|
+
onClick={ onClose }
|
|
102
|
+
>
|
|
103
|
+
{ __( 'View site' ) }
|
|
104
|
+
<VisuallyHidden as="span">
|
|
105
|
+
{
|
|
106
|
+
/* translators: accessibility text */
|
|
107
|
+
__( '(opens in a new tab)' )
|
|
108
|
+
}
|
|
109
|
+
</VisuallyHidden>
|
|
110
|
+
</MenuItem>
|
|
111
|
+
</MenuGroup>
|
|
112
|
+
) }
|
|
113
|
+
{ isViewable && (
|
|
114
|
+
<MenuGroup>
|
|
115
|
+
<PostPreviewButton
|
|
116
|
+
className="editor-preview-dropdown__button-external"
|
|
117
|
+
role="menuitem"
|
|
118
|
+
forceIsAutosaveable={ forceIsAutosaveable }
|
|
119
|
+
textContent={
|
|
120
|
+
<>
|
|
121
|
+
{ __( 'Preview in new tab' ) }
|
|
122
|
+
<Icon icon={ external } />
|
|
123
|
+
</>
|
|
124
|
+
}
|
|
125
|
+
onPreview={ onClose }
|
|
126
|
+
/>
|
|
127
|
+
</MenuGroup>
|
|
128
|
+
) }
|
|
129
|
+
</>
|
|
130
|
+
) }
|
|
131
|
+
</DropdownMenu>
|
|
132
|
+
);
|
|
133
|
+
}
|