@wordpress/block-editor 15.6.1-next.36001005c.0 → 15.6.1

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 (163) hide show
  1. package/build/components/background-image-control/index.js +2 -2
  2. package/build/components/background-image-control/index.js.map +2 -2
  3. package/build/components/block-list/block.js +3 -3
  4. package/build/components/block-list/block.js.map +2 -2
  5. package/build/components/block-list/index.js +2 -2
  6. package/build/components/block-list/index.js.map +1 -1
  7. package/build/components/block-quick-navigation/index.js +0 -1
  8. package/build/components/block-quick-navigation/index.js.map +2 -2
  9. package/build/components/global-styles/border-panel.js +1 -2
  10. package/build/components/global-styles/border-panel.js.map +2 -2
  11. package/build/components/global-styles/color-panel.js +1 -2
  12. package/build/components/global-styles/color-panel.js.map +2 -2
  13. package/build/components/global-styles/dimensions-panel.js +2 -3
  14. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  15. package/build/components/global-styles/filters-panel.js +1 -2
  16. package/build/components/global-styles/filters-panel.js.map +2 -2
  17. package/build/components/global-styles/get-block-css-selector.js +78 -0
  18. package/build/components/global-styles/get-block-css-selector.js.map +7 -0
  19. package/build/components/global-styles/hooks.js +95 -23
  20. package/build/components/global-styles/hooks.js.map +2 -2
  21. package/build/components/global-styles/index.js +14 -0
  22. package/build/components/global-styles/index.js.map +2 -2
  23. package/build/components/global-styles/typography-panel.js +19 -3
  24. package/build/components/global-styles/typography-panel.js.map +2 -2
  25. package/build/components/global-styles/typography-utils.js +49 -2
  26. package/build/components/global-styles/typography-utils.js.map +2 -2
  27. package/build/components/global-styles/use-global-styles-output.js +998 -0
  28. package/build/components/global-styles/use-global-styles-output.js.map +7 -0
  29. package/build/components/global-styles/utils.js +377 -0
  30. package/build/components/global-styles/utils.js.map +2 -2
  31. package/build/components/rich-text/index.js +8 -7
  32. package/build/components/rich-text/index.js.map +2 -2
  33. package/build/hooks/block-bindings.js +111 -170
  34. package/build/hooks/block-bindings.js.map +2 -2
  35. package/build/hooks/block-style-variation.js +10 -6
  36. package/build/hooks/block-style-variation.js.map +2 -2
  37. package/build/hooks/custom-class-name.js +1 -1
  38. package/build/hooks/custom-class-name.js.map +1 -1
  39. package/build/hooks/duotone.js +3 -3
  40. package/build/hooks/duotone.js.map +2 -2
  41. package/build/hooks/fit-text.js +31 -18
  42. package/build/hooks/fit-text.js.map +2 -2
  43. package/build/hooks/font-size.js +6 -5
  44. package/build/hooks/font-size.js.map +2 -2
  45. package/build/hooks/metadata.js +48 -2
  46. package/build/hooks/metadata.js.map +2 -2
  47. package/build/hooks/typography.js +11 -4
  48. package/build/hooks/typography.js.map +3 -3
  49. package/build/hooks/use-typography-props.js +2 -2
  50. package/build/hooks/use-typography-props.js.map +2 -2
  51. package/build/store/private-selectors.js +3 -3
  52. package/build/store/private-selectors.js.map +2 -2
  53. package/build/store/selectors.js +38 -13
  54. package/build/store/selectors.js.map +2 -2
  55. package/build/store/utils.js +2 -1
  56. package/build/store/utils.js.map +2 -2
  57. package/build/utils/fit-text-utils.js +4 -4
  58. package/build/utils/fit-text-utils.js.map +2 -2
  59. package/build-module/components/background-image-control/index.js +1 -1
  60. package/build-module/components/background-image-control/index.js.map +2 -2
  61. package/build-module/components/block-list/block.js +3 -3
  62. package/build-module/components/block-list/block.js.map +2 -2
  63. package/build-module/components/block-list/index.js +2 -2
  64. package/build-module/components/block-list/index.js.map +1 -1
  65. package/build-module/components/block-quick-navigation/index.js +0 -1
  66. package/build-module/components/block-quick-navigation/index.js.map +2 -2
  67. package/build-module/components/global-styles/border-panel.js +1 -2
  68. package/build-module/components/global-styles/border-panel.js.map +2 -2
  69. package/build-module/components/global-styles/color-panel.js +1 -2
  70. package/build-module/components/global-styles/color-panel.js.map +2 -2
  71. package/build-module/components/global-styles/dimensions-panel.js +1 -2
  72. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  73. package/build-module/components/global-styles/filters-panel.js +1 -2
  74. package/build-module/components/global-styles/filters-panel.js.map +2 -2
  75. package/build-module/components/global-styles/get-block-css-selector.js +54 -0
  76. package/build-module/components/global-styles/get-block-css-selector.js.map +7 -0
  77. package/build-module/components/global-styles/hooks.js +95 -27
  78. package/build-module/components/global-styles/hooks.js.map +2 -2
  79. package/build-module/components/global-styles/index.js +14 -0
  80. package/build-module/components/global-styles/index.js.map +2 -2
  81. package/build-module/components/global-styles/typography-panel.js +19 -3
  82. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  83. package/build-module/components/global-styles/typography-utils.js +49 -1
  84. package/build-module/components/global-styles/typography-utils.js.map +2 -2
  85. package/build-module/components/global-styles/use-global-styles-output.js +979 -0
  86. package/build-module/components/global-styles/use-global-styles-output.js.map +7 -0
  87. package/build-module/components/global-styles/utils.js +364 -0
  88. package/build-module/components/global-styles/utils.js.map +2 -2
  89. package/build-module/components/rich-text/index.js +8 -7
  90. package/build-module/components/rich-text/index.js.map +2 -2
  91. package/build-module/hooks/block-bindings.js +112 -172
  92. package/build-module/hooks/block-bindings.js.map +2 -2
  93. package/build-module/hooks/block-style-variation.js +12 -4
  94. package/build-module/hooks/block-style-variation.js.map +2 -2
  95. package/build-module/hooks/custom-class-name.js +1 -1
  96. package/build-module/hooks/custom-class-name.js.map +1 -1
  97. package/build-module/hooks/duotone.js +3 -3
  98. package/build-module/hooks/duotone.js.map +2 -2
  99. package/build-module/hooks/fit-text.js +32 -19
  100. package/build-module/hooks/fit-text.js.map +2 -2
  101. package/build-module/hooks/font-size.js +5 -4
  102. package/build-module/hooks/font-size.js.map +2 -2
  103. package/build-module/hooks/metadata.js +46 -1
  104. package/build-module/hooks/metadata.js.map +2 -2
  105. package/build-module/hooks/typography.js +11 -4
  106. package/build-module/hooks/typography.js.map +3 -3
  107. package/build-module/hooks/use-typography-props.js +1 -1
  108. package/build-module/hooks/use-typography-props.js.map +2 -2
  109. package/build-module/store/private-selectors.js +2 -2
  110. package/build-module/store/private-selectors.js.map +2 -2
  111. package/build-module/store/selectors.js +39 -14
  112. package/build-module/store/selectors.js.map +2 -2
  113. package/build-module/store/utils.js +3 -2
  114. package/build-module/store/utils.js.map +2 -2
  115. package/build-module/utils/fit-text-utils.js +4 -4
  116. package/build-module/utils/fit-text-utils.js.map +2 -2
  117. package/build-style/style-rtl.css +6 -10
  118. package/build-style/style.css +6 -10
  119. package/package.json +35 -36
  120. package/src/components/background-image-control/index.js +1 -1
  121. package/src/components/block-card/style.scss +1 -1
  122. package/src/components/block-list/block.js +1 -1
  123. package/src/components/block-list/index.js +2 -2
  124. package/src/components/block-navigation/style.scss +1 -1
  125. package/src/components/block-quick-navigation/index.js +0 -1
  126. package/src/components/block-switcher/style.scss +1 -1
  127. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  128. package/src/components/global-styles/border-panel.js +1 -2
  129. package/src/components/global-styles/color-panel.js +1 -2
  130. package/src/components/global-styles/color-panel.native.js +1 -1
  131. package/src/components/global-styles/dimensions-panel.js +1 -2
  132. package/src/components/global-styles/filters-panel.js +1 -2
  133. package/src/components/global-styles/get-block-css-selector.js +114 -0
  134. package/src/components/global-styles/hooks.js +108 -29
  135. package/src/components/global-styles/index.js +8 -0
  136. package/src/components/global-styles/test/typography-utils.js +806 -0
  137. package/src/components/global-styles/test/use-global-styles-output.js +1131 -0
  138. package/src/components/global-styles/test/utils.js +442 -1
  139. package/src/components/global-styles/typography-panel.js +27 -3
  140. package/src/components/global-styles/typography-utils.js +133 -0
  141. package/src/components/global-styles/use-global-styles-output.js +1487 -0
  142. package/src/components/global-styles/utils.js +537 -0
  143. package/src/components/inserter/style.scss +2 -2
  144. package/src/components/multi-selection-inspector/style.scss +1 -1
  145. package/src/components/rich-text/index.js +8 -14
  146. package/src/hooks/block-bindings.js +79 -153
  147. package/src/hooks/block-style-variation.js +12 -4
  148. package/src/hooks/custom-class-name.js +1 -1
  149. package/src/hooks/duotone.js +3 -3
  150. package/src/hooks/fit-text.js +37 -28
  151. package/src/hooks/font-size.js +8 -4
  152. package/src/hooks/metadata.js +89 -0
  153. package/src/hooks/test/metadata.js +316 -0
  154. package/src/hooks/typography.js +15 -4
  155. package/src/hooks/use-typography-props.js +1 -1
  156. package/src/store/private-selectors.js +2 -2
  157. package/src/store/selectors.js +59 -21
  158. package/src/store/test/selectors.js +1 -1
  159. package/src/store/utils.js +2 -1
  160. package/src/style.scss +0 -1
  161. package/src/utils/fit-text-utils.js +4 -16
  162. package/tsconfig.json +0 -1
  163. package/src/components/block-quick-navigation/style.scss +0 -5
