@wordpress/block-editor 12.3.10 → 12.3.12

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 (60) hide show
  1. package/build/components/block-list/index.js +2 -4
  2. package/build/components/block-list/index.js.map +1 -1
  3. package/build/components/block-tools/block-contextual-toolbar.js +4 -2
  4. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  5. package/build/components/editor-styles/index.js +2 -2
  6. package/build/components/editor-styles/index.js.map +1 -1
  7. package/build/components/global-styles/hooks.js +2 -2
  8. package/build/components/global-styles/hooks.js.map +1 -1
  9. package/build/components/inserter/hooks/use-block-types-state.js +6 -2
  10. package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
  11. package/build/components/inserter-list-item/index.js +1 -1
  12. package/build/components/inserter-list-item/index.js.map +1 -1
  13. package/build/components/list-view/use-list-view-drop-zone.js +6 -1
  14. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  15. package/build/components/rich-text/format-edit.js +57 -28
  16. package/build/components/rich-text/format-edit.js.map +1 -1
  17. package/build/components/rich-text/get-rich-text-values.js +11 -18
  18. package/build/components/rich-text/get-rich-text-values.js.map +1 -1
  19. package/build/components/spacing-sizes-control/utils.js +2 -2
  20. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  21. package/build/private-apis.js +4 -1
  22. package/build/private-apis.js.map +1 -1
  23. package/build-module/components/block-list/index.js +2 -3
  24. package/build-module/components/block-list/index.js.map +1 -1
  25. package/build-module/components/block-tools/block-contextual-toolbar.js +4 -2
  26. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  27. package/build-module/components/editor-styles/index.js +2 -2
  28. package/build-module/components/editor-styles/index.js.map +1 -1
  29. package/build-module/components/global-styles/hooks.js +2 -2
  30. package/build-module/components/global-styles/hooks.js.map +1 -1
  31. package/build-module/components/inserter/hooks/use-block-types-state.js +7 -3
  32. package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
  33. package/build-module/components/inserter-list-item/index.js +1 -1
  34. package/build-module/components/inserter-list-item/index.js.map +1 -1
  35. package/build-module/components/list-view/use-list-view-drop-zone.js +6 -1
  36. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  37. package/build-module/components/rich-text/format-edit.js +51 -26
  38. package/build-module/components/rich-text/format-edit.js.map +1 -1
  39. package/build-module/components/rich-text/get-rich-text-values.js +13 -18
  40. package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
  41. package/build-module/components/spacing-sizes-control/utils.js +2 -2
  42. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  43. package/build-module/private-apis.js +3 -1
  44. package/build-module/private-apis.js.map +1 -1
  45. package/build-style/style-rtl.css +9 -1
  46. package/build-style/style.css +9 -1
  47. package/package.json +6 -6
  48. package/src/components/block-list/index.js +3 -6
  49. package/src/components/block-tools/block-contextual-toolbar.js +43 -35
  50. package/src/components/block-tools/style.scss +12 -3
  51. package/src/components/editor-styles/index.js +2 -2
  52. package/src/components/global-styles/hooks.js +2 -1
  53. package/src/components/inserter/hooks/use-block-types-state.js +15 -6
  54. package/src/components/inserter-list-item/index.js +3 -1
  55. package/src/components/list-view/use-list-view-drop-zone.js +5 -1
  56. package/src/components/rich-text/format-edit.js +62 -38
  57. package/src/components/rich-text/get-rich-text-values.js +22 -28
  58. package/src/components/spacing-sizes-control/test/utils.js +9 -1
  59. package/src/components/spacing-sizes-control/utils.js +2 -2
  60. package/src/private-apis.js +2 -0
@@ -18,13 +18,13 @@ import { Content } from './content';
18
18
  * except that it does not render the elements to a string, but instead collects
19
19
  * the values of all rich text `Content` elements.
20
20
  */
