@wordpress/block-editor 11.3.3 → 11.4.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 (192) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/block-popover/inbetween.js +10 -33
  3. package/build/components/block-popover/inbetween.js.map +1 -1
  4. package/build/components/block-types-list/index.native.js +2 -0
  5. package/build/components/block-types-list/index.native.js.map +1 -1
  6. package/build/components/colors-gradients/control.js +6 -3
  7. package/build/components/colors-gradients/control.js.map +1 -1
  8. package/build/components/font-appearance-control/index.js +0 -3
  9. package/build/components/font-appearance-control/index.js.map +1 -1
  10. package/build/components/global-styles/hooks.js +106 -45
  11. package/build/components/global-styles/hooks.js.map +1 -1
  12. package/build/components/global-styles/index.js +24 -0
  13. package/build/components/global-styles/index.js.map +1 -1
  14. package/build/components/global-styles/typography-panel.js +421 -0
  15. package/build/components/global-styles/typography-panel.js.map +1 -0
  16. package/build/components/global-styles/use-global-styles-output.js +6 -2
  17. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  18. package/build/components/iframe/index.js +17 -11
  19. package/build/components/iframe/index.js.map +1 -1
  20. package/build/components/image-editor/aspect-ratio-dropdown.js +2 -1
  21. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  22. package/build/components/image-size-control/index.js +6 -11
  23. package/build/components/image-size-control/index.js.map +1 -1
  24. package/build/components/inserter/block-patterns-tab.js +9 -15
  25. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  26. package/build/components/inserter/block-types-tab.native.js +4 -1
  27. package/build/components/inserter/block-types-tab.native.js.map +1 -1
  28. package/build/components/inserter/reusable-blocks-tab.native.js +4 -1
  29. package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  30. package/build/components/inserter/search-results.native.js +4 -1
  31. package/build/components/inserter/search-results.native.js.map +1 -1
  32. package/build/components/link-control/index.js +15 -15
  33. package/build/components/link-control/index.js.map +1 -1
  34. package/build/components/link-control/settings-drawer.js +72 -30
  35. package/build/components/link-control/settings-drawer.js.map +1 -1
  36. package/build/components/link-control/settings.js +52 -0
  37. package/build/components/link-control/settings.js.map +1 -0
  38. package/build/components/list-view/index.js +6 -1
  39. package/build/components/list-view/index.js.map +1 -1
  40. package/build/components/off-canvas-editor/block-contents.js +3 -2
  41. package/build/components/off-canvas-editor/block-contents.js.map +1 -1
  42. package/build/components/off-canvas-editor/leaf-more-menu.js +116 -0
  43. package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  44. package/build/components/off-canvas-editor/link-ui.js +1 -0
  45. package/build/components/off-canvas-editor/link-ui.js.map +1 -1
  46. package/build/components/rich-text/index.js +0 -2
  47. package/build/components/rich-text/index.js.map +1 -1
  48. package/build/components/url-input/index.js +2 -2
  49. package/build/components/url-input/index.js.map +1 -1
  50. package/build/hooks/dimensions.js +6 -0
  51. package/build/hooks/dimensions.js.map +1 -1
  52. package/build/hooks/font-family.js +2 -76
  53. package/build/hooks/font-family.js.map +1 -1
  54. package/build/hooks/font-size.js +3 -51
  55. package/build/hooks/font-size.js.map +1 -1
  56. package/build/hooks/gap.js +2 -1
  57. package/build/hooks/gap.js.map +1 -1
  58. package/build/hooks/index.js +2 -0
  59. package/build/hooks/index.js.map +1 -1
  60. package/build/hooks/line-height.js +0 -42
  61. package/build/hooks/line-height.js.map +1 -1
  62. package/build/hooks/typography.js +112 -127
  63. package/build/hooks/typography.js.map +1 -1
  64. package/build/private-apis.js +3 -0
  65. package/build/private-apis.js.map +1 -1
  66. package/build/store/selectors.js +18 -1
  67. package/build/store/selectors.js.map +1 -1
  68. package/build-module/components/block-popover/inbetween.js +10 -33
  69. package/build-module/components/block-popover/inbetween.js.map +1 -1
  70. package/build-module/components/block-types-list/index.native.js +2 -0
  71. package/build-module/components/block-types-list/index.native.js.map +1 -1
  72. package/build-module/components/colors-gradients/control.js +6 -3
  73. package/build-module/components/colors-gradients/control.js.map +1 -1
  74. package/build-module/components/font-appearance-control/index.js +2 -1
  75. package/build-module/components/font-appearance-control/index.js.map +1 -1
  76. package/build-module/components/global-styles/hooks.js +100 -46
  77. package/build-module/components/global-styles/hooks.js.map +1 -1
  78. package/build-module/components/global-styles/index.js +2 -1
  79. package/build-module/components/global-styles/index.js.map +1 -1
  80. package/build-module/components/global-styles/typography-panel.js +400 -0
  81. package/build-module/components/global-styles/typography-panel.js.map +1 -0
  82. package/build-module/components/global-styles/use-global-styles-output.js +6 -2
  83. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  84. package/build-module/components/iframe/index.js +17 -11
  85. package/build-module/components/iframe/index.js.map +1 -1
  86. package/build-module/components/image-editor/aspect-ratio-dropdown.js +2 -1
  87. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  88. package/build-module/components/image-size-control/index.js +7 -12
  89. package/build-module/components/image-size-control/index.js.map +1 -1
  90. package/build-module/components/inserter/block-patterns-tab.js +9 -15
  91. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  92. package/build-module/components/inserter/block-types-tab.native.js +3 -1
  93. package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
  94. package/build-module/components/inserter/reusable-blocks-tab.native.js +3 -1
  95. package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  96. package/build-module/components/inserter/search-results.native.js +3 -1
  97. package/build-module/components/inserter/search-results.native.js.map +1 -1
  98. package/build-module/components/link-control/index.js +16 -16
  99. package/build-module/components/link-control/index.js.map +1 -1
  100. package/build-module/components/link-control/settings-drawer.js +68 -30
  101. package/build-module/components/link-control/settings-drawer.js.map +1 -1
  102. package/build-module/components/link-control/settings.js +43 -0
  103. package/build-module/components/link-control/settings.js.map +1 -0
  104. package/build-module/components/list-view/index.js +6 -1
  105. package/build-module/components/list-view/index.js.map +1 -1
  106. package/build-module/components/off-canvas-editor/block-contents.js +3 -2
  107. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
  108. package/build-module/components/off-canvas-editor/leaf-more-menu.js +99 -0
  109. package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  110. package/build-module/components/off-canvas-editor/link-ui.js +1 -0
  111. package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
  112. package/build-module/components/rich-text/index.js +0 -2
  113. package/build-module/components/rich-text/index.js.map +1 -1
  114. package/build-module/components/url-input/index.js +2 -2
  115. package/build-module/components/url-input/index.js.map +1 -1
  116. package/build-module/hooks/dimensions.js +6 -0
  117. package/build-module/hooks/dimensions.js.map +1 -1
  118. package/build-module/hooks/font-family.js +3 -69
  119. package/build-module/hooks/font-family.js.map +1 -1
  120. package/build-module/hooks/font-size.js +6 -47
  121. package/build-module/hooks/font-size.js.map +1 -1
  122. package/build-module/hooks/gap.js +3 -2
  123. package/build-module/hooks/gap.js.map +1 -1
  124. package/build-module/hooks/index.js +1 -0
  125. package/build-module/hooks/index.js.map +1 -1
  126. package/build-module/hooks/line-height.js +0 -38
  127. package/build-module/hooks/line-height.js.map +1 -1
  128. package/build-module/hooks/typography.js +110 -123
  129. package/build-module/hooks/typography.js.map +1 -1
  130. package/build-module/private-apis.js +2 -0
  131. package/build-module/private-apis.js.map +1 -1
  132. package/build-module/store/selectors.js +18 -1
  133. package/build-module/store/selectors.js.map +1 -1
  134. package/build-style/style-rtl.css +35 -22
  135. package/build-style/style.css +35 -22
  136. package/package.json +31 -31
  137. package/src/components/block-popover/inbetween.js +21 -53
  138. package/src/components/block-types-list/index.native.js +2 -0
  139. package/src/components/colors-gradients/control.js +3 -0
  140. package/src/components/font-appearance-control/index.js +1 -1
  141. package/src/components/global-styles/hooks.js +186 -66
  142. package/src/components/global-styles/index.js +5 -0
  143. package/src/components/global-styles/typography-panel.js +403 -0
  144. package/src/components/global-styles/use-global-styles-output.js +6 -2
  145. package/src/components/iframe/index.js +20 -18
  146. package/src/components/image-editor/aspect-ratio-dropdown.js +1 -0
  147. package/src/components/image-size-control/index.js +10 -12
  148. package/src/components/image-size-control/style.scss +3 -21
  149. package/src/components/inserter/block-patterns-tab.js +9 -23
  150. package/src/components/inserter/block-types-tab.native.js +2 -0
  151. package/src/components/inserter/reusable-blocks-tab.native.js +2 -0
  152. package/src/components/inserter/search-results.native.js +2 -0
  153. package/src/components/link-control/index.js +22 -22
  154. package/src/components/link-control/settings-drawer.js +85 -30
  155. package/src/components/link-control/settings.js +41 -0
  156. package/src/components/link-control/style.scss +39 -7
  157. package/src/components/link-control/test/index.js +213 -4
  158. package/src/components/list-view/index.js +5 -0
  159. package/src/components/off-canvas-editor/block-contents.js +2 -1
  160. package/src/components/off-canvas-editor/leaf-more-menu.js +115 -0
  161. package/src/components/off-canvas-editor/link-ui.js +1 -0
  162. package/src/components/rich-text/index.js +0 -2
  163. package/src/components/url-input/index.js +3 -2
  164. package/src/hooks/dimensions.js +12 -0
  165. package/src/hooks/font-family.js +0 -58
  166. package/src/hooks/font-size.js +1 -36
  167. package/src/hooks/gap.js +9 -2
  168. package/src/hooks/index.js +1 -0
  169. package/src/hooks/line-height.js +0 -33
  170. package/src/hooks/typography.js +133 -212
  171. package/src/private-apis.js +2 -0
  172. package/src/store/selectors.js +16 -1
  173. package/build/hooks/font-appearance.js +0 -188
  174. package/build/hooks/font-appearance.js.map +0 -1
  175. package/build/hooks/letter-spacing.js +0 -129
  176. package/build/hooks/letter-spacing.js.map +0 -1
  177. package/build/hooks/text-decoration.js +0 -130
  178. package/build/hooks/text-decoration.js.map +0 -1
  179. package/build/hooks/text-transform.js +0 -130
  180. package/build/hooks/text-transform.js.map +0 -1
  181. package/build-module/hooks/font-appearance.js +0 -161
  182. package/build-module/hooks/font-appearance.js.map +0 -1
  183. package/build-module/hooks/letter-spacing.js +0 -107
  184. package/build-module/hooks/letter-spacing.js.map +0 -1
  185. package/build-module/hooks/text-decoration.js +0 -108
  186. package/build-module/hooks/text-decoration.js.map +0 -1
  187. package/build-module/hooks/text-transform.js +0 -108
  188. package/build-module/hooks/text-transform.js.map +0 -1
  189. package/src/hooks/font-appearance.js +0 -146
  190. package/src/hooks/letter-spacing.js +0 -101
  191. package/src/hooks/text-decoration.js +0 -102
  192. package/src/hooks/text-transform.js +0 -101
