@wordpress/block-editor 11.3.2 → 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 (262) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -4
  3. package/build/components/block-actions/index.js +2 -7
  4. package/build/components/block-actions/index.js.map +1 -1
  5. package/build/components/block-alignment-control/use-available-alignments.js +5 -3
  6. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  7. package/build/components/block-popover/inbetween.js +10 -33
  8. package/build/components/block-popover/inbetween.js.map +1 -1
  9. package/build/components/block-tools/selected-block-popover.js +2 -2
  10. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  11. package/build/components/block-types-list/index.native.js +2 -0
  12. package/build/components/block-types-list/index.native.js.map +1 -1
  13. package/build/components/colors-gradients/control.js +6 -3
  14. package/build/components/colors-gradients/control.js.map +1 -1
  15. package/build/components/font-appearance-control/index.js +0 -3
  16. package/build/components/font-appearance-control/index.js.map +1 -1
  17. package/build/components/global-styles/hooks.js +106 -45
  18. package/build/components/global-styles/hooks.js.map +1 -1
  19. package/build/components/global-styles/index.js +24 -0
  20. package/build/components/global-styles/index.js.map +1 -1
  21. package/build/components/global-styles/typography-panel.js +421 -0
  22. package/build/components/global-styles/typography-panel.js.map +1 -0
  23. package/build/components/global-styles/use-global-styles-output.js +6 -2
  24. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  25. package/build/components/iframe/index.js +17 -11
  26. package/build/components/iframe/index.js.map +1 -1
  27. package/build/components/image-editor/aspect-ratio-dropdown.js +2 -1
  28. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  29. package/build/components/image-size-control/index.js +6 -11
  30. package/build/components/image-size-control/index.js.map +1 -1
  31. package/build/components/inserter/block-patterns-tab.js +9 -15
  32. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  33. package/build/components/inserter/block-types-tab.native.js +4 -1
  34. package/build/components/inserter/block-types-tab.native.js.map +1 -1
  35. package/build/components/inserter/reusable-blocks-tab.native.js +4 -1
  36. package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  37. package/build/components/inserter/search-results.native.js +4 -1
  38. package/build/components/inserter/search-results.native.js.map +1 -1
  39. package/build/components/link-control/index.js +15 -15
  40. package/build/components/link-control/index.js.map +1 -1
  41. package/build/components/link-control/settings-drawer.js +72 -30
  42. package/build/components/link-control/settings-drawer.js.map +1 -1
  43. package/build/components/link-control/settings.js +52 -0
  44. package/build/components/link-control/settings.js.map +1 -0
  45. package/build/components/list-view/index.js +6 -1
  46. package/build/components/list-view/index.js.map +1 -1
  47. package/build/components/off-canvas-editor/block-contents.js +5 -4
  48. package/build/components/off-canvas-editor/block-contents.js.map +1 -1
  49. package/build/components/off-canvas-editor/leaf-more-menu.js +116 -0
  50. package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  51. package/build/components/off-canvas-editor/link-ui.js +1 -0
  52. package/build/components/off-canvas-editor/link-ui.js.map +1 -1
  53. package/build/components/provider/index.js +2 -2
  54. package/build/components/provider/index.js.map +1 -1
  55. package/build/components/rich-text/index.js +0 -2
  56. package/build/components/rich-text/index.js.map +1 -1
  57. package/build/components/url-input/index.js +2 -2
  58. package/build/components/url-input/index.js.map +1 -1
  59. package/build/components/url-popover/index.js +6 -1
  60. package/build/components/url-popover/index.js.map +1 -1
  61. package/build/hooks/dimensions.js +8 -2
  62. package/build/hooks/dimensions.js.map +1 -1
  63. package/build/hooks/font-family.js +2 -76
  64. package/build/hooks/font-family.js.map +1 -1
  65. package/build/hooks/font-size.js +3 -51
  66. package/build/hooks/font-size.js.map +1 -1
  67. package/build/hooks/gap.js +2 -1
  68. package/build/hooks/gap.js.map +1 -1
  69. package/build/hooks/index.js +2 -0
  70. package/build/hooks/index.js.map +1 -1
  71. package/build/hooks/line-height.js +0 -42
  72. package/build/hooks/line-height.js.map +1 -1
  73. package/build/hooks/metadata.js +6 -0
  74. package/build/hooks/metadata.js.map +1 -1
  75. package/build/hooks/position.js +6 -1
  76. package/build/hooks/position.js.map +1 -1
  77. package/build/hooks/typography.js +112 -127
  78. package/build/hooks/typography.js.map +1 -1
  79. package/build/index.js +6 -6
  80. package/build/index.js.map +1 -1
  81. package/build/layouts/flow.js +23 -2
  82. package/build/layouts/flow.js.map +1 -1
  83. package/build/lock-unlock.js +19 -0
  84. package/build/lock-unlock.js.map +1 -0
  85. package/build/{experiments.js → private-apis.js} +12 -19
  86. package/build/private-apis.js.map +1 -0
  87. package/build/{experiments.native.js → private-apis.native.js} +9 -19
  88. package/build/private-apis.native.js.map +1 -0
  89. package/build/store/index.js +3 -3
  90. package/build/store/index.js.map +1 -1
  91. package/build/store/selectors.js +18 -1
  92. package/build/store/selectors.js.map +1 -1
  93. package/build-module/components/block-actions/index.js +2 -7
  94. package/build-module/components/block-actions/index.js.map +1 -1
  95. package/build-module/components/block-alignment-control/use-available-alignments.js +5 -3
  96. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  97. package/build-module/components/block-popover/inbetween.js +10 -33
  98. package/build-module/components/block-popover/inbetween.js.map +1 -1
  99. package/build-module/components/block-tools/selected-block-popover.js +1 -1
  100. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  101. package/build-module/components/block-types-list/index.native.js +2 -0
  102. package/build-module/components/block-types-list/index.native.js.map +1 -1
  103. package/build-module/components/colors-gradients/control.js +6 -3
  104. package/build-module/components/colors-gradients/control.js.map +1 -1
  105. package/build-module/components/font-appearance-control/index.js +2 -1
  106. package/build-module/components/font-appearance-control/index.js.map +1 -1
  107. package/build-module/components/global-styles/hooks.js +100 -46
  108. package/build-module/components/global-styles/hooks.js.map +1 -1
  109. package/build-module/components/global-styles/index.js +2 -1
  110. package/build-module/components/global-styles/index.js.map +1 -1
  111. package/build-module/components/global-styles/typography-panel.js +400 -0
  112. package/build-module/components/global-styles/typography-panel.js.map +1 -0
  113. package/build-module/components/global-styles/use-global-styles-output.js +6 -2
  114. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  115. package/build-module/components/iframe/index.js +17 -11
  116. package/build-module/components/iframe/index.js.map +1 -1
  117. package/build-module/components/image-editor/aspect-ratio-dropdown.js +2 -1
  118. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  119. package/build-module/components/image-size-control/index.js +7 -12
  120. package/build-module/components/image-size-control/index.js.map +1 -1
  121. package/build-module/components/inserter/block-patterns-tab.js +9 -15
  122. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  123. package/build-module/components/inserter/block-types-tab.native.js +3 -1
  124. package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
  125. package/build-module/components/inserter/reusable-blocks-tab.native.js +3 -1
  126. package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  127. package/build-module/components/inserter/search-results.native.js +3 -1
  128. package/build-module/components/inserter/search-results.native.js.map +1 -1
  129. package/build-module/components/link-control/index.js +16 -16
  130. package/build-module/components/link-control/index.js.map +1 -1
  131. package/build-module/components/link-control/settings-drawer.js +68 -30
  132. package/build-module/components/link-control/settings-drawer.js.map +1 -1
  133. package/build-module/components/link-control/settings.js +43 -0
  134. package/build-module/components/link-control/settings.js.map +1 -0
  135. package/build-module/components/list-view/index.js +6 -1
  136. package/build-module/components/list-view/index.js.map +1 -1
  137. package/build-module/components/off-canvas-editor/block-contents.js +4 -3
  138. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
  139. package/build-module/components/off-canvas-editor/leaf-more-menu.js +99 -0
  140. package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  141. package/build-module/components/off-canvas-editor/link-ui.js +1 -0
  142. package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
  143. package/build-module/components/provider/index.js +1 -1
  144. package/build-module/components/provider/index.js.map +1 -1
  145. package/build-module/components/rich-text/index.js +0 -2
  146. package/build-module/components/rich-text/index.js.map +1 -1
  147. package/build-module/components/url-input/index.js +2 -2
  148. package/build-module/components/url-input/index.js.map +1 -1
  149. package/build-module/components/url-popover/index.js +6 -2
  150. package/build-module/components/url-popover/index.js.map +1 -1
  151. package/build-module/hooks/dimensions.js +7 -1
  152. package/build-module/hooks/dimensions.js.map +1 -1
  153. package/build-module/hooks/font-family.js +3 -69
  154. package/build-module/hooks/font-family.js.map +1 -1
  155. package/build-module/hooks/font-size.js +6 -47
  156. package/build-module/hooks/font-size.js.map +1 -1
  157. package/build-module/hooks/gap.js +3 -2
  158. package/build-module/hooks/gap.js.map +1 -1
  159. package/build-module/hooks/index.js +1 -0
  160. package/build-module/hooks/index.js.map +1 -1
  161. package/build-module/hooks/line-height.js +0 -38
  162. package/build-module/hooks/line-height.js.map +1 -1
  163. package/build-module/hooks/metadata.js +6 -0
  164. package/build-module/hooks/metadata.js.map +1 -1
  165. package/build-module/hooks/position.js +5 -1
  166. package/build-module/hooks/position.js.map +1 -1
  167. package/build-module/hooks/typography.js +110 -123
  168. package/build-module/hooks/typography.js.map +1 -1
  169. package/build-module/index.js +1 -1
  170. package/build-module/index.js.map +1 -1
  171. package/build-module/layouts/flow.js +23 -2
  172. package/build-module/layouts/flow.js.map +1 -1
  173. package/build-module/lock-unlock.js +9 -0
  174. package/build-module/lock-unlock.js.map +1 -0
  175. package/build-module/private-apis.js +19 -0
  176. package/build-module/private-apis.js.map +1 -0
  177. package/build-module/private-apis.native.js +15 -0
  178. package/build-module/private-apis.native.js.map +1 -0
  179. package/build-module/store/index.js +1 -1
  180. package/build-module/store/index.js.map +1 -1
  181. package/build-module/store/selectors.js +18 -1
  182. package/build-module/store/selectors.js.map +1 -1
  183. package/build-style/style-rtl.css +35 -22
  184. package/build-style/style.css +35 -22
  185. package/package.json +31 -31
  186. package/src/components/block-actions/index.js +0 -9
  187. package/src/components/block-alignment-control/use-available-alignments.js +17 -12
  188. package/src/components/block-popover/inbetween.js +21 -53
  189. package/src/components/block-tools/selected-block-popover.js +1 -1
  190. package/src/components/block-types-list/index.native.js +2 -0
  191. package/src/components/colors-gradients/control.js +3 -0
  192. package/src/components/font-appearance-control/index.js +1 -1
  193. package/src/components/global-styles/hooks.js +186 -66
  194. package/src/components/global-styles/index.js +5 -0
  195. package/src/components/global-styles/typography-panel.js +403 -0
  196. package/src/components/global-styles/use-global-styles-output.js +6 -2
  197. package/src/components/iframe/index.js +20 -18
  198. package/src/components/image-editor/aspect-ratio-dropdown.js +1 -0
  199. package/src/components/image-size-control/index.js +10 -12
  200. package/src/components/image-size-control/style.scss +3 -21
  201. package/src/components/inserter/block-patterns-tab.js +9 -23
  202. package/src/components/inserter/block-types-tab.native.js +2 -0
  203. package/src/components/inserter/reusable-blocks-tab.native.js +2 -0
  204. package/src/components/inserter/search-results.native.js +2 -0
  205. package/src/components/link-control/index.js +22 -22
  206. package/src/components/link-control/settings-drawer.js +85 -30
  207. package/src/components/link-control/settings.js +41 -0
  208. package/src/components/link-control/style.scss +39 -7
  209. package/src/components/link-control/test/index.js +213 -4
  210. package/src/components/list-view/index.js +5 -0
  211. package/src/components/off-canvas-editor/block-contents.js +3 -2
  212. package/src/components/off-canvas-editor/leaf-more-menu.js +115 -0
  213. package/src/components/off-canvas-editor/link-ui.js +1 -0
  214. package/src/components/provider/index.js +1 -1
  215. package/src/components/rich-text/index.js +0 -2
  216. package/src/components/url-input/index.js +3 -2
  217. package/src/components/url-popover/index.js +8 -2
  218. package/src/hooks/dimensions.js +13 -1
  219. package/src/hooks/font-family.js +0 -58
  220. package/src/hooks/font-size.js +1 -36
  221. package/src/hooks/gap.js +9 -2
  222. package/src/hooks/index.js +1 -0
  223. package/src/hooks/line-height.js +0 -33
  224. package/src/hooks/metadata.js +4 -0
  225. package/src/hooks/position.js +7 -1
  226. package/src/hooks/typography.js +133 -212
  227. package/src/index.js +1 -1
  228. package/src/layouts/flow.js +16 -1
  229. package/src/lock-unlock.js +10 -0
  230. package/src/private-apis.js +19 -0
  231. package/src/private-apis.native.js +15 -0
  232. package/src/store/index.js +1 -1
  233. package/src/store/selectors.js +16 -1
  234. package/tsconfig.json +20 -1
  235. package/build/experiments.js.map +0 -1
  236. package/build/experiments.native.js.map +0 -1
  237. package/build/hooks/font-appearance.js +0 -188
  238. package/build/hooks/font-appearance.js.map +0 -1
  239. package/build/hooks/letter-spacing.js +0 -129
  240. package/build/hooks/letter-spacing.js.map +0 -1
  241. package/build/hooks/text-decoration.js +0 -130
  242. package/build/hooks/text-decoration.js.map +0 -1
  243. package/build/hooks/text-transform.js +0 -130
  244. package/build/hooks/text-transform.js.map +0 -1
  245. package/build-module/experiments.js +0 -25
  246. package/build-module/experiments.js.map +0 -1
  247. package/build-module/experiments.native.js +0 -23
  248. package/build-module/experiments.native.js.map +0 -1
  249. package/build-module/hooks/font-appearance.js +0 -161
  250. package/build-module/hooks/font-appearance.js.map +0 -1
  251. package/build-module/hooks/letter-spacing.js +0 -107
  252. package/build-module/hooks/letter-spacing.js.map +0 -1
  253. package/build-module/hooks/text-decoration.js +0 -108
  254. package/build-module/hooks/text-decoration.js.map +0 -1
  255. package/build-module/hooks/text-transform.js +0 -108
  256. package/build-module/hooks/text-transform.js.map +0 -1
  257. package/src/experiments.js +0 -27
  258. package/src/experiments.native.js +0 -25
  259. package/src/hooks/font-appearance.js +0 -146
  260. package/src/hooks/letter-spacing.js +0 -101
  261. package/src/hooks/text-decoration.js +0 -102
  262. package/src/hooks/text-transform.js +0 -101