@@ -7,6 +7,145 @@ import fastDeepEqual from 'fast-deep-equal/es6';
7
7
  * WordPress dependencies
8
8
  */
9
9
  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
+ };
10
149
 
11
150
  export function useToolsPanelDropdownMenuProps() {
12
151
  const isMobile = useViewportMatch( 'medium', '<' );
@@ -21,6 +160,208 @@ export function useToolsPanelDropdownMenuProps() {
21
160
  : {};
22
161
  }
23
162
 
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
+
24
365
  /**
25
366
  * Function that scopes a selector with another one. This works a bit like
26
367
  * SCSS nesting except the `&` operator isn't supported.
@@ -56,6 +397,78 @@ export function scopeSelector( scope, selector ) {
56
397
  return selectorsScoped.join( ', ' );
57
398
  }
58
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
+
59
472
  /**
60
473
  * Compares global style variations according to their styles and settings properties.
61
474
  *
@@ -81,3 +494,127 @@ export function areGlobalStyleConfigsEqual( original, variation ) {
81
494
  fastDeepEqual( original?.settings, variation?.settings )
82
495
  );
83
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
+ }
@@ -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: $font-weight-medium;
154
+ font-weight: 500;
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: $font-weight-medium;
443
+ font-weight: 500;
444
444
  }
445
445
 
446
446
  .block-editor-inserter__patterns-explore-button,
@@ -5,7 +5,7 @@
5
5
  }
6
6
 
7
7
  .block-editor-multi-selection-inspector__card-title {
8
- font-weight: $font-weight-medium;
8
+ font-weight: 500;
9
9
  }
10
10
 
11
11
  .block-editor-multi-selection-inspector__card .block-editor-block-icon {
@@ -41,6 +41,7 @@ import { getAllowedFormats } from './utils';
41
41
  import { Content, valueToHTMLString } from './content';
42
42
  import { withDeprecations } from './with-deprecations';
43
43
  import BlockContext from '../block-context';
44
+ import { PrivateBlockContext } from '../block-list/private-block-context';
44
45
 
45
46
  export const keyboardShortcutContext = createContext();
46
47
  keyboardShortcutContext.displayName = 'keyboardShortcutContext';
@@ -124,9 +125,10 @@ export function RichTextWrapper(
124
125
  const instanceId = useInstanceId( RichTextWrapper );
125
126
  const anchorRef = useRef();
126
127
  const context = useBlockEditContext();
127
- const { clientId, isSelected: isBlockSelected, name: blockName } = context;
128
+ const { clientId, isSelected: isBlockSelected } = context;
128
129
  const blockBindings = context[ blockBindingsKey ];
129
130
  const blockContext = useContext( BlockContext );
131
+ const { bindableAttributes } = useContext( PrivateBlockContext );
130
132
  const registry = useRegistry();
131
133
  const selector = ( select ) => {
132
134
  // Avoid subscribing to the block editor store if the block is not
@@ -171,15 +173,7 @@ export function RichTextWrapper(
171
173
 
172
174
  const { disableBoundBlock, bindingsPlaceholder, bindingsLabel } = useSelect(
173
175
  ( select ) => {
174
- const { __experimentalBlockBindingsSupportedAttributes } =
175
- select( blockEditorStore ).getSettings();
176
-
177
- if (
178
- ! blockBindings?.[ identifier ] ||
179
- ! (
180
- blockName in __experimentalBlockBindingsSupportedAttributes
181
- )
182
- ) {
176
+ if ( ! blockBindings?.[ identifier ] || ! bindableAttributes ) {
183
177
  return {};
184
178
  }
185
179
 
@@ -214,12 +208,12 @@ export function RichTextWrapper(
214
208
  const { getBlockAttributes } = select( blockEditorStore );
215
209
  const blockAttributes = getBlockAttributes( clientId );
216
210
  let clientSideFieldLabel = null;
217
- if ( blockBindingsSource?.editorUI ) {
218
- const editorUIResult = blockBindingsSource.editorUI( {
211
+ if ( blockBindingsSource?.getFieldsList ) {
212
+ const fieldsItems = blockBindingsSource.getFieldsList( {
219
213
  select,
220
214
  context: blockBindingsContext,
221
215
  } );
222
- clientSideFieldLabel = editorUIResult.data?.find( ( item ) =>
216
+ clientSideFieldLabel = fieldsItems?.find( ( item ) =>
223
217
  fastDeepEqual( item.args, relatedBinding?.args )
224
218
  )?.label;
225
219
  }
@@ -252,7 +246,7 @@ export function RichTextWrapper(
252
246
  [
253
247
  blockBindings,
254
248
  identifier,
255
- blockName,
249
+ bindableAttributes,
256
250
  adjustedValue,
257
251
  clientId,
258
252
  blockContext,