21
- function addValuesForElement( element, ...args ) {
21
+ function addValuesForElement( element, values, innerBlocks ) {
22
22
  if ( null === element || undefined === element || false === element ) {
23
23
  return;
24
24
  }
25
25
 
26
26
  if ( Array.isArray( element ) ) {
27
- return addValuesForElements( element, ...args );
27
+ return addValuesForElements( element, values, innerBlocks );
28
28
  }
29
29
 
30
30
  switch ( typeof element ) {
@@ -38,13 +38,12 @@ function addValuesForElement( element, ...args ) {
38
38
  switch ( type ) {
39
39
  case StrictMode:
40
40
  case Fragment:
41
- return addValuesForElements( props.children, ...args );
41
+ return addValuesForElements( props.children, values, innerBlocks );
42
42
  case RawHTML:
43
43
  return;
44
44
  case InnerBlocks.Content:
45
- return addValuesForBlocks( ...args );
45
+ return addValuesForBlocks( values, innerBlocks );
46
46
  case Content:
47
- const [ values ] = args;
48
47
  values.push( props.value );
49
48
  return;
50
49
  }
@@ -52,21 +51,19 @@ function addValuesForElement( element, ...args ) {
52
51
  switch ( typeof type ) {
53
52
  case 'string':
54
53
  if ( typeof props.children !== 'undefined' ) {
55
- return addValuesForElements( props.children, ...args );
54
+ return addValuesForElements(
55
+ props.children,
56
+ values,
57
+ innerBlocks
58
+ );
56
59
  }
57
60
  return;
58
61
  case 'function':
59
- if (
60
- type.prototype &&
61
- typeof type.prototype.render === 'function'
62
- ) {
63
- return addValuesForElement(
64
- new type( props ).render(),
65
- ...args
66
- );
67
- }
68
-
69
- return addValuesForElement( type( props ), ...args );
62
+ const el =
63
+ type.prototype && typeof type.prototype.render === 'function'
64
+ ? new type( props ).render()
65
+ : type( props );
66
+ return addValuesForElement( el, values, innerBlocks );
70
67
  }
71
68
  }
72
69
 
@@ -78,20 +75,17 @@ function addValuesForElements( children, ...args ) {
78
75
  }
79
76
  }
80
77
 
81
- function _getSaveElement( name, attributes, innerBlocks ) {
82
- return getSaveElement(
83
- name,
84
- attributes,
85
- innerBlocks.map( ( block ) =>
86
- _getSaveElement( block.name, block.attributes, block.innerBlocks )
87
- )
88
- );
89
- }
90
-
91
78
  function addValuesForBlocks( values, blocks ) {
92
79
  for ( let i = 0; i < blocks.length; i++ ) {
93
80
  const { name, attributes, innerBlocks } = blocks[ i ];
94
- const saveElement = _getSaveElement( name, attributes, innerBlocks );
81
+ const saveElement = getSaveElement(
82
+ name,
83
+ attributes,
84
+ // Instead of letting save elements use `useInnerBlocksProps.save`,
85
+ // force them to use InnerBlocks.Content instead so we can intercept
86
+ // a single component.
87
+ <InnerBlocks.Content />
88
+ );
95
89
  addValuesForElement( saveElement, values, innerBlocks );
96
90
  }
97
91
  }
@@ -49,7 +49,15 @@ describe( 'getCustomValueFromPreset', () => {
49
49
  } );
50
50
 
51
51
  describe( 'getPresetValueFromCustomValue', () => {
52
- const spacingSizes = [ { name: 'Small', slug: 20, size: '8px' } ];
52
+ const spacingSizes = [
53
+ { name: 'Default', slug: 'default', size: undefined },
54
+ { name: 'Small', slug: 20, size: '8px' },
55
+ ];
56
+ it( 'should return undefined even if an undefined value exist in spacing sizes as occurs if spacingSizes has > 7 entries', () => {
57
+ expect( getPresetValueFromCustomValue( undefined, spacingSizes ) ).toBe(
58
+ undefined
59
+ );
60
+ } );
53
61
  it( 'should return original value if a string in spacing presets var format', () => {
54
62
  expect(
55
63
  getPresetValueFromCustomValue(
@@ -101,8 +101,8 @@ export function getCustomValueFromPreset( value, spacingSizes ) {
101
101
  * @return {string} The preset value if it can be found.
102
102
  */
103
103
  export function getPresetValueFromCustomValue( value, spacingSizes ) {
104
- // Return value as-is if it is already a preset;
105
- if ( isValueSpacingPreset( value ) || value === '0' ) {
104
+ // Return value as-is if it is undefined or is already a preset, or '0';
105
+ if ( ! value || isValueSpacingPreset( value ) || value === '0' ) {
106
106
  return value;
107
107
  }
108
108
 
@@ -22,6 +22,7 @@ import {
22
22
  default as ReusableBlocksRenameHint,
23
23
  useReusableBlocksRenameHint,
24
24
  } from './components/inserter/reusable-block-rename-hint';
25
+ import { usesContextKey } from './components/rich-text/format-edit';
25
26
 
26
27
  /**
27
28
  * Private @wordpress/block-editor APIs.
@@ -47,4 +48,5 @@ lock( privateApis, {
47
48
  ResolutionTool,
48
49
  ReusableBlocksRenameHint,
49
50
  useReusableBlocksRenameHint,
51
+ usesContextKey,
50
52
  } );