@@ -7,16 +7,67 @@ import { get, set } from 'lodash';
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
10
- import { useContext, useCallback } from '@wordpress/element';
10
+ import { useContext, useCallback, useMemo } from '@wordpress/element';
11
+ import { useSelect } from '@wordpress/data';
12
+ import { store as blocksStore } from '@wordpress/blocks';
11
13
 
12
14
  /**
13
15
  * Internal dependencies
14
16
  */
15
17
  import { getValueFromVariable, getPresetVariableFromValue } from './utils';
16
18
  import { GlobalStylesContext } from './context';
19
+ import { unlock } from '../../lock-unlock';
17
20
 
18
21
  const EMPTY_CONFIG = { settings: {}, styles: {} };
19
22
 
23
+ const VALID_SETTINGS = [
24
+ 'appearanceTools',
25
+ 'useRootPaddingAwareAlignments',
26
+ 'border.color',
27
+ 'border.radius',
28
+ 'border.style',
29
+ 'border.width',
30
+ 'shadow.presets',
31
+ 'shadow.defaultPresets',
32
+ 'color.background',
33
+ 'color.custom',
34
+ 'color.customDuotone',
35
+ 'color.customGradient',
36
+ 'color.defaultDuotone',
37
+ 'color.defaultGradients',
38
+ 'color.defaultPalette',
39
+ 'color.duotone',
40
+ 'color.gradients',
41
+ 'color.link',
42
+ 'color.palette',
43
+ 'color.text',
44
+ 'custom',
45
+ 'dimensions.minHeight',
46
+ 'layout.contentSize',
47
+ 'layout.definitions',
48
+ 'layout.wideSize',
49
+ 'position.fixed',
50
+ 'position.sticky',
51
+ 'spacing.customSpacingSize',
52
+ 'spacing.spacingSizes',
53
+ 'spacing.spacingScale',
54
+ 'spacing.blockGap',
55
+ 'spacing.margin',
56
+ 'spacing.padding',
57
+ 'spacing.units',
58
+ 'typography.fuild',
59
+ 'typography.customFontSize',
60
+ 'typography.dropCap',
61
+ 'typography.fontFamilies',
62
+ 'typography.fontSizes',
63
+ 'typography.fontStyle',
64
+ 'typography.fontWeight',
65
+ 'typography.letterSpacing',
66
+ 'typography.lineHeight',
67
+ 'typography.textDecoration',
68
+ 'typography.textTransform',
69
+ ];
70
+
20
71
  export const useGlobalStylesReset = () => {
21
72
  const { user: config, setUserConfig } = useContext( GlobalStylesContext );
22
73
  const canReset = !! config && ! fastDeepEqual( config, EMPTY_CONFIG );
@@ -29,68 +80,78 @@ export const useGlobalStylesReset = () => {
29
80
  ];
30
81
  };