@@ -2,68 +2,38 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
5
- import { __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
6
- import { __ } from '@wordpress/i18n';
5
+ import { useMemo } from '@wordpress/element';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
10
9
  */
11
10
  import InspectorControls from '../components/inspector-controls';
12
- import { getFontAppearanceLabel } from '../components/font-appearance-control';
13
-
14
- import {
15
- LINE_HEIGHT_SUPPORT_KEY,
16
- LineHeightEdit,
17
- hasLineHeightValue,
18
- resetLineHeight,
19
- useIsLineHeightDisabled,
20
- } from './line-height';
21
- import {
22
- FONT_STYLE_SUPPORT_KEY,
23
- FONT_WEIGHT_SUPPORT_KEY,
24
- FontAppearanceEdit,
25
- hasFontAppearanceValue,
26
- resetFontAppearance,
27
- useIsFontAppearanceDisabled,
28
- useIsFontStyleDisabled,
29
- useIsFontWeightDisabled,
30
- } from './font-appearance';
31
- import {
32
- FONT_FAMILY_SUPPORT_KEY,
33
- FontFamilyEdit,
34
- hasFontFamilyValue,
35
- resetFontFamily,
36
- useIsFontFamilyDisabled,
37
- } from './font-family';
38
- import {
39
- FONT_SIZE_SUPPORT_KEY,
40
- FontSizeEdit,
41
- hasFontSizeValue,
42
- resetFontSize,
43
- useIsFontSizeDisabled,
44
- } from './font-size';
45
- import {
46
- TEXT_DECORATION_SUPPORT_KEY,
47
- TextDecorationEdit,
48
- hasTextDecorationValue,
49
- resetTextDecoration,
50
- useIsTextDecorationDisabled,
51
- } from './text-decoration';
52
11
  import {
53
- TEXT_TRANSFORM_SUPPORT_KEY,
54
- TextTransformEdit,
55
- hasTextTransformValue,
56
- resetTextTransform,
57
- useIsTextTransformDisabled,
58
- } from './text-transform';
12
+ default as StylesTypographyPanel,
13
+ useHasTypographyPanel,
14
+ } from '../components/global-styles/typography-panel';
15
+
16
+ import { LINE_HEIGHT_SUPPORT_KEY } from './line-height';
17
+ import { FONT_FAMILY_SUPPORT_KEY } from './font-family';
18
+ import { FONT_SIZE_SUPPORT_KEY } from './font-size';
19
+ import { useSetting } from '../components';
20
+ import { cleanEmptyObject } from './utils';
59
21
  import {
60
- LETTER_SPACING_SUPPORT_KEY,
61
- LetterSpacingEdit,
62
- hasLetterSpacingValue,
63
- resetLetterSpacing,
64
- useIsLetterSpacingDisabled,
65
- } from './letter-spacing';
22
+ overrideSettingsWithSupports,
23
+ useSupportedStyles,
24
+ } from '../components/global-styles/hooks';
25
+
26
+ function omit( object, keys ) {
27
+ return Object.fromEntries(
28
+ Object.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) )
29
+ );
30
+ }
66
31
 
