@wordpress/block-editor 15.10.1-next.v.0 → 15.11.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 (81) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-edit/context.cjs +5 -0
  3. package/build/components/block-edit/context.cjs.map +2 -2
  4. package/build/components/block-edit/index.cjs +3 -0
  5. package/build/components/block-edit/index.cjs.map +2 -2
  6. package/build/components/block-inspector/index.cjs +2 -9
  7. package/build/components/block-inspector/index.cjs.map +2 -2
  8. package/build/components/block-list/block.cjs +3 -0
  9. package/build/components/block-list/block.cjs.map +2 -2
  10. package/build/components/button-block-appender/index.cjs +23 -19
  11. package/build/components/button-block-appender/index.cjs.map +2 -2
  12. package/build/components/font-sizes/font-size-picker.cjs +2 -1
  13. package/build/components/font-sizes/font-size-picker.cjs.map +2 -2
  14. package/build/components/inspector-controls/fill.cjs +4 -25
  15. package/build/components/inspector-controls/fill.cjs.map +2 -2
  16. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +6 -6
  17. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
  18. package/build/hooks/block-fields/index.cjs +52 -86
  19. package/build/hooks/block-fields/index.cjs.map +3 -3
  20. package/build/hooks/block-fields/link/index.cjs +2 -11
  21. package/build/hooks/block-fields/link/index.cjs.map +2 -2
  22. package/build/hooks/block-fields/media/index.cjs +9 -14
  23. package/build/hooks/block-fields/media/index.cjs.map +2 -2
  24. package/build/hooks/index.cjs +2 -1
  25. package/build/hooks/index.cjs.map +3 -3
  26. package/build/hooks/list-view.cjs +27 -10
  27. package/build/hooks/list-view.cjs.map +2 -2
  28. package/build/hooks/utils.cjs +3 -2
  29. package/build/hooks/utils.cjs.map +2 -2
  30. package/build/store/selectors.cjs +7 -1
  31. package/build/store/selectors.cjs.map +2 -2
  32. package/build-module/components/block-edit/context.mjs +4 -0
  33. package/build-module/components/block-edit/context.mjs.map +2 -2
  34. package/build-module/components/block-edit/index.mjs +4 -0
  35. package/build-module/components/block-edit/index.mjs.map +2 -2
  36. package/build-module/components/block-inspector/index.mjs +2 -9
  37. package/build-module/components/block-inspector/index.mjs.map +2 -2
  38. package/build-module/components/block-list/block.mjs +3 -0
  39. package/build-module/components/block-list/block.mjs.map +2 -2
  40. package/build-module/components/button-block-appender/index.mjs +23 -19
  41. package/build-module/components/button-block-appender/index.mjs.map +2 -2
  42. package/build-module/components/font-sizes/font-size-picker.mjs +2 -1
  43. package/build-module/components/font-sizes/font-size-picker.mjs.map +2 -2
  44. package/build-module/components/inspector-controls/fill.mjs +6 -22
  45. package/build-module/components/inspector-controls/fill.mjs.map +2 -2
  46. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +6 -6
  47. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
  48. package/build-module/hooks/block-fields/index.mjs +45 -87
  49. package/build-module/hooks/block-fields/index.mjs.map +2 -2
  50. package/build-module/hooks/block-fields/link/index.mjs +2 -11
  51. package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
  52. package/build-module/hooks/block-fields/media/index.mjs +9 -14
  53. package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
  54. package/build-module/hooks/index.mjs +2 -1
  55. package/build-module/hooks/index.mjs.map +2 -2
  56. package/build-module/hooks/list-view.mjs +27 -10
  57. package/build-module/hooks/list-view.mjs.map +2 -2
  58. package/build-module/hooks/utils.mjs +5 -3
  59. package/build-module/hooks/utils.mjs.map +2 -2
  60. package/build-module/store/selectors.mjs +7 -1
  61. package/build-module/store/selectors.mjs.map +2 -2
  62. package/package.json +39 -39
  63. package/src/components/block-edit/context.js +3 -0
  64. package/src/components/block-edit/index.js +6 -0
  65. package/src/components/block-inspector/index.js +2 -6
  66. package/src/components/block-list/block.js +3 -0
  67. package/src/components/block-list/block.native.js +5 -0
  68. package/src/components/block-patterns-list/stories/index.story.jsx +1 -1
  69. package/src/components/button-block-appender/index.js +2 -2
  70. package/src/components/font-sizes/font-size-picker.js +1 -0
  71. package/src/components/inspector-controls/fill.js +10 -20
  72. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +11 -8
  73. package/src/hooks/block-fields/index.js +66 -111
  74. package/src/hooks/block-fields/link/index.js +2 -14
  75. package/src/hooks/block-fields/media/index.js +9 -21
  76. package/src/hooks/index.js +2 -1
  77. package/src/hooks/list-view.js +40 -10
  78. package/src/hooks/utils.js +4 -0
  79. package/src/store/selectors.js +14 -6
  80. /package/src/components/block-icon/stories/{index.story.js → index.story.ts} +0 -0
  81. /package/src/components/contrast-checker/stories/{index.story.js → index.story.ts} +0 -0
