@wordpress/block-editor 12.22.0 → 12.23.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/README.md +4 -0
- package/build/components/block-list/block.js +11 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-mover/button.js +4 -1
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +5 -1
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +4 -1
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +7 -3
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/index.js +4 -3
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +5 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/shuffle.js +18 -9
- package/build/components/block-toolbar/shuffle.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +48 -8
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +14 -2
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/global-styles/advanced-panel.js +9 -2
- package/build/components/global-styles/advanced-panel.js.map +1 -1
- package/build/components/global-styles/background-panel.js +444 -0
- package/build/components/global-styles/background-panel.js.map +1 -0
- package/build/components/global-styles/color-panel.js +2 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/get-global-styles-changes.js +3 -0
- package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +13 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +15 -14
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/iframe/index.js +9 -4
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
- package/build/components/inserter/library.js +2 -0
- package/build/components/inserter/library.js.map +1 -1
- package/build/components/inserter/menu.js +8 -2
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-items.js +36 -15
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +11 -0
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +16 -0
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +1 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/index.js +17 -2
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-collapse-items.js +47 -0
- package/build/components/list-view/use-list-view-collapse-items.js.map +1 -0
- package/build/components/rich-text/index.js +14 -11
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +17 -11
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/native/get-format-colors.native.js +1 -1
- package/build/components/rich-text/native/get-format-colors.native.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +2 -2
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/rich-text/with-deprecations.js +0 -3
- package/build/components/rich-text/with-deprecations.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +50 -36
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/use-block-display-information/index.js +4 -6
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/hooks/anchor.js +2 -2
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/background.js +70 -424
- package/build/hooks/background.js.map +1 -1
- package/build/hooks/index.js +7 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-zoom-out.js +47 -0
- package/build/hooks/use-zoom-out.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/private-apis.js +6 -1
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +3 -1
- package/build/private-apis.native.js.map +1 -1
- package/build/store/private-actions.js +13 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-keys.js +2 -1
- package/build/store/private-keys.js.map +1 -1
- package/build/store/private-selectors.js +24 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +22 -0
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +34 -32
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +7 -1
- package/build/store/utils.js.map +1 -1
- package/build/utils/transform-styles/index.js +2 -1
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-list/block.js +11 -3
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-mover/button.js +4 -1
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +5 -1
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +4 -1
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +7 -3
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/index.js +4 -3
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +5 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/shuffle.js +18 -9
- package/build-module/components/block-toolbar/shuffle.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +50 -10
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +14 -2
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/global-styles/advanced-panel.js +9 -2
- package/build-module/components/global-styles/advanced-panel.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +430 -0
- package/build-module/components/global-styles/background-panel.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +2 -1
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/get-global-styles-changes.js +3 -0
- package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +1 -0
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +16 -15
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/iframe/index.js +9 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
- package/build-module/components/inserter/library.js +2 -0
- package/build-module/components/inserter/library.js.map +1 -1
- package/build-module/components/inserter/menu.js +8 -2
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-items.js +33 -15
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +11 -0
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +16 -0
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +1 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/index.js +17 -2
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-collapse-items.js +40 -0
- package/build-module/components/list-view/use-list-view-collapse-items.js.map +1 -0
- package/build-module/components/rich-text/index.js +15 -12
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +16 -11
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/native/get-format-colors.native.js +1 -1
- package/build-module/components/rich-text/native/get-format-colors.native.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +2 -2
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/rich-text/with-deprecations.js +0 -3
- package/build-module/components/rich-text/with-deprecations.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +50 -36
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +5 -7
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/hooks/anchor.js +2 -2
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/background.js +67 -419
- package/build-module/hooks/background.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-zoom-out.js +41 -0
- package/build-module/hooks/use-zoom-out.js.map +1 -0
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/private-apis.js +7 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +3 -1
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/private-actions.js +12 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-keys.js +1 -0
- package/build-module/store/private-keys.js.map +1 -1
- package/build-module/store/private-selectors.js +22 -4
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +21 -0
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +35 -33
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +6 -1
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +2 -1
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +4 -1
- package/build-style/content.css +4 -1
- package/build-style/style-rtl.css +84 -79
- package/build-style/style.css +84 -79
- package/package.json +31 -31
- package/src/components/block-list/block.js +19 -3
- package/src/components/block-mover/button.js +4 -1
- package/src/components/block-mover/index.js +8 -1
- package/src/components/block-patterns-list/index.js +22 -17
- package/src/components/block-preview/style.scss +28 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +8 -2
- package/src/components/block-switcher/index.js +5 -3
- package/src/components/block-switcher/style.scss +1 -1
- package/src/components/block-toolbar/index.js +22 -19
- package/src/components/block-toolbar/shuffle.js +19 -13
- package/src/components/block-toolbar/style.scss +1 -1
- package/src/components/block-tools/block-selection-button.js +66 -9
- package/src/components/block-tools/index.js +18 -1
- package/src/components/button-block-appender/content.scss +5 -1
- package/src/components/default-block-appender/content.scss +2 -2
- package/src/components/global-styles/advanced-panel.js +8 -2
- package/src/components/global-styles/background-panel.js +591 -0
- package/src/components/global-styles/color-panel.js +2 -1
- package/src/components/global-styles/get-global-styles-changes.js +3 -0
- package/src/components/global-styles/hooks.js +1 -0
- package/src/components/global-styles/index.js +4 -0
- package/src/components/global-styles/style.scss +78 -1
- package/src/{hooks/test/background.js → components/global-styles/test/background-panel.js} +36 -1
- package/src/components/global-styles/test/get-global-styles-changes.js +22 -3
- package/src/components/global-styles/test/use-global-styles-output.js +9 -9
- package/src/components/global-styles/use-global-styles-output.js +27 -16
- package/src/components/global-styles/utils.js +1 -0
- package/src/components/iframe/index.js +19 -9
- package/src/components/inserter/block-patterns-tab/index.js +1 -0
- package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
- package/src/components/inserter/library.js +4 -0
- package/src/components/inserter/menu.js +8 -1
- package/src/components/inserter/search-items.js +37 -15
- package/src/components/inserter/style.scss +6 -12
- package/src/components/keyboard-shortcuts/index.js +11 -0
- package/src/components/list-view/block-select-button.js +13 -1
- package/src/components/list-view/block.js +1 -1
- package/src/components/list-view/index.js +18 -1
- package/src/components/list-view/style.scss +4 -4
- package/src/components/list-view/use-list-view-collapse-items.js +33 -0
- package/src/components/rich-text/index.js +30 -13
- package/src/components/rich-text/index.native.js +14 -11
- package/src/components/rich-text/native/get-format-colors.native.js +1 -1
- package/src/components/rich-text/native/index.native.js +2 -2
- package/src/components/rich-text/with-deprecations.js +0 -3
- package/src/components/url-popover/image-url-input-ui.js +68 -51
- package/src/components/use-block-display-information/index.js +8 -10
- package/src/hooks/anchor.js +11 -9
- package/src/hooks/background.js +77 -538
- package/src/hooks/index.js +1 -0
- package/src/hooks/use-zoom-out.js +36 -0
- package/src/index.js +1 -0
- package/src/private-apis.js +13 -1
- package/src/private-apis.native.js +2 -0
- package/src/store/private-actions.js +12 -0
- package/src/store/private-keys.js +1 -0
- package/src/store/private-selectors.js +54 -27
- package/src/store/reducer.js +22 -0
- package/src/store/selectors.js +195 -180
- package/src/store/test/private-actions.js +10 -0
- package/src/store/test/private-selectors.js +13 -0
- package/src/store/test/reducer.js +26 -0
- package/src/store/test/selectors.js +90 -199
- package/src/store/utils.js +13 -0
- package/src/style.scss +0 -2
- package/src/utils/transform-styles/index.js +2 -1
- package/src/hooks/anchor.scss +0 -4
- package/src/hooks/background.scss +0 -75
package/src/store/selectors.js
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
checkAllowListRecursive,
|
|
31
31
|
checkAllowList,
|
|
32
32
|
getAllPatternsDependants,
|
|
33
|
+
getInsertBlockTypeDependants,
|
|
33
34
|
} from './utils';
|
|
34
35
|
import { orderBy } from '../utils/sorting';
|
|
35
36
|
import { STORE_NAME } from './constants';
|
|
@@ -1235,11 +1236,22 @@ export function isBlockSelected( state, clientId ) {
|
|
|
1235
1236
|
* @return {boolean} Whether the block has an inner block selected
|
|
1236
1237
|
*/
|
|
1237
1238
|
export function hasSelectedInnerBlock( state, clientId, deep = false ) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1239
|
+
const selectedBlockClientIds = getSelectedBlockClientIds( state );
|
|
1240
|
+
|
|
1241
|
+
if ( ! selectedBlockClientIds.length ) {
|
|
1242
|
+
return false;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
if ( deep ) {
|
|
1246
|
+
return selectedBlockClientIds.some( ( id ) =>
|
|
1247
|
+
// Pass true because we don't care about order and it's more
|
|
1248
|
+
// performant.
|
|
1249
|
+
getBlockParents( state, id, true ).includes( clientId )
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
return selectedBlockClientIds.some(
|
|
1254
|
+
( id ) => getBlockRootClientId( state, id ) === clientId
|
|
1243
1255
|
);
|
|
1244
1256
|
}
|
|
1245
1257
|
|
|
@@ -1666,13 +1678,8 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1666
1678
|
*/
|
|
1667
1679
|
export const canInsertBlockType = createSelector(
|
|
1668
1680
|
canInsertBlockTypeUnmemoized,
|
|
1669
|
-
( state, blockName, rootClientId ) =>
|
|
1670
|
-
state
|
|
1671
|
-
state.blocks.byClientId.get( rootClientId ),
|
|
1672
|
-
state.settings.allowedBlockTypes,
|
|
1673
|
-
state.settings.templateLock,
|
|
1674
|
-
state.blockEditingModes,
|
|
1675
|
-
]
|
|
1681
|
+
( state, blockName, rootClientId ) =>
|
|
1682
|
+
getInsertBlockTypeDependants( state, rootClientId )
|
|
1676
1683
|
);
|
|
1677
1684
|
|
|
1678
1685
|
/**
|
|
@@ -1977,95 +1984,108 @@ const buildBlockTypeItem =
|
|
|
1977
1984
|
* this item.
|
|
1978
1985
|
* @property {number} frecency Heuristic that combines frequency and recency.
|
|
1979
1986
|
*/
|
|
1980
|
-
export const getInserterItems =
|
|
1981
|
-
(
|
|
1982
|
-
|
|
1983
|
-
const
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
1987
|
+
export const getInserterItems = createRegistrySelector( ( select ) =>
|
|
1988
|
+
createSelector(
|
|
1989
|
+
( state, rootClientId = null ) => {
|
|
1990
|
+
const buildReusableBlockInserterItem = ( reusableBlock ) => {
|
|
1991
|
+
const icon = ! reusableBlock.wp_pattern_sync_status
|
|
1992
|
+
? {
|
|
1993
|
+
src: symbol,
|
|
1994
|
+
foreground: 'var(--wp-block-synced-color)',
|
|
1995
|
+
}
|
|
1996
|
+
: symbol;
|
|
1997
|
+
const id = `core/block/${ reusableBlock.id }`;
|
|
1998
|
+
const { time, count = 0 } = getInsertUsage( state, id ) || {};
|
|
1999
|
+
const frecency = calculateFrecency( time, count );
|
|
2000
|
+
|
|
2001
|
+
return {
|
|
2002
|
+
id,
|
|
2003
|
+
name: 'core/block',
|
|
2004
|
+
initialAttributes: { ref: reusableBlock.id },
|
|
2005
|
+
title: reusableBlock.title?.raw,
|
|
2006
|
+
icon,
|
|
2007
|
+
category: 'reusable',
|
|
2008
|
+
keywords: [ 'reusable' ],
|
|
2009
|
+
isDisabled: false,
|
|
2010
|
+
utility: 1, // Deprecated.
|
|
2011
|
+
frecency,
|
|
2012
|
+
content: reusableBlock.content?.raw,
|
|
2013
|
+
syncStatus: reusableBlock.wp_pattern_sync_status,
|
|
2014
|
+
};
|
|
2006
2015
|
};
|
|
2007
|
-
};
|
|
2008
|
-
|
|
2009
|
-
const syncedPatternInserterItems = canInsertBlockTypeUnmemoized(
|
|
2010
|
-
state,
|
|
2011
|
-
'core/block',
|
|
2012
|
-
rootClientId
|
|
2013
|
-
)
|
|
2014
|
-
? getReusableBlocks( state ).map( buildReusableBlockInserterItem )
|
|
2015
|
-
: [];
|
|
2016
2016
|
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
const blockTypeInserterItems = getBlockTypes()
|
|
2022
|
-
.filter( ( blockType ) =>
|
|
2023
|
-
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
|
|
2017
|
+
const syncedPatternInserterItems = canInsertBlockTypeUnmemoized(
|
|
2018
|
+
state,
|
|
2019
|
+
'core/block',
|
|
2020
|
+
rootClientId
|
|
2024
2021
|
)
|
|
2025
|
-
|
|
2022
|
+
? unlock( select( STORE_NAME ) )
|
|
2023
|
+
.getReusableBlocks()
|
|
2024
|
+
.map( buildReusableBlockInserterItem )
|
|
2025
|
+
: [];
|
|
2026
2026
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
if ( ! variations.some( ( { isDefault } ) => isDefault ) ) {
|
|
2031
|
-
accumulator.push( item );
|
|
2032
|
-
}
|
|
2033
|
-
if ( variations.length ) {
|
|
2034
|
-
const variationMapper = getItemFromVariation( state, item );
|
|
2035
|
-
accumulator.push( ...variations.map( variationMapper ) );
|
|
2036
|
-
}
|
|
2037
|
-
return accumulator;
|
|
2038
|
-
}, [] );
|
|
2027
|
+
const buildBlockTypeInserterItem = buildBlockTypeItem( state, {
|
|
2028
|
+
buildScope: 'inserter',
|
|
2029
|
+
} );
|
|
2039
2030
|
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2031
|
+
const blockTypeInserterItems = getBlockTypes()
|
|
2032
|
+
.filter( ( blockType ) =>
|
|
2033
|
+
canIncludeBlockTypeInInserter(
|
|
2034
|
+
state,
|
|
2035
|
+
blockType,
|
|
2036
|
+
rootClientId
|
|
2037
|
+
)
|
|
2038
|
+
)
|
|
2039
|
+
.map( buildBlockTypeInserterItem );
|
|
2040
|
+
|
|
2041
|
+
const items = blockTypeInserterItems.reduce(
|
|
2042
|
+
( accumulator, item ) => {
|
|
2043
|
+
const { variations = [] } = item;
|
|
2044
|
+
// Exclude any block type item that is to be replaced by a default variation.
|
|
2045
|
+
if ( ! variations.some( ( { isDefault } ) => isDefault ) ) {
|
|
2046
|
+
accumulator.push( item );
|
|
2047
|
+
}
|
|
2048
|
+
if ( variations.length ) {
|
|
2049
|
+
const variationMapper = getItemFromVariation(
|
|
2050
|
+
state,
|
|
2051
|
+
item
|
|
2052
|
+
);
|
|
2053
|
+
accumulator.push(
|
|
2054
|
+
...variations.map( variationMapper )
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
return accumulator;
|
|
2058
|
+
},
|
|
2059
|
+
[]
|
|
2060
|
+
);
|
|
2061
|
+
|
|
2062
|
+
// Ensure core blocks are prioritized in the returned results,
|
|
2063
|
+
// because third party blocks can be registered earlier than
|
|
2064
|
+
// the core blocks (usually by using the `init` action),
|
|
2065
|
+
// thus affecting the display order.
|
|
2066
|
+
// We don't sort reusable blocks as they are handled differently.
|
|
2067
|
+
const groupByType = ( blocks, block ) => {
|
|
2068
|
+
const { core, noncore } = blocks;
|
|
2069
|
+
const type = block.name.startsWith( 'core/' ) ? core : noncore;
|
|
2070
|
+
|
|
2071
|
+
type.push( block );
|
|
2072
|
+
return blocks;
|
|
2073
|
+
};
|
|
2074
|
+
const { core: coreItems, noncore: nonCoreItems } = items.reduce(
|
|
2075
|
+
groupByType,
|
|
2076
|
+
{ core: [], noncore: [] }
|
|
2077
|
+
);
|
|
2078
|
+
const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ];
|
|
2079
|
+
return [ ...sortedBlockTypes, ...syncedPatternInserterItems ];
|
|
2080
|
+
},
|
|
2081
|
+
( state, rootClientId ) => [
|
|
2082
|
+
getBlockTypes(),
|
|
2083
|
+
unlock( select( STORE_NAME ) ).getReusableBlocks(),
|
|
2084
|
+
state.blocks.order,
|
|
2085
|
+
state.preferences.insertUsage,
|
|
2086
|
+
...getInsertBlockTypeDependants( state, rootClientId ),
|
|
2087
|
+
]
|
|
2088
|
+
)
|
|
2069
2089
|
);
|
|
2070
2090
|
|
|
2071
2091
|
/**
|
|
@@ -2128,12 +2148,9 @@ export const getBlockTransformItems = createSelector(
|
|
|
2128
2148
|
);
|
|
2129
2149
|
},
|
|
2130
2150
|
( state, blocks, rootClientId ) => [
|
|
2131
|
-
state.blockListSettings[ rootClientId ],
|
|
2132
|
-
state.blocks.byClientId.get( rootClientId ),
|
|
2133
|
-
state.preferences.insertUsage,
|
|
2134
|
-
state.settings.allowedBlockTypes,
|
|
2135
|
-
state.settings.templateLock,
|
|
2136
2151
|
getBlockTypes(),
|
|
2152
|
+
state.preferences.insertUsage,
|
|
2153
|
+
...getInsertBlockTypeDependants( state, rootClientId ),
|
|
2137
2154
|
]
|
|
2138
2155
|
);
|
|
2139
2156
|
|
|
@@ -2145,28 +2162,25 @@ export const getBlockTransformItems = createSelector(
|
|
|
2145
2162
|
*
|
|
2146
2163
|
* @return {boolean} Items that appear in inserter.
|
|
2147
2164
|
*/
|
|
2148
|
-
export const hasInserterItems =
|
|
2149
|
-
(
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2165
|
+
export const hasInserterItems = createRegistrySelector(
|
|
2166
|
+
( select ) =>
|
|
2167
|
+
( state, rootClientId = null ) => {
|
|
2168
|
+
const hasBlockType = getBlockTypes().some( ( blockType ) =>
|
|
2169
|
+
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
|
|
2170
|
+
);
|
|
2171
|
+
if ( hasBlockType ) {
|
|
2172
|
+
return true;
|
|
2173
|
+
}
|
|
2174
|
+
const hasReusableBlock =
|
|
2175
|
+
canInsertBlockTypeUnmemoized(
|
|
2176
|
+
state,
|
|
2177
|
+
'core/block',
|
|
2178
|
+
rootClientId
|
|
2179
|
+
) &&
|
|
2180
|
+
unlock( select( STORE_NAME ) ).getReusableBlocks().length > 0;
|
|
2159
2181
|
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
( state, rootClientId ) => [
|
|
2163
|
-
state.blockListSettings[ rootClientId ],
|
|
2164
|
-
state.blocks.byClientId.get( rootClientId ),
|
|
2165
|
-
state.settings.allowedBlockTypes,
|
|
2166
|
-
state.settings.templateLock,
|
|
2167
|
-
getReusableBlocks( state ),
|
|
2168
|
-
getBlockTypes(),
|
|
2169
|
-
]
|
|
2182
|
+
return hasReusableBlock;
|
|
2183
|
+
}
|
|
2170
2184
|
);
|
|
2171
2185
|
|
|
2172
2186
|
/**
|
|
@@ -2177,34 +2191,37 @@ export const hasInserterItems = createSelector(
|
|
|
2177
2191
|
*
|
|
2178
2192
|
* @return {Array?} The list of allowed block types.
|
|
2179
2193
|
*/
|
|
2180
|
-
export const getAllowedBlocks =
|
|
2181
|
-
(
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2194
|
+
export const getAllowedBlocks = createRegistrySelector( ( select ) =>
|
|
2195
|
+
createSelector(
|
|
2196
|
+
( state, rootClientId = null ) => {
|
|
2197
|
+
if ( ! rootClientId ) {
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2185
2200
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2201
|
+
const blockTypes = getBlockTypes().filter( ( blockType ) =>
|
|
2202
|
+
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
|
|
2203
|
+
);
|
|
2189
2204
|
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2205
|
+
const hasReusableBlock =
|
|
2206
|
+
canInsertBlockTypeUnmemoized(
|
|
2207
|
+
state,
|
|
2208
|
+
'core/block',
|
|
2209
|
+
rootClientId
|
|
2210
|
+
) &&
|
|
2211
|
+
unlock( select( STORE_NAME ) ).getReusableBlocks().length > 0;
|
|
2193
2212
|
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2213
|
+
if ( hasReusableBlock ) {
|
|
2214
|
+
blockTypes.push( 'core/block' );
|
|
2215
|
+
}
|
|
2197
2216
|
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
getBlockTypes(),
|
|
2207
|
-
]
|
|
2217
|
+
return blockTypes;
|
|
2218
|
+
},
|
|
2219
|
+
( state, rootClientId ) => [
|
|
2220
|
+
getBlockTypes(),
|
|
2221
|
+
unlock( select( STORE_NAME ) ).getReusableBlocks(),
|
|
2222
|
+
...getInsertBlockTypeDependants( state, rootClientId ),
|
|
2223
|
+
]
|
|
2224
|
+
)
|
|
2208
2225
|
);
|
|
2209
2226
|
|
|
2210
2227
|
export const __experimentalGetAllowedBlocks = createSelector(
|
|
@@ -2220,9 +2237,8 @@ export const __experimentalGetAllowedBlocks = createSelector(
|
|
|
2220
2237
|
);
|
|
2221
2238
|
return getAllowedBlocks( state, rootClientId );
|
|
2222
2239
|
},
|
|
2223
|
-
( state, rootClientId ) =>
|
|
2224
|
-
|
|
2225
|
-
]
|
|
2240
|
+
( state, rootClientId ) =>
|
|
2241
|
+
getAllowedBlocks.getDependants( state, rootClientId )
|
|
2226
2242
|
);
|
|
2227
2243
|
|
|
2228
2244
|
/**
|
|
@@ -2287,6 +2303,10 @@ export const __experimentalGetParsedPattern = createRegistrySelector(
|
|
|
2287
2303
|
metadata: {
|
|
2288
2304
|
...( blocks[ 0 ].attributes.metadata || {} ),
|
|
2289
2305
|
categories: pattern.categories,
|
|
2306
|
+
patternName: pattern.name,
|
|
2307
|
+
name:
|
|
2308
|
+
blocks[ 0 ].attributes.metadata?.name ||
|
|
2309
|
+
pattern.title,
|
|
2290
2310
|
},
|
|
2291
2311
|
};
|
|
2292
2312
|
}
|
|
@@ -2297,15 +2317,10 @@ export const __experimentalGetParsedPattern = createRegistrySelector(
|
|
|
2297
2317
|
}, getAllPatternsDependants( select ) )
|
|
2298
2318
|
);
|
|
2299
2319
|
|
|
2300
|
-
const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) =>
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
state.settings.templateLock,
|
|
2305
|
-
state.blockListSettings[ rootClientId ],
|
|
2306
|
-
state.blocks.byClientId.get( rootClientId ),
|
|
2307
|
-
];
|
|
2308
|
-
};
|
|
2320
|
+
const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => [
|
|
2321
|
+
...getAllPatternsDependants( select )( state ),
|
|
2322
|
+
...getInsertBlockTypeDependants( state, rootClientId ),
|
|
2323
|
+
];
|
|
2309
2324
|
|
|
2310
2325
|
/**
|
|
2311
2326
|
* Returns the list of allowed patterns for inner blocks children.
|
|
@@ -2526,18 +2541,29 @@ export const __experimentalGetBlockListSettingsForBlocks = createSelector(
|
|
|
2526
2541
|
*
|
|
2527
2542
|
* @return {string} The reusable block saved title.
|
|
2528
2543
|
*/
|
|
2529
|
-
export const __experimentalGetReusableBlockTitle =
|
|
2530
|
-
(
|
|
2531
|
-
|
|
2532
|
-
(
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2544
|
+
export const __experimentalGetReusableBlockTitle = createRegistrySelector(
|
|
2545
|
+
( select ) =>
|
|
2546
|
+
createSelector(
|
|
2547
|
+
( state, ref ) => {
|
|
2548
|
+
deprecated(
|
|
2549
|
+
"wp.data.select( 'core/block-editor' ).__experimentalGetReusableBlockTitle",
|
|
2550
|
+
{
|
|
2551
|
+
since: '6.6',
|
|
2552
|
+
version: '6.8',
|
|
2553
|
+
}
|
|
2554
|
+
);
|
|
2537
2555
|
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2556
|
+
const reusableBlock = unlock( select( STORE_NAME ) )
|
|
2557
|
+
.getReusableBlocks()
|
|
2558
|
+
.find( ( block ) => block.id === ref );
|
|
2559
|
+
if ( ! reusableBlock ) {
|
|
2560
|
+
return null;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
return reusableBlock.title?.raw;
|
|
2564
|
+
},
|
|
2565
|
+
() => [ unlock( select( STORE_NAME ) ).getReusableBlocks() ]
|
|
2566
|
+
)
|
|
2541
2567
|
);
|
|
2542
2568
|
|
|
2543
2569
|
/**
|
|
@@ -2571,17 +2597,6 @@ export function __experimentalGetLastBlockAttributeChanges( state ) {
|
|
|
2571
2597
|
return state.lastBlockAttributesChange;
|
|
2572
2598
|
}
|
|
2573
2599
|
|
|
2574
|
-
/**
|
|
2575
|
-
* Returns the available reusable blocks
|
|
2576
|
-
*
|
|
2577
|
-
* @param {Object} state Global application state.
|
|
2578
|
-
*
|
|
2579
|
-
* @return {Array} Reusable blocks
|
|
2580
|
-
*/
|
|
2581
|
-
function getReusableBlocks( state ) {
|
|
2582
|
-
return state.settings.__experimentalReusableBlocks ?? EMPTY_ARRAY;
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
2600
|
/**
|
|
2586
2601
|
* Returns whether the navigation mode is enabled.
|
|
2587
2602
|
*
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import {
|
|
5
5
|
hideBlockInterface,
|
|
6
6
|
showBlockInterface,
|
|
7
|
+
expandBlock,
|
|
7
8
|
__experimentalUpdateSettings,
|
|
8
9
|
setOpenedBlockSettingsMenu,
|
|
9
10
|
startDragging,
|
|
@@ -113,4 +114,13 @@ describe( 'private actions', () => {
|
|
|
113
114
|
} );
|
|
114
115
|
} );
|
|
115
116
|
} );
|
|
117
|
+
|
|
118
|
+
describe( 'expandBlock', () => {
|
|
119
|
+
it( 'should return the SET_BLOCK_EXPANDED_IN_LIST_VIEW action', () => {
|
|
120
|
+
expect( expandBlock( 'block-1' ) ).toEqual( {
|
|
121
|
+
type: 'SET_BLOCK_EXPANDED_IN_LIST_VIEW',
|
|
122
|
+
clientId: 'block-1',
|
|
123
|
+
} );
|
|
124
|
+
} );
|
|
125
|
+
} );
|
|
116
126
|
} );
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
isBlockSubtreeDisabled,
|
|
8
8
|
getEnabledClientIdsTree,
|
|
9
9
|
getEnabledBlockParents,
|
|
10
|
+
getExpandedBlock,
|
|
10
11
|
isDragging,
|
|
11
12
|
} from '../private-selectors';
|
|
12
13
|
import { getBlockEditingMode } from '../selectors';
|
|
@@ -496,4 +497,16 @@ describe( 'private selectors', () => {
|
|
|
496
497
|
expect( isDragging( state ) ).toBe( false );
|
|
497
498
|
} );
|
|
498
499
|
} );
|
|
500
|
+
|
|
501
|
+
describe( 'getExpandedBlock', () => {
|
|
502
|
+
it( 'should return the expanded block', () => {
|
|
503
|
+
const state = {
|
|
504
|
+
expandedBlock: '9b9c5c3f-2e46-4f02-9e14-9fe9515b958f',
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
expect( getExpandedBlock( state ) ).toBe(
|
|
508
|
+
'9b9c5c3f-2e46-4f02-9e14-9fe9515b958f'
|
|
509
|
+
);
|
|
510
|
+
} );
|
|
511
|
+
} );
|
|
499
512
|
} );
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
lastBlockInserted,
|
|
36
36
|
blockEditingModes,
|
|
37
37
|
openedBlockSettingsMenu,
|
|
38
|
+
expandedBlock,
|
|
38
39
|
} from '../reducer';
|
|
39
40
|
|
|
40
41
|
const noop = () => {};
|
|
@@ -3459,4 +3460,29 @@ describe( 'state', () => {
|
|
|
3459
3460
|
expect( state ).toBe( null );
|
|
3460
3461
|
} );
|
|
3461
3462
|
} );
|
|
3463
|
+
|
|
3464
|
+
describe( 'expandedBlock', () => {
|
|
3465
|
+
it( 'should return null by default', () => {
|
|
3466
|
+
expect( expandedBlock( undefined, {} ) ).toBe( null );
|
|
3467
|
+
} );
|
|
3468
|
+
|
|
3469
|
+
it( 'should set client id for expanded block', () => {
|
|
3470
|
+
const state = expandedBlock( null, {
|
|
3471
|
+
type: 'SET_BLOCK_EXPANDED_IN_LIST_VIEW',
|
|
3472
|
+
clientId: '14501cc2-90a6-4f52-aa36-ab6e896135d1',
|
|
3473
|
+
} );
|
|
3474
|
+
expect( state ).toBe( '14501cc2-90a6-4f52-aa36-ab6e896135d1' );
|
|
3475
|
+
} );
|
|
3476
|
+
|
|
3477
|
+
it( 'should clear the state when a block is selected', () => {
|
|
3478
|
+
const state = expandedBlock(
|
|
3479
|
+
'14501cc2-90a6-4f52-aa36-ab6e896135d1',
|
|
3480
|
+
{
|
|
3481
|
+
type: 'SELECT_BLOCK',
|
|
3482
|
+
clientId: 'a-different-block',
|
|
3483
|
+
}
|
|
3484
|
+
);
|
|
3485
|
+
expect( state ).toBe( null );
|
|
3486
|
+
} );
|
|
3487
|
+
} );
|
|
3462
3488
|
} );
|