@wordpress/editor 12.5.0 → 12.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/entities-saved-states/entity-type-list.js +11 -5
- package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build/components/post-title/index.js +13 -2
- package/build/components/post-title/index.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-type-list.js +12 -6
- package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build-module/components/post-title/index.js +12 -2
- package/build-module/components/post-title/index.js.map +1 -1
- package/package.json +27 -27
- package/src/components/entities-saved-states/entity-type-list.js +15 -16
- package/src/components/post-title/index.js +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -32,13 +32,13 @@ var _entityRecordItem = _interopRequireDefault(require("./entity-record-item"));
|
|
|
32
32
|
/**
|
|
33
33
|
* Internal dependencies
|
|
34
34
|
*/
|
|
35
|
-
function getEntityDescription(entity,
|
|
35
|
+
function getEntityDescription(entity, count) {
|
|
36
36
|
switch (entity) {
|
|
37
37
|
case 'site':
|
|
38
|
-
return (0, _i18n.
|
|
38
|
+
return 1 === count ? (0, _i18n.__)('This change will affect your whole site.') : (0, _i18n.__)('These changes will affect your whole site.');
|
|
39
39
|
|
|
40
40
|
case 'wp_template':
|
|
41
|
-
return (0, _i18n.
|
|
41
|
+
return (0, _i18n.__)('This change will affect pages and posts that use this template.');
|
|
42
42
|
|
|
43
43
|
case 'page':
|
|
44
44
|
case 'post':
|
|
@@ -53,14 +53,20 @@ function EntityTypeList(_ref) {
|
|
|
53
53
|
setUnselectedEntities,
|
|
54
54
|
closePanel
|
|
55
55
|
} = _ref;
|
|
56
|
+
const count = list.length;
|
|
56
57
|
const firstRecord = list[0];
|
|
57
58
|
const entityConfig = (0, _data.useSelect)(select => select(_coreData.store).getEntityConfig(firstRecord.kind, firstRecord.name), [firstRecord.kind, firstRecord.name]);
|
|
58
59
|
const {
|
|
59
60
|
name
|
|
60
61
|
} = firstRecord;
|
|
61
|
-
|
|
62
|
+
let entityLabel = entityConfig.label;
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
if (name === 'wp_template_part') {
|
|
65
|
+
entityLabel = 1 === count ? (0, _i18n.__)('Template Part') : (0, _i18n.__)('Template Parts');
|
|
66
|
+
} // Set description based on type of entity.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const description = getEntityDescription(name, count);
|
|
64
70
|
return (0, _element.createElement)(_components.PanelBody, {
|
|
65
71
|
title: entityLabel,
|
|
66
72
|
initialOpen: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/entity-type-list.js"],"names":["getEntityDescription","entity","
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/entity-type-list.js"],"names":["getEntityDescription","entity","count","EntityTypeList","list","unselectedEntities","setUnselectedEntities","closePanel","length","firstRecord","entityConfig","select","coreStore","getEntityConfig","kind","name","entityLabel","label","description","map","record","key","property","elt","value"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAGA,SAASA,oBAAT,CAA+BC,MAA/B,EAAuCC,KAAvC,EAA+C;AAC9C,UAASD,MAAT;AACC,SAAK,MAAL;AACC,aAAO,MAAMC,KAAN,GACJ,cAAI,0CAAJ,CADI,GAEJ,cAAI,4CAAJ,CAFH;;AAGD,SAAK,aAAL;AACC,aAAO,cACN,iEADM,CAAP;;AAGD,SAAK,MAAL;AACA,SAAK,MAAL;AACC,aAAO,cAAI,0CAAJ,CAAP;AAXF;AAaA;;AAEc,SAASC,cAAT,OAKX;AAAA,MALoC;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA,kBAFuC;AAGvCC,IAAAA,qBAHuC;AAIvCC,IAAAA;AAJuC,GAKpC;AACH,QAAML,KAAK,GAAG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CAAEc,MAAF,EAAUI,KAAV,CAdvB;AAgBC,MAAA,UAAU,EAAGjB;AAhBd,MADD;AAoBA,GArBC,CAFH,CADD;AA2BA","sourcesContent":["/**\n * External dependencies\n */\nimport { some } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PanelBody, PanelRow } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport EntityRecordItem from './entity-record-item';\n\nfunction getEntityDescription( entity, count ) {\n\tswitch ( entity ) {\n\t\tcase 'site':\n\t\t\treturn 1 === count\n\t\t\t\t? __( 'This change will affect your whole site.' )\n\t\t\t\t: __( 'These changes will affect your whole site.' );\n\t\tcase 'wp_template':\n\t\t\treturn __(\n\t\t\t\t'This change will affect pages and posts that use this template.'\n\t\t\t);\n\t\tcase 'page':\n\t\tcase 'post':\n\t\t\treturn __( 'The following content has been modified.' );\n\t}\n}\n\nexport default function EntityTypeList( {\n\tlist,\n\tunselectedEntities,\n\tsetUnselectedEntities,\n\tclosePanel,\n} ) {\n\tconst count = list.length;\n\tconst firstRecord = list[ 0 ];\n\tconst entityConfig = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityConfig(\n\t\t\t\tfirstRecord.kind,\n\t\t\t\tfirstRecord.name\n\t\t\t),\n\t\t[ firstRecord.kind, firstRecord.name ]\n\t);\n\tconst { name } = firstRecord;\n\n\tlet entityLabel = entityConfig.label;\n\tif ( name === 'wp_template_part' ) {\n\t\tentityLabel =\n\t\t\t1 === count ? __( 'Template Part' ) : __( 'Template Parts' );\n\t}\n\t// Set description based on type of entity.\n\tconst description = getEntityDescription( name, count );\n\n\treturn (\n\t\t<PanelBody title={ entityLabel } initialOpen={ true }>\n\t\t\t{ description && <PanelRow>{ description }</PanelRow> }\n\t\t\t{ list.map( ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<EntityRecordItem\n\t\t\t\t\t\tkey={ record.key || record.property }\n\t\t\t\t\t\trecord={ record }\n\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t! some(\n\t\t\t\t\t\t\t\tunselectedEntities,\n\t\t\t\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\t\t\t\telt.kind === record.kind &&\n\t\t\t\t\t\t\t\t\telt.name === record.name &&\n\t\t\t\t\t\t\t\t\telt.key === record.key &&\n\t\t\t\t\t\t\t\t\telt.property === record.property\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetUnselectedEntities( record, value )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclosePanel={ closePanel }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</PanelBody>\n\t);\n}\n"]}
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = void 0;
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
@@ -48,7 +48,7 @@ var _store = require("../../store");
|
|
|
48
48
|
*/
|
|
49
49
|
const REGEXP_NEWLINES = /[\r\n]+/g;
|
|
50
50
|
|
|
51
|
-
function PostTitle() {
|
|
51
|
+
function PostTitle(_, forwardedRef) {
|
|
52
52
|
const ref = (0, _element.useRef)();
|
|
53
53
|
const [isSelected, setIsSelected] = (0, _element.useState)(false);
|
|
54
54
|
const {
|
|
@@ -86,6 +86,13 @@ function PostTitle() {
|
|
|
86
86
|
hasFixedToolbar: _hasFixedToolbar
|
|
87
87
|
};
|
|
88
88
|
}, []);
|
|
89
|
+
(0, _element.useImperativeHandle)(forwardedRef, () => ({
|
|
90
|
+
focus: () => {
|
|
91
|
+
var _ref$current;
|
|
92
|
+
|
|
93
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
89
96
|
(0, _element.useEffect)(() => {
|
|
90
97
|
if (!ref.current) {
|
|
91
98
|
return;
|
|
@@ -243,4 +250,8 @@ function PostTitle() {
|
|
|
243
250
|
}));
|
|
244
251
|
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
245
252
|
}
|
|
253
|
+
|
|
254
|
+
var _default = (0, _element.forwardRef)(PostTitle);
|
|
255
|
+
|
|
256
|
+
exports.default = _default;
|
|
246
257
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-title/index.js"],"names":["REGEXP_NEWLINES","PostTitle","ref","isSelected","setIsSelected","editPost","editorStore","insertDefaultBlock","clearSelectedBlock","insertBlocks","blockEditorStore","isCleanNewPost","title","placeholder","isFocusMode","hasFixedToolbar","select","getEditedPostAttribute","_isCleanNewPost","getSettings","titlePlaceholder","focusMode","_hasFixedToolbar","current","ownerDocument","activeElement","body","focus","onEnterPress","undefined","onInsertBlockAfter","blocks","onUpdate","newTitle","selection","setSelection","onSelect","onUnselect","onChange","value","replace","onKeyDown","event","keyCode","ENTER","preventDefault","onPaste","clipboardData","plainText","html","getData","error1","error2","window","console","log","content","HTML","length","firstBlock","name","attributes","slice","className","decodedPlaceholder","richTextRef","selectionStart","start","selectionEnd","end","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","preserveWhiteSpace"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAtBA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,UAAxB;;AAEe,SAASC,SAAT,GAAqB;AACnC,QAAM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import { __ } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } 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 { __unstableUseRichText as useRichText } from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\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\nexport default function PostTitle() {\n\tconst ref = useRef();\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\tconst { editPost } = useDispatch( editorStore );\n\tconst {\n\t\tinsertDefaultBlock,\n\t\tclearSelectedBlock,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisCleanNewPost,\n\t\ttitle,\n\t\tplaceholder,\n\t\tisFocusMode,\n\t\thasFixedToolbar,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tisCleanNewPost: _isCleanNewPost,\n\t\t} = select( editorStore );\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst {\n\t\t\ttitlePlaceholder,\n\t\t\tfocusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t} = getSettings();\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\tisFocusMode: focusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerDocument } = ref.current;\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\tif ( typeof content !== 'string' && content.length ) {\n\t\t\tevent.preventDefault();\n\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( 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}\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'is-focus-mode': isFocusMode,\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-title/index.js"],"names":["REGEXP_NEWLINES","PostTitle","_","forwardedRef","ref","isSelected","setIsSelected","editPost","editorStore","insertDefaultBlock","clearSelectedBlock","insertBlocks","blockEditorStore","isCleanNewPost","title","placeholder","isFocusMode","hasFixedToolbar","select","getEditedPostAttribute","_isCleanNewPost","getSettings","titlePlaceholder","focusMode","_hasFixedToolbar","focus","current","ownerDocument","activeElement","body","onEnterPress","undefined","onInsertBlockAfter","blocks","onUpdate","newTitle","selection","setSelection","onSelect","onUnselect","onChange","value","replace","onKeyDown","event","keyCode","ENTER","preventDefault","onPaste","clipboardData","plainText","html","getData","error1","error2","window","console","log","content","HTML","length","firstBlock","name","attributes","slice","className","decodedPlaceholder","richTextRef","selectionStart","start","selectionEnd","end","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","preserveWhiteSpace"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AA5BA;AACA;AACA;;AAGA;AACA;AACA;;AAiBA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,UAAxB;;AAEA,SAASC,SAAT,CAAoBC,CA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AAO,EAAG5B,QAPX;AAQC,IAAA,MAAM,EAAGC,UARV;AASC,IAAA,SAAS,EAAGI,SATb;AAUC,IAAA,UAAU,EAAGJ,UAVd;AAWC,IAAA,OAAO,EAAGS;AAXX,IADD,CADD;AAiBA;AACA;;eAEc,yBAAY/C,SAAZ,C","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 { __unstableUseRichText as useRichText } from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\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 {\n\t\tinsertDefaultBlock,\n\t\tclearSelectedBlock,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisCleanNewPost,\n\t\ttitle,\n\t\tplaceholder,\n\t\tisFocusMode,\n\t\thasFixedToolbar,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tisCleanNewPost: _isCleanNewPost,\n\t\t} = select( editorStore );\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst {\n\t\t\ttitlePlaceholder,\n\t\t\tfocusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t} = getSettings();\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\tisFocusMode: focusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\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 { ownerDocument } = ref.current;\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\tif ( typeof content !== 'string' && content.length ) {\n\t\t\tevent.preventDefault();\n\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( 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}\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'is-focus-mode': isFocusMode,\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"]}
|
|
@@ -8,7 +8,7 @@ import { some } from 'lodash';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { __
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
12
|
import { useSelect } from '@wordpress/data';
|
|
13
13
|
import { PanelBody, PanelRow } from '@wordpress/components';
|
|
14
14
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -18,13 +18,13 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
18
18
|
|
|
19
19
|
import EntityRecordItem from './entity-record-item';
|
|
20
20
|
|
|
21
|
-
function getEntityDescription(entity,
|
|
21
|
+
function getEntityDescription(entity, count) {
|
|
22
22
|
switch (entity) {
|
|
23
23
|
case 'site':
|
|
24
|
-
return
|
|
24
|
+
return 1 === count ? __('This change will affect your whole site.') : __('These changes will affect your whole site.');
|
|
25
25
|
|
|
26
26
|
case 'wp_template':
|
|
27
|
-
return
|
|
27
|
+
return __('This change will affect pages and posts that use this template.');
|
|
28
28
|
|
|
29
29
|
case 'page':
|
|
30
30
|
case 'post':
|
|
@@ -39,14 +39,20 @@ export default function EntityTypeList(_ref) {
|
|
|
39
39
|
setUnselectedEntities,
|
|
40
40
|
closePanel
|
|
41
41
|
} = _ref;
|
|
42
|
+
const count = list.length;
|
|
42
43
|
const firstRecord = list[0];
|
|
43
44
|
const entityConfig = useSelect(select => select(coreStore).getEntityConfig(firstRecord.kind, firstRecord.name), [firstRecord.kind, firstRecord.name]);
|
|
44
45
|
const {
|
|
45
46
|
name
|
|
46
47
|
} = firstRecord;
|
|
47
|
-
|
|
48
|
+
let entityLabel = entityConfig.label;
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
if (name === 'wp_template_part') {
|
|
51
|
+
entityLabel = 1 === count ? __('Template Part') : __('Template Parts');
|
|
52
|
+
} // Set description based on type of entity.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const description = getEntityDescription(name, count);
|
|
50
56
|
return createElement(PanelBody, {
|
|
51
57
|
title: entityLabel,
|
|
52
58
|
initialOpen: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/entity-type-list.js"],"names":["some","__","
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/entities-saved-states/entity-type-list.js"],"names":["some","__","useSelect","PanelBody","PanelRow","store","coreStore","EntityRecordItem","getEntityDescription","entity","count","EntityTypeList","list","unselectedEntities","setUnselectedEntities","closePanel","length","firstRecord","entityConfig","select","getEntityConfig","kind","name","entityLabel","label","description","map","record","key","property","elt","value"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,uBAApC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;;AAEA,SAASC,oBAAT,CAA+BC,MAA/B,EAAuCC,KAAvC,EAA+C;AAC9C,UAASD,MAAT;AACC,SAAK,MAAL;AACC,aAAO,MAAMC,KAAN,GACJT,EAAE,CAAE,0CAAF,CADE,GAEJA,EAAE,CAAE,4CAAF,CAFL;;AAGD,SAAK,aAAL;AACC,aAAOA,EAAE,CACR,iEADQ,CAAT;;AAGD,SAAK,MAAL;AACA,SAAK,MAAL;AACC,aAAOA,EAAE,CAAE,0CAAF,CAAT;AAXF;AAaA;;AAED,eAAe,SAASU,cAAT,OAKX;AAAA,MALoC;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA,kBAFuC;AAGvCC,IAAAA,qBAHuC;AAIvCC,IAAAA;AAJuC,GAKpC;AACH,QAAML,KAAK,GAAGE,IAAI,CAACI,MAAnB;AACA,QAAMC,WAAW,GAAGL,IAAI,CAAE,CAAF,CAAxB;AACA,QAAMM,YAAY,GAAGhB,SAAS,CAC3BiB,MAAF,IACCA,MAAM,CAAEb,SAAF,CAAN,CAAoBc,eAApB,CACCH,WAAW,CAACI,IADb,EAECJ,WAAW,CAACK,IAFb,CAF4B,EAM7B,CAAEL,WAAW,CAACI,IAAd,EAAoBJ,WAAW,CAACK,IAAhC,CAN6B,CAA9B;AAQA,QAAM;AAAEA,IAAAA;AAAF,MAAWL,WAAjB;AAEA,MAAIM,WAAW,GAAGL,YAAY,CAACM,KAA/B;;AACA,MAAKF,IAAI,KAAK,kBAAd,EAAmC;AAClCC,IAAAA,WAAW,GACV,MAAMb,KAAN,GAAcT,EAAE,CAAE,eAAF,CAAhB,GAAsCA,EAAE,CAAE,gBAAF,CADzC;AAEA,GAjBE,CAkBH;;;AACA,QAAMwB,WAAW,GAAGjB,oBAAoB,CAAEc,IAAF,EAAQZ,KAAR,CAAxC;AAEA,SACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGa,WAAnB;AAAiC,IAAA,WAAW,EAAG;AAA/C,KACGE,WAAW,IAAI,cAAC,QAAD,QAAYA,WAAZ,CADlB,EAEGb,IAAI,CAACc,GAAL,CAAYC,MAAF,IAAc;AACzB,WACC,cAAC,gBAAD;AACC,MAAA,GAAG,EAAGA,MAAM,CAACC,GAAP,IAAcD,MAAM,CAACE,QAD5B;AAEC,MAAA,MAAM,EAAGF,MAFV;AAGC,MAAA,OAAO,EACN,CAAE3B,IAAI,CACLa,kBADK,EAEHiB,GAAF,IACCA,GAAG,CAACT,IAAJ,KAAaM,MAAM,CAACN,IAApB,IACAS,GAAG,CAACR,IAAJ,KAAaK,MAAM,CAACL,IADpB,IAEAQ,GAAG,CAACF,GAAJ,KAAYD,MAAM,CAACC,GAFnB,IAGAE,GAAG,CAACD,QAAJ,KAAiBF,MAAM,CAACE,QANpB,CAJR;AAaC,MAAA,QAAQ,EAAKE,KAAF,IACVjB,qBAAqB,CAAEa,MAAF,EAAUI,KAAV,CAdvB;AAgBC,MAAA,UAAU,EAAGhB;AAhBd,MADD;AAoBA,GArBC,CAFH,CADD;AA2BA","sourcesContent":["/**\n * External dependencies\n */\nimport { some } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PanelBody, PanelRow } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport EntityRecordItem from './entity-record-item';\n\nfunction getEntityDescription( entity, count ) {\n\tswitch ( entity ) {\n\t\tcase 'site':\n\t\t\treturn 1 === count\n\t\t\t\t? __( 'This change will affect your whole site.' )\n\t\t\t\t: __( 'These changes will affect your whole site.' );\n\t\tcase 'wp_template':\n\t\t\treturn __(\n\t\t\t\t'This change will affect pages and posts that use this template.'\n\t\t\t);\n\t\tcase 'page':\n\t\tcase 'post':\n\t\t\treturn __( 'The following content has been modified.' );\n\t}\n}\n\nexport default function EntityTypeList( {\n\tlist,\n\tunselectedEntities,\n\tsetUnselectedEntities,\n\tclosePanel,\n} ) {\n\tconst count = list.length;\n\tconst firstRecord = list[ 0 ];\n\tconst entityConfig = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityConfig(\n\t\t\t\tfirstRecord.kind,\n\t\t\t\tfirstRecord.name\n\t\t\t),\n\t\t[ firstRecord.kind, firstRecord.name ]\n\t);\n\tconst { name } = firstRecord;\n\n\tlet entityLabel = entityConfig.label;\n\tif ( name === 'wp_template_part' ) {\n\t\tentityLabel =\n\t\t\t1 === count ? __( 'Template Part' ) : __( 'Template Parts' );\n\t}\n\t// Set description based on type of entity.\n\tconst description = getEntityDescription( name, count );\n\n\treturn (\n\t\t<PanelBody title={ entityLabel } initialOpen={ true }>\n\t\t\t{ description && <PanelRow>{ description }</PanelRow> }\n\t\t\t{ list.map( ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<EntityRecordItem\n\t\t\t\t\t\tkey={ record.key || record.property }\n\t\t\t\t\t\trecord={ record }\n\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t! some(\n\t\t\t\t\t\t\t\tunselectedEntities,\n\t\t\t\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\t\t\t\telt.kind === record.kind &&\n\t\t\t\t\t\t\t\t\telt.name === record.name &&\n\t\t\t\t\t\t\t\t\telt.key === record.key &&\n\t\t\t\t\t\t\t\t\telt.property === record.property\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetUnselectedEntities( record, value )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclosePanel={ closePanel }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</PanelBody>\n\t);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import classnames from 'classnames';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
|
-
import { useEffect, useRef, useState } from '@wordpress/element';
|
|
12
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@wordpress/element';
|
|
13
13
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
14
14
|
import { ENTER } from '@wordpress/keycodes';
|
|
15
15
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
@@ -28,7 +28,8 @@ import { store as editorStore } from '../../store';
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
const REGEXP_NEWLINES = /[\r\n]+/g;
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
function PostTitle(_, forwardedRef) {
|
|
32
33
|
const ref = useRef();
|
|
33
34
|
const [isSelected, setIsSelected] = useState(false);
|
|
34
35
|
const {
|
|
@@ -66,6 +67,13 @@ export default function PostTitle() {
|
|
|
66
67
|
hasFixedToolbar: _hasFixedToolbar
|
|
67
68
|
};
|
|
68
69
|
}, []);
|
|
70
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
71
|
+
focus: () => {
|
|
72
|
+
var _ref$current;
|
|
73
|
+
|
|
74
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
69
77
|
useEffect(() => {
|
|
70
78
|
if (!ref.current) {
|
|
71
79
|
return;
|
|
@@ -225,4 +233,6 @@ export default function PostTitle() {
|
|
|
225
233
|
}));
|
|
226
234
|
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
227
235
|
}
|
|
236
|
+
|
|
237
|
+
export default forwardRef(PostTitle);
|
|
228
238
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-title/index.js"],"names":["classnames","__","useEffect","useRef","useState","decodeEntities","ENTER","useSelect","useDispatch","pasteHandler","store","blockEditorStore","__unstableUseRichText","useRichText","useMergeRefs","PostTypeSupportCheck","editorStore","REGEXP_NEWLINES","PostTitle","ref","isSelected","setIsSelected","editPost","insertDefaultBlock","clearSelectedBlock","insertBlocks","isCleanNewPost","title","placeholder","isFocusMode","hasFixedToolbar","select","getEditedPostAttribute","_isCleanNewPost","getSettings","titlePlaceholder","focusMode","_hasFixedToolbar","current","ownerDocument","activeElement","body","focus","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","name","attributes","slice","className","decodedPlaceholder","richTextRef","selectionStart","start","selectionEnd","end","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","preserveWhiteSpace"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,oBAA5C;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,sBAArD;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,4BAAjC;AACA,SAASL,KAAK,IAAIM,WAA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IAAA,OAAO,EAAG3B,QAPX;AAQC,IAAA,MAAM,EAAGC,UARV;AASC,IAAA,SAAS,EAAGI,SATb;AAUC,IAAA,UAAU,EAAGJ,UAVd;AAWC,IAAA,OAAO,EAAGQ;AAXX,IADD,CADD;AAiBA;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } 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 { __unstableUseRichText as useRichText } from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\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\nexport default function PostTitle() {\n\tconst ref = useRef();\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\tconst { editPost } = useDispatch( editorStore );\n\tconst {\n\t\tinsertDefaultBlock,\n\t\tclearSelectedBlock,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisCleanNewPost,\n\t\ttitle,\n\t\tplaceholder,\n\t\tisFocusMode,\n\t\thasFixedToolbar,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tisCleanNewPost: _isCleanNewPost,\n\t\t} = select( editorStore );\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst {\n\t\t\ttitlePlaceholder,\n\t\t\tfocusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t} = getSettings();\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\tisFocusMode: focusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerDocument } = ref.current;\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\tif ( typeof content !== 'string' && content.length ) {\n\t\t\tevent.preventDefault();\n\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( 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}\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'is-focus-mode': isFocusMode,\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-title/index.js"],"names":["classnames","__","forwardRef","useEffect","useImperativeHandle","useRef","useState","decodeEntities","ENTER","useSelect","useDispatch","pasteHandler","store","blockEditorStore","__unstableUseRichText","useRichText","useMergeRefs","PostTypeSupportCheck","editorStore","REGEXP_NEWLINES","PostTitle","_","forwardedRef","ref","isSelected","setIsSelected","editPost","insertDefaultBlock","clearSelectedBlock","insertBlocks","isCleanNewPost","title","placeholder","isFocusMode","hasFixedToolbar","select","getEditedPostAttribute","_isCleanNewPost","getSettings","titlePlaceholder","focusMode","_hasFixedToolbar","focus","current","ownerDocument","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","name","attributes","slice","className","decodedPlaceholder","richTextRef","selectionStart","start","selectionEnd","end","onSelectionChange","newStart","newEnd","sel","__unstableDisableFormats","preserveWhiteSpace"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,UADD,EAECC,SAFD,EAGCC,mBAHD,EAICC,MAJD,EAKCC,QALD,QAMO,oBANP;AAOA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,sBAArD;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,4BAAjC;AACA,SAASL,KAAK,IAAIM,WAAlB,QAAqC,aAArC;AAEA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,UAAxB;;AAEA,SAASC,SAAT,CAAoBC,CAApB,EAAuBC,YAAvB,EAAsC;AACrC,QAAMC,GAAG,GAAGlB,MAAM,EAAlB;AACA,QAAM,CAAEmB,UAAF,EAAcC,aAAd,IAAgCnB,QAAQ,CAAE,KAAF,CAA9C;AACA,QAAM;AAAEoB,IAAAA;AAAF,MAAehB,WAAW,CAAEQ,WAAF,CAAhC;AACA,QAAM;AACLS,IAAAA,kBADK;AAELC,IAAAA,kBAFK;AAGLC,IAAAA;AAHK,MAIFnB,WAAW,CAAEG,gBAAF,CAJf;AAKA,QAAM;AACLiB,IAAAA,cADK;AAELC,IAAAA,KAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA,WAJK;AAKLC,IAAAA;AALK,MAMFzB,SAAS,CAAI0B,MAAF,IAAc;AAC5B,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AAEzC0B,IAAAA,QAFyC;AAGzCzB,IAAAA,WAAW,EAAEkD,kBAH4B;AAIzCE,IAAAA,cAAc,EAAE/B,SAAS,CAACgC,KAJe;AAKzCC,IAAAA,YAAY,EAAEjC,SAAS,CAACkC,GALiB;;AAMzCC,IAAAA,iBAAiB,CAAEC,QAAF,EAAYC,MAAZ,EAAqB;AACrCpC,MAAAA,YAAY,CAAIqC,GAAF,IAAW;AACxB,cAAM;AAAEN,UAAAA,KAAF;AAASE,UAAAA;AAAT,YAAiBI,GAAvB;;AACA,YAAKN,KAAK,KAAKI,QAAV,IAAsBF,GAAG,KAAKG,MAAnC,EAA4C;AAC3C,iBAAOC,GAAP;AACA;;AACD,eAAO;AACNN,UAAAA,KAAK,EAAEI,QADD;AAENF,UAAAA,GAAG,EAAEG;AAFC,SAAP;AAIA,OATW,CAAZ;AAUA,KAjBwC;;AAkBzCE,IAAAA,wBAAwB,EAAE,IAlBe;AAmBzCC,IAAAA,kBAAkB,EAAE;AAnBqB,GAAF,CAAxC;AAsBA;;AACA,SACC,cAAC,oBAAD;AAAsB,IAAA,WAAW,EAAC;AAAlC,KACC;AACC,IAAA,GAAG,EAAG7E,YAAY,CAAE,CAAEmE,WAAF,EAAe5D,GAAf,CAAF,CADnB;AAEC,IAAA,eAAe,MAFhB;AAGC,IAAA,SAAS,EAAG0D,SAHb;AAIC,kBAAaC,kBAJd;AAKC,IAAA,IAAI,EAAC,SALN;AAMC,sBAAe,MANhB;AAOC,IAAA,OAAO,EAAG3B,QAPX;AAQC,IAAA,MAAM,EAAGC,UARV;AASC,IAAA,SAAS,EAAGI,SATb;AAUC,IAAA,UAAU,EAAGJ,UAVd;AAWC,IAAA,OAAO,EAAGQ;AAXX,IADD,CADD;AAiBA;AACA;;AAED,eAAe9D,UAAU,CAAEkB,SAAF,CAAzB","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 { __unstableUseRichText as useRichText } from '@wordpress/rich-text';\nimport { useMergeRefs } from '@wordpress/compose';\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 {\n\t\tinsertDefaultBlock,\n\t\tclearSelectedBlock,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisCleanNewPost,\n\t\ttitle,\n\t\tplaceholder,\n\t\tisFocusMode,\n\t\thasFixedToolbar,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tisCleanNewPost: _isCleanNewPost,\n\t\t} = select( editorStore );\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst {\n\t\t\ttitlePlaceholder,\n\t\t\tfocusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\n\t\t} = getSettings();\n\n\t\treturn {\n\t\t\tisCleanNewPost: _isCleanNewPost(),\n\t\t\ttitle: getEditedPostAttribute( 'title' ),\n\t\t\tplaceholder: titlePlaceholder,\n\t\t\tisFocusMode: focusMode,\n\t\t\thasFixedToolbar: _hasFixedToolbar,\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 { ownerDocument } = ref.current;\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\tif ( typeof content !== 'string' && content.length ) {\n\t\t\tevent.preventDefault();\n\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( 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}\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'is-focus-mode': isFocusMode,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.0",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,31 +31,31 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/a11y": "^3.
|
|
35
|
-
"@wordpress/api-fetch": "^6.
|
|
36
|
-
"@wordpress/block-editor": "^8.
|
|
37
|
-
"@wordpress/blocks": "^11.
|
|
38
|
-
"@wordpress/components": "^19.
|
|
39
|
-
"@wordpress/compose": "^5.
|
|
40
|
-
"@wordpress/core-data": "^4.
|
|
41
|
-
"@wordpress/data": "^6.
|
|
42
|
-
"@wordpress/date": "^4.
|
|
43
|
-
"@wordpress/deprecated": "^3.
|
|
44
|
-
"@wordpress/element": "^4.
|
|
45
|
-
"@wordpress/hooks": "^3.
|
|
46
|
-
"@wordpress/html-entities": "^3.
|
|
47
|
-
"@wordpress/i18n": "^4.
|
|
48
|
-
"@wordpress/icons": "^8.
|
|
49
|
-
"@wordpress/keyboard-shortcuts": "^3.
|
|
50
|
-
"@wordpress/keycodes": "^3.
|
|
51
|
-
"@wordpress/media-utils": "^3.
|
|
52
|
-
"@wordpress/notices": "^3.
|
|
53
|
-
"@wordpress/preferences": "^1.
|
|
54
|
-
"@wordpress/reusable-blocks": "^3.
|
|
55
|
-
"@wordpress/rich-text": "^5.
|
|
56
|
-
"@wordpress/server-side-render": "^3.
|
|
57
|
-
"@wordpress/url": "^3.
|
|
58
|
-
"@wordpress/wordcount": "^3.
|
|
34
|
+
"@wordpress/a11y": "^3.7.0",
|
|
35
|
+
"@wordpress/api-fetch": "^6.4.0",
|
|
36
|
+
"@wordpress/block-editor": "^8.6.0",
|
|
37
|
+
"@wordpress/blocks": "^11.6.0",
|
|
38
|
+
"@wordpress/components": "^19.9.0",
|
|
39
|
+
"@wordpress/compose": "^5.5.0",
|
|
40
|
+
"@wordpress/core-data": "^4.5.0",
|
|
41
|
+
"@wordpress/data": "^6.7.0",
|
|
42
|
+
"@wordpress/date": "^4.7.0",
|
|
43
|
+
"@wordpress/deprecated": "^3.7.0",
|
|
44
|
+
"@wordpress/element": "^4.5.0",
|
|
45
|
+
"@wordpress/hooks": "^3.7.0",
|
|
46
|
+
"@wordpress/html-entities": "^3.7.0",
|
|
47
|
+
"@wordpress/i18n": "^4.7.0",
|
|
48
|
+
"@wordpress/icons": "^8.3.0",
|
|
49
|
+
"@wordpress/keyboard-shortcuts": "^3.5.0",
|
|
50
|
+
"@wordpress/keycodes": "^3.7.0",
|
|
51
|
+
"@wordpress/media-utils": "^3.5.0",
|
|
52
|
+
"@wordpress/notices": "^3.7.0",
|
|
53
|
+
"@wordpress/preferences": "^1.3.0",
|
|
54
|
+
"@wordpress/reusable-blocks": "^3.5.0",
|
|
55
|
+
"@wordpress/rich-text": "^5.5.0",
|
|
56
|
+
"@wordpress/server-side-render": "^3.5.0",
|
|
57
|
+
"@wordpress/url": "^3.8.0",
|
|
58
|
+
"@wordpress/wordcount": "^3.7.0",
|
|
59
59
|
"classnames": "^2.3.1",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"memize": "^1.1.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "1ba52312b56db563df2d8d4fba5b00613fb46d8c"
|
|
73
73
|
}
|
|
@@ -6,7 +6,7 @@ import { some } from 'lodash';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { __
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
10
|
import { useSelect } from '@wordpress/data';
|
|
11
11
|
import { PanelBody, PanelRow } from '@wordpress/components';
|
|
12
12
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -16,19 +16,15 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
16
16
|
*/
|
|
17
17
|
import EntityRecordItem from './entity-record-item';
|
|
18
18
|
|
|
19
|
-
function getEntityDescription( entity,
|
|
19
|
+
function getEntityDescription( entity, count ) {
|
|
20
20
|
switch ( entity ) {
|
|
21
21
|
case 'site':
|
|
22
|
-
return
|
|
23
|
-
'This change will affect your whole site.'
|
|
24
|
-
'These changes will affect your whole site.'
|
|
25
|
-
length
|
|
26
|
-
);
|
|
22
|
+
return 1 === count
|
|
23
|
+
? __( 'This change will affect your whole site.' )
|
|
24
|
+
: __( 'These changes will affect your whole site.' );
|
|
27
25
|
case 'wp_template':
|
|
28
|
-
return
|
|
29
|
-
'This change will affect pages and posts that use this template.'
|
|
30
|
-
'These changes will affect pages and posts that use these templates.',
|
|
31
|
-
length
|
|
26
|
+
return __(
|
|
27
|
+
'This change will affect pages and posts that use this template.'
|
|
32
28
|
);
|
|
33
29
|
case 'page':
|
|
34
30
|
case 'post':
|
|
@@ -42,6 +38,7 @@ export default function EntityTypeList( {
|
|
|
42
38
|
setUnselectedEntities,
|
|
43
39
|
closePanel,
|
|
44
40
|
} ) {
|
|
41
|
+
const count = list.length;
|
|
45
42
|
const firstRecord = list[ 0 ];
|
|
46
43
|
const entityConfig = useSelect(
|
|
47
44
|
( select ) =>
|
|
@@ -52,12 +49,14 @@ export default function EntityTypeList( {
|
|
|
52
49
|
[ firstRecord.kind, firstRecord.name ]
|
|
53
50
|
);
|
|
54
51
|
const { name } = firstRecord;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
|
|
53
|
+
let entityLabel = entityConfig.label;
|
|
54
|
+
if ( name === 'wp_template_part' ) {
|
|
55
|
+
entityLabel =
|
|
56
|
+
1 === count ? __( 'Template Part' ) : __( 'Template Parts' );
|
|
57
|
+
}
|
|
59
58
|
// Set description based on type of entity.
|
|
60
|
-
const description = getEntityDescription( name,
|
|
59
|
+
const description = getEntityDescription( name, count );
|
|
61
60
|
|
|
62
61
|
return (
|
|
63
62
|
<PanelBody title={ entityLabel } initialOpen={ true }>
|
|
@@ -7,7 +7,13 @@ import classnames from 'classnames';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
forwardRef,
|
|
12
|
+
useEffect,
|
|
13
|
+
useImperativeHandle,
|
|
14
|
+
useRef,
|
|
15
|
+
useState,
|
|
16
|
+
} from '@wordpress/element';
|
|
11
17
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
12
18
|
import { ENTER } from '@wordpress/keycodes';
|
|
13
19
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
@@ -27,7 +33,7 @@ import { store as editorStore } from '../../store';
|
|
|
27
33
|
*/
|
|
28
34
|
const REGEXP_NEWLINES = /[\r\n]+/g;
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
function PostTitle( _, forwardedRef ) {
|
|
31
37
|
const ref = useRef();
|
|
32
38
|
const [ isSelected, setIsSelected ] = useState( false );
|
|
33
39
|
const { editPost } = useDispatch( editorStore );
|
|
@@ -63,6 +69,12 @@ export default function PostTitle() {
|
|
|
63
69
|
};
|
|
64
70
|
}, [] );
|
|
65
71
|
|
|
72
|
+
useImperativeHandle( forwardedRef, () => ( {
|
|
73
|
+
focus: () => {
|
|
74
|
+
ref?.current?.focus();
|
|
75
|
+
},
|
|
76
|
+
} ) );
|
|
77
|
+
|
|
66
78
|
useEffect( () => {
|
|
67
79
|
if ( ! ref.current ) {
|
|
68
80
|
return;
|
|
@@ -219,3 +231,5 @@ export default function PostTitle() {
|
|
|
219
231
|
);
|
|
220
232
|
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
|
|
221
233
|
}
|
|
234
|
+
|
|
235
|
+
export default forwardRef( PostTitle );
|