@@ -25,8 +25,7 @@ import { getMediaSelectKey } from '../../../store/private-keys';
25
25
  import { store as blockEditorStore } from '../../../store';
26
26
 
27
27
  function MediaThumbnail( { data, field, attachment, config } ) {
28
- const { fieldDef } = config;
29
- const { allowedTypes = [], multiple = false } = fieldDef.args || {};
28
+ const { allowedTypes = [], multiple = false } = config || {};
30
29
 
31
30
  if ( multiple ) {
32
31
  return 'todo multiple';
@@ -85,12 +84,11 @@ export default function Media( { data, field, onChange, config = {} } ) {
85
84
  isControl: true,
86
85
  } );
87
86
  const value = field.getValue( { item: data } );
88
- const { fieldDef } = config;
89
- const { allowedTypes = [], multiple = false } = fieldDef.args || {};
90
-
91
- // Check if featured image is supported by checking if it's in the mapping
92
- const hasFeaturedImageSupport =
93
- fieldDef?.mapping && 'featuredImage' in fieldDef.mapping;
87
+ const {
88
+ allowedTypes = [],
89
+ multiple = false,
90
+ useFeaturedImage = false,
91
+ } = config;
94
92
 
95
93
  const id = value?.id;
96
94
  const url = value?.url;
@@ -140,23 +138,14 @@ export default function Media( { data, field, onChange, config = {} } ) {
140
138
  multiple={ multiple }
141
139
  popoverProps={ popoverProps }
142
140
  onReset={ () => {
143
- // Build reset value dynamically based on mapping
144
- const resetValue = {};
145
-
146
- if ( fieldDef?.mapping ) {
147
- Object.keys( fieldDef.mapping ).forEach( ( key ) => {
148
- resetValue[ key ] = undefined;
149
- } );
150
- }
151
-
152
141
  onChange(
153
142
  field.setValue( {
154
143
  item: data,
155
- value: resetValue,
144
+ value: {},
156
145
  } )
157
146
  );
158
147
  } }
159
- { ...( hasFeaturedImageSupport && {
148
+ { ...( useFeaturedImage && {
160
149
  useFeaturedImage: !! value?.featuredImage,
161
150
  onToggleFeaturedImage: () => {
162
151
  onChange(
@@ -171,14 +160,13 @@ export default function Media( { data, field, onChange, config = {} } ) {
171
160
  } ) }
172
161
  onSelect={ ( selectedMedia ) => {
173
162
  if ( selectedMedia.id && selectedMedia.url ) {
174
- // Build new value dynamically based on what's in the mapping
175
163
  const newValue = {
176
164
  ...selectedMedia,
177
165
  mediaType: selectedMedia.media_type,
178
166
  };
179
167
 
180
168
  // Turn off featured image when manually selecting media
181
- if ( hasFeaturedImageSupport ) {
169
+ if ( useFeaturedImage ) {
182
170
  newValue.featuredImage = false;
183
171
  }
184
172
 
@@ -14,7 +14,7 @@ import './lock';
14
14
  import allowedBlocks from './allowed-blocks';
15
15
  import anchor from './anchor';
16
16
  import ariaLabel from './aria-label';
17
- import './block-fields';
17
+ import blockFields from './block-fields';
18
18
  import customClassName from './custom-class-name';
19
19
  import './generated-class-name';
20
20
  import style from './style';
@@ -56,6 +56,7 @@ createBlockEditFilter(
56
56
  blockBindingsPanel,
57
57
  childLayout,
58
58
  allowedBlocks,
59
+ blockFields,
59
60
  listView,
60
61
  autoInspectorControls,
61
62
  ].filter( Boolean )
@@ -5,13 +5,15 @@ import { __ } from '@wordpress/i18n';
5
5
  import { PanelBody } from '@wordpress/components';
6
6
  import { useSelect } from '@wordpress/data';
7
7
  import { store as blocksStore, hasBlockSupport } from '@wordpress/blocks';
8
+ import { useContext } from '@wordpress/element';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
11
12
  */
12
- import InspectorControls from '../components/inspector-controls';
13
13
  import { store as blockEditorStore } from '../store';
14
14
  import { PrivateListView } from '../components/list-view';
15
+ import InspectorControls from '../components/inspector-controls/fill';
16
+ import { PrivateBlockContext } from '../components/block-list/private-block-context';
15
17
 
16
18
  export const LIST_VIEW_SUPPORT_KEY = 'listView';
17
19
 
@@ -34,23 +36,50 @@ export function hasListViewSupport( nameOrType ) {
34
36
  * @return {Element|null} List view inspector controls or null.
35
37
  */
36
38
  export function ListViewPanel( { clientId, name } ) {
39
+ const { isSelectionWithinCurrentSection } =
40
+ useContext( PrivateBlockContext );
37
41
  const isEnabled = hasListViewSupport( name );
38
- const { hasChildren, blockTitle } = useSelect(
39
- ( select ) => ( {
40
- hasChildren:
41
- !! select( blockEditorStore ).getBlockCount( clientId ),
42
- blockTitle: select( blocksStore ).getBlockType( name )?.title,
43
- } ),
44
- [ clientId, name ]
42
+ const { hasChildren, blockTitle, isNestedListView } = useSelect(
43
+ ( select ) => {
44
+ const { getBlockCount, getBlockParents, getBlockName } =
45
+ select( blockEditorStore );
46
+
47
+ // When the ListView is shown in a section, avoid showing List Views
48
+ // for both parent and child blocks that have support. In this situation
49
+ // the parent will show the child anyway in its List.
50
+ // Search parents to see if there's one that also has support, and if so
51
+ // skip rendering.
52
+ // This matches closely the logic in the `BlockCard` component.
53
+ let _isNestedListView = false;
54
+ if ( isSelectionWithinCurrentSection ) {
55
+ const parents = getBlockParents( clientId, true );
56
+ _isNestedListView = parents.find( ( parentId ) => {
57
+ const parentName = getBlockName( parentId );
58
+ return (
59
+ parentName === 'core/navigation' ||
60
+ hasBlockSupport( parentName, 'listView' )
61
+ );
62
+ } );
63
+ }
64
+
65
+ return {
66
+ hasChildren: !! getBlockCount( clientId ),
67
+ blockTitle: select( blocksStore ).getBlockType( name )?.title,
68
+ isNestedListView: _isNestedListView,
69
+ };
70
+ },
71
+ [ clientId, name, isSelectionWithinCurrentSection ]
45
72
  );
46
73
 
47
- if ( ! isEnabled ) {
74
+ if ( ! isEnabled || isNestedListView ) {
48
75
  return null;
49
76
  }
50
77
 
78
+ const showBlockTitle = isSelectionWithinCurrentSection;
79
+
51
80
  return (
52
81
  <InspectorControls group="list">
53
- <PanelBody title={ null }>
82
+ <PanelBody title={ showBlockTitle ? blockTitle : undefined }>
54
83
  { ! hasChildren && (
55
84
  <p className="block-editor-block-inspector__no-blocks">
56
85
  { __( 'No items yet.' ) }
@@ -74,4 +103,5 @@ export default {
74
103
  edit: ListViewPanel,
75
104
  hasSupport: hasListViewSupport,
76
105
  attributeKeys: [],
106
+ supportsPatternEditing: true,
77
107
  };
@@ -19,6 +19,7 @@ import {
19
19
  useBlockEditContext,
20
20
  mayDisplayControlsKey,
21
21
  mayDisplayParentControlsKey,
22
+ mayDisplayPatternEditingControlsKey,
22
23
  } from '../components/block-edit/context';
23
24
  import { useSettings } from '../components';
24
25
  import { useSettingsForBlockElement } from '../components/global-styles/hooks';
@@ -534,8 +535,11 @@ export function createBlockEditFilter( features ) {
534
535
  hasSupport,
535
536
  attributeKeys = [],
536
537
  shareWithChildBlocks,
538
+ supportsPatternEditing,
537
539
  } = feature;
538
540
  const shouldDisplayControls =
541
+ ( supportsPatternEditing &&
542
+ context[ mayDisplayPatternEditingControlsKey ] ) ||
539
543
  context[ mayDisplayControlsKey ] ||
540
544
  ( context[ mayDisplayParentControlsKey ] &&
541
545
  shareWithChildBlocks );
@@ -2279,13 +2279,21 @@ export const getInserterItems = createRegistrySelector( ( select ) =>
2279
2279
  )
2280
2280
  );
2281
2281
  } else {
2282
+ const { getClosestAllowedInsertionPoint } = unlock(
2283
+ select( STORE_NAME )
2284
+ );
2282
2285
  blockTypeInserterItems = blockTypeInserterItems
2283
- .filter( ( blockType ) =>
2284
- isBlockVisibleInTheInserter(
2285
- state,
2286
- blockType,
2287
- rootClientId
2288
- )
2286
+ .filter(
2287
+ ( blockType ) =>
2288
+ isBlockVisibleInTheInserter(
2289
+ state,
2290
+ blockType,
2291
+ rootClientId
2292
+ ) &&
2293
+ getClosestAllowedInsertionPoint(
2294
+ blockType.name,
2295
+ rootClientId
2296
+ ) !== null
2289
2297
  )
2290
2298
  .map( ( blockType ) => ( {
2291
2299
  ...blockType,