@wordpress/block-editor 11.6.0 → 11.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +46 -55
- package/build/components/block-list/block-html.js +1 -3
- package/build/components/block-list/block-html.js.map +1 -1
- package/build/components/block-list/block.native.js +4 -3
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +11 -21
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +3 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-popover/inbetween.js +2 -9
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -23
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +1 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/caption/index.native.js +0 -1
- package/build/components/caption/index.native.js.map +1 -1
- package/build/components/date-format-picker/index.js +1 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/editor-styles/index.js +20 -2
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/global-styles/border-panel.js +15 -29
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +583 -0
- package/build/components/global-styles/color-panel.js.map +1 -0
- package/build/components/global-styles/dimensions-panel.js +23 -44
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +244 -0
- package/build/components/global-styles/effects-panel.js.map +1 -0
- package/build/components/global-styles/filters-panel.js +151 -0
- package/build/components/global-styles/filters-panel.js.map +1 -0
- package/build/components/global-styles/get-block-css-selector.js +118 -0
- package/build/components/global-styles/get-block-css-selector.js.map +1 -0
- package/build/components/global-styles/hooks.js +60 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +46 -2
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +9 -35
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +173 -91
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/iframe/index.js +1 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-size-control/index.js +8 -5
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/image-size-control/use-dimension-handler.js +5 -3
- package/build/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build/components/index.js +16 -0
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +4 -2
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +43 -7
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build/components/inspector-controls-tabs/utils.js +5 -3
- package/build/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build/components/line-height-control/index.js +15 -1
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/appender.js +105 -0
- package/build/components/list-view/appender.js.map +1 -0
- package/build/components/list-view/block.js +6 -5
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +25 -5
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +56 -14
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +7 -3
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +8 -2
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-replace-flow/index.js +13 -4
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +6 -1
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +17 -14
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/resizable-box-popover/index.js +38 -0
- package/build/components/resizable-box-popover/index.js.map +1 -0
- package/build/components/rich-text/format-edit.js +2 -30
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/index.js +0 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +7 -11
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +8 -0
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/writing-flow/use-input.js +4 -8
- package/build/components/writing-flow/use-input.js.map +1 -1
- package/build/hooks/anchor.js +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +1 -2
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +92 -229
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/content-lock-ui.js +4 -2
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/{color-panel.js → contrast-checker.js} +11 -49
- package/build/hooks/contrast-checker.js.map +1 -0
- package/build/hooks/dimensions.js +0 -1
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +92 -64
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/margin.js +27 -17
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +19 -9
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/position.js +2 -2
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/style.js +23 -26
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +0 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +28 -76
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/grid.js +165 -0
- package/build/layouts/grid.js.map +1 -0
- package/build/layouts/index.js +3 -1
- package/build/layouts/index.js.map +1 -1
- package/build/layouts/utils.js +3 -2
- package/build/layouts/utils.js.map +1 -1
- package/build/private-apis.js +7 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/utils/object.js +76 -0
- package/build/utils/object.js.map +1 -0
- package/build-module/components/block-list/block-html.js +1 -3
- package/build-module/components/block-list/block-html.js.map +1 -1
- package/build-module/components/block-list/block.native.js +4 -3
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +11 -19
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +2 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +2 -9
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -22
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -9
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/caption/index.native.js +0 -1
- package/build-module/components/caption/index.native.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +1 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/editor-styles/index.js +19 -2
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +15 -29
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +554 -0
- package/build-module/components/global-styles/color-panel.js.map +1 -0
- package/build-module/components/global-styles/dimensions-panel.js +22 -44
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +228 -0
- package/build-module/components/global-styles/effects-panel.js.map +1 -0
- package/build-module/components/global-styles/filters-panel.js +139 -0
- package/build-module/components/global-styles/filters-panel.js.map +1 -0
- package/build-module/components/global-styles/get-block-css-selector.js +109 -0
- package/build-module/components/global-styles/get-block-css-selector.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +58 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +5 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +8 -35
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +175 -93
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-size-control/index.js +8 -5
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/image-size-control/use-dimension-handler.js +5 -3
- package/build-module/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +5 -2
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +42 -7
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/utils.js +4 -3
- package/build-module/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build-module/components/line-height-control/index.js +15 -1
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/appender.js +88 -0
- package/build-module/components/list-view/appender.js.map +1 -0
- package/build-module/components/list-view/block.js +6 -4
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +22 -5
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +50 -13
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +7 -3
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +8 -4
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +12 -4
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +5 -1
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +17 -14
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/resizable-box-popover/index.js +26 -0
- package/build-module/components/resizable-box-popover/index.js.map +1 -0
- package/build-module/components/rich-text/format-edit.js +3 -31
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/index.js +0 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +7 -10
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +7 -0
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/writing-flow/use-input.js +4 -8
- package/build-module/components/writing-flow/use-input.js.map +1 -1
- package/build-module/hooks/anchor.js +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +1 -2
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +90 -232
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +4 -2
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/{color-panel.js → contrast-checker.js} +10 -44
- package/build-module/hooks/contrast-checker.js.map +1 -0
- package/build-module/hooks/dimensions.js +0 -1
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +91 -65
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/margin.js +29 -18
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +21 -10
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/position.js +3 -3
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/style.js +23 -26
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +0 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +27 -74
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/grid.js +151 -0
- package/build-module/layouts/grid.js.map +1 -0
- package/build-module/layouts/index.js +2 -1
- package/build-module/layouts/index.js.map +1 -1
- package/build-module/layouts/utils.js +3 -2
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/private-apis.js +5 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/utils/object.js +69 -0
- package/build-module/utils/object.js.map +1 -0
- package/build-style/style-rtl.css +77 -16
- package/build-style/style.css +77 -16
- package/package.json +31 -31
- package/src/components/block-draggable/content.scss +1 -1
- package/src/components/block-inspector/style.scss +6 -4
- package/src/components/block-list/block-html.js +1 -1
- package/src/components/block-list/block.native.js +3 -2
- package/src/components/block-list/index.native.js +19 -38
- package/src/components/block-list/use-in-between-inserter.js +4 -1
- package/src/components/block-popover/inbetween.js +2 -13
- package/src/components/block-preview/auto.js +2 -17
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -12
- package/src/components/caption/index.native.js +0 -1
- package/src/components/colors-gradients/style.scss +8 -8
- package/src/components/date-format-picker/index.js +1 -1
- package/src/components/editor-styles/index.js +29 -1
- package/src/components/global-styles/README.md +129 -16
- package/src/components/global-styles/border-panel.js +13 -32
- package/src/components/global-styles/color-panel.js +706 -0
- package/src/components/global-styles/dimensions-panel.js +43 -55
- package/src/components/global-styles/effects-panel.js +228 -0
- package/src/components/global-styles/filters-panel.js +157 -0
- package/src/components/global-styles/get-block-css-selector.js +118 -0
- package/src/components/global-styles/hooks.js +90 -0
- package/src/components/global-styles/index.js +4 -1
- package/src/components/global-styles/style.scss +42 -0
- package/src/components/global-styles/test/use-global-styles-output.js +34 -5
- package/src/components/global-styles/typography-panel.js +26 -51
- package/src/components/global-styles/use-global-styles-output.js +188 -89
- package/src/components/global-styles/utils.js +3 -0
- package/src/components/iframe/index.js +1 -1
- package/src/components/image-size-control/index.js +4 -3
- package/src/components/image-size-control/test/index.js +2 -2
- package/src/components/image-size-control/use-dimension-handler.js +4 -3
- package/src/components/index.js +4 -1
- package/src/components/inner-blocks/README.md +1 -1
- package/src/components/inserter/block-patterns-tab.js +3 -1
- package/src/components/inspector-controls-tabs/position-controls-panel.js +40 -9
- package/src/components/inspector-controls-tabs/utils.js +4 -3
- package/src/components/line-height-control/index.js +10 -1
- package/src/components/list-view/README.md +2 -0
- package/src/components/list-view/appender.js +101 -0
- package/src/components/list-view/block.js +6 -4
- package/src/components/list-view/branch.js +30 -1
- package/src/components/list-view/index.js +60 -11
- package/src/components/list-view/style.scss +22 -1
- package/src/components/list-view/test/use-list-view-drop-zone.js +188 -0
- package/src/components/list-view/use-list-view-client-ids.js +5 -3
- package/src/components/list-view/use-list-view-drop-zone.js +9 -3
- package/src/components/media-replace-flow/index.js +36 -24
- package/src/components/media-replace-flow/style.scss +5 -2
- package/src/components/off-canvas-editor/block-contents.js +4 -0
- package/src/components/off-canvas-editor/index.js +15 -11
- package/src/components/resizable-box-popover/index.js +27 -0
- package/src/components/rich-text/format-edit.js +2 -32
- package/src/components/rich-text/index.js +0 -1
- package/src/components/rich-text/index.native.js +2 -5
- package/src/components/spacing-sizes-control/spacing-input-control.js +10 -0
- package/src/components/spacing-sizes-control/style.scss +7 -7
- package/src/components/writing-flow/use-input.js +4 -5
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +1 -2
- package/src/hooks/color.js +120 -296
- package/src/hooks/content-lock-ui.js +6 -2
- package/src/hooks/{color-panel.js → contrast-checker.js} +10 -46
- package/src/hooks/dimensions.js +0 -1
- package/src/hooks/duotone.js +121 -76
- package/src/hooks/margin.js +31 -26
- package/src/hooks/padding.js +24 -18
- package/src/hooks/position.js +3 -3
- package/src/hooks/style.js +29 -28
- package/src/hooks/test/utils.js +0 -104
- package/src/hooks/typography.js +0 -1
- package/src/hooks/utils.js +31 -74
- package/src/layouts/grid.js +172 -0
- package/src/layouts/index.js +2 -1
- package/src/layouts/test/grid.js +21 -0
- package/src/layouts/utils.js +2 -2
- package/src/private-apis.js +4 -0
- package/src/store/actions.js +1 -1
- package/src/style.scss +1 -0
- package/src/utils/object.js +69 -0
- package/src/utils/test/object.js +145 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/rich-text/use-native-props.js +0 -11
- package/build/components/rich-text/use-native-props.js.map +0 -1
- package/build/components/rich-text/use-native-props.native.js +0 -24
- package/build/components/rich-text/use-native-props.native.js.map +0 -1
- package/build/hooks/color-panel.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.js +0 -4
- package/build-module/components/rich-text/use-native-props.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.native.js +0 -15
- package/build-module/components/rich-text/use-native-props.native.js.map +0 -1
- package/build-module/hooks/color-panel.js.map +0 -1
- package/src/components/rich-text/use-native-props.js +0 -3
- package/src/components/rich-text/use-native-props.native.js +0 -17
package/src/hooks/color.js
CHANGED
|
@@ -8,8 +8,7 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import { addFilter } from '@wordpress/hooks';
|
|
10
10
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
11
|
-
import {
|
|
12
|
-
import { useRef, useEffect, useMemo, Platform } from '@wordpress/element';
|
|
11
|
+
import { useMemo, Platform, useCallback } from '@wordpress/element';
|
|
13
12
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -17,22 +16,22 @@ import { createHigherOrderComponent } from '@wordpress/compose';
|
|
|
17
16
|
*/
|
|
18
17
|
import {
|
|
19
18
|
getColorClassName,
|
|
20
|
-
getColorObjectByColorValue,
|
|
21
19
|
getColorObjectByAttributeValues,
|
|
22
20
|
} from '../components/colors';
|
|
23
|
-
import {
|
|
24
|
-
__experimentalGetGradientClass,
|
|
25
|
-
getGradientValueBySlug,
|
|
26
|
-
getGradientSlugByValue,
|
|
27
|
-
} from '../components/gradients';
|
|
21
|
+
import { __experimentalGetGradientClass } from '../components/gradients';
|
|
28
22
|
import {
|
|
29
23
|
cleanEmptyObject,
|
|
30
24
|
transformStyles,
|
|
31
|
-
immutableSet,
|
|
32
25
|
shouldSkipSerialization,
|
|
26
|
+
useBlockSettings,
|
|
33
27
|
} from './utils';
|
|
34
|
-
import ColorPanel from './color-panel';
|
|
35
28
|
import useSetting from '../components/use-setting';
|
|
29
|
+
import InspectorControls from '../components/inspector-controls';
|
|
30
|
+
import {
|
|
31
|
+
useHasColorPanel,
|
|
32
|
+
default as StylesColorPanel,
|
|
33
|
+
} from '../components/global-styles/color-panel';
|
|
34
|
+
import BlockColorContrastChecker from './contrast-checker';
|
|
36
35
|
|
|
37
36
|
export const COLOR_SUPPORT_KEY = 'color';
|
|
38
37
|
|
|
@@ -83,60 +82,6 @@ const hasTextColorSupport = ( blockType ) => {
|
|
|
83
82
|
return colorSupport && colorSupport.text !== false;
|
|
84
83
|
};
|
|
85
84
|
|
|
86
|
-
/**
|
|
87
|
-
* Clears a single color property from a style object.
|
|
88
|
-
*
|
|
89
|
-
* @param {Array} path Path to color property to clear within styles object.
|
|
90
|
-
* @param {Object} style Block attributes style object.
|
|
91
|
-
* @return {Object} Styles with the color property omitted.
|
|
92
|
-
*/
|
|
93
|
-
const clearColorFromStyles = ( path, style ) =>
|
|
94
|
-
cleanEmptyObject( immutableSet( style, path, undefined ) );
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Clears text color related properties from supplied attributes.
|
|
98
|
-
*
|
|
99
|
-
* @param {Object} attributes Block attributes.
|
|
100
|
-
* @return {Object} Update block attributes with text color properties omitted.
|
|
101
|
-
*/
|
|
102
|
-
const resetAllTextFilter = ( attributes ) => ( {
|
|
103
|
-
textColor: undefined,
|
|
104
|
-
style: clearColorFromStyles( [ 'color', 'text' ], attributes.style ),
|
|
105
|
-
} );
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Clears link color related properties from supplied attributes.
|
|
109
|
-
*
|
|
110
|
-
* @param {Object} attributes Block attributes.
|
|
111
|
-
* @return {Object} Update block attributes with link color properties omitted.
|
|
112
|
-
*/
|
|
113
|
-
const resetAllLinkFilter = ( attributes ) => ( {
|
|
114
|
-
style: clearColorFromStyles(
|
|
115
|
-
[ 'elements', 'link', 'color', 'text' ],
|
|
116
|
-
attributes.style
|
|
117
|
-
),
|
|
118
|
-
} );
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Clears all background color related properties including gradients from
|
|
122
|
-
* supplied block attributes.
|
|
123
|
-
*
|
|
124
|
-
* @param {Object} attributes Block attributes.
|
|
125
|
-
* @return {Object} Block attributes with background and gradient omitted.
|
|
126
|
-
*/
|
|
127
|
-
const clearBackgroundAndGradient = ( attributes ) => ( {
|
|
128
|
-
backgroundColor: undefined,
|
|
129
|
-
gradient: undefined,
|
|
130
|
-
style: {
|
|
131
|
-
...attributes.style,
|
|
132
|
-
color: {
|
|
133
|
-
...attributes.style?.color,
|
|
134
|
-
background: undefined,
|
|
135
|
-
gradient: undefined,
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
} );
|
|
139
|
-
|
|
140
85
|
/**
|
|
141
86
|
* Filters registered block settings, extending attributes to include
|
|
142
87
|
* `backgroundColor` and `textColor` attribute.
|
|
@@ -273,194 +218,112 @@ export function addEditProps( settings ) {
|
|
|
273
218
|
return settings;
|
|
274
219
|
}
|
|
275
220
|
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
],
|
|
306
|
-
[ userPalette, themePalette, defaultPalette ]
|
|
307
|
-
);
|
|
308
|
-
const userGradientPalette = useSetting( 'color.gradients.custom' );
|
|
309
|
-
const themeGradientPalette = useSetting( 'color.gradients.theme' );
|
|
310
|
-
const defaultGradientPalette = useSetting( 'color.gradients.default' );
|
|
311
|
-
const allGradients = useMemo(
|
|
312
|
-
() => [
|
|
313
|
-
...( userGradientPalette || [] ),
|
|
314
|
-
...( themeGradientPalette || [] ),
|
|
315
|
-
...( defaultGradientPalette || [] ),
|
|
316
|
-
],
|
|
317
|
-
[ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
|
|
318
|
-
);
|
|
319
|
-
const areCustomSolidsEnabled = useSetting( 'color.custom' );
|
|
320
|
-
const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
|
|
321
|
-
const isBackgroundEnabled = useSetting( 'color.background' );
|
|
322
|
-
const isLinkEnabled = useSetting( 'color.link' );
|
|
323
|
-
const isTextEnabled = useSetting( 'color.text' );
|
|
324
|
-
|
|
325
|
-
const solidsEnabled =
|
|
326
|
-
areCustomSolidsEnabled || ! themePalette || themePalette?.length > 0;
|
|
327
|
-
|
|
328
|
-
const gradientsEnabled =
|
|
329
|
-
areCustomGradientsEnabled ||
|
|
330
|
-
! themeGradientPalette ||
|
|
331
|
-
themeGradientPalette?.length > 0;
|
|
332
|
-
|
|
333
|
-
// Shouldn't be needed but right now the ColorGradientsPanel
|
|
334
|
-
// can trigger both onChangeColor and onChangeBackground
|
|
335
|
-
// synchronously causing our two callbacks to override changes
|
|
336
|
-
// from each other.
|
|
337
|
-
const localAttributes = useRef( attributes );
|
|
338
|
-
useEffect( () => {
|
|
339
|
-
localAttributes.current = attributes;
|
|
340
|
-
}, [ attributes ] );
|
|
341
|
-
|
|
342
|
-
if ( ! hasColorSupport( blockName ) ) {
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const hasLinkColor =
|
|
347
|
-
hasLinkColorSupport( blockName ) && isLinkEnabled && solidsEnabled;
|
|
348
|
-
const hasTextColor =
|
|
349
|
-
hasTextColorSupport( blockName ) && isTextEnabled && solidsEnabled;
|
|
350
|
-
const hasBackgroundColor =
|
|
351
|
-
hasBackgroundColorSupport( blockName ) &&
|
|
352
|
-
isBackgroundEnabled &&
|
|
353
|
-
solidsEnabled;
|
|
354
|
-
const hasGradientColor =
|
|
355
|
-
hasGradientSupport( blockName ) && gradientsEnabled;
|
|
356
|
-
|
|
357
|
-
if (
|
|
358
|
-
! hasLinkColor &&
|
|
359
|
-
! hasTextColor &&
|
|
360
|
-
! hasBackgroundColor &&
|
|
361
|
-
! hasGradientColor
|
|
362
|
-
) {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
221
|
+
function styleToAttributes( style ) {
|
|
222
|
+
const textColorValue = style?.color?.text;
|
|
223
|
+
const textColorSlug = textColorValue?.startsWith( 'var:preset|color|' )
|
|
224
|
+
? textColorValue.substring( 'var:preset|color|'.length )
|
|
225
|
+
: undefined;
|
|
226
|
+
const backgroundColorValue = style?.color?.background;
|
|
227
|
+
const backgroundColorSlug = backgroundColorValue?.startsWith(
|
|
228
|
+
'var:preset|color|'
|
|
229
|
+
)
|
|
230
|
+
? backgroundColorValue.substring( 'var:preset|color|'.length )
|
|
231
|
+
: undefined;
|
|
232
|
+
const gradientValue = style?.color?.gradient;
|
|
233
|
+
const gradientSlug = gradientValue?.startsWith( 'var:preset|gradient|' )
|
|
234
|
+
? gradientValue.substring( 'var:preset|gradient|'.length )
|
|
235
|
+
: undefined;
|
|
236
|
+
const updatedStyle = { ...style };
|
|
237
|
+
updatedStyle.color = {
|
|
238
|
+
...updatedStyle.color,
|
|
239
|
+
text: textColorSlug ? undefined : textColorValue,
|
|
240
|
+
background: backgroundColorSlug ? undefined : backgroundColorValue,
|
|
241
|
+
gradient: gradientSlug ? undefined : gradientValue,
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
style: cleanEmptyObject( updatedStyle ),
|
|
245
|
+
textColor: textColorSlug,
|
|
246
|
+
backgroundColor: backgroundColorSlug,
|
|
247
|
+
gradient: gradientSlug,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
365
250
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
251
|
+
function attributesToStyle( attributes ) {
|
|
252
|
+
return {
|
|
253
|
+
...attributes.style,
|
|
254
|
+
color: {
|
|
255
|
+
...attributes.style?.color,
|
|
256
|
+
text: attributes.textColor
|
|
257
|
+
? 'var:preset|color|' + attributes.textColor
|
|
258
|
+
: attributes.style?.color?.text,
|
|
259
|
+
background: attributes.backgroundColor
|
|
260
|
+
? 'var:preset|color|' + attributes.backgroundColor
|
|
261
|
+
: attributes.style?.color?.background,
|
|
262
|
+
gradient: attributes.gradient
|
|
263
|
+
? 'var:preset|gradient|' + attributes.gradient
|
|
264
|
+
: attributes.style?.color?.gradient,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
373
268
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
...
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
}
|
|
269
|
+
function ColorInspectorControl( { children, resetAllFilter } ) {
|
|
270
|
+
const attributesResetAllFilter = useCallback(
|
|
271
|
+
( attributes ) => {
|
|
272
|
+
const existingStyle = attributesToStyle( attributes );
|
|
273
|
+
const updatedStyle = resetAllFilter( existingStyle );
|
|
274
|
+
return {
|
|
275
|
+
...attributes,
|
|
276
|
+
...styleToAttributes( updatedStyle ),
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
[ resetAllFilter ]
|
|
280
|
+
);
|
|
384
281
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
282
|
+
return (
|
|
283
|
+
<InspectorControls
|
|
284
|
+
group="color"
|
|
285
|
+
resetAllFilter={ attributesResetAllFilter }
|
|
286
|
+
>
|
|
287
|
+
{ children }
|
|
288
|
+
</InspectorControls>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
390
291
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
292
|
+
export function ColorEdit( props ) {
|
|
293
|
+
const { clientId, name, attributes, setAttributes } = props;
|
|
294
|
+
const settings = useBlockSettings( name );
|
|
295
|
+
const isEnabled = useHasColorPanel( settings );
|
|
296
|
+
const value = useMemo( () => {
|
|
297
|
+
return attributesToStyle( {
|
|
298
|
+
style: attributes.style,
|
|
299
|
+
textColor: attributes.textColor,
|
|
300
|
+
backgroundColor: attributes.backgroundColor,
|
|
301
|
+
gradient: attributes.gradient,
|
|
302
|
+
} );
|
|
303
|
+
}, [
|
|
304
|
+
attributes.style,
|
|
305
|
+
attributes.textColor,
|
|
306
|
+
attributes.backgroundColor,
|
|
307
|
+
attributes.gradient,
|
|
308
|
+
] );
|
|
397
309
|
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
let newAttributes;
|
|
401
|
-
if ( slug ) {
|
|
402
|
-
const newStyle = {
|
|
403
|
-
...localAttributes.current?.style,
|
|
404
|
-
color: {
|
|
405
|
-
...localAttributes.current?.style?.color,
|
|
406
|
-
gradient: undefined,
|
|
407
|
-
},
|
|
408
|
-
};
|
|
409
|
-
newAttributes = {
|
|
410
|
-
style: cleanEmptyObject( newStyle ),
|
|
411
|
-
gradient: slug,
|
|
412
|
-
};
|
|
413
|
-
} else {
|
|
414
|
-
const newStyle = {
|
|
415
|
-
...localAttributes.current?.style,
|
|
416
|
-
color: {
|
|
417
|
-
...localAttributes.current?.style?.color,
|
|
418
|
-
gradient: value,
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
newAttributes = {
|
|
422
|
-
style: cleanEmptyObject( newStyle ),
|
|
423
|
-
gradient: undefined,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
props.setAttributes( newAttributes );
|
|
427
|
-
localAttributes.current = {
|
|
428
|
-
...localAttributes.current,
|
|
429
|
-
...newAttributes,
|
|
430
|
-
};
|
|
310
|
+
const onChange = ( newStyle ) => {
|
|
311
|
+
setAttributes( styleToAttributes( newStyle ) );
|
|
431
312
|
};
|
|
432
313
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
? `var:preset|color|${ colorObject.slug }`
|
|
437
|
-
: value;
|
|
438
|
-
|
|
439
|
-
const newStyle = cleanEmptyObject(
|
|
440
|
-
immutableSet(
|
|
441
|
-
localAttributes.current?.style,
|
|
442
|
-
[ 'elements', 'link', 'color', 'text' ],
|
|
443
|
-
newLinkColorValue
|
|
444
|
-
)
|
|
445
|
-
);
|
|
446
|
-
props.setAttributes( { style: newStyle } );
|
|
447
|
-
localAttributes.current = {
|
|
448
|
-
...localAttributes.current,
|
|
449
|
-
...{ style: newStyle },
|
|
450
|
-
};
|
|
451
|
-
};
|
|
314
|
+
if ( ! isEnabled ) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
452
317
|
|
|
453
|
-
const
|
|
318
|
+
const defaultControls = getBlockSupport( props.name, [
|
|
454
319
|
COLOR_SUPPORT_KEY,
|
|
455
320
|
'__experimentalDefaultControls',
|
|
456
321
|
] );
|
|
457
322
|
|
|
458
323
|
const enableContrastChecking =
|
|
459
324
|
Platform.OS === 'web' &&
|
|
460
|
-
! gradient &&
|
|
461
|
-
|
|
462
|
-
hasBackgroundColor &&
|
|
463
|
-
( hasLinkColor || hasTextColor ) &&
|
|
325
|
+
! value?.color?.gradient &&
|
|
326
|
+
( settings?.color?.text || settings?.color?.link ) &&
|
|
464
327
|
// Contrast checking is enabled by default.
|
|
465
328
|
// Deactivating it requires `enableContrastChecker` to have
|
|
466
329
|
// an explicit value of `false`.
|
|
@@ -471,64 +334,25 @@ export function ColorEdit( props ) {
|
|
|
471
334
|
] );
|
|
472
335
|
|
|
473
336
|
return (
|
|
474
|
-
<
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
: [] ),
|
|
494
|
-
...( hasBackgroundColor || hasGradientColor
|
|
495
|
-
? [
|
|
496
|
-
{
|
|
497
|
-
label: __( 'Background' ),
|
|
498
|
-
onColorChange: hasBackgroundColor
|
|
499
|
-
? onChangeColor( 'background' )
|
|
500
|
-
: undefined,
|
|
501
|
-
colorValue: getColorObjectByAttributeValues(
|
|
502
|
-
allSolids,
|
|
503
|
-
backgroundColor,
|
|
504
|
-
style?.color?.background
|
|
505
|
-
).color,
|
|
506
|
-
gradientValue,
|
|
507
|
-
onGradientChange: hasGradientColor
|
|
508
|
-
? onChangeGradient
|
|
509
|
-
: undefined,
|
|
510
|
-
isShownByDefault:
|
|
511
|
-
defaultColorControls?.background,
|
|
512
|
-
resetAllFilter: clearBackgroundAndGradient,
|
|
513
|
-
},
|
|
514
|
-
]
|
|
515
|
-
: [] ),
|
|
516
|
-
...( hasLinkColor
|
|
517
|
-
? [
|
|
518
|
-
{
|
|
519
|
-
label: __( 'Link' ),
|
|
520
|
-
onColorChange: onChangeLinkColor,
|
|
521
|
-
colorValue: getLinkColorFromAttributeValue(
|
|
522
|
-
allSolids,
|
|
523
|
-
style?.elements?.link?.color?.text
|
|
524
|
-
),
|
|
525
|
-
isShownByDefault: defaultColorControls?.link,
|
|
526
|
-
resetAllFilter: resetAllLinkFilter,
|
|
527
|
-
},
|
|
528
|
-
]
|
|
529
|
-
: [] ),
|
|
530
|
-
] }
|
|
531
|
-
/>
|
|
337
|
+
<StylesColorPanel
|
|
338
|
+
as={ ColorInspectorControl }
|
|
339
|
+
panelId={ clientId }
|
|
340
|
+
settings={ settings }
|
|
341
|
+
value={ value }
|
|
342
|
+
onChange={ onChange }
|
|
343
|
+
defaultControls={ defaultControls }
|
|
344
|
+
enableContrastChecker={
|
|
345
|
+
false !==
|
|
346
|
+
getBlockSupport( props.name, [
|
|
347
|
+
COLOR_SUPPORT_KEY,
|
|
348
|
+
'enableContrastChecker',
|
|
349
|
+
] )
|
|
350
|
+
}
|
|
351
|
+
>
|
|
352
|
+
{ enableContrastChecking && (
|
|
353
|
+
<BlockColorContrastChecker clientId={ clientId } />
|
|
354
|
+
) }
|
|
355
|
+
</StylesColorPanel>
|
|
532
356
|
);
|
|
533
357
|
}
|
|
534
358
|
|
|
@@ -104,9 +104,13 @@ export const withBlockControls = createHigherOrderComponent(
|
|
|
104
104
|
return <BlockEdit { ...props } />;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
const showStopEditingAsBlocks = isEditingAsBlocks && ! isContentLocked;
|
|
108
|
+
const showStartEditingAsBlocks =
|
|
109
|
+
! isEditingAsBlocks && isContentLocked && props.isSelected;
|
|
110
|
+
|
|
107
111
|
return (
|
|
108
112
|
<>
|
|
109
|
-
{
|
|
113
|
+
{ showStopEditingAsBlocks && (
|
|
110
114
|
<>
|
|
111
115
|
<StopEditingAsBlocksOnOutsideSelect
|
|
112
116
|
clientId={ props.clientId }
|
|
@@ -123,7 +127,7 @@ export const withBlockControls = createHigherOrderComponent(
|
|
|
123
127
|
</BlockControls>
|
|
124
128
|
</>
|
|
125
129
|
) }
|
|
126
|
-
{
|
|
130
|
+
{ showStartEditingAsBlocks && (
|
|
127
131
|
<BlockSettingsMenuControls>
|
|
128
132
|
{ ( { onClose } ) => (
|
|
129
133
|
<MenuItem
|
|
@@ -6,45 +6,23 @@ import { useState, useEffect } from '@wordpress/element';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';
|
|
10
9
|
import ContrastChecker from '../components/contrast-checker';
|
|
11
|
-
import InspectorControls from '../components/inspector-controls';
|
|
12
|
-
import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
|
|
13
10
|
import { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs';
|
|
14
11
|
|
|
15
12
|
function getComputedStyle( node ) {
|
|
16
13
|
return node.ownerDocument.defaultView.getComputedStyle( node );
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
export default function
|
|
20
|
-
enableAlpha = false,
|
|
21
|
-
settings,
|
|
22
|
-
clientId,
|
|
23
|
-
enableContrastChecking = true,
|
|
24
|
-
} ) {
|
|
16
|
+
export default function BlockColorContrastChecker( { clientId } ) {
|
|
25
17
|
const [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();
|
|
26
18
|
const [ detectedColor, setDetectedColor ] = useState();
|
|
27
19
|
const [ detectedLinkColor, setDetectedLinkColor ] = useState();
|
|
28
20
|
const ref = useBlockRef( clientId );
|
|
29
|
-
const definedColors = settings.filter( ( setting ) => setting?.colorValue );
|
|
30
21
|
|
|
22
|
+
// There are so many things that can change the color of a block
|
|
23
|
+
// So we perform this check on every render.
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
25
|
useEffect( () => {
|
|
32
|
-
if ( ! enableContrastChecking ) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if ( ! definedColors.length ) {
|
|
36
|
-
if ( detectedBackgroundColor ) {
|
|
37
|
-
setDetectedBackgroundColor();
|
|
38
|
-
}
|
|
39
|
-
if ( detectedColor ) {
|
|
40
|
-
setDetectedColor();
|
|
41
|
-
}
|
|
42
|
-
if ( detectedLinkColor ) {
|
|
43
|
-
setDetectedColor();
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
26
|
if ( ! ref.current ) {
|
|
49
27
|
return;
|
|
50
28
|
}
|
|
@@ -72,26 +50,12 @@ export default function ColorPanel( {
|
|
|
72
50
|
setDetectedBackgroundColor( backgroundColor );
|
|
73
51
|
} );
|
|
74
52
|
|
|
75
|
-
const colorGradientSettings = useMultipleOriginColorsAndGradients();
|
|
76
|
-
|
|
77
53
|
return (
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
__experimentalIsRenderedInSidebar
|
|
85
|
-
{ ...colorGradientSettings }
|
|
86
|
-
/>
|
|
87
|
-
{ enableContrastChecking && (
|
|
88
|
-
<ContrastChecker
|
|
89
|
-
backgroundColor={ detectedBackgroundColor }
|
|
90
|
-
textColor={ detectedColor }
|
|
91
|
-
enableAlphaChecker={ enableAlpha }
|
|
92
|
-
linkColor={ detectedLinkColor }
|
|
93
|
-
/>
|
|
94
|
-
) }
|
|
95
|
-
</InspectorControls>
|
|
54
|
+
<ContrastChecker
|
|
55
|
+
backgroundColor={ detectedBackgroundColor }
|
|
56
|
+
textColor={ detectedColor }
|
|
57
|
+
enableAlphaChecker
|
|
58
|
+
linkColor={ detectedLinkColor }
|
|
59
|
+
/>
|
|
96
60
|
);
|
|
97
61
|
}
|
package/src/hooks/dimensions.js
CHANGED