@wordpress/block-editor 12.3.7 → 12.3.9
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/README.md +0 -4
- package/build/components/block-removal-warning-modal/index.js +15 -25
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/colors-gradients/control.js +4 -2
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +13 -2
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/iframe/index.js +16 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-compatibility-styles.js +5 -0
- package/build/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build/components/index.js +1 -10
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +22 -2
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -1
- package/build/components/rich-text/get-rich-text-values.js +7 -1
- package/build/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/axial.js +6 -2
- package/build/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/separated.js +5 -1
- package/build/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/single.js +5 -1
- package/build/components/spacing-sizes-control/input-controls/single.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +1 -1
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/private-apis.js +5 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/index.js +10 -1
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +36 -36
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +16 -8
- package/build/store/reducer.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +16 -23
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +3 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +13 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/iframe/index.js +16 -3
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-compatibility-styles.js +5 -0
- package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build-module/components/index.js +0 -5
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +2 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +21 -2
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -1
- package/build-module/components/rich-text/get-rich-text-values.js +7 -1
- package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/axial.js +7 -3
- package/build-module/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/separated.js +6 -2
- package/build-module/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/single.js +6 -2
- package/build-module/components/spacing-sizes-control/input-controls/single.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +1 -1
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/private-apis.js +4 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/index.js +10 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +35 -32
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +16 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-style/style-rtl.css +3 -0
- package/build-style/style.css +3 -0
- package/package.json +10 -10
- package/src/components/block-removal-warning-modal/index.js +13 -27
- package/src/components/block-tools/style.scss +4 -1
- package/src/components/colors-gradients/control.js +3 -2
- package/src/components/global-styles/dimensions-panel.js +8 -2
- package/src/components/iframe/index.js +15 -10
- package/src/components/iframe/use-compatibility-styles.js +5 -0
- package/src/components/index.js +0 -5
- package/src/components/inserter/hooks/use-patterns-state.js +1 -0
- package/src/components/inserter/reusable-block-rename-hint.js +17 -0
- package/src/components/rich-text/get-rich-text-values.js +11 -1
- package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
- package/src/components/spacing-sizes-control/input-controls/axial.js +17 -2
- package/src/components/spacing-sizes-control/input-controls/separated.js +17 -2
- package/src/components/spacing-sizes-control/input-controls/single.js +12 -2
- package/src/components/spacing-sizes-control/utils.js +1 -1
- package/src/private-apis.js +6 -0
- package/src/store/index.js +10 -0
- package/src/store/private-actions.js +33 -36
- package/src/store/private-selectors.js +2 -2
- package/src/store/reducer.js +16 -8
- package/src/store/test/actions.js +3 -0
- package/src/store/test/selectors.js +5 -5
|
@@ -4,27 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.__experimentalUpdateSettings = __experimentalUpdateSettings;
|
|
7
|
-
exports.
|
|
8
|
-
exports.displayRemovalPrompt = displayRemovalPrompt;
|
|
7
|
+
exports.clearBlockRemovalPrompt = clearBlockRemovalPrompt;
|
|
9
8
|
exports.ensureDefaultBlock = void 0;
|
|
10
9
|
exports.hideBlockInterface = hideBlockInterface;
|
|
11
10
|
exports.privateRemoveBlocks = void 0;
|
|
12
11
|
exports.setBlockEditingMode = setBlockEditingMode;
|
|
12
|
+
exports.setBlockRemovalRules = setBlockRemovalRules;
|
|
13
13
|
exports.showBlockInterface = showBlockInterface;
|
|
14
|
-
exports.toggleRemovalPromptSupport = toggleRemovalPromptSupport;
|
|
15
14
|
exports.unsetBlockEditingMode = unsetBlockEditingMode;
|
|
16
15
|
|
|
17
16
|
var _element = require("@wordpress/element");
|
|
18
17
|
|
|
19
|
-
var _blockRemovalWarningModal = require("../components/block-removal-warning-modal");
|
|
20
|
-
|
|
21
18
|
/**
|
|
22
19
|
* WordPress dependencies
|
|
23
20
|
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Internal dependencies
|
|
27
|
-
*/
|
|
28
21
|
const castArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
29
22
|
/**
|
|
30
23
|
* A list of private/experimental block editor settings that
|
|
@@ -169,26 +162,18 @@ const privateRemoveBlocks = (clientIds, selectPrevious = true, forceRemove = fal
|
|
|
169
162
|
// confirmation that they intended to remove such block(s). However,
|
|
170
163
|
// the editor instance is responsible for presenting those confirmation
|
|
171
164
|
// prompts to the user. Any instance opting into removal prompts must
|
|
172
|
-
// register using `
|
|
165
|
+
// register using `setBlockRemovalRules()`.
|
|
173
166
|
//
|
|
174
167
|
// @see https://github.com/WordPress/gutenberg/pull/51145
|
|
175
168
|
|
|
176
169
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// the fact that the `registry` object passed to the thunk actions
|
|
181
|
-
// doesn't include this private action. This needs to be
|
|
182
|
-
// investigated to understand whether it's a real smell or if it's
|
|
183
|
-
// because not all store code has been updated to accommodate
|
|
184
|
-
// private selectors.
|
|
185
|
-
select.isRemovalPromptSupported && select.isRemovalPromptSupported()) {
|
|
170
|
+
const rules = !forceRemove && select.getBlockRemovalRules();
|
|
171
|
+
|
|
172
|
+
if (rules) {
|
|
186
173
|
const blockNamesForPrompt = new Set(); // Given a list of client IDs of blocks that the user intended to
|
|
187
174
|
// remove, perform a tree search (BFS) to find all block names
|
|
188
175
|
// corresponding to "important" blocks, i.e. blocks that require a
|
|
189
176
|
// removal prompt.
|
|
190
|
-
//
|
|
191
|
-
// @see blockTypePromptMessages
|
|
192
177
|
|
|
193
178
|
const queue = [...clientIds];
|
|
194
179
|
|
|
@@ -196,7 +181,7 @@ const privateRemoveBlocks = (clientIds, selectPrevious = true, forceRemove = fal
|
|
|
196
181
|
const clientId = queue.shift();
|
|
197
182
|
const blockName = select.getBlockName(clientId);
|
|
198
183
|
|
|
199
|
-
if (
|
|
184
|
+
if (rules[blockName]) {
|
|
200
185
|
blockNamesForPrompt.add(blockName);
|
|
201
186
|
}
|
|
202
187
|
|
|
@@ -207,7 +192,7 @@ const privateRemoveBlocks = (clientIds, selectPrevious = true, forceRemove = fal
|
|
|
207
192
|
|
|
208
193
|
|
|
209
194
|
if (blockNamesForPrompt.size) {
|
|
210
|
-
dispatch(
|
|
195
|
+
dispatch(displayBlockRemovalPrompt(clientIds, selectPrevious, Array.from(blockNamesForPrompt)));
|
|
211
196
|
return;
|
|
212
197
|
}
|
|
213
198
|
}
|
|
@@ -263,7 +248,7 @@ const ensureDefaultBlock = () => ({
|
|
|
263
248
|
* Returns an action object used in signalling that a block removal prompt must
|
|
264
249
|
* be displayed.
|
|
265
250
|
*
|
|
266
|
-
* Contrast with `
|
|
251
|
+
* Contrast with `setBlockRemovalRules`.
|
|
267
252
|
*
|
|
268
253
|
* @param {string|string[]} clientIds Client IDs of blocks to remove.
|
|
269
254
|
* @param {boolean} selectPrevious True if the previous block
|
|
@@ -271,16 +256,19 @@ const ensureDefaultBlock = () => ({
|
|
|
271
256
|
* (if no previous block exists)
|
|
272
257
|
* should be selected
|
|
273
258
|
* when a block is removed.
|
|
274
|
-
* @param {string[]} blockNamesForPrompt Names of blocks
|
|
259
|
+
* @param {string[]} blockNamesForPrompt Names of the blocks that
|
|
260
|
+
* triggered the need for
|
|
261
|
+
* confirmation before removal.
|
|
262
|
+
*
|
|
275
263
|
* @return {Object} Action object.
|
|
276
264
|
*/
|
|
277
265
|
|
|
278
266
|
|
|
279
267
|
exports.ensureDefaultBlock = ensureDefaultBlock;
|
|
280
268
|
|
|
281
|
-
function
|
|
269
|
+
function displayBlockRemovalPrompt(clientIds, selectPrevious, blockNamesForPrompt) {
|
|
282
270
|
return {
|
|
283
|
-
type: '
|
|
271
|
+
type: 'DISPLAY_BLOCK_REMOVAL_PROMPT',
|
|
284
272
|
clientIds,
|
|
285
273
|
selectPrevious,
|
|
286
274
|
blockNamesForPrompt
|
|
@@ -295,26 +283,38 @@ function displayRemovalPrompt(clientIds, selectPrevious, blockNamesForPrompt) {
|
|
|
295
283
|
*/
|
|
296
284
|
|
|
297
285
|
|
|
298
|
-
function
|
|
286
|
+
function clearBlockRemovalPrompt() {
|
|
299
287
|
return {
|
|
300
|
-
type: '
|
|
288
|
+
type: 'CLEAR_BLOCK_REMOVAL_PROMPT'
|
|
301
289
|
};
|
|
302
290
|
}
|
|
303
291
|
/**
|
|
304
|
-
* Returns an action object used
|
|
305
|
-
*
|
|
292
|
+
* Returns an action object used to set up any rules that a block editor may
|
|
293
|
+
* provide in order to prevent a user from accidentally removing certain
|
|
294
|
+
* blocks. These rules are then used to display a confirmation prompt to the
|
|
295
|
+
* user. For instance, in the Site Editor, the Query Loop block is important
|
|
296
|
+
* enough to warrant such confirmation.
|
|
297
|
+
*
|
|
298
|
+
* IMPORTANT: Registering rules implicitly signals to the `privateRemoveBlocks`
|
|
299
|
+
* action that the editor will be responsible for displaying block removal
|
|
300
|
+
* prompts and confirming deletions. This action is meant to be used by
|
|
301
|
+
* component `BlockRemovalWarningModal` only.
|
|
302
|
+
*
|
|
303
|
+
* The data is a record whose keys are block types (e.g. 'core/query') and
|
|
304
|
+
* whose values are the explanation to be shown to users (e.g. 'Query Loop
|
|
305
|
+
* displays a list of posts or pages.').
|
|
306
306
|
*
|
|
307
|
-
* Contrast with `
|
|
307
|
+
* Contrast with `displayBlockRemovalPrompt`.
|
|
308
308
|
*
|
|
309
|
-
* @param {
|
|
309
|
+
* @param {Record<string,string>|false} rules Block removal rules.
|
|
310
310
|
* @return {Object} Action object.
|
|
311
311
|
*/
|
|
312
312
|
|
|
313
313
|
|
|
314
|
-
function
|
|
314
|
+
function setBlockRemovalRules(rules = false) {
|
|
315
315
|
return {
|
|
316
|
-
type: '
|
|
317
|
-
|
|
316
|
+
type: 'SET_BLOCK_REMOVAL_RULES',
|
|
317
|
+
rules
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
//# sourceMappingURL=private-actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/store/private-actions.js"],"names":["castArray","maybeArray","Array","isArray","privateSettings","__experimentalUpdateSettings","settings","stripExperimentalSettings","cleanSettings","Platform","OS","key","includes","type","hideBlockInterface","showBlockInterface","setBlockEditingMode","clientId","mode","unsetBlockEditingMode","privateRemoveBlocks","clientIds","selectPrevious","forceRemove","select","dispatch","length","rootClientId","getBlockRootClientId","canRemoveBlocks","isRemovalPromptSupported","blockNamesForPrompt","Set","queue","shift","blockName","getBlockName","blockTypePromptMessages","add","innerBlocks","getBlockOrder","push","size","displayRemovalPrompt","from","selectPreviousBlock","ensureDefaultBlock","count","getBlockCount","__unstableHasCustomAppender","getSettings","insertDefaultBlock","clearRemovalPrompt","toggleRemovalPromptSupport","status"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA,MAAMA,SAAS,GAAKC,UAAF,IACjBC,KAAK,CAACC,OAAN,CAAeF,UAAf,IAA8BA,UAA9B,GAA2C,CAAEA,UAAF,CAD5C;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,eAAe,GAAG,CACvB,yBADuB,EAEvB,yBAFuB,CAAxB;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,4BAAT,CACNC,QADM,EAENC,yBAAyB,G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AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASwC,0BAAT,CAAqCC,MAAM,GAAG,IAA9C,EAAqD;AAC3D,SAAO;AACNzC,IAAAA,IAAI,EAAE,+BADA;AAENyC,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { blockTypePromptMessages } from '../components/block-removal-warning-modal';\n\nconst castArray = ( maybeArray ) =>\n\tArray.isArray( maybeArray ) ? maybeArray : [ maybeArray ];\n\n/**\n * A list of private/experimental block editor settings that\n * should not become a part of the WordPress public API.\n * BlockEditorProvider will remove these settings from the\n * settings object it receives.\n *\n * @see https://github.com/WordPress/gutenberg/pull/46131\n */\nconst privateSettings = [\n\t'inserterMediaCategories',\n\t'blockInspectorAnimation',\n];\n\n/**\n * Action that updates the block editor settings and\n * conditionally preserves the experimental ones.\n *\n * @param {Object} settings Updated settings\n * @param {boolean} stripExperimentalSettings Whether to strip experimental settings.\n * @return {Object} Action object\n */\nexport function __experimentalUpdateSettings(\n\tsettings,\n\tstripExperimentalSettings = false\n) {\n\tlet cleanSettings = settings;\n\t// There are no plugins in the mobile apps, so there is no\n\t// need to strip the experimental settings:\n\tif ( stripExperimentalSettings && Platform.OS === 'web' ) {\n\t\tcleanSettings = {};\n\t\tfor ( const key in settings ) {\n\t\t\tif ( ! privateSettings.includes( key ) ) {\n\t\t\t\tcleanSettings[ key ] = settings[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\ttype: 'UPDATE_SETTINGS',\n\t\tsettings: cleanSettings,\n\t};\n}\n\n/**\n * Hides the block interface (eg. toolbar, outline, etc.)\n *\n * @return {Object} Action object.\n */\nexport function hideBlockInterface() {\n\treturn {\n\t\ttype: 'HIDE_BLOCK_INTERFACE',\n\t};\n}\n\n/**\n * Shows the block interface (eg. toolbar, outline, etc.)\n *\n * @return {Object} Action object.\n */\nexport function showBlockInterface() {\n\treturn {\n\t\ttype: 'SHOW_BLOCK_INTERFACE',\n\t};\n}\n\n/**\n * @typedef {import('../components/block-editing-mode').BlockEditingMode} BlockEditingMode\n */\n\n/**\n * Sets the block editing mode for a given block.\n *\n * @see useBlockEditingMode\n *\n * @param {string} clientId The block client ID, or `''` for the root container.\n * @param {BlockEditingMode} mode The block editing mode. One of `'disabled'`,\n * `'contentOnly'`, or `'default'`.\n *\n * @return {Object} Action object.\n */\nexport function setBlockEditingMode( clientId = '', mode ) {\n\treturn {\n\t\ttype: 'SET_BLOCK_EDITING_MODE',\n\t\tclientId,\n\t\tmode,\n\t};\n}\n\n/**\n * Clears the block editing mode for a given block.\n *\n * @see useBlockEditingMode\n *\n * @param {string} clientId The block client ID, or `''` for the root container.\n *\n * @return {Object} Action object.\n */\nexport function unsetBlockEditingMode( clientId = '' ) {\n\treturn {\n\t\ttype: 'UNSET_BLOCK_EDITING_MODE',\n\t\tclientId,\n\t};\n}\n\n/**\n * Yields action objects used in signalling that the blocks corresponding to\n * the set of specified client IDs are to be removed.\n *\n * Compared to `removeBlocks`, this private interface exposes an additional\n * parameter; see `forceRemove`.\n *\n * @param {string|string[]} clientIds Client IDs of blocks to remove.\n * @param {boolean} selectPrevious True if the previous block\n * or the immediate parent\n * (if no previous block exists)\n * should be selected\n * when a block is removed.\n * @param {boolean} forceRemove Whether to force the operation,\n * bypassing any checks for certain\n * block types.\n */\nexport const privateRemoveBlocks =\n\t( clientIds, selectPrevious = true, forceRemove = false ) =>\n\t( { select, dispatch } ) => {\n\t\tif ( ! clientIds || ! clientIds.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tclientIds = castArray( clientIds );\n\t\tconst rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );\n\t\tconst canRemoveBlocks = select.canRemoveBlocks(\n\t\t\tclientIds,\n\t\t\trootClientId\n\t\t);\n\n\t\tif ( ! canRemoveBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// In certain editing contexts, we'd like to prevent accidental removal\n\t\t// of important blocks. For example, in the site editor, the Query Loop\n\t\t// block is deemed important. In such cases, we'll ask the user for\n\t\t// confirmation that they intended to remove such block(s). However,\n\t\t// the editor instance is responsible for presenting those confirmation\n\t\t// prompts to the user. Any instance opting into removal prompts must\n\t\t// register using `toggleRemovalPromptSupport()`.\n\t\t//\n\t\t// @see https://github.com/WordPress/gutenberg/pull/51145\n\t\tif (\n\t\t\t! forceRemove &&\n\t\t\t// FIXME: Without this existence check, the unit tests for\n\t\t\t// `__experimentalDeleteReusableBlock` in\n\t\t\t// `packages/reusable-blocks/src/store/test/actions.js` fail due to\n\t\t\t// the fact that the `registry` object passed to the thunk actions\n\t\t\t// doesn't include this private action. This needs to be\n\t\t\t// investigated to understand whether it's a real smell or if it's\n\t\t\t// because not all store code has been updated to accommodate\n\t\t\t// private selectors.\n\t\t\tselect.isRemovalPromptSupported &&\n\t\t\tselect.isRemovalPromptSupported()\n\t\t) {\n\t\t\tconst blockNamesForPrompt = new Set();\n\n\t\t\t// Given a list of client IDs of blocks that the user intended to\n\t\t\t// remove, perform a tree search (BFS) to find all block names\n\t\t\t// corresponding to \"important\" blocks, i.e. blocks that require a\n\t\t\t// removal prompt.\n\t\t\t//\n\t\t\t// @see blockTypePromptMessages\n\t\t\tconst queue = [ ...clientIds ];\n\t\t\twhile ( queue.length ) {\n\t\t\t\tconst clientId = queue.shift();\n\t\t\t\tconst blockName = select.getBlockName( clientId );\n\t\t\t\tif ( blockTypePromptMessages[ blockName ] ) {\n\t\t\t\t\tblockNamesForPrompt.add( blockName );\n\t\t\t\t}\n\t\t\t\tconst innerBlocks = select.getBlockOrder( clientId );\n\t\t\t\tqueue.push( ...innerBlocks );\n\t\t\t}\n\n\t\t\t// If any such blocks were found, trigger the removal prompt and\n\t\t\t// skip any other steps (thus postponing actual removal).\n\t\t\tif ( blockNamesForPrompt.size ) {\n\t\t\t\tdispatch(\n\t\t\t\t\tdisplayRemovalPrompt(\n\t\t\t\t\t\tclientIds,\n\t\t\t\t\t\tselectPrevious,\n\t\t\t\t\t\tArray.from( blockNamesForPrompt )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif ( selectPrevious ) {\n\t\t\tdispatch.selectPreviousBlock( clientIds[ 0 ], selectPrevious );\n\t\t}\n\n\t\tdispatch( { type: 'REMOVE_BLOCKS', clientIds } );\n\n\t\t// To avoid a focus loss when removing the last block, assure there is\n\t\t// always a default block if the last of the blocks have been removed.\n\t\tdispatch( ensureDefaultBlock() );\n\t};\n\n/**\n * Action which will insert a default block insert action if there\n * are no other blocks at the root of the editor. This action should be used\n * in actions which may result in no blocks remaining in the editor (removal,\n * replacement, etc).\n */\nexport const ensureDefaultBlock =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\t// To avoid a focus loss when removing the last block, assure there is\n\t\t// always a default block if the last of the blocks have been removed.\n\t\tconst count = select.getBlockCount();\n\t\tif ( count > 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If there's an custom appender, don't insert default block.\n\t\t// We have to remember to manually move the focus elsewhere to\n\t\t// prevent it from being lost though.\n\t\tconst { __unstableHasCustomAppender } = select.getSettings();\n\t\tif ( __unstableHasCustomAppender ) {\n\t\t\treturn;\n\t\t}\n\n\t\tdispatch.insertDefaultBlock();\n\t};\n\n/**\n * Returns an action object used in signalling that a block removal prompt must\n * be displayed.\n *\n * Contrast with `toggleRemovalPromptSupport`.\n *\n * @param {string|string[]} clientIds Client IDs of blocks to remove.\n * @param {boolean} selectPrevious True if the previous block\n * or the immediate parent\n * (if no previous block exists)\n * should be selected\n * when a block is removed.\n * @param {string[]} blockNamesForPrompt Names of blocks requiring user\n * @return {Object} Action object.\n */\nexport function displayRemovalPrompt(\n\tclientIds,\n\tselectPrevious,\n\tblockNamesForPrompt\n) {\n\treturn {\n\t\ttype: 'DISPLAY_REMOVAL_PROMPT',\n\t\tclientIds,\n\t\tselectPrevious,\n\t\tblockNamesForPrompt,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a block removal prompt must\n * be cleared, either be cause the user has confirmed or canceled the request\n * for removal.\n *\n * @return {Object} Action object.\n */\nexport function clearRemovalPrompt() {\n\treturn {\n\t\ttype: 'CLEAR_REMOVAL_PROMPT',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a removal prompt display\n * mechanism is available or unavailable in the current editor.\n *\n * Contrast with `displayRemovalPrompt`.\n *\n * @param {boolean} status Whether a prompt display mechanism exists.\n * @return {Object} Action object.\n */\nexport function toggleRemovalPromptSupport( status = true ) {\n\treturn {\n\t\ttype: 'TOGGLE_REMOVAL_PROMPT_SUPPORT',\n\t\tstatus,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/store/private-actions.js"],"names":["castArray","maybeArray","Array","isArray","privateSettings","__experimentalUpdateSettings","settings","stripExperimentalSettings","cleanSettings","Platform","OS","key","includes","type","hideBlockInterface","showBlockInterface","setBlockEditingMode","clientId","mode","unsetBlockEditingMode","privateRemoveBlocks","clientIds","selectPrevious","forceRemove","select","dispatch","length","rootClientId","getBlockRootClientId","canRemoveBlocks","rules","getBlockRemovalRules","blockNamesForPrompt","Set","queue","shift","blockName","getBlockName","add","innerBlocks","getBlockOrder","push","size","displayBlockRemovalPrompt","from","selectPreviousBlock","ensureDefaultBlock","count","getBlockCount","__unstableHasCustomAppender","getSettings","insertDefaultBlock","clearBlockRemovalPrompt","setBlockRemovalRules"],"mappings":";;;;;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,SAAS,GAAKC,UAAF,IACjBC,KAAK,CAACC,OAAN,CAAeF,UAAf,IAA8BA,UAA9B,GAA2C,CAAEA,UAAF,CAD5C;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,eAAe,GAAG,CACvB,yBADuB,EAEvB,yBAFuB,CAAxB;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,4BAAT,CACNC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AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASwC,oBAAT,CAA+BvB,KAAK,GAAG,KAAvC,EAA+C;AACrD,SAAO;AACNjB,IAAAA,IAAI,EAAE,yBADA;AAENiB,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Platform } from '@wordpress/element';\n\nconst castArray = ( maybeArray ) =>\n\tArray.isArray( maybeArray ) ? maybeArray : [ maybeArray ];\n\n/**\n * A list of private/experimental block editor settings that\n * should not become a part of the WordPress public API.\n * BlockEditorProvider will remove these settings from the\n * settings object it receives.\n *\n * @see https://github.com/WordPress/gutenberg/pull/46131\n */\nconst privateSettings = [\n\t'inserterMediaCategories',\n\t'blockInspectorAnimation',\n];\n\n/**\n * Action that updates the block editor settings and\n * conditionally preserves the experimental ones.\n *\n * @param {Object} settings Updated settings\n * @param {boolean} stripExperimentalSettings Whether to strip experimental settings.\n * @return {Object} Action object\n */\nexport function __experimentalUpdateSettings(\n\tsettings,\n\tstripExperimentalSettings = false\n) {\n\tlet cleanSettings = settings;\n\t// There are no plugins in the mobile apps, so there is no\n\t// need to strip the experimental settings:\n\tif ( stripExperimentalSettings && Platform.OS === 'web' ) {\n\t\tcleanSettings = {};\n\t\tfor ( const key in settings ) {\n\t\t\tif ( ! privateSettings.includes( key ) ) {\n\t\t\t\tcleanSettings[ key ] = settings[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\ttype: 'UPDATE_SETTINGS',\n\t\tsettings: cleanSettings,\n\t};\n}\n\n/**\n * Hides the block interface (eg. toolbar, outline, etc.)\n *\n * @return {Object} Action object.\n */\nexport function hideBlockInterface() {\n\treturn {\n\t\ttype: 'HIDE_BLOCK_INTERFACE',\n\t};\n}\n\n/**\n * Shows the block interface (eg. toolbar, outline, etc.)\n *\n * @return {Object} Action object.\n */\nexport function showBlockInterface() {\n\treturn {\n\t\ttype: 'SHOW_BLOCK_INTERFACE',\n\t};\n}\n\n/**\n * @typedef {import('../components/block-editing-mode').BlockEditingMode} BlockEditingMode\n */\n\n/**\n * Sets the block editing mode for a given block.\n *\n * @see useBlockEditingMode\n *\n * @param {string} clientId The block client ID, or `''` for the root container.\n * @param {BlockEditingMode} mode The block editing mode. One of `'disabled'`,\n * `'contentOnly'`, or `'default'`.\n *\n * @return {Object} Action object.\n */\nexport function setBlockEditingMode( clientId = '', mode ) {\n\treturn {\n\t\ttype: 'SET_BLOCK_EDITING_MODE',\n\t\tclientId,\n\t\tmode,\n\t};\n}\n\n/**\n * Clears the block editing mode for a given block.\n *\n * @see useBlockEditingMode\n *\n * @param {string} clientId The block client ID, or `''` for the root container.\n *\n * @return {Object} Action object.\n */\nexport function unsetBlockEditingMode( clientId = '' ) {\n\treturn {\n\t\ttype: 'UNSET_BLOCK_EDITING_MODE',\n\t\tclientId,\n\t};\n}\n\n/**\n * Yields action objects used in signalling that the blocks corresponding to\n * the set of specified client IDs are to be removed.\n *\n * Compared to `removeBlocks`, this private interface exposes an additional\n * parameter; see `forceRemove`.\n *\n * @param {string|string[]} clientIds Client IDs of blocks to remove.\n * @param {boolean} selectPrevious True if the previous block\n * or the immediate parent\n * (if no previous block exists)\n * should be selected\n * when a block is removed.\n * @param {boolean} forceRemove Whether to force the operation,\n * bypassing any checks for certain\n * block types.\n */\nexport const privateRemoveBlocks =\n\t( clientIds, selectPrevious = true, forceRemove = false ) =>\n\t( { select, dispatch } ) => {\n\t\tif ( ! clientIds || ! clientIds.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tclientIds = castArray( clientIds );\n\t\tconst rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );\n\t\tconst canRemoveBlocks = select.canRemoveBlocks(\n\t\t\tclientIds,\n\t\t\trootClientId\n\t\t);\n\n\t\tif ( ! canRemoveBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// In certain editing contexts, we'd like to prevent accidental removal\n\t\t// of important blocks. For example, in the site editor, the Query Loop\n\t\t// block is deemed important. In such cases, we'll ask the user for\n\t\t// confirmation that they intended to remove such block(s). However,\n\t\t// the editor instance is responsible for presenting those confirmation\n\t\t// prompts to the user. Any instance opting into removal prompts must\n\t\t// register using `setBlockRemovalRules()`.\n\t\t//\n\t\t// @see https://github.com/WordPress/gutenberg/pull/51145\n\t\tconst rules = ! forceRemove && select.getBlockRemovalRules();\n\t\tif ( rules ) {\n\t\t\tconst blockNamesForPrompt = new Set();\n\n\t\t\t// Given a list of client IDs of blocks that the user intended to\n\t\t\t// remove, perform a tree search (BFS) to find all block names\n\t\t\t// corresponding to \"important\" blocks, i.e. blocks that require a\n\t\t\t// removal prompt.\n\t\t\tconst queue = [ ...clientIds ];\n\t\t\twhile ( queue.length ) {\n\t\t\t\tconst clientId = queue.shift();\n\t\t\t\tconst blockName = select.getBlockName( clientId );\n\t\t\t\tif ( rules[ blockName ] ) {\n\t\t\t\t\tblockNamesForPrompt.add( blockName );\n\t\t\t\t}\n\t\t\t\tconst innerBlocks = select.getBlockOrder( clientId );\n\t\t\t\tqueue.push( ...innerBlocks );\n\t\t\t}\n\n\t\t\t// If any such blocks were found, trigger the removal prompt and\n\t\t\t// skip any other steps (thus postponing actual removal).\n\t\t\tif ( blockNamesForPrompt.size ) {\n\t\t\t\tdispatch(\n\t\t\t\t\tdisplayBlockRemovalPrompt(\n\t\t\t\t\t\tclientIds,\n\t\t\t\t\t\tselectPrevious,\n\t\t\t\t\t\tArray.from( blockNamesForPrompt )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif ( selectPrevious ) {\n\t\t\tdispatch.selectPreviousBlock( clientIds[ 0 ], selectPrevious );\n\t\t}\n\n\t\tdispatch( { type: 'REMOVE_BLOCKS', clientIds } );\n\n\t\t// To avoid a focus loss when removing the last block, assure there is\n\t\t// always a default block if the last of the blocks have been removed.\n\t\tdispatch( ensureDefaultBlock() );\n\t};\n\n/**\n * Action which will insert a default block insert action if there\n * are no other blocks at the root of the editor. This action should be used\n * in actions which may result in no blocks remaining in the editor (removal,\n * replacement, etc).\n */\nexport const ensureDefaultBlock =\n\t() =>\n\t( { select, dispatch } ) => {\n\t\t// To avoid a focus loss when removing the last block, assure there is\n\t\t// always a default block if the last of the blocks have been removed.\n\t\tconst count = select.getBlockCount();\n\t\tif ( count > 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If there's an custom appender, don't insert default block.\n\t\t// We have to remember to manually move the focus elsewhere to\n\t\t// prevent it from being lost though.\n\t\tconst { __unstableHasCustomAppender } = select.getSettings();\n\t\tif ( __unstableHasCustomAppender ) {\n\t\t\treturn;\n\t\t}\n\n\t\tdispatch.insertDefaultBlock();\n\t};\n\n/**\n * Returns an action object used in signalling that a block removal prompt must\n * be displayed.\n *\n * Contrast with `setBlockRemovalRules`.\n *\n * @param {string|string[]} clientIds Client IDs of blocks to remove.\n * @param {boolean} selectPrevious True if the previous block\n * or the immediate parent\n * (if no previous block exists)\n * should be selected\n * when a block is removed.\n * @param {string[]} blockNamesForPrompt Names of the blocks that\n * triggered the need for\n * confirmation before removal.\n *\n * @return {Object} Action object.\n */\nfunction displayBlockRemovalPrompt(\n\tclientIds,\n\tselectPrevious,\n\tblockNamesForPrompt\n) {\n\treturn {\n\t\ttype: 'DISPLAY_BLOCK_REMOVAL_PROMPT',\n\t\tclientIds,\n\t\tselectPrevious,\n\t\tblockNamesForPrompt,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a block removal prompt must\n * be cleared, either be cause the user has confirmed or canceled the request\n * for removal.\n *\n * @return {Object} Action object.\n */\nexport function clearBlockRemovalPrompt() {\n\treturn {\n\t\ttype: 'CLEAR_BLOCK_REMOVAL_PROMPT',\n\t};\n}\n\n/**\n * Returns an action object used to set up any rules that a block editor may\n * provide in order to prevent a user from accidentally removing certain\n * blocks. These rules are then used to display a confirmation prompt to the\n * user. For instance, in the Site Editor, the Query Loop block is important\n * enough to warrant such confirmation.\n *\n * IMPORTANT: Registering rules implicitly signals to the `privateRemoveBlocks`\n * action that the editor will be responsible for displaying block removal\n * prompts and confirming deletions. This action is meant to be used by\n * component `BlockRemovalWarningModal` only.\n *\n * The data is a record whose keys are block types (e.g. 'core/query') and\n * whose values are the explanation to be shown to users (e.g. 'Query Loop\n * displays a list of posts or pages.').\n *\n * Contrast with `displayBlockRemovalPrompt`.\n *\n * @param {Record<string,string>|false} rules Block removal rules.\n * @return {Object} Action object.\n */\nexport function setBlockRemovalRules( rules = false ) {\n\treturn {\n\t\ttype: 'SET_BLOCK_REMOVAL_RULES',\n\t\trules,\n\t};\n}\n"]}
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.getBlockEditingMode = getBlockEditingMode;
|
|
9
|
+
exports.getBlockRemovalRules = getBlockRemovalRules;
|
|
9
10
|
exports.getEnabledClientIdsTree = exports.getEnabledBlockParents = void 0;
|
|
10
11
|
exports.getLastInsertedBlocksClientIds = getLastInsertedBlocksClientIds;
|
|
11
12
|
exports.getRemovalPromptData = getRemovalPromptData;
|
|
12
13
|
exports.isBlockInterfaceHidden = isBlockInterfaceHidden;
|
|
13
14
|
exports.isBlockSubtreeDisabled = void 0;
|
|
14
|
-
exports.isRemovalPromptSupported = isRemovalPromptSupported;
|
|
15
15
|
|
|
16
16
|
var _rememo = _interopRequireDefault(require("rememo"));
|
|
17
17
|
|
|
@@ -198,7 +198,7 @@ function getRemovalPromptData(state) {
|
|
|
198
198
|
*/
|
|
199
199
|
|
|
200
200
|
|
|
201
|
-
function
|
|
202
|
-
return state.
|
|
201
|
+
function getBlockRemovalRules(state) {
|
|
202
|
+
return state.blockRemovalRules;
|
|
203
203
|
}
|
|
204
204
|
//# sourceMappingURL=private-selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/store/private-selectors.js"],"names":["isBlockInterfaceHidden","state","getLastInsertedBlocksClientIds","lastBlockInserted","clientIds","getBlockEditingMode","clientId","blockEditingModes","has","get","rootClientId","templateLock","name","isContent","blocksStore","__experimentalHasContentRoleAttribute","parentMode","isBlockSubtreeDisabled","isChildSubtreeDisabled","childClientId","mode","undefined","every","blocks","parents","getEnabledClientIdsTree","flatMap","innerBlocks","order","settings","blockListSettings","getEnabledBlockParents","ascending","filter","parent","getRemovalPromptData","removalPromptData","isRemovalPromptSupported"],"mappings":";;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACD,sBAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,8BAAT,CAAyCD,KAAzC,EAAiD;AACvD,SAAOA,KAAK,EAAEE,iBAAP,EAA0BC,SAAjC;AACA;AAED;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA8BJ,KAA9B,EAAqCK,QAAQ,GAAG,EAAhD,EAAqD;AAC3D,MAAKL,KAAK,CAACM,iBAAN,CAAwBC,GAAxB,CAA6BF,QAA7B,CAAL,EAA+C;AAC9C,WAAOL,KAAK,CAACM,iBAAN,CAAwBE,GAAxB,CAA6BH,QAA7B,CAAP;AACA;;AACD,MAAK,CAAEA,QAAP,EAAkB;AACjB,WAAO,SAAP;AACA;;AACD,QAAMI,YAAY,GAAG,qCAAsBT,KAAtB,EAA6BK,QAA7B,CAArB;AACA,QAAMK,YAAY,GAAG,gCAAiBV,KAAjB,EAAwBS,YAAxB,CAArB;;AACA,MAAKC,YAAY,KAA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AAgB;AACpE,QAAKD,mBAAmB,CAAEJ,KAAF,EAASK,QAAT,CAAnB,KAA2C,UAAhD,EAA6D;AAC5D,aAAO,CACN;AACCA,QAAAA,QADD;AAECqB,QAAAA,WAAW,EAAEF,uBAAuB,CAAExB,KAAF,EAASK,QAAT;AAFrC,OADM,CAAP;AAMA;;AACD,WAAOmB,uBAAuB,CAAExB,KAAF,EAASK,QAAT,CAA9B;AACA,GAVM,CAAP;AAWA,CAbqC,EAcpCL,KAAF,IAAa,CACZA,KAAK,CAACsB,MAAN,CAAaK,KADD,EAEZ3B,KAAK,CAACM,iBAFM,EAGZN,KAAK,CAAC4B,QAAN,CAAelB,YAHH,EAIZV,KAAK,CAAC6B,iBAJM,CAdyB,CAAhC;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,sBAAsB,GAAG,qBACrC,CAAE9B,KAAF,EAASK,QAAT,EAAmB0B,SAAS,GAAG,KAA/B,KAA0C;AACzC,SAAO,gCAAiB/B,KAAjB,EAAwBK,QAAxB,EAAkC0B,SAAlC,EAA8CC,MAA9C,CACJC,MAAF,IAAc7B,mBAAmB,CAAEJ,KAAF,EAASiC,MAAT,CAAnB,KAAyC,UADjD,CAAP;AAGA,CALoC,EAMnCjC,KAAF,IAAa,CACZA,KAAK,CAACsB,MAAN,CAAaC,OADD,EAEZvB,KAAK,CAACM,iBAFM,EAGZN,KAAK,CAAC4B,QAAN,CAAelB,YAHH,EAIZV,KAAK,CAAC6B,iBAJM,CANwB,CAA/B;AAcP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASK,oBAAT,CAA+BlC,KAA/B,EAAuC;AAC7C,SAAOA,KAAK,CAACmC,iBAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,wBAAT,CAAmCpC,KAAnC,EAA2C;AACjD,SAAOA,KAAK,CAACoC,wBAAb;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\nimport { select } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetBlockRootClientId,\n\tgetTemplateLock,\n\tgetBlockName,\n\tgetBlockOrder,\n\tgetBlockParents,\n} from './selectors';\n\n/**\n * Returns true if the block interface is hidden, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the block toolbar is hidden.\n */\nexport function isBlockInterfaceHidden( state ) {\n\treturn state.isBlockInterfaceHidden;\n}\n\n/**\n * Gets the client ids of the last inserted blocks.\n *\n * @param {Object} state Global application state.\n * @return {Array|undefined} Client Ids of the last inserted block(s).\n */\nexport function getLastInsertedBlocksClientIds( state ) {\n\treturn state?.lastBlockInserted?.clientIds;\n}\n\n/**\n * @typedef {import('../components/block-editing-mode').BlockEditingMode} BlockEditingMode\n */\n\n/**\n * Returns the block editing mode for a given block.\n *\n * The mode can be one of three options:\n *\n * - `'disabled'`: Prevents editing the block entirely, i.e. it cannot be\n * selected.\n * - `'contentOnly'`: Hides all non-content UI, e.g. auxiliary controls in the\n * toolbar, the block movers, block settings.\n * - `'default'`: Allows editing the block as normal.\n *\n * Blocks can set a mode using the `useBlockEditingMode` hook.\n *\n * The mode is inherited by all of the block's inner blocks, unless they have\n * their own mode.\n *\n * A template lock can also set a mode. If the template lock is `'contentOnly'`,\n * the block's mode is overridden to `'contentOnly'` if the block has a content\n * role attribute, or `'disabled'` otherwise.\n *\n * @see useBlockEditingMode\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID, or `''` for the root container.\n *\n * @return {BlockEditingMode} The block editing mode. One of `'disabled'`,\n * `'contentOnly'`, or `'default'`.\n */\nexport function getBlockEditingMode( state, clientId = '' ) {\n\tif ( state.blockEditingModes.has( clientId ) ) {\n\t\treturn state.blockEditingModes.get( clientId );\n\t}\n\tif ( ! clientId ) {\n\t\treturn 'default';\n\t}\n\tconst rootClientId = getBlockRootClientId( state, clientId );\n\tconst templateLock = getTemplateLock( state, rootClientId );\n\tif ( templateLock === 'contentOnly' ) {\n\t\tconst name = getBlockName( state, clientId );\n\t\t// TODO: Terrible hack! We're calling the global select() function\n\t\t// here instead of using createRegistrySelector(). The problem with\n\t\t// using createRegistrySelector() is that then the public\n\t\t// block-editor selectors (e.g. canInsertBlockTypeUnmemoized) can't\n\t\t// call this private block-editor selector due to a bug in\n\t\t// @wordpress/data. See\n\t\t// https://github.com/WordPress/gutenberg/pull/50985.\n\t\tconst isContent =\n\t\t\tselect( blocksStore ).__experimentalHasContentRoleAttribute( name );\n\t\treturn isContent ? 'contentOnly' : 'disabled';\n\t}\n\tconst parentMode = getBlockEditingMode( state, rootClientId );\n\treturn parentMode === 'contentOnly' ? 'default' : parentMode;\n}\n\n/**\n * Returns true if the block with the given client ID and all of its descendants\n * have an editing mode of 'disabled', or false otherwise.\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n *\n * @return {boolean} Whether the block and its descendants are disabled.\n */\nexport const isBlockSubtreeDisabled = createSelector(\n\t( state, clientId ) => {\n\t\tconst isChildSubtreeDisabled = ( childClientId ) => {\n\t\t\tconst mode = state.blockEditingModes.get( childClientId );\n\t\t\treturn (\n\t\t\t\t( mode === undefined || mode === 'disabled' ) &&\n\t\t\t\tgetBlockOrder( state, childClientId ).every(\n\t\t\t\t\tisChildSubtreeDisabled\n\t\t\t\t)\n\t\t\t);\n\t\t};\n\t\treturn (\n\t\t\tgetBlockEditingMode( state, clientId ) === 'disabled' &&\n\t\t\tgetBlockOrder( state, clientId ).every( isChildSubtreeDisabled )\n\t\t);\n\t},\n\t( state ) => [ state.blockEditingModes, state.blocks.parents ]\n);\n\n/**\n * Returns a tree of block objects with only clientID and innerBlocks set.\n * Blocks with a 'disabled' editing mode are not included.\n *\n * @param {Object} state Global application state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Object[]} Tree of block objects with only clientID and innerBlocks set.\n */\nexport const getEnabledClientIdsTree = createSelector(\n\t( state, rootClientId = '' ) => {\n\t\treturn getBlockOrder( state, rootClientId ).flatMap( ( clientId ) => {\n\t\t\tif ( getBlockEditingMode( state, clientId ) !== 'disabled' ) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tinnerBlocks: getEnabledClientIdsTree( state, clientId ),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn getEnabledClientIdsTree( state, clientId );\n\t\t} );\n\t},\n\t( state ) => [\n\t\tstate.blocks.order,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Returns a list of a given block's ancestors, from top to bottom. Blocks with\n * a 'disabled' editing mode are excluded.\n *\n * @see getBlockParents\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n * @param {boolean} ascending Order results from bottom to top (true) or top\n * to bottom (false).\n */\nexport const getEnabledBlockParents = createSelector(\n\t( state, clientId, ascending = false ) => {\n\t\treturn getBlockParents( state, clientId, ascending ).filter(\n\t\t\t( parent ) => getBlockEditingMode( state, parent ) !== 'disabled'\n\t\t);\n\t},\n\t( state ) => [\n\t\tstate.blocks.parents,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Selector that returns the data needed to display a prompt when certain\n * blocks are removed, or `false` if no such prompt is requested.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object|false} Data for removal prompt display, if any.\n */\nexport function getRemovalPromptData( state ) {\n\treturn state.removalPromptData;\n}\n\n/**\n * Returns true if removal prompt exists, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether removal prompt exists.\n */\nexport function isRemovalPromptSupported( state ) {\n\treturn state.isRemovalPromptSupported;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/store/private-selectors.js"],"names":["isBlockInterfaceHidden","state","getLastInsertedBlocksClientIds","lastBlockInserted","clientIds","getBlockEditingMode","clientId","blockEditingModes","has","get","rootClientId","templateLock","name","isContent","blocksStore","__experimentalHasContentRoleAttribute","parentMode","isBlockSubtreeDisabled","isChildSubtreeDisabled","childClientId","mode","undefined","every","blocks","parents","getEnabledClientIdsTree","flatMap","innerBlocks","order","settings","blockListSettings","getEnabledBlockParents","ascending","filter","parent","getRemovalPromptData","removalPromptData","getBlockRemovalRules","blockRemovalRules"],"mappings":";;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACD,sBAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,8BAAT,CAAyCD,KAAzC,EAAiD;AACvD,SAAOA,KAAK,EAAEE,iBAAP,EAA0BC,SAAjC;AACA;AAED;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA8BJ,KAA9B,EAAqCK,QAAQ,GAAG,EAAhD,EAAqD;AAC3D,MAAKL,KAAK,CAACM,iBAAN,CAAwBC,GAAxB,CAA6BF,QAA7B,CAAL,EAA+C;AAC9C,WAAOL,KAAK,CAACM,iBAAN,CAAwBE,GAAxB,CAA6BH,QAA7B,CAAP;AACA;;AACD,MAAK,CAAEA,QAAP,EAAkB;AACjB,WAAO,SAAP;AACA;;AACD,QAAMI,YAAY,GAAG,qCAAsBT,KAAtB,EAA6BK,QAA7B,CAArB;AACA,QAAMK,YAAY,GAAG,gCAAiBV,KAAjB,EAAwBS,YAAxB,CAArB;;AACA,MAAKC,YAAY,KAAK,aAAtB,E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,QAAKD,mBAAmB,CAAEJ,KAAF,EAASK,QAAT,CAAnB,KAA2C,UAAhD,EAA6D;AAC5D,aAAO,CACN;AACCA,QAAAA,QADD;AAECqB,QAAAA,WAAW,EAAEF,uBAAuB,CAAExB,KAAF,EAASK,QAAT;AAFrC,OADM,CAAP;AAMA;;AACD,WAAOmB,uBAAuB,CAAExB,KAAF,EAASK,QAAT,CAA9B;AACA,GAVM,CAAP;AAWA,CAbqC,EAcpCL,KAAF,IAAa,CACZA,KAAK,CAACsB,MAAN,CAAaK,KADD,EAEZ3B,KAAK,CAACM,iBAFM,EAGZN,KAAK,CAAC4B,QAAN,CAAelB,YAHH,EAIZV,KAAK,CAAC6B,iBAJM,CAdyB,CAAhC;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,sBAAsB,GAAG,qBACrC,CAAE9B,KAAF,EAASK,QAAT,EAAmB0B,SAAS,GAAG,KAA/B,KAA0C;AACzC,SAAO,gCAAiB/B,KAAjB,EAAwBK,QAAxB,EAAkC0B,SAAlC,EAA8CC,MAA9C,CACJC,MAAF,IAAc7B,mBAAmB,CAAEJ,KAAF,EAASiC,MAAT,CAAnB,KAAyC,UADjD,CAAP;AAGA,CALoC,EAMnCjC,KAAF,IAAa,CACZA,KAAK,CAACsB,MAAN,CAAaC,OADD,EAEZvB,KAAK,CAACM,iBAFM,EAGZN,KAAK,CAAC4B,QAAN,CAAelB,YAHH,EAIZV,KAAK,CAAC6B,iBAJM,CANwB,CAA/B;AAcP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASK,oBAAT,CAA+BlC,KAA/B,EAAuC;AAC7C,SAAOA,KAAK,CAACmC,iBAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,CAA+BpC,KAA/B,EAAuC;AAC7C,SAAOA,KAAK,CAACqC,iBAAb;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\nimport { select } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetBlockRootClientId,\n\tgetTemplateLock,\n\tgetBlockName,\n\tgetBlockOrder,\n\tgetBlockParents,\n} from './selectors';\n\n/**\n * Returns true if the block interface is hidden, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the block toolbar is hidden.\n */\nexport function isBlockInterfaceHidden( state ) {\n\treturn state.isBlockInterfaceHidden;\n}\n\n/**\n * Gets the client ids of the last inserted blocks.\n *\n * @param {Object} state Global application state.\n * @return {Array|undefined} Client Ids of the last inserted block(s).\n */\nexport function getLastInsertedBlocksClientIds( state ) {\n\treturn state?.lastBlockInserted?.clientIds;\n}\n\n/**\n * @typedef {import('../components/block-editing-mode').BlockEditingMode} BlockEditingMode\n */\n\n/**\n * Returns the block editing mode for a given block.\n *\n * The mode can be one of three options:\n *\n * - `'disabled'`: Prevents editing the block entirely, i.e. it cannot be\n * selected.\n * - `'contentOnly'`: Hides all non-content UI, e.g. auxiliary controls in the\n * toolbar, the block movers, block settings.\n * - `'default'`: Allows editing the block as normal.\n *\n * Blocks can set a mode using the `useBlockEditingMode` hook.\n *\n * The mode is inherited by all of the block's inner blocks, unless they have\n * their own mode.\n *\n * A template lock can also set a mode. If the template lock is `'contentOnly'`,\n * the block's mode is overridden to `'contentOnly'` if the block has a content\n * role attribute, or `'disabled'` otherwise.\n *\n * @see useBlockEditingMode\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID, or `''` for the root container.\n *\n * @return {BlockEditingMode} The block editing mode. One of `'disabled'`,\n * `'contentOnly'`, or `'default'`.\n */\nexport function getBlockEditingMode( state, clientId = '' ) {\n\tif ( state.blockEditingModes.has( clientId ) ) {\n\t\treturn state.blockEditingModes.get( clientId );\n\t}\n\tif ( ! clientId ) {\n\t\treturn 'default';\n\t}\n\tconst rootClientId = getBlockRootClientId( state, clientId );\n\tconst templateLock = getTemplateLock( state, rootClientId );\n\tif ( templateLock === 'contentOnly' ) {\n\t\tconst name = getBlockName( state, clientId );\n\t\t// TODO: Terrible hack! We're calling the global select() function\n\t\t// here instead of using createRegistrySelector(). The problem with\n\t\t// using createRegistrySelector() is that then the public\n\t\t// block-editor selectors (e.g. canInsertBlockTypeUnmemoized) can't\n\t\t// call this private block-editor selector due to a bug in\n\t\t// @wordpress/data. See\n\t\t// https://github.com/WordPress/gutenberg/pull/50985.\n\t\tconst isContent =\n\t\t\tselect( blocksStore ).__experimentalHasContentRoleAttribute( name );\n\t\treturn isContent ? 'contentOnly' : 'disabled';\n\t}\n\tconst parentMode = getBlockEditingMode( state, rootClientId );\n\treturn parentMode === 'contentOnly' ? 'default' : parentMode;\n}\n\n/**\n * Returns true if the block with the given client ID and all of its descendants\n * have an editing mode of 'disabled', or false otherwise.\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n *\n * @return {boolean} Whether the block and its descendants are disabled.\n */\nexport const isBlockSubtreeDisabled = createSelector(\n\t( state, clientId ) => {\n\t\tconst isChildSubtreeDisabled = ( childClientId ) => {\n\t\t\tconst mode = state.blockEditingModes.get( childClientId );\n\t\t\treturn (\n\t\t\t\t( mode === undefined || mode === 'disabled' ) &&\n\t\t\t\tgetBlockOrder( state, childClientId ).every(\n\t\t\t\t\tisChildSubtreeDisabled\n\t\t\t\t)\n\t\t\t);\n\t\t};\n\t\treturn (\n\t\t\tgetBlockEditingMode( state, clientId ) === 'disabled' &&\n\t\t\tgetBlockOrder( state, clientId ).every( isChildSubtreeDisabled )\n\t\t);\n\t},\n\t( state ) => [ state.blockEditingModes, state.blocks.parents ]\n);\n\n/**\n * Returns a tree of block objects with only clientID and innerBlocks set.\n * Blocks with a 'disabled' editing mode are not included.\n *\n * @param {Object} state Global application state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Object[]} Tree of block objects with only clientID and innerBlocks set.\n */\nexport const getEnabledClientIdsTree = createSelector(\n\t( state, rootClientId = '' ) => {\n\t\treturn getBlockOrder( state, rootClientId ).flatMap( ( clientId ) => {\n\t\t\tif ( getBlockEditingMode( state, clientId ) !== 'disabled' ) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tinnerBlocks: getEnabledClientIdsTree( state, clientId ),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn getEnabledClientIdsTree( state, clientId );\n\t\t} );\n\t},\n\t( state ) => [\n\t\tstate.blocks.order,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Returns a list of a given block's ancestors, from top to bottom. Blocks with\n * a 'disabled' editing mode are excluded.\n *\n * @see getBlockParents\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n * @param {boolean} ascending Order results from bottom to top (true) or top\n * to bottom (false).\n */\nexport const getEnabledBlockParents = createSelector(\n\t( state, clientId, ascending = false ) => {\n\t\treturn getBlockParents( state, clientId, ascending ).filter(\n\t\t\t( parent ) => getBlockEditingMode( state, parent ) !== 'disabled'\n\t\t);\n\t},\n\t( state ) => [\n\t\tstate.blocks.parents,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Selector that returns the data needed to display a prompt when certain\n * blocks are removed, or `false` if no such prompt is requested.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object|false} Data for removal prompt display, if any.\n */\nexport function getRemovalPromptData( state ) {\n\treturn state.removalPromptData;\n}\n\n/**\n * Returns true if removal prompt exists, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether removal prompt exists.\n */\nexport function getBlockRemovalRules( state ) {\n\treturn state.blockRemovalRules;\n}\n"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -1455,7 +1455,7 @@ function isSelectionEnabled(state = true, action) {
|
|
|
1455
1455
|
|
|
1456
1456
|
function removalPromptData(state = false, action) {
|
|
1457
1457
|
switch (action.type) {
|
|
1458
|
-
case '
|
|
1458
|
+
case 'DISPLAY_BLOCK_REMOVAL_PROMPT':
|
|
1459
1459
|
const {
|
|
1460
1460
|
clientIds,
|
|
1461
1461
|
selectPrevious,
|
|
@@ -1467,26 +1467,34 @@ function removalPromptData(state = false, action) {
|
|
|
1467
1467
|
blockNamesForPrompt
|
|
1468
1468
|
};
|
|
1469
1469
|
|
|
1470
|
-
case '
|
|
1470
|
+
case 'CLEAR_BLOCK_REMOVAL_PROMPT':
|
|
1471
1471
|
return false;
|
|
1472
1472
|
}
|
|
1473
1473
|
|
|
1474
1474
|
return state;
|
|
1475
1475
|
}
|
|
1476
1476
|
/**
|
|
1477
|
-
* Reducer
|
|
1477
|
+
* Reducer returning any rules that a block editor may provide in order to
|
|
1478
|
+
* prevent a user from accidentally removing certain blocks. These rules are
|
|
1479
|
+
* then used to display a confirmation prompt to the user. For instance, in the
|
|
1480
|
+
* Site Editor, the Query Loop block is important enough to warrant such
|
|
1481
|
+
* confirmation.
|
|
1482
|
+
*
|
|
1483
|
+
* The data is a record whose keys are block types (e.g. 'core/query') and
|
|
1484
|
+
* whose values are the explanation to be shown to users (e.g. 'Query Loop
|
|
1485
|
+
* displays a list of posts or pages.').
|
|
1478
1486
|
*
|
|
1479
1487
|
* @param {boolean} state Current state.
|
|
1480
1488
|
* @param {Object} action Dispatched action.
|
|
1481
1489
|
*
|
|
1482
|
-
* @return {
|
|
1490
|
+
* @return {Record<string,string>} Updated state.
|
|
1483
1491
|
*/
|
|
1484
1492
|
|
|
1485
1493
|
|
|
1486
|
-
function
|
|
1494
|
+
function blockRemovalRules(state = false, action) {
|
|
1487
1495
|
switch (action.type) {
|
|
1488
|
-
case '
|
|
1489
|
-
return action.
|
|
1496
|
+
case 'SET_BLOCK_REMOVAL_RULES':
|
|
1497
|
+
return action.rules;
|
|
1490
1498
|
}
|
|
1491
1499
|
|
|
1492
1500
|
return state;
|
|
@@ -1922,7 +1930,7 @@ const combinedReducers = (0, _data.combineReducers)({
|
|
|
1922
1930
|
blockVisibility,
|
|
1923
1931
|
blockEditingModes,
|
|
1924
1932
|
removalPromptData,
|
|
1925
|
-
|
|
1933
|
+
blockRemovalRules
|
|
1926
1934
|
});
|
|
1927
1935
|
|
|
1928
1936
|
function withAutomaticChangeReset(reducer) {
|