@wordpress/block-editor 15.6.1 → 15.7.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 (158) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/background-image-control/index.js +2 -2
  3. package/build/components/background-image-control/index.js.map +2 -2
  4. package/build/components/block-quick-navigation/index.js +1 -0
  5. package/build/components/block-quick-navigation/index.js.map +2 -2
  6. package/build/components/block-toolbar/switch-section-style.js +2 -5
  7. package/build/components/block-toolbar/switch-section-style.js.map +2 -2
  8. package/build/components/global-styles/border-panel.js +2 -1
  9. package/build/components/global-styles/border-panel.js.map +2 -2
  10. package/build/components/global-styles/color-panel.js +2 -1
  11. package/build/components/global-styles/color-panel.js.map +2 -2
  12. package/build/components/global-styles/dimensions-panel.js +3 -2
  13. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  14. package/build/components/global-styles/filters-panel.js +2 -1
  15. package/build/components/global-styles/filters-panel.js.map +2 -2
  16. package/build/components/global-styles/hooks.js +0 -179
  17. package/build/components/global-styles/hooks.js.map +3 -3
  18. package/build/components/global-styles/index.js +0 -29
  19. package/build/components/global-styles/index.js.map +2 -2
  20. package/build/components/global-styles/typography-panel.js +2 -1
  21. package/build/components/global-styles/typography-panel.js.map +2 -2
  22. package/build/components/global-styles/typography-utils.js +2 -49
  23. package/build/components/global-styles/typography-utils.js.map +2 -2
  24. package/build/components/global-styles/utils.js +0 -396
  25. package/build/components/global-styles/utils.js.map +3 -3
  26. package/build/components/inserter/media-tab/media-tab.js +33 -1
  27. package/build/components/inserter/media-tab/media-tab.js.map +3 -3
  28. package/build/components/inserter/tips.js +0 -2
  29. package/build/components/inserter/tips.js.map +2 -2
  30. package/build/components/media-placeholder/index.js +31 -1
  31. package/build/components/media-placeholder/index.js.map +3 -3
  32. package/build/components/media-replace-flow/index.js +29 -1
  33. package/build/components/media-replace-flow/index.js.map +3 -3
  34. package/build/components/{global-styles/context.js → media-upload-modal/index.js} +8 -23
  35. package/build/components/media-upload-modal/index.js.map +7 -0
  36. package/build/hooks/allowed-blocks.js +3 -8
  37. package/build/hooks/allowed-blocks.js.map +3 -3
  38. package/build/hooks/block-style-variation.js +10 -23
  39. package/build/hooks/block-style-variation.js.map +2 -2
  40. package/build/hooks/duotone.js +3 -3
  41. package/build/hooks/duotone.js.map +2 -2
  42. package/build/hooks/fit-text.js +2 -2
  43. package/build/hooks/fit-text.js.map +2 -2
  44. package/build/hooks/font-size.js +2 -2
  45. package/build/hooks/font-size.js.map +2 -2
  46. package/build/hooks/use-typography-props.js +2 -2
  47. package/build/hooks/use-typography-props.js.map +2 -2
  48. package/build/private-apis.js +3 -1
  49. package/build/private-apis.js.map +3 -3
  50. package/build-module/components/background-image-control/index.js +1 -1
  51. package/build-module/components/background-image-control/index.js.map +2 -2
  52. package/build-module/components/block-quick-navigation/index.js +1 -0
  53. package/build-module/components/block-quick-navigation/index.js.map +2 -2
  54. package/build-module/components/block-toolbar/switch-section-style.js +2 -5
  55. package/build-module/components/block-toolbar/switch-section-style.js.map +2 -2
  56. package/build-module/components/global-styles/border-panel.js +2 -1
  57. package/build-module/components/global-styles/border-panel.js.map +2 -2
  58. package/build-module/components/global-styles/color-panel.js +2 -1
  59. package/build-module/components/global-styles/color-panel.js.map +2 -2
  60. package/build-module/components/global-styles/dimensions-panel.js +2 -1
  61. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  62. package/build-module/components/global-styles/filters-panel.js +2 -1
  63. package/build-module/components/global-styles/filters-panel.js.map +2 -2
  64. package/build-module/components/global-styles/hooks.js +1 -167
  65. package/build-module/components/global-styles/hooks.js.map +2 -2
  66. package/build-module/components/global-styles/index.js +1 -29
  67. package/build-module/components/global-styles/index.js.map +2 -2
  68. package/build-module/components/global-styles/typography-panel.js +2 -1
  69. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  70. package/build-module/components/global-styles/typography-utils.js +1 -49
  71. package/build-module/components/global-styles/typography-utils.js.map +2 -2
  72. package/build-module/components/global-styles/utils.js +0 -372
  73. package/build-module/components/global-styles/utils.js.map +2 -2
  74. package/build-module/components/inserter/media-tab/media-tab.js +34 -2
  75. package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
  76. package/build-module/components/inserter/tips.js +0 -2
  77. package/build-module/components/inserter/tips.js.map +2 -2
  78. package/build-module/components/media-placeholder/index.js +31 -1
  79. package/build-module/components/media-placeholder/index.js.map +2 -2
  80. package/build-module/components/media-replace-flow/index.js +29 -1
  81. package/build-module/components/media-replace-flow/index.js.map +2 -2
  82. package/build-module/components/media-upload-modal/index.js +7 -0
  83. package/build-module/components/media-upload-modal/index.js.map +7 -0
  84. package/build-module/hooks/allowed-blocks.js +3 -8
  85. package/build-module/hooks/allowed-blocks.js.map +2 -2
  86. package/build-module/hooks/block-style-variation.js +8 -25
  87. package/build-module/hooks/block-style-variation.js.map +2 -2
  88. package/build-module/hooks/duotone.js +3 -3
  89. package/build-module/hooks/duotone.js.map +2 -2
  90. package/build-module/hooks/fit-text.js +2 -2
  91. package/build-module/hooks/fit-text.js.map +2 -2
  92. package/build-module/hooks/font-size.js +1 -1
  93. package/build-module/hooks/font-size.js.map +2 -2
  94. package/build-module/hooks/use-typography-props.js +1 -1
  95. package/build-module/hooks/use-typography-props.js.map +2 -2
  96. package/build-module/private-apis.js +3 -1
  97. package/build-module/private-apis.js.map +2 -2
  98. package/build-style/style-rtl.css +10 -6
  99. package/build-style/style.css +10 -6
  100. package/package.json +36 -35
  101. package/src/components/background-image-control/index.js +1 -1
  102. package/src/components/block-card/style.scss +1 -1
  103. package/src/components/block-navigation/style.scss +1 -1
  104. package/src/components/block-quick-navigation/index.js +1 -0
  105. package/src/components/block-quick-navigation/style.scss +5 -0
  106. package/src/components/block-switcher/style.scss +1 -1
  107. package/src/components/block-toolbar/switch-section-style.js +2 -5
  108. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  109. package/src/components/global-styles/border-panel.js +2 -1
  110. package/src/components/global-styles/color-panel.js +2 -1
  111. package/src/components/global-styles/color-panel.native.js +1 -1
  112. package/src/components/global-styles/dimensions-panel.js +2 -1
  113. package/src/components/global-styles/filters-panel.js +2 -1
  114. package/src/components/global-styles/hooks.js +1 -200
  115. package/src/components/global-styles/index.js +1 -17
  116. package/src/components/global-styles/test/typography-utils.js +0 -806
  117. package/src/components/global-styles/typography-panel.js +2 -1
  118. package/src/components/global-styles/typography-utils.js +0 -133
  119. package/src/components/global-styles/utils.js +0 -568
  120. package/src/components/inserter/media-tab/media-tab.js +44 -2
  121. package/src/components/inserter/style.scss +2 -2
  122. package/src/components/inserter/tips.js +0 -2
  123. package/src/components/media-placeholder/index.js +41 -1
  124. package/src/components/media-replace-flow/index.js +39 -1
  125. package/src/components/media-upload-modal/index.js +18 -0
  126. package/src/components/multi-selection-inspector/style.scss +1 -1
  127. package/src/hooks/allowed-blocks.js +3 -11
  128. package/src/hooks/block-style-variation.js +8 -28
  129. package/src/hooks/duotone.js +3 -3
  130. package/src/hooks/fit-text.js +2 -2
  131. package/src/hooks/font-size.js +1 -1
  132. package/src/hooks/use-typography-props.js +1 -1
  133. package/src/private-apis.js +2 -0
  134. package/src/style.scss +1 -0
  135. package/tsconfig.json +2 -0
  136. package/build/components/global-styles/context.js.map +0 -7
  137. package/build/components/global-styles/get-block-css-selector.js +0 -78
  138. package/build/components/global-styles/get-block-css-selector.js.map +0 -7
  139. package/build/components/global-styles/get-global-styles-changes.js +0 -216
  140. package/build/components/global-styles/get-global-styles-changes.js.map +0 -7
  141. package/build/components/global-styles/use-global-styles-output.js +0 -998
  142. package/build/components/global-styles/use-global-styles-output.js.map +0 -7
  143. package/build-module/components/global-styles/context.js +0 -17
  144. package/build-module/components/global-styles/context.js.map +0 -7
  145. package/build-module/components/global-styles/get-block-css-selector.js +0 -54
  146. package/build-module/components/global-styles/get-block-css-selector.js.map +0 -7
  147. package/build-module/components/global-styles/get-global-styles-changes.js +0 -182
  148. package/build-module/components/global-styles/get-global-styles-changes.js.map +0 -7
  149. package/build-module/components/global-styles/use-global-styles-output.js +0 -979
  150. package/build-module/components/global-styles/use-global-styles-output.js.map +0 -7
  151. package/src/components/global-styles/README.md +0 -190
  152. package/src/components/global-styles/context.js +0 -16
  153. package/src/components/global-styles/get-block-css-selector.js +0 -114
  154. package/src/components/global-styles/get-global-styles-changes.js +0 -252
  155. package/src/components/global-styles/test/get-global-styles-changes.js +0 -290
  156. package/src/components/global-styles/test/use-global-styles-output.js +0 -1131
  157. package/src/components/global-styles/test/utils.js +0 -499
  158. package/src/components/global-styles/use-global-styles-output.js +0 -1487
