@wordpress/block-editor 12.10.9 → 12.10.11
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/build/components/block-rename/index.js +28 -0
- package/build/components/block-rename/index.js.map +1 -0
- package/build/components/block-rename/is-empty-string.js +10 -0
- package/build/components/block-rename/is-empty-string.js.map +1 -0
- package/build/components/block-rename/modal.js +86 -0
- package/build/components/block-rename/modal.js.map +1 -0
- package/build/components/block-rename/rename-control.js +73 -0
- package/build/components/block-rename/rename-control.js.map +1 -0
- package/build/components/block-rename/use-block-rename.js +19 -0
- package/build/components/block-rename/use-block-rename.js.map +1 -0
- package/build/components/block-settings-menu-controls/index.js +7 -0
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +2 -2
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/use-block-commands/index.js +6 -1
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/hooks/block-rename.js +51 -0
- package/build/hooks/block-rename.js.map +1 -0
- package/build/hooks/index.js +1 -1
- package/build/hooks/index.js.map +1 -1
- package/build-module/components/block-rename/index.js +4 -0
- package/build-module/components/block-rename/index.js.map +1 -0
- package/build-module/components/block-rename/is-empty-string.js +4 -0
- package/build-module/components/block-rename/is-empty-string.js.map +1 -0
- package/build-module/components/block-rename/modal.js +79 -0
- package/build-module/components/block-rename/modal.js.map +1 -0
- package/build-module/components/block-rename/rename-control.js +66 -0
- package/build-module/components/block-rename/rename-control.js.map +1 -0
- package/build-module/components/block-rename/use-block-rename.js +12 -0
- package/build-module/components/block-rename/use-block-rename.js.map +1 -0
- package/build-module/components/block-settings-menu-controls/index.js +7 -0
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +2 -2
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +5 -1
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/hooks/block-rename.js +43 -0
- package/build-module/hooks/block-rename.js.map +1 -0
- package/build-module/hooks/index.js +1 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-style/style-rtl.css +4 -4
- package/build-style/style.css +4 -4
- package/package.json +32 -32
- package/src/components/block-rename/index.js +3 -0
- package/src/components/block-rename/is-empty-string.js +3 -0
- package/src/components/block-rename/modal.js +115 -0
- package/src/components/block-rename/rename-control.js +80 -0
- package/src/components/block-rename/use-block-rename.js +20 -0
- package/src/components/block-settings-menu-controls/index.js +9 -0
- package/src/components/global-styles/image-settings-panel.js +2 -2
- package/src/components/use-block-commands/index.js +2 -1
- package/src/hooks/block-rename.js +52 -0
- package/src/hooks/index.js +1 -1
- package/src/style.scss +1 -1
- package/build/hooks/block-rename-ui.js +0 -164
- package/build/hooks/block-rename-ui.js.map +0 -1
- package/build-module/hooks/block-rename-ui.js +0 -157
- package/build-module/hooks/block-rename-ui.js.map +0 -1
- package/src/hooks/block-rename-ui.js +0 -235
- /package/src/{hooks/block-rename-ui.scss → components/block-rename/style.scss} +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
/**
|
|
3
|
-
* WordPress dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
|
|
6
|
-
import { addFilter } from '@wordpress/hooks';
|
|
7
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
8
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
9
|
-
import { MenuItem, __experimentalHStack as HStack, __experimentalVStack as VStack, Button, TextControl, Modal } from '@wordpress/components';
|
|
10
|
-
import { useState } from '@wordpress/element';
|
|
11
|
-
import { speak } from '@wordpress/a11y';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { BlockSettingsMenuControls, useBlockDisplayInformation, InspectorControls } from '../components';
|
|
17
|
-
const emptyString = testString => testString?.trim()?.length === 0;
|
|
18
|
-
function RenameModal({
|
|
19
|
-
blockName,
|
|
20
|
-
originalBlockName,
|
|
21
|
-
onClose,
|
|
22
|
-
onSave
|
|
23
|
-
}) {
|
|
24
|
-
const [editedBlockName, setEditedBlockName] = useState(blockName);
|
|
25
|
-
const nameHasChanged = editedBlockName !== blockName;
|
|
26
|
-
const nameIsOriginal = editedBlockName === originalBlockName;
|
|
27
|
-
const nameIsEmpty = emptyString(editedBlockName);
|
|
28
|
-
const isNameValid = nameHasChanged || nameIsOriginal;
|
|
29
|
-
const autoSelectInputText = event => event.target.select();
|
|
30
|
-
const dialogDescription = useInstanceId(RenameModal, `block-editor-rename-modal__description`);
|
|
31
|
-
const handleSubmit = () => {
|
|
32
|
-
const message = nameIsOriginal || nameIsEmpty ? sprintf( /* translators: %s: new name/label for the block */
|
|
33
|
-
__('Block name reset to: "%s".'), editedBlockName) : sprintf( /* translators: %s: new name/label for the block */
|
|
34
|
-
__('Block name changed to: "%s".'), editedBlockName);
|
|
35
|
-
|
|
36
|
-
// Must be assertive to immediately announce change.
|
|
37
|
-
speak(message, 'assertive');
|
|
38
|
-
onSave(editedBlockName);
|
|
39
|
-
|
|
40
|
-
// Immediate close avoids ability to hit save multiple times.
|
|
41
|
-
onClose();
|
|
42
|
-
};
|
|
43
|
-
return createElement(Modal, {
|
|
44
|
-
title: __('Rename'),
|
|
45
|
-
onRequestClose: onClose,
|
|
46
|
-
overlayClassName: "block-editor-block-rename-modal",
|
|
47
|
-
aria: {
|
|
48
|
-
describedby: dialogDescription
|
|
49
|
-
},
|
|
50
|
-
focusOnMount: "firstContentElement"
|
|
51
|
-
}, createElement("p", {
|
|
52
|
-
id: dialogDescription
|
|
53
|
-
}, __('Enter a custom name for this block.')), createElement("form", {
|
|
54
|
-
onSubmit: e => {
|
|
55
|
-
e.preventDefault();
|
|
56
|
-
if (!isNameValid) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
handleSubmit();
|
|
60
|
-
}
|
|
61
|
-
}, createElement(VStack, {
|
|
62
|
-
spacing: "3"
|
|
63
|
-
}, createElement(TextControl, {
|
|
64
|
-
__nextHasNoMarginBottom: true,
|
|
65
|
-
value: editedBlockName,
|
|
66
|
-
label: __('Block name'),
|
|
67
|
-
hideLabelFromVision: true,
|
|
68
|
-
placeholder: originalBlockName,
|
|
69
|
-
onChange: setEditedBlockName,
|
|
70
|
-
onFocus: autoSelectInputText
|
|
71
|
-
}), createElement(HStack, {
|
|
72
|
-
justify: "right"
|
|
73
|
-
}, createElement(Button, {
|
|
74
|
-
variant: "tertiary",
|
|
75
|
-
onClick: onClose
|
|
76
|
-
}, __('Cancel')), createElement(Button, {
|
|
77
|
-
"aria-disabled": !isNameValid,
|
|
78
|
-
variant: "primary",
|
|
79
|
-
type: "submit"
|
|
80
|
-
}, __('Save'))))));
|
|
81
|
-
}
|
|
82
|
-
function BlockRenameControl(props) {
|
|
83
|
-
const [renamingBlock, setRenamingBlock] = useState(false);
|
|
84
|
-
const {
|
|
85
|
-
clientId,
|
|
86
|
-
customName,
|
|
87
|
-
onChange
|
|
88
|
-
} = props;
|
|
89
|
-
const blockInformation = useBlockDisplayInformation(clientId);
|
|
90
|
-
return createElement(Fragment, null, createElement(InspectorControls, {
|
|
91
|
-
group: "advanced"
|
|
92
|
-
}, createElement(TextControl, {
|
|
93
|
-
__nextHasNoMarginBottom: true,
|
|
94
|
-
label: __('Block name'),
|
|
95
|
-
value: customName || '',
|
|
96
|
-
onChange: onChange
|
|
97
|
-
})), createElement(BlockSettingsMenuControls, null, ({
|
|
98
|
-
selectedClientIds
|
|
99
|
-
}) => {
|
|
100
|
-
// Only enabled for single selections.
|
|
101
|
-
const canRename = selectedClientIds.length === 1 && clientId === selectedClientIds[0];
|
|
102
|
-
|
|
103
|
-
// This check ensures the `BlockSettingsMenuControls` fill
|
|
104
|
-
// doesn't render multiple times and also that it renders for
|
|
105
|
-
// the block from which the menu was triggered.
|
|
106
|
-
if (!canRename) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
return createElement(MenuItem, {
|
|
110
|
-
onClick: () => {
|
|
111
|
-
setRenamingBlock(true);
|
|
112
|
-
},
|
|
113
|
-
"aria-expanded": renamingBlock,
|
|
114
|
-
"aria-haspopup": "dialog"
|
|
115
|
-
}, __('Rename'));
|
|
116
|
-
}), renamingBlock && createElement(RenameModal, {
|
|
117
|
-
blockName: customName || '',
|
|
118
|
-
originalBlockName: blockInformation?.title,
|
|
119
|
-
onClose: () => setRenamingBlock(false),
|
|
120
|
-
onSave: newName => {
|
|
121
|
-
// If the new value is the block's original name (e.g. `Group`)
|
|
122
|
-
// or it is an empty string then assume the intent is to reset
|
|
123
|
-
// the value. Therefore reset the metadata.
|
|
124
|
-
if (newName === blockInformation?.title || emptyString(newName)) {
|
|
125
|
-
newName = undefined;
|
|
126
|
-
}
|
|
127
|
-
onChange(newName);
|
|
128
|
-
}
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
export const withBlockRenameControl = createHigherOrderComponent(BlockEdit => props => {
|
|
132
|
-
const {
|
|
133
|
-
clientId,
|
|
134
|
-
name,
|
|
135
|
-
attributes,
|
|
136
|
-
setAttributes
|
|
137
|
-
} = props;
|
|
138
|
-
const metaDataSupport = getBlockSupport(name, '__experimentalMetadata', false);
|
|
139
|
-
const supportsBlockNaming = !!(true === metaDataSupport || metaDataSupport?.name);
|
|
140
|
-
return createElement(Fragment, null, supportsBlockNaming && createElement(Fragment, null, createElement(BlockRenameControl, {
|
|
141
|
-
clientId: clientId,
|
|
142
|
-
customName: attributes?.metadata?.name,
|
|
143
|
-
onChange: newName => {
|
|
144
|
-
setAttributes({
|
|
145
|
-
metadata: {
|
|
146
|
-
...(attributes?.metadata && attributes?.metadata),
|
|
147
|
-
name: newName
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
})), createElement(BlockEdit, {
|
|
152
|
-
key: "edit",
|
|
153
|
-
...props
|
|
154
|
-
}));
|
|
155
|
-
}, 'withToolbarControls');
|
|
156
|
-
addFilter('editor.BlockEdit', 'core/block-rename-ui/with-block-rename-control', withBlockRenameControl);
|
|
157
|
-
//# sourceMappingURL=block-rename-ui.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createHigherOrderComponent","useInstanceId","addFilter","__","sprintf","getBlockSupport","MenuItem","__experimentalHStack","HStack","__experimentalVStack","VStack","Button","TextControl","Modal","useState","speak","BlockSettingsMenuControls","useBlockDisplayInformation","InspectorControls","emptyString","testString","trim","length","RenameModal","blockName","originalBlockName","onClose","onSave","editedBlockName","setEditedBlockName","nameHasChanged","nameIsOriginal","nameIsEmpty","isNameValid","autoSelectInputText","event","target","select","dialogDescription","handleSubmit","message","createElement","title","onRequestClose","overlayClassName","aria","describedby","focusOnMount","id","onSubmit","e","preventDefault","spacing","__nextHasNoMarginBottom","value","label","hideLabelFromVision","placeholder","onChange","onFocus","justify","variant","onClick","type","BlockRenameControl","props","renamingBlock","setRenamingBlock","clientId","customName","blockInformation","Fragment","group","selectedClientIds","canRename","newName","undefined","withBlockRenameControl","BlockEdit","name","attributes","setAttributes","metaDataSupport","supportsBlockNaming","metadata","key"],"sources":["@wordpress/block-editor/src/hooks/block-rename-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\tMenuItem,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tButton,\n\tTextControl,\n\tModal,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport {\n\tBlockSettingsMenuControls,\n\tuseBlockDisplayInformation,\n\tInspectorControls,\n} from '../components';\n\nconst emptyString = ( testString ) => testString?.trim()?.length === 0;\n\nfunction RenameModal( { blockName, originalBlockName, onClose, onSave } ) {\n\tconst [ editedBlockName, setEditedBlockName ] = useState( blockName );\n\n\tconst nameHasChanged = editedBlockName !== blockName;\n\tconst nameIsOriginal = editedBlockName === originalBlockName;\n\tconst nameIsEmpty = emptyString( editedBlockName );\n\n\tconst isNameValid = nameHasChanged || nameIsOriginal;\n\n\tconst autoSelectInputText = ( event ) => event.target.select();\n\n\tconst dialogDescription = useInstanceId(\n\t\tRenameModal,\n\t\t`block-editor-rename-modal__description`\n\t);\n\n\tconst handleSubmit = () => {\n\t\tconst message =\n\t\t\tnameIsOriginal || nameIsEmpty\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: %s: new name/label for the block */\n\t\t\t\t\t\t__( 'Block name reset to: \"%s\".' ),\n\t\t\t\t\t\teditedBlockName\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: new name/label for the block */\n\t\t\t\t\t\t__( 'Block name changed to: \"%s\".' ),\n\t\t\t\t\t\teditedBlockName\n\t\t\t\t );\n\n\t\t// Must be assertive to immediately announce change.\n\t\tspeak( message, 'assertive' );\n\t\tonSave( editedBlockName );\n\n\t\t// Immediate close avoids ability to hit save multiple times.\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t\toverlayClassName=\"block-editor-block-rename-modal\"\n\t\t\taria={ {\n\t\t\t\tdescribedby: dialogDescription,\n\t\t\t} }\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t>\n\t\t\t<p id={ dialogDescription }>\n\t\t\t\t{ __( 'Enter a custom name for this block.' ) }\n\t\t\t</p>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\n\t\t\t\t\tif ( ! isNameValid ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\thandleSubmit();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ editedBlockName }\n\t\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tplaceholder={ originalBlockName }\n\t\t\t\t\t\tonChange={ setEditedBlockName }\n\t\t\t\t\t\tonFocus={ autoSelectInputText }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onClose }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\taria-disabled={ ! isNameValid }\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n\nfunction BlockRenameControl( props ) {\n\tconst [ renamingBlock, setRenamingBlock ] = useState( false );\n\n\tconst { clientId, customName, onChange } = props;\n\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\tvalue={ customName || '' }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t{ ( { selectedClientIds } ) => {\n\t\t\t\t\t// Only enabled for single selections.\n\t\t\t\t\tconst canRename =\n\t\t\t\t\t\tselectedClientIds.length === 1 &&\n\t\t\t\t\t\tclientId === selectedClientIds[ 0 ];\n\n\t\t\t\t\t// This check ensures the `BlockSettingsMenuControls` fill\n\t\t\t\t\t// doesn't render multiple times and also that it renders for\n\t\t\t\t\t// the block from which the menu was triggered.\n\t\t\t\t\tif ( ! canRename ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetRenamingBlock( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-expanded={ renamingBlock }\n\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rename' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</BlockSettingsMenuControls>\n\n\t\t\t{ renamingBlock && (\n\t\t\t\t<RenameModal\n\t\t\t\t\tblockName={ customName || '' }\n\t\t\t\t\toriginalBlockName={ blockInformation?.title }\n\t\t\t\t\tonClose={ () => setRenamingBlock( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\t// If the new value is the block's original name (e.g. `Group`)\n\t\t\t\t\t\t// or it is an empty string then assume the intent is to reset\n\t\t\t\t\t\t// the value. Therefore reset the metadata.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnewName === blockInformation?.title ||\n\t\t\t\t\t\t\temptyString( newName )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewName = undefined;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const withBlockRenameControl = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name, attributes, setAttributes } = props;\n\n\t\tconst metaDataSupport = getBlockSupport(\n\t\t\tname,\n\t\t\t'__experimentalMetadata',\n\t\t\tfalse\n\t\t);\n\n\t\tconst supportsBlockNaming = !! (\n\t\t\ttrue === metaDataSupport || metaDataSupport?.name\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ supportsBlockNaming && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockRenameControl\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tcustomName={ attributes?.metadata?.name }\n\t\t\t\t\t\t\tonChange={ ( newName ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t...( attributes?.metadata &&\n\t\t\t\t\t\t\t\t\t\t\tattributes?.metadata ),\n\t\t\t\t\t\t\t\t\t\tname: newName,\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/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-rename-ui/with-block-rename-control',\n\twithBlockRenameControl\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,0BAA0B,EAAEC,aAAa,QAAQ,oBAAoB;AAC9E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SACCC,QAAQ,EACRC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,MAAM,EACNC,WAAW,EACXC,KAAK,QACC,uBAAuB;AAC9B,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,SACCC,yBAAyB,EACzBC,0BAA0B,EAC1BC,iBAAiB,QACX,eAAe;AAEtB,MAAMC,WAAW,G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e,CACtC0E,IAAI,EACJ,wBAAwB,EACxB,KACD,CAAC;EAED,MAAMI,mBAAmB,GAAG,CAAC,EAC5B,IAAI,KAAKD,eAAe,IAAIA,eAAe,EAAEH,IAAI,CACjD;EAED,OACCtC,aAAA,CAAA8B,QAAA,QACGY,mBAAmB,IACpB1C,aAAA,CAAA8B,QAAA,QACC9B,aAAA,CAACuB,kBAAkB;IAClBI,QAAQ,EAAGA,QAAU;IACrBC,UAAU,EAAGW,UAAU,EAAEI,QAAQ,EAAEL,IAAM;IACzCrB,QAAQ,EAAKiB,OAAO,IAAM;MACzBM,aAAa,CAAE;QACdG,QAAQ,EAAE;UACT,IAAKJ,UAAU,EAAEI,QAAQ,IACxBJ,UAAU,EAAEI,QAAQ,CAAE;UACvBL,IAAI,EAAEJ;QACP;MACD,CAAE,CAAC;IACJ;EAAG,CACH,CACA,CACF,EAEDlC,aAAA,CAACqC,SAAS;IAACO,GAAG,EAAC,MAAM;IAAA,GAAMpB;EAAK,CAAI,CACnC,CAAC;AAEL,CAAC,EACD,qBACD,CAAC;AAED/D,SAAS,CACR,kBAAkB,EAClB,gDAAgD,EAChD2E,sBACD,CAAC"}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
|
|
5
|
-
import { addFilter } from '@wordpress/hooks';
|
|
6
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
8
|
-
import {
|
|
9
|
-
MenuItem,
|
|
10
|
-
__experimentalHStack as HStack,
|
|
11
|
-
__experimentalVStack as VStack,
|
|
12
|
-
Button,
|
|
13
|
-
TextControl,
|
|
14
|
-
Modal,
|
|
15
|
-
} from '@wordpress/components';
|
|
16
|
-
import { useState } from '@wordpress/element';
|
|
17
|
-
import { speak } from '@wordpress/a11y';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal dependencies
|
|
21
|
-
*/
|
|
22
|
-
import {
|
|
23
|
-
BlockSettingsMenuControls,
|
|
24
|
-
useBlockDisplayInformation,
|
|
25
|
-
InspectorControls,
|
|
26
|
-
} from '../components';
|
|
27
|
-
|
|
28
|
-
const emptyString = ( testString ) => testString?.trim()?.length === 0;
|
|
29
|
-
|
|
30
|
-
function RenameModal( { blockName, originalBlockName, onClose, onSave } ) {
|
|
31
|
-
const [ editedBlockName, setEditedBlockName ] = useState( blockName );
|
|
32
|
-
|
|
33
|
-
const nameHasChanged = editedBlockName !== blockName;
|
|
34
|
-
const nameIsOriginal = editedBlockName === originalBlockName;
|
|
35
|
-
const nameIsEmpty = emptyString( editedBlockName );
|
|
36
|
-
|
|
37
|
-
const isNameValid = nameHasChanged || nameIsOriginal;
|
|
38
|
-
|
|
39
|
-
const autoSelectInputText = ( event ) => event.target.select();
|
|
40
|
-
|
|
41
|
-
const dialogDescription = useInstanceId(
|
|
42
|
-
RenameModal,
|
|
43
|
-
`block-editor-rename-modal__description`
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const handleSubmit = () => {
|
|
47
|
-
const message =
|
|
48
|
-
nameIsOriginal || nameIsEmpty
|
|
49
|
-
? sprintf(
|
|
50
|
-
/* translators: %s: new name/label for the block */
|
|
51
|
-
__( 'Block name reset to: "%s".' ),
|
|
52
|
-
editedBlockName
|
|
53
|
-
)
|
|
54
|
-
: sprintf(
|
|
55
|
-
/* translators: %s: new name/label for the block */
|
|
56
|
-
__( 'Block name changed to: "%s".' ),
|
|
57
|
-
editedBlockName
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Must be assertive to immediately announce change.
|
|
61
|
-
speak( message, 'assertive' );
|
|
62
|
-
onSave( editedBlockName );
|
|
63
|
-
|
|
64
|
-
// Immediate close avoids ability to hit save multiple times.
|
|
65
|
-
onClose();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<Modal
|
|
70
|
-
title={ __( 'Rename' ) }
|
|
71
|
-
onRequestClose={ onClose }
|
|
72
|
-
overlayClassName="block-editor-block-rename-modal"
|
|
73
|
-
aria={ {
|
|
74
|
-
describedby: dialogDescription,
|
|
75
|
-
} }
|
|
76
|
-
focusOnMount="firstContentElement"
|
|
77
|
-
>
|
|
78
|
-
<p id={ dialogDescription }>
|
|
79
|
-
{ __( 'Enter a custom name for this block.' ) }
|
|
80
|
-
</p>
|
|
81
|
-
<form
|
|
82
|
-
onSubmit={ ( e ) => {
|
|
83
|
-
e.preventDefault();
|
|
84
|
-
|
|
85
|
-
if ( ! isNameValid ) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
handleSubmit();
|
|
90
|
-
} }
|
|
91
|
-
>
|
|
92
|
-
<VStack spacing="3">
|
|
93
|
-
<TextControl
|
|
94
|
-
__nextHasNoMarginBottom
|
|
95
|
-
value={ editedBlockName }
|
|
96
|
-
label={ __( 'Block name' ) }
|
|
97
|
-
hideLabelFromVision={ true }
|
|
98
|
-
placeholder={ originalBlockName }
|
|
99
|
-
onChange={ setEditedBlockName }
|
|
100
|
-
onFocus={ autoSelectInputText }
|
|
101
|
-
/>
|
|
102
|
-
<HStack justify="right">
|
|
103
|
-
<Button variant="tertiary" onClick={ onClose }>
|
|
104
|
-
{ __( 'Cancel' ) }
|
|
105
|
-
</Button>
|
|
106
|
-
|
|
107
|
-
<Button
|
|
108
|
-
aria-disabled={ ! isNameValid }
|
|
109
|
-
variant="primary"
|
|
110
|
-
type="submit"
|
|
111
|
-
>
|
|
112
|
-
{ __( 'Save' ) }
|
|
113
|
-
</Button>
|
|
114
|
-
</HStack>
|
|
115
|
-
</VStack>
|
|
116
|
-
</form>
|
|
117
|
-
</Modal>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function BlockRenameControl( props ) {
|
|
122
|
-
const [ renamingBlock, setRenamingBlock ] = useState( false );
|
|
123
|
-
|
|
124
|
-
const { clientId, customName, onChange } = props;
|
|
125
|
-
|
|
126
|
-
const blockInformation = useBlockDisplayInformation( clientId );
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<>
|
|
130
|
-
<InspectorControls group="advanced">
|
|
131
|
-
<TextControl
|
|
132
|
-
__nextHasNoMarginBottom
|
|
133
|
-
label={ __( 'Block name' ) }
|
|
134
|
-
value={ customName || '' }
|
|
135
|
-
onChange={ onChange }
|
|
136
|
-
/>
|
|
137
|
-
</InspectorControls>
|
|
138
|
-
<BlockSettingsMenuControls>
|
|
139
|
-
{ ( { selectedClientIds } ) => {
|
|
140
|
-
// Only enabled for single selections.
|
|
141
|
-
const canRename =
|
|
142
|
-
selectedClientIds.length === 1 &&
|
|
143
|
-
clientId === selectedClientIds[ 0 ];
|
|
144
|
-
|
|
145
|
-
// This check ensures the `BlockSettingsMenuControls` fill
|
|
146
|
-
// doesn't render multiple times and also that it renders for
|
|
147
|
-
// the block from which the menu was triggered.
|
|
148
|
-
if ( ! canRename ) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<MenuItem
|
|
154
|
-
onClick={ () => {
|
|
155
|
-
setRenamingBlock( true );
|
|
156
|
-
} }
|
|
157
|
-
aria-expanded={ renamingBlock }
|
|
158
|
-
aria-haspopup="dialog"
|
|
159
|
-
>
|
|
160
|
-
{ __( 'Rename' ) }
|
|
161
|
-
</MenuItem>
|
|
162
|
-
);
|
|
163
|
-
} }
|
|
164
|
-
</BlockSettingsMenuControls>
|
|
165
|
-
|
|
166
|
-
{ renamingBlock && (
|
|
167
|
-
<RenameModal
|
|
168
|
-
blockName={ customName || '' }
|
|
169
|
-
originalBlockName={ blockInformation?.title }
|
|
170
|
-
onClose={ () => setRenamingBlock( false ) }
|
|
171
|
-
onSave={ ( newName ) => {
|
|
172
|
-
// If the new value is the block's original name (e.g. `Group`)
|
|
173
|
-
// or it is an empty string then assume the intent is to reset
|
|
174
|
-
// the value. Therefore reset the metadata.
|
|
175
|
-
if (
|
|
176
|
-
newName === blockInformation?.title ||
|
|
177
|
-
emptyString( newName )
|
|
178
|
-
) {
|
|
179
|
-
newName = undefined;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
onChange( newName );
|
|
183
|
-
} }
|
|
184
|
-
/>
|
|
185
|
-
) }
|
|
186
|
-
</>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export const withBlockRenameControl = createHigherOrderComponent(
|
|
191
|
-
( BlockEdit ) => ( props ) => {
|
|
192
|
-
const { clientId, name, attributes, setAttributes } = props;
|
|
193
|
-
|
|
194
|
-
const metaDataSupport = getBlockSupport(
|
|
195
|
-
name,
|
|
196
|
-
'__experimentalMetadata',
|
|
197
|
-
false
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
const supportsBlockNaming = !! (
|
|
201
|
-
true === metaDataSupport || metaDataSupport?.name
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
return (
|
|
205
|
-
<>
|
|
206
|
-
{ supportsBlockNaming && (
|
|
207
|
-
<>
|
|
208
|
-
<BlockRenameControl
|
|
209
|
-
clientId={ clientId }
|
|
210
|
-
customName={ attributes?.metadata?.name }
|
|
211
|
-
onChange={ ( newName ) => {
|
|
212
|
-
setAttributes( {
|
|
213
|
-
metadata: {
|
|
214
|
-
...( attributes?.metadata &&
|
|
215
|
-
attributes?.metadata ),
|
|
216
|
-
name: newName,
|
|
217
|
-
},
|
|
218
|
-
} );
|
|
219
|
-
} }
|
|
220
|
-
/>
|
|
221
|
-
</>
|
|
222
|
-
) }
|
|
223
|
-
|
|
224
|
-
<BlockEdit key="edit" { ...props } />
|
|
225
|
-
</>
|
|
226
|
-
);
|
|
227
|
-
},
|
|
228
|
-
'withToolbarControls'
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
addFilter(
|
|
232
|
-
'editor.BlockEdit',
|
|
233
|
-
'core/block-rename-ui/with-block-rename-control',
|
|
234
|
-
withBlockRenameControl
|
|
235
|
-
);
|
|
File without changes
|