@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.
- package/CHANGELOG.md +6 -0
- package/build/components/block-popover/inbetween.js +10 -33
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-types-list/index.native.js +2 -0
- package/build/components/block-types-list/index.native.js.map +1 -1
- package/build/components/colors-gradients/control.js +6 -3
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/font-appearance-control/index.js +0 -3
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/global-styles/hooks.js +106 -45
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +24 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +421 -0
- package/build/components/global-styles/typography-panel.js.map +1 -0
- package/build/components/global-styles/use-global-styles-output.js +6 -2
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/index.js +17 -11
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js +2 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -11
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +9 -15
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js +4 -1
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +4 -1
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +4 -1
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/link-control/index.js +15 -15
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +72 -30
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/settings.js +52 -0
- package/build/components/link-control/settings.js.map +1 -0
- package/build/components/list-view/index.js +6 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +3 -2
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +116 -0
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
- package/build/components/off-canvas-editor/link-ui.js +1 -0
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/rich-text/index.js +0 -2
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-input/index.js +2 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/hooks/dimensions.js +6 -0
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/font-family.js +2 -76
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +3 -51
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/gap.js +2 -1
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/line-height.js +0 -42
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/typography.js +112 -127
- package/build/hooks/typography.js.map +1 -1
- package/build/private-apis.js +3 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/selectors.js +18 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +10 -33
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-types-list/index.native.js +2 -0
- package/build-module/components/block-types-list/index.native.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +6 -3
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +2 -1
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +100 -46
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +400 -0
- package/build-module/components/global-styles/typography-panel.js.map +1 -0
- package/build-module/components/global-styles/use-global-styles-output.js +6 -2
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/index.js +17 -11
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +2 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-size-control/index.js +7 -12
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +9 -15
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.native.js +3 -1
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +3 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +3 -1
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/link-control/index.js +16 -16
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +68 -30
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/settings.js +43 -0
- package/build-module/components/link-control/settings.js.map +1 -0
- package/build-module/components/list-view/index.js +6 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +3 -2
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +99 -0
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
- package/build-module/components/off-canvas-editor/link-ui.js +1 -0
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/rich-text/index.js +0 -2
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-input/index.js +2 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/hooks/dimensions.js +6 -0
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/font-family.js +3 -69
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +6 -47
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/gap.js +3 -2
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/line-height.js +0 -38
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/typography.js +110 -123
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/selectors.js +18 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +35 -22
- package/build-style/style.css +35 -22
- package/package.json +31 -31
- package/src/components/block-popover/inbetween.js +21 -53
- package/src/components/block-types-list/index.native.js +2 -0
- package/src/components/colors-gradients/control.js +3 -0
- package/src/components/font-appearance-control/index.js +1 -1
- package/src/components/global-styles/hooks.js +186 -66
- package/src/components/global-styles/index.js +5 -0
- package/src/components/global-styles/typography-panel.js +403 -0
- package/src/components/global-styles/use-global-styles-output.js +6 -2
- package/src/components/iframe/index.js +20 -18
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -0
- package/src/components/image-size-control/index.js +10 -12
- package/src/components/image-size-control/style.scss +3 -21
- package/src/components/inserter/block-patterns-tab.js +9 -23
- package/src/components/inserter/block-types-tab.native.js +2 -0
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -0
- package/src/components/inserter/search-results.native.js +2 -0
- package/src/components/link-control/index.js +22 -22
- package/src/components/link-control/settings-drawer.js +85 -30
- package/src/components/link-control/settings.js +41 -0
- package/src/components/link-control/style.scss +39 -7
- package/src/components/link-control/test/index.js +213 -4
- package/src/components/list-view/index.js +5 -0
- package/src/components/off-canvas-editor/block-contents.js +2 -1
- package/src/components/off-canvas-editor/leaf-more-menu.js +115 -0
- package/src/components/off-canvas-editor/link-ui.js +1 -0
- package/src/components/rich-text/index.js +0 -2
- package/src/components/url-input/index.js +3 -2
- package/src/hooks/dimensions.js +12 -0
- package/src/hooks/font-family.js +0 -58
- package/src/hooks/font-size.js +1 -36
- package/src/hooks/gap.js +9 -2
- package/src/hooks/index.js +1 -0
- package/src/hooks/line-height.js +0 -33
- package/src/hooks/typography.js +133 -212
- package/src/private-apis.js +2 -0
- package/src/store/selectors.js +16 -1
- package/build/hooks/font-appearance.js +0 -188
- package/build/hooks/font-appearance.js.map +0 -1
- package/build/hooks/letter-spacing.js +0 -129
- package/build/hooks/letter-spacing.js.map +0 -1
- package/build/hooks/text-decoration.js +0 -130
- package/build/hooks/text-decoration.js.map +0 -1
- package/build/hooks/text-transform.js +0 -130
- package/build/hooks/text-transform.js.map +0 -1
- package/build-module/hooks/font-appearance.js +0 -161
- package/build-module/hooks/font-appearance.js.map +0 -1
- package/build-module/hooks/letter-spacing.js +0 -107
- package/build-module/hooks/letter-spacing.js.map +0 -1
- package/build-module/hooks/text-decoration.js +0 -108
- package/build-module/hooks/text-decoration.js.map +0 -1
- package/build-module/hooks/text-transform.js +0 -108
- package/build-module/hooks/text-transform.js.map +0 -1
- package/src/hooks/font-appearance.js +0 -146
- package/src/hooks/letter-spacing.js +0 -101
- package/src/hooks/text-decoration.js +0 -102
- package/src/hooks/text-transform.js +0 -101
package/src/hooks/typography.js
CHANGED
|
@@ -2,68 +2,38 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
|
|
5
|
-
import {
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} from './
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
90
|
-
const
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
<
|
|
115
|
-
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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/private-apis.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as globalStyles from './components/global-styles';
|
|
|
5
5
|
import { ExperimentalBlockEditorProvider } from './components/provider';
|
|
6
6
|
import { lock } from './lock-unlock';
|
|
7
7
|
import OffCanvasEditor from './components/off-canvas-editor';
|
|
8
|
+
import LeafMoreMenu from './components/off-canvas-editor/leaf-more-menu';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Private @wordpress/block-editor APIs.
|
|
@@ -13,5 +14,6 @@ export const privateApis = {};
|
|
|
13
14
|
lock( privateApis, {
|
|
14
15
|
...globalStyles,
|
|
15
16
|
ExperimentalBlockEditorProvider,
|
|
17
|
+
LeafMoreMenu,
|
|
16
18
|
OffCanvasEditor,
|
|
17
19
|
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -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
|
-
|
|
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
|
);
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.FONT_WEIGHT_SUPPORT_KEY = exports.FONT_STYLE_SUPPORT_KEY = void 0;
|
|
9
|
-
exports.FontAppearanceEdit = FontAppearanceEdit;
|
|
10
|
-
exports.hasFontAppearanceValue = hasFontAppearanceValue;
|
|
11
|
-
exports.resetFontAppearance = resetFontAppearance;
|
|
12
|
-
exports.useIsFontAppearanceDisabled = useIsFontAppearanceDisabled;
|
|
13
|
-
exports.useIsFontStyleDisabled = useIsFontStyleDisabled;
|
|
14
|
-
exports.useIsFontWeightDisabled = useIsFontWeightDisabled;
|
|
15
|
-
|
|
16
|
-
var _element = require("@wordpress/element");
|
|
17
|
-
|
|
18
|
-
var _blocks = require("@wordpress/blocks");
|
|
19
|
-
|
|
20
|
-
var _fontAppearanceControl = _interopRequireDefault(require("../components/font-appearance-control"));
|
|
21
|
-
|
|
22
|
-
var _useSetting = _interopRequireDefault(require("../components/use-setting"));
|
|
23
|
-
|
|
24
|
-
var _utils = require("./utils");
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* WordPress dependencies
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Internal dependencies
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Key within block settings' support array indicating support for font style.
|
|
36
|
-
*/
|
|
37
|
-
const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
|
|
38
|
-
/**
|
|
39
|
-
* Key within block settings' support array indicating support for font weight.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
exports.FONT_STYLE_SUPPORT_KEY = FONT_STYLE_SUPPORT_KEY;
|
|
43
|
-
const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
|
|
44
|
-
/**
|
|
45
|
-
* Inspector control panel containing the font appearance options.
|
|
46
|
-
*
|
|
47
|
-
* @param {Object} props Block properties.
|
|
48
|
-
*
|
|
49
|
-
* @return {WPElement} Font appearance edit element.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
exports.FONT_WEIGHT_SUPPORT_KEY = FONT_WEIGHT_SUPPORT_KEY;
|
|
53
|
-
|
|
54
|
-
function FontAppearanceEdit(props) {
|
|
55
|
-
var _style$typography, _style$typography2;
|
|
56
|
-
|
|
57
|
-
const {
|
|
58
|
-
attributes: {
|
|
59
|
-
style
|
|
60
|
-
},
|
|
61
|
-
setAttributes
|
|
62
|
-
} = props;
|
|
63
|
-
const hasFontStyles = !useIsFontStyleDisabled(props);
|
|
64
|
-
const hasFontWeights = !useIsFontWeightDisabled(props);
|
|
65
|
-
|
|
66
|
-
const onChange = newStyles => {
|
|
67
|
-
setAttributes({
|
|
68
|
-
style: (0, _utils.cleanEmptyObject)({ ...style,
|
|
69
|
-
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
|
|
70
|
-
fontStyle: newStyles.fontStyle,
|
|
71
|
-
fontWeight: newStyles.fontWeight
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const fontStyle = style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.fontStyle;
|
|
78
|
-
const fontWeight = style === null || style === void 0 ? void 0 : (_style$typography2 = style.typography) === null || _style$typography2 === void 0 ? void 0 : _style$typography2.fontWeight;
|
|
79
|
-
return (0, _element.createElement)(_fontAppearanceControl.default, {
|
|
80
|
-
onChange: onChange,
|
|
81
|
-
hasFontStyles: hasFontStyles,
|
|
82
|
-
hasFontWeights: hasFontWeights,
|
|
83
|
-
value: {
|
|
84
|
-
fontStyle,
|
|
85
|
-
fontWeight
|
|
86
|
-
},
|
|
87
|
-
size: "__unstable-large"
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Checks if font style support has been disabled either by not opting in for
|
|
92
|
-
* support or by failing to provide preset styles.
|
|
93
|
-
*
|
|
94
|
-
* @param {Object} props Block properties.
|
|
95
|
-
* @param {string} props.name Name for the block type.
|
|
96
|
-
*
|
|
97
|
-
* @return {boolean} Whether font style support has been disabled.
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
function useIsFontStyleDisabled() {
|
|
102
|
-
let {
|
|
103
|
-
name: blockName
|
|
104
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
105
|
-
const styleSupport = (0, _blocks.hasBlockSupport)(blockName, FONT_STYLE_SUPPORT_KEY);
|
|
106
|
-
const hasFontStyles = (0, _useSetting.default)('typography.fontStyle');
|
|
107
|
-
return !styleSupport || !hasFontStyles;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Checks if font weight support has been disabled either by not opting in for
|
|
111
|
-
* support or by failing to provide preset weights.
|
|
112
|
-
*
|
|
113
|
-
* @param {Object} props Block properties.
|
|
114
|
-
* @param {string} props.name Name for the block type.
|
|
115
|
-
*
|
|
116
|
-
* @return {boolean} Whether font weight support has been disabled.
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function useIsFontWeightDisabled() {
|
|
121
|
-
let {
|
|
122
|
-
name: blockName
|
|
123
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
124
|
-
const weightSupport = (0, _blocks.hasBlockSupport)(blockName, FONT_WEIGHT_SUPPORT_KEY);
|
|
125
|
-
const hasFontWeights = (0, _useSetting.default)('typography.fontWeight');
|
|
126
|
-
return !weightSupport || !hasFontWeights;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Checks if font appearance support has been disabled.
|
|
130
|
-
*
|
|
131
|
-
* @param {Object} props Block properties.
|
|
132
|
-
*
|
|
133
|
-
* @return {boolean} Whether font appearance support has been disabled.
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function useIsFontAppearanceDisabled(props) {
|
|
138
|
-
const stylesDisabled = useIsFontStyleDisabled(props);
|
|
139
|
-
const weightsDisabled = useIsFontWeightDisabled(props);
|
|
140
|
-
return stylesDisabled && weightsDisabled;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Checks if there is either a font style or weight value set within the
|
|
144
|
-
* typography styles.
|
|
145
|
-
*
|
|
146
|
-
* @param {Object} props Block props.
|
|
147
|
-
* @return {boolean} Whether or not the block has a font style or weight.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
function hasFontAppearanceValue(props) {
|
|
152
|
-
var _props$attributes$sty;
|
|
153
|
-
|
|
154
|
-
const {
|
|
155
|
-
fontStyle,
|
|
156
|
-
fontWeight
|
|
157
|
-
} = ((_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : _props$attributes$sty.typography) || {};
|
|
158
|
-
return !!fontStyle || !!fontWeight;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Resets the font style and weight block support attributes. This can be used
|
|
162
|
-
* when disabling the font appearance support controls for a block via a
|
|
163
|
-
* progressive discovery panel.
|
|
164
|
-
*
|
|
165
|
-
* @param {Object} props Block props.
|
|
166
|
-
* @param {Object} props.attributes Block's attributes.
|
|
167
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
function resetFontAppearance(_ref) {
|
|
172
|
-
let {
|
|
173
|
-
attributes = {},
|
|
174
|
-
setAttributes
|
|
175
|
-
} = _ref;
|
|
176
|
-
const {
|
|
177
|
-
style
|
|
178
|
-
} = attributes;
|
|
179
|
-
setAttributes({
|
|
180
|
-
style: (0, _utils.cleanEmptyObject)({ ...style,
|
|
181
|
-
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
|
|
182
|
-
fontStyle: undefined,
|
|
183
|
-
fontWeight: undefined
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
//# sourceMappingURL=font-appearance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/font-appearance.js"],"names":["FONT_STYLE_SUPPORT_KEY","FONT_WEIGHT_SUPPORT_KEY","FontAppearanceEdit","props","attributes","style","setAttributes","hasFontStyles","useIsFontStyleDisabled","hasFontWeights","useIsFontWeightDisabled","onChange","newStyles","typography","fontStyle","fontWeight","name","blockName","styleSupport","weightSupport","useIsFontAppearanceDisabled","stylesDisabled","weightsDisabled","hasFontAppearanceValue","resetFontAppearance","undefined"],"mappings":"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","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport FontAppearanceControl from '../components/font-appearance-control';\nimport useSetting from '../components/use-setting';\nimport { cleanEmptyObject } from './utils';\n\n/**\n * Key within block settings' support array indicating support for font style.\n */\nexport const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';\n\n/**\n * Key within block settings' support array indicating support for font weight.\n */\nexport const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';\n\n/**\n * Inspector control panel containing the font appearance options.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Font appearance edit element.\n */\nexport function FontAppearanceEdit( props ) {\n\tconst {\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst hasFontStyles = ! useIsFontStyleDisabled( props );\n\tconst hasFontWeights = ! useIsFontWeightDisabled( props );\n\n\tconst onChange = ( newStyles ) => {\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\tfontStyle: newStyles.fontStyle,\n\t\t\t\t\tfontWeight: newStyles.fontWeight,\n\t\t\t\t},\n\t\t\t} ),\n\t\t} );\n\t};\n\n\tconst fontStyle = style?.typography?.fontStyle;\n\tconst fontWeight = style?.typography?.fontWeight;\n\n\treturn (\n\t\t<FontAppearanceControl\n\t\t\tonChange={ onChange }\n\t\t\thasFontStyles={ hasFontStyles }\n\t\t\thasFontWeights={ hasFontWeights }\n\t\t\tvalue={ { fontStyle, fontWeight } }\n\t\t\tsize=\"__unstable-large\"\n\t\t/>\n\t);\n}\n\n/**\n * Checks if font style support has been disabled either by not opting in for\n * support or by failing to provide preset styles.\n *\n * @param {Object} props Block properties.\n * @param {string} props.name Name for the block type.\n *\n * @return {boolean} Whether font style support has been disabled.\n */\nexport function useIsFontStyleDisabled( { name: blockName } = {} ) {\n\tconst styleSupport = hasBlockSupport( blockName, FONT_STYLE_SUPPORT_KEY );\n\tconst hasFontStyles = useSetting( 'typography.fontStyle' );\n\n\treturn ! styleSupport || ! hasFontStyles;\n}\n\n/**\n * Checks if font weight support has been disabled either by not opting in for\n * support or by failing to provide preset weights.\n *\n * @param {Object} props Block properties.\n * @param {string} props.name Name for the block type.\n *\n * @return {boolean} Whether font weight support has been disabled.\n */\nexport function useIsFontWeightDisabled( { name: blockName } = {} ) {\n\tconst weightSupport = hasBlockSupport( blockName, FONT_WEIGHT_SUPPORT_KEY );\n\tconst hasFontWeights = useSetting( 'typography.fontWeight' );\n\n\treturn ! weightSupport || ! hasFontWeights;\n}\n\n/**\n * Checks if font appearance support has been disabled.\n *\n * @param {Object} props Block properties.\n *\n * @return {boolean} Whether font appearance support has been disabled.\n */\nexport function useIsFontAppearanceDisabled( props ) {\n\tconst stylesDisabled = useIsFontStyleDisabled( props );\n\tconst weightsDisabled = useIsFontWeightDisabled( props );\n\n\treturn stylesDisabled && weightsDisabled;\n}\n\n/**\n * Checks if there is either a font style or weight value set within the\n * typography styles.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a font style or weight.\n */\nexport function hasFontAppearanceValue( props ) {\n\tconst { fontStyle, fontWeight } = props.attributes.style?.typography || {};\n\treturn !! fontStyle || !! fontWeight;\n}\n\n/**\n * Resets the font style and weight block support attributes. This can be used\n * when disabling the font appearance support controls for a block via a\n * progressive discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetFontAppearance( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\ttypography: {\n\t\t\t\t...style?.typography,\n\t\t\t\tfontStyle: undefined,\n\t\t\t\tfontWeight: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n"]}
|