@wordpress/block-editor 12.19.1 → 12.19.2

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 (52) hide show
  1. package/build/components/global-styles/border-panel.js +4 -3
  2. package/build/components/global-styles/border-panel.js.map +1 -1
  3. package/build/components/global-styles/get-global-styles-changes.js +61 -24
  4. package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
  5. package/build/components/global-styles/typography-panel.js +8 -6
  6. package/build/components/global-styles/typography-panel.js.map +1 -1
  7. package/build/components/iframe/index.js +4 -1
  8. package/build/components/iframe/index.js.map +1 -1
  9. package/build/components/rich-text/index.native.js +1 -0
  10. package/build/components/rich-text/index.native.js.map +1 -1
  11. package/build/components/rich-text/use-enter.js +1 -0
  12. package/build/components/rich-text/use-enter.js.map +1 -1
  13. package/build/hooks/use-bindings-attributes.js +0 -17
  14. package/build/hooks/use-bindings-attributes.js.map +1 -1
  15. package/build/hooks/utils.js +8 -4
  16. package/build/hooks/utils.js.map +1 -1
  17. package/build/store/get-block-settings.js +17 -4
  18. package/build/store/get-block-settings.js.map +1 -1
  19. package/build/store/private-actions.js +5 -0
  20. package/build/store/private-actions.js.map +1 -1
  21. package/build-module/components/global-styles/border-panel.js +5 -4
  22. package/build-module/components/global-styles/border-panel.js.map +1 -1
  23. package/build-module/components/global-styles/get-global-styles-changes.js +61 -25
  24. package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
  25. package/build-module/components/global-styles/typography-panel.js +9 -7
  26. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  27. package/build-module/components/iframe/index.js +4 -1
  28. package/build-module/components/iframe/index.js.map +1 -1
  29. package/build-module/components/rich-text/index.native.js +1 -0
  30. package/build-module/components/rich-text/index.native.js.map +1 -1
  31. package/build-module/components/rich-text/use-enter.js +1 -0
  32. package/build-module/components/rich-text/use-enter.js.map +1 -1
  33. package/build-module/hooks/use-bindings-attributes.js +0 -17
  34. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  35. package/build-module/hooks/utils.js +8 -4
  36. package/build-module/hooks/utils.js.map +1 -1
  37. package/build-module/store/get-block-settings.js +16 -4
  38. package/build-module/store/get-block-settings.js.map +1 -1
  39. package/build-module/store/private-actions.js +5 -0
  40. package/build-module/store/private-actions.js.map +1 -1
  41. package/package.json +31 -31
  42. package/src/components/global-styles/border-panel.js +4 -6
  43. package/src/components/global-styles/get-global-styles-changes.js +68 -28
  44. package/src/components/global-styles/test/get-global-styles-changes.js +114 -75
  45. package/src/components/global-styles/typography-panel.js +11 -7
  46. package/src/components/iframe/index.js +4 -1
  47. package/src/components/rich-text/index.native.js +1 -0
  48. package/src/components/rich-text/use-enter.js +1 -0
  49. package/src/hooks/use-bindings-attributes.js +0 -21
  50. package/src/hooks/utils.js +24 -8
  51. package/src/store/get-block-settings.js +15 -4
  52. package/src/store/private-actions.js +9 -0
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import getGlobalStylesChanges from '../get-global-styles-changes';
4
+ import getGlobalStylesChanges, {
5
+ getGlobalStylesChangelist,
6
+ } from '../get-global-styles-changes';
5
7
 
