@wordpress/block-editor 11.5.0 → 11.6.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 +2 -0
- package/build/components/block-list/block-invalid-warning.js +63 -80
- package/build/components/block-list/block-invalid-warning.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.native.js +1 -0
- package/build/components/block-switcher/block-transformations-menu.native.js.map +1 -1
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +6 -3
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build/components/global-styles/border-panel.js +306 -0
- package/build/components/global-styles/border-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +57 -3
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +20 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +62 -15
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +20 -13
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/inserter/index.js +29 -17
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/menu.js +1 -1
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +4 -2
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-results.js +10 -3
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/inserter/tabs.js +1 -1
- package/build/components/inserter/tabs.js.map +1 -1
- package/build/components/link-control/index.js +1 -1
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-item.js +5 -2
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +1 -2
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +28 -3
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +5 -3
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +9 -7
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/link-ui.js +0 -1
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/provider/use-block-sync.js +17 -3
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +0 -3
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/hooks/border.js +91 -240
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/custom-class-name.js +4 -4
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/custom-class-name.native.js +3 -4
- package/build/hooks/custom-class-name.native.js.map +1 -1
- package/build/hooks/layout.js +19 -22
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/supports.js +7 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +2 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +27 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/constrained.js +6 -2
- package/build/layouts/constrained.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +10 -8
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +19 -3
- package/build/store/selectors.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +15 -9
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.js +66 -78
- package/build-module/components/block-list/block-invalid-warning.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +1 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.native.js +1 -0
- package/build-module/components/block-switcher/block-transformations-menu.native.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +6 -3
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +291 -0
- package/build-module/components/global-styles/border-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +54 -3
- 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 +62 -16
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +20 -13
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/inserter/index.js +28 -16
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/menu.js +1 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +4 -2
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-results.js +10 -3
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/inserter/tabs.js +1 -1
- package/build-module/components/inserter/tabs.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-item.js +4 -2
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +1 -2
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +28 -4
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +5 -3
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +9 -7
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/link-ui.js +0 -1
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +17 -3
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +0 -3
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/hooks/border.js +93 -240
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/custom-class-name.js +4 -4
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/custom-class-name.native.js +3 -4
- package/build-module/hooks/custom-class-name.native.js.map +1 -1
- package/build-module/hooks/layout.js +19 -22
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/supports.js +7 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +2 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +27 -1
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/constrained.js +6 -2
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +10 -8
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +17 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +15 -9
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +6 -6
- package/build-style/style.css +6 -6
- package/package.json +31 -31
- package/src/components/block-inspector/style.scss +3 -0
- package/src/components/block-list/block-invalid-warning.js +72 -64
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +20 -2
- package/src/components/block-preview/test/index.js +0 -2
- package/src/components/block-settings-menu-controls/index.js +2 -1
- package/src/components/block-styles/style.scss +2 -2
- package/src/components/block-switcher/block-transformations-menu.native.js +1 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +16 -14
- package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +48 -38
- package/src/components/global-styles/border-panel.js +285 -0
- package/src/components/global-styles/hooks.js +74 -1
- package/src/components/global-styles/index.js +2 -0
- package/src/components/global-styles/test/use-global-styles-output.js +1 -1
- package/src/components/global-styles/typography-panel.js +48 -1
- package/src/components/global-styles/use-global-styles-output.js +13 -13
- package/src/components/inserter/index.js +30 -11
- package/src/components/inserter/menu.js +0 -1
- package/src/components/inserter/quick-inserter.js +2 -0
- package/src/components/inserter/search-results.js +7 -1
- package/src/components/inserter/style.scss +3 -0
- package/src/components/inserter/tabs.js +1 -9
- package/src/components/link-control/index.js +1 -1
- package/src/components/link-control/search-item.js +3 -1
- package/src/components/link-control/style.scss +0 -4
- package/src/components/link-control/test/index.js +0 -2
- package/src/components/list-view/use-block-selection.js +0 -2
- package/src/components/off-canvas-editor/appender.js +31 -5
- package/src/components/off-canvas-editor/branch.js +3 -1
- package/src/components/off-canvas-editor/index.js +7 -7
- package/src/components/off-canvas-editor/link-ui.js +0 -1
- package/src/components/provider/use-block-sync.js +21 -4
- package/src/components/rich-text/format-toolbar-container.js +1 -7
- package/src/components/url-popover/test/index.js +0 -2
- package/src/hooks/border.js +94 -225
- package/src/hooks/custom-class-name.js +4 -4
- package/src/hooks/custom-class-name.native.js +3 -4
- package/src/hooks/layout.js +19 -16
- package/src/hooks/supports.js +6 -0
- package/src/hooks/test/style.js +2 -1
- package/src/hooks/test/use-typography-props.js +2 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/utils.js +36 -0
- package/src/layouts/constrained.js +23 -17
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +10 -8
- package/src/store/selectors.js +20 -3
- package/src/utils/parse-css-unit-to-px.js +14 -9
- package/src/utils/test/parse-css-unit-to-px.js +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/border-radius.js +0 -100
- package/build/hooks/border-radius.js.map +0 -1
- package/build-module/hooks/border-radius.js +0 -84
- package/build-module/hooks/border-radius.js.map +0 -1
- package/src/hooks/border-radius.js +0 -70
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { __experimentalBorderBoxControl as BorderBoxControl, __experimentalHasSplitBorders as hasSplitBorders, __experimentalIsDefinedBorder as isDefinedBorder, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
|
|
7
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import BorderRadiusControl from '../border-radius-control';
|
|
14
|
+
import { useColorsPerOrigin } from './hooks';
|
|
15
|
+
import { getValueFromVariable } from './utils';
|
|
16
|
+
export function useHasBorderPanel(settings) {
|
|
17
|
+
const controls = [useHasBorderColorControl(settings), useHasBorderRadiusControl(settings), useHasBorderStyleControl(settings), useHasBorderWidthControl(settings)];
|
|
18
|
+
return controls.some(Boolean);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function useHasBorderColorControl(settings) {
|
|
22
|
+
var _settings$border;
|
|
23
|
+
|
|
24
|
+
return settings === null || settings === void 0 ? void 0 : (_settings$border = settings.border) === null || _settings$border === void 0 ? void 0 : _settings$border.color;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function useHasBorderRadiusControl(settings) {
|
|
28
|
+
var _settings$border2;
|
|
29
|
+
|
|
30
|
+
return settings === null || settings === void 0 ? void 0 : (_settings$border2 = settings.border) === null || _settings$border2 === void 0 ? void 0 : _settings$border2.radius;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useHasBorderStyleControl(settings) {
|
|
34
|
+
var _settings$border3;
|
|
35
|
+
|
|
36
|
+
return settings === null || settings === void 0 ? void 0 : (_settings$border3 = settings.border) === null || _settings$border3 === void 0 ? void 0 : _settings$border3.style;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function useHasBorderWidthControl(settings) {
|
|
40
|
+
var _settings$border4;
|
|
41
|
+
|
|
42
|
+
return settings === null || settings === void 0 ? void 0 : (_settings$border4 = settings.border) === null || _settings$border4 === void 0 ? void 0 : _settings$border4.width;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function applyFallbackStyle(border) {
|
|
46
|
+
if (!border) {
|
|
47
|
+
return border;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!border.style && (border.color || border.width)) {
|
|
51
|
+
return { ...border,
|
|
52
|
+
style: 'solid'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return border;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applyAllFallbackStyles(border) {
|
|
60
|
+
if (!border) {
|
|
61
|
+
return border;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (hasSplitBorders(border)) {
|
|
65
|
+
return {
|
|
66
|
+
top: applyFallbackStyle(border.top),
|
|
67
|
+
right: applyFallbackStyle(border.right),
|
|
68
|
+
bottom: applyFallbackStyle(border.bottom),
|
|
69
|
+
left: applyFallbackStyle(border.left)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return applyFallbackStyle(border);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function BorderToolsPanel(_ref) {
|
|
77
|
+
let {
|
|
78
|
+
resetAllFilter,
|
|
79
|
+
onChange,
|
|
80
|
+
value,
|
|
81
|
+
panelId,
|
|
82
|
+
children
|
|
83
|
+
} = _ref;
|
|
84
|
+
|
|
85
|
+
const resetAll = () => {
|
|
86
|
+
const updatedValue = resetAllFilter(value);
|
|
87
|
+
onChange(updatedValue);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return createElement(ToolsPanel, {
|
|
91
|
+
label: __('Border'),
|
|
92
|
+
resetAll: resetAll,
|
|
93
|
+
panelId: panelId
|
|
94
|
+
}, children);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const DEFAULT_CONTROLS = {
|
|
98
|
+
radius: true,
|
|
99
|
+
color: true,
|
|
100
|
+
width: true
|
|
101
|
+
};
|
|
102
|
+
export default function BorderPanel(_ref2) {
|
|
103
|
+
let {
|
|
104
|
+
as: Wrapper = BorderToolsPanel,
|
|
105
|
+
value,
|
|
106
|
+
onChange,
|
|
107
|
+
inheritedValue = value,
|
|
108
|
+
settings,
|
|
109
|
+
panelId,
|
|
110
|
+
defaultControls = DEFAULT_CONTROLS
|
|
111
|
+
} = _ref2;
|
|
112
|
+
const colors = useColorsPerOrigin(settings);
|
|
113
|
+
|
|
114
|
+
const decodeValue = rawValue => getValueFromVariable({
|
|
115
|
+
settings
|
|
116
|
+
}, '', rawValue);
|
|
117
|
+
|
|
118
|
+
const encodeColorValue = colorValue => {
|
|
119
|
+
const allColors = colors.flatMap(_ref3 => {
|
|
120
|
+
let {
|
|
121
|
+
colors: originColors
|
|
122
|
+
} = _ref3;
|
|
123
|
+
return originColors;
|
|
124
|
+
});
|
|
125
|
+
const colorObject = allColors.find(_ref4 => {
|
|
126
|
+
let {
|
|
127
|
+
color
|
|
128
|
+
} = _ref4;
|
|
129
|
+
return color === colorValue;
|
|
130
|
+
});
|
|
131
|
+
return colorObject ? 'var:preset|color|' + colorObject.slug : colorValue;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const decodeColorValue = useCallback(colorValue => {
|
|
135
|
+
const allColors = colors.flatMap(_ref5 => {
|
|
136
|
+
let {
|
|
137
|
+
colors: originColors
|
|
138
|
+
} = _ref5;
|
|
139
|
+
return originColors;
|
|
140
|
+
});
|
|
141
|
+
const colorObject = allColors.find(_ref6 => {
|
|
142
|
+
let {
|
|
143
|
+
slug
|
|
144
|
+
} = _ref6;
|
|
145
|
+
return colorValue === 'var:preset|color|' + slug;
|
|
146
|
+
});
|
|
147
|
+
return colorObject ? colorObject.color : colorValue;
|
|
148
|
+
}, [colors]);
|
|
149
|
+
const border = useMemo(() => {
|
|
150
|
+
var _inheritedValue$borde, _inheritedValue$borde2;
|
|
151
|
+
|
|
152
|
+
if (hasSplitBorders(inheritedValue === null || inheritedValue === void 0 ? void 0 : inheritedValue.border)) {
|
|
153
|
+
const borderValue = { ...(inheritedValue === null || inheritedValue === void 0 ? void 0 : inheritedValue.border)
|
|
154
|
+
};
|
|
155
|
+
['top', 'right', 'bottom', 'left'].forEach(side => {
|
|
156
|
+
var _borderValue$side;
|
|
157
|
+
|
|
158
|
+
borderValue[side] = { ...borderValue[side],
|
|
159
|
+
color: decodeColorValue((_borderValue$side = borderValue[side]) === null || _borderValue$side === void 0 ? void 0 : _borderValue$side.color)
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
return borderValue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { ...(inheritedValue === null || inheritedValue === void 0 ? void 0 : inheritedValue.border),
|
|
166
|
+
color: inheritedValue !== null && inheritedValue !== void 0 && (_inheritedValue$borde = inheritedValue.border) !== null && _inheritedValue$borde !== void 0 && _inheritedValue$borde.color ? decodeColorValue(inheritedValue === null || inheritedValue === void 0 ? void 0 : (_inheritedValue$borde2 = inheritedValue.border) === null || _inheritedValue$borde2 === void 0 ? void 0 : _inheritedValue$borde2.color) : undefined
|
|
167
|
+
};
|
|
168
|
+
}, [inheritedValue === null || inheritedValue === void 0 ? void 0 : inheritedValue.border, decodeColorValue]);
|
|
169
|
+
|
|
170
|
+
const setBorder = newBorder => onChange({ ...value,
|
|
171
|
+
border: newBorder
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const showBorderColor = useHasBorderColorControl(settings);
|
|
175
|
+
const showBorderStyle = useHasBorderStyleControl(settings);
|
|
176
|
+
const showBorderWidth = useHasBorderWidthControl(settings); // Border radius.
|
|
177
|
+
|
|
178
|
+
const showBorderRadius = useHasBorderRadiusControl(settings);
|
|
179
|
+
const borderRadiusValues = decodeValue(border === null || border === void 0 ? void 0 : border.radius);
|
|
180
|
+
|
|
181
|
+
const setBorderRadius = newBorderRadius => setBorder({ ...border,
|
|
182
|
+
radius: newBorderRadius
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const hasBorderRadius = () => {
|
|
186
|
+
var _value$border;
|
|
187
|
+
|
|
188
|
+
const borderValues = value === null || value === void 0 ? void 0 : (_value$border = value.border) === null || _value$border === void 0 ? void 0 : _value$border.radius;
|
|
189
|
+
|
|
190
|
+
if (typeof borderValues === 'object') {
|
|
191
|
+
return Object.entries(borderValues).some(Boolean);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return !!borderValues;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const resetBorder = () => {
|
|
198
|
+
if (hasBorderRadius()) {
|
|
199
|
+
var _value$border2;
|
|
200
|
+
|
|
201
|
+
return setBorder({
|
|
202
|
+
radius: value === null || value === void 0 ? void 0 : (_value$border2 = value.border) === null || _value$border2 === void 0 ? void 0 : _value$border2.radius
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setBorder(undefined);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const onBorderChange = newBorder => {
|
|
210
|
+
// Ensure we have a visible border style when a border width or
|
|
211
|
+
// color is being selected.
|
|
212
|
+
const newBorderWithStyle = applyAllFallbackStyles(newBorder); // As we can't conditionally generate styles based on if other
|
|
213
|
+
// style properties have been set we need to force split border
|
|
214
|
+
// definitions for user set border styles. Border radius is derived
|
|
215
|
+
// from the same property i.e. `border.radius` if it is a string
|
|
216
|
+
// that is used. The longhand border radii styles are only generated
|
|
217
|
+
// if that property is an object.
|
|
218
|
+
//
|
|
219
|
+
// For borders (color, style, and width) those are all properties on
|
|
220
|
+
// the `border` style property. This means if the theme.json defined
|
|
221
|
+
// split borders and the user condenses them into a flat border or
|
|
222
|
+
// vice-versa we'd get both sets of styles which would conflict.
|
|
223
|
+
|
|
224
|
+
const updatedBorder = !hasSplitBorders(newBorderWithStyle) ? {
|
|
225
|
+
top: newBorderWithStyle,
|
|
226
|
+
right: newBorderWithStyle,
|
|
227
|
+
bottom: newBorderWithStyle,
|
|
228
|
+
left: newBorderWithStyle
|
|
229
|
+
} : {
|
|
230
|
+
color: null,
|
|
231
|
+
style: null,
|
|
232
|
+
width: null,
|
|
233
|
+
...newBorderWithStyle
|
|
234
|
+
};
|
|
235
|
+
['top', 'right', 'bottom', 'left'].forEach(side => {
|
|
236
|
+
var _updatedBorder$side;
|
|
237
|
+
|
|
238
|
+
updatedBorder[side] = { ...updatedBorder[side],
|
|
239
|
+
color: encodeColorValue((_updatedBorder$side = updatedBorder[side]) === null || _updatedBorder$side === void 0 ? void 0 : _updatedBorder$side.color)
|
|
240
|
+
};
|
|
241
|
+
}); // As radius is maintained separately to color, style, and width
|
|
242
|
+
// maintain its value. Undefined values here will be cleaned when
|
|
243
|
+
// global styles are saved.
|
|
244
|
+
|
|
245
|
+
setBorder({
|
|
246
|
+
radius: border === null || border === void 0 ? void 0 : border.radius,
|
|
247
|
+
...updatedBorder
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const resetAllFilter = useCallback(previousValue => {
|
|
252
|
+
return { ...previousValue,
|
|
253
|
+
border: undefined
|
|
254
|
+
};
|
|
255
|
+
}, []);
|
|
256
|
+
const showBorderByDefault = (defaultControls === null || defaultControls === void 0 ? void 0 : defaultControls.color) || (defaultControls === null || defaultControls === void 0 ? void 0 : defaultControls.width);
|
|
257
|
+
return createElement(Wrapper, {
|
|
258
|
+
resetAllFilter: resetAllFilter,
|
|
259
|
+
value: value,
|
|
260
|
+
onChange: onChange,
|
|
261
|
+
panelId: panelId
|
|
262
|
+
}, (showBorderWidth || showBorderColor) && createElement(ToolsPanelItem, {
|
|
263
|
+
hasValue: () => isDefinedBorder(value === null || value === void 0 ? void 0 : value.border),
|
|
264
|
+
label: __('Border'),
|
|
265
|
+
onDeselect: () => resetBorder(),
|
|
266
|
+
isShownByDefault: showBorderByDefault,
|
|
267
|
+
panelId: panelId
|
|
268
|
+
}, createElement(BorderBoxControl, {
|
|
269
|
+
colors: colors,
|
|
270
|
+
enableAlpha: true,
|
|
271
|
+
enableStyle: showBorderStyle,
|
|
272
|
+
onChange: onBorderChange,
|
|
273
|
+
popoverOffset: 40,
|
|
274
|
+
popoverPlacement: "left-start",
|
|
275
|
+
value: border,
|
|
276
|
+
__experimentalIsRenderedInSidebar: true,
|
|
277
|
+
size: '__unstable-large'
|
|
278
|
+
})), showBorderRadius && createElement(ToolsPanelItem, {
|
|
279
|
+
hasValue: hasBorderRadius,
|
|
280
|
+
label: __('Radius'),
|
|
281
|
+
onDeselect: () => setBorderRadius(undefined),
|
|
282
|
+
isShownByDefault: defaultControls.radius,
|
|
283
|
+
panelId: panelId
|
|
284
|
+
}, createElement(BorderRadiusControl, {
|
|
285
|
+
values: borderRadiusValues,
|
|
286
|
+
onChange: newValue => {
|
|
287
|
+
setBorderRadius(newValue || undefined);
|
|
288
|
+
}
|
|
289
|
+
})));
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=border-panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/border-panel.js"],"names":["__experimentalBorderBoxControl","BorderBoxControl","__experimentalHasSplitBorders","hasSplitBorders","__experimentalIsDefinedBorder","isDefinedBorder","__experimentalToolsPanel","ToolsPanel","__experimentalToolsPanelItem","ToolsPanelItem","useCallback","useMemo","__","BorderRadiusControl","useColorsPerOrigin","getValueFromVariable","useHasBorderPanel","settings","controls","useHasBorderColorControl","useHasBorderRadiusControl","useHasBorderStyleControl","useHasBorderWidthControl","some","Boolean","border","color","radius","style","width","applyFallbackStyle","applyAllFallbackStyles","top","right","bottom","left","BorderToolsPanel","resetAllFilter","onChange","value","panelId","children","resetAll","updatedValue","DEFAULT_CONTROLS","BorderPanel","as","Wrapper","inheritedValue","defaultControls","colors","decodeValue","rawValue","encodeColorValue","colorValue","allColors","flatMap","originColors","colorObject","find","slug","decodeColorValue","borderValue","forEach","side","undefined","setBorder","newBorder","showBorderColor","showBorderStyle","showBorderWidth","showBorderRadius","borderRadiusValues","setBorderRadius","newBorderRadius","hasBorderRadius","borderValues","Object","entries","resetBorder","onBorderChange","newBorderWithStyle","updatedBorder","previousValue","showBorderByDefault","newValue"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,8BAA8B,IAAIC,gBADnC,EAECC,6BAA6B,IAAIC,eAFlC,EAGCC,6BAA6B,IAAIC,eAHlC,EAICC,wBAAwB,IAAIC,UAJ7B,EAKCC,4BAA4B,IAAIC,cALjC,QAMO,uBANP;AAOA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,0BAAhC;AACA,SAASC,kBAAT,QAAmC,SAAnC;AACA,SAASC,oBAAT,QAAqC,SAArC;AAEA,OAAO,SAASC,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAMC,QAAQ,GAAG,CAChBC,wBAAwB,CAAEF,QAAF,CADR,EAEhBG,yBAAyB,CAAEH,QAAF,CAFT,EAGhBI,wBAAwB,CAAEJ,QAAF,CAHR,EAIhBK,wBAAwB,CAAEL,QAAF,CAJR,CAAjB;AAOA,SAAOC,QAAQ,CAACK,IAAT,CAAeC,OAAf,CAAP;AACA;;AAED,SAASL,wBAAT,CAAmCF,QAAnC,EAA8C;AAAA;;AAC7C,SAAOA,QAAP,aAAOA,QAAP,2CAAOA,QAAQ,CAAEQ,MAAjB,qDAAO,iBAAkBC,KAAzB;AACA;;AAED,SAASN,yBAAT,CAAoCH,QAApC,EAA+C;AAAA;;AAC9C,SAAOA,QAAP,aAAOA,QAAP,4CAAOA,QAAQ,CAAEQ,MAAjB,sDAAO,kBAAkBE,MAAzB;AACA;;AAED,SAASN,wBAAT,CAAmCJ,QAAnC,EAA8C;AAAA;;AAC7C,SAAOA,QAAP,aAAOA,QAAP,4CAAOA,QAAQ,CAAEQ,MAAjB,sDAAO,kBAAkBG,KAAzB;AACA;;AAED,SAASN,wBAAT,CAAmCL,QAAnC,EAA8C;AAAA;;AAC7C,SAAOA,QAAP,aAA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Z,MAAAA,eAAe,CAAEY,QAAQ,IAAIpB,SAAd,CAAf;AACA;AAJF,IAPD,CA5BF,CADD;AA8CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalBorderBoxControl as BorderBoxControl,\n\t__experimentalHasSplitBorders as hasSplitBorders,\n\t__experimentalIsDefinedBorder as isDefinedBorder,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BorderRadiusControl from '../border-radius-control';\nimport { useColorsPerOrigin } from './hooks';\nimport { getValueFromVariable } from './utils';\n\nexport function useHasBorderPanel( settings ) {\n\tconst controls = [\n\t\tuseHasBorderColorControl( settings ),\n\t\tuseHasBorderRadiusControl( settings ),\n\t\tuseHasBorderStyleControl( settings ),\n\t\tuseHasBorderWidthControl( settings ),\n\t];\n\n\treturn controls.some( Boolean );\n}\n\nfunction useHasBorderColorControl( settings ) {\n\treturn settings?.border?.color;\n}\n\nfunction useHasBorderRadiusControl( settings ) {\n\treturn settings?.border?.radius;\n}\n\nfunction useHasBorderStyleControl( settings ) {\n\treturn settings?.border?.style;\n}\n\nfunction useHasBorderWidthControl( settings ) {\n\treturn settings?.border?.width;\n}\n\nfunction applyFallbackStyle( border ) {\n\tif ( ! border ) {\n\t\treturn border;\n\t}\n\n\tif ( ! border.style && ( border.color || border.width ) ) {\n\t\treturn { ...border, style: 'solid' };\n\t}\n\n\treturn border;\n}\n\nfunction applyAllFallbackStyles( border ) {\n\tif ( ! border ) {\n\t\treturn border;\n\t}\n\n\tif ( hasSplitBorders( border ) ) {\n\t\treturn {\n\t\t\ttop: applyFallbackStyle( border.top ),\n\t\t\tright: applyFallbackStyle( border.right ),\n\t\t\tbottom: applyFallbackStyle( border.bottom ),\n\t\t\tleft: applyFallbackStyle( border.left ),\n\t\t};\n\t}\n\n\treturn applyFallbackStyle( border );\n}\n\nfunction BorderToolsPanel( {\n\tresetAllFilter,\n\tonChange,\n\tvalue,\n\tpanelId,\n\tchildren,\n} ) {\n\tconst resetAll = () => {\n\t\tconst updatedValue = resetAllFilter( value );\n\t\tonChange( updatedValue );\n\t};\n\n\treturn (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Border' ) }\n\t\t\tresetAll={ resetAll }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t{ children }\n\t\t</ToolsPanel>\n\t);\n}\n\nconst DEFAULT_CONTROLS = {\n\tradius: true,\n\tcolor: true,\n\twidth: true,\n};\n\nexport default function BorderPanel( {\n\tas: Wrapper = BorderToolsPanel,\n\tvalue,\n\tonChange,\n\tinheritedValue = value,\n\tsettings,\n\tpanelId,\n\tdefaultControls = DEFAULT_CONTROLS,\n} ) {\n\tconst colors = useColorsPerOrigin( settings );\n\tconst decodeValue = ( rawValue ) =>\n\t\tgetValueFromVariable( { settings }, '', rawValue );\n\tconst encodeColorValue = ( colorValue ) => {\n\t\tconst allColors = colors.flatMap(\n\t\t\t( { colors: originColors } ) => originColors\n\t\t);\n\t\tconst colorObject = allColors.find(\n\t\t\t( { color } ) => color === colorValue\n\t\t);\n\t\treturn colorObject\n\t\t\t? 'var:preset|color|' + colorObject.slug\n\t\t\t: colorValue;\n\t};\n\tconst decodeColorValue = useCallback(\n\t\t( colorValue ) => {\n\t\t\tconst allColors = colors.flatMap(\n\t\t\t\t( { colors: originColors } ) => originColors\n\t\t\t);\n\t\t\tconst colorObject = allColors.find(\n\t\t\t\t( { slug } ) => colorValue === 'var:preset|color|' + slug\n\t\t\t);\n\t\t\treturn colorObject ? colorObject.color : colorValue;\n\t\t},\n\t\t[ colors ]\n\t);\n\tconst border = useMemo( () => {\n\t\tif ( hasSplitBorders( inheritedValue?.border ) ) {\n\t\t\tconst borderValue = { ...inheritedValue?.border };\n\t\t\t[ 'top', 'right', 'bottom', 'left' ].forEach( ( side ) => {\n\t\t\t\tborderValue[ side ] = {\n\t\t\t\t\t...borderValue[ side ],\n\t\t\t\t\tcolor: decodeColorValue( borderValue[ side ]?.color ),\n\t\t\t\t};\n\t\t\t} );\n\t\t\treturn borderValue;\n\t\t}\n\t\treturn {\n\t\t\t...inheritedValue?.border,\n\t\t\tcolor: inheritedValue?.border?.color\n\t\t\t\t? decodeColorValue( inheritedValue?.border?.color )\n\t\t\t\t: undefined,\n\t\t};\n\t}, [ inheritedValue?.border, decodeColorValue ] );\n\tconst setBorder = ( newBorder ) =>\n\t\tonChange( { ...value, border: newBorder } );\n\tconst showBorderColor = useHasBorderColorControl( settings );\n\tconst showBorderStyle = useHasBorderStyleControl( settings );\n\tconst showBorderWidth = useHasBorderWidthControl( settings );\n\n\t// Border radius.\n\tconst showBorderRadius = useHasBorderRadiusControl( settings );\n\tconst borderRadiusValues = decodeValue( border?.radius );\n\tconst setBorderRadius = ( newBorderRadius ) =>\n\t\tsetBorder( { ...border, radius: newBorderRadius } );\n\tconst hasBorderRadius = () => {\n\t\tconst borderValues = value?.border?.radius;\n\t\tif ( typeof borderValues === 'object' ) {\n\t\t\treturn Object.entries( borderValues ).some( Boolean );\n\t\t}\n\t\treturn !! borderValues;\n\t};\n\n\tconst resetBorder = () => {\n\t\tif ( hasBorderRadius() ) {\n\t\t\treturn setBorder( { radius: value?.border?.radius } );\n\t\t}\n\n\t\tsetBorder( undefined );\n\t};\n\n\tconst onBorderChange = ( newBorder ) => {\n\t\t// Ensure we have a visible border style when a border width or\n\t\t// color is being selected.\n\t\tconst newBorderWithStyle = applyAllFallbackStyles( newBorder );\n\n\t\t// As we can't conditionally generate styles based on if other\n\t\t// style properties have been set we need to force split border\n\t\t// definitions for user set border styles. Border radius is derived\n\t\t// from the same property i.e. `border.radius` if it is a string\n\t\t// that is used. The longhand border radii styles are only generated\n\t\t// if that property is an object.\n\t\t//\n\t\t// For borders (color, style, and width) those are all properties on\n\t\t// the `border` style property. This means if the theme.json defined\n\t\t// split borders and the user condenses them into a flat border or\n\t\t// vice-versa we'd get both sets of styles which would conflict.\n\t\tconst updatedBorder = ! hasSplitBorders( newBorderWithStyle )\n\t\t\t? {\n\t\t\t\t\ttop: newBorderWithStyle,\n\t\t\t\t\tright: newBorderWithStyle,\n\t\t\t\t\tbottom: newBorderWithStyle,\n\t\t\t\t\tleft: newBorderWithStyle,\n\t\t\t }\n\t\t\t: {\n\t\t\t\t\tcolor: null,\n\t\t\t\t\tstyle: null,\n\t\t\t\t\twidth: null,\n\t\t\t\t\t...newBorderWithStyle,\n\t\t\t };\n\n\t\t[ 'top', 'right', 'bottom', 'left' ].forEach( ( side ) => {\n\t\t\tupdatedBorder[ side ] = {\n\t\t\t\t...updatedBorder[ side ],\n\t\t\t\tcolor: encodeColorValue( updatedBorder[ side ]?.color ),\n\t\t\t};\n\t\t} );\n\n\t\t// As radius is maintained separately to color, style, and width\n\t\t// maintain its value. Undefined values here will be cleaned when\n\t\t// global styles are saved.\n\t\tsetBorder( { radius: border?.radius, ...updatedBorder } );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tborder: undefined,\n\t\t};\n\t}, [] );\n\n\tconst showBorderByDefault =\n\t\tdefaultControls?.color || defaultControls?.width;\n\n\treturn (\n\t\t<Wrapper\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t{ ( showBorderWidth || showBorderColor ) && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ () => isDefinedBorder( value?.border ) }\n\t\t\t\t\tlabel={ __( 'Border' ) }\n\t\t\t\t\tonDeselect={ () => resetBorder() }\n\t\t\t\t\tisShownByDefault={ showBorderByDefault }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<BorderBoxControl\n\t\t\t\t\t\tcolors={ colors }\n\t\t\t\t\t\tenableAlpha={ true }\n\t\t\t\t\t\tenableStyle={ showBorderStyle }\n\t\t\t\t\t\tonChange={ onBorderChange }\n\t\t\t\t\t\tpopoverOffset={ 40 }\n\t\t\t\t\t\tpopoverPlacement=\"left-start\"\n\t\t\t\t\t\tvalue={ border }\n\t\t\t\t\t\t__experimentalIsRenderedInSidebar={ true }\n\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ showBorderRadius && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\thasValue={ hasBorderRadius }\n\t\t\t\t\tlabel={ __( 'Radius' ) }\n\t\t\t\t\tonDeselect={ () => setBorderRadius( undefined ) }\n\t\t\t\t\tisShownByDefault={ defaultControls.radius }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<BorderRadiusControl\n\t\t\t\t\t\tvalues={ borderRadiusValues }\n\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\tsetBorderRadius( newValue || undefined );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</ToolsPanelItem>\n\t\t\t) }\n\t\t</Wrapper>\n\t);\n}\n"]}
|
|
@@ -10,6 +10,7 @@ import { get, set } from 'lodash';
|
|
|
10
10
|
import { useContext, useCallback, useMemo } from '@wordpress/element';
|
|
11
11
|
import { useSelect } from '@wordpress/data';
|
|
12
12
|
import { store as blocksStore } from '@wordpress/blocks';
|
|
13
|
+
import { _x } from '@wordpress/i18n';
|
|
13
14
|
/**
|
|
14
15
|
* Internal dependencies
|
|
15
16
|
*/
|
|
@@ -21,7 +22,7 @@ const EMPTY_CONFIG = {
|
|
|
21
22
|
settings: {},
|
|
22
23
|
styles: {}
|
|
23
24
|
};
|
|
24
|
-
const VALID_SETTINGS = ['appearanceTools', 'useRootPaddingAwareAlignments', 'border.color', 'border.radius', 'border.style', 'border.width', 'shadow.presets', 'shadow.defaultPresets', 'color.background', 'color.custom', 'color.customDuotone', 'color.customGradient', 'color.defaultDuotone', 'color.defaultGradients', 'color.defaultPalette', 'color.duotone', 'color.gradients', 'color.link', 'color.palette', 'color.text', 'custom', 'dimensions.minHeight', 'layout.contentSize', 'layout.definitions', 'layout.wideSize', 'position.fixed', 'position.sticky', 'spacing.customSpacingSize', 'spacing.spacingSizes', 'spacing.spacingScale', 'spacing.blockGap', 'spacing.margin', 'spacing.padding', 'spacing.units', 'typography.fluid', 'typography.customFontSize', 'typography.dropCap', 'typography.fontFamilies', 'typography.fontSizes', 'typography.fontStyle', 'typography.fontWeight', 'typography.letterSpacing', 'typography.lineHeight', 'typography.textDecoration', 'typography.textTransform'];
|
|
25
|
+
const VALID_SETTINGS = ['appearanceTools', 'useRootPaddingAwareAlignments', 'border.color', 'border.radius', 'border.style', 'border.width', 'shadow.presets', 'shadow.defaultPresets', 'color.background', 'color.custom', 'color.customDuotone', 'color.customGradient', 'color.defaultDuotone', 'color.defaultGradients', 'color.defaultPalette', 'color.duotone', 'color.gradients', 'color.link', 'color.palette', 'color.text', 'custom', 'dimensions.minHeight', 'layout.contentSize', 'layout.definitions', 'layout.wideSize', 'position.fixed', 'position.sticky', 'spacing.customSpacingSize', 'spacing.spacingSizes', 'spacing.spacingScale', 'spacing.blockGap', 'spacing.margin', 'spacing.padding', 'spacing.units', 'typography.fluid', 'typography.customFontSize', 'typography.dropCap', 'typography.fontFamilies', 'typography.fontSizes', 'typography.fontStyle', 'typography.fontWeight', 'typography.letterSpacing', 'typography.lineHeight', 'typography.textColumns', 'typography.textDecoration', 'typography.textTransform'];
|
|
25
26
|
export const useGlobalStylesReset = () => {
|
|
26
27
|
const {
|
|
27
28
|
user: config,
|
|
@@ -105,7 +106,7 @@ export function useGlobalStyle(path, blockName) {
|
|
|
105
106
|
|
|
106
107
|
switch (source) {
|
|
107
108
|
case 'all':
|
|
108
|
-
rawResult = // The
|
|
109
|
+
rawResult = // The styles.css path is allowed to be empty, so don't revert to base if undefined.
|
|
109
110
|
finalPath === 'styles.css' ? get(userConfig, finalPath) : get(mergedConfig, finalPath);
|
|
110
111
|
result = shouldDecodeEncode ? getValueFromVariable(mergedConfig, blockName, rawResult) : rawResult;
|
|
111
112
|
break;
|
|
@@ -171,7 +172,16 @@ export function useSettingsForBlockElement(parentSettings, blockName, element) {
|
|
|
171
172
|
[key]: false
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
|
-
});
|
|
175
|
+
}); // The column-count style is named text column to reduce confusion with
|
|
176
|
+
// the columns block and manage expectations from the support.
|
|
177
|
+
// See: https://github.com/WordPress/gutenberg/pull/33587
|
|
178
|
+
|
|
179
|
+
if (!supportedStyles.includes('columnCount')) {
|
|
180
|
+
updatedSettings.typography = { ...updatedSettings.typography,
|
|
181
|
+
textColumns: false
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
175
185
|
['contentSize', 'wideSize'].forEach(key => {
|
|
176
186
|
if (!supportedStyles.includes(key)) {
|
|
177
187
|
updatedSettings.layout = { ...updatedSettings.layout,
|
|
@@ -207,7 +217,48 @@ export function useSettingsForBlockElement(parentSettings, blockName, element) {
|
|
|
207
217
|
};
|
|
208
218
|
}
|
|
209
219
|
|
|
220
|
+
['radius', 'color', 'style', 'width'].forEach(key => {
|
|
221
|
+
if (!supportedStyles.includes('border' + key.charAt(0).toUpperCase() + key.slice(1))) {
|
|
222
|
+
updatedSettings.border = { ...updatedSettings.border,
|
|
223
|
+
[key]: false
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
});
|
|
210
227
|
return updatedSettings;
|
|
211
228
|
}, [parentSettings, supportedStyles, supports]);
|
|
212
229
|
}
|
|
230
|
+
export function useColorsPerOrigin(settings) {
|
|
231
|
+
var _settings$color, _settings$color$palet, _settings$color2, _settings$color2$pale, _settings$color3, _settings$color3$pale, _settings$color4;
|
|
232
|
+
|
|
233
|
+
const customColors = settings === null || settings === void 0 ? void 0 : (_settings$color = settings.color) === null || _settings$color === void 0 ? void 0 : (_settings$color$palet = _settings$color.palette) === null || _settings$color$palet === void 0 ? void 0 : _settings$color$palet.custom;
|
|
234
|
+
const themeColors = settings === null || settings === void 0 ? void 0 : (_settings$color2 = settings.color) === null || _settings$color2 === void 0 ? void 0 : (_settings$color2$pale = _settings$color2.palette) === null || _settings$color2$pale === void 0 ? void 0 : _settings$color2$pale.theme;
|
|
235
|
+
const defaultColors = settings === null || settings === void 0 ? void 0 : (_settings$color3 = settings.color) === null || _settings$color3 === void 0 ? void 0 : (_settings$color3$pale = _settings$color3.palette) === null || _settings$color3$pale === void 0 ? void 0 : _settings$color3$pale.default;
|
|
236
|
+
const shouldDisplayDefaultColors = settings === null || settings === void 0 ? void 0 : (_settings$color4 = settings.color) === null || _settings$color4 === void 0 ? void 0 : _settings$color4.defaultPalette;
|
|
237
|
+
return useMemo(() => {
|
|
238
|
+
const result = [];
|
|
239
|
+
|
|
240
|
+
if (themeColors && themeColors.length) {
|
|
241
|
+
result.push({
|
|
242
|
+
name: _x('Theme', 'Indicates this palette comes from the theme.'),
|
|
243
|
+
colors: themeColors
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (shouldDisplayDefaultColors && defaultColors && defaultColors.length) {
|
|
248
|
+
result.push({
|
|
249
|
+
name: _x('Default', 'Indicates this palette comes from WordPress.'),
|
|
250
|
+
colors: defaultColors
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (customColors && customColors.length) {
|
|
255
|
+
result.push({
|
|
256
|
+
name: _x('Custom', 'Indicates this palette is created by the user.'),
|
|
257
|
+
colors: customColors
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return result;
|
|
262
|
+
}, [customColors, themeColors, defaultColors, shouldDisplayDefaultColors]);
|
|
263
|
+
}
|
|
213
264
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/hooks.js"],"names":["fastDeepEqual","get","set","useContext","useCallback","useMemo","useSelect","store","blocksStore","getValueFromVariable","getPresetVariableFromValue","GlobalStylesContext","unlock","EMPTY_CONFIG","settings","styles","VALID_SETTINGS","useGlobalStylesReset","user","config","setUserConfig","canReset","useGlobalSetting","propertyPath","blockName","source","configs","appendedBlockPath","appendedPropertyPath","contextualPath","globalPath","sourceKey","settingValue","configToUse","result","forEach","setting","value","setSetting","newValue","currentConfig","newUserConfig","JSON","parse","stringify","useGlobalStyle","path","shouldDecodeEncode","merged","mergedConfig","base","baseConfig","userConfig","appendedPath","finalPath","setStyle","rawResult","useSettingsForBlockElement","parentSettings","element","supportedStyles","supports","select","getSupportedStyles","getBlockType","updatedSettings","includes","typography","fontSizes","customFontSize","fontFamilies","key","layout","spacing","sides","Array","isArray","length","dimensions","minHeight"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAP,MAA0B,qBAA1B;AACA,SAASC,GAAT,EAAcC,GAAd,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,EAAqBC,WAArB,EAAkCC,OAAlC,QAAiD,oBAAjD;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AAEA;AACA;AACA;;AACA,SAASC,oBAAT,EAA+BC,0BAA/B,QAAiE,SAAjE;AACA,SAASC,mBAAT,QAAoC,WAApC;AACA,SAASC,MAAT,QAAuB,mBAAvB;AAEA,MAAMC,YAAY,GAAG;AAAEC,EAAAA,QAAQ,EAAE,EAAZ;AAAgBC,EAAAA,MAAM,EAAE;AAAxB,CAArB;AAEA,MAAMC,cAAc,GAAG,CACtB,iBADsB,EAEtB,+BAFsB,EAGtB,cAHsB,EAItB,eAJsB,EAKtB,cALsB,EAMtB,cANsB,EAOtB,gBAPsB,EAQtB,uBARsB,EAStB,kBATsB,EAUtB,cAVsB,EAWtB,qBAXsB,EAYtB,sBAZsB,EAatB,sBAbsB,EActB,wBAdsB,EAetB,sBAfsB,EAgBt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AAEzB,WAAEF,GAAF,GAAS;AAFgB,SAA1B;AAIA;;AAED,YAAMG,KAAK,GAAGC,KAAK,CAACC,OAAN,CAAef,QAAf,aAAeA,QAAf,4CAAeA,QAAQ,CAAEY,OAAzB,sDAAe,kBAAqBF,GAArB,CAAf,IACXV,QADW,aACXA,QADW,6CACXA,QAAQ,CAAEY,OADC,uDACX,mBAAqBF,GAArB,CADW,GAEXV,QAFW,aAEXA,QAFW,6CAEXA,QAAQ,CAAEY,OAFC,gFAEX,mBAAqBF,GAArB,CAFW,0DAEX,sBAA4BG,KAF/B;;AAGA,UAAKA,KAAL,aAAKA,KAAL,eAAKA,KAAK,CAAEG,MAAZ,EAAqB;AAAA;;AACpBZ,QAAAA,eAAe,CAACQ,OAAhB,GAA0B,EACzB,GAAGR,eAAe,CAACQ,OADM;AAEzB,WAAEF,GAAF,GAAS,EACR,6BAAGN,eAAe,CAACQ,OAAnB,0DAAG,sBAA2BF,GAA3B,CAAH,CADQ;AAERG,YAAAA;AAFQ;AAFgB,SAA1B;AAOA;AACD,KApBD;;AAsBA,QAAK,CAAEd,eAAe,CAACM,QAAhB,CAA0B,WAA1B,CAAP,EAAiD;AAChDD,MAAAA,eAAe,CAACa,UAAhB,GAA6B,EAC5B,GAAGb,eAAe,CAACa,UADS;AAE5BC,QAAAA,SAAS,EAAE;AAFiB,OAA7B;AAIA;;AAED,WAAOd,eAAP;AACA,GAzEa,EAyEX,CAAEP,cAAF,EAAkBE,eAAlB,EAAmCC,QAAnC,CAzEW,CAAd;AA0EA","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { get, set } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { getValueFromVariable, getPresetVariableFromValue } from './utils';\nimport { GlobalStylesContext } from './context';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_CONFIG = { settings: {}, styles: {} };\n\nconst VALID_SETTINGS = [\n\t'appearanceTools',\n\t'useRootPaddingAwareAlignments',\n\t'border.color',\n\t'border.radius',\n\t'border.style',\n\t'border.width',\n\t'shadow.presets',\n\t'shadow.defaultPresets',\n\t'color.background',\n\t'color.custom',\n\t'color.customDuotone',\n\t'color.customGradient',\n\t'color.defaultDuotone',\n\t'color.defaultGradients',\n\t'color.defaultPalette',\n\t'color.duotone',\n\t'color.gradients',\n\t'color.link',\n\t'color.palette',\n\t'color.text',\n\t'custom',\n\t'dimensions.minHeight',\n\t'layout.contentSize',\n\t'layout.definitions',\n\t'layout.wideSize',\n\t'position.fixed',\n\t'position.sticky',\n\t'spacing.customSpacingSize',\n\t'spacing.spacingSizes',\n\t'spacing.spacingScale',\n\t'spacing.blockGap',\n\t'spacing.margin',\n\t'spacing.padding',\n\t'spacing.units',\n\t'typography.fluid',\n\t'typography.customFontSize',\n\t'typography.dropCap',\n\t'typography.fontFamilies',\n\t'typography.fontSizes',\n\t'typography.fontStyle',\n\t'typography.fontWeight',\n\t'typography.letterSpacing',\n\t'typography.lineHeight',\n\t'typography.textDecoration',\n\t'typography.textTransform',\n];\n\nexport const useGlobalStylesReset = () => {\n\tconst { user: config, setUserConfig } = useContext( GlobalStylesContext );\n\tconst canReset = !! config && ! fastDeepEqual( config, EMPTY_CONFIG );\n\treturn [\n\t\tcanReset,\n\t\tuseCallback(\n\t\t\t() => setUserConfig( () => EMPTY_CONFIG ),\n\t\t\t[ setUserConfig ]\n\t\t),\n\t];\n};\n\nexport function useGlobalSetting( propertyPath, blockName, source = 'all' ) {\n\tconst { setUserConfig, ...configs } = useContext( GlobalStylesContext );\n\n\tconst appendedBlockPath = blockName ? '.blocks.' + blockName : '';\n\tconst appendedPropertyPath = propertyPath ? '.' + propertyPath : '';\n\tconst contextualPath = `settings${ appendedBlockPath }${ appendedPropertyPath }`;\n\tconst globalPath = `settings${ appendedPropertyPath }`;\n\tconst sourceKey = source === 'all' ? 'merged' : source;\n\n\tconst settingValue = useMemo( () => {\n\t\tconst configToUse = configs[ sourceKey ];\n\t\tif ( ! configToUse ) {\n\t\t\tthrow 'Unsupported source';\n\t\t}\n\n\t\tif ( propertyPath ) {\n\t\t\treturn (\n\t\t\t\tget( configToUse, contextualPath ) ??\n\t\t\t\tget( configToUse, globalPath )\n\t\t\t);\n\t\t}\n\n\t\tconst result = {};\n\t\tVALID_SETTINGS.forEach( ( setting ) => {\n\t\t\tconst value =\n\t\t\t\tget(\n\t\t\t\t\tconfigToUse,\n\t\t\t\t\t`settings${ appendedBlockPath }.${ setting }`\n\t\t\t\t) ?? get( configToUse, `settings.${ setting }` );\n\t\t\tif ( value ) {\n\t\t\t\tset( result, setting, value );\n\t\t\t}\n\t\t} );\n\t\treturn result;\n\t}, [\n\t\tconfigs,\n\t\tsourceKey,\n\t\tpropertyPath,\n\t\tcontextualPath,\n\t\tglobalPath,\n\t\tappendedBlockPath,\n\t] );\n\n\tconst setSetting = ( newValue ) => {\n\t\tsetUserConfig( ( currentConfig ) => {\n\t\t\t// Deep clone `currentConfig` to avoid mutating it later.\n\t\t\tconst newUserConfig = JSON.parse( JSON.stringify( currentConfig ) );\n\t\t\tset( newUserConfig, contextualPath, newValue );\n\n\t\t\treturn newUserConfig;\n\t\t} );\n\t};\n\n\treturn [ settingValue, setSetting ];\n}\n\nexport function useGlobalStyle(\n\tpath,\n\tblockName,\n\tsource = 'all',\n\t{ shouldDecodeEncode = true } = {}\n) {\n\tconst {\n\t\tmerged: mergedConfig,\n\t\tbase: baseConfig,\n\t\tuser: userConfig,\n\t\tsetUserConfig,\n\t} = useContext( GlobalStylesContext );\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\n\tconst setStyle = ( newValue ) => {\n\t\tsetUserConfig( ( currentConfig ) => {\n\t\t\t// Deep clone `currentConfig` to avoid mutating it later.\n\t\t\tconst newUserConfig = JSON.parse( JSON.stringify( currentConfig ) );\n\t\t\tset(\n\t\t\t\tnewUserConfig,\n\t\t\t\tfinalPath,\n\t\t\t\tshouldDecodeEncode\n\t\t\t\t\t? getPresetVariableFromValue(\n\t\t\t\t\t\t\tmergedConfig.settings,\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tnewValue\n\t\t\t\t\t )\n\t\t\t\t\t: newValue\n\t\t\t);\n\t\t\treturn newUserConfig;\n\t\t} );\n\t};\n\n\tlet rawResult, result;\n\tswitch ( source ) {\n\t\tcase 'all':\n\t\t\trawResult =\n\t\t\t\t// The stlyes.css path is allowed to be empty, so don't revert to base if undefined.\n\t\t\t\tfinalPath === 'styles.css'\n\t\t\t\t\t? get( userConfig, finalPath )\n\t\t\t\t\t: get( mergedConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( mergedConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tcase 'user':\n\t\t\trawResult = get( userConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( mergedConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tcase 'base':\n\t\t\trawResult = get( baseConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( baseConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow 'Unsupported source';\n\t}\n\n\treturn [ result, setStyle ];\n}\n\n/**\n * React hook that overrides a global settings object with block and element specific settings.\n *\n * @param {Object} parentSettings Settings object.\n * @param {blockName?} blockName Block name.\n * @param {element?} element Element name.\n *\n * @return {Object} Merge of settings and supports.\n */\nexport function useSettingsForBlockElement(\n\tparentSettings,\n\tblockName,\n\telement\n) {\n\tconst { supportedStyles, supports } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\tsupportedStyles: unlock(\n\t\t\t\t\tselect( blocksStore )\n\t\t\t\t).getSupportedStyles( blockName, element ),\n\t\t\t\tsupports:\n\t\t\t\t\tselect( blocksStore ).getBlockType( blockName )?.supports,\n\t\t\t};\n\t\t},\n\t\t[ blockName, element ]\n\t);\n\n\treturn useMemo( () => {\n\t\tconst updatedSettings = { ...parentSettings };\n\n\t\tif ( ! supportedStyles.includes( 'fontSize' ) ) {\n\t\t\tupdatedSettings.typography = {\n\t\t\t\t...updatedSettings.typography,\n\t\t\t\tfontSizes: {},\n\t\t\t\tcustomFontSize: false,\n\t\t\t};\n\t\t}\n\n\t\tif ( ! supportedStyles.includes( 'fontFamily' ) ) {\n\t\t\tupdatedSettings.typography = {\n\t\t\t\t...updatedSettings.typography,\n\t\t\t\tfontFamilies: {},\n\t\t\t};\n\t\t}\n\n\t\t[\n\t\t\t'lineHeight',\n\t\t\t'fontStyle',\n\t\t\t'fontWeight',\n\t\t\t'letterSpacing',\n\t\t\t'textTransform',\n\t\t\t'textDecoration',\n\t\t].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.typography = {\n\t\t\t\t\t...updatedSettings.typography,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\t[ 'contentSize', 'wideSize' ].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.layout = {\n\t\t\t\t\t...updatedSettings.layout,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\t[ 'padding', 'margin', 'blockGap' ].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.spacing = {\n\t\t\t\t\t...updatedSettings.spacing,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst sides = Array.isArray( supports?.spacing?.[ key ] )\n\t\t\t\t? supports?.spacing?.[ key ]\n\t\t\t\t: supports?.spacing?.[ key ]?.sides;\n\t\t\tif ( sides?.length ) {\n\t\t\t\tupdatedSettings.spacing = {\n\t\t\t\t\t...updatedSettings.spacing,\n\t\t\t\t\t[ key ]: {\n\t\t\t\t\t\t...updatedSettings.spacing?.[ key ],\n\t\t\t\t\t\tsides,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\tif ( ! supportedStyles.includes( 'minHeight' ) ) {\n\t\t\tupdatedSettings.dimensions = {\n\t\t\t\t...updatedSettings.dimensions,\n\t\t\t\tminHeight: false,\n\t\t\t};\n\t\t}\n\n\t\treturn updatedSettings;\n\t}, [ parentSettings, supportedStyles, supports ] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/hooks.js"],"names":["fastDeepEqual","get","set","useContext","useCallback","useMemo","useSelect","store","blocksStore","_x","getValueFromVariable","getPresetVariableFromValue","GlobalStylesContext","unlock","EMPTY_CONFIG","settings","styles","VALID_SETTINGS","useGlobalStylesReset","user","config","setUserConfig","canReset","useGlobalSetting","propertyPath","blockName","source","configs","appendedBlockPath","appendedPropertyPath","contextualPath","globalPath","sourceKey","settingValue","configToUse","result","forEach","setting","value","setSetting","newValue","currentConfig","newUserConfig","JSON","parse","stringify","useGlobalStyle","path","shouldDecodeEncode","merged","mergedConfig","base","baseConfig","userConfig","appendedPath","finalPath","setStyle","rawResult","useSettingsForBlockElement","parentSettings","element","supportedStyles","supports","select","getSupportedStyles","getBlockType","updatedSettings","includes","typography","fontSizes","customFontSize","fontFamilies","key","textColumns","layout","spacing","sides","Array","isArray","length","dimensions","minHeight","charAt","toUpperCase","slice","border","useColorsPerOrigin","customColors","color","palette","custom","themeColors","theme","defaultColors","default","shouldDisplayDefaultColors","defaultPalette","push","name","colors"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAP,MAA0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QAAMC,WAAW,GAAG5E,QAAH,aAAGA,QAAH,2CAAGA,QAAQ,CAAEyE,KAAb,8EAAG,iBAAiBC,OAApB,0DAAG,sBAA0BG,KAA9C;AACA,QAAMC,aAAa,GAAG9E,QAAH,aAAGA,QAAH,2CAAGA,QAAQ,CAAEyE,KAAb,8EAAG,iBAAiBC,OAApB,0DAAG,sBAA0BK,OAAhD;AACA,QAAMC,0BAA0B,GAAGhF,QAAH,aAAGA,QAAH,2CAAGA,QAAQ,CAAEyE,KAAb,qDAAG,iBAAiBQ,cAApD;AAEA,SAAO3F,OAAO,CAAE,MAAM;AACrB,UAAM8B,MAAM,GAAG,EAAf;;AACA,QAAKwD,WAAW,IAAIA,WAAW,CAACZ,MAAhC,EAAyC;AACxC5C,MAAAA,MAAM,CAAC8D,IAAP,CAAa;AACZC,QAAAA,IAAI,EAAEzF,EAAE,CACP,OADO,EAEP,8CAFO,CADI;AAKZ0F,QAAAA,MAAM,EAAER;AALI,OAAb;AAOA;;AACD,QACCI,0BAA0B,IAC1BF,aADA,IAEAA,aAAa,CAACd,MAHf,EAIE;AACD5C,MAAAA,MAAM,CAAC8D,IAAP,CAAa;AACZC,QAAAA,IAAI,EAAEzF,EAAE,CACP,SADO,EAEP,8CAFO,CADI;AAKZ0F,QAAAA,MAAM,EAAEN;AALI,OAAb;AAOA;;AACD,QAAKN,YAAY,IAAIA,YAAY,CAACR,MAAlC,EAA2C;AAC1C5C,MAAAA,MAAM,CAAC8D,IAAP,CAAa;AACZC,QAAAA,IAAI,EAAEzF,EAAE,CACP,QADO,EAEP,gDAFO,CADI;AAKZ0F,QAAAA,MAAM,EAAEZ;AALI,OAAb;AAOA;;AACD,WAAOpD,MAAP;AACA,GAlCa,EAkCX,CACFoD,YADE,EAEFI,WAFE,EAGFE,aAHE,EAIFE,0BAJE,CAlCW,CAAd;AAwCA","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { get, set } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getValueFromVariable, getPresetVariableFromValue } from './utils';\nimport { GlobalStylesContext } from './context';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_CONFIG = { settings: {}, styles: {} };\n\nconst VALID_SETTINGS = [\n\t'appearanceTools',\n\t'useRootPaddingAwareAlignments',\n\t'border.color',\n\t'border.radius',\n\t'border.style',\n\t'border.width',\n\t'shadow.presets',\n\t'shadow.defaultPresets',\n\t'color.background',\n\t'color.custom',\n\t'color.customDuotone',\n\t'color.customGradient',\n\t'color.defaultDuotone',\n\t'color.defaultGradients',\n\t'color.defaultPalette',\n\t'color.duotone',\n\t'color.gradients',\n\t'color.link',\n\t'color.palette',\n\t'color.text',\n\t'custom',\n\t'dimensions.minHeight',\n\t'layout.contentSize',\n\t'layout.definitions',\n\t'layout.wideSize',\n\t'position.fixed',\n\t'position.sticky',\n\t'spacing.customSpacingSize',\n\t'spacing.spacingSizes',\n\t'spacing.spacingScale',\n\t'spacing.blockGap',\n\t'spacing.margin',\n\t'spacing.padding',\n\t'spacing.units',\n\t'typography.fluid',\n\t'typography.customFontSize',\n\t'typography.dropCap',\n\t'typography.fontFamilies',\n\t'typography.fontSizes',\n\t'typography.fontStyle',\n\t'typography.fontWeight',\n\t'typography.letterSpacing',\n\t'typography.lineHeight',\n\t'typography.textColumns',\n\t'typography.textDecoration',\n\t'typography.textTransform',\n];\n\nexport const useGlobalStylesReset = () => {\n\tconst { user: config, setUserConfig } = useContext( GlobalStylesContext );\n\tconst canReset = !! config && ! fastDeepEqual( config, EMPTY_CONFIG );\n\treturn [\n\t\tcanReset,\n\t\tuseCallback(\n\t\t\t() => setUserConfig( () => EMPTY_CONFIG ),\n\t\t\t[ setUserConfig ]\n\t\t),\n\t];\n};\n\nexport function useGlobalSetting( propertyPath, blockName, source = 'all' ) {\n\tconst { setUserConfig, ...configs } = useContext( GlobalStylesContext );\n\n\tconst appendedBlockPath = blockName ? '.blocks.' + blockName : '';\n\tconst appendedPropertyPath = propertyPath ? '.' + propertyPath : '';\n\tconst contextualPath = `settings${ appendedBlockPath }${ appendedPropertyPath }`;\n\tconst globalPath = `settings${ appendedPropertyPath }`;\n\tconst sourceKey = source === 'all' ? 'merged' : source;\n\n\tconst settingValue = useMemo( () => {\n\t\tconst configToUse = configs[ sourceKey ];\n\t\tif ( ! configToUse ) {\n\t\t\tthrow 'Unsupported source';\n\t\t}\n\n\t\tif ( propertyPath ) {\n\t\t\treturn (\n\t\t\t\tget( configToUse, contextualPath ) ??\n\t\t\t\tget( configToUse, globalPath )\n\t\t\t);\n\t\t}\n\n\t\tconst result = {};\n\t\tVALID_SETTINGS.forEach( ( setting ) => {\n\t\t\tconst value =\n\t\t\t\tget(\n\t\t\t\t\tconfigToUse,\n\t\t\t\t\t`settings${ appendedBlockPath }.${ setting }`\n\t\t\t\t) ?? get( configToUse, `settings.${ setting }` );\n\t\t\tif ( value ) {\n\t\t\t\tset( result, setting, value );\n\t\t\t}\n\t\t} );\n\t\treturn result;\n\t}, [\n\t\tconfigs,\n\t\tsourceKey,\n\t\tpropertyPath,\n\t\tcontextualPath,\n\t\tglobalPath,\n\t\tappendedBlockPath,\n\t] );\n\n\tconst setSetting = ( newValue ) => {\n\t\tsetUserConfig( ( currentConfig ) => {\n\t\t\t// Deep clone `currentConfig` to avoid mutating it later.\n\t\t\tconst newUserConfig = JSON.parse( JSON.stringify( currentConfig ) );\n\t\t\tset( newUserConfig, contextualPath, newValue );\n\n\t\t\treturn newUserConfig;\n\t\t} );\n\t};\n\n\treturn [ settingValue, setSetting ];\n}\n\nexport function useGlobalStyle(\n\tpath,\n\tblockName,\n\tsource = 'all',\n\t{ shouldDecodeEncode = true } = {}\n) {\n\tconst {\n\t\tmerged: mergedConfig,\n\t\tbase: baseConfig,\n\t\tuser: userConfig,\n\t\tsetUserConfig,\n\t} = useContext( GlobalStylesContext );\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\n\tconst setStyle = ( newValue ) => {\n\t\tsetUserConfig( ( currentConfig ) => {\n\t\t\t// Deep clone `currentConfig` to avoid mutating it later.\n\t\t\tconst newUserConfig = JSON.parse( JSON.stringify( currentConfig ) );\n\t\t\tset(\n\t\t\t\tnewUserConfig,\n\t\t\t\tfinalPath,\n\t\t\t\tshouldDecodeEncode\n\t\t\t\t\t? getPresetVariableFromValue(\n\t\t\t\t\t\t\tmergedConfig.settings,\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tnewValue\n\t\t\t\t\t )\n\t\t\t\t\t: newValue\n\t\t\t);\n\t\t\treturn newUserConfig;\n\t\t} );\n\t};\n\n\tlet rawResult, result;\n\tswitch ( source ) {\n\t\tcase 'all':\n\t\t\trawResult =\n\t\t\t\t// The styles.css path is allowed to be empty, so don't revert to base if undefined.\n\t\t\t\tfinalPath === 'styles.css'\n\t\t\t\t\t? get( userConfig, finalPath )\n\t\t\t\t\t: get( mergedConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( mergedConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tcase 'user':\n\t\t\trawResult = get( userConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( mergedConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tcase 'base':\n\t\t\trawResult = get( baseConfig, finalPath );\n\t\t\tresult = shouldDecodeEncode\n\t\t\t\t? getValueFromVariable( baseConfig, blockName, rawResult )\n\t\t\t\t: rawResult;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow 'Unsupported source';\n\t}\n\n\treturn [ result, setStyle ];\n}\n\n/**\n * React hook that overrides a global settings object with block and element specific settings.\n *\n * @param {Object} parentSettings Settings object.\n * @param {blockName?} blockName Block name.\n * @param {element?} element Element name.\n *\n * @return {Object} Merge of settings and supports.\n */\nexport function useSettingsForBlockElement(\n\tparentSettings,\n\tblockName,\n\telement\n) {\n\tconst { supportedStyles, supports } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\tsupportedStyles: unlock(\n\t\t\t\t\tselect( blocksStore )\n\t\t\t\t).getSupportedStyles( blockName, element ),\n\t\t\t\tsupports:\n\t\t\t\t\tselect( blocksStore ).getBlockType( blockName )?.supports,\n\t\t\t};\n\t\t},\n\t\t[ blockName, element ]\n\t);\n\n\treturn useMemo( () => {\n\t\tconst updatedSettings = { ...parentSettings };\n\n\t\tif ( ! supportedStyles.includes( 'fontSize' ) ) {\n\t\t\tupdatedSettings.typography = {\n\t\t\t\t...updatedSettings.typography,\n\t\t\t\tfontSizes: {},\n\t\t\t\tcustomFontSize: false,\n\t\t\t};\n\t\t}\n\n\t\tif ( ! supportedStyles.includes( 'fontFamily' ) ) {\n\t\t\tupdatedSettings.typography = {\n\t\t\t\t...updatedSettings.typography,\n\t\t\t\tfontFamilies: {},\n\t\t\t};\n\t\t}\n\n\t\t[\n\t\t\t'lineHeight',\n\t\t\t'fontStyle',\n\t\t\t'fontWeight',\n\t\t\t'letterSpacing',\n\t\t\t'textTransform',\n\t\t\t'textDecoration',\n\t\t].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.typography = {\n\t\t\t\t\t...updatedSettings.typography,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\t// The column-count style is named text column to reduce confusion with\n\t\t// the columns block and manage expectations from the support.\n\t\t// See: https://github.com/WordPress/gutenberg/pull/33587\n\t\tif ( ! supportedStyles.includes( 'columnCount' ) ) {\n\t\t\tupdatedSettings.typography = {\n\t\t\t\t...updatedSettings.typography,\n\t\t\t\ttextColumns: false,\n\t\t\t};\n\t\t}\n\n\t\t[ 'contentSize', 'wideSize' ].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.layout = {\n\t\t\t\t\t...updatedSettings.layout,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\t[ 'padding', 'margin', 'blockGap' ].forEach( ( key ) => {\n\t\t\tif ( ! supportedStyles.includes( key ) ) {\n\t\t\t\tupdatedSettings.spacing = {\n\t\t\t\t\t...updatedSettings.spacing,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst sides = Array.isArray( supports?.spacing?.[ key ] )\n\t\t\t\t? supports?.spacing?.[ key ]\n\t\t\t\t: supports?.spacing?.[ key ]?.sides;\n\t\t\tif ( sides?.length ) {\n\t\t\t\tupdatedSettings.spacing = {\n\t\t\t\t\t...updatedSettings.spacing,\n\t\t\t\t\t[ key ]: {\n\t\t\t\t\t\t...updatedSettings.spacing?.[ key ],\n\t\t\t\t\t\tsides,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\tif ( ! supportedStyles.includes( 'minHeight' ) ) {\n\t\t\tupdatedSettings.dimensions = {\n\t\t\t\t...updatedSettings.dimensions,\n\t\t\t\tminHeight: false,\n\t\t\t};\n\t\t}\n\n\t\t[ 'radius', 'color', 'style', 'width' ].forEach( ( key ) => {\n\t\t\tif (\n\t\t\t\t! supportedStyles.includes(\n\t\t\t\t\t'border' + key.charAt( 0 ).toUpperCase() + key.slice( 1 )\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tupdatedSettings.border = {\n\t\t\t\t\t...updatedSettings.border,\n\t\t\t\t\t[ key ]: false,\n\t\t\t\t};\n\t\t\t}\n\t\t} );\n\n\t\treturn updatedSettings;\n\t}, [ parentSettings, supportedStyles, supports ] );\n}\n\nexport function useColorsPerOrigin( settings ) {\n\tconst customColors = settings?.color?.palette?.custom;\n\tconst themeColors = settings?.color?.palette?.theme;\n\tconst defaultColors = settings?.color?.palette?.default;\n\tconst shouldDisplayDefaultColors = settings?.color?.defaultPalette;\n\n\treturn useMemo( () => {\n\t\tconst result = [];\n\t\tif ( themeColors && themeColors.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Theme',\n\t\t\t\t\t'Indicates this palette comes from the theme.'\n\t\t\t\t),\n\t\t\t\tcolors: themeColors,\n\t\t\t} );\n\t\t}\n\t\tif (\n\t\t\tshouldDisplayDefaultColors &&\n\t\t\tdefaultColors &&\n\t\t\tdefaultColors.length\n\t\t) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Default',\n\t\t\t\t\t'Indicates this palette comes from WordPress.'\n\t\t\t\t),\n\t\t\t\tcolors: defaultColors,\n\t\t\t} );\n\t\t}\n\t\tif ( customColors && customColors.length ) {\n\t\t\tresult.push( {\n\t\t\t\tname: _x(\n\t\t\t\t\t'Custom',\n\t\t\t\t\t'Indicates this palette is created by the user.'\n\t\t\t\t),\n\t\t\t\tcolors: customColors,\n\t\t\t} );\n\t\t}\n\t\treturn result;\n\t}, [\n\t\tcustomColors,\n\t\tthemeColors,\n\t\tdefaultColors,\n\t\tshouldDisplayDefaultColors,\n\t] );\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { useGlobalStylesReset, useGlobalSetting, useGlobalStyle, useSettingsForBlockElement } from './hooks';
|
|
1
|
+
export { useGlobalStylesReset, useGlobalSetting, useGlobalStyle, useSettingsForBlockElement, useColorsPerOrigin } from './hooks';
|
|
2
2
|
export { useGlobalStylesOutput } from './use-global-styles-output';
|
|
3
3
|
export { GlobalStylesContext } from './context';
|
|
4
4
|
export { default as TypographyPanel, useHasTypographyPanel } from './typography-panel';
|
|
5
5
|
export { default as DimensionsPanel, useHasDimensionsPanel } from './dimensions-panel';
|
|
6
|
+
export { default as BorderPanel, useHasBorderPanel } from './border-panel';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/index.js"],"names":["useGlobalStylesReset","useGlobalSetting","useGlobalStyle","useSettingsForBlockElement","useGlobalStylesOutput","GlobalStylesContext","default","TypographyPanel","useHasTypographyPanel","DimensionsPanel","useHasDimensionsPanel"],"mappings":"AAAA,SACCA,oBADD,EAECC,gBAFD,EAGCC,cAHD,EAICC,0BAJD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/index.js"],"names":["useGlobalStylesReset","useGlobalSetting","useGlobalStyle","useSettingsForBlockElement","useColorsPerOrigin","useGlobalStylesOutput","GlobalStylesContext","default","TypographyPanel","useHasTypographyPanel","DimensionsPanel","useHasDimensionsPanel","BorderPanel","useHasBorderPanel"],"mappings":"AAAA,SACCA,oBADD,EAECC,gBAFD,EAGCC,cAHD,EAICC,0BAJD,EAKCC,kBALD,QAMO,SANP;AAOA,SAASC,qBAAT,QAAsC,4BAAtC;AACA,SAASC,mBAAT,QAAoC,WAApC;AACA,SACCC,OAAO,IAAIC,eADZ,EAECC,qBAFD,QAGO,oBAHP;AAIA,SACCF,OAAO,IAAIG,eADZ,EAECC,qBAFD,QAGO,oBAHP;AAIA,SAASJ,OAAO,IAAIK,WAApB,EAAiCC,iBAAjC,QAA0D,gBAA1D","sourcesContent":["export {\n\tuseGlobalStylesReset,\n\tuseGlobalSetting,\n\tuseGlobalStyle,\n\tuseSettingsForBlockElement,\n\tuseColorsPerOrigin,\n} from './hooks';\nexport { useGlobalStylesOutput } from './use-global-styles-output';\nexport { GlobalStylesContext } from './context';\nexport {\n\tdefault as TypographyPanel,\n\tuseHasTypographyPanel,\n} from './typography-panel';\nexport {\n\tdefault as DimensionsPanel,\n\tuseHasDimensionsPanel,\n} from './dimensions-panel';\nexport { default as BorderPanel, useHasBorderPanel } from './border-panel';\n"]}
|