@wordpress/block-editor 15.7.1-next.2f1c7c01b.0 → 15.8.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.
Files changed (187) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-card/index.js +76 -34
  3. package/build/components/block-card/index.js.map +2 -2
  4. package/build/components/block-inspector/edit-contents.js +72 -0
  5. package/build/components/block-inspector/edit-contents.js.map +7 -0
  6. package/build/components/block-inspector/index.js +32 -9
  7. package/build/components/block-inspector/index.js.map +3 -3
  8. package/build/components/block-list/index.js +9 -9
  9. package/build/components/block-list/index.js.map +2 -2
  10. package/build/components/block-switcher/index.js +24 -123
  11. package/build/components/block-switcher/index.js.map +3 -3
  12. package/build/components/block-toolbar/block-toolbar-icon.js +175 -0
  13. package/build/components/block-toolbar/block-toolbar-icon.js.map +7 -0
  14. package/build/components/block-toolbar/index.js +51 -53
  15. package/build/components/block-toolbar/index.js.map +3 -3
  16. package/build/components/block-toolbar/pattern-overrides-dropdown.js +93 -0
  17. package/build/components/block-toolbar/pattern-overrides-dropdown.js.map +7 -0
  18. package/build/components/block-tools/index.js +10 -3
  19. package/build/components/block-tools/index.js.map +2 -2
  20. package/build/components/border-radius-control/utils.js +7 -3
  21. package/build/components/border-radius-control/utils.js.map +2 -2
  22. package/build/components/content-lock/modify-content-lock-menu-item.js +3 -3
  23. package/build/components/content-lock/modify-content-lock-menu-item.js.map +2 -2
  24. package/build/components/global-styles/border-panel.js +11 -7
  25. package/build/components/global-styles/border-panel.js.map +2 -2
  26. package/build/components/global-styles/color-panel.js +35 -27
  27. package/build/components/global-styles/color-panel.js.map +2 -2
  28. package/build/components/global-styles/typography-panel.js +3 -2
  29. package/build/components/global-styles/typography-panel.js.map +2 -2
  30. package/build/components/inserter/media-tab/media-tab.js +2 -1
  31. package/build/components/inserter/media-tab/media-tab.js.map +2 -2
  32. package/build/components/inspector-controls-tabs/index.js +2 -1
  33. package/build/components/inspector-controls-tabs/index.js.map +2 -2
  34. package/build/components/inspector-controls-tabs/styles-tab.js +55 -1
  35. package/build/components/inspector-controls-tabs/styles-tab.js.map +3 -3
  36. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  37. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  38. package/build/components/keyboard-shortcuts/index.js +8 -0
  39. package/build/components/keyboard-shortcuts/index.js.map +2 -2
  40. package/build/components/rich-text/index.js +1 -0
  41. package/build/components/rich-text/index.js.map +2 -2
  42. package/build/hooks/border.js +10 -5
  43. package/build/hooks/border.js.map +3 -3
  44. package/build/hooks/color.js +31 -9
  45. package/build/hooks/color.js.map +3 -3
  46. package/build/hooks/content-lock-ui.js +4 -5
  47. package/build/hooks/content-lock-ui.js.map +2 -2
  48. package/build/hooks/dimensions.js +9 -4
  49. package/build/hooks/dimensions.js.map +2 -2
  50. package/build/hooks/fit-text.js +19 -75
  51. package/build/hooks/fit-text.js.map +3 -3
  52. package/build/hooks/font-size.js +5 -2
  53. package/build/hooks/font-size.js.map +2 -2
  54. package/build/hooks/layout.js +4 -1
  55. package/build/hooks/layout.js.map +2 -2
  56. package/build/hooks/spacing-visualizer.js +5 -0
  57. package/build/hooks/spacing-visualizer.js.map +2 -2
  58. package/build/hooks/typography.js +23 -14
  59. package/build/hooks/typography.js.map +3 -3
  60. package/build/store/private-selectors.js +21 -1
  61. package/build/store/private-selectors.js.map +2 -2
  62. package/build/store/reducer.js +4 -0
  63. package/build/store/reducer.js.map +2 -2
  64. package/build/store/selectors.js +9 -3
  65. package/build/store/selectors.js.map +2 -2
  66. package/build/utils/fit-text-frontend.js +1 -0
  67. package/build/utils/fit-text-frontend.js.map +2 -2
  68. package/build/utils/fit-text-utils.js +1 -1
  69. package/build/utils/fit-text-utils.js.map +1 -1
  70. package/build-module/components/block-card/index.js +82 -32
  71. package/build-module/components/block-card/index.js.map +2 -2
  72. package/build-module/components/block-inspector/edit-contents.js +51 -0
  73. package/build-module/components/block-inspector/edit-contents.js.map +7 -0
  74. package/build-module/components/block-inspector/index.js +32 -9
  75. package/build-module/components/block-inspector/index.js.map +2 -2
  76. package/build-module/components/block-list/index.js +11 -11
  77. package/build-module/components/block-list/index.js.map +2 -2
  78. package/build-module/components/block-switcher/index.js +24 -124
  79. package/build-module/components/block-switcher/index.js.map +2 -2
  80. package/build-module/components/block-toolbar/block-toolbar-icon.js +144 -0
  81. package/build-module/components/block-toolbar/block-toolbar-icon.js.map +7 -0
  82. package/build-module/components/block-toolbar/index.js +51 -53
  83. package/build-module/components/block-toolbar/index.js.map +2 -2
  84. package/build-module/components/block-toolbar/pattern-overrides-dropdown.js +76 -0
  85. package/build-module/components/block-toolbar/pattern-overrides-dropdown.js.map +7 -0
  86. package/build-module/components/block-tools/index.js +10 -3
  87. package/build-module/components/block-tools/index.js.map +2 -2
  88. package/build-module/components/border-radius-control/utils.js +7 -3
  89. package/build-module/components/border-radius-control/utils.js.map +2 -2
  90. package/build-module/components/content-lock/modify-content-lock-menu-item.js +3 -3
  91. package/build-module/components/content-lock/modify-content-lock-menu-item.js.map +2 -2
  92. package/build-module/components/global-styles/border-panel.js +11 -7
  93. package/build-module/components/global-styles/border-panel.js.map +2 -2
  94. package/build-module/components/global-styles/color-panel.js +34 -27
  95. package/build-module/components/global-styles/color-panel.js.map +2 -2
  96. package/build-module/components/global-styles/typography-panel.js +3 -2
  97. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  98. package/build-module/components/inserter/media-tab/media-tab.js +2 -1
  99. package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
  100. package/build-module/components/inspector-controls-tabs/index.js +2 -1
  101. package/build-module/components/inspector-controls-tabs/index.js.map +2 -2
  102. package/build-module/components/inspector-controls-tabs/styles-tab.js +55 -1
  103. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +2 -2
  104. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  105. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  106. package/build-module/components/keyboard-shortcuts/index.js +8 -0
  107. package/build-module/components/keyboard-shortcuts/index.js.map +2 -2
  108. package/build-module/components/rich-text/index.js +1 -0
  109. package/build-module/components/rich-text/index.js.map +2 -2
  110. package/build-module/hooks/border.js +10 -5
  111. package/build-module/hooks/border.js.map +3 -3
  112. package/build-module/hooks/color.js +31 -9
  113. package/build-module/hooks/color.js.map +3 -3
  114. package/build-module/hooks/content-lock-ui.js +4 -5
  115. package/build-module/hooks/content-lock-ui.js.map +2 -2
  116. package/build-module/hooks/dimensions.js +9 -4
  117. package/build-module/hooks/dimensions.js.map +2 -2
  118. package/build-module/hooks/fit-text.js +18 -66
  119. package/build-module/hooks/fit-text.js.map +2 -2
  120. package/build-module/hooks/font-size.js +5 -2
  121. package/build-module/hooks/font-size.js.map +2 -2
  122. package/build-module/hooks/layout.js +4 -1
  123. package/build-module/hooks/layout.js.map +2 -2
  124. package/build-module/hooks/spacing-visualizer.js +5 -0
  125. package/build-module/hooks/spacing-visualizer.js.map +2 -2
  126. package/build-module/hooks/typography.js +23 -14
  127. package/build-module/hooks/typography.js.map +3 -3
  128. package/build-module/store/private-selectors.js +20 -1
  129. package/build-module/store/private-selectors.js.map +2 -2
  130. package/build-module/store/reducer.js +4 -0
  131. package/build-module/store/reducer.js.map +2 -2
  132. package/build-module/store/selectors.js +9 -3
  133. package/build-module/store/selectors.js.map +2 -2
  134. package/build-module/utils/fit-text-frontend.js +1 -0
  135. package/build-module/utils/fit-text-frontend.js.map +2 -2
  136. package/build-module/utils/fit-text-utils.js +1 -1
  137. package/build-module/utils/fit-text-utils.js.map +1 -1
  138. package/build-style/style-rtl.css +31 -71
  139. package/build-style/style.css +31 -71
  140. package/package.json +37 -37
  141. package/src/components/block-card/index.js +95 -38
  142. package/src/components/block-card/style.scss +17 -1
  143. package/src/components/block-inspector/edit-contents.js +64 -0
  144. package/src/components/block-inspector/index.js +35 -13
  145. package/src/components/block-inspector/style.scss +6 -3
  146. package/src/components/block-list/index.js +11 -9
  147. package/src/components/block-switcher/index.js +51 -180
  148. package/src/components/block-switcher/style.scss +0 -70
  149. package/src/components/block-switcher/test/index.js +17 -18
  150. package/src/components/block-toolbar/block-toolbar-icon.js +173 -0
  151. package/src/components/block-toolbar/index.js +50 -52
  152. package/src/components/block-toolbar/pattern-overrides-dropdown.js +99 -0
  153. package/src/components/block-toolbar/style.scss +21 -21
  154. package/src/components/block-toolbar/test/block-toolbar-icon.js +182 -0
  155. package/src/components/block-tools/index.js +11 -1
  156. package/src/components/border-radius-control/test/utils.js +90 -0
  157. package/src/components/border-radius-control/utils.js +7 -3
  158. package/src/components/content-lock/modify-content-lock-menu-item.js +9 -3
  159. package/src/components/global-styles/border-panel.js +11 -7
  160. package/src/components/global-styles/color-panel.js +32 -26
  161. package/src/components/global-styles/typography-panel.js +2 -1
  162. package/src/components/inserter/media-tab/media-tab.js +7 -1
  163. package/src/components/inspector-controls-tabs/index.js +1 -0
  164. package/src/components/inspector-controls-tabs/styles-tab.js +58 -0
  165. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +5 -1
  166. package/src/components/keyboard-shortcuts/index.js +9 -0
  167. package/src/components/rich-text/index.js +1 -0
  168. package/src/hooks/border.js +12 -6
  169. package/src/hooks/color.js +40 -13
  170. package/src/hooks/content-lock-ui.js +9 -6
  171. package/src/hooks/dimensions.js +25 -17
  172. package/src/hooks/fit-text.js +23 -84
  173. package/src/hooks/font-size.js +7 -2
  174. package/src/hooks/layout.js +11 -7
  175. package/src/hooks/spacing-visualizer.js +9 -1
  176. package/src/hooks/typography.js +24 -18
  177. package/src/store/private-selectors.js +26 -1
  178. package/src/store/reducer.js +6 -0
  179. package/src/store/selectors.js +17 -3
  180. package/src/utils/fit-text-frontend.js +1 -0
  181. package/src/utils/fit-text-utils.js +1 -1
  182. package/tsconfig.tsbuildinfo +1 -1
  183. package/build/components/block-inspector/edit-contents-button.js +0 -61
  184. package/build/components/block-inspector/edit-contents-button.js.map +0 -7
  185. package/build-module/components/block-inspector/edit-contents-button.js +0 -40
  186. package/build-module/components/block-inspector/edit-contents-button.js.map +0 -7
  187. package/src/components/block-inspector/edit-contents-button.js +0 -46
