@wordpress/block-editor 8.5.0 → 8.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-alignment-control/ui.js +1 -1
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-content-overlay/index.js +13 -4
- package/build/components/block-content-overlay/index.js.map +1 -1
- package/build/components/block-list/block.native.js +3 -1
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-lock/index.js +8 -0
- package/build/components/block-lock/index.js.map +1 -1
- package/build/components/block-lock/menu-item.js +5 -20
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +33 -12
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +7 -20
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-lock/use-block-lock.js +50 -0
- package/build/components/block-lock/use-block-lock.js.map +1 -0
- package/build/components/block-mover/button.js +4 -4
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +39 -65
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +37 -22
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +183 -0
- package/build/components/block-popover/inbetween.js.map +1 -0
- package/build/components/block-popover/index.js +82 -0
- package/build/components/block-popover/index.js.map +1 -0
- package/build/components/{block-tools → block-popover}/use-popover-scroll.js +4 -1
- package/build/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build/components/block-preview/auto.js +6 -3
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +4 -2
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-styles/index.js +1 -10
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-switcher/index.js +7 -2
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -2
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +4 -2
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +5 -5
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +14 -121
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/{block-popover.js → selected-block-popover.js} +25 -108
- package/build/components/block-tools/selected-block-popover.js.map +1 -0
- package/build/components/copy-handler/index.js +44 -9
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/duotone-control/index.js +5 -1
- package/build/components/duotone-control/index.js.map +1 -1
- package/build/components/inserter/index.native.js +30 -8
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/link-control/index.js +6 -7
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +4 -10
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +13 -2
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/rich-text/index.js +0 -5
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +0 -4
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/use-block-display-information/index.js +3 -1
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/hooks/border.js +468 -44
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/duotone.js +66 -16
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +8 -2
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-border-props.js +22 -32
- package/build/hooks/use-border-props.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +36 -31
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +0 -26
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +131 -6
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +27 -0
- package/build/store/utils.js.map +1 -0
- package/build-module/components/block-alignment-control/ui.js +2 -2
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-content-overlay/index.js +13 -4
- package/build-module/components/block-content-overlay/index.js.map +1 -1
- package/build-module/components/block-list/block.native.js +3 -1
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-lock/index.js +1 -0
- package/build-module/components/block-lock/index.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +4 -18
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +31 -12
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +6 -18
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-lock/use-block-lock.js +41 -0
- package/build-module/components/block-lock/use-block-lock.js.map +1 -0
- package/build-module/components/block-mover/button.js +5 -5
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +38 -63
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +39 -24
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +165 -0
- package/build-module/components/block-popover/inbetween.js.map +1 -0
- package/build-module/components/block-popover/index.js +67 -0
- package/build-module/components/block-popover/index.js.map +1 -0
- package/build-module/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/build-module/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build-module/components/block-preview/auto.js +6 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +4 -2
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-styles/index.js +1 -9
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +7 -2
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +1 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +3 -2
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +3 -3
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +16 -121
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/{block-popover.js → selected-block-popover.js} +25 -105
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -0
- package/build-module/components/copy-handler/index.js +44 -9
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/duotone-control/index.js +4 -1
- package/build-module/components/duotone-control/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +31 -10
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/link-control/index.js +6 -7
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +4 -9
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +13 -2
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/rich-text/index.js +0 -4
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +0 -4
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +3 -1
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/hooks/border.js +458 -44
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/duotone.js +63 -16
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +2 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-border-props.js +21 -30
- package/build-module/hooks/use-border-props.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +19 -16
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +0 -24
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +120 -5
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +20 -0
- package/build-module/store/utils.js.map +1 -0
- package/build-style/style-rtl.css +145 -272
- package/build-style/style.css +145 -272
- package/package.json +28 -28
- package/src/components/block-alignment-control/ui.js +2 -2
- package/src/components/block-content-overlay/index.js +19 -2
- package/src/components/block-list/block.native.js +2 -0
- package/src/components/block-lock/index.js +1 -0
- package/src/components/block-lock/menu-item.js +3 -23
- package/src/components/block-lock/modal.js +37 -13
- package/src/components/block-lock/style.scss +1 -2
- package/src/components/block-lock/toolbar.js +4 -21
- package/src/components/block-lock/use-block-lock.js +45 -0
- package/src/components/block-mover/button.js +5 -7
- package/src/components/block-mover/index.js +37 -60
- package/src/components/block-mover/stories/index.js +110 -0
- package/src/components/block-mover/style.scss +48 -138
- package/src/components/block-pattern-setup/index.js +84 -59
- package/src/components/block-pattern-setup/setup-toolbar.js +3 -1
- package/src/components/block-pattern-setup/style.scss +32 -26
- package/src/components/block-popover/README.md +41 -0
- package/src/components/block-popover/inbetween.js +180 -0
- package/src/components/block-popover/index.js +73 -0
- package/src/components/block-popover/style.scss +24 -0
- package/src/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/src/components/block-preview/auto.js +10 -1
- package/src/components/block-preview/index.js +2 -0
- package/src/components/block-styles/index.js +1 -12
- package/src/components/block-switcher/index.js +13 -1
- package/src/components/block-switcher/style.scss +4 -4
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +15 -13
- package/src/components/block-toolbar/style.scss +0 -12
- package/src/components/block-tools/back-compat.js +1 -1
- package/src/components/block-tools/block-selection-button.js +3 -1
- package/src/components/block-tools/index.js +6 -4
- package/src/components/block-tools/insertion-point.js +19 -152
- package/src/components/block-tools/{block-popover.js → selected-block-popover.js} +24 -116
- package/src/components/block-tools/style.scss +11 -123
- package/src/components/border-radius-control/style.scss +5 -2
- package/src/components/copy-handler/index.js +52 -10
- package/src/components/default-block-appender/style.scss +1 -2
- package/src/components/duotone-control/index.js +8 -1
- package/src/components/gradients/README.md +29 -0
- package/src/components/inserter/index.native.js +60 -25
- package/src/components/inserter/style.native.scss +24 -3
- package/src/components/link-control/index.js +5 -5
- package/src/components/list-view/block-select-button.js +2 -10
- package/src/components/list-view/block.js +16 -7
- package/src/components/navigable-toolbar/README.md +16 -0
- package/src/components/rich-text/index.js +0 -2
- package/src/components/rich-text/index.native.js +0 -4
- package/src/components/use-block-display-information/index.js +2 -0
- package/src/hooks/border.js +438 -72
- package/src/hooks/border.scss +48 -0
- package/src/hooks/duotone.js +98 -62
- package/src/hooks/index.js +2 -1
- package/src/hooks/use-border-props.js +15 -32
- package/src/index.js +1 -0
- package/src/store/actions.js +19 -15
- package/src/store/reducer.js +0 -21
- package/src/store/selectors.js +160 -5
- package/src/store/test/actions.js +0 -18
- package/src/store/test/reducer.js +0 -19
- package/src/store/test/selectors.js +0 -19
- package/src/store/utils.js +19 -0
- package/src/style.scss +1 -1
- package/build/components/block-mobile-toolbar/index.js +0 -42
- package/build/components/block-mobile-toolbar/index.js.map +0 -1
- package/build/components/block-tools/block-popover.js.map +0 -1
- package/build/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build/components/list-view/appender.js +0 -93
- package/build/components/list-view/appender.js.map +0 -1
- package/build/components/list-view/list-item.js +0 -62
- package/build/components/list-view/list-item.js.map +0 -1
- package/build/components/rich-text/use-caret-in-format.js +0 -43
- package/build/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build/hooks/border-color.js +0 -302
- package/build/hooks/border-color.js.map +0 -1
- package/build/hooks/border-style.js +0 -96
- package/build/hooks/border-style.js.map +0 -1
- package/build/hooks/border-width.js +0 -162
- package/build/hooks/border-width.js.map +0 -1
- package/build-module/components/block-mobile-toolbar/index.js +0 -31
- package/build-module/components/block-mobile-toolbar/index.js.map +0 -1
- package/build-module/components/block-tools/block-popover.js.map +0 -1
- package/build-module/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build-module/components/list-view/appender.js +0 -76
- package/build-module/components/list-view/appender.js.map +0 -1
- package/build-module/components/list-view/list-item.js +0 -47
- package/build-module/components/list-view/list-item.js.map +0 -1
- package/build-module/components/rich-text/use-caret-in-format.js +0 -33
- package/build-module/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build-module/hooks/border-color.js +0 -276
- package/build-module/hooks/border-color.js.map +0 -1
- package/build-module/hooks/border-style.js +0 -78
- package/build-module/hooks/border-style.js.map +0 -1
- package/build-module/hooks/border-width.js +0 -143
- package/build-module/hooks/border-width.js.map +0 -1
- package/src/components/block-mobile-toolbar/index.js +0 -24
- package/src/components/block-mobile-toolbar/style.scss +0 -29
- package/src/components/list-view/appender.js +0 -82
- package/src/components/list-view/list-item.js +0 -59
- package/src/components/rich-text/use-caret-in-format.js +0 -28
- package/src/hooks/border-color.js +0 -315
- package/src/hooks/border-style.js +0 -64
- package/src/hooks/border-width.js +0 -139
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WordPress dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { __experimentalUnitControl as UnitControl, __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';
|
|
7
|
-
import { useState } from '@wordpress/element';
|
|
8
|
-
import { __ } from '@wordpress/i18n';
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { cleanEmptyObject } from './utils';
|
|
14
|
-
import { removeBorderAttribute } from './border';
|
|
15
|
-
import useSetting from '../components/use-setting';
|
|
16
|
-
const MIN_BORDER_WIDTH = 0;
|
|
17
|
-
/**
|
|
18
|
-
* Inspector control for configuring border width property.
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} props Block properties.
|
|
21
|
-
*
|
|
22
|
-
* @return {WPElement} Border width edit element.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export const BorderWidthEdit = props => {
|
|
26
|
-
const {
|
|
27
|
-
attributes: {
|
|
28
|
-
borderColor,
|
|
29
|
-
style
|
|
30
|
-
},
|
|
31
|
-
setAttributes
|
|
32
|
-
} = props;
|
|
33
|
-
const {
|
|
34
|
-
width,
|
|
35
|
-
color: customBorderColor,
|
|
36
|
-
style: borderStyle
|
|
37
|
-
} = (style === null || style === void 0 ? void 0 : style.border) || {}; // Used to temporarily track previous border color & style selections to be
|
|
38
|
-
// able to restore them when border width changes from zero value.
|
|
39
|
-
|
|
40
|
-
const [styleSelection, setStyleSelection] = useState();
|
|
41
|
-
const [colorSelection, setColorSelection] = useState();
|
|
42
|
-
const [customColorSelection, setCustomColorSelection] = useState();
|
|
43
|
-
|
|
44
|
-
const onChange = newWidth => {
|
|
45
|
-
let newStyle = { ...style,
|
|
46
|
-
border: { ...(style === null || style === void 0 ? void 0 : style.border),
|
|
47
|
-
width: newWidth
|
|
48
|
-
}
|
|
49
|
-
}; // Used to clear named border color attribute.
|
|
50
|
-
|
|
51
|
-
let borderPaletteColor = borderColor;
|
|
52
|
-
const hasZeroWidth = parseFloat(newWidth) === 0;
|
|
53
|
-
const hadPreviousZeroWidth = parseFloat(width) === 0; // Setting the border width explicitly to zero will also set the
|
|
54
|
-
// border style to `none` and clear border color attributes.
|
|
55
|
-
|
|
56
|
-
if (hasZeroWidth && !hadPreviousZeroWidth) {
|
|
57
|
-
// Before clearing color and style selections, keep track of
|
|
58
|
-
// the current selections so they can be restored when the width
|
|
59
|
-
// changes to a non-zero value.
|
|
60
|
-
setColorSelection(borderColor);
|
|
61
|
-
setCustomColorSelection(customBorderColor);
|
|
62
|
-
setStyleSelection(borderStyle); // Clear style and color attributes.
|
|
63
|
-
|
|
64
|
-
borderPaletteColor = undefined;
|
|
65
|
-
newStyle.border.color = undefined;
|
|
66
|
-
newStyle.border.style = 'none';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!hasZeroWidth && hadPreviousZeroWidth) {
|
|
70
|
-
// Restore previous border style selection if width is now not zero and
|
|
71
|
-
// border style was 'none'. This is to support changes to the UI which
|
|
72
|
-
// change the border style UI to a segmented control without a "none"
|
|
73
|
-
// option.
|
|
74
|
-
if (borderStyle === 'none') {
|
|
75
|
-
newStyle.border.style = styleSelection;
|
|
76
|
-
} // Restore previous border color selection if width is no longer zero
|
|
77
|
-
// and current border color is undefined.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (borderColor === undefined) {
|
|
81
|
-
borderPaletteColor = colorSelection;
|
|
82
|
-
newStyle.border.color = customColorSelection;
|
|
83
|
-
}
|
|
84
|
-
} // If width was reset, clean out undefined styles.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (newWidth === undefined || newWidth === '') {
|
|
88
|
-
newStyle = cleanEmptyObject(newStyle);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setAttributes({
|
|
92
|
-
borderColor: borderPaletteColor,
|
|
93
|
-
style: newStyle
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const units = useCustomUnits({
|
|
98
|
-
availableUnits: useSetting('spacing.units') || ['px', 'em', 'rem']
|
|
99
|
-
});
|
|
100
|
-
return createElement(UnitControl, {
|
|
101
|
-
value: width,
|
|
102
|
-
label: __('Width'),
|
|
103
|
-
min: MIN_BORDER_WIDTH,
|
|
104
|
-
onChange: onChange,
|
|
105
|
-
units: units
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Checks if there is a current value in the border width block support
|
|
110
|
-
* attributes.
|
|
111
|
-
*
|
|
112
|
-
* @param {Object} props Block props.
|
|
113
|
-
* @return {boolean} Whether or not the block has a border width value set.
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
export function hasBorderWidthValue(props) {
|
|
117
|
-
var _props$attributes$sty, _props$attributes$sty2;
|
|
118
|
-
|
|
119
|
-
return !!((_props$attributes$sty = props.attributes.style) !== null && _props$attributes$sty !== void 0 && (_props$attributes$sty2 = _props$attributes$sty.border) !== null && _props$attributes$sty2 !== void 0 && _props$attributes$sty2.width);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Resets the border width block support attribute. This can be used when
|
|
123
|
-
* disabling the border width support control for a block via a progressive
|
|
124
|
-
* discovery panel.
|
|
125
|
-
*
|
|
126
|
-
* @param {Object} props Block props.
|
|
127
|
-
* @param {Object} props.attributes Block's attributes.
|
|
128
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
export function resetBorderWidth(_ref) {
|
|
132
|
-
let {
|
|
133
|
-
attributes = {},
|
|
134
|
-
setAttributes
|
|
135
|
-
} = _ref;
|
|
136
|
-
const {
|
|
137
|
-
style
|
|
138
|
-
} = attributes;
|
|
139
|
-
setAttributes({
|
|
140
|
-
style: removeBorderAttribute(style, 'width')
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=border-width.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/border-width.js"],"names":["__experimentalUnitControl","UnitControl","__experimentalUseCustomUnits","useCustomUnits","useState","__","cleanEmptyObject","removeBorderAttribute","useSetting","MIN_BORDER_WIDTH","BorderWidthEdit","props","attributes","borderColor","style","setAttributes","width","color","customBorderColor","borderStyle","border","styleSelection","setStyleSelection","colorSelection","setColorSelection","customColorSelection","setCustomColorSelection","onChange","newWidth","newStyle","borderPaletteColor","hasZeroWidth","parseFloat","hadPreviousZeroWidth","undefined","units","availableUnits","hasBorderWidthValue","resetBorderWidth"],"mappings":"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","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalUseCustomUnits as useCustomUnits,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { cleanEmptyObject } from './utils';\nimport { removeBorderAttribute } from './border';\nimport useSetting from '../components/use-setting';\n\nconst MIN_BORDER_WIDTH = 0;\n\n/**\n * Inspector control for configuring border width property.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border width edit element.\n */\nexport const BorderWidthEdit = ( props ) => {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst { width, color: customBorderColor, style: borderStyle } =\n\t\tstyle?.border || {};\n\n\t// Used to temporarily track previous border color & style selections to be\n\t// able to restore them when border width changes from zero value.\n\tconst [ styleSelection, setStyleSelection ] = useState();\n\tconst [ colorSelection, setColorSelection ] = useState();\n\tconst [ customColorSelection, setCustomColorSelection ] = useState();\n\n\tconst onChange = ( newWidth ) => {\n\t\tlet newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\twidth: newWidth,\n\t\t\t},\n\t\t};\n\n\t\t// Used to clear named border color attribute.\n\t\tlet borderPaletteColor = borderColor;\n\n\t\tconst hasZeroWidth = parseFloat( newWidth ) === 0;\n\t\tconst hadPreviousZeroWidth = parseFloat( width ) === 0;\n\n\t\t// Setting the border width explicitly to zero will also set the\n\t\t// border style to `none` and clear border color attributes.\n\t\tif ( hasZeroWidth && ! hadPreviousZeroWidth ) {\n\t\t\t// Before clearing color and style selections, keep track of\n\t\t\t// the current selections so they can be restored when the width\n\t\t\t// changes to a non-zero value.\n\t\t\tsetColorSelection( borderColor );\n\t\t\tsetCustomColorSelection( customBorderColor );\n\t\t\tsetStyleSelection( borderStyle );\n\n\t\t\t// Clear style and color attributes.\n\t\t\tborderPaletteColor = undefined;\n\t\t\tnewStyle.border.color = undefined;\n\t\t\tnewStyle.border.style = 'none';\n\t\t}\n\n\t\tif ( ! hasZeroWidth && hadPreviousZeroWidth ) {\n\t\t\t// Restore previous border style selection if width is now not zero and\n\t\t\t// border style was 'none'. This is to support changes to the UI which\n\t\t\t// change the border style UI to a segmented control without a \"none\"\n\t\t\t// option.\n\t\t\tif ( borderStyle === 'none' ) {\n\t\t\t\tnewStyle.border.style = styleSelection;\n\t\t\t}\n\n\t\t\t// Restore previous border color selection if width is no longer zero\n\t\t\t// and current border color is undefined.\n\t\t\tif ( borderColor === undefined ) {\n\t\t\t\tborderPaletteColor = colorSelection;\n\t\t\t\tnewStyle.border.color = customColorSelection;\n\t\t\t}\n\t\t}\n\n\t\t// If width was reset, clean out undefined styles.\n\t\tif ( newWidth === undefined || newWidth === '' ) {\n\t\t\tnewStyle = cleanEmptyObject( newStyle );\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tborderColor: borderPaletteColor,\n\t\t\tstyle: newStyle,\n\t\t} );\n\t};\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\treturn (\n\t\t<UnitControl\n\t\t\tvalue={ width }\n\t\t\tlabel={ __( 'Width' ) }\n\t\t\tmin={ MIN_BORDER_WIDTH }\n\t\t\tonChange={ onChange }\n\t\t\tunits={ units }\n\t\t/>\n\t);\n};\n\n/**\n * Checks if there is a current value in the border width block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border width value set.\n */\nexport function hasBorderWidthValue( props ) {\n\treturn !! props.attributes.style?.border?.width;\n}\n\n/**\n * Resets the border width block support attribute. This can be used when\n * disabling the border width support control for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderWidth( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\tsetAttributes( { style: removeBorderAttribute( style, 'width' ) } );\n}\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useViewportMatch } from '@wordpress/compose';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import BlockMover from '../block-mover';
|
|
10
|
-
|
|
11
|
-
function BlockMobileToolbar( { clientId } ) {
|
|
12
|
-
const isMobile = useViewportMatch( 'small', '<' );
|
|
13
|
-
if ( ! isMobile ) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<div className="block-editor-block-mobile-toolbar">
|
|
19
|
-
<BlockMover clientIds={ [ clientId ] } />
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default BlockMobileToolbar;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
.block-editor-block-mobile-toolbar {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: row;
|
|
4
|
-
border-right: $border-width solid $gray-300;
|
|
5
|
-
|
|
6
|
-
.block-editor-block-mover-button {
|
|
7
|
-
width: $button-size;
|
|
8
|
-
height: $button-size;
|
|
9
|
-
border-radius: $radius-block-ui;
|
|
10
|
-
padding: 3px;
|
|
11
|
-
margin: 0;
|
|
12
|
-
justify-content: center;
|
|
13
|
-
align-items: center;
|
|
14
|
-
|
|
15
|
-
.dashicon {
|
|
16
|
-
margin: auto;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Movers
|
|
21
|
-
.block-editor-block-mover {
|
|
22
|
-
display: flex;
|
|
23
|
-
margin-right: auto;
|
|
24
|
-
|
|
25
|
-
.block-editor-block-mover-button {
|
|
26
|
-
float: left;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { __experimentalTreeGridCell as TreeGridCell } from '@wordpress/components';
|
|
10
|
-
import { useInstanceId } from '@wordpress/compose';
|
|
11
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
12
|
-
import { useSelect } from '@wordpress/data';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import ListViewLeaf from './leaf';
|
|
18
|
-
import Inserter from '../inserter';
|
|
19
|
-
import { store as blockEditorStore } from '../../store';
|
|
20
|
-
|
|
21
|
-
export default function ListViewAppender( {
|
|
22
|
-
parentBlockClientId,
|
|
23
|
-
position,
|
|
24
|
-
level,
|
|
25
|
-
rowCount,
|
|
26
|
-
path,
|
|
27
|
-
} ) {
|
|
28
|
-
const isDragging = useSelect(
|
|
29
|
-
( select ) => {
|
|
30
|
-
const { isBlockBeingDragged, isAncestorBeingDragged } = select(
|
|
31
|
-
blockEditorStore
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
isBlockBeingDragged( parentBlockClientId ) ||
|
|
36
|
-
isAncestorBeingDragged( parentBlockClientId )
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
[ parentBlockClientId ]
|
|
40
|
-
);
|
|
41
|
-
const instanceId = useInstanceId( ListViewAppender );
|
|
42
|
-
const descriptionId = `list-view-appender-row__description_${ instanceId }`;
|
|
43
|
-
|
|
44
|
-
const appenderPositionDescription = sprintf(
|
|
45
|
-
/* translators: 1: The numerical position of the block that will be inserted. 2: The level of nesting for the block that will be inserted. */
|
|
46
|
-
__( 'Add block at position %1$d, Level %2$d' ),
|
|
47
|
-
position,
|
|
48
|
-
level
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<ListViewLeaf
|
|
53
|
-
className={ classnames( { 'is-dragging': isDragging } ) }
|
|
54
|
-
level={ level }
|
|
55
|
-
position={ position }
|
|
56
|
-
rowCount={ rowCount }
|
|
57
|
-
path={ path }
|
|
58
|
-
>
|
|
59
|
-
<TreeGridCell
|
|
60
|
-
className="block-editor-list-view-appender__cell"
|
|
61
|
-
colSpan="3"
|
|
62
|
-
>
|
|
63
|
-
{ ( { ref, tabIndex, onFocus } ) => (
|
|
64
|
-
<div className="block-editor-list-view-appender__container">
|
|
65
|
-
<Inserter
|
|
66
|
-
rootClientId={ parentBlockClientId }
|
|
67
|
-
__experimentalIsQuick
|
|
68
|
-
aria-describedby={ descriptionId }
|
|
69
|
-
toggleProps={ { ref, tabIndex, onFocus } }
|
|
70
|
-
/>
|
|
71
|
-
<div
|
|
72
|
-
className="block-editor-list-view-appender__description"
|
|
73
|
-
id={ descriptionId }
|
|
74
|
-
>
|
|
75
|
-
{ appenderPositionDescription }
|
|
76
|
-
</div>
|
|
77
|
-
</div>
|
|
78
|
-
) }
|
|
79
|
-
</TreeGridCell>
|
|
80
|
-
</ListViewLeaf>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { Button, VisuallyHidden } from '@wordpress/components';
|
|
10
|
-
import {
|
|
11
|
-
__experimentalGetBlockLabel as getBlockLabel,
|
|
12
|
-
getBlockType,
|
|
13
|
-
} from '@wordpress/blocks';
|
|
14
|
-
import { __ } from '@wordpress/i18n';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
import BlockIcon from '../block-icon';
|
|
20
|
-
|
|
21
|
-
export default function ListViewListItem( {
|
|
22
|
-
block,
|
|
23
|
-
onClick,
|
|
24
|
-
isSelected,
|
|
25
|
-
wrapperComponent: WrapperComponent,
|
|
26
|
-
children,
|
|
27
|
-
} ) {
|
|
28
|
-
const blockType = getBlockType( block.name );
|
|
29
|
-
const blockLabel = blockType
|
|
30
|
-
? getBlockLabel( blockType, block.attributes )
|
|
31
|
-
: null;
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div className="block-editor-list-view__list-item">
|
|
35
|
-
<WrapperComponent
|
|
36
|
-
className={ classnames(
|
|
37
|
-
'block-editor-list-view__list-item-button',
|
|
38
|
-
{
|
|
39
|
-
'is-selected': isSelected,
|
|
40
|
-
}
|
|
41
|
-
) }
|
|
42
|
-
onClick={ onClick }
|
|
43
|
-
>
|
|
44
|
-
<BlockIcon icon={ blockType?.icon } showColors />
|
|
45
|
-
{ children ? children : blockLabel }
|
|
46
|
-
{ isSelected && (
|
|
47
|
-
<VisuallyHidden as="span">
|
|
48
|
-
{ __( '(selected block)' ) }
|
|
49
|
-
</VisuallyHidden>
|
|
50
|
-
) }
|
|
51
|
-
</WrapperComponent>
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
ListViewListItem.defaultProps = {
|
|
57
|
-
onClick: () => {},
|
|
58
|
-
wrapperComponent: ( props ) => <Button { ...props } />,
|
|
59
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useEffect } from '@wordpress/element';
|
|
5
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as blockEditorStore } from '../../store';
|
|
11
|
-
|
|
12
|
-
export function useCaretInFormat( { value } ) {
|
|
13
|
-
const hasActiveFormats =
|
|
14
|
-
value.activeFormats && !! value.activeFormats.length;
|
|
15
|
-
const { isCaretWithinFormattedText } = useSelect( blockEditorStore );
|
|
16
|
-
const { enterFormattedText, exitFormattedText } = useDispatch(
|
|
17
|
-
blockEditorStore
|
|
18
|
-
);
|
|
19
|
-
useEffect( () => {
|
|
20
|
-
if ( hasActiveFormats ) {
|
|
21
|
-
if ( ! isCaretWithinFormattedText() ) {
|
|
22
|
-
enterFormattedText();
|
|
23
|
-
}
|
|
24
|
-
} else if ( isCaretWithinFormattedText() ) {
|
|
25
|
-
exitFormattedText();
|
|
26
|
-
}
|
|
27
|
-
}, [ hasActiveFormats ] );
|
|
28
|
-
}
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { addFilter } from '@wordpress/hooks';
|
|
10
|
-
import { __ } from '@wordpress/i18n';
|
|
11
|
-
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
12
|
-
import { useEffect, useState } from '@wordpress/element';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';
|
|
18
|
-
import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
|
|
19
|
-
import {
|
|
20
|
-
getColorClassName,
|
|
21
|
-
getColorObjectByColorValue,
|
|
22
|
-
getColorObjectByAttributeValues,
|
|
23
|
-
} from '../components/colors';
|
|
24
|
-
import useSetting from '../components/use-setting';
|
|
25
|
-
import {
|
|
26
|
-
BORDER_SUPPORT_KEY,
|
|
27
|
-
hasBorderSupport,
|
|
28
|
-
removeBorderAttribute,
|
|
29
|
-
} from './border';
|
|
30
|
-
import { cleanEmptyObject, shouldSkipSerialization } from './utils';
|
|
31
|
-
|
|
32
|
-
// Defining empty array here instead of inline avoids unnecessary re-renders of
|
|
33
|
-
// color control.
|
|
34
|
-
const EMPTY_ARRAY = [];
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Inspector control panel containing the border color related configuration.
|
|
38
|
-
*
|
|
39
|
-
* There is deliberate overlap between the colors and borders block supports
|
|
40
|
-
* relating to border color. It can be argued the border color controls could
|
|
41
|
-
* be included within either, or both, the colors and borders panels in the
|
|
42
|
-
* inspector controls. If they share the same block attributes it should not
|
|
43
|
-
* matter.
|
|
44
|
-
*
|
|
45
|
-
* @param {Object} props Block properties.
|
|
46
|
-
*
|
|
47
|
-
* @return {WPElement} Border color edit element.
|
|
48
|
-
*/
|
|
49
|
-
export function BorderColorEdit( props ) {
|
|
50
|
-
const {
|
|
51
|
-
attributes: { borderColor, style },
|
|
52
|
-
setAttributes,
|
|
53
|
-
} = props;
|
|
54
|
-
const colorGradientSettings = useMultipleOriginColorsAndGradients();
|
|
55
|
-
const availableColors = colorGradientSettings.colors.reduce(
|
|
56
|
-
( colors, origin ) => colors.concat( origin.colors ),
|
|
57
|
-
[]
|
|
58
|
-
);
|
|
59
|
-
const { color: customBorderColor } = style?.border || {};
|
|
60
|
-
const [ colorValue, setColorValue ] = useState(
|
|
61
|
-
() =>
|
|
62
|
-
getColorObjectByAttributeValues(
|
|
63
|
-
availableColors,
|
|
64
|
-
borderColor,
|
|
65
|
-
customBorderColor
|
|
66
|
-
)?.color
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// Detect changes in the color attributes and update the colorValue to keep the
|
|
70
|
-
// UI in sync. This is necessary for situations when border controls interact with
|
|
71
|
-
// each other: eg, setting the border width to zero causes the color and style
|
|
72
|
-
// selections to be cleared.
|
|
73
|
-
useEffect( () => {
|
|
74
|
-
setColorValue(
|
|
75
|
-
getColorObjectByAttributeValues(
|
|
76
|
-
availableColors,
|
|
77
|
-
borderColor,
|
|
78
|
-
customBorderColor
|
|
79
|
-
)?.color
|
|
80
|
-
);
|
|
81
|
-
}, [ borderColor, customBorderColor, availableColors ] );
|
|
82
|
-
|
|
83
|
-
const onChangeColor = ( value ) => {
|
|
84
|
-
setColorValue( value );
|
|
85
|
-
|
|
86
|
-
const colorObject = getColorObjectByColorValue(
|
|
87
|
-
availableColors,
|
|
88
|
-
value
|
|
89
|
-
);
|
|
90
|
-
const newStyle = {
|
|
91
|
-
...style,
|
|
92
|
-
border: {
|
|
93
|
-
...style?.border,
|
|
94
|
-
color: colorObject?.slug ? undefined : value,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// If empty slug, ensure undefined to remove attribute.
|
|
99
|
-
const newNamedColor = colorObject?.slug ? colorObject.slug : undefined;
|
|
100
|
-
|
|
101
|
-
setAttributes( {
|
|
102
|
-
style: cleanEmptyObject( newStyle ),
|
|
103
|
-
borderColor: newNamedColor,
|
|
104
|
-
} );
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const settings = [
|
|
108
|
-
{
|
|
109
|
-
label: __( 'Color' ),
|
|
110
|
-
onColorChange: onChangeColor,
|
|
111
|
-
colorValue,
|
|
112
|
-
clearable: false,
|
|
113
|
-
},
|
|
114
|
-
];
|
|
115
|
-
return (
|
|
116
|
-
<ColorGradientSettingsDropdown
|
|
117
|
-
settings={ settings }
|
|
118
|
-
disableCustomColors
|
|
119
|
-
disableCustomGradients
|
|
120
|
-
__experimentalHasMultipleOrigins
|
|
121
|
-
__experimentalIsRenderedInSidebar
|
|
122
|
-
enableAlpha
|
|
123
|
-
{ ...colorGradientSettings }
|
|
124
|
-
/>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Checks if there is a current value in the border color block support
|
|
130
|
-
* attributes.
|
|
131
|
-
*
|
|
132
|
-
* @param {Object} props Block props.
|
|
133
|
-
* @return {boolean} Whether or not the block has a border color value set.
|
|
134
|
-
*/
|
|
135
|
-
export function hasBorderColorValue( props ) {
|
|
136
|
-
const {
|
|
137
|
-
attributes: { borderColor, style },
|
|
138
|
-
} = props;
|
|
139
|
-
|
|
140
|
-
return !! borderColor || !! style?.border?.color;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Resets the border color block support attributes. This can be used when
|
|
145
|
-
* disabling the border color support controls for a block via a progressive
|
|
146
|
-
* discovery panel.
|
|
147
|
-
*
|
|
148
|
-
* @param {Object} props Block props.
|
|
149
|
-
* @param {Object} props.attributes Block's attributes.
|
|
150
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
151
|
-
*/
|
|
152
|
-
export function resetBorderColor( { attributes = {}, setAttributes } ) {
|
|
153
|
-
const { style } = attributes;
|
|
154
|
-
|
|
155
|
-
setAttributes( {
|
|
156
|
-
borderColor: undefined,
|
|
157
|
-
style: removeBorderAttribute( style, 'color' ),
|
|
158
|
-
} );
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Filters registered block settings, extending attributes to include
|
|
163
|
-
* `borderColor` if needed.
|
|
164
|
-
*
|
|
165
|
-
* @param {Object} settings Original block settings.
|
|
166
|
-
*
|
|
167
|
-
* @return {Object} Updated block settings.
|
|
168
|
-
*/
|
|
169
|
-
function addAttributes( settings ) {
|
|
170
|
-
if ( ! hasBorderSupport( settings, 'color' ) ) {
|
|
171
|
-
return settings;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Allow blocks to specify default value if needed.
|
|
175
|
-
if ( settings.attributes.borderColor ) {
|
|
176
|
-
return settings;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Add new borderColor attribute to block settings.
|
|
180
|
-
return {
|
|
181
|
-
...settings,
|
|
182
|
-
attributes: {
|
|
183
|
-
...settings.attributes,
|
|
184
|
-
borderColor: {
|
|
185
|
-
type: 'string',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Override props assigned to save component to inject border color.
|
|
193
|
-
*
|
|
194
|
-
* @param {Object} props Additional props applied to save element.
|
|
195
|
-
* @param {Object} blockType Block type definition.
|
|
196
|
-
* @param {Object} attributes Block's attributes.
|
|
197
|
-
*
|
|
198
|
-
* @return {Object} Filtered props to apply to save element.
|
|
199
|
-
*/
|
|
200
|
-
function addSaveProps( props, blockType, attributes ) {
|
|
201
|
-
if (
|
|
202
|
-
! hasBorderSupport( blockType, 'color' ) ||
|
|
203
|
-
shouldSkipSerialization( blockType, BORDER_SUPPORT_KEY, 'color' )
|
|
204
|
-
) {
|
|
205
|
-
return props;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const { borderColor, style } = attributes;
|
|
209
|
-
const borderColorClass = getColorClassName( 'border-color', borderColor );
|
|
210
|
-
|
|
211
|
-
const newClassName = classnames( props.className, {
|
|
212
|
-
'has-border-color': borderColor || style?.border?.color,
|
|
213
|
-
[ borderColorClass ]: !! borderColorClass,
|
|
214
|
-
} );
|
|
215
|
-
|
|
216
|
-
// If we are clearing the last of the previous classes in `className`
|
|
217
|
-
// set it to `undefined` to avoid rendering empty DOM attributes.
|
|
218
|
-
props.className = newClassName ? newClassName : undefined;
|
|
219
|
-
|
|
220
|
-
return props;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Filters the registered block settings to apply border color styles and
|
|
225
|
-
* classnames to the block edit wrapper.
|
|
226
|
-
*
|
|
227
|
-
* @param {Object} settings Original block settings.
|
|
228
|
-
*
|
|
229
|
-
* @return {Object} Filtered block settings.
|
|
230
|
-
*/
|
|
231
|
-
function addEditProps( settings ) {
|
|
232
|
-
if (
|
|
233
|
-
! hasBorderSupport( settings, 'color' ) ||
|
|
234
|
-
shouldSkipSerialization( settings, BORDER_SUPPORT_KEY, 'color' )
|
|
235
|
-
) {
|
|
236
|
-
return settings;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const existingGetEditWrapperProps = settings.getEditWrapperProps;
|
|
240
|
-
settings.getEditWrapperProps = ( attributes ) => {
|
|
241
|
-
let props = {};
|
|
242
|
-
|
|
243
|
-
if ( existingGetEditWrapperProps ) {
|
|
244
|
-
props = existingGetEditWrapperProps( attributes );
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return addSaveProps( props, settings, attributes );
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
return settings;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* This adds inline styles for color palette colors.
|
|
255
|
-
* Ideally, this is not needed and themes should load their palettes on the editor.
|
|
256
|
-
*
|
|
257
|
-
* @param {Function} BlockListBlock Original component.
|
|
258
|
-
*
|
|
259
|
-
* @return {Function} Wrapped component.
|
|
260
|
-
*/
|
|
261
|
-
export const withBorderColorPaletteStyles = createHigherOrderComponent(
|
|
262
|
-
( BlockListBlock ) => ( props ) => {
|
|
263
|
-
const { name, attributes } = props;
|
|
264
|
-
const { borderColor } = attributes;
|
|
265
|
-
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
! hasBorderSupport( name, 'color' ) ||
|
|
269
|
-
shouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )
|
|
270
|
-
) {
|
|
271
|
-
return <BlockListBlock { ...props } />;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const extraStyles = {
|
|
275
|
-
borderColor: borderColor
|
|
276
|
-
? getColorObjectByAttributeValues( colors, borderColor )?.color
|
|
277
|
-
: undefined,
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
let wrapperProps = props.wrapperProps;
|
|
281
|
-
wrapperProps = {
|
|
282
|
-
...props.wrapperProps,
|
|
283
|
-
style: {
|
|
284
|
-
...extraStyles,
|
|
285
|
-
...props.wrapperProps?.style,
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
|
|
290
|
-
}
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
addFilter(
|
|
294
|
-
'blocks.registerBlockType',
|
|
295
|
-
'core/border/addAttributes',
|
|
296
|
-
addAttributes
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
addFilter(
|
|
300
|
-
'blocks.getSaveContent.extraProps',
|
|
301
|
-
'core/border/addSaveProps',
|
|
302
|
-
addSaveProps
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
addFilter(
|
|
306
|
-
'blocks.registerBlockType',
|
|
307
|
-
'core/border/addEditProps',
|
|
308
|
-
addEditProps
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
addFilter(
|
|
312
|
-
'editor.BlockListBlock',
|
|
313
|
-
'core/border/with-border-color-palette-styles',
|
|
314
|
-
withBorderColorPaletteStyles
|
|
315
|
-
);
|