32
+ const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
33
+ const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
34
+ const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
35
+ const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
36
+ const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
67
37
  export const TYPOGRAPHY_SUPPORT_KEY = 'typography';
68
38
  export const TYPOGRAPHY_SUPPORT_KEYS = [
69
39
  LINE_HEIGHT_SUPPORT_KEY,
@@ -76,159 +46,124 @@ export const TYPOGRAPHY_SUPPORT_KEYS = [
76
46
  LETTER_SPACING_SUPPORT_KEY,
77
47
  ];
78
48
 
79
- export function TypographyPanel( props ) {
80
- const { clientId } = props;
81
- const isFontFamilyDisabled = useIsFontFamilyDisabled( props );
82
- const isFontSizeDisabled = useIsFontSizeDisabled( props );
83
- const isFontAppearanceDisabled = useIsFontAppearanceDisabled( props );
84
- const isLineHeightDisabled = useIsLineHeightDisabled( props );
85
- const isTextDecorationDisabled = useIsTextDecorationDisabled( props );
86
- const isTextTransformDisabled = useIsTextTransformDisabled( props );
87
- const isLetterSpacingDisabled = useIsLetterSpacingDisabled( props );
49
+ function TypographyInspectorControl( { children } ) {
50
+ return (
51
+ <InspectorControls group="typography">{ children }</InspectorControls>
52
+ );
53
+ }
88
54
 
89
- const hasFontStyles = ! useIsFontStyleDisabled( props );
90
- const hasFontWeights = ! useIsFontWeightDisabled( props );
55
+ function useBlockSettings( name ) {
56
+ const fontFamilies = useSetting( 'typography.fontFamilies' );
57
+ const fontSizes = useSetting( 'typography.fontSizes' );
58
+ const customFontSize = useSetting( 'typography.customFontSize' );
59
+ const fontStyle = useSetting( 'typography.fontStyle' );
60
+ const fontWeight = useSetting( 'typography.fontWeight' );
61
+ const lineHeight = useSetting( 'typography.lineHeight' );
62
+ const textDecoration = useSetting( 'typography.textDecoration' );
63
+ const textTransform = useSetting( 'typography.textTransform' );
64
+ const letterSpacing = useSetting( 'typography.letterSpacing' );
65
+ const supports = useSupportedStyles( name, null );
91
66
 
92
- const isDisabled = useIsTypographyDisabled( props );
93
- const isSupported = hasTypographySupport( props.name );
67
+ return useMemo( () => {
68
+ const rawSettings = {
69
+ typography: {
70
+ fontFamilies: {
71
+ custom: fontFamilies,
72
+ },
73
+ fontSizes: {
74
+ custom: fontSizes,
75
+ },
76
+ customFontSize,
77
+ fontStyle,
78
+ fontWeight,
79
+ lineHeight,
80
+ textDecoration,
81
+ textTransform,
82
+ letterSpacing,
83
+ },
84
+ };
85
+ return overrideSettingsWithSupports( rawSettings, supports );
86
+ }, [
87
+ fontFamilies,
88
+ fontSizes,
89
+ customFontSize,
90
+ fontStyle,
91
+ fontWeight,
92
+ lineHeight,
93
+ textDecoration,
94
+ textTransform,
95
+ letterSpacing,
96
+ supports,
97
+ ] );
98
+ }
94
99
 
95
- if ( isDisabled || ! isSupported ) return null;
100
+ export function TypographyPanel( {
101
+ clientId,
102
+ name,
103
+ attributes,
104
+ setAttributes,
105
+ } ) {
106
+ const settings = useBlockSettings( name );
107
+ const isEnabled = useHasTypographyPanel( settings );
108
+ const value = useMemo( () => {
109
+ return {
110
+ ...attributes.style,
111
+ typography: {
112
+ ...attributes.style?.typography,
113
+ fontFamily: attributes.fontFamily
114
+ ? 'var:preset|font-family|' + attributes.fontFamily
115
+ : undefined,
116
+ fontSize: attributes.fontSize
117
+ ? 'var:preset|font-size|' + attributes.fontSize
118
+ : attributes.style?.typography?.fontSize,
119
+ },
120
+ };
121
+ }, [ attributes.style, attributes.fontSize, attributes.fontFamily ] );
96
122
 
97
- const defaultControls = getBlockSupport( props.name, [
123
+ const onChange = ( newStyle ) => {
124
+ const updatedStyle = { ...omit( newStyle, [ 'fontFamily' ] ) };
125
+ const fontSizeValue = newStyle?.typography?.fontSize;
126
+ const fontFamilyValue = newStyle?.typography?.fontFamily;
127
+ const fontSizeSlug = fontSizeValue?.startsWith(
128
+ 'var:preset|font-size|'
129
+ )
130
+ ? fontSizeValue.substring( 'var:preset|font-size|'.length )
131
+ : undefined;
132
+ const fontFamilySlug = fontFamilyValue?.startsWith(
133
+ 'var:preset|font-family|'
134
+ )
135
+ ? fontFamilyValue.substring( 'var:preset|font-family|'.length )
136
+ : undefined;
137
+ updatedStyle.typography = {
138
+ ...omit( updatedStyle.typography, [ 'fontFamily' ] ),
139
+ fontSize: fontSizeSlug ? undefined : fontSizeValue,
140
+ };
141
+ setAttributes( {
142
+ style: cleanEmptyObject( updatedStyle ),
143
+ fontFamily: fontFamilySlug,
144
+ fontSize: fontSizeSlug,
145
+ } );
146
+ };
147
+
148
+ if ( ! isEnabled ) {
149
+ return null;
150
+ }
151
+
152
+ const defaultControls = getBlockSupport( name, [
98
153
  TYPOGRAPHY_SUPPORT_KEY,
99
154
  '__experimentalDefaultControls',
100
155
  ] );
101
156
 
102
- const createResetAllFilter = ( attribute ) => ( newAttributes ) => ( {
103
- ...newAttributes,
104
- style: {
105
- ...newAttributes.style,
106
- typography: {
107
- ...newAttributes.style?.typography,
108
- [ attribute ]: undefined,
109
- },
110
- },
111
- } );
112
-
113
157
  return (
114
- <InspectorControls group="typography">
115
- { ! isFontFamilyDisabled && (
116
- <ToolsPanelItem
117
- hasValue={ () => hasFontFamilyValue( props ) }
118
- label={ __( 'Font family' ) }
119
- onDeselect={ () => resetFontFamily( props ) }
120
- isShownByDefault={ defaultControls?.fontFamily }
121
- resetAllFilter={ ( newAttributes ) => ( {
122
- ...newAttributes,
123
- fontFamily: undefined,
124
- } ) }
125
- panelId={ clientId }
126
- >
127
- <FontFamilyEdit { ...props } />
128
- </ToolsPanelItem>
129
- ) }
130
- { ! isFontSizeDisabled && (
131
- <ToolsPanelItem
132
- hasValue={ () => hasFontSizeValue( props ) }
133
- /* translators: Ensure translation is distinct from "Letter case" */
134
- label={ __( 'Font size' ) }
135
- onDeselect={ () => resetFontSize( props ) }
136
- isShownByDefault={ defaultControls?.fontSize }
137
- resetAllFilter={ ( newAttributes ) => ( {
138
- ...newAttributes,
139
- fontSize: undefined,
140
- style: {
141
- ...newAttributes.style,
142
- typography: {
143
- ...newAttributes.style?.typography,
144
- fontSize: undefined,
145
- },
146
- },
147
- } ) }
148
- panelId={ clientId }
149
- >
150
- <FontSizeEdit { ...props } />
151
- </ToolsPanelItem>
152
- ) }
153
- { ! isFontAppearanceDisabled && (
154
- <ToolsPanelItem
155
- className="single-column"
156
- hasValue={ () => hasFontAppearanceValue( props ) }
157
- label={ getFontAppearanceLabel(
158
- hasFontStyles,
159
- hasFontWeights
160
- ) }
161
- onDeselect={ () => resetFontAppearance( props ) }
162
- isShownByDefault={ defaultControls?.fontAppearance }
163
- resetAllFilter={ ( newAttributes ) => ( {
164
- ...newAttributes,
165
- style: {
166
- ...newAttributes.style,
167
- typography: {
168
- ...newAttributes.style?.typography,
169
- fontStyle: undefined,
170
- fontWeight: undefined,
171
- },
172
- },
173
- } ) }
174
- panelId={ clientId }
175
- >
176
- <FontAppearanceEdit { ...props } />
177
- </ToolsPanelItem>
178
- ) }
179
- { ! isLineHeightDisabled && (
180
- <ToolsPanelItem
181
- className="single-column"
182
- hasValue={ () => hasLineHeightValue( props ) }
183
- label={ __( 'Line height' ) }
184
- onDeselect={ () => resetLineHeight( props ) }
185
- isShownByDefault={ defaultControls?.lineHeight }
186
- resetAllFilter={ createResetAllFilter( 'lineHeight' ) }
187
- panelId={ clientId }
188
- >
189
- <LineHeightEdit { ...props } />
190
- </ToolsPanelItem>
191
- ) }
192
- { ! isLetterSpacingDisabled && (
193
- <ToolsPanelItem
194
- className="single-column"
195
- hasValue={ () => hasLetterSpacingValue( props ) }
196
- label={ __( 'Letter spacing' ) }
197
- onDeselect={ () => resetLetterSpacing( props ) }
198
- isShownByDefault={ defaultControls?.letterSpacing }
199
- resetAllFilter={ createResetAllFilter( 'letterSpacing' ) }
200
- panelId={ clientId }
201
- >
202
- <LetterSpacingEdit { ...props } />
203
- </ToolsPanelItem>
204
- ) }
205
- { ! isTextDecorationDisabled && (
206
- <ToolsPanelItem
207
- className="single-column"
208
- hasValue={ () => hasTextDecorationValue( props ) }
209
- label={ __( 'Decoration' ) }
210
- onDeselect={ () => resetTextDecoration( props ) }
211
- isShownByDefault={ defaultControls?.textDecoration }
212
- resetAllFilter={ createResetAllFilter( 'textDecoration' ) }
213
- panelId={ clientId }
214
- >
215
- <TextDecorationEdit { ...props } />
216
- </ToolsPanelItem>
217
- ) }
218
- { ! isTextTransformDisabled && (
219
- <ToolsPanelItem
220
- hasValue={ () => hasTextTransformValue( props ) }
221
- /* translators: Ensure translation is distinct from "Font size" */
222
- label={ __( 'Letter case' ) }
223
- onDeselect={ () => resetTextTransform( props ) }
224
- isShownByDefault={ defaultControls?.textTransform }
225
- resetAllFilter={ createResetAllFilter( 'textTransform' ) }
226
- panelId={ clientId }
227
- >
228
- <TextTransformEdit { ...props } />
229
- </ToolsPanelItem>
230
- ) }
231
- </InspectorControls>
158
+ <StylesTypographyPanel
159
+ as={ TypographyInspectorControl }
160
+ panelId={ clientId }
161
+ name={ name }
162
+ settings={ settings }
163
+ value={ value }
164
+ onChange={ onChange }
165
+ defaultControls={ defaultControls }
166
+ />
232
167
  );
233
168
  }
234
169
 
@@ -237,17 +172,3 @@ export const hasTypographySupport = ( blockName ) => {
237
172
  hasBlockSupport( blockName, key )
238
173
  );
239
174
  };
240
-
241
- function useIsTypographyDisabled( props = {} ) {
242
- const configs = [
243
- useIsFontAppearanceDisabled( props ),
244
- useIsFontSizeDisabled( props ),
245
- useIsLineHeightDisabled( props ),
246
- useIsFontFamilyDisabled( props ),
247
- useIsTextDecorationDisabled( props ),
248
- useIsTextTransformDisabled( props ),
249
- useIsLetterSpacingDisabled( props ),
250
- ];
251
-
252
- return configs.filter( Boolean ).length === configs.length;
253
- }
package/src/index.js CHANGED
@@ -20,4 +20,4 @@ export * from './elements';
20
20
  export * from './utils';
21
21
  export { storeConfig, store } from './store';
22
22
  export { SETTINGS_DEFAULTS } from './store/defaults';
23
- export { experiments } from './experiments';
23
+ export { privateApis } from './private-apis';
@@ -56,7 +56,7 @@ export default {
56
56
  getOrientation() {
57
57
  return 'vertical';
58
58
  },
59
- getAlignments( layout ) {
59
+ getAlignments( layout, isBlockBasedTheme ) {
60
60
  const alignmentInfo = getAlignmentsInfo( layout );
61
61
  if ( layout.alignments !== undefined ) {
62
62
  if ( ! layout.alignments.includes( 'none' ) ) {
@@ -74,6 +74,21 @@ export default {
74
74
  { name: 'right' },
75
75
  ];
76
76
 
77
+ // This is for backwards compatibility with hybrid themes.
78
+ if ( ! isBlockBasedTheme ) {
79
+ const { contentSize, wideSize } = layout;
80
+ if ( contentSize ) {
81
+ alignments.unshift( { name: 'full' } );
82
+ }
83
+
84
+ if ( wideSize ) {
85
+ alignments.unshift( {
86
+ name: 'wide',
87
+ info: alignmentInfo.wide,
88
+ } );
89
+ }
90
+ }
91
+
77
92
  alignments.unshift( { name: 'none', info: alignmentInfo.none } );
78
93
 
79
94
  return alignments;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
5
+
6
+ export const { lock, unlock } =
7
+ __dangerousOptInToUnstableAPIsOnlyForCoreModules(
8
+ 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',
9
+ '@wordpress/block-editor'
10
+ );
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import * as globalStyles from './components/global-styles';
5
+ import { ExperimentalBlockEditorProvider } from './components/provider';
6
+ import { lock } from './lock-unlock';
7
+ import OffCanvasEditor from './components/off-canvas-editor';
8
+ import LeafMoreMenu from './components/off-canvas-editor/leaf-more-menu';
9
+
10
+ /**
11
+ * Private @wordpress/block-editor APIs.
12
+ */
13
+ export const privateApis = {};
14
+ lock( privateApis, {
15
+ ...globalStyles,
16
+ ExperimentalBlockEditorProvider,
17
+ LeafMoreMenu,
18
+ OffCanvasEditor,
19
+ } );
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import * as globalStyles from './components/global-styles';
5
+ import { ExperimentalBlockEditorProvider } from './components/provider';
6
+ import { lock } from './lock-unlock';
7
+
8
+ /**
9
+ * Private @wordpress/block-editor APIs.
10
+ */
11
+ export const privateApis = {};
12
+ lock( privateApis, {
13
+ ...globalStyles,
14
+ ExperimentalBlockEditorProvider,
15
+ } );
@@ -12,7 +12,7 @@ import * as privateActions from './private-actions';
12
12
  import * as privateSelectors from './private-selectors';
13
13
  import * as actions from './actions';
14
14
  import { STORE_NAME } from './constants';
15
- import { unlock } from '../experiments';
15
+ import { unlock } from '../lock-unlock';
16
16
 
17
17
  /**
18
18
  * Block editor data store configuration.
@@ -55,6 +55,17 @@ const MILLISECONDS_PER_WEEK = 7 * 24 * 3600 * 1000;
55
55
  */
56
56
  const EMPTY_ARRAY = [];
57
57
 
58
+ /**
59
+ * Shared reference to an empty Set for cases where it is important to avoid
60
+ * returning a new Set reference on every invocation, as in a connected or
61
+ * other pure component which performs `shouldComponentUpdate` check on props.
62
+ * This should be used as a last resort, since the normalized data should be
63
+ * maintained by the reducer result in state.
64
+ *
65
+ * @type {Set}
66
+ */
67
+ const EMPTY_SET = new Set();
68
+
58
69
  /**
59
70
  * Returns a block's name given its client ID, or null if no block exists with
60
71
  * the client ID.
@@ -2722,11 +2733,15 @@ export function isBlockVisible( state, clientId ) {
2722
2733
  */
2723
2734
  export const __unstableGetVisibleBlocks = createSelector(
2724
2735
  ( state ) => {
2725
- return new Set(
2736
+ const visibleBlocks = new Set(
2726
2737
  Object.keys( state.blockVisibility ).filter(
2727
2738
  ( key ) => state.blockVisibility[ key ]
2728
2739
  )
2729
2740
  );
2741
+ if ( visibleBlocks.size === 0 ) {
2742
+ return EMPTY_SET;
2743
+ }
2744
+ return visibleBlocks;
2730
2745
  },
2731
2746
  ( state ) => [ state.blockVisibility ]
2732
2747
  );
package/tsconfig.json CHANGED
@@ -5,10 +5,29 @@
5
5
  "declarationDir": "build-types"
6
6
  },
7
7
  "references": [
8
+ { "path": "../a11y" },
9
+ { "path": "../api-fetch" },
10
+ { "path": "../blob" },
11
+ { "path": "../components" },
12
+ { "path": "../compose" },
13
+ { "path": "../data" },
14
+ { "path": "../date" },
8
15
  { "path": "../deprecated" },
16
+ { "path": "../dom" },
9
17
  { "path": "../element" },
18
+ { "path": "../escape-html" },
19
+ { "path": "../private-apis" },
10
20
  { "path": "../hooks" },
11
- { "path": "../data" }
21
+ { "path": "../html-entities" },
22
+ { "path": "../i18n" },
23
+ { "path": "../icons" },
24
+ { "path": "../is-shallow-equal" },
25
+ { "path": "../keycodes" },
26
+ { "path": "../style-engine" },
27
+ { "path": "../token-list" },
28
+ { "path": "../url" },
29
+ { "path": "../warning" },
30
+ { "path": "../wordcount" }
12
31
  ],
13
32
  // NOTE: This package is being progressively typed. You are encouraged to
14
33
  // expand this array with files which can be type-checked. At some point in
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/experiments.js"],"names":["lock","unlock","experiments","globalStyles","ExperimentalBlockEditorProvider","OffCanvasEditor"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;;;;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAKO,MAAM;AAAEA,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZ,mEACC,8GADD,EAEC,yBAFD,CADM;AAMP;AACA;AACA;;;;AACO,MAAMC,WAAW,GAAG,EAApB;;AACPF,IAAI,CAAEE,WAAF,EAAe,EAClB,GAAGC,YADe;AAElBC,EAAAA,+BAA+B,EAA/BA,yCAFkB;AAGlBC,EAAAA,eAAe,EAAfA;AAHkB,CAAf,CAAJ","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments';\n\n/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport OffCanvasEditor from './components/off-canvas-editor';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/block-editor'\n\t);\n\n/**\n * Experimental @wordpress/block-editor APIs.\n */\nexport const experiments = {};\nlock( experiments, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n\tOffCanvasEditor,\n} );\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/experiments.native.js"],"names":["lock","unlock","experiments","globalStyles","ExperimentalBlockEditorProvider"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;;;;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAM;AAAEA,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZ,mEACC,8GADD,EAEC,yBAFD,CADM;AAMP;AACA;AACA;;;;AACO,MAAMC,WAAW,GAAG,EAApB;;AACPF,IAAI,CAAEE,WAAF,EAAe,EAClB,GAAGC,YADe;AAElBC,EAAAA,+BAA+B,EAA/BA;AAFkB,CAAf,CAAJ","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments';\n\n/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/block-editor'\n\t);\n\n/**\n * Experimental @wordpress/block-editor APIs.\n */\nexport const experiments = {};\nlock( experiments, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n} );\n"]}