31
82
 
32
- export function useGlobalSetting( path, blockName, source = 'all' ) {
33
- const {
34
- merged: mergedConfig,
35
- base: baseConfig,
36
- user: userConfig,
37
- setUserConfig,
38
- } = useContext( GlobalStylesContext );
83
+ export function useGlobalSetting( propertyPath, blockName, source = 'all' ) {
84
+ const { setUserConfig, ...configs } = useContext( GlobalStylesContext );
85
+
86
+ const appendedBlockPath = blockName ? '.blocks.' + blockName : '';
87
+ const appendedPropertyPath = propertyPath ? '.' + propertyPath : '';
88
+ const contextualPath = `settings${ appendedBlockPath }${ appendedPropertyPath }`;
89
+ const globalPath = `settings${ appendedPropertyPath }`;
90
+ const sourceKey = source === 'all' ? 'merged' : source;
91
+
92
+ const settingValue = useMemo( () => {
93
+ const configToUse = configs[ sourceKey ];
94
+ if ( ! configToUse ) {
95
+ throw 'Unsupported source';
96
+ }
39
97
 
40
- const fullPath = ! blockName
41
- ? `settings.${ path }`
42
- : `settings.blocks.${ blockName }.${ path }`;
98
+ if ( propertyPath ) {
99
+ return (
100
+ get( configToUse, contextualPath ) ??
101
+ get( configToUse, globalPath )
102
+ );
103
+ }
104
+
105
+ const result = {};
106
+ VALID_SETTINGS.forEach( ( setting ) => {
107
+ const value =
108
+ get(
109
+ configToUse,
110
+ `settings${ appendedBlockPath }.${ setting }`
111
+ ) ?? get( configToUse, `settings.${ setting }` );
112
+ if ( value ) {
113
+ set( result, setting, value );
114
+ }
115
+ } );
116
+ return result;
117
+ }, [
118
+ configs,
119
+ sourceKey,
120
+ propertyPath,
121
+ contextualPath,
122
+ globalPath,
123
+ appendedBlockPath,
124
+ ] );
43
125
 
44
126
  const setSetting = ( newValue ) => {
45
127
  setUserConfig( ( currentConfig ) => {
46
128
  // Deep clone `currentConfig` to avoid mutating it later.
47
129
  const newUserConfig = JSON.parse( JSON.stringify( currentConfig ) );
48
- set( newUserConfig, fullPath, newValue );
130
+ set( newUserConfig, contextualPath, newValue );
49
131
 
50
132
  return newUserConfig;
51
133
  } );
52
134
  };
53
135
 
54
- const getSettingValueForContext = ( name ) => {
55
- const currentPath = ! name
56
- ? `settings.${ path }`
57
- : `settings.blocks.${ name }.${ path }`;
58
-
59
- let result;
60
- switch ( source ) {
61
- case 'all':
62
- result = get( mergedConfig, currentPath );
63
- break;
64
- case 'user':
65
- result = get( userConfig, currentPath );
66
- break;
67
- case 'base':
68
- result = get( baseConfig, currentPath );
69
- break;
70
- default:
71
- throw 'Unsupported source';
72
- }
73
-
74
- return result;
75
- };
76
-
77
- // Unlike styles settings get inherited from top level settings.
78
- const resultWithFallback =
79
- getSettingValueForContext( blockName ) ?? getSettingValueForContext();
80
-
81
- return [ resultWithFallback, setSetting ];
136
+ return [ settingValue, setSetting ];
82
137
  }
83
138
 
84
- export function useGlobalStyle( path, blockName, source = 'all' ) {
139
+ export function useGlobalStyle(
140
+ path,
141
+ blockName,
142
+ source = 'all',
143
+ { shouldDecodeEncode = true } = {}
144
+ ) {
85
145
  const {
86
146
  merged: mergedConfig,
87
147
  base: baseConfig,
88
148
  user: userConfig,
89
149
  setUserConfig,
90
150
  } = useContext( GlobalStylesContext );
151
+ const appendedPath = path ? '.' + path : '';
91
152
  const finalPath = ! blockName
92
- ? `styles.${ path }`
93
- : `styles.blocks.${ blockName }.${ path }`;
153
+ ? `styles${ appendedPath }`
154
+ : `styles.blocks.${ blockName }${ appendedPath }`;
94
155
 
95
156
  const setStyle = ( newValue ) => {
96
157
  setUserConfig( ( currentConfig ) => {
@@ -99,43 +160,42 @@ export function useGlobalStyle( path, blockName, source = 'all' ) {
99
160
  set(
100
161
  newUserConfig,
101
162
  finalPath,
102
- getPresetVariableFromValue(
103
- mergedConfig.settings,
104
- blockName,
105
- path,
106
- newValue
107
- )
163
+ shouldDecodeEncode
164
+ ? getPresetVariableFromValue(
165
+ mergedConfig.settings,
166
+ blockName,
167
+ path,
168
+ newValue
169
+ )
170
+ : newValue
108
171
  );
109
172
  return newUserConfig;
110
173
  } );
111
174
  };
112
175
 
113
- let result;
176
+ let rawResult, result;
114
177
  switch ( source ) {
115
178
  case 'all':
116
- result = getValueFromVariable(
117
- mergedConfig,
118
- blockName,
179
+ rawResult =
119
180
  // The stlyes.css path is allowed to be empty, so don't revert to base if undefined.
120
181
  finalPath === 'styles.css'
121
182
  ? get( userConfig, finalPath )
122
- : get( userConfig, finalPath ) ??
123
- get( baseConfig, finalPath )
124
- );
183
+ : get( mergedConfig, finalPath );
184
+ result = shouldDecodeEncode
185
+ ? getValueFromVariable( mergedConfig, blockName, rawResult )
186
+ : rawResult;
125
187
  break;
126
188
  case 'user':
127
- result = getValueFromVariable(
128
- mergedConfig,
129
- blockName,
130
- get( userConfig, finalPath )
131
- );
189
+ rawResult = get( userConfig, finalPath );
190
+ result = shouldDecodeEncode
191
+ ? getValueFromVariable( mergedConfig, blockName, rawResult )
192
+ : rawResult;
132
193
  break;
133
194
  case 'base':
134
- result = getValueFromVariable(
135
- baseConfig,
136
- blockName,
137
- get( baseConfig, finalPath )
138
- );
195
+ rawResult = get( baseConfig, finalPath );
196
+ result = shouldDecodeEncode
197
+ ? getValueFromVariable( baseConfig, blockName, rawResult )
198
+ : rawResult;
139
199
  break;
140
200
  default:
141
201
  throw 'Unsupported source';
@@ -143,3 +203,63 @@ export function useGlobalStyle( path, blockName, source = 'all' ) {
143
203
 
144
204
  return [ result, setStyle ];
145
205
  }
206
+
207
+ export function useSupportedStyles( name, element ) {
208
+ const { supportedPanels } = useSelect(
209
+ ( select ) => {
210
+ return {
211
+ supportedPanels: unlock(
212
+ select( blocksStore )
213
+ ).getSupportedStyles( name, element ),
214
+ };
215
+ },
216
+ [ name, element ]
217
+ );
218
+
219
+ return supportedPanels;
220
+ }
221
+
222
+ /**
223
+ * Given a settings object and a list of supported panels,
224
+ * returns a new settings object with the unsupported panels removed.
225
+ *
226
+ * @param {Object} settings Settings object.
227
+ * @param {string[]} supports Supported style panels.
228
+ *
229
+ * @return {Object} Merge of settings and supports.
230
+ */
231
+ export function overrideSettingsWithSupports( settings, supports ) {
232
+ const updatedSettings = { ...settings };
233
+
234
+ if ( ! supports.includes( 'fontSize' ) ) {
235
+ updatedSettings.typography = {
236
+ ...updatedSettings.typography,
237
+ fontSizes: {},
238
+ customFontSize: false,
239
+ };
240
+ }
241
+
242
+ if ( ! supports.includes( 'fontFamily' ) ) {
243
+ updatedSettings.typography = {
244
+ ...updatedSettings.typography,
245
+ fontFamilies: {},
246
+ };
247
+ }
248
+
249
+ [
250
+ 'lineHeight',
251
+ 'fontStyle',
252
+ 'fontWeight',
253
+ 'letterSpacing',
254
+ 'textTransform',
255
+ ].forEach( ( key ) => {
256
+ if ( ! supports.includes( key ) ) {
257
+ updatedSettings.typography = {
258
+ ...updatedSettings.typography,
259
+ [ key ]: false,
260
+ };
261
+ }
262
+ } );
263
+
264
+ return updatedSettings;
265
+ }
@@ -2,6 +2,11 @@ export {
2
2
  useGlobalStylesReset,
3
3
  useGlobalSetting,
4
4
  useGlobalStyle,
5
+ overrideSettingsWithSupports,
5
6
  } from './hooks';
6
7
  export { useGlobalStylesOutput } from './use-global-styles-output';
7
8
  export { GlobalStylesContext } from './context';
9
+ export {
10
+ default as TypographyPanel,
11
+ useHasTypographyPanel,
12
+ } from './typography-panel';