@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.
- package/CHANGELOG.md +6 -0
- package/README.md +4 -4
- package/build/components/block-actions/index.js +2 -7
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-alignment-control/use-available-alignments.js +5 -3
- package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
- package/build/components/block-popover/inbetween.js +10 -33
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +2 -2
- package/build/components/block-tools/selected-block-popover.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 +5 -4
- 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/provider/index.js +2 -2
- package/build/components/provider/index.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/components/url-popover/index.js +6 -1
- package/build/components/url-popover/index.js.map +1 -1
- package/build/hooks/dimensions.js +8 -2
- 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/metadata.js +6 -0
- package/build/hooks/metadata.js.map +1 -1
- package/build/hooks/position.js +6 -1
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/typography.js +112 -127
- package/build/hooks/typography.js.map +1 -1
- package/build/index.js +6 -6
- package/build/index.js.map +1 -1
- package/build/layouts/flow.js +23 -2
- package/build/layouts/flow.js.map +1 -1
- package/build/lock-unlock.js +19 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/{experiments.js → private-apis.js} +12 -19
- package/build/private-apis.js.map +1 -0
- package/build/{experiments.native.js → private-apis.native.js} +9 -19
- package/build/private-apis.native.js.map +1 -0
- package/build/store/index.js +3 -3
- package/build/store/index.js.map +1 -1
- package/build/store/selectors.js +18 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-actions/index.js +2 -7
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-alignment-control/use-available-alignments.js +5 -3
- package/build-module/components/block-alignment-control/use-available-alignments.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-tools/selected-block-popover.js +1 -1
- package/build-module/components/block-tools/selected-block-popover.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 +4 -3
- 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/provider/index.js +1 -1
- package/build-module/components/provider/index.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/components/url-popover/index.js +6 -2
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/hooks/dimensions.js +7 -1
- 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/metadata.js +6 -0
- package/build-module/hooks/metadata.js.map +1 -1
- package/build-module/hooks/position.js +5 -1
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/typography.js +110 -123
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flow.js +23 -2
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/private-apis.js +19 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/private-apis.native.js +15 -0
- package/build-module/private-apis.native.js.map +1 -0
- package/build-module/store/index.js +1 -1
- package/build-module/store/index.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-actions/index.js +0 -9
- package/src/components/block-alignment-control/use-available-alignments.js +17 -12
- package/src/components/block-popover/inbetween.js +21 -53
- package/src/components/block-tools/selected-block-popover.js +1 -1
- 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 +3 -2
- 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/provider/index.js +1 -1
- package/src/components/rich-text/index.js +0 -2
- package/src/components/url-input/index.js +3 -2
- package/src/components/url-popover/index.js +8 -2
- package/src/hooks/dimensions.js +13 -1
- 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/metadata.js +4 -0
- package/src/hooks/position.js +7 -1
- package/src/hooks/typography.js +133 -212
- package/src/index.js +1 -1
- package/src/layouts/flow.js +16 -1
- package/src/lock-unlock.js +10 -0
- package/src/private-apis.js +19 -0
- package/src/private-apis.native.js +15 -0
- package/src/store/index.js +1 -1
- package/src/store/selectors.js +16 -1
- package/tsconfig.json +20 -1
- package/build/experiments.js.map +0 -1
- package/build/experiments.native.js.map +0 -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/experiments.js +0 -25
- package/build-module/experiments.js.map +0 -1
- package/build-module/experiments.native.js +0 -23
- package/build-module/experiments.native.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/experiments.js +0 -27
- package/src/experiments.native.js +0 -25
- 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
|
@@ -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(
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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,
|
|
130
|
+
set( newUserConfig, contextualPath, newValue );
|
|
49
131
|
|
|
50
132
|
return newUserConfig;
|
|
51
133
|
} );
|
|
52
134
|
};
|
|
53
135
|
|
|
54
|
-
|
|
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(
|
|
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
|
|
93
|
-
: `styles.blocks.${ blockName }
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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(
|
|
123
|
-
|
|
124
|
-
|
|
183
|
+
: get( mergedConfig, finalPath );
|
|
184
|
+
result = shouldDecodeEncode
|
|
185
|
+
? getValueFromVariable( mergedConfig, blockName, rawResult )
|
|
186
|
+
: rawResult;
|
|
125
187
|
break;
|
|
126
188
|
case 'user':
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
blockName,
|
|
130
|
-
|
|
131
|
-
);
|
|
189
|
+
rawResult = get( userConfig, finalPath );
|
|
190
|
+
result = shouldDecodeEncode
|
|
191
|
+
? getValueFromVariable( mergedConfig, blockName, rawResult )
|
|
192
|
+
: rawResult;
|
|
132
193
|
break;
|
|
133
194
|
case 'base':
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
blockName,
|
|
137
|
-
|
|
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';
|