@@ -6,6 +6,21 @@
6
6
  color: $gray-900;
7
7
  display: flex;
8
8
  padding: $grid-unit-20;
9
+
10
+ &.is-parent {
11
+ padding-bottom: $grid-unit-05;
12
+ }
13
+
14
+ &.is-child {
15
+ padding-top: $grid-unit-05;
16
+ }
17
+ }
18
+
19
+ .block-editor-block-card__parent-select-button {
20
+ padding: 0;
21
+ align-items: start;
22
+ text-align: start;
23
+ height: auto !important;
9
24
  }
10
25
 
11
26
  .block-editor-block-card__title {
@@ -26,7 +41,8 @@
26
41
  padding: 3px 0; // This makes the title as high as the icon.
27
42
  }
28
43
 
29
- .block-editor-block-card .block-editor-block-icon {
44
+ .block-editor-block-card .block-editor-block-icon,
45
+ .block-editor-block-card__child-indicator-icon {
30
46
  flex: 0 0 $button-size-small;
31
47
  margin-left: 0;
32
48
  margin-right: $grid-unit-15;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Button, __experimentalVStack as VStack } from '@wordpress/components';
5
+ import { useDispatch, useSelect } from '@wordpress/data';
6
+ import { __ } from '@wordpress/i18n';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { store as blockEditorStore } from '../../store';
12
+ import { unlock } from '../../lock-unlock';
13
+
14
+ export default function EditContents( { clientId } ) {
15
+ const { editContentOnlySection, stopEditingContentOnlySection } = unlock(
16
+ useDispatch( blockEditorStore )
17
+ );
18
+ const { isWithinSection, isWithinEditedSection, editedContentOnlySection } =
19
+ useSelect(
20
+ ( select ) => {
21
+ const {
22
+ isSectionBlock,
23
+ getParentSectionBlock,
24
+ getEditedContentOnlySection,
25
+ isWithinEditedContentOnlySection,
26
+ } = unlock( select( blockEditorStore ) );
27
+
28
+ return {
29
+ isWithinSection:
30
+ isSectionBlock( clientId ) ||
31
+ !! getParentSectionBlock( clientId ),
32
+ isWithinEditedSection:
33
+ isWithinEditedContentOnlySection( clientId ),
34
+ editedContentOnlySection: getEditedContentOnlySection(),
35
+ };
36
+ },
37
+ [ clientId ]
38
+ );
39
+
40
+ if ( ! isWithinSection && ! isWithinEditedSection ) {
41
+ return null;
42
+ }
43
+
44
+ return (
45
+ <VStack className="block-editor-block-inspector-edit-contents" expanded>
46
+ <Button
47
+ className="block-editor-block-inspector-edit-contents__button"
48
+ __next40pxDefaultSize
49
+ variant="secondary"
50
+ onClick={ () => {
51
+ if ( ! editedContentOnlySection ) {
52
+ editContentOnlySection( clientId );
53
+ } else {
54
+ stopEditingContentOnlySection();
55
+ }
56
+ } }
57
+ >
58
+ { editedContentOnlySection
59
+ ? __( 'Lock design' )
60
+ : __( 'Unlock design' ) }
61
+ </Button>
62
+ </VStack>
63
+ );
64
+ }
@@ -13,7 +13,7 @@ import { useSelect } from '@wordpress/data';
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
- import EditContentsButton from './edit-contents-button';
16
+ import EditContents from './edit-contents';
17
17
  import SkipToSelectedBlock from '../skip-to-selected-block';
18
18
  import BlockCard from '../block-card';
19
19
  import MultiSelectionInspector from '../multi-selection-inspector';
@@ -93,6 +93,7 @@ function BlockInspector() {
93
93
  isSectionBlock,
94
94
  isSectionBlockInSelection,
95
95
  hasBlockStyles,
96
+ editedContentOnlySection,
96
97
  } = useSelect( ( select ) => {
97
98
  const {
98
99
  getSelectedBlockClientId,
@@ -101,12 +102,18 @@ function BlockInspector() {
101
102
  getBlockName,
102
103
  getParentSectionBlock,
103
104
  isSectionBlock: _isSectionBlock,
105
+ getEditedContentOnlySection,
106
+ isWithinEditedContentOnlySection,
104
107
  } = unlock( select( blockEditorStore ) );
105
108
  const { getBlockStyles } = select( blocksStore );
106
109
  const _selectedBlockClientId = getSelectedBlockClientId();
107
- const renderedBlockClientId =
108
- getParentSectionBlock( _selectedBlockClientId ) ||
109
- _selectedBlockClientId;
110
+ const isWithinEditedSection = isWithinEditedContentOnlySection(
111
+ _selectedBlockClientId
112
+ );
113
+ const renderedBlockClientId = isWithinEditedSection
114
+ ? _selectedBlockClientId
115
+ : getParentSectionBlock( _selectedBlockClientId ) ||
116
+ _selectedBlockClientId;
110
117
  const _selectedBlockName =
111
118
  renderedBlockClientId && getBlockName( renderedBlockClientId );
112
119
  const _blockType =
@@ -115,7 +122,6 @@ function BlockInspector() {
115
122
  const _isSectionBlockInSelection = selectedBlockClientIds.some(
116
123
  ( id ) => _isSectionBlock( id )
117
124
  );
118
-
119
125
  const blockStyles =
120
126
  _selectedBlockName && getBlockStyles( _selectedBlockName );
121
127
  const _hasBlockStyles = blockStyles && blockStyles.length > 0;
@@ -128,6 +134,7 @@ function BlockInspector() {
128
134
  isSectionBlockInSelection: _isSectionBlockInSelection,
129
135
  isSectionBlock: _isSectionBlock( renderedBlockClientId ),
130
136
  hasBlockStyles: _hasBlockStyles,
137
+ editedContentOnlySection: getEditedContentOnlySection(),
131
138
  };
132
139
  }, [] );
133
140
 
@@ -263,6 +270,7 @@ function BlockInspector() {
263
270
  availableTabs={ availableTabs }
264
271
  contentClientIds={ contentClientIds }
265
272
  hasBlockStyles={ hasBlockStyles }
273
+ editedContentOnlySection={ editedContentOnlySection }
266
274
  />
267
275
  </BlockInspectorSingleBlockWrapper>
268
276
  );
@@ -311,25 +319,39 @@ const BlockInspectorSingleBlock = ( {
311
319
  availableTabs,
312
320
  contentClientIds,
313
321
  hasBlockStyles,
322
+ editedContentOnlySection,
314
323
  } ) => {
315
324
  const hasMultipleTabs = availableTabs?.length > 1;
316
-
325
+ const hasParentChildBlockCards =
326
+ window?.__experimentalContentOnlyPatternInsertion &&
327
+ editedContentOnlySection &&
328
+ editedContentOnlySection !== clientId;
329
+ const parentBlockInformation = useBlockDisplayInformation(
330
+ editedContentOnlySection
331
+ );
317
332
  const blockInformation = useBlockDisplayInformation( clientId );
318
333
  const isBlockSynced = blockInformation.isSynced;
319
-
320
334
  const shouldShowTabs = ! isBlockSynced && hasMultipleTabs;
321
335
 
322
336
  return (
323
337
  <div className="block-editor-block-inspector">
338
+ { hasParentChildBlockCards && (
339
+ <BlockCard
340
+ { ...parentBlockInformation }
341
+ className={ parentBlockInformation.isSynced && 'is-synced' }
342
+ parentClientId={ editedContentOnlySection }
343
+ />
344
+ ) }
324
345
  <BlockCard
325
346
  { ...blockInformation }
326
- className={ isBlockSynced && 'is-synced' }
327
347
  allowParentNavigation
328
- >
329
- { window?.__experimentalContentOnlyPatternInsertion && (
330
- <EditContentsButton clientId={ clientId } />
331
- ) }
332
- </BlockCard>
348
+ className={ isBlockSynced && 'is-synced' }
349
+ isChild={ hasParentChildBlockCards }
350
+ clientId={ clientId }
351
+ />
352
+ { window?.__experimentalContentOnlyPatternInsertion && (
353
+ <EditContents clientId={ clientId } />
354
+ ) }
333
355
  <BlockVariationTransforms blockClientId={ clientId } />
334
356
  { shouldShowTabs && (
335
357
  <InspectorControlsTabs
@@ -55,7 +55,10 @@
55
55
  border-top: $border-width solid $gray-300;
56
56
  }
57
57
 
58
- .block-editor-block-inspector-edit-contents-button {
59
- margin-top: $grid-unit-10;
60
- justify-content: center;
58
+ .block-editor-block-inspector-edit-contents {
59
+ margin: 0 $grid-unit-20 $grid-unit-20 $grid-unit-20;
60
+
61
+ .block-editor-block-inspector-edit-contents__button {
62
+ justify-content: center;
63
+ }
61
64
  }
@@ -15,9 +15,9 @@ import {
15
15
  import { useMergeRefs, useDebounce } from '@wordpress/compose';
16
16
  import {
17
17
  createContext,
18
+ useEffect,
18
19
  useMemo,
19
20
  useCallback,
20
- useEffect,
21
21
  } from '@wordpress/element';
22
22
  import { getDefaultBlockName } from '@wordpress/blocks';
23
23
 
@@ -52,9 +52,9 @@ function Root( { className, ...settings } ) {
52
52
  ( select ) => {
53
53
  const {
54
54
  getSettings,
55
- getEditedContentOnlySection,
56
55
  isTyping,
57
56
  hasBlockSpotlight,
57
+ getEditedContentOnlySection,
58
58
  } = unlock( select( blockEditorStore ) );
59
59
  const { outlineMode, focusMode } = getSettings();
60
60
  return {
@@ -133,24 +133,26 @@ function StopEditingContentOnlySectionOnOutsideSelect( { clientId } ) {
133
133
  );
134
134
  const isBlockOrDescendantSelected = useSelect(
135
135
  ( select ) => {
136
- const { isBlockSelected, hasSelectedInnerBlock } =
137
- select( blockEditorStore );
136
+ const {
137
+ isBlockSelected,
138
+ hasSelectedInnerBlock,
139
+ getBlockSelectionStart,
140
+ } = select( blockEditorStore );
138
141
  return (
142
+ ! getBlockSelectionStart() ||
139
143
  isBlockSelected( clientId ) ||
140
144
  hasSelectedInnerBlock( clientId, true )
141
145
  );
142
146
  },
143
147
  [ clientId ]
144
148
  );
149
+
145
150
  useEffect( () => {
146
151
  if ( ! isBlockOrDescendantSelected ) {
147
152
  stopEditingContentOnlySection();
148
153
  }
149
- }, [
150
- isBlockOrDescendantSelected,
151
- clientId,
152
- stopEditingContentOnlySection,
153
- ] );
154
+ }, [ isBlockOrDescendantSelected, stopEditingContentOnlySection ] );
155
+
154
156
  return null;
155
157
  }
156
158
 
@@ -4,7 +4,6 @@
4
4
  import { __, _n, sprintf, _x } from '@wordpress/i18n';
5
5
  import {
6
6
  DropdownMenu,
7
- ToolbarButton,
8
7
  ToolbarGroup,
9
8
  ToolbarItem,
10
9
  __experimentalText as Text,
@@ -17,60 +16,64 @@ import {
17
16
  isTemplatePart,
18
17
  } from '@wordpress/blocks';
19
18
  import { useSelect, useDispatch } from '@wordpress/data';
20
- import { copy } from '@wordpress/icons';
21
- import { store as preferencesStore } from '@wordpress/preferences';
22
19
 
23
20
  /**
24
21
  * Internal dependencies
25
22
  */
26
23
  import { store as blockEditorStore } from '../../store';
27
- import BlockIcon from '../block-icon';
28
24
  import BlockTransformationsMenu from './block-transformations-menu';
29
25
  import { useBlockVariationTransforms } from './block-variation-transformations';
30
26
  import BlockStylesMenu from './block-styles-menu';
31
27
  import PatternTransformationsMenu from './pattern-transformations-menu';
32
- import useBlockDisplayTitle from '../block-title/use-block-display-title';
33
- import { unlock } from '../../lock-unlock';
34
28
 
35
- function BlockSwitcherDropdownMenuContents( {
36
- onClose,
37
- clientIds,
38
- hasBlockStyles,
39
- canRemove,
40
- } ) {
29
+ function BlockSwitcherDropdownMenuContents( { onClose, clientIds } ) {
41
30
  const { replaceBlocks, multiSelect, updateBlockAttributes } =
42
31
  useDispatch( blockEditorStore );
43
- const { possibleBlockTransformations, patterns, blocks, isUsingBindings } =
44
- useSelect(
45
- ( select ) => {
46
- const {
47
- getBlockAttributes,
48
- getBlocksByClientId,
49
- getBlockRootClientId,
50
- getBlockTransformItems,
51
- __experimentalGetPatternTransformItems,
52
- } = select( blockEditorStore );
53
- const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
54
- const _blocks = getBlocksByClientId( clientIds );
55
- return {
56
- blocks: _blocks,
57
- possibleBlockTransformations: getBlockTransformItems(
58
- _blocks,
59
- rootClientId
60
- ),
61
- patterns: __experimentalGetPatternTransformItems(
62
- _blocks,
63
- rootClientId
64
- ),
65
- isUsingBindings: clientIds.every(
66
- ( clientId ) =>
67
- !! getBlockAttributes( clientId )?.metadata
68
- ?.bindings
69
- ),
70
- };
71
- },
72
- [ clientIds ]
73
- );
32
+ const {
33
+ possibleBlockTransformations,
34
+ patterns,
35
+ blocks,
36
+ isUsingBindings,
37
+ canRemove,
38
+ hasBlockStyles,
39
+ } = useSelect(
40
+ ( select ) => {
41
+ const {
42
+ getBlockAttributes,
43
+ getBlocksByClientId,
44
+ getBlockRootClientId,
45
+ getBlockTransformItems,
46
+ __experimentalGetPatternTransformItems,
47
+ canRemoveBlocks,
48
+ getBlockName,
49
+ } = select( blockEditorStore );
50
+ const { getBlockStyles } = select( blocksStore );
51
+ const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
52
+ const _blocks = getBlocksByClientId( clientIds );
53
+ const _isSingleBlock = clientIds.length === 1;
54
+ const _blockName = _isSingleBlock && getBlockName( clientIds[ 0 ] );
55
+ const _hasBlockStyles =
56
+ _isSingleBlock && !! getBlockStyles( _blockName )?.length;
57
+ return {
58
+ blocks: _blocks,
59
+ possibleBlockTransformations: getBlockTransformItems(
60
+ _blocks,
61
+ rootClientId
62
+ ),
63
+ patterns: __experimentalGetPatternTransformItems(
64
+ _blocks,
65
+ rootClientId
66
+ ),
67
+ isUsingBindings: clientIds.every(
68
+ ( clientId ) =>
69
+ !! getBlockAttributes( clientId )?.metadata?.bindings
70
+ ),
71
+ canRemove: canRemoveBlocks( clientIds ),
72
+ hasBlockStyles: _hasBlockStyles,
73
+ };
74
+ },
75
+ [ clientIds ]
76
+ );
74
77
  const blockVariationTransformations = useBlockVariationTransforms( {
75
78
  clientIds,
76
79
  blocks,
@@ -101,6 +104,7 @@ function BlockSwitcherDropdownMenuContents( {
101
104
  replaceBlocks( clientIds, transformedBlocks );
102
105
  selectForMultipleBlocks( transformedBlocks );
103
106
  }
107
+
104
108
  /**
105
109
  * The `isSynced` check is a stopgap solution here.
106
110
  * Ideally, the Transforms API should handle this
@@ -189,133 +193,8 @@ function BlockSwitcherDropdownMenuContents( {
189
193
  );
190
194
  }
191
195
 
192
- export const BlockSwitcher = ( { clientIds } ) => {
193
- const {
194
- hasContentOnlyLocking,
195
- canRemove,
196
- hasBlockStyles,
197
- icon,
198
- invalidBlocks,
199
- isReusable,
200
- isTemplate,
201
- isDisabled,
202
- isSectionInSelection,
203
- } = useSelect(
204
- ( select ) => {
205
- const {
206
- getTemplateLock,
207
- getBlocksByClientId,
208
- getBlockAttributes,
209
- canRemoveBlocks,
210
- getBlockEditingMode,
211
- isSectionBlock,
212
- } = unlock( select( blockEditorStore ) );
213
- const { getBlockStyles, getBlockType, getActiveBlockVariation } =
214
- select( blocksStore );
215
- const _blocks = getBlocksByClientId( clientIds );
216
- if ( ! _blocks.length || _blocks.some( ( block ) => ! block ) ) {
217
- return { invalidBlocks: true };
218
- }
219
- const [ { name: firstBlockName } ] = _blocks;
220
- const _isSingleBlockSelected = _blocks.length === 1;
221
- const blockType = getBlockType( firstBlockName );
222
- const editingMode = getBlockEditingMode( clientIds[ 0 ] );
223
-
224
- let _icon;
225
- let _hasTemplateLock;
226
- if ( _isSingleBlockSelected ) {
227
- const match = getActiveBlockVariation(
228
- firstBlockName,
229
- getBlockAttributes( clientIds[ 0 ] )
230
- );
231
- // Take into account active block variations.
232
- _icon = match?.icon || blockType.icon;
233
- _hasTemplateLock =
234
- getTemplateLock( clientIds[ 0 ] ) === 'contentOnly';
235
- } else {
236
- const isSelectionOfSameType =
237
- new Set( _blocks.map( ( { name } ) => name ) ).size === 1;
238
- _hasTemplateLock = clientIds.some(
239
- ( id ) => getTemplateLock( id ) === 'contentOnly'
240
- );
241
- // When selection consists of blocks of multiple types, display an
242
- // appropriate icon to communicate the non-uniformity.
243
- _icon = isSelectionOfSameType ? blockType.icon : copy;
244
- }
245
-
246
- const _isSectionInSelection = clientIds.some( ( id ) =>
247
- isSectionBlock( id )
248
- );
249
-
250
- return {
251
- canRemove: canRemoveBlocks( clientIds ),
252
- hasBlockStyles:
253
- _isSingleBlockSelected &&
254
- !! getBlockStyles( firstBlockName )?.length,
255
- icon: _icon,
256
- isReusable:
257
- _isSingleBlockSelected && isReusableBlock( _blocks[ 0 ] ),
258
- isTemplate:
259
- _isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
260
- hasContentOnlyLocking: _hasTemplateLock,
261
- isDisabled: editingMode !== 'default',
262
- isSectionInSelection: _isSectionInSelection,
263
- };
264
- },
265
- [ clientIds ]
266
- );
267
- const blockTitle = useBlockDisplayTitle( {
268
- clientId: clientIds?.[ 0 ],
269
- maximumLength: 35,
270
- } );
271
- const showIconLabels = useSelect(
272
- ( select ) =>
273
- select( preferencesStore ).get( 'core', 'showIconLabels' ),
274
- []
275
- );
276
-
277
- if ( invalidBlocks ) {
278
- return null;
279
- }
280
-
196
+ export const BlockSwitcher = ( { children, clientIds, label, text } ) => {
281
197
  const isSingleBlock = clientIds.length === 1;
282
- const blockSwitcherLabel = isSingleBlock
283
- ? blockTitle
284
- : __( 'Multiple blocks selected' );
285
-
286
- const blockIndicatorText =
287
- ( isReusable || isTemplate ) && ! showIconLabels && blockTitle
288
- ? blockTitle
289
- : undefined;
290
-
291
- const hideTransformsForSections =
292
- window?.__experimentalContentOnlyPatternInsertion &&
293
- isSectionInSelection;
294
- const hideDropdown =
295
- hideTransformsForSections ||
296
- isDisabled ||
297
- ( ! hasBlockStyles && ! canRemove ) ||
298
- hasContentOnlyLocking;
299
-
300
- if ( hideDropdown ) {
301
- return (
302
- <ToolbarGroup>
303
- <ToolbarButton
304
- disabled
305
- className="block-editor-block-switcher__no-switcher-icon"
306
- title={ blockSwitcherLabel }
307
- icon={
308
- <BlockIcon
309
- className="block-editor-block-switcher__toggle"
310
- icon={ icon }
311
- showColors
312
- />
313
- }
314
- text={ blockIndicatorText }
315
- />
316
- </ToolbarGroup>
317
- );
318
- }
319
198
 
320
199
  const blockSwitcherDescription = isSingleBlock
321
200
  ? __( 'Change block type or style' )
@@ -334,19 +213,13 @@ export const BlockSwitcher = ( { clientIds } ) => {
334
213
  { ( toggleProps ) => (
335
214
  <DropdownMenu
336
215
  className="block-editor-block-switcher"
337
- label={ blockSwitcherLabel }
216
+ label={ label }
338
217
  popoverProps={ {
339
218
  placement: 'bottom-start',
340
219
  className: 'block-editor-block-switcher__popover',
341
220
  } }
342
- icon={
343
- <BlockIcon
344
- className="block-editor-block-switcher__toggle"
345
- icon={ icon }
346
- showColors
347
- />
348
- }
349
- text={ blockIndicatorText }
221
+ icon={ children }
222
+ text={ text }
350
223
  toggleProps={ {
351
224
  description: blockSwitcherDescription,
352
225
  ...toggleProps,
@@ -357,8 +230,6 @@ export const BlockSwitcher = ( { clientIds } ) => {
357
230
  <BlockSwitcherDropdownMenuContents
358
231
  onClose={ onClose }
359
232
  clientIds={ clientIds }
360
- hasBlockStyles={ hasBlockStyles }
361
- canRemove={ canRemove }
362
233
  />
363
234
  ) }
364
235
  </DropdownMenu>
@@ -1,54 +1,6 @@
1
1
  @use "@wordpress/base-styles/variables" as *;
2
2
  @use "@wordpress/base-styles/colors" as *;
3
3
 
4
- .block-editor-block-switcher {
5
- position: relative;
6
-
7
- // @todo override toolbar group inherited paddings from components/block-tools/style.scss.
8
- // This is best fixed by making the mover control area a proper single toolbar group.
9
- // It needs specificity due to style inherited from .components-accessible-toolbar .components-button.has-icon.has-icon.
10
- .components-button.components-dropdown-menu__toggle.has-icon.has-icon {
11
- min-width: $button-size;
12
- }
13
- }
14
-
15
- // Show an indicator triangle.
16
- .block-editor-block-switcher__no-switcher-icon,
17
- .block-editor-block-switcher__toggle {
18
- position: relative;
19
- }
20
-
21
- .components-button.block-editor-block-switcher__toggle,
22
- .components-button.block-editor-block-switcher__no-switcher-icon {
23
- margin: 0;
24
- display: block;
25
- height: $grid-unit-60;
26
-
27
- .block-editor-block-icon {
28
- margin: auto;
29
- }
30
- }
31
-
32
- .components-button.block-editor-block-switcher__no-switcher-icon {
33
- display: flex;
34
-
35
- .block-editor-block-icon {
36
- margin-right: auto;
37
- margin-left: auto;
38
- min-width: $icon-size !important;
39
- }
40
- }
41
-
42
- // Even when the block switcher does not have any transformations, it still serves as a block indicator.
43
- .components-button.block-editor-block-switcher__no-switcher-icon[aria-disabled="true"] {
44
- color: $gray-900;
45
-
46
- // Since it's not clickable, though, don't show a hover state.
47
- &:hover {
48
- color: $gray-900;
49
- }
50
- }
51
-
52
4
  .components-popover.block-editor-block-switcher__popover .components-popover__content {
53
5
  min-width: 300px;
54
6
  }
@@ -97,28 +49,6 @@
97
49
  font-weight: $font-weight-medium;
98
50
  }
99
51
 
100
- // The block switcher in the contextual toolbar should be bigger.
101
- .block-editor-block-contextual-toolbar {
102
- .components-button.block-editor-block-switcher__no-switcher-icon {
103
- min-width: $button-size;
104
- }
105
-
106
- .components-button.block-editor-block-switcher__no-switcher-icon,
107
- .components-button.block-editor-block-switcher__toggle {
108
- height: $grid-unit-60;
109
-
110
- .block-editor-block-icon,
111
- .block-editor-block-switcher__transform {
112
- width: $block-toolbar-height;
113
- height: $block-toolbar-height;
114
- }
115
-
116
- .block-editor-block-switcher__transform {
117
- padding: $grid-unit-15;
118
- }
119
- }
120
- }
121
-
122
52
  .block-editor-block-switcher__preview-patterns-container {
123
53
  padding-bottom: $grid-unit-20;
124
54