@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,151 +1,7 @@
1
- /**
2
- * External dependencies
3
- */
4
- import fastDeepEqual from 'fast-deep-equal/es6';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
9
4
  import { useViewportMatch } from '@wordpress/compose';
10
- import { getCSSValueFromRawStyle } from '@wordpress/style-engine';
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
- import { getTypographyFontSizeValue } from './typography-utils';
16
- import { getValueFromObjectPath } from '../../utils/object';
17
-
18
- /* Supporting data. */
19
- export const ROOT_BLOCK_SELECTOR = 'body';
20
- export const ROOT_CSS_PROPERTIES_SELECTOR = ':root';
21
-
22
- export const PRESET_METADATA = [
23
- {
24
- path: [ 'color', 'palette' ],
25
- valueKey: 'color',
26
- cssVarInfix: 'color',
27
- classes: [
28
- { classSuffix: 'color', propertyName: 'color' },
29
- {
30
- classSuffix: 'background-color',
31
- propertyName: 'background-color',
32
- },
33
- {
34
- classSuffix: 'border-color',
35
- propertyName: 'border-color',
36
- },
37
- ],
38
- },
39
- {
40
- path: [ 'color', 'gradients' ],
41
- valueKey: 'gradient',
42
- cssVarInfix: 'gradient',
43
- classes: [
44
- {
45
- classSuffix: 'gradient-background',
46
- propertyName: 'background',
47
- },
48
- ],
49
- },
50
- {
51
- path: [ 'color', 'duotone' ],
52
- valueKey: 'colors',
53
- cssVarInfix: 'duotone',
54
- valueFunc: ( { slug } ) => `url( '#wp-duotone-${ slug }' )`,
55
- classes: [],
56
- },
57
- {
58
- path: [ 'shadow', 'presets' ],
59
- valueKey: 'shadow',
60
- cssVarInfix: 'shadow',
61
- classes: [],
62
- },
63
- {
64
- path: [ 'typography', 'fontSizes' ],
65
- valueFunc: ( preset, settings ) =>
66
- getTypographyFontSizeValue( preset, settings ),
67
- valueKey: 'size',
68
- cssVarInfix: 'font-size',
69
- classes: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],
70
- },
71
- {
72
- path: [ 'typography', 'fontFamilies' ],
73
- valueKey: 'fontFamily',
74
- cssVarInfix: 'font-family',
75
- classes: [
76
- { classSuffix: 'font-family', propertyName: 'font-family' },
77
- ],
78
- },
79
- {
80
- path: [ 'spacing', 'spacingSizes' ],
81
- valueKey: 'size',
82
- cssVarInfix: 'spacing',
83
- classes: [],
84
- },
85
- {
86
- path: [ 'border', 'radiusSizes' ],
87
- valueKey: 'size',
88
- cssVarInfix: 'border-radius',
89
- classes: [],
90
- },
91
- ];
92
-
93
- export const STYLE_PATH_TO_CSS_VAR_INFIX = {
94
- 'color.background': 'color',
95
- 'color.text': 'color',
96
- 'filter.duotone': 'duotone',
97
- 'elements.link.color.text': 'color',
98
- 'elements.link.:hover.color.text': 'color',
99
- 'elements.link.typography.fontFamily': 'font-family',
100
- 'elements.link.typography.fontSize': 'font-size',
101
- 'elements.button.color.text': 'color',
102
- 'elements.button.color.background': 'color',
103
- 'elements.caption.color.text': 'color',
104
- 'elements.button.typography.fontFamily': 'font-family',
105
- 'elements.button.typography.fontSize': 'font-size',
106
- 'elements.heading.color': 'color',
107
- 'elements.heading.color.background': 'color',
108
- 'elements.heading.typography.fontFamily': 'font-family',
109
- 'elements.heading.gradient': 'gradient',
110
- 'elements.heading.color.gradient': 'gradient',
111
- 'elements.h1.color': 'color',
112
- 'elements.h1.color.background': 'color',
113
- 'elements.h1.typography.fontFamily': 'font-family',
114
- 'elements.h1.color.gradient': 'gradient',
115
- 'elements.h2.color': 'color',
116
- 'elements.h2.color.background': 'color',
117
- 'elements.h2.typography.fontFamily': 'font-family',
118
- 'elements.h2.color.gradient': 'gradient',
119
- 'elements.h3.color': 'color',
120
- 'elements.h3.color.background': 'color',
121
- 'elements.h3.typography.fontFamily': 'font-family',
122
- 'elements.h3.color.gradient': 'gradient',
123
- 'elements.h4.color': 'color',
124
- 'elements.h4.color.background': 'color',
125
- 'elements.h4.typography.fontFamily': 'font-family',
126
- 'elements.h4.color.gradient': 'gradient',
127
- 'elements.h5.color': 'color',
128
- 'elements.h5.color.background': 'color',
129
- 'elements.h5.typography.fontFamily': 'font-family',
130
- 'elements.h5.color.gradient': 'gradient',
131
- 'elements.h6.color': 'color',
132
- 'elements.h6.color.background': 'color',
133
- 'elements.h6.typography.fontFamily': 'font-family',
134
- 'elements.h6.color.gradient': 'gradient',
135
- 'color.gradient': 'gradient',
136
- shadow: 'shadow',
137
- 'typography.fontSize': 'font-size',
138
- 'typography.fontFamily': 'font-family',
139
- };
140
-
141
- // A static list of block attributes that store global style preset slugs.
142
- export const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
143
- 'color.background': 'backgroundColor',
144
- 'color.text': 'textColor',
145
- 'color.gradient': 'gradient',
146
- 'typography.fontSize': 'fontSize',
147
- 'typography.fontFamily': 'fontFamily',
148
- };
149
5
 
