@wordpress/editor 13.22.0 → 13.24.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/build/components/entities-saved-states/index.js +15 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/index.js +32 -0
- package/build/components/index.js.map +1 -1
- package/build/components/page-attributes/order.js +1 -0
- package/build/components/page-attributes/order.js.map +1 -1
- package/build/components/post-author/panel.js +24 -0
- package/build/components/post-author/panel.js.map +1 -0
- package/build/components/post-featured-image/index.js +3 -1
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-panel-row/index.js +36 -0
- package/build/components/post-panel-row/index.js.map +1 -0
- package/build/components/post-saved-state/index.js +21 -16
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/panel.js +67 -0
- package/build/components/post-schedule/panel.js.map +1 -0
- package/build/components/post-sync-status/index.js +9 -5
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-title/constants.js +11 -0
- package/build/components/post-title/constants.js.map +1 -0
- package/build/components/post-title/index.js +61 -90
- package/build/components/post-title/index.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/post-title/post-title-raw.js +92 -0
- package/build/components/post-title/post-title-raw.js.map +1 -0
- package/build/components/post-title/use-post-title-focus.js +64 -0
- package/build/components/post-title/use-post-title-focus.js.map +1 -0
- package/build/components/post-title/use-post-title.js +41 -0
- package/build/components/post-title/use-post-title.js.map +1 -0
- package/build/components/post-url/panel.js +70 -0
- package/build/components/post-url/panel.js.map +1 -0
- package/build/components/provider/constants.js +9 -0
- package/build/components/provider/constants.js.map +1 -0
- package/build/components/provider/disable-non-page-content-blocks.js +63 -0
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -0
- package/build/components/provider/index.js +126 -14
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +22 -17
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.native.js +2 -2
- package/build/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build/private-apis.js +7 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +23 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +10 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +16 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +16 -2
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/index.js +4 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/page-attributes/order.js +1 -0
- package/build-module/components/page-attributes/order.js.map +1 -1
- package/build-module/components/post-author/panel.js +14 -0
- package/build-module/components/post-author/panel.js.map +1 -0
- package/build-module/components/post-featured-image/index.js +3 -1
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-panel-row/index.js +27 -0
- package/build-module/components/post-panel-row/index.js.map +1 -0
- package/build-module/components/post-saved-state/index.js +22 -17
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/panel.js +59 -0
- package/build-module/components/post-schedule/panel.js.map +1 -0
- package/build-module/components/post-sync-status/index.js +10 -7
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-title/constants.js +3 -0
- package/build-module/components/post-title/constants.js.map +1 -0
- package/build-module/components/post-title/index.js +62 -92
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/index.native.js +3 -3
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-title/post-title-raw.js +83 -0
- package/build-module/components/post-title/post-title-raw.js.map +1 -0
- package/build-module/components/post-title/use-post-title-focus.js +57 -0
- package/build-module/components/post-title/use-post-title-focus.js.map +1 -0
- package/build-module/components/post-title/use-post-title.js +33 -0
- package/build-module/components/post-title/use-post-title.js.map +1 -0
- package/build-module/components/post-url/panel.js +62 -0
- package/build-module/components/post-url/panel.js.map +1 -0
- package/build-module/components/provider/constants.js +2 -0
- package/build-module/components/provider/constants.js.map +1 -0
- package/build-module/components/provider/disable-non-page-content-blocks.js +56 -0
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -0
- package/build-module/components/provider/index.js +127 -15
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +22 -17
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.native.js +2 -2
- package/build-module/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build-module/private-apis.js +6 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +21 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +9 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +70 -10
- package/build-style/style.css +70 -10
- package/package.json +31 -31
- package/src/components/entities-saved-states/index.js +16 -1
- package/src/components/index.js +4 -0
- package/src/components/page-attributes/order.js +1 -0
- package/src/components/post-author/panel.js +18 -0
- package/src/components/post-author/style.scss +7 -0
- package/src/components/post-featured-image/index.js +3 -1
- package/src/components/post-panel-row/index.js +26 -0
- package/src/components/post-panel-row/style.scss +21 -0
- package/src/components/post-saved-state/index.js +46 -37
- package/src/components/post-schedule/panel.js +65 -0
- package/src/components/post-schedule/style.scss +23 -0
- package/src/components/post-sync-status/index.js +10 -8
- package/src/components/post-sync-status/style.scss +3 -18
- package/src/components/post-title/constants.js +4 -0
- package/src/components/post-title/index.js +56 -88
- package/src/components/post-title/index.native.js +4 -8
- package/src/components/post-title/post-title-raw.js +82 -0
- package/src/components/post-title/style.scss +5 -0
- package/src/components/post-title/use-post-title-focus.js +50 -0
- package/src/components/post-title/use-post-title.js +25 -0
- package/src/components/post-url/panel.js +60 -0
- package/src/components/post-url/style.scss +19 -0
- package/src/components/provider/README.md +37 -0
- package/src/components/provider/constants.js +5 -0
- package/src/components/provider/disable-non-page-content-blocks.js +55 -0
- package/src/components/provider/index.js +200 -14
- package/src/components/provider/use-block-editor-settings.js +54 -35
- package/src/components/provider/use-block-editor-settings.native.js +2 -2
- package/src/private-apis.js +6 -0
- package/src/store/actions.js +21 -0
- package/src/store/reducer.js +10 -0
- package/src/store/selectors.js +11 -0
- package/src/style.scss +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useDispatch","__","
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","__","_x","Modal","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","useEffect","useState","privateApis","blockEditorPrivateApis","PostPanelRow","store","editorStore","unlock","ReusableBlocksRenameHint","PostSyncStatus","syncStatus","postType","select","getEditedPostAttribute","meta","currentSyncStatus","wp_pattern_sync_status","createElement","label","className","PostSyncStatusModal","editPost","isModalOpen","setIsModalOpen","syncType","setSyncType","undefined","isNewPost","isCleanNewPost","setSyncStatus","Fragment","title","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","help","checked","onChange","justify","variant","type"],"sources":["@wordpress/editor/src/components/post-sync-status/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, _x } from '@wordpress/i18n';\nimport {\n\tModal,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PostPanelRow from '../post-panel-row';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );\n\nexport default function PostSyncStatus() {\n\tconst { syncStatus, postType } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\tconst meta = getEditedPostAttribute( 'meta' );\n\n\t\t// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.\n\t\tconst currentSyncStatus =\n\t\t\tmeta?.wp_pattern_sync_status === 'unsynced'\n\t\t\t\t? 'unsynced'\n\t\t\t\t: getEditedPostAttribute( 'wp_pattern_sync_status' );\n\n\t\treturn {\n\t\t\tsyncStatus: currentSyncStatus,\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t};\n\t} );\n\n\tif ( postType !== 'wp_block' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PostPanelRow label={ __( 'Sync status' ) }>\n\t\t\t<div className=\"editor-post-sync-status__value\">\n\t\t\t\t{ syncStatus === 'unsynced'\n\t\t\t\t\t? __( 'Not synced' )\n\t\t\t\t\t: __( 'Fully synced' ) }\n\t\t\t</div>\n\t\t</PostPanelRow>\n\t);\n}\n\nexport function PostSyncStatusModal() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\n\tconst { postType, isNewPost } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute, isCleanNewPost } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\tisNewPost: isCleanNewPost(),\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isNewPost && postType === 'wp_block' ) {\n\t\t\tsetIsModalOpen( true );\n\t\t}\n\t\t// We only want the modal to open when the page is first loaded.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst setSyncStatus = () => {\n\t\teditPost( {\n\t\t\tmeta: {\n\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t},\n\t\t} );\n\t};\n\n\tif ( postType !== 'wp_block' || ! isNewPost ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Set pattern sync status' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetSyncStatus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,i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cAAc,CAAC,CAAC;MACtBb,cAAc,CAAE,KAAM,CAAC;MACvBM,aAAa,CAAC,CAAC;IAChB;EAAG,GAEHZ,aAAA,CAACnB,MAAM;IAACuC,OAAO,EAAC;EAAG,GAClBpB,aAAA,CAACT,wBAAwB,MAAE,CAAC,EAC5BS,aAAA,CAAClB,aAAa;IACbmB,KAAK,EAAG1B,EAAE,CACT,QAAQ,EACR,sDACD,CAAG;IACH8C,IAAI,EAAG/C,EAAE,CACR,8CACD,CAAG;IACHgD,OAAO,EAAG,CAAEf,QAAU;IACtBgB,QAAQ,EAAGA,CAAA,KAAM;MAChBf,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGE,SAC3B,CAAC;IACF;EAAG,CACH,CAAC,EACFT,aAAA,CAACrB,MAAM;IAAC6C,OAAO,EAAC;EAAO,GACtBxB,aAAA,CAACvB,MAAM;IAACgD,OAAO,EAAC,SAAS;IAACC,IAAI,EAAC;EAAQ,GACpCpD,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAEP,CAAC;AAEL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_CLASSNAMES","REGEXP_NEWLINES"],"sources":["@wordpress/editor/src/components/post-title/constants.js"],"sourcesContent":["export const DEFAULT_CLASSNAMES =\n\t'wp-block wp-block-post-title block-editor-block-list__block editor-post-title editor-post-title__input rich-text';\n\nexport const REGEXP_NEWLINES = /[\\r\\n]+/g;\n"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,GAC9B,kHAAkH;AAEnH,OAAO,MAAMC,eAAe,GAAG,UAAU"}
|
|
@@ -8,12 +8,12 @@ import classnames from 'classnames';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { __ } from '@wordpress/i18n';
|
|
11
|
-
import { forwardRef,
|
|
11
|
+
import { forwardRef, useState } from '@wordpress/element';
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
|
-
import { ENTER } from '@wordpress/keycodes';
|
|
14
13
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
15
|
-
import { pasteHandler } from '@wordpress/blocks';
|
|
16
14
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
15
|
+
import { ENTER } from '@wordpress/keycodes';
|
|
16
|
+
import { pasteHandler } from '@wordpress/blocks';
|
|
17
17
|
import { __unstableUseRichText as useRichText, create, toHTMLString, insert } from '@wordpress/rich-text';
|
|
18
18
|
import { useMergeRefs } from '@wordpress/compose';
|
|
19
19
|
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
@@ -21,33 +21,18 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
|
21
21
|
/**
|
|
22
22
|
* Internal dependencies
|
|
23
23
|
*/
|
|
24
|
-
import PostTypeSupportCheck from '../post-type-support-check';
|
|
25
24
|
import { store as editorStore } from '../../store';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const REGEXP_NEWLINES = /[\r\n]+/g;
|
|
25
|
+
import { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';
|
|
26
|
+
import usePostTitleFocus from './use-post-title-focus';
|
|
27
|
+
import usePostTitle from './use-post-title';
|
|
28
|
+
import PostTypeSupportCheck from '../post-type-support-check';
|
|
31
29
|
function PostTitle(_, forwardedRef) {
|
|
32
|
-
const ref = useRef();
|
|
33
|
-
const [isSelected, setIsSelected] = useState(false);
|
|
34
|
-
const {
|
|
35
|
-
editPost
|
|
36
|
-
} = useDispatch(editorStore);
|
|
37
|
-
const {
|
|
38
|
-
insertDefaultBlock,
|
|
39
|
-
clearSelectedBlock,
|
|
40
|
-
insertBlocks
|
|
41
|
-
} = useDispatch(blockEditorStore);
|
|
42
30
|
const {
|
|
43
|
-
isCleanNewPost,
|
|
44
|
-
title,
|
|
45
31
|
placeholder,
|
|
46
32
|
hasFixedToolbar
|
|
47
33
|
} = useSelect(select => {
|
|
48
34
|
const {
|
|
49
|
-
getEditedPostAttribute
|
|
50
|
-
isCleanNewPost: _isCleanNewPost
|
|
35
|
+
getEditedPostAttribute
|
|
51
36
|
} = select(editorStore);
|
|
52
37
|
const {
|
|
53
38
|
getSettings
|
|
@@ -57,54 +42,31 @@ function PostTitle(_, forwardedRef) {
|
|
|
57
42
|
hasFixedToolbar: _hasFixedToolbar
|
|
58
43
|
} = getSettings();
|
|
59
44
|
return {
|
|
60
|
-
isCleanNewPost: _isCleanNewPost(),
|
|
61
45
|
title: getEditedPostAttribute('title'),
|
|
62
46
|
placeholder: titlePlaceholder,
|
|
63
47
|
hasFixedToolbar: _hasFixedToolbar
|
|
64
48
|
};
|
|
65
49
|
}, []);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const ownerDocument = name === 'editor-canvas' ? parent.document : defaultView.document;
|
|
83
|
-
const {
|
|
84
|
-
activeElement,
|
|
85
|
-
body
|
|
86
|
-
} = ownerDocument;
|
|
87
|
-
|
|
88
|
-
// Only autofocus the title when the post is entirely empty. This should
|
|
89
|
-
// only happen for a new post, which means we focus the title on new
|
|
90
|
-
// post so the author can start typing right away, without needing to
|
|
91
|
-
// click anything.
|
|
92
|
-
if (isCleanNewPost && (!activeElement || body === activeElement)) {
|
|
93
|
-
ref.current.focus();
|
|
94
|
-
}
|
|
95
|
-
}, [isCleanNewPost]);
|
|
96
|
-
function onEnterPress() {
|
|
97
|
-
insertDefaultBlock(undefined, undefined, 0);
|
|
50
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
51
|
+
const {
|
|
52
|
+
ref: focusRef
|
|
53
|
+
} = usePostTitleFocus(forwardedRef);
|
|
54
|
+
const {
|
|
55
|
+
title,
|
|
56
|
+
setTitle: onUpdate
|
|
57
|
+
} = usePostTitle();
|
|
58
|
+
const [selection, setSelection] = useState({});
|
|
59
|
+
const {
|
|
60
|
+
clearSelectedBlock,
|
|
61
|
+
insertBlocks,
|
|
62
|
+
insertDefaultBlock
|
|
63
|
+
} = useDispatch(blockEditorStore);
|
|
64
|
+
function onChange(value) {
|
|
65
|
+
onUpdate(value.replace(REGEXP_NEWLINES, ' '));
|
|
98
66
|
}
|
|
99
67
|
function onInsertBlockAfter(blocks) {
|
|
100
68
|
insertBlocks(blocks, 0);
|
|
101
69
|
}
|
|
102
|
-
function onUpdate(newTitle) {
|
|
103
|
-
editPost({
|
|
104
|
-
title: newTitle
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const [selection, setSelection] = useState({});
|
|
108
70
|
function onSelect() {
|
|
109
71
|
setIsSelected(true);
|
|
110
72
|
clearSelectedBlock();
|
|
@@ -113,8 +75,8 @@ function PostTitle(_, forwardedRef) {
|
|
|
113
75
|
setIsSelected(false);
|
|
114
76
|
setSelection({});
|
|
115
77
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
78
|
+
function onEnterPress() {
|
|
79
|
+
insertDefaultBlock(undefined, undefined, 0);
|
|
118
80
|
}
|
|
119
81
|
function onKeyDown(event) {
|
|
120
82
|
if (event.keyCode === ENTER) {
|
|
@@ -158,7 +120,11 @@ function PostTitle(_, forwardedRef) {
|
|
|
158
120
|
if (typeof content !== 'string') {
|
|
159
121
|
const [firstBlock] = content;
|
|
160
122
|
if (!title && (firstBlock.name === 'core/heading' || firstBlock.name === 'core/paragraph')) {
|
|
161
|
-
|
|
123
|
+
// Strip HTML to avoid unwanted HTML being added to the title.
|
|
124
|
+
// In the majority of cases it is assumed that HTML in the title
|
|
125
|
+
// is undesirable.
|
|
126
|
+
const contentNoHTML = stripHTML(firstBlock.attributes.content);
|
|
127
|
+
onUpdate(contentNoHTML);
|
|
162
128
|
onInsertBlockAfter(content.slice(1));
|
|
163
129
|
} else {
|
|
164
130
|
onInsertBlockAfter(content);
|
|
@@ -170,8 +136,13 @@ function PostTitle(_, forwardedRef) {
|
|
|
170
136
|
}),
|
|
171
137
|
...selection
|
|
172
138
|
};
|
|
139
|
+
|
|
140
|
+
// Strip HTML to avoid unwanted HTML being added to the title.
|
|
141
|
+
// In the majority of cases it is assumed that HTML in the title
|
|
142
|
+
// is undesirable.
|
|
143
|
+
const contentNoHTML = stripHTML(content);
|
|
173
144
|
const newValue = insert(value, create({
|
|
174
|
-
html:
|
|
145
|
+
html: contentNoHTML
|
|
175
146
|
}));
|
|
176
147
|
onUpdate(toHTMLString({
|
|
177
148
|
value: newValue
|
|
@@ -182,13 +153,6 @@ function PostTitle(_, forwardedRef) {
|
|
|
182
153
|
});
|
|
183
154
|
}
|
|
184
155
|
}
|
|
185
|
-
|
|
186
|
-
// The wp-block className is important for editor styles.
|
|
187
|
-
// This same block is used in both the visual and the code editor.
|
|
188
|
-
const className = classnames('wp-block wp-block-post-title block-editor-block-list__block editor-post-title editor-post-title__input rich-text', {
|
|
189
|
-
'is-selected': isSelected,
|
|
190
|
-
'has-fixed-toolbar': hasFixedToolbar
|
|
191
|
-
});
|
|
192
156
|
const decodedPlaceholder = decodeEntities(placeholder) || __('Add title');
|
|
193
157
|
const {
|
|
194
158
|
ref: richTextRef
|
|
@@ -213,27 +177,33 @@ function PostTitle(_, forwardedRef) {
|
|
|
213
177
|
};
|
|
214
178
|
});
|
|
215
179
|
},
|
|
216
|
-
__unstableDisableFormats:
|
|
217
|
-
preserveWhiteSpace: true
|
|
180
|
+
__unstableDisableFormats: false
|
|
218
181
|
});
|
|
219
182
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
183
|
+
// The wp-block className is important for editor styles.
|
|
184
|
+
// This same block is used in both the visual and the code editor.
|
|
185
|
+
const className = classnames(DEFAULT_CLASSNAMES, {
|
|
186
|
+
'is-selected': isSelected,
|
|
187
|
+
'has-fixed-toolbar': hasFixedToolbar
|
|
188
|
+
});
|
|
189
|
+
return (/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
190
|
+
createElement(PostTypeSupportCheck, {
|
|
191
|
+
supportKeys: "title"
|
|
192
|
+
}, createElement("h1", {
|
|
193
|
+
ref: useMergeRefs([richTextRef, focusRef]),
|
|
194
|
+
contentEditable: true,
|
|
195
|
+
className: className,
|
|
196
|
+
"aria-label": decodedPlaceholder,
|
|
197
|
+
role: "textbox",
|
|
198
|
+
"aria-multiline": "true",
|
|
199
|
+
onFocus: onSelect,
|
|
200
|
+
onBlur: onUnselect,
|
|
201
|
+
onKeyDown: onKeyDown,
|
|
202
|
+
onKeyPress: onUnselect,
|
|
203
|
+
onPaste: onPaste
|
|
204
|
+
}))
|
|
205
|
+
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
206
|
+
);
|
|
237
207
|
}
|
|
238
208
|
|
|
239
209
|
export default forwardRef(PostTitle);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","__","forwardRef","useEffect","useImperativeHandle","useRef","useState","decodeEntities","ENTER","useSelect","useDispatch","pasteHandler","store","blockEditorStore","__unstableUseRichText","useRichText","create","toHTMLString","insert","useMergeRefs","__unstableStripHTML","stripHTML","PostTypeSupportCheck","editorStore","REGEXP_NEWLINES","PostTitle","_","forwardedRef","ref","isSelected","setIsSelected","editPost","insertDefaultBlock","clearSelectedBlock","insertBlocks","isCleanNewPost","title","placeholder","hasFixedToolbar","select","getEditedPostAttribute","_isCleanNewPost","getSettings","titlePlaceholder","_hasFixedToolbar","focus","current","defaultView","ownerDocument","name","parent","document","activeElement","body","onEnterPress","undefined","onInsertBlockAfter","blocks","onUpdate","newTitle","selection","setSelection","onSelect","onUnselect","onChange","value","replace","onKeyDown","event","keyCode","preventDefault","onPaste","clipboardData","plainText","html","getData","error1","error2","window","console","log","content","HTML","length","firstBlock","attributes","slice","newValue","start","end","className","decodedPlaceholder","richTextRef","selectionStart","selectionEnd","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","preserveWhiteSpace","createElement","supportKeys","contentEditable","role","onFocus","onBlur","onKeyPress"],"sources":["@wordpress/editor/src/components/post-title/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { ENTER } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { pasteHandler } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\t__unstableUseRichText as useRichText,\n\tcreate,\n\ttoHTMLString,\n\tinsert,\n} from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport PostTypeSupportCheck from '../post-type-support-check';\nimport { store as editorStore } from '../../store';\n\n/**\n * Constants\n */\nconst REGEXP_NEWLINES = /[\\r\\n]+/g;\n\nfunction PostTitle( _, forwardedRef ) {\n\tconst ref = useRef();\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { insertDefaultBlock, clearSelectedBlock, insertBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { isCleanNewPost, title, placeholder, hasFixedToolbar } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedPostAttribute, isCleanNewPost: _isCleanNewPost } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\tconst { titlePlaceholder, hasFixedToolbar: _hasFixedToolbar } =\n\t\t\t\tgetSettings();\n\n\t\t\treturn {\n\t\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\t\tplaceholder: titlePlaceholder,\n\t\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tuseImperativeHandle( forwardedRef, () => ( {\n\t\tfocus: () => {\n\t\t\tref?.current?.focus();\n\t\t},\n\t} ) );\n\n\tuseEffect( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { defaultView } = ref.current.ownerDocument;\n\t\tconst { name, parent } = defaultView;\n\t\tconst ownerDocument =\n\t\t\tname === 'editor-canvas' ? parent.document : defaultView.document;\n\t\tconst { activeElement, body } = ownerDocument;\n\n\t\t// Only autofocus the title when the post is entirely empty. This should\n\t\t// only happen for a new post, which means we focus the title on new\n\t\t// post so the author can start typing right away, without needing to\n\t\t// click anything.\n\t\tif ( isCleanNewPost && ( ! activeElement || body === activeElement ) ) {\n\t\t\tref.current.focus();\n\t\t}\n\t}, [ isCleanNewPost ] );\n\n\tfunction onEnterPress() {\n\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t}\n\n\tfunction onInsertBlockAfter( blocks ) {\n\t\tinsertBlocks( blocks, 0 );\n\t}\n\n\tfunction onUpdate( newTitle ) {\n\t\teditPost( { title: newTitle } );\n\t}\n\n\tconst [ selection, setSelection ] = useState( {} );\n\n\tfunction onSelect() {\n\t\tsetIsSelected( true );\n\t\tclearSelectedBlock();\n\t}\n\n\tfunction onUnselect() {\n\t\tsetIsSelected( false );\n\t\tsetSelection( {} );\n\t}\n\n\tfunction onChange( value ) {\n\t\tonUpdate( value.replace( REGEXP_NEWLINES, ' ' ) );\n\t}\n\n\tfunction onKeyDown( event ) {\n\t\tif ( event.keyCode === ENTER ) {\n\t\t\tevent.preventDefault();\n\t\t\tonEnterPress();\n\t\t}\n\t}\n\n\tfunction onPaste( event ) {\n\t\tconst clipboardData = event.clipboardData;\n\n\t\tlet plainText = '';\n\t\tlet html = '';\n\n\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t// arguments first, then fallback to `Text` if they fail.\n\t\ttry {\n\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t} catch ( error1 ) {\n\t\t\ttry {\n\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t} catch ( error2 ) {\n\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t// behaviour.\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\tconst content = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t} );\n\n\t\tevent.preventDefault();\n\n\t\tif ( ! content.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( typeof content !== 'string' ) {\n\t\t\tconst [ firstBlock ] = content;\n\n\t\t\tif (\n\t\t\t\t! title &&\n\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t) {\n\t\t\t\tonUpdate( stripHTML( firstBlock.attributes.content ) );\n\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t} else {\n\t\t\t\tonInsertBlockAfter( content );\n\t\t\t}\n\t\t} else {\n\t\t\tconst value = {\n\t\t\t\t...create( { html: title } ),\n\t\t\t\t...selection,\n\t\t\t};\n\t\t\tconst newValue = insert(\n\t\t\t\tvalue,\n\t\t\t\tcreate( { html: stripHTML( content ) } )\n\t\t\t);\n\t\t\tonUpdate( toHTMLString( { value: newValue } ) );\n\t\t\tsetSelection( {\n\t\t\t\tstart: newValue.start,\n\t\t\t\tend: newValue.end,\n\t\t\t} );\n\t\t}\n\t}\n\n\t// The wp-block className is important for editor styles.\n\t// This same block is used in both the visual and the code editor.\n\tconst className = classnames(\n\t\t'wp-block wp-block-post-title block-editor-block-list__block editor-post-title editor-post-title__input rich-text',\n\t\t{\n\t\t\t'is-selected': isSelected,\n\t\t\t'has-fixed-toolbar': hasFixedToolbar,\n\t\t}\n\t);\n\tconst decodedPlaceholder =\n\t\tdecodeEntities( placeholder ) || __( 'Add title' );\n\tconst { ref: richTextRef } = useRichText( {\n\t\tvalue: title,\n\t\tonChange,\n\t\tplaceholder: decodedPlaceholder,\n\t\tselectionStart: selection.start,\n\t\tselectionEnd: selection.end,\n\t\tonSelectionChange( newStart, newEnd ) {\n\t\t\tsetSelection( ( sel ) => {\n\t\t\t\tconst { start, end } = sel;\n\t\t\t\tif ( start === newStart && end === newEnd ) {\n\t\t\t\t\treturn sel;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tstart: newStart,\n\t\t\t\t\tend: newEnd,\n\t\t\t\t};\n\t\t\t} );\n\t\t},\n\t\t__unstableDisableFormats: true,\n\t\tpreserveWhiteSpace: true,\n\t} );\n\n\t/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */\n\treturn (\n\t\t<PostTypeSupportCheck supportKeys=\"title\">\n\t\t\t<h1\n\t\t\t\tref={ useMergeRefs( [ richTextRef, ref ] ) }\n\t\t\t\tcontentEditable\n\t\t\t\tclassName={ className }\n\t\t\t\taria-label={ decodedPlaceholder }\n\t\t\t\trole=\"textbox\"\n\t\t\t\taria-multiline=\"true\"\n\t\t\t\tonFocus={ onSelect }\n\t\t\t\tonBlur={ onUnselect }\n\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\tonKeyPress={ onUnselect }\n\t\t\t\tonPaste={ onPaste }\n\t\t\t/>\n\t\t</PostTypeSupportCheck>\n\t);\n\t/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */\n}\n\nexport default forwardRef( PostTitle );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SACCC,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,MAAM,EACNC,QAAQ,QACF,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,qBAAqB;AAC3C,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SACCC,qBAAqB,IAAIC,WAAW,EACpCC,MAAM,EACNC,YAAY,EACZC,MAAM,QACA,sBAAsB;AAC7B,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,mBAAmB,IAAIC,SAAS,QAAQ,gBAAgB;;AAEjE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,4BAA4B;AAC7D,SAASV,KAAK,IAAIW,WAAW,QAAQ,aAAa;;AAElD;AACA;AACA;AACA,MAAMC,eAAe,GAAG,UAAU;AAElC,SAASC,SAASA,CAAEC,CAAC,EAAEC,YAAY,EAAG;EACrC,MAAMC,GAAG,GAAGvB,MAAM,CAAC,CAAC;EACpB,MAAM,CAAEwB,UAAU,EAAEC,aAAa,CAAE,GAAGxB,QAAQ,CAAE,KAAM,CAAC;EACvD,MAAM;IAAEyB;EAAS,CAAC,GAAGrB,WAAW,CAAEa,WAAY,CAAC;EAC/C,MAAM;IAAES,kBAAkB;IAAEC,kBAAkB;IAAEC;EAAa,CAAC,GAC7DxB,WAAW,CAAEG,gBAAiB,CAAC;EAChC,MAAM;IAAEsB,cAAc;IAAEC,KAAK;IAAEC,WAAW;IAAEC;EAAgB,CAA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MAAM,EAAG3C,UAAY;IACrBI,SAAS,EAAGA,SAAW;IACvBwC,UAAU,EAAG5C,UAAY;IACzBQ,OAAO,EAAGA;EAAS,CACnB,CACoB,CAAC;EAExB;AACD;;AAEA,eAAerE,UAAU,CAAEuB,SAAU,CAAC"}
|
|
1
|
+
{"version":3,"names":["classnames","__","forwardRef","useState","decodeEntities","useSelect","useDispatch","store","blockEditorStore","ENTER","pasteHandler","__unstableUseRichText","useRichText","create","toHTMLString","insert","useMergeRefs","__unstableStripHTML","stripHTML","editorStore","DEFAULT_CLASSNAMES","REGEXP_NEWLINES","usePostTitleFocus","usePostTitle","PostTypeSupportCheck","PostTitle","_","forwardedRef","placeholder","hasFixedToolbar","select","getEditedPostAttribute","getSettings","titlePlaceholder","_hasFixedToolbar","title","isSelected","setIsSelected","ref","focusRef","setTitle","onUpdate","selection","setSelection","clearSelectedBlock","insertBlocks","insertDefaultBlock","onChange","value","replace","onInsertBlockAfter","blocks","onSelect","onUnselect","onEnterPress","undefined","onKeyDown","event","keyCode","preventDefault","onPaste","clipboardData","plainText","html","getData","error1","error2","window","console","log","content","HTML","length","firstBlock","name","contentNoHTML","attributes","slice","newValue","start","end","decodedPlaceholder","richTextRef","selectionStart","selectionEnd","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","className","createElement","supportKeys","contentEditable","role","onFocus","onBlur","onKeyPress"],"sources":["@wordpress/editor/src/components/post-title/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef, useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { ENTER } from '@wordpress/keycodes';\nimport { pasteHandler } from '@wordpress/blocks';\nimport {\n\t__unstableUseRichText as useRichText,\n\tcreate,\n\ttoHTMLString,\n\tinsert,\n} from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';\nimport usePostTitleFocus from './use-post-title-focus';\nimport usePostTitle from './use-post-title';\nimport PostTypeSupportCheck from '../post-type-support-check';\n\nfunction PostTitle( _, forwardedRef ) {\n\tconst { placeholder, hasFixedToolbar } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { titlePlaceholder, hasFixedToolbar: _hasFixedToolbar } =\n\t\t\tgetSettings();\n\n\t\treturn {\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t};\n\t}, [] );\n\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\n\tconst { ref: focusRef } = usePostTitleFocus( forwardedRef );\n\n\tconst { title, setTitle: onUpdate } = usePostTitle();\n\n\tconst [ selection, setSelection ] = useState( {} );\n\n\tconst { clearSelectedBlock, insertBlocks, insertDefaultBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tfunction onChange( value ) {\n\t\tonUpdate( value.replace( REGEXP_NEWLINES, ' ' ) );\n\t}\n\n\tfunction onInsertBlockAfter( blocks ) {\n\t\tinsertBlocks( blocks, 0 );\n\t}\n\n\tfunction onSelect() {\n\t\tsetIsSelected( true );\n\t\tclearSelectedBlock();\n\t}\n\n\tfunction onUnselect() {\n\t\tsetIsSelected( false );\n\t\tsetSelection( {} );\n\t}\n\n\tfunction onEnterPress() {\n\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t}\n\n\tfunction onKeyDown( event ) {\n\t\tif ( event.keyCode === ENTER ) {\n\t\t\tevent.preventDefault();\n\t\t\tonEnterPress();\n\t\t}\n\t}\n\n\tfunction onPaste( event ) {\n\t\tconst clipboardData = event.clipboardData;\n\n\t\tlet plainText = '';\n\t\tlet html = '';\n\n\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t// arguments first, then fallback to `Text` if they fail.\n\t\ttry {\n\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t} catch ( error1 ) {\n\t\t\ttry {\n\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t} catch ( error2 ) {\n\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t// behaviour.\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\tconst content = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t} );\n\n\t\tevent.preventDefault();\n\n\t\tif ( ! content.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( typeof content !== 'string' ) {\n\t\t\tconst [ firstBlock ] = content;\n\n\t\t\tif (\n\t\t\t\t! title &&\n\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t) {\n\t\t\t\t// Strip HTML to avoid unwanted HTML being added to the title.\n\t\t\t\t// In the majority of cases it is assumed that HTML in the title\n\t\t\t\t// is undesirable.\n\t\t\t\tconst contentNoHTML = stripHTML(\n\t\t\t\t\tfirstBlock.attributes.content\n\t\t\t\t);\n\t\t\t\tonUpdate( contentNoHTML );\n\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t} else {\n\t\t\t\tonInsertBlockAfter( content );\n\t\t\t}\n\t\t} else {\n\t\t\tconst value = {\n\t\t\t\t...create( { html: title } ),\n\t\t\t\t...selection,\n\t\t\t};\n\n\t\t\t// Strip HTML to avoid unwanted HTML being added to the title.\n\t\t\t// In the majority of cases it is assumed that HTML in the title\n\t\t\t// is undesirable.\n\t\t\tconst contentNoHTML = stripHTML( content );\n\n\t\t\tconst newValue = insert( value, create( { html: contentNoHTML } ) );\n\t\t\tonUpdate( toHTMLString( { value: newValue } ) );\n\t\t\tsetSelection( {\n\t\t\t\tstart: newValue.start,\n\t\t\t\tend: newValue.end,\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst decodedPlaceholder =\n\t\tdecodeEntities( placeholder ) || __( 'Add title' );\n\n\tconst { ref: richTextRef } = useRichText( {\n\t\tvalue: title,\n\t\tonChange,\n\t\tplaceholder: decodedPlaceholder,\n\t\tselectionStart: selection.start,\n\t\tselectionEnd: selection.end,\n\t\tonSelectionChange( newStart, newEnd ) {\n\t\t\tsetSelection( ( sel ) => {\n\t\t\t\tconst { start, end } = sel;\n\t\t\t\tif ( start === newStart && end === newEnd ) {\n\t\t\t\t\treturn sel;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tstart: newStart,\n\t\t\t\t\tend: newEnd,\n\t\t\t\t};\n\t\t\t} );\n\t\t},\n\t\t__unstableDisableFormats: false,\n\t} );\n\n\t// The wp-block className is important for editor styles.\n\t// This same block is used in both the visual and the code editor.\n\tconst className = classnames( DEFAULT_CLASSNAMES, {\n\t\t'is-selected': isSelected,\n\t\t'has-fixed-toolbar': hasFixedToolbar,\n\t} );\n\n\treturn (\n\t\t/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */\n\t\t<PostTypeSupportCheck supportKeys=\"title\">\n\t\t\t<h1\n\t\t\t\tref={ useMergeRefs( [ richTextRef, focusRef ] ) }\n\t\t\t\tcontentEditable\n\t\t\t\tclassName={ className }\n\t\t\t\taria-label={ decodedPlaceholder }\n\t\t\t\trole=\"textbox\"\n\t\t\t\taria-multiline=\"true\"\n\t\t\t\tonFocus={ onSelect }\n\t\t\t\tonBlur={ onUnselect }\n\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\tonKeyPress={ onUnselect }\n\t\t\t\tonPaste={ onPaste }\n\t\t\t/>\n\t\t</PostTypeSupportCheck>\n\t\t/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */\n\t);\n}\n\nexport default forwardRef( PostTitle );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,UAAU,EAAEC,QAAQ,QAAQ,oBAAoB;AACzD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,KAAK,QAAQ,qBAAqB;AAC3C,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SACCC,qBAAqB,IAAIC,WAAW,EACpCC,MAAM,EACNC,YAAY,EACZC,MAAM,QACA,sBAAsB;AAC7B,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,mBAAmB,IAAIC,SAAS,QAAQ,gBAAgB;;AAEjE;AACA;AACA;AACA,SAASX,KAAK,IAAIY,WAAW,QAAQ,aAAa;AAClD,SAASC,kBAAkB,EAAEC,eAAe,QAAQ,aAAa;AACjE,OAAOC,iBAAiB,MAAM,wBAAwB;AACtD,OAAOC,YAAY,MAAM,kBAAkB;AAC3C,OAAOC,oBAAoB,MAAM,4BAA4B;AAE7D,SAASC,SAASA,CAAEC,CAAC,EAAEC,YAAY,EAAG;EACrC,MAAM;IAAEC,WAAW;IAAEC;EAAgB,CAAC,GAAGxB,SAAS,CAAIyB,MAAM,IAAM;IACjE,MAAM;MAAEC;IAAuB,CAAC,GAAGD,MAAM,CAAEX,WAAY,CAAC;IACxD,MAAM;MAAEa;IAAY,CAAC,GAAGF,MAAM,CAAEtB,gBAAiB,CAAC;IAClD,MAA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O;UACNT,KAAK,EAAEO,QAAQ;UACfN,GAAG,EAAEO;QACN,CAAC;MACF,CAAE,CAAC;IACJ,CAAC;IACDE,wBAAwB,EAAE;EAC3B,CAAE,CAAC;;EAEH;EACA;EACA,MAAMC,SAAS,GAAG1F,UAAU,CAAEoB,kBAAkB,EAAE;IACjD,aAAa,EAAEgB,UAAU;IACzB,mBAAmB,EAAEP;EACtB,CAAE,CAAC;EAEH,OACC;IACA8D,aAAA,CAACnE,oBAAoB;MAACoE,WAAW,EAAC;IAAO,GACxCD,aAAA;MACCrD,GAAG,EAAGtB,YAAY,CAAE,CAAEkE,WAAW,EAAE3C,QAAQ,CAAG,CAAG;MACjDsD,eAAe;MACfH,SAAS,EAAGA,SAAW;MACvB,cAAaT,kBAAoB;MACjCa,IAAI,EAAC,SAAS;MACd,kBAAe,MAAM;MACrBC,OAAO,EAAG3C,QAAU;MACpB4C,MAAM,EAAG3C,UAAY;MACrBG,SAAS,EAAGA,SAAW;MACvByC,UAAU,EAAG5C,UAAY;MACzBO,OAAO,EAAGA;IAAS,CACnB,CACoB;IACtB;EAAA;AAEF;;AAEA,eAAe1D,UAAU,CAAEuB,SAAU,CAAC"}
|
|
@@ -8,14 +8,14 @@ import { View } from 'react-native';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { Component } from '@wordpress/element';
|
|
11
|
-
import {
|
|
11
|
+
import { create, insert } from '@wordpress/rich-text';
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
13
|
import { withDispatch, withSelect } from '@wordpress/data';
|
|
14
14
|
import { withFocusOutside } from '@wordpress/components';
|
|
15
15
|
import { withInstanceId, compose } from '@wordpress/compose';
|
|
16
16
|
import { __, sprintf } from '@wordpress/i18n';
|
|
17
17
|
import { pasteHandler } from '@wordpress/blocks';
|
|
18
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
18
|
+
import { store as blockEditorStore, RichText } from '@wordpress/block-editor';
|
|
19
19
|
import { store as editorStore } from '@wordpress/editor';
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -121,7 +121,7 @@ class PostTitle extends Component {
|
|
|
121
121
|
accessible: !this.props.isSelected,
|
|
122
122
|
accessibilityLabel: this.getTitle(title, postType),
|
|
123
123
|
accessibilityHint: __('Updates the title.')
|
|
124
|
-
}, createElement(RichText, {
|
|
124
|
+
}, createElement(RichText.Raw, {
|
|
125
125
|
setRef: this.setRef,
|
|
126
126
|
accessibilityLabel: this.getTitle(title, postType),
|
|
127
127
|
tagName: 'p',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["View","Component","__experimentalRichText","RichText","create","insert","decodeEntities","withDispatch","withSelect","withFocusOutside","withInstanceId","compose","__","sprintf","pasteHandler","store","blockEditorStore","editorStore","styles","PostTitle","constructor","props","setRef","bind","onPaste","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","value","onChange","plainText","html","title","onInsertBlockAfter","onUpdate","content","HTML","length","valueToInsert","firstBlock","name","attributes","slice","richText","getTitle","postType","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","borderColor","titleStyles","text","color","placeholderColor","createElement","testID","titleContainer","dimmed","accessible","accessibilityLabel","accessibilityHint","tagName","tagsToEliminate","unstableOnFocus","onBlur","multiline","fontSize","lineHeight","fontWeight","deleteEnter","onSelectionChange","onEnter","onEnterPress","disableEditingMenu","__unstableIsSelected","__unstableOnCreateUndoLevel","select","isPostTitleSelected","getEditedPostAttribute","getSelectedBlockClientId","getBlockRootClientId","getSettings","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks"],"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport {\n\t__experimentalRichText as RichText,\n\tcreate,\n\tinsert,\n} from '@wordpress/rich-text';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { withFocusOutside } from '@wordpress/components';\nimport { withInstanceId, compose } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { pasteHandler } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nclass PostTitle extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.setRef = this.setRef.bind( this );\n\t\tthis.onPaste = this.onPaste.bind( this );\n\t}\n\tcomponentDidUpdate( prevProps ) {\n\t\t// Unselect if any other block is selected and blur the RichText.\n\t\tif (\n\t\t\tthis.props.isSelected &&\n\t\t\t! prevProps.isAnyBlockSelected &&\n\t\t\tthis.props.isAnyBlockSelected\n\t\t) {\n\t\t\tif ( this.richTextRef ) {\n\t\t\t\tthis.richTextRef.blur();\n\t\t\t}\n\t\t\tthis.props.onUnselect();\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.props.innerRef ) {\n\t\t\tthis.props.innerRef( this );\n\t\t}\n\t}\n\n\thandleFocusOutside() {\n\t\tthis.props.onUnselect();\n\t}\n\n\tfocus() {\n\t\tthis.props.onSelect();\n\t}\n\n\tonPaste( { value, onChange, plainText, html } ) {\n\t\tconst { title, onInsertBlockAfter, onUpdate } = this.props;\n\n\t\tconst content = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t} );\n\n\t\tif ( content.length ) {\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tconst valueToInsert = create( { html: content } );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else {\n\t\t\t\tconst [ firstBlock ] = content;\n\t\t\t\tif (\n\t\t\t\t\t! title &&\n\t\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t\t) {\n\t\t\t\t\tonUpdate( firstBlock.attributes.content );\n\t\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t\t} else {\n\t\t\t\t\tonInsertBlockAfter( content );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tsetRef( richText ) {\n\t\tthis.richTextRef = richText;\n\t}\n\n\tgetTitle( title, postType ) {\n\t\tif ( 'page' === postType ) {\n\t\t\treturn ! title\n\t\t\t\t? /* translators: accessibility text. empty page title. */\n\t\t\t\t __( 'Page title. Empty' )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: text content of the page title. */\n\t\t\t\t\t\t__( 'Page title. %s' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t );\n\t\t}\n\n\t\treturn ! title\n\t\t\t? /* translators: accessibility text. empty post title. */\n\t\t\t __( 'Post title. Empty' )\n\t\t\t: sprintf(\n\t\t\t\t\t/* translators: accessibility text. %s: text content of the post title. */\n\t\t\t\t\t__( 'Post title. %s' ),\n\t\t\t\t\ttitle\n\t\t\t );\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tplaceholder,\n\t\t\tstyle,\n\t\t\ttitle,\n\t\t\tfocusedBorderColor,\n\t\t\tborderStyle,\n\t\t\tisDimmed,\n\t\t\tpostType,\n\t\t\tglobalStyles,\n\t\t} = this.props;\n\n\t\tconst decodedPlaceholder = decodeEntities( placeholder );\n\t\tconst borderColor = this.props.isSelected\n\t\t\t? focusedBorderColor\n\t\t\t: 'transparent';\n\t\tconst titleStyles = {\n\t\t\t...style,\n\t\t\t...( globalStyles?.text && {\n\t\t\t\tcolor: globalStyles.text,\n\t\t\t\tplaceholderColor: globalStyles.text,\n\t\t\t} ),\n\t\t};\n\n\t\treturn (\n\t\t\t<View\n\t\t\t\ttestID=\"post-title\"\n\t\t\t\tstyle={ [\n\t\t\t\t\tstyles.titleContainer,\n\t\t\t\t\tborderStyle,\n\t\t\t\t\t{ borderColor },\n\t\t\t\t\tisDimmed && styles.dimmed,\n\t\t\t\t] }\n\t\t\t\taccessible={ ! this.props.isSelected }\n\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\taccessibilityHint={ __( 'Updates the title.' ) }\n\t\t\t>\n\t\t\t\t<RichText\n\t\t\t\t\tsetRef={ this.setRef }\n\t\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\t\ttagName={ 'p' }\n\t\t\t\t\ttagsToEliminate={ [ 'strong' ] }\n\t\t\t\t\tunstableOnFocus={ this.props.onSelect }\n\t\t\t\t\tonBlur={ this.props.onBlur } // Always assign onBlur as a props.\n\t\t\t\t\tmultiline={ false }\n\t\t\t\t\tstyle={ titleStyles }\n\t\t\t\t\tstyles={ styles }\n\t\t\t\t\tfontSize={ 24 }\n\t\t\t\t\tlineHeight={ 1 }\n\t\t\t\t\tfontWeight={ 'bold' }\n\t\t\t\t\tdeleteEnter={ true }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tthis.props.onUpdate( value );\n\t\t\t\t\t} }\n\t\t\t\t\tonPaste={ this.onPaste }\n\t\t\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonSelectionChange={ () => {} }\n\t\t\t\t\tonEnter={ this.props.onEnterPress }\n\t\t\t\t\tdisableEditingMenu={ true }\n\t\t\t\t\t__unstableIsSelected={ this.props.isSelected }\n\t\t\t\t\t__unstableOnCreateUndoLevel={ () => {} }\n\t\t\t\t></RichText>\n\t\t\t</View>\n\t\t);\n\t}\n}\n\nexport default compose(\n\twithSelect( ( select ) => {\n\t\tconst { isPostTitleSelected, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst { getSelectedBlockClientId, getBlockRootClientId, getSettings } =\n\t\t\tselect( blockEditorStore );\n\n\t\tconst selectedId = getSelectedBlockClientId();\n\t\tconst selectionIsNested = !! getBlockRootClientId( selectedId );\n\t\tconst globalStyles =\n\t\t\tgetSettings()?.__experimentalGlobalStylesBaseStyles?.color;\n\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tisAnyBlockSelected: !! selectedId,\n\t\t\tisSelected: isPostTitleSelected(),\n\t\t\tisDimmed: selectionIsNested,\n\t\t\tglobalStyles,\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { undo, redo, togglePostTitleSelection, editPost } =\n\t\t\tdispatch( editorStore );\n\n\t\tconst { clearSelectedBlock, insertDefaultBlock, insertBlocks } =\n\t\t\tdispatch( blockEditorStore );\n\n\t\treturn {\n\t\t\tonEnterPress() {\n\t\t\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t\t\t},\n\t\t\tonUndo: undo,\n\t\t\tonRedo: redo,\n\t\t\tonSelect() {\n\t\t\t\ttogglePostTitleSelection( true );\n\t\t\t\tclearSelectedBlock();\n\t\t\t},\n\t\t\tonUnselect() {\n\t\t\t\ttogglePostTitleSelection( false );\n\t\t\t},\n\t\t\tonUpdate( title ) {\n\t\t\t\teditPost( { title } );\n\t\t\t},\n\t\t\tonInsertBlockAfter( blocks ) {\n\t\t\t\tinsertBlocks( blocks, 0 );\n\t\t\t},\n\t\t};\n\t} ),\n\twithInstanceId,\n\twithFocusOutside\n)( PostTitle );\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,cAAc;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SACCC,sBAAsB,IAAIC,QAAQ,EAClCC,MAAM,EACNC,MAAM,QACA,sBAAsB;AAC7B,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,YAAY,EAAEC,UAAU,QAAQ,iBAAiB;AAC1D,SAASC,gBAAgB,QAAQ,u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E,UAAU,EAAEgE,mBAAmB,CAAC,CAAC;IACjC/B,QAAQ,EAAEqC,iBAAiB;IAC3BpC;EACD,CAAC;AACF,CAAE,CAAC,EACHtD,YAAY,CAAI4F,QAAQ,IAAM;EAC7B,MAAM;IAAEC,IAAI;IAAEC,IAAI;IAAEC,wBAAwB;IAAEC;EAAS,CAAC,GACvDJ,QAAQ,CAAElF,WAAY,CAAC;EAExB,MAAM;IAAEuF,kBAAkB;IAAEC,kBAAkB;IAAEC;EAAa,CAAC,GAC7DP,QAAQ,CAAEnF,gBAAiB,CAAC;EAE7B,OAAO;IACNsE,YAAYA,CAAA,EAAG;MACdmB,kBAAkB,CAAEE,SAAS,EAAEA,SAAS,EAAE,CAAE,CAAC;IAC9C,CAAC;IACDC,MAAM,EAAER,IAAI;IACZS,MAAM,EAAER,IAAI;IACZjE,QAAQA,CAAA,EAAG;MACVkE,wBAAwB,CAAE,IAAK,CAAC;MAChCE,kBAAkB,CAAC,CAAC;IACrB,CAAC;IACDzE,UAAUA,CAAA,EAAG;MACZuE,wBAAwB,CAAE,KAAM,CAAC;IAClC,CAAC;IACD3D,QAAQA,CAAEF,KAAK,EAAG;MACjB8D,QAAQ,CAAE;QAAE9D;MAAM,CAAE,CAAC;IACtB,CAAC;IACDC,kBAAkBA,CAAEoE,MAAM,EAAG;MAC5BJ,YAAY,CAAEI,MAAM,EAAE,CAAE,CAAC;IAC1B;EACD,CAAC;AACF,CAAE,CAAC,EACHpG,cAAc,EACdD,gBACD,CAAC,CAAEU,SAAU,CAAC"}
|
|
1
|
+
{"version":3,"names":["View","Component","create","insert","decodeEntities","withDispatch","withSelect","withFocusOutside","withInstanceId","compose","__","sprintf","pasteHandler","store","blockEditorStore","RichText","editorStore","styles","PostTitle","constructor","props","setRef","bind","onPaste","componentDidUpdate","prevProps","isSelected","isAnyBlockSelected","richTextRef","blur","onUnselect","componentDidMount","innerRef","handleFocusOutside","focus","onSelect","value","onChange","plainText","html","title","onInsertBlockAfter","onUpdate","content","HTML","length","valueToInsert","firstBlock","name","attributes","slice","richText","getTitle","postType","render","placeholder","style","focusedBorderColor","borderStyle","isDimmed","globalStyles","decodedPlaceholder","borderColor","titleStyles","text","color","placeholderColor","createElement","testID","titleContainer","dimmed","accessible","accessibilityLabel","accessibilityHint","Raw","tagName","tagsToEliminate","unstableOnFocus","onBlur","multiline","fontSize","lineHeight","fontWeight","deleteEnter","onSelectionChange","onEnter","onEnterPress","disableEditingMenu","__unstableIsSelected","__unstableOnCreateUndoLevel","select","isPostTitleSelected","getEditedPostAttribute","getSelectedBlockClientId","getBlockRootClientId","getSettings","selectedId","selectionIsNested","__experimentalGlobalStylesBaseStyles","dispatch","undo","redo","togglePostTitleSelection","editPost","clearSelectedBlock","insertDefaultBlock","insertBlocks","undefined","onUndo","onRedo","blocks"],"sources":["@wordpress/editor/src/components/post-title/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { create, insert } from '@wordpress/rich-text';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { withDispatch, withSelect } from '@wordpress/data';\nimport { withFocusOutside } from '@wordpress/components';\nimport { withInstanceId, compose } from '@wordpress/compose';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { pasteHandler } from '@wordpress/blocks';\nimport { store as blockEditorStore, RichText } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nclass PostTitle extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.setRef = this.setRef.bind( this );\n\t\tthis.onPaste = this.onPaste.bind( this );\n\t}\n\tcomponentDidUpdate( prevProps ) {\n\t\t// Unselect if any other block is selected and blur the RichText.\n\t\tif (\n\t\t\tthis.props.isSelected &&\n\t\t\t! prevProps.isAnyBlockSelected &&\n\t\t\tthis.props.isAnyBlockSelected\n\t\t) {\n\t\t\tif ( this.richTextRef ) {\n\t\t\t\tthis.richTextRef.blur();\n\t\t\t}\n\t\t\tthis.props.onUnselect();\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.props.innerRef ) {\n\t\t\tthis.props.innerRef( this );\n\t\t}\n\t}\n\n\thandleFocusOutside() {\n\t\tthis.props.onUnselect();\n\t}\n\n\tfocus() {\n\t\tthis.props.onSelect();\n\t}\n\n\tonPaste( { value, onChange, plainText, html } ) {\n\t\tconst { title, onInsertBlockAfter, onUpdate } = this.props;\n\n\t\tconst content = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t} );\n\n\t\tif ( content.length ) {\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tconst valueToInsert = create( { html: content } );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else {\n\t\t\t\tconst [ firstBlock ] = content;\n\t\t\t\tif (\n\t\t\t\t\t! title &&\n\t\t\t\t\t( firstBlock.name === 'core/heading' ||\n\t\t\t\t\t\tfirstBlock.name === 'core/paragraph' )\n\t\t\t\t) {\n\t\t\t\t\tonUpdate( firstBlock.attributes.content );\n\t\t\t\t\tonInsertBlockAfter( content.slice( 1 ) );\n\t\t\t\t} else {\n\t\t\t\t\tonInsertBlockAfter( content );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tsetRef( richText ) {\n\t\tthis.richTextRef = richText;\n\t}\n\n\tgetTitle( title, postType ) {\n\t\tif ( 'page' === postType ) {\n\t\t\treturn ! title\n\t\t\t\t? /* translators: accessibility text. empty page title. */\n\t\t\t\t __( 'Page title. Empty' )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: text content of the page title. */\n\t\t\t\t\t\t__( 'Page title. %s' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t );\n\t\t}\n\n\t\treturn ! title\n\t\t\t? /* translators: accessibility text. empty post title. */\n\t\t\t __( 'Post title. Empty' )\n\t\t\t: sprintf(\n\t\t\t\t\t/* translators: accessibility text. %s: text content of the post title. */\n\t\t\t\t\t__( 'Post title. %s' ),\n\t\t\t\t\ttitle\n\t\t\t );\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tplaceholder,\n\t\t\tstyle,\n\t\t\ttitle,\n\t\t\tfocusedBorderColor,\n\t\t\tborderStyle,\n\t\t\tisDimmed,\n\t\t\tpostType,\n\t\t\tglobalStyles,\n\t\t} = this.props;\n\n\t\tconst decodedPlaceholder = decodeEntities( placeholder );\n\t\tconst borderColor = this.props.isSelected\n\t\t\t? focusedBorderColor\n\t\t\t: 'transparent';\n\t\tconst titleStyles = {\n\t\t\t...style,\n\t\t\t...( globalStyles?.text && {\n\t\t\t\tcolor: globalStyles.text,\n\t\t\t\tplaceholderColor: globalStyles.text,\n\t\t\t} ),\n\t\t};\n\n\t\treturn (\n\t\t\t<View\n\t\t\t\ttestID=\"post-title\"\n\t\t\t\tstyle={ [\n\t\t\t\t\tstyles.titleContainer,\n\t\t\t\t\tborderStyle,\n\t\t\t\t\t{ borderColor },\n\t\t\t\t\tisDimmed && styles.dimmed,\n\t\t\t\t] }\n\t\t\t\taccessible={ ! this.props.isSelected }\n\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\taccessibilityHint={ __( 'Updates the title.' ) }\n\t\t\t>\n\t\t\t\t<RichText.Raw\n\t\t\t\t\tsetRef={ this.setRef }\n\t\t\t\t\taccessibilityLabel={ this.getTitle( title, postType ) }\n\t\t\t\t\ttagName={ 'p' }\n\t\t\t\t\ttagsToEliminate={ [ 'strong' ] }\n\t\t\t\t\tunstableOnFocus={ this.props.onSelect }\n\t\t\t\t\tonBlur={ this.props.onBlur } // Always assign onBlur as a props.\n\t\t\t\t\tmultiline={ false }\n\t\t\t\t\tstyle={ titleStyles }\n\t\t\t\t\tstyles={ styles }\n\t\t\t\t\tfontSize={ 24 }\n\t\t\t\t\tlineHeight={ 1 }\n\t\t\t\t\tfontWeight={ 'bold' }\n\t\t\t\t\tdeleteEnter={ true }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tthis.props.onUpdate( value );\n\t\t\t\t\t} }\n\t\t\t\t\tonPaste={ this.onPaste }\n\t\t\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonSelectionChange={ () => {} }\n\t\t\t\t\tonEnter={ this.props.onEnterPress }\n\t\t\t\t\tdisableEditingMenu={ true }\n\t\t\t\t\t__unstableIsSelected={ this.props.isSelected }\n\t\t\t\t\t__unstableOnCreateUndoLevel={ () => {} }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t}\n}\n\nexport default compose(\n\twithSelect( ( select ) => {\n\t\tconst { isPostTitleSelected, getEditedPostAttribute } =\n\t\t\tselect( editorStore );\n\t\tconst { getSelectedBlockClientId, getBlockRootClientId, getSettings } =\n\t\t\tselect( blockEditorStore );\n\n\t\tconst selectedId = getSelectedBlockClientId();\n\t\tconst selectionIsNested = !! getBlockRootClientId( selectedId );\n\t\tconst globalStyles =\n\t\t\tgetSettings()?.__experimentalGlobalStylesBaseStyles?.color;\n\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tisAnyBlockSelected: !! selectedId,\n\t\t\tisSelected: isPostTitleSelected(),\n\t\t\tisDimmed: selectionIsNested,\n\t\t\tglobalStyles,\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { undo, redo, togglePostTitleSelection, editPost } =\n\t\t\tdispatch( editorStore );\n\n\t\tconst { clearSelectedBlock, insertDefaultBlock, insertBlocks } =\n\t\t\tdispatch( blockEditorStore );\n\n\t\treturn {\n\t\t\tonEnterPress() {\n\t\t\t\tinsertDefaultBlock( undefined, undefined, 0 );\n\t\t\t},\n\t\t\tonUndo: undo,\n\t\t\tonRedo: redo,\n\t\t\tonSelect() {\n\t\t\t\ttogglePostTitleSelection( true );\n\t\t\t\tclearSelectedBlock();\n\t\t\t},\n\t\t\tonUnselect() {\n\t\t\t\ttogglePostTitleSelection( false );\n\t\t\t},\n\t\t\tonUpdate( title ) {\n\t\t\t\teditPost( { title } );\n\t\t\t},\n\t\t\tonInsertBlockAfter( blocks ) {\n\t\t\t\tinsertBlocks( blocks, 0 );\n\t\t\t},\n\t\t};\n\t} ),\n\twithInstanceId,\n\twithFocusOutside\n)( PostTitle );\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,cAAc;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,MAAM,EAAEC,MAAM,QAAQ,sBAAsB;AACrD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,YAAY,EAAEC,UAAU,QAAQ,iBAAiB;AAC1D,SAASC,gBAAgB,QAAQ,uBAAuB;AACxD,SAASC,cAAc,EAAEC,OAAO,QAAQ,oBAAoB;AAC5D,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,KAAK,IAAIC,gBAAgB,EAAEC,QAAQ,QAAQ,yBAAyB;AAC7E,SAASF,KAAK,IAAIG,WAAW,QAAQ,mBAAmB;;AAExD;AACA;AACA;AACA,OAAOC,MAAM,MAAM,cAAc;AAEjC,MAAMC,SAAS,SAASjB,SAAS,CAAC;EACjCkB,WAAWA,CAAEC,KAAK,EAAG;IACpB,KAAK,CAAEA,KAAM,CAAC;IAEd,IAAI,CAACC,MAAM,GAAG,IAAI,CAACA,MAAM,CAACC,IAAI,CAAE,IAAK,CAAC;IACtC,IAAI,CAACC,OAAO,GAAG,IAAI,CAACA,OAAO,CAACD,IAAI,CAAE,IAAK,CAAC;EACzC;EACAE,kBAAkBA,CAAEC,SAAS,EAAG;IAC/B;IACA,IACC,IAAI,CAACL,KAAK,CAACM,UAAU,IACrB,CAAED,SAAS,CAACE,kBAAkB,IAC9B,IAAI,CAACP,KAAK,CAACO,k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AAC;IACD5D,QAAQA,CAAEF,KAAK,EAAG;MACjB+D,QAAQ,CAAE;QAAE/D;MAAM,CAAE,CAAC;IACtB,CAAC;IACDC,kBAAkBA,CAAEqE,MAAM,EAAG;MAC5BJ,YAAY,CAAEI,MAAM,EAAE,CAAE,CAAC;IAC1B;EACD,CAAC;AACF,CAAE,CAAC,EACHtG,cAAc,EACdD,gBACD,CAAC,CAAEW,SAAU,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { TextareaControl } from '@wordpress/components';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
|
+
import { useSelect } from '@wordpress/data';
|
|
14
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
15
|
+
import { useState, forwardRef } from '@wordpress/element';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
import { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';
|
|
21
|
+
import usePostTitleFocus from './use-post-title-focus';
|
|
22
|
+
import usePostTitle from './use-post-title';
|
|
23
|
+
function PostTitleRaw(_, forwardedRef) {
|
|
24
|
+
const {
|
|
25
|
+
placeholder,
|
|
26
|
+
hasFixedToolbar
|
|
27
|
+
} = useSelect(select => {
|
|
28
|
+
const {
|
|
29
|
+
getSettings
|
|
30
|
+
} = select(blockEditorStore);
|
|
31
|
+
const {
|
|
32
|
+
titlePlaceholder,
|
|
33
|
+
hasFixedToolbar: _hasFixedToolbar
|
|
34
|
+
} = getSettings();
|
|
35
|
+
return {
|
|
36
|
+
placeholder: titlePlaceholder,
|
|
37
|
+
hasFixedToolbar: _hasFixedToolbar
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
41
|
+
const {
|
|
42
|
+
title,
|
|
43
|
+
setTitle: onUpdate
|
|
44
|
+
} = usePostTitle();
|
|
45
|
+
const {
|
|
46
|
+
ref: focusRef
|
|
47
|
+
} = usePostTitleFocus(forwardedRef);
|
|
48
|
+
function onChange(value) {
|
|
49
|
+
onUpdate(value.replace(REGEXP_NEWLINES, ' '));
|
|
50
|
+
}
|
|
51
|
+
function onSelect() {
|
|
52
|
+
setIsSelected(true);
|
|
53
|
+
}
|
|
54
|
+
function onUnselect() {
|
|
55
|
+
setIsSelected(false);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The wp-block className is important for editor styles.
|
|
59
|
+
// This same block is used in both the visual and the code editor.
|
|
60
|
+
const className = classnames(DEFAULT_CLASSNAMES, {
|
|
61
|
+
'is-selected': isSelected,
|
|
62
|
+
'has-fixed-toolbar': hasFixedToolbar,
|
|
63
|
+
'is-raw-text': true
|
|
64
|
+
});
|
|
65
|
+
const decodedPlaceholder = decodeEntities(placeholder) || __('Add title');
|
|
66
|
+
return createElement(TextareaControl, {
|
|
67
|
+
ref: focusRef,
|
|
68
|
+
value: title,
|
|
69
|
+
onChange: onChange,
|
|
70
|
+
onFocus: onSelect,
|
|
71
|
+
onBlur: onUnselect,
|
|
72
|
+
label: placeholder,
|
|
73
|
+
className: className,
|
|
74
|
+
placeholder: decodedPlaceholder,
|
|
75
|
+
hideLabelFromVision: true,
|
|
76
|
+
autoComplete: "off",
|
|
77
|
+
dir: "auto",
|
|
78
|
+
rows: 1,
|
|
79
|
+
__nextHasNoMarginBottom: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export default forwardRef(PostTitleRaw);
|
|
83
|
+
//# sourceMappingURL=post-title-raw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["classnames","TextareaControl","__","decodeEntities","useSelect","store","blockEditorStore","useState","forwardRef","DEFAULT_CLASSNAMES","REGEXP_NEWLINES","usePostTitleFocus","usePostTitle","PostTitleRaw","_","forwardedRef","placeholder","hasFixedToolbar","select","getSettings","titlePlaceholder","_hasFixedToolbar","isSelected","setIsSelected","title","setTitle","onUpdate","ref","focusRef","onChange","value","replace","onSelect","onUnselect","className","decodedPlaceholder","createElement","onFocus","onBlur","label","hideLabelFromVision","autoComplete","dir","rows","__nextHasNoMarginBottom"],"sources":["@wordpress/editor/src/components/post-title/post-title-raw.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { TextareaControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';\nimport usePostTitleFocus from './use-post-title-focus';\nimport usePostTitle from './use-post-title';\n\nfunction PostTitleRaw( _, forwardedRef ) {\n\tconst { placeholder, hasFixedToolbar } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { titlePlaceholder, hasFixedToolbar: _hasFixedToolbar } =\n\t\t\tgetSettings();\n\n\t\treturn {\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t};\n\t}, [] );\n\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\n\tconst { title, setTitle: onUpdate } = usePostTitle();\n\tconst { ref: focusRef } = usePostTitleFocus( forwardedRef );\n\n\tfunction onChange( value ) {\n\t\tonUpdate( value.replace( REGEXP_NEWLINES, ' ' ) );\n\t}\n\n\tfunction onSelect() {\n\t\tsetIsSelected( true );\n\t}\n\n\tfunction onUnselect() {\n\t\tsetIsSelected( false );\n\t}\n\n\t// The wp-block className is important for editor styles.\n\t// This same block is used in both the visual and the code editor.\n\tconst className = classnames( DEFAULT_CLASSNAMES, {\n\t\t'is-selected': isSelected,\n\t\t'has-fixed-toolbar': hasFixedToolbar,\n\t\t'is-raw-text': true,\n\t} );\n\n\tconst decodedPlaceholder =\n\t\tdecodeEntities( placeholder ) || __( 'Add title' );\n\n\treturn (\n\t\t<TextareaControl\n\t\t\tref={ focusRef }\n\t\t\tvalue={ title }\n\t\t\tonChange={ onChange }\n\t\t\tonFocus={ onSelect }\n\t\t\tonBlur={ onUnselect }\n\t\t\tlabel={ placeholder }\n\t\t\tclassName={ className }\n\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\thideLabelFromVision={ true }\n\t\t\tautoComplete=\"off\"\n\t\t\tdir=\"auto\"\n\t\t\trows={ 1 }\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\nexport default forwardRef( PostTitleRaw );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,EAAEC,UAAU,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA,SAASC,kBAAkB,EAAEC,eAAe,QAAQ,aAAa;AACjE,OAAOC,iBAAiB,MAAM,wBAAwB;AACtD,OAAOC,YAAY,MAAM,kBAAkB;AAE3C,SAASC,YAAYA,CAAEC,CAAC,EAAEC,YAAY,EAAG;EACxC,MAAM;IAAEC,WAAW;IAAEC;EAAgB,CAAC,GAAGb,SAAS,CAAIc,MAAM,IAAM;IACjE,MAAM;MAAEC;IAAY,CAAC,GAAGD,MAAM,CAAEZ,gBAAiB,CAAC;IAClD,MAAM;MAAE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AClBC,GAAG,EAAC,MAAM;IACVC,IAAI,EAAG,CAAG;IACVC,uBAAuB;EAAA,CACvB,CAAC;AAEJ;AAEA,eAAepC,UAAU,CAAEK,YAAa,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useImperativeHandle, useRef } from '@wordpress/element';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as editorStore } from '../../store';
|
|
11
|
+
export default function usePostTitleFocus(forwardedRef) {
|
|
12
|
+
const ref = useRef();
|
|
13
|
+
const {
|
|
14
|
+
isCleanNewPost
|
|
15
|
+
} = useSelect(select => {
|
|
16
|
+
const {
|
|
17
|
+
isCleanNewPost: _isCleanNewPost
|
|
18
|
+
} = select(editorStore);
|
|
19
|
+
return {
|
|
20
|
+
isCleanNewPost: _isCleanNewPost()
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
24
|
+
focus: () => {
|
|
25
|
+
ref?.current?.focus();
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!ref.current) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
defaultView
|
|
34
|
+
} = ref.current.ownerDocument;
|
|
35
|
+
const {
|
|
36
|
+
name,
|
|
37
|
+
parent
|
|
38
|
+
} = defaultView;
|
|
39
|
+
const ownerDocument = name === 'editor-canvas' ? parent.document : defaultView.document;
|
|
40
|
+
const {
|
|
41
|
+
activeElement,
|
|
42
|
+
body
|
|
43
|
+
} = ownerDocument;
|
|
44
|
+
|
|
45
|
+
// Only autofocus the title when the post is entirely empty. This should
|
|
46
|
+
// only happen for a new post, which means we focus the title on new
|
|
47
|
+
// post so the author can start typing right away, without needing to
|
|
48
|
+
// click anything.
|
|
49
|
+
if (isCleanNewPost && (!activeElement || body === activeElement)) {
|
|
50
|
+
ref.current.focus();
|
|
51
|
+
}
|
|
52
|
+
}, [isCleanNewPost]);
|
|
53
|
+
return {
|
|
54
|
+
ref
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=use-post-title-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useImperativeHandle","useRef","useSelect","store","editorStore","usePostTitleFocus","forwardedRef","ref","isCleanNewPost","select","_isCleanNewPost","focus","current","defaultView","ownerDocument","name","parent","document","activeElement","body"],"sources":["@wordpress/editor/src/components/post-title/use-post-title-focus.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useImperativeHandle, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function usePostTitleFocus( forwardedRef ) {\n\tconst ref = useRef();\n\n\tconst { isCleanNewPost } = useSelect( ( select ) => {\n\t\tconst { isCleanNewPost: _isCleanNewPost } = select( editorStore );\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t};\n\t}, [] );\n\n\tuseImperativeHandle( forwardedRef, () => ( {\n\t\tfocus: () => {\n\t\t\tref?.current?.focus();\n\t\t},\n\t} ) );\n\n\tuseEffect( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { defaultView } = ref.current.ownerDocument;\n\t\tconst { name, parent } = defaultView;\n\t\tconst ownerDocument =\n\t\t\tname === 'editor-canvas' ? parent.document : defaultView.document;\n\t\tconst { activeElement, body } = ownerDocument;\n\n\t\t// Only autofocus the title when the post is entirely empty. This should\n\t\t// only happen for a new post, which means we focus the title on new\n\t\t// post so the author can start typing right away, without needing to\n\t\t// click anything.\n\t\tif ( isCleanNewPost && ( ! activeElement || body === activeElement ) ) {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