6
8
  /**
7
9
  * WordPress dependencies
@@ -12,24 +14,8 @@ import {
12
14
  getBlockTypes,
13
15
  } from '@wordpress/blocks';
14
16
 
15
- describe( 'getGlobalStylesChanges', () => {
16
- beforeEach( () => {
17
- registerBlockType( 'core/test-fiori-di-zucca', {
18
- save: () => {},
19
- category: 'text',
20
- title: 'Test pumpkin flowers',
21
- edit: () => {},
22
- } );
23
- } );
24
-
25
- afterEach( () => {
26
- getBlockTypes().forEach( ( block ) => {
27
- unregisterBlockType( block.name );
28
- } );
29
- } );
30
-
31
- const revision = {
32
- id: 10,
17
+ describe( 'getGlobalStylesChanges and utils', () => {
18
+ const next = {
33
19
  styles: {
34
20
  typography: {
35
21
  fontSize: 'var(--wp--preset--font-size--potato)',
@@ -85,11 +71,18 @@ describe( 'getGlobalStylesChanges', () => {
85
71
  },
86
72
  ],
87
73
  },
74
+ gradients: [
75
+ {
76
+ name: 'Something something',
77
+ gradient:
78
+ 'linear-gradient(105deg,rgba(6,147,100,1) 0%,rgb(155,81,100) 100%)',
79
+ slug: 'something-something',
80
+ },
81
+ ],
88
82
  },
89
83
  },
90
84
  };
91
- const previousRevision = {
92
- id: 9,
85
+ const previous = {
93
86
  styles: {
94
87
  typography: {
95
88
  fontSize: 'var(--wp--preset--font-size--fungus)',
@@ -161,74 +154,120 @@ describe( 'getGlobalStylesChanges', () => {
161
154
  color: 'blue',
162
155
  },
163
156
  ],
157
+ custom: [
158
+ {
159
+ slug: 'one',
160
+ color: 'tomato',
161
+ },
162
+ ],
164
163
  },
164
+ gradients: [
165
+ {
166
+ name: 'Vivid cyan blue to vivid purple',
167
+ gradient:
168
+ 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
169
+ slug: 'vivid-cyan-blue-to-vivid-purple',
170
+ },
171
+ ],
172
+ },
173
+ typography: {
174
+ fluid: true,
165
175
  },
166
176
  },
167
177
  };
168
178
 
169
- it( 'returns a list of changes and caches them', () => {
170
- const resultA = getGlobalStylesChanges( revision, previousRevision );
171
- expect( resultA ).toEqual( [
172
- 'Colors',
173
- 'Typography',
174
- 'Test pumpkin flowers',
175
- 'H3 element',
176
- 'Caption element',
177
- 'H6 element',
178
- 'Link element',
179
- 'Color settings',
180
- ] );
181
-
182
- const resultB = getGlobalStylesChanges( revision, previousRevision );
183
-
184
- expect( resultA ).toBe( resultB );
179
+ beforeEach( () => {
180
+ registerBlockType( 'core/test-fiori-di-zucca', {
181
+ save: () => {},
182
+ category: 'text',
183
+ title: 'Test pumpkin flowers',
184
+ edit: () => {},
185
+ } );
185
186
  } );
186
187
 
187
- it( 'returns a list of truncated changes', () => {
188
- const resultA = getGlobalStylesChanges( revision, previousRevision, {
189
- maxResults: 3,
188
+ afterEach( () => {
189
+ getBlockTypes().forEach( ( block ) => {
190
+ unregisterBlockType( block.name );
190
191
  } );
191
- expect( resultA ).toEqual( [
192
- 'Colors',
193
- 'Typography',
194
- 'Test pumpkin flowers',
195
- '…and 5 more changes',
196
- ] );
197
192
  } );
198
193
 
199
- it( 'skips unknown and unchanged keys', () => {
200
- const result = getGlobalStylesChanges(
201
- {
202
- styles: {
203
- frogs: {
204
- legs: 'green',
205
- },
206
- typography: {
207
- fontSize: '1rem',
208
- },
209
- settings: {
210
- '': {
211
- '': 'foo',
194
+ describe( 'getGlobalStylesChanges()', () => {
195
+ it( 'returns a list of changes', () => {
196
+ const result = getGlobalStylesChanges( next, previous );
197
+ expect( result ).toEqual( [
198
+ 'Colors, Typography styles.',
199
+ 'Test pumpkin flowers block.',
200
+ 'H3, Caption, H6, Link elements.',
201
+ 'Color, Typography settings.',
202
+ ] );
203
+ } );
204
+
205
+ it( 'returns a list of truncated changes', () => {
206
+ const resultA = getGlobalStylesChanges( next, previous, {
207
+ maxResults: 3,
208
+ } );
209
+ expect( resultA ).toEqual( [
210
+ 'Colors, Typography styles.',
211
+ 'Test pumpkin flowers block.',
212
+ ] );
213
+ } );
214
+
215
+ it( 'skips unknown and unchanged keys', () => {
216
+ const result = getGlobalStylesChanges(
217
+ {
218
+ styles: {
219
+ frogs: {
220
+ legs: 'green',
221
+ },
222
+ typography: {
223
+ fontSize: '1rem',
224
+ },
225
+ settings: {
226
+ '': {
227
+ '': 'foo',
228
+ },
212
229
  },
213
230
  },
214
231
  },
215
- },
216
- {
217
- styles: {
218
- frogs: {
219
- legs: 'yellow',
220
- },
221
- typography: {
222
- fontSize: '1rem',
223
- },
224
- settings: {
225
- '': {
226
- '': 'bar',
232
+ {
233
+ styles: {
234
+ frogs: {
235
+ legs: 'yellow',
236
+ },
237
+ typography: {
238
+ fontSize: '1rem',
239
+ },
240
+ settings: {
241
+ '': {
242
+ '': 'bar',
243
+ },
227
244
  },
228
245
  },
229
- },
230
- }
231
- );
232
- expect( result ).toEqual( [] );
246
+ }
247
+ );
248
+ expect( result ).toEqual( [] );
249
+ } );
250
+ } );
251
+
252
+ describe( 'getGlobalStylesChangelist()', () => {
253
+ it( 'compares two objects and returns a cached list of changed keys', () => {
254
+ const resultA = getGlobalStylesChangelist( next, previous );
255
+
256
+ expect( resultA ).toEqual( [
257
+ [ 'styles', 'Colors' ],
258
+ [ 'styles', 'Typography' ],
259
+ [ 'blocks', 'Test pumpkin flowers' ],
260
+ [ 'elements', 'H3' ],
261
+ [ 'elements', 'Caption' ],
262
+ [ 'elements', 'H6' ],
263
+ [ 'elements', 'Link' ],
264
+ [ 'settings', 'Color' ],
265
+ [ 'settings', 'Typography' ],
266
+ ] );
267
+
268
+ const resultB = getGlobalStylesChangelist( next, previous );
269
+
270
+ expect( resultB ).toEqual( resultA );
271
+ } );
233
272
  } );
234
273
  } );
@@ -13,7 +13,11 @@ import { useCallback } from '@wordpress/element';
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
- import { mergeOrigins, hasMergedOrigins } from '../../store/get-block-settings';
16
+ import {
17
+ mergeOrigins,
18
+ overrideOrigins,
19
+ hasOriginValue,
20
+ } from '../../store/get-block-settings';
17
21
  import FontFamilyControl from '../font-family';
18
22
  import FontAppearanceControl from '../font-appearance-control';
19
23
  import LineHeightControl from '../line-height-control';
@@ -53,13 +57,13 @@ export function useHasTypographyPanel( settings ) {
53
57
 
54
58
  function useHasFontSizeControl( settings ) {
55
59
  return (
56
- hasMergedOrigins( settings?.typography?.fontSizes ) ||
60
+ hasOriginValue( settings?.typography?.fontSizes ) ||
57
61
  settings?.typography?.customFontSize
58
62
  );
59
63
  }
60
64
 
61
65
  function useHasFontFamilyControl( settings ) {
62
- return hasMergedOrigins( settings?.typography?.fontFamilies );
66
+ return hasOriginValue( settings?.typography?.fontFamilies );
63
67
  }
64
68
 
65
69
  function useHasLineHeightControl( settings ) {
@@ -101,10 +105,10 @@ function useHasTextColumnsControl( settings ) {
101
105
  }
102
106
 
103
107
  function getUniqueFontSizesBySlug( settings ) {
104
- const fontSizes = settings?.typography?.fontSizes;
105
- const mergedFontSizes = fontSizes ? mergeOrigins( fontSizes ) : [];
108
+ const fontSizes = settings?.typography?.fontSizes ?? {};
109
+ const overriddenFontSizes = overrideOrigins( fontSizes ) ?? [];
106
110
  const uniqueSizes = [];
107
- for ( const currentSize of mergedFontSizes ) {
111
+ for ( const currentSize of overriddenFontSizes ) {
108
112
  if ( ! uniqueSizes.some( ( { slug } ) => slug === currentSize.slug ) ) {
109
113
  uniqueSizes.push( currentSize );
110
114
  }
@@ -162,7 +166,7 @@ export default function TypographyPanel( {
162
166
 
163
167
  // Font Family
164
168
  const hasFontFamilyEnabled = useHasFontFamilyControl( settings );
165
- const fontFamilies = settings?.typography?.fontFamilies;
169
+ const fontFamilies = settings?.typography?.fontFamilies ?? {};
166
170
  const mergedFontFamilies = fontFamilies ? mergeOrigins( fontFamilies ) : [];
167
171
  const fontFamily = decodeValue( inheritedValue?.typography?.fontFamily );
168
172
  const setFontFamily = ( newValue ) => {
@@ -273,13 +273,16 @@ function Iframe( {
273
273
  src={ src }
274
274
  title={ __( 'Editor canvas' ) }
275
275
  onKeyDown={ ( event ) => {
276
+ if ( props.onKeyDown ) {
277
+ props.onKeyDown( event );
278
+ }
276
279
  // If the event originates from inside the iframe, it means
277
280
  // it bubbled through the portal, but only with React
278
281
  // events. We need to to bubble native events as well,
279
282
  // though by doing so we also trigger another React event,
280
283
  // so we need to stop the propagation of this event to avoid
281
284
  // duplication.
282
- if (
285
+ else if (
283
286
  event.currentTarget.ownerDocument !==
284
287
  event.target.ownerDocument
285
288
  ) {
@@ -316,6 +316,7 @@ export function RichTextWrapper(
316
316
  transformation.transform( { content: value.text } ),
317
317
  ] );
318
318
  __unstableMarkAutomaticChange();
319
+ return;
319
320
  }
320
321
  }
321
322
 
@@ -61,6 +61,7 @@ export function useEnter( props ) {
61
61
  } ),
62
62
  ] );
63
63
  __unstableMarkAutomaticChange();
64
+ return;
64
65
  }
65
66
  }
66
67
 
@@ -112,24 +112,3 @@ addFilter(
112
112
  'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',
113
113
  shimAttributeSource
114
114
  );
115
-
116
- // Add the context to all blocks.
117
- addFilter(
118
- 'blocks.registerBlockType',
119
- 'core/block-bindings-ui',
120
- ( settings, name ) => {
121
- if ( ! ( name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
122
- return settings;
123
- }
124
- const contextItems = [ 'postId', 'postType', 'queryId' ];
125
- const usesContextArray = settings.usesContext;
126
- const oldUsesContextArray = new Set( usesContextArray );
127
- contextItems.forEach( ( item ) => {
128
- if ( ! oldUsesContextArray.has( item ) ) {
129
- usesContextArray.push( item );
130
- }
131
- } );
132
- settings.usesContext = usesContextArray;
133
- return settings;
134
- }
135
- );
@@ -176,8 +176,12 @@ export function useBlockSettings( name, parentLayout ) {
176
176
  const [
177
177
  backgroundImage,
178
178
  backgroundSize,
179
- fontFamilies,
180
- fontSizes,
179
+ customFontFamilies,
180
+ defaultFontFamilies,
181
+ themeFontFamilies,
182
+ customFontSizes,
183
+ defaultFontSizes,
184
+ themeFontSizes,
181
185
  customFontSize,
182
186
  fontStyle,
183
187
  fontWeight,
@@ -223,8 +227,12 @@ export function useBlockSettings( name, parentLayout ) {
223
227
  ] = useSettings(
224
228
  'background.backgroundImage',
225
229
  'background.backgroundSize',
226
- 'typography.fontFamilies',
227
- 'typography.fontSizes',
230
+ 'typography.fontFamilies.custom',
231
+ 'typography.fontFamilies.default',
232
+ 'typography.fontFamilies.theme',
233
+ 'typography.fontSizes.custom',
234
+ 'typography.fontSizes.default',
235
+ 'typography.fontSizes.theme',
228
236
  'typography.customFontSize',
229
237
  'typography.fontStyle',
230
238
  'typography.fontWeight',
@@ -305,10 +313,14 @@ export function useBlockSettings( name, parentLayout ) {
305
313
  },
306
314
  typography: {
307
315
  fontFamilies: {
308
- custom: fontFamilies,
316
+ custom: customFontFamilies,
317
+ default: defaultFontFamilies,
318
+ theme: themeFontFamilies,
309
319
  },
310
320
  fontSizes: {
311
- custom: fontSizes,
321
+ custom: customFontSizes,
322
+ default: defaultFontSizes,
323
+ theme: themeFontSizes,
312
324
  },
313
325
  customFontSize,
314
326
  fontStyle,
@@ -346,8 +358,12 @@ export function useBlockSettings( name, parentLayout ) {
346
358
  }, [
347
359
  backgroundImage,
348
360
  backgroundSize,
349
- fontFamilies,
350
- fontSizes,
361
+ customFontFamilies,
362
+ defaultFontFamilies,
363
+ themeFontFamilies,
364
+ customFontSizes,
365
+ defaultFontSizes,
366
+ themeFontSizes,
351
367
  customFontSize,
352
368
  fontStyle,
353
369
  fontWeight,
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import {
5
- __EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,
5
+ __EXPERIMENTAL_PATHS_WITH_OVERRIDE as PATHS_WITH_OVERRIDE,
6
6
  hasBlockSupport,
7
7
  } from '@wordpress/blocks';
8
8
  import { applyFilters } from '@wordpress/hooks';
@@ -111,6 +111,17 @@ export function mergeOrigins( value ) {
111
111
  }
112
112
  const mergeCache = new WeakMap();
113
113
 
114
+ /**
115
+ * For settings like `color.palette`, which have a value that is an object
116
+ * with `default`, `theme`, `custom`, with field values that are arrays of
117
+ * items, returns the one with the highest priority among these three arrays.
118
+ * @param {Object} value Object to extract from
119
+ * @return {Array} Array of items extracted from the three origins
120
+ */
121
+ export function overrideOrigins( value ) {
122
+ return value.custom ?? value.theme ?? value.default;
123
+ }
124
+
114
125
  /**
115
126
  * For settings like `color.palette`, which have a value that is an object
116
127
  * with `default`, `theme`, `custom`, with field values that are arrays of
@@ -119,7 +130,7 @@ const mergeCache = new WeakMap();
119
130
  * @param {Object} value Object to check
120
131
  * @return {boolean} Whether the object has values in any of the three origins
121
132
  */