@@ -1,252 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import memoize from 'memize';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { __, _n, sprintf } from '@wordpress/i18n';
10
- import { getBlockTypes } from '@wordpress/blocks';
11
-
12
- const globalStylesChangesCache = new Map();
13
- const EMPTY_ARRAY = [];
14
- const translationMap = {
15
- caption: __( 'Caption' ),
16
- link: __( 'Link' ),
17
- button: __( 'Button' ),
18
- heading: __( 'Heading' ),
19
- h1: __( 'H1' ),
20
- h2: __( 'H2' ),
21
- h3: __( 'H3' ),
22
- h4: __( 'H4' ),
23
- h5: __( 'H5' ),
24
- h6: __( 'H6' ),
25
- 'settings.color': __( 'Color' ),
26
- 'settings.typography': __( 'Typography' ),
27
- 'settings.shadow': __( 'Shadow' ),
28
- 'settings.layout': __( 'Layout' ),
29
- 'styles.color': __( 'Colors' ),
30
- 'styles.spacing': __( 'Spacing' ),
31
- 'styles.background': __( 'Background' ),
32
- 'styles.typography': __( 'Typography' ),
33
- };
34
- const getBlockNames = memoize( () =>
35
- getBlockTypes().reduce( ( accumulator, { name, title } ) => {
36
- accumulator[ name ] = title;
37
- return accumulator;
38
- }, {} )
39
- );
40
- const isObject = ( obj ) => obj !== null && typeof obj === 'object';
41
-
42
- /**
43
- * Get the translation for a given global styles key.
44
- * @param {string} key A key representing a path to a global style property or setting.
45
- * @return {string|undefined} A translated key or undefined if no translation exists.
46
- */
47
- function getTranslation( key ) {
48
- if ( translationMap[ key ] ) {
49
- return translationMap[ key ];
50
- }
51
-
52
- const keyArray = key.split( '.' );
53
-
54
- if ( keyArray?.[ 0 ] === 'blocks' ) {
55
- const blockName = getBlockNames()?.[ keyArray[ 1 ] ];
56
- return blockName || keyArray[ 1 ];
57
- }
58
-
59
- if ( keyArray?.[ 0 ] === 'elements' ) {
60
- return translationMap[ keyArray[ 1 ] ] || keyArray[ 1 ];
61
- }
62
-
63
- return undefined;
64
- }
65
-
66
- /**
67
- * A deep comparison of two objects, optimized for comparing global styles.
68
- * @param {Object} changedObject The changed object to compare.
69
- * @param {Object} originalObject The original object to compare against.
70
- * @param {string} parentPath A key/value pair object of block names and their rendered titles.
71
- * @return {string[]} An array of paths whose values have changed.
72
- */
73
- function deepCompare( changedObject, originalObject, parentPath = '' ) {
74
- // We have two non-object values to compare.
75
- if ( ! isObject( changedObject ) && ! isObject( originalObject ) ) {
76
- /*
77
- * Only return a path if the value has changed.
78
- * And then only the path name up to 2 levels deep.
79
- */
80
- return changedObject !== originalObject
81
- ? parentPath.split( '.' ).slice( 0, 2 ).join( '.' )
82
- : undefined;
83
- }
84
-
85
- // Enable comparison when an object doesn't have a corresponding property to compare.
86
- changedObject = isObject( changedObject ) ? changedObject : {};
87
- originalObject = isObject( originalObject ) ? originalObject : {};
88
-
89
- const allKeys = new Set( [
90
- ...Object.keys( changedObject ),
91
- ...Object.keys( originalObject ),
92
- ] );
93
-
94
- let diffs = [];
95
- for ( const key of allKeys ) {
96
- const path = parentPath ? parentPath + '.' + key : key;
97
- const changedPath = deepCompare(
98
- changedObject[ key ],
99
- originalObject[ key ],
100
- path
101
- );
102
- if ( changedPath ) {
103
- diffs = diffs.concat( changedPath );
104
- }
105
- }
106
- return diffs;
107
- }
108
-
109
- /**
110
- * Returns an array of translated summarized global styles changes.
111
- * Results are cached using a Map() key of `JSON.stringify( { next, previous } )`.
112
- *
113
- * @param {Object} next The changed object to compare.
114
- * @param {Object} previous The original object to compare against.
115
- * @return {Array[]} A 2-dimensional array of tuples: [ "group", "translated change" ].
116
- */
117
- export function getGlobalStylesChangelist( next, previous ) {
118
- const cacheKey = JSON.stringify( { next, previous } );
119
-
120
- if ( globalStylesChangesCache.has( cacheKey ) ) {
121
- return globalStylesChangesCache.get( cacheKey );
122
- }
123
-
124
- /*
125
- * Compare the two changesets with normalized keys.
126
- * The order of these keys determines the order in which
127
- * they'll appear in the results.
128
- */
129
- const changedValueTree = deepCompare(
130
- {
131
- styles: {
132
- background: next?.styles?.background,
133
- color: next?.styles?.color,
134
- typography: next?.styles?.typography,
135
- spacing: next?.styles?.spacing,
136
- },
137
- blocks: next?.styles?.blocks,
138
- elements: next?.styles?.elements,
139
- settings: next?.settings,
140
- },
141
- {
142
- styles: {
143
- background: previous?.styles?.background,
144
- color: previous?.styles?.color,
145
- typography: previous?.styles?.typography,
146
- spacing: previous?.styles?.spacing,
147
- },
148
- blocks: previous?.styles?.blocks,
149
- elements: previous?.styles?.elements,
150
- settings: previous?.settings,
151
- }
152
- );
153
-
154
- if ( ! changedValueTree.length ) {
155
- globalStylesChangesCache.set( cacheKey, EMPTY_ARRAY );
156
- return EMPTY_ARRAY;
157
- }
158
-
159
- // Remove duplicate results.
160
- const result = [ ...new Set( changedValueTree ) ]
161
- /*
162
- * Translate the keys.
163
- * Remove empty translations.
164
- */
165
- .reduce( ( acc, curr ) => {
166
- const translation = getTranslation( curr );
167
- if ( translation ) {
168
- acc.push( [ curr.split( '.' )[ 0 ], translation ] );
169
- }
170
- return acc;
171
- }, [] );
172
-
173
- globalStylesChangesCache.set( cacheKey, result );
174
-
175
- return result;
176
- }
177
-
178
- /**
179
- * From a getGlobalStylesChangelist() result, returns an array of translated global styles changes, grouped by type.
180
- * The types are 'blocks', 'elements', 'settings', and 'styles'.
181
- *
182
- * @param {Object} next The changed object to compare.
183
- * @param {Object} previous The original object to compare against.
184
- * @param {{maxResults:number}} options Options. maxResults: results to return before truncating.
185
- * @return {string[]} An array of translated changes.
186
- */
187
- export default function getGlobalStylesChanges( next, previous, options = {} ) {
188
- let changeList = getGlobalStylesChangelist( next, previous );
189
- const changesLength = changeList.length;
190
- const { maxResults } = options;
191
-
192
- if ( changesLength ) {
193
- // Truncate to `n` results if necessary.
194
- if ( !! maxResults && changesLength > maxResults ) {
195
- changeList = changeList.slice( 0, maxResults );
196
- }
197
- return Object.entries(
198
- changeList.reduce( ( acc, curr ) => {
199
- const group = acc[ curr[ 0 ] ] || [];
200
- if ( ! group.includes( curr[ 1 ] ) ) {
201
- acc[ curr[ 0 ] ] = [ ...group, curr[ 1 ] ];
202
- }
203
- return acc;
204
- }, {} )
205
- ).map( ( [ key, changeValues ] ) => {
206
- const changeValuesLength = changeValues.length;
207
- const joinedChangesValue = changeValues.join(
208
- /* translators: Used between list items, there is a space after the comma. */
209
- __( ', ' ) // eslint-disable-line @wordpress/i18n-no-flanking-whitespace
210
- );
211
- switch ( key ) {
212
- case 'blocks': {
213
- return sprintf(
214
- // translators: %s: a list of block names separated by a comma.
215
- _n( '%s block.', '%s blocks.', changeValuesLength ),
216
- joinedChangesValue
217
- );
218
- }
219
- case 'elements': {
220
- return sprintf(
221
- // translators: %s: a list of element names separated by a comma.
222
- _n( '%s element.', '%s elements.', changeValuesLength ),
223
- joinedChangesValue
224
- );
225
- }
226
- case 'settings': {
227
- return sprintf(
228
- // translators: %s: a list of theme.json setting labels separated by a comma.
229
- __( '%s settings.' ),
230
- joinedChangesValue
231
- );
232
- }
233
- case 'styles': {
234
- return sprintf(
235
- // translators: %s: a list of theme.json top-level styles labels separated by a comma.
236
- __( '%s styles.' ),
237
- joinedChangesValue
238
- );
239
- }
240
- default: {
241
- return sprintf(
242
- // translators: %s: a list of global styles changes separated by a comma.
243
- __( '%s.' ),
244
- joinedChangesValue
245
- );
246
- }
247
- }
248
- } );
249
- }
250
-
251
- return EMPTY_ARRAY;
252
- }
@@ -1,290 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import getGlobalStylesChanges, {
5
- getGlobalStylesChangelist,
6
- } from '../get-global-styles-changes';
7
-
8
- /**
9
- * WordPress dependencies
10
- */
11
- import {
12
- registerBlockType,
13
- unregisterBlockType,
14
- getBlockTypes,
15
- } from '@wordpress/blocks';
16
-
17
- describe( 'getGlobalStylesChanges and utils', () => {
18
- const next = {
19
- styles: {
20
- background: {
21
- backgroundImage: {
22
- url: 'https://example.com/image.jpg',
23
- },
24
- backgroundSize: 'contain',
25
- backgroundPosition: '30% 30%',
26
- backgroundRepeat: 'no-repeat',
27
- },
28
- typography: {
29
- fontSize: 'var(--wp--preset--font-size--potato)',
30
- fontStyle: 'normal',
31
- fontWeight: '600',
32
- lineHeight: '1.85',
33
- fontFamily: 'var(--wp--preset--font-family--asparagus)',
34
- },
35
- spacing: {
36
- padding: {
37
- top: '36px',
38
- right: '89px',
39
- bottom: '133px',
40
- left: 'var(--wp--preset--spacing--20)',
41
- },
42
- blockGap: '114px',
43
- },
44
- elements: {
45
- heading: {
46
- typography: {
47
- letterSpacing: '37px',
48
- },
49
- },
50
- h3: {
51
- typography: {
52
- lineHeight: '1.2',
53
- },
54
- },
55
- caption: {
56
- color: {
57
- text: 'var(--wp--preset--color--pineapple)',
58
- },
59
- },
60
- },
61
- color: {
62
- text: 'var(--wp--preset--color--tomato)',
63
- },
64
- blocks: {
65
- 'core/test-fiori-di-zucca': {
66
- color: {
67
- text: '#000000',
68
- },
69
- },
70
- },
71
- },
72
- settings: {
73
- color: {
74
- palette: {
75
- theme: [
76
- {
77
- slug: 'one',
78
- color: 'pink',
79
- },
80
- ],
81
- },
82
- gradients: [
83
- {
84
- name: 'Something something',
85
- gradient:
86
- 'linear-gradient(105deg,rgba(6,147,100,1) 0%,rgb(155,81,100) 100%)',
87
- slug: 'something-something',
88
- },
89
- ],
90
- },
91
- },
92
- };
93
- const previous = {
94
- styles: {
95
- background: {
96
- backgroundImage: {
97
- url: 'https://example.com/image_new.jpg',
98
- },
99
- backgroundSize: 'contain',
100
- backgroundPosition: '40% 77%',
101
- backgroundRepeat: 'repeat',
102
- },
103
- typography: {
104
- fontSize: 'var(--wp--preset--font-size--fungus)',
105
- fontStyle: 'normal',
106
- fontWeight: '600',
107
- lineHeight: '1.85',
108
- fontFamily: 'var(--wp--preset--font-family--grapes)',
109
- },
110
- spacing: {
111
- padding: {
112
- top: '36px',
113
- right: '89px',
114
- bottom: '133px',
115
- left: 'var(--wp--preset--spacing--20)',
116
- },
117
- blockGap: '114px',
118
- },
119
- elements: {
120
- heading: {
121
- typography: {
122
- letterSpacing: '37px',
123
- },
124
- },
125
- h3: {
126
- typography: {
127
- lineHeight: '2',
128
- },
129
- },
130
- h6: {
131
- typography: {
132
- lineHeight: '1.2',
133
- },
134
- },
135
- caption: {
136
- typography: {
137
- fontSize: '1.11rem',
138
- fontStyle: 'normal',
139
- fontWeight: '600',
140
- },
141
- },
142
- link: {
143
- typography: {
144
- lineHeight: 2,
145
- textDecoration: 'line-through',
146
- },
147
- color: {
148
- text: 'var(--wp--preset--color--egg)',
149
- },
150
- },
151
- },
152
- color: {
153
- text: 'var(--wp--preset--color--tomato)',
154
- background: 'var(--wp--preset--color--pumpkin)',
155
- },
156
- blocks: {
157
- 'core/test-fiori-di-zucca': {
158
- color: {
159
- text: '#fff',
160
- },
161
- },
162
- },
163
- },
164
- settings: {
165
- color: {
166
- palette: {
167
- theme: [
168
- {
169
- slug: 'one',
170
- color: 'blue',
171
- },
172
- ],
173
- custom: [
174
- {
175
- slug: 'one',
176
- color: 'tomato',
177
- },
178
- ],
179
- },
180
- gradients: [
181
- {
182
- name: 'Vivid cyan blue to vivid purple',
183
- gradient:
184
- 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
185
- slug: 'vivid-cyan-blue-to-vivid-purple',
186
- },
187
- ],
188
- },
189
- typography: {
190
- fluid: true,
191
- },
192
- },
193
- };
194
-
195
- beforeEach( () => {
196
- registerBlockType( 'core/test-fiori-di-zucca', {
197
- save: () => {},
198
- category: 'text',
199
- title: 'Test pumpkin flowers',
200
- edit: () => {},
201
- } );
202
- } );
203
-
204
- afterEach( () => {
205
- getBlockTypes().forEach( ( block ) => {
206
- unregisterBlockType( block.name );
207
- } );
208
- } );
209
-
210
- describe( 'getGlobalStylesChanges()', () => {
211
- it( 'returns a list of changes', () => {
212
- const result = getGlobalStylesChanges( next, previous );
213
- expect( result ).toEqual( [
214
- 'Background, Colors, Typography styles.',
215
- 'Test pumpkin flowers block.',
216
- 'H3, Caption, H6, Link elements.',
217
- 'Color, Typography settings.',
218
- ] );
219
- } );
220
-
221
- it( 'returns a list of truncated changes', () => {
222
- const resultA = getGlobalStylesChanges( next, previous, {
223
- maxResults: 4,
224
- } );
225
- expect( resultA ).toEqual( [
226
- 'Background, Colors, Typography styles.',
227
- 'Test pumpkin flowers block.',
228
- ] );
229
- } );
230
-
231
- it( 'skips unknown and unchanged keys', () => {
232
- const result = getGlobalStylesChanges(
233
- {
234
- styles: {
235
- frogs: {
236
- legs: 'green',
237
- },
238
- typography: {
239
- fontSize: '1rem',
240
- },
241
- settings: {
242
- '': {
243
- '': 'foo',
244
- },
245
- },
246
- },
247
- },
248
- {
249
- styles: {
250
- frogs: {
251
- legs: 'yellow',
252
- },
253
- typography: {
254
- fontSize: '1rem',
255
- },
256
- settings: {
257
- '': {
258
- '': 'bar',
259
- },
260
- },
261
- },
262
- }
263
- );
264
- expect( result ).toEqual( [] );
265
- } );
266
- } );
267
-
268
- describe( 'getGlobalStylesChangelist()', () => {
269
- it( 'compares two objects and returns a cached list of changed keys', () => {
270
- const resultA = getGlobalStylesChangelist( next, previous );
271
-
272
- expect( resultA ).toEqual( [
273
- [ 'styles', 'Background' ],
274
- [ 'styles', 'Colors' ],
275
- [ 'styles', 'Typography' ],
276
- [ 'blocks', 'Test pumpkin flowers' ],
277
- [ 'elements', 'H3' ],
278
- [ 'elements', 'Caption' ],
279
- [ 'elements', 'H6' ],
280
- [ 'elements', 'Link' ],
281
- [ 'settings', 'Color' ],
282
- [ 'settings', 'Typography' ],
283
- ] );
284
-
285
- const resultB = getGlobalStylesChangelist( next, previous );
286
-
287
- expect( resultB ).toEqual( resultA );
288
- } );
289
- } );
290
- } );