150
6
  export function useToolsPanelDropdownMenuProps() {
151
7
  const isMobile = useViewportMatch( 'medium', '<' );
@@ -160,208 +16,6 @@ export function useToolsPanelDropdownMenuProps() {
160
16
  : {};
161
17
  }
162
18
 
163
- function findInPresetsBy(
164
- features,
165
- blockName,
166
- presetPath,
167
- presetProperty,
168
- presetValueValue
169
- ) {
170
- // Block presets take priority above root level presets.
171
- const orderedPresetsByOrigin = [
172
- getValueFromObjectPath( features, [
173
- 'blocks',
174
- blockName,
175
- ...presetPath,
176
- ] ),
177
- getValueFromObjectPath( features, presetPath ),
178
- ];
179
-
180
- for ( const presetByOrigin of orderedPresetsByOrigin ) {
181
- if ( presetByOrigin ) {
182
- // Preset origins ordered by priority.
183
- const origins = [ 'custom', 'theme', 'default' ];
184
- for ( const origin of origins ) {
185
- const presets = presetByOrigin[ origin ];
186
- if ( presets ) {
187
- const presetObject = presets.find(
188
- ( preset ) =>
189
- preset[ presetProperty ] === presetValueValue
190
- );
191
- if ( presetObject ) {
192
- if ( presetProperty === 'slug' ) {
193
- return presetObject;
194
- }
195
- // If there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.
196
- const highestPresetObjectWithSameSlug = findInPresetsBy(
197
- features,
198
- blockName,
199
- presetPath,
200
- 'slug',
201
- presetObject.slug
202
- );
203
- if (
204
- highestPresetObjectWithSameSlug[
205
- presetProperty
206
- ] === presetObject[ presetProperty ]
207
- ) {
208
- return presetObject;
209
- }
210
- return undefined;
211
- }
212
- }
213
- }
214
- }
215
- }
216
- }
217
-
218
- export function getPresetVariableFromValue(
219
- features,
220
- blockName,
221
- variableStylePath,
222
- presetPropertyValue
223
- ) {
224
- if ( ! presetPropertyValue ) {
225
- return presetPropertyValue;
226
- }
227
-
228
- const cssVarInfix = STYLE_PATH_TO_CSS_VAR_INFIX[ variableStylePath ];
229
-
230
- const metadata = PRESET_METADATA.find(
231
- ( data ) => data.cssVarInfix === cssVarInfix
232
- );
233
-
234
- if ( ! metadata ) {
235
- // The property doesn't have preset data
236
- // so the value should be returned as it is.
237
- return presetPropertyValue;
238
- }
239
- const { valueKey, path } = metadata;
240
-
241
- const presetObject = findInPresetsBy(
242
- features,
243
- blockName,
244
- path,
245
- valueKey,
246
- presetPropertyValue
247
- );
248
-
249
- if ( ! presetObject ) {
250
- // Value wasn't found in the presets,
251
- // so it must be a custom value.
252
- return presetPropertyValue;
253
- }
254
-
255
- return `var:preset|${ cssVarInfix }|${ presetObject.slug }`;
256
- }
257
-
258
- function getValueFromPresetVariable(
259
- features,
260
- blockName,
261
- variable,
262
- [ presetType, slug ]
263
- ) {
264
- const metadata = PRESET_METADATA.find(
265
- ( data ) => data.cssVarInfix === presetType
266
- );
267
- if ( ! metadata ) {
268
- return variable;
269
- }
270
-
271
- const presetObject = findInPresetsBy(
272
- features.settings,
273
- blockName,
274
- metadata.path,
275
- 'slug',
276
- slug
277
- );
278
-
279
- if ( presetObject ) {
280
- const { valueKey } = metadata;
281
- const result = presetObject[ valueKey ];
282
- return getValueFromVariable( features, blockName, result );
283
- }
284
-
285
- return variable;
286
- }
287
-
288
- function getValueFromCustomVariable( features, blockName, variable, path ) {
289
- const result =
290
- getValueFromObjectPath( features.settings, [
291
- 'blocks',
292
- blockName,
293
- 'custom',
294
- ...path,
295
- ] ) ??
296
- getValueFromObjectPath( features.settings, [ 'custom', ...path ] );
297
- if ( ! result ) {
298
- return variable;
299
- }
300
- // A variable may reference another variable so we need recursion until we find the value.
301
- return getValueFromVariable( features, blockName, result );
302
- }
303
-
304
- /**
305
- * Attempts to fetch the value of a theme.json CSS variable.
306
- *
307
- * @param {Object} features GlobalStylesContext config, e.g., user, base or merged. Represents the theme.json tree.
308
- * @param {string} blockName The name of a block as represented in the styles property. E.g., 'root' for root-level, and 'core/${blockName}' for blocks.
309
- * @param {string|*} variable An incoming style value. A CSS var value is expected, but it could be any value.
310
- * @return {string|*|{ref}} The value of the CSS var, if found. If not found, the passed variable argument.
311
- */
312
- export function getValueFromVariable( features, blockName, variable ) {
313
- if ( ! variable || typeof variable !== 'string' ) {
314
- if ( typeof variable?.ref === 'string' ) {
315
- variable = getValueFromObjectPath( features, variable.ref );
316
- // Presence of another ref indicates a reference to another dynamic value.
317
- // Pointing to another dynamic value is not supported.
318
- if ( ! variable || !! variable?.ref ) {
319
- return variable;
320
- }
321
- } else {
322
- return variable;
323
- }
324
- }
325
- const USER_VALUE_PREFIX = 'var:';
326
- const THEME_VALUE_PREFIX = 'var(--wp--';
327
- const THEME_VALUE_SUFFIX = ')';
328
-
329
- let parsedVar;
330
-
331
- if ( variable.startsWith( USER_VALUE_PREFIX ) ) {
332
- parsedVar = variable.slice( USER_VALUE_PREFIX.length ).split( '|' );
333
- } else if (
334
- variable.startsWith( THEME_VALUE_PREFIX ) &&
335
- variable.endsWith( THEME_VALUE_SUFFIX )
336
- ) {
337
- parsedVar = variable
338
- .slice( THEME_VALUE_PREFIX.length, -THEME_VALUE_SUFFIX.length )
339
- .split( '--' );
340
- } else {
341
- // We don't know how to parse the value: either is raw of uses complex CSS such as `calc(1px * var(--wp--variable) )`
342
- return variable;
343
- }
344
-
345
- const [ type, ...path ] = parsedVar;
346
- if ( type === 'preset' ) {
347
- return getValueFromPresetVariable(
348
- features,
349
- blockName,
350
- variable,
351
- path
352
- );
353
- }
354
- if ( type === 'custom' ) {
355
- return getValueFromCustomVariable(
356
- features,
357
- blockName,
358
- variable,
359
- path
360
- );
361
- }
362
- return variable;
363
- }
364
-
365
19
  /**
366
20
  * Function that scopes a selector with another one. This works a bit like
367
21
  * SCSS nesting except the `&` operator isn't supported.
@@ -396,225 +50,3 @@ export function scopeSelector( scope, selector ) {
396
50
 
397
51
  return selectorsScoped.join( ', ' );
398
52
  }
399
-
400
- /**
401
- * Scopes a collection of selectors for features and subfeatures.
402
- *
403
- * @example
404
- * ```js
405
- * const scope = '.custom-scope';
406
- * const selectors = {
407
- * color: '.wp-my-block p',
408
- * typography: { fontSize: '.wp-my-block caption' },
409
- * };
410
- * const result = scopeFeatureSelector( scope, selectors );
411
- * // result is {
412
- * // color: '.custom-scope .wp-my-block p',
413
- * // typography: { fonSize: '.custom-scope .wp-my-block caption' },
414
- * // }
415
- * ```
416
- *
417
- * @param {string} scope Selector to scope collection of selectors with.
418
- * @param {Object} selectors Collection of feature selectors e.g.
419
- *
420
- * @return {Object|undefined} Scoped collection of feature selectors.
421
- */
422
- export function scopeFeatureSelectors( scope, selectors ) {
423
- if ( ! scope || ! selectors ) {
424
- return;
425
- }
426
-
427
- const featureSelectors = {};
428
-
429
- Object.entries( selectors ).forEach( ( [ feature, selector ] ) => {
430
- if ( typeof selector === 'string' ) {
431
- featureSelectors[ feature ] = scopeSelector( scope, selector );
432
- }
433
-
434
- if ( typeof selector === 'object' ) {
435
- featureSelectors[ feature ] = {};
436
-
437
- Object.entries( selector ).forEach(
438
- ( [ subfeature, subfeatureSelector ] ) => {
439
- featureSelectors[ feature ][ subfeature ] = scopeSelector(
440
- scope,
441
- subfeatureSelector
442
- );
443
- }
444
- );
445
- }
446
- } );
447
-
448
- return featureSelectors;
449
- }
450
-
451
- /**
452
- * Appends a sub-selector to an existing one.
453
- *
454
- * Given the compounded `selector` "h1, h2, h3"
455
- * and the `toAppend` selector ".some-class" the result will be
456
- * "h1.some-class, h2.some-class, h3.some-class".
457
- *
458
- * @param {string} selector Original selector.
459
- * @param {string} toAppend Selector to append.
460
- *
461
- * @return {string} The new selector.
462
- */
463
- export function appendToSelector( selector, toAppend ) {
464
- if ( ! selector.includes( ',' ) ) {
465
- return selector + toAppend;
466
- }
467
- const selectors = selector.split( ',' );
468
- const newSelectors = selectors.map( ( sel ) => sel + toAppend );
469
- return newSelectors.join( ',' );
470
- }
471
-
472
- /**
473
- * Compares global style variations according to their styles and settings properties.
474
- *
475
- * @example
476
- * ```js
477
- * const globalStyles = { styles: { typography: { fontSize: '10px' } }, settings: {} };
478
- * const variation = { styles: { typography: { fontSize: '10000px' } }, settings: {} };
479
- * const isEqual = areGlobalStyleConfigsEqual( globalStyles, variation );
480
- * // false
481
- * ```
482
- *
483
- * @param {Object} original A global styles object.
484
- * @param {Object} variation A global styles object.
485
- *
486
- * @return {boolean} Whether `original` and `variation` match.
487
- */
488
- export function areGlobalStyleConfigsEqual( original, variation ) {
489
- if ( typeof original !== 'object' || typeof variation !== 'object' ) {
490
- return original === variation;
491
- }
492
- return (
493
- fastDeepEqual( original?.styles, variation?.styles ) &&
494
- fastDeepEqual( original?.settings, variation?.settings )
495
- );
496
- }
497
-
498
- /**
499
- * Generates the selector for a block style variation by creating the
500
- * appropriate CSS class and adding it to the ancestor portion of the block's
501
- * selector.
502
- *
503
- * For example, take the Button block which has a compound selector:
504
- * `.wp-block-button .wp-block-button__link`. With a variation named 'custom',
505
- * the class `.is-style-custom` should be added to the `.wp-block-button`
506
- * ancestor only.
507
- *
508
- * This function will take into account comma separated and complex selectors.
509
- *
510
- * @param {string} variation Name for the variation.
511
- * @param {string} blockSelector CSS selector for the block.
512
- *
513
- * @return {string} CSS selector for the block style variation.
514
- */
515
- export function getBlockStyleVariationSelector( variation, blockSelector ) {
516
- const variationClass = `.is-style-${ variation }`;
517
-
518
- if ( ! blockSelector ) {
519
- return variationClass;
520
- }
521
-
522
- const ancestorRegex = /((?::\([^)]+\))?\s*)([^\s:]+)/;
523
- const addVariationClass = ( _match, group1, group2 ) => {
524
- return group1 + group2 + variationClass;
525
- };
526
-
527
- const result = blockSelector
528
- .split( ',' )
529
- .map( ( part ) => part.replace( ancestorRegex, addVariationClass ) );
530
-
531
- return result.join( ',' );
532
- }
533
-
534
- /**
535
- * Looks up a theme file URI based on a relative path.
536
- *
537
- * @param {string} file A relative path.
538
- * @param {Array<Object>} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths.
539
- * @return {string} A resolved theme file URI, if one is found in the themeFileURIs collection.
540
- */
541
- export function getResolvedThemeFilePath( file, themeFileURIs ) {
542
- if ( ! file || ! themeFileURIs || ! Array.isArray( themeFileURIs ) ) {
543
- return file;
544
- }
545
-
546
- const uri = themeFileURIs.find(
547
- ( themeFileUri ) => themeFileUri?.name === file
548
- );
549
-
550
- if ( ! uri?.href ) {
551
- return file;
552
- }
553
-
554
- return uri?.href;
555
- }
556
-
557
- /**
558
- * Resolves ref values in theme JSON.
559
- *
560
- * @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.
561
- * @param {Object} tree A theme.json object.
562
- * @return {*} The resolved value or incoming ruleValue.
563
- */
564
- export function getResolvedRefValue( ruleValue, tree ) {
565
- if ( ! ruleValue || ! tree ) {
566
- return ruleValue;
567
- }
568
-
569
- /*
570
- * Where the rule value is an object with a 'ref' property pointing
571
- * to a path, this converts that path into the value at that path.
572
- * For example: { "ref": "style.color.background" } => "#fff".
573
- */
574
- if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
575
- const resolvedRuleValue = getCSSValueFromRawStyle(
576
- getValueFromObjectPath( tree, ruleValue.ref )
577
- );
578
-
579
- /*
580
- * Presence of another ref indicates a reference to another dynamic value.
581
- * Pointing to another dynamic value is not supported.
582
- */
583
- if ( resolvedRuleValue?.ref ) {
584
- return undefined;
585
- }
586
-
587
- if ( resolvedRuleValue === undefined ) {
588
- return ruleValue;
589
- }
590
-
591
- return resolvedRuleValue;
592
- }
593
- return ruleValue;
594
- }
595
-
596
- /**
597
- * Resolves ref and relative path values in theme JSON.
598
- *
599
- * @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.
600
- * @param {Object} tree A theme.json object.
601
- * @return {*} The resolved value or incoming ruleValue.
602
- */
603
- export function getResolvedValue( ruleValue, tree ) {
604
- if ( ! ruleValue || ! tree ) {
605
- return ruleValue;
606
- }
607
-
608
- // Resolve ref values.
609
- const resolvedValue = getResolvedRefValue( ruleValue, tree );
610
-
611
- // Resolve relative paths.
612
- if ( resolvedValue?.url ) {
613
- resolvedValue.url = getResolvedThemeFilePath(
614
- resolvedValue.url,
615
- tree?._links?.[ 'wp:theme-file' ]
616
- );
617
- }
618
-
619
- return resolvedValue;
620
- }
@@ -4,7 +4,8 @@
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { useViewportMatch } from '@wordpress/compose';
6
6
  import { Button } from '@wordpress/components';