122
- export function hasMergedOrigins( value ) {
133
+ export function hasOriginValue( value ) {
123
134
  return [ 'default', 'theme', 'custom' ].some(
124
135
  ( key ) => value?.[ key ]?.length
125
136
  );
@@ -203,8 +214,8 @@ export function getBlockSettings( state, clientId, ...paths ) {
203
214
 
204
215
  // Return if the setting was found in either the block instance or the store.
205
216
  if ( result !== undefined ) {
206
- if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
207
- return mergeOrigins( result );
217
+ if ( PATHS_WITH_OVERRIDE[ normalizedPath ] ) {
218
+ return overrideOrigins( result );
208
219
  }
209
220
  return result;
210
221
  }
@@ -140,6 +140,15 @@ export const privateRemoveBlocks =
140
140
  }
141
141
 
142
142
  if ( rules[ 'bindings/core/pattern-overrides' ] ) {
143
+ const parentPatternBlocks =
144
+ select.getBlockParentsByBlockName(
145
+ clientId,
146
+ 'core/block'
147
+ );
148
+ // We only need to run this check when editing the original pattern, not pattern instances.
149
+ if ( parentPatternBlocks?.length > 0 ) {
150
+ continue;
151
+ }
143
152
  const blockAttributes =
144
153
  select.getBlockAttributes( clientId );
145
154
  if (