7
- import { useCallback, useMemo } from '@wordpress/element';
7
+ import { useCallback, useMemo, useState } from '@wordpress/element';
8
+ import { useSelect } from '@wordpress/data';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
@@ -12,14 +13,55 @@ import { useCallback, useMemo } from '@wordpress/element';
12
13
  import { MediaCategoryPanel } from './media-panel';
13
14
  import MediaUploadCheck from '../../media-upload/check';
14
15
  import MediaUpload from '../../media-upload';
16
+ import MediaUploadModal from '../../media-upload-modal';
15
17
  import { useMediaCategories } from './hooks';
16
18
  import { getBlockAndPreviewFromMedia } from './utils';
17
19
  import MobileTabNavigation from '../mobile-tab-navigation';
18
20
  import CategoryTabs from '../category-tabs';
19
21
  import InserterNoResults from '../no-results';
22
+ import { store as blockEditorStore } from '../../../store';
20
23
 
21
24
  const ALLOWED_MEDIA_TYPES = [ 'image', 'video', 'audio' ];
22
25
 
26
+ /**
27
+ * Conditional Media component that uses MediaUploadModal when experiment is enabled,
28
+ * otherwise falls back to MediaUpload.
29
+ *
30
+ * @param {Object} root0 Component props.
31
+ * @param {Function} root0.render Render prop function that receives { open } object.
32
+ * @return {JSX.Element} The component.
33
+ */
34
+ function ConditionalMediaUpload( { render, ...props } ) {
35
+ const [ isModalOpen, setIsModalOpen ] = useState( false );
36
+ const mediaUpload = useSelect( ( select ) => {
37
+ const { getSettings } = select( blockEditorStore );
38
+ return getSettings().mediaUpload;
39
+ }, [] );
40
+
41
+ if ( window.__experimentalDataViewsMediaModal ) {
42
+ return (
43
+ <>
44
+ { render && render( { open: () => setIsModalOpen( true ) } ) }
45
+ <MediaUploadModal
46
+ { ...props }
47
+ isOpen={ isModalOpen }
48
+ onClose={ () => {
49
+ setIsModalOpen( false );
50
+ props.onClose?.();
51
+ } }
52
+ onSelect={ ( media ) => {
53
+ setIsModalOpen( false );
54
+ props.onSelect?.( media );
55
+ } }
56
+ onUpload={ mediaUpload }
57
+ />
58
+ </>
59
+ );
60
+ }
61
+
62
+ return <MediaUpload { ...props } render={ render } />;
63
+ }
64
+
23
65
  function MediaTab( {
24
66
  rootClientId,
25
67
  selectedCategory,
@@ -65,7 +107,7 @@ function MediaTab( {
65
107
  { children }
66
108
  </CategoryTabs>
67
109
  <MediaUploadCheck>
68
- <MediaUpload
110
+ <ConditionalMediaUpload
69
111
  multiple={ false }
70
112
  onSelect={ onSelectMedia }
71
113
  allowedTypes={ ALLOWED_MEDIA_TYPES }
@@ -151,7 +151,7 @@ $block-inserter-tabs-height: 44px;
151
151
  color: $gray-700;
152
152
  text-transform: uppercase;
153
153
  font-size: 11px;
154
- font-weight: 500;
154
+ font-weight: $font-weight-medium;
155
155
  }
156
156
 
157
157
  .block-editor-inserter__panel-dropdown select.components-select-control__input.components-select-control__input.components-select-control__input {
@@ -440,7 +440,7 @@ $block-inserter-tabs-height: 44px;
440
440
  }
441
441
 
442
442
  .components-heading.block-editor-inserter__patterns-category-panel-title {
443
- font-weight: 500;
443
+ font-weight: $font-weight-medium;
444
444
  }
445
445
 
446
446
  .block-editor-inserter__patterns-explore-button,
@@ -30,8 +30,6 @@ const globalTips = [
30
30
 
31
31
  function Tips() {
32
32
  const [ randomIndex ] = useState(
33
- // Disable Reason: I'm not generating an HTML id.
34
- // eslint-disable-next-line no-restricted-syntax
35
33
  Math.floor( Math.random() * globalTips.length )
36
34
  );
37
35