@wordpress/block-editor 15.19.1-next.v.202605131032.0 → 15.20.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 +15 -1
- package/build/components/block-card/index.cjs +51 -41
- package/build/components/block-card/index.cjs.map +3 -3
- package/build/components/block-heading-level-dropdown/heading-level-icon.cjs.map +3 -3
- package/build/components/block-icon/index.cjs +7 -1
- package/build/components/block-icon/index.cjs.map +3 -3
- package/build/components/block-inspector/index.cjs +156 -11
- package/build/components/block-inspector/index.cjs.map +3 -3
- package/build/components/block-inspector/inspector-pre-tabs-slot-fill.cjs +38 -0
- package/build/components/block-inspector/inspector-pre-tabs-slot-fill.cjs.map +7 -0
- package/build/components/block-list/use-block-props/index.cjs +1 -1
- package/build/components/block-list/use-block-props/index.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-focus-handler.cjs +3 -4
- package/build/components/block-list/use-block-props/use-focus-handler.cjs.map +3 -3
- package/build/components/block-list/use-block-props/use-is-hovered.cjs +24 -14
- package/build/components/block-list/use-block-props/use-is-hovered.cjs.map +3 -3
- package/build/components/block-lock/modal.cjs.map +3 -3
- package/build/components/block-patterns-list/index.cjs +13 -2
- package/build/components/block-patterns-list/index.cjs.map +2 -2
- package/build/components/block-popover/index.cjs +13 -3
- package/build/components/block-popover/index.cjs.map +2 -2
- package/build/components/block-toolbar/switch-section-style.cjs.map +3 -3
- package/build/components/block-visibility/modal.cjs.map +3 -3
- package/build/components/block-visibility/viewport-visibility-info.cjs.map +3 -3
- package/build/components/colors-gradients/control.cjs +7 -4
- package/build/components/colors-gradients/control.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs +24 -22
- package/build/components/global-styles/advanced-panel.cjs.map +3 -3
- package/build/components/global-styles/color-panel.cjs +95 -58
- package/build/components/global-styles/color-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +11 -5
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/index.cjs +3 -0
- package/build/components/global-styles/index.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs +38 -26
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/global-styles/state-control-badges.cjs +69 -0
- package/build/components/global-styles/state-control-badges.cjs.map +7 -0
- package/build/components/global-styles/state-control.cjs +54 -63
- package/build/components/global-styles/state-control.cjs.map +3 -3
- package/build/components/iframe/index.cjs +0 -3
- package/build/components/iframe/index.cjs.map +2 -2
- package/build/components/iframe/use-scale-canvas.cjs +4 -1
- package/build/components/iframe/use-scale-canvas.cjs.map +2 -2
- package/build/components/inserter/hooks/use-patterns-state.cjs +4 -6
- package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
- package/build/components/inserter/index.cjs +1 -0
- package/build/components/inserter/index.cjs.map +2 -2
- package/build/components/inserter/media-tab/media-preview.cjs +27 -18
- package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
- package/build/components/inserter/media-tab/utils.cjs +1 -1
- package/build/components/inserter/media-tab/utils.cjs.map +2 -2
- package/build/components/inserter/panel.cjs.map +3 -3
- package/build/components/inspector-controls/block-support-tools-panel.cjs +10 -2
- package/build/components/inspector-controls/block-support-tools-panel.cjs.map +2 -2
- package/build/components/inspector-controls/fill.cjs +14 -4
- package/build/components/inspector-controls/fill.cjs.map +2 -2
- package/build/components/inspector-controls/groups.cjs +2 -0
- package/build/components/inspector-controls/groups.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/index.cjs +13 -8
- package/build/components/inspector-controls-tabs/index.cjs.map +3 -3
- package/build/components/inspector-controls-tabs/settings-tab.cjs +1 -4
- package/build/components/inspector-controls-tabs/settings-tab.cjs.map +3 -3
- package/build/components/inspector-controls-tabs/styles-tab.cjs +9 -0
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +3 -3
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +11 -5
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
- package/build/components/list-view/block-select-button.cjs +20 -8
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +2 -1
- package/build/components/list-view/block.cjs.map +2 -2
- package/build/components/preset-input-control/custom-value-controls.cjs +10 -1
- package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
- package/build/components/preset-input-control/index.cjs.map +3 -3
- package/build/components/provider/use-media-upload-settings.cjs +1 -0
- package/build/components/provider/use-media-upload-settings.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/enter.cjs +9 -2
- package/build/components/rich-text/event-listeners/enter.cjs.map +3 -3
- package/build/components/rich-text/event-listeners/paste-handler.cjs +4 -4
- package/build/components/rich-text/event-listeners/paste-handler.cjs.map +3 -3
- package/build/hooks/background.cjs +13 -3
- package/build/hooks/background.cjs.map +2 -2
- package/build/hooks/block-fields/link/index.cjs.map +3 -3
- package/build/hooks/block-fields/media/index.cjs.map +3 -3
- package/build/hooks/block-style-state.cjs +112 -0
- package/build/hooks/block-style-state.cjs.map +7 -0
- package/build/hooks/border.cjs +13 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/color.cjs +28 -9
- package/build/hooks/color.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +15 -6
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +147 -61
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/layout.cjs +263 -56
- package/build/hooks/layout.cjs.map +3 -3
- package/build/hooks/state-utils.cjs +94 -0
- package/build/hooks/state-utils.cjs.map +7 -0
- package/build/hooks/states.cjs +124 -0
- package/build/hooks/states.cjs.map +7 -0
- package/build/hooks/style.cjs +304 -17
- package/build/hooks/style.cjs.map +3 -3
- package/build/hooks/typography.cjs +14 -5
- package/build/hooks/typography.cjs.map +2 -2
- package/build/layouts/constrained.cjs +128 -55
- package/build/layouts/constrained.cjs.map +3 -3
- package/build/layouts/flex.cjs +119 -31
- package/build/layouts/flex.cjs.map +3 -3
- package/build/layouts/grid.cjs +103 -40
- package/build/layouts/grid.cjs.map +3 -3
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build/store/private-actions.cjs +18 -0
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-keys.cjs +10 -2
- package/build/store/private-keys.cjs.map +2 -2
- package/build/store/private-selectors.cjs +26 -2
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/reducer.cjs +70 -1
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/utils.cjs +1 -1
- package/build/store/utils.cjs.map +2 -2
- package/build/utils/color-values.cjs +44 -0
- package/build/utils/color-values.cjs.map +7 -0
- package/build-module/components/block-card/index.mjs +52 -45
- package/build-module/components/block-card/index.mjs.map +2 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.mjs +2 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.mjs.map +2 -2
- package/build-module/components/block-icon/index.mjs +8 -2
- package/build-module/components/block-icon/index.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +166 -13
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-inspector/inspector-pre-tabs-slot-fill.mjs +12 -0
- package/build-module/components/block-inspector/inspector-pre-tabs-slot-fill.mjs.map +7 -0
- package/build-module/components/block-list/use-block-props/index.mjs +1 -1
- package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-focus-handler.mjs +7 -5
- package/build-module/components/block-list/use-block-props/use-focus-handler.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-is-hovered.mjs +28 -15
- package/build-module/components/block-list/use-block-props/use-is-hovered.mjs.map +2 -2
- package/build-module/components/block-lock/modal.mjs +4 -4
- package/build-module/components/block-lock/modal.mjs.map +2 -2
- package/build-module/components/block-patterns-list/index.mjs +14 -4
- package/build-module/components/block-patterns-list/index.mjs.map +2 -2
- package/build-module/components/block-popover/index.mjs +13 -3
- package/build-module/components/block-popover/index.mjs.map +2 -2
- package/build-module/components/block-toolbar/switch-section-style.mjs +2 -2
- package/build-module/components/block-toolbar/switch-section-style.mjs.map +2 -2
- package/build-module/components/block-visibility/modal.mjs +2 -2
- package/build-module/components/block-visibility/modal.mjs.map +2 -2
- package/build-module/components/block-visibility/viewport-visibility-info.mjs +2 -2
- package/build-module/components/block-visibility/viewport-visibility-info.mjs.map +2 -2
- package/build-module/components/colors-gradients/control.mjs +7 -4
- package/build-module/components/colors-gradients/control.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +25 -27
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/color-panel.mjs +96 -59
- package/build-module/components/global-styles/color-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +14 -5
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/index.mjs +2 -0
- package/build-module/components/global-styles/index.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs +39 -28
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/global-styles/state-control-badges.mjs +48 -0
- package/build-module/components/global-styles/state-control-badges.mjs.map +7 -0
- package/build-module/components/global-styles/state-control.mjs +57 -71
- package/build-module/components/global-styles/state-control.mjs.map +2 -2
- package/build-module/components/iframe/index.mjs +0 -3
- package/build-module/components/iframe/index.mjs.map +2 -2
- package/build-module/components/iframe/use-scale-canvas.mjs +4 -1
- package/build-module/components/iframe/use-scale-canvas.mjs.map +2 -2
- package/build-module/components/inserter/hooks/use-patterns-state.mjs +8 -7
- package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
- package/build-module/components/inserter/index.mjs +1 -0
- package/build-module/components/inserter/index.mjs.map +2 -2
- package/build-module/components/inserter/media-tab/media-preview.mjs +27 -19
- package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
- package/build-module/components/inserter/media-tab/utils.mjs +1 -1
- package/build-module/components/inserter/media-tab/utils.mjs.map +2 -2
- package/build-module/components/inserter/panel.mjs +2 -2
- package/build-module/components/inserter/panel.mjs.map +2 -2
- package/build-module/components/inspector-controls/block-support-tools-panel.mjs +10 -2
- package/build-module/components/inspector-controls/block-support-tools-panel.mjs.map +2 -2
- package/build-module/components/inspector-controls/fill.mjs +18 -5
- package/build-module/components/inspector-controls/fill.mjs.map +2 -2
- package/build-module/components/inspector-controls/groups.mjs +2 -0
- package/build-module/components/inspector-controls/groups.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.mjs +14 -10
- package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/settings-tab.mjs +1 -4
- package/build-module/components/inspector-controls-tabs/settings-tab.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +9 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +11 -5
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
- package/build-module/components/list-view/block-select-button.mjs +20 -9
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +2 -1
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/preset-input-control/custom-value-controls.mjs +10 -2
- package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
- package/build-module/components/preset-input-control/index.mjs +2 -2
- package/build-module/components/preset-input-control/index.mjs.map +2 -2
- package/build-module/components/provider/use-media-upload-settings.mjs +1 -0
- package/build-module/components/provider/use-media-upload-settings.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +9 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/paste-handler.mjs +4 -4
- package/build-module/components/rich-text/event-listeners/paste-handler.mjs.map +2 -2
- package/build-module/hooks/background.mjs +18 -3
- package/build-module/hooks/background.mjs.map +2 -2
- package/build-module/hooks/block-fields/link/index.mjs +3 -3
- package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/media/index.mjs +3 -3
- package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
- package/build-module/hooks/block-style-state.mjs +79 -0
- package/build-module/hooks/block-style-state.mjs.map +7 -0
- package/build-module/hooks/border.mjs +18 -3
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/color.mjs +33 -9
- package/build-module/hooks/color.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +20 -6
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +141 -61
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/layout.mjs +270 -58
- package/build-module/hooks/layout.mjs.map +2 -2
- package/build-module/hooks/state-utils.mjs +64 -0
- package/build-module/hooks/state-utils.mjs.map +7 -0
- package/build-module/hooks/states.mjs +85 -0
- package/build-module/hooks/states.mjs.map +7 -0
- package/build-module/hooks/style.mjs +309 -18
- package/build-module/hooks/style.mjs.map +2 -2
- package/build-module/hooks/typography.mjs +19 -5
- package/build-module/hooks/typography.mjs.map +2 -2
- package/build-module/layouts/constrained.mjs +130 -57
- package/build-module/layouts/constrained.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +123 -35
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/layouts/grid.mjs +105 -42
- package/build-module/layouts/grid.mjs.map +2 -2
- package/build-module/private-apis.mjs +4 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +16 -0
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-keys.mjs +7 -1
- package/build-module/store/private-keys.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +25 -2
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +69 -1
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/utils.mjs +5 -2
- package/build-module/store/utils.mjs.map +2 -2
- package/build-module/utils/color-values.mjs +19 -0
- package/build-module/utils/color-values.mjs.map +7 -0
- package/build-style/content-rtl.css +18 -3
- package/build-style/content.css +18 -3
- package/build-style/style-rtl.css +14 -17
- package/build-style/style.css +14 -17
- package/package.json +41 -41
- package/src/components/audio-player/index.native.js +7 -3
- package/src/components/block-card/index.js +67 -60
- package/src/components/block-heading-level-dropdown/heading-level-icon.js +2 -2
- package/src/components/block-icon/index.js +5 -2
- package/src/components/block-icon/index.native.js +2 -2
- package/src/components/block-inspector/index.js +153 -7
- package/src/components/block-inspector/inspector-pre-tabs-slot-fill.js +11 -0
- package/src/components/block-list/block-selection-button.native.js +3 -3
- package/src/components/block-list/content.scss +0 -6
- package/src/components/block-list/use-block-props/index.js +1 -1
- package/src/components/block-list/use-block-props/use-focus-handler.js +8 -6
- package/src/components/block-list/use-block-props/use-is-hovered.js +32 -15
- package/src/components/block-lock/modal.js +4 -4
- package/src/components/block-patterns-list/index.js +14 -5
- package/src/components/block-patterns-list/stories/index.story.jsx +2 -0
- package/src/components/block-patterns-list/style.scss +0 -1
- package/src/components/block-popover/index.js +20 -10
- package/src/components/block-toolbar/switch-section-style.js +2 -2
- package/src/components/block-visibility/modal.js +2 -2
- package/src/components/block-visibility/viewport-visibility-info.js +2 -2
- package/src/components/colors/test/with-colors.js +1 -1
- package/src/components/colors-gradients/control.js +10 -8
- package/src/components/colors-gradients/test/control.js +98 -1
- package/src/components/global-styles/advanced-panel.js +44 -39
- package/src/components/global-styles/color-panel.js +133 -60
- package/src/components/global-styles/dimensions-panel.js +17 -4
- package/src/components/global-styles/index.js +1 -0
- package/src/components/global-styles/shadow-panel-components.js +29 -19
- package/src/components/global-styles/state-control-badges.js +58 -0
- package/src/components/global-styles/state-control.js +28 -36
- package/src/components/global-styles/test/color-panel.js +135 -0
- package/src/components/iframe/index.js +0 -3
- package/src/components/iframe/use-scale-canvas.js +8 -2
- package/src/components/inserter/hooks/use-patterns-state.js +12 -7
- package/src/components/inserter/index.js +1 -0
- package/src/components/inserter/media-tab/media-preview.js +29 -20
- package/src/components/inserter/media-tab/utils.js +1 -1
- package/src/components/inserter/panel.js +2 -2
- package/src/components/inserter/style.scss +1 -0
- package/src/components/inserter-button/index.native.js +5 -2
- package/src/components/inspector-controls/block-support-tools-panel.js +10 -2
- package/src/components/inspector-controls/fill.js +18 -5
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/index.js +9 -5
- package/src/components/inspector-controls-tabs/settings-tab.js +1 -7
- package/src/components/inspector-controls-tabs/styles-tab.js +6 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +13 -7
- package/src/components/list-view/block-select-button.js +19 -9
- package/src/components/list-view/block.js +6 -1
- package/src/components/media-replace-flow/style.scss +0 -18
- package/src/components/preset-input-control/custom-value-controls.js +13 -6
- package/src/components/preset-input-control/index.js +2 -2
- package/src/components/provider/use-media-upload-settings.js +1 -0
- package/src/components/rich-text/event-listeners/enter.js +14 -2
- package/src/components/rich-text/event-listeners/paste-handler.js +5 -4
- package/src/components/unsupported-block-details/index.native.js +6 -2
- package/src/components/video-player/index.native.js +2 -2
- package/src/components/warning/index.native.js +2 -2
- package/src/hooks/background.js +59 -37
- package/src/hooks/block-fields/link/index.js +3 -3
- package/src/hooks/block-fields/media/index.js +3 -3
- package/src/hooks/block-style-state.js +127 -0
- package/src/hooks/border.js +25 -6
- package/src/hooks/color.js +40 -18
- package/src/hooks/dimensions.js +32 -11
- package/src/hooks/layout-child.js +179 -62
- package/src/hooks/layout.js +349 -75
- package/src/hooks/layout.scss +6 -0
- package/src/hooks/state-utils.js +158 -0
- package/src/hooks/states.js +109 -0
- package/src/hooks/style.js +456 -19
- package/src/hooks/test/block-style-state.js +270 -0
- package/src/hooks/test/layout.js +185 -0
- package/src/hooks/test/state-utils.js +193 -0
- package/src/hooks/test/style.js +301 -1
- package/src/hooks/typography.js +33 -14
- package/src/layouts/constrained.js +182 -95
- package/src/layouts/flex.js +141 -36
- package/src/layouts/grid.js +122 -32
- package/src/layouts/test/flex.js +57 -20
- package/src/private-apis.js +4 -0
- package/src/store/private-actions.js +32 -0
- package/src/store/private-keys.js +4 -0
- package/src/store/private-selectors.js +44 -2
- package/src/store/reducer.js +105 -1
- package/src/store/test/private-actions.js +26 -0
- package/src/store/test/private-selectors.js +90 -0
- package/src/store/test/reducer.js +363 -0
- package/src/store/utils.js +6 -2
- package/src/utils/color-values.js +28 -0
- package/src/utils/test/color-values.js +78 -0
package/build/hooks/color.cjs
CHANGED
|
@@ -49,8 +49,10 @@ var import_background = require("./background.cjs");
|
|
|
49
49
|
var import_use_settings = require("../components/use-settings/index.cjs");
|
|
50
50
|
var import_inspector_controls = __toESM(require("../components/inspector-controls/index.cjs"));
|
|
51
51
|
var import_color_panel = __toESM(require("../components/global-styles/color-panel.cjs"));
|
|
52
|
+
var import_color_values = require("../utils/color-values.cjs");
|
|
52
53
|
var import_contrast_checker = __toESM(require("./contrast-checker.cjs"));
|
|
53
54
|
var import_store = require("../store/index.cjs");
|
|
55
|
+
var import_block_style_state = require("./block-style-state.cjs");
|
|
54
56
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
55
57
|
var COLOR_SUPPORT_KEY = "color";
|
|
56
58
|
var hasColorSupport = (blockNameOrType) => {
|
|
@@ -131,13 +133,14 @@ function addSaveProps(props, blockNameOrType, attributes) {
|
|
|
131
133
|
}
|
|
132
134
|
function styleToAttributes(style) {
|
|
133
135
|
const textColorValue = style?.color?.text;
|
|
134
|
-
const textColorSlug =
|
|
136
|
+
const textColorSlug = (0, import_color_values.extractPresetSlug)(textColorValue, "color");
|
|
135
137
|
const backgroundColorValue = style?.color?.background;
|
|
136
|
-
const backgroundColorSlug =
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
const backgroundColorSlug = (0, import_color_values.extractPresetSlug)(
|
|
139
|
+
backgroundColorValue,
|
|
140
|
+
"color"
|
|
141
|
+
);
|
|
139
142
|
const gradientValue = style?.color?.gradient;
|
|
140
|
-
const gradientSlug =
|
|
143
|
+
const gradientSlug = (0, import_color_values.extractPresetSlug)(gradientValue, "gradient");
|
|
141
144
|
const updatedStyle = { ...style };
|
|
142
145
|
updatedStyle.color = {
|
|
143
146
|
...updatedStyle.color,
|
|
@@ -193,6 +196,7 @@ function ColorEdit({
|
|
|
193
196
|
label,
|
|
194
197
|
defaultControls
|
|
195
198
|
}) {
|
|
199
|
+
const selectedState = (0, import_block_style_state.useBlockStyleState)();
|
|
196
200
|
const isEnabled = (0, import_color_panel.useHasColorPanel)(settings);
|
|
197
201
|
const { style, textColor, backgroundColor, gradient } = (0, import_data.useSelect)(
|
|
198
202
|
(select) => {
|
|
@@ -214,17 +218,33 @@ function ColorEdit({
|
|
|
214
218
|
},
|
|
215
219
|
[clientId, isEnabled]
|
|
216
220
|
);
|
|
221
|
+
const isStateSelected = !(0, import_block_style_state.isDefaultBlockStyleState)(selectedState);
|
|
217
222
|
const value = (0, import_element.useMemo)(() => {
|
|
223
|
+
if (isStateSelected) {
|
|
224
|
+
return (0, import_block_style_state.getStyleForState)(style, selectedState);
|
|
225
|
+
}
|
|
218
226
|
return attributesToStyle({
|
|
219
227
|
style,
|
|
220
228
|
textColor,
|
|
221
229
|
backgroundColor,
|
|
222
230
|
gradient
|
|
223
231
|
});
|
|
224
|
-
}, [
|
|
225
|
-
|
|
232
|
+
}, [
|
|
233
|
+
isStateSelected,
|
|
234
|
+
selectedState,
|
|
235
|
+
style,
|
|
236
|
+
textColor,
|
|
237
|
+
backgroundColor,
|
|
238
|
+
gradient
|
|
239
|
+
]);
|
|
240
|
+
const onChange = isStateSelected ? (newStyle) => {
|
|
241
|
+
setAttributes({
|
|
242
|
+
style: (0, import_block_style_state.setStyleForState)(style, selectedState, newStyle)
|
|
243
|
+
});
|
|
244
|
+
} : (newStyle) => {
|
|
226
245
|
setAttributes(styleToAttributes(newStyle));
|
|
227
246
|
};
|
|
247
|
+
const Wrapper = asWrapper || ColorInspectorControl;
|
|
228
248
|
if (!isEnabled) {
|
|
229
249
|
return null;
|
|
230
250
|
}
|
|
@@ -232,14 +252,13 @@ function ColorEdit({
|
|
|
232
252
|
COLOR_SUPPORT_KEY,
|
|
233
253
|
"__experimentalDefaultControls"
|
|
234
254
|
]);
|
|
235
|
-
const enableContrastChecking = import_element.Platform.OS === "web" && !value?.color?.gradient && (settings?.color?.text || settings?.color?.link) && // Contrast checking is enabled by default.
|
|
255
|
+
const enableContrastChecking = !isStateSelected && import_element.Platform.OS === "web" && !value?.color?.gradient && (settings?.color?.text || settings?.color?.link) && // Contrast checking is enabled by default.
|
|
236
256
|
// Deactivating it requires `enableContrastChecker` to have
|
|
237
257
|
// an explicit value of `false`.
|
|
238
258
|
false !== (0, import_blocks.getBlockSupport)(name, [
|
|
239
259
|
COLOR_SUPPORT_KEY,
|
|
240
260
|
"enableContrastChecker"
|
|
241
261
|
]);
|
|
242
|
-
const Wrapper = asWrapper || ColorInspectorControl;
|
|
243
262
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
244
263
|
import_color_panel.default,
|
|
245
264
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/color.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo, Platform, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport { __experimentalGetGradientClass } from '../components/gradients';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport { getBackgroundImageClasses } from './background';\nimport { useSettings } from '../components/use-settings';\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tuseHasColorPanel,\n\tdefault as StylesColorPanel,\n} from '../components/global-styles/color-panel';\nimport BlockColorContrastChecker from './contrast-checker';\nimport { store as blockEditorStore } from '../store';\n\nexport const COLOR_SUPPORT_KEY = 'color';\n\nconst hasColorSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\nconst hasLinkColorSupport = ( blockType ) => {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\nconst hasGradientSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\nconst hasBackgroundColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\nconst hasTextColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Filters registered block settings, extending attributes to include\n * `backgroundColor` and `textColor` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasColorSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.backgroundColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\tif ( ! settings.attributes.textColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\tif ( hasGradientSupport( settings ) && ! settings.attributes.gradient ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tgradient: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject colors classnames.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasColorSupport( blockNameOrType ) ||\n\t\tshouldSkipSerialization( blockNameOrType, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst hasGradient = hasGradientSupport( blockNameOrType );\n\n\t// I'd have preferred to avoid the \"style\" attribute usage here\n\tconst { backgroundColor, textColor, gradient, style } = attributes;\n\n\tconst shouldSerialize = ( feature ) =>\n\t\t! shouldSkipSerialization(\n\t\t\tblockNameOrType,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\tfeature\n\t\t);\n\n\t// Primary color classes must come before the `has-text-color`,\n\t// `has-background` and `has-link-color` classes to maintain backwards\n\t// compatibility and avoid block invalidations.\n\tconst textClass = shouldSerialize( 'text' )\n\t\t? getColorClassName( 'color', textColor )\n\t\t: undefined;\n\n\tconst gradientClass = shouldSerialize( 'gradients' )\n\t\t? __experimentalGetGradientClass( gradient )\n\t\t: undefined;\n\n\tconst backgroundClass = shouldSerialize( 'background' )\n\t\t? getColorClassName( 'background-color', backgroundColor )\n\t\t: undefined;\n\n\tconst serializeHasBackground =\n\t\tshouldSerialize( 'background' ) || shouldSerialize( 'gradients' );\n\tconst hasBackground =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\t( hasGradient && ( gradient || style?.color?.gradient ) );\n\n\tconst newClassName = clsx( props.className, textClass, gradientClass, {\n\t\t// Don't apply the background class if there's a custom gradient.\n\t\t[ backgroundClass ]:\n\t\t\t( ! hasGradient || ! style?.color?.gradient ) && !! backgroundClass,\n\t\t'has-text-color':\n\t\t\tshouldSerialize( 'text' ) && ( textColor || style?.color?.text ),\n\t\t'has-background': serializeHasBackground && hasBackground,\n\t\t'has-link-color':\n\t\t\tshouldSerialize( 'link' ) && style?.elements?.link?.color,\n\t} );\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\nfunction styleToAttributes( style ) {\n\tconst textColorValue = style?.color?.text;\n\tconst textColorSlug = textColorValue?.startsWith( 'var:preset|color|' )\n\t\t? textColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst backgroundColorValue = style?.color?.background;\n\tconst backgroundColorSlug = backgroundColorValue?.startsWith(\n\t\t'var:preset|color|'\n\t)\n\t\t? backgroundColorValue.substring( 'var:preset|color|'.length )\n\t\t: undefined;\n\tconst gradientValue = style?.color?.gradient;\n\tconst gradientSlug = gradientValue?.startsWith( 'var:preset|gradient|' )\n\t\t? gradientValue.substring( 'var:preset|gradient|'.length )\n\t\t: undefined;\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.color = {\n\t\t...updatedStyle.color,\n\t\ttext: textColorSlug ? undefined : textColorValue,\n\t\tbackground: backgroundColorSlug ? undefined : backgroundColorValue,\n\t\tgradient: gradientSlug ? undefined : gradientValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\ttextColor: textColorSlug,\n\t\tbackgroundColor: backgroundColorSlug,\n\t\tgradient: gradientSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\treturn {\n\t\t...attributes.style,\n\t\tcolor: {\n\t\t\t...attributes.style?.color,\n\t\t\ttext: attributes.textColor\n\t\t\t\t? 'var:preset|color|' + attributes.textColor\n\t\t\t\t: attributes.style?.color?.text,\n\t\t\tbackground: attributes.backgroundColor\n\t\t\t\t? 'var:preset|color|' + attributes.backgroundColor\n\t\t\t\t: attributes.style?.color?.background,\n\t\t\tgradient: attributes.gradient\n\t\t\t\t? 'var:preset|gradient|' + attributes.gradient\n\t\t\t\t: attributes.style?.color?.gradient,\n\t\t},\n\t};\n}\n\nfunction ColorInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"color\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function ColorEdit( {\n\tclientId,\n\tname,\n\tsetAttributes,\n\tsettings,\n\tasWrapper,\n\tlabel,\n\tdefaultControls,\n} ) {\n\tconst isEnabled = useHasColorPanel( settings );\n\n\tconst { style, textColor, backgroundColor, gradient } = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t} = select( blockEditorStore ).getBlockAttributes( clientId ) || {};\n\t\t\treturn {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t};\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( {\n\t\t\tstyle,\n\t\t\ttextColor,\n\t\t\tbackgroundColor,\n\t\t\tgradient,\n\t\t} );\n\t}, [ style, textColor, backgroundColor, gradient ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tdefaultControls = defaultControls\n\t\t? defaultControls\n\t\t: getBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'__experimentalDefaultControls',\n\t\t ] );\n\n\tconst enableContrastChecking =\n\t\tPlatform.OS === 'web' &&\n\t\t! value?.color?.gradient &&\n\t\t( settings?.color?.text || settings?.color?.link ) &&\n\t\t// Contrast checking is enabled by default.\n\t\t// Deactivating it requires `enableContrastChecker` to have\n\t\t// an explicit value of `false`.\n\t\tfalse !==\n\t\t\tgetBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'enableContrastChecker',\n\t\t\t] );\n\n\t// Use provided wrapper or default to ColorInspectorControl\n\tconst Wrapper = asWrapper || ColorInspectorControl;\n\n\treturn (\n\t\t<StylesColorPanel\n\t\t\tas={ Wrapper }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t\tlabel={ label }\n\t\t\tenableContrastChecker={\n\t\t\t\tfalse !==\n\t\t\t\tgetBlockSupport( name, [\n\t\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t\t'enableContrastChecker',\n\t\t\t\t] )\n\t\t\t}\n\t\t>\n\t\t\t{ enableContrastChecking && (\n\t\t\t\t<BlockColorContrastChecker\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tname={ name }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</StylesColorPanel>\n\t);\n}\n\nfunction useBlockProps( {\n\tname,\n\tbackgroundColor,\n\ttextColor,\n\tgradient,\n\tstyle,\n} ) {\n\tconst [ userPalette, themePalette, defaultPalette ] = useSettings(\n\t\t'color.palette.custom',\n\t\t'color.palette.theme',\n\t\t'color.palette.default'\n\t);\n\n\tconst colors = useMemo(\n\t\t() => [\n\t\t\t...( userPalette || [] ),\n\t\t\t...( themePalette || [] ),\n\t\t\t...( defaultPalette || [] ),\n\t\t],\n\t\t[ userPalette, themePalette, defaultPalette ]\n\t);\n\tif (\n\t\t! hasColorSupport( name ) ||\n\t\tshouldSkipSerialization( name, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn {};\n\t}\n\tconst extraStyles = {};\n\n\tif (\n\t\ttextColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'text' )\n\t) {\n\t\textraStyles.color = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\ttextColor\n\t\t)?.color;\n\t}\n\tif (\n\t\tbackgroundColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'background' )\n\t) {\n\t\textraStyles.backgroundColor = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\tbackgroundColor\n\t\t)?.color;\n\t}\n\n\tconst saveProps = addSaveProps( { style: extraStyles }, name, {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t\tstyle,\n\t} );\n\n\tconst hasBackgroundValue =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\tgradient ||\n\t\tstyle?.color?.gradient;\n\n\treturn {\n\t\t...saveProps,\n\t\tclassName: clsx(\n\t\t\tsaveProps.className,\n\t\t\t// Add background image classes in the editor, if not already handled by background color values.\n\t\t\t! hasBackgroundValue && getBackgroundImageClasses( style )\n\t\t),\n\t};\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'backgroundColor', 'textColor', 'gradient', 'style' ],\n\thasSupport: hasColorSupport,\n};\n\nconst MIGRATION_PATHS = {\n\tlinkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],\n\ttextColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],\n\tbackgroundColor: [\n\t\t[ 'backgroundColor' ],\n\t\t[ 'style', 'color', 'background' ],\n\t],\n\tgradient: [ [ 'gradient' ], [ 'style', 'color', 'gradient' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tlinkColor: hasLinkColorSupport( destinationBlockType ),\n\t\ttextColor: hasTextColorSupport( destinationBlockType ),\n\t\tbackgroundColor: hasBackgroundColorSupport( destinationBlockType ),\n\t\tgradient: hasGradientSupport( destinationBlockType ),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/color/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/color/addTransforms',\n\taddTransforms\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,mBAA0B;AAC1B,oBAAgC;AAChC,qBAA+C;AAC/C,kBAA0B;AAK1B,oBAGO;AACP,uBAA+C;AAC/C,mBAIO;AACP,wBAA0C;AAC1C,0BAA4B;AAC5B,gCAA8B;AAC9B,yBAGO;AACP,8BAAsC;AACtC,mBAA0C;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo, Platform, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport { __experimentalGetGradientClass } from '../components/gradients';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport { getBackgroundImageClasses } from './background';\nimport { useSettings } from '../components/use-settings';\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tuseHasColorPanel,\n\tdefault as StylesColorPanel,\n} from '../components/global-styles/color-panel';\nimport { extractPresetSlug } from '../utils/color-values';\nimport BlockColorContrastChecker from './contrast-checker';\nimport { store as blockEditorStore } from '../store';\nimport {\n\tgetStyleForState,\n\tisDefaultBlockStyleState,\n\tsetStyleForState,\n\tuseBlockStyleState,\n} from './block-style-state';\n\nexport const COLOR_SUPPORT_KEY = 'color';\n\nconst hasColorSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\nconst hasLinkColorSupport = ( blockType ) => {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\nconst hasGradientSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\nconst hasBackgroundColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\nconst hasTextColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Filters registered block settings, extending attributes to include\n * `backgroundColor` and `textColor` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasColorSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.backgroundColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\tif ( ! settings.attributes.textColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\tif ( hasGradientSupport( settings ) && ! settings.attributes.gradient ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tgradient: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject colors classnames.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasColorSupport( blockNameOrType ) ||\n\t\tshouldSkipSerialization( blockNameOrType, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst hasGradient = hasGradientSupport( blockNameOrType );\n\n\t// I'd have preferred to avoid the \"style\" attribute usage here\n\tconst { backgroundColor, textColor, gradient, style } = attributes;\n\n\tconst shouldSerialize = ( feature ) =>\n\t\t! shouldSkipSerialization(\n\t\t\tblockNameOrType,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\tfeature\n\t\t);\n\n\t// Primary color classes must come before the `has-text-color`,\n\t// `has-background` and `has-link-color` classes to maintain backwards\n\t// compatibility and avoid block invalidations.\n\tconst textClass = shouldSerialize( 'text' )\n\t\t? getColorClassName( 'color', textColor )\n\t\t: undefined;\n\n\tconst gradientClass = shouldSerialize( 'gradients' )\n\t\t? __experimentalGetGradientClass( gradient )\n\t\t: undefined;\n\n\tconst backgroundClass = shouldSerialize( 'background' )\n\t\t? getColorClassName( 'background-color', backgroundColor )\n\t\t: undefined;\n\n\tconst serializeHasBackground =\n\t\tshouldSerialize( 'background' ) || shouldSerialize( 'gradients' );\n\tconst hasBackground =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\t( hasGradient && ( gradient || style?.color?.gradient ) );\n\n\tconst newClassName = clsx( props.className, textClass, gradientClass, {\n\t\t// Don't apply the background class if there's a custom gradient.\n\t\t[ backgroundClass ]:\n\t\t\t( ! hasGradient || ! style?.color?.gradient ) && !! backgroundClass,\n\t\t'has-text-color':\n\t\t\tshouldSerialize( 'text' ) && ( textColor || style?.color?.text ),\n\t\t'has-background': serializeHasBackground && hasBackground,\n\t\t'has-link-color':\n\t\t\tshouldSerialize( 'link' ) && style?.elements?.link?.color,\n\t} );\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\nfunction styleToAttributes( style ) {\n\tconst textColorValue = style?.color?.text;\n\tconst textColorSlug = extractPresetSlug( textColorValue, 'color' );\n\tconst backgroundColorValue = style?.color?.background;\n\tconst backgroundColorSlug = extractPresetSlug(\n\t\tbackgroundColorValue,\n\t\t'color'\n\t);\n\tconst gradientValue = style?.color?.gradient;\n\tconst gradientSlug = extractPresetSlug( gradientValue, 'gradient' );\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.color = {\n\t\t...updatedStyle.color,\n\t\ttext: textColorSlug ? undefined : textColorValue,\n\t\tbackground: backgroundColorSlug ? undefined : backgroundColorValue,\n\t\tgradient: gradientSlug ? undefined : gradientValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\ttextColor: textColorSlug,\n\t\tbackgroundColor: backgroundColorSlug,\n\t\tgradient: gradientSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\treturn {\n\t\t...attributes.style,\n\t\tcolor: {\n\t\t\t...attributes.style?.color,\n\t\t\ttext: attributes.textColor\n\t\t\t\t? 'var:preset|color|' + attributes.textColor\n\t\t\t\t: attributes.style?.color?.text,\n\t\t\tbackground: attributes.backgroundColor\n\t\t\t\t? 'var:preset|color|' + attributes.backgroundColor\n\t\t\t\t: attributes.style?.color?.background,\n\t\t\tgradient: attributes.gradient\n\t\t\t\t? 'var:preset|gradient|' + attributes.gradient\n\t\t\t\t: attributes.style?.color?.gradient,\n\t\t},\n\t};\n}\n\nfunction ColorInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"color\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function ColorEdit( {\n\tclientId,\n\tname,\n\tsetAttributes,\n\tsettings,\n\tasWrapper,\n\tlabel,\n\tdefaultControls,\n} ) {\n\tconst selectedState = useBlockStyleState();\n\tconst isEnabled = useHasColorPanel( settings );\n\n\tconst { style, textColor, backgroundColor, gradient } = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t} = select( blockEditorStore ).getBlockAttributes( clientId ) || {};\n\t\t\treturn {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t};\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\n\tconst isStateSelected = ! isDefaultBlockStyleState( selectedState );\n\n\tconst value = useMemo( () => {\n\t\tif ( isStateSelected ) {\n\t\t\treturn getStyleForState( style, selectedState );\n\t\t}\n\t\treturn attributesToStyle( {\n\t\t\tstyle,\n\t\t\ttextColor,\n\t\t\tbackgroundColor,\n\t\t\tgradient,\n\t\t} );\n\t}, [\n\t\tisStateSelected,\n\t\tselectedState,\n\t\tstyle,\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t] );\n\n\tconst onChange = isStateSelected\n\t\t? ( newStyle ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tstyle: setStyleForState( style, selectedState, newStyle ),\n\t\t\t\t} );\n\t\t }\n\t\t: ( newStyle ) => {\n\t\t\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t\t };\n\n\tconst Wrapper = asWrapper || ColorInspectorControl;\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tdefaultControls = defaultControls\n\t\t? defaultControls\n\t\t: getBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'__experimentalDefaultControls',\n\t\t ] );\n\n\tconst enableContrastChecking =\n\t\t! isStateSelected &&\n\t\tPlatform.OS === 'web' &&\n\t\t! value?.color?.gradient &&\n\t\t( settings?.color?.text || settings?.color?.link ) &&\n\t\t// Contrast checking is enabled by default.\n\t\t// Deactivating it requires `enableContrastChecker` to have\n\t\t// an explicit value of `false`.\n\t\tfalse !==\n\t\t\tgetBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'enableContrastChecker',\n\t\t\t] );\n\n\treturn (\n\t\t<StylesColorPanel\n\t\t\tas={ Wrapper }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t\tlabel={ label }\n\t\t\tenableContrastChecker={\n\t\t\t\tfalse !==\n\t\t\t\tgetBlockSupport( name, [\n\t\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t\t'enableContrastChecker',\n\t\t\t\t] )\n\t\t\t}\n\t\t>\n\t\t\t{ enableContrastChecking && (\n\t\t\t\t<BlockColorContrastChecker\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tname={ name }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</StylesColorPanel>\n\t);\n}\n\nfunction useBlockProps( {\n\tname,\n\tbackgroundColor,\n\ttextColor,\n\tgradient,\n\tstyle,\n} ) {\n\tconst [ userPalette, themePalette, defaultPalette ] = useSettings(\n\t\t'color.palette.custom',\n\t\t'color.palette.theme',\n\t\t'color.palette.default'\n\t);\n\n\tconst colors = useMemo(\n\t\t() => [\n\t\t\t...( userPalette || [] ),\n\t\t\t...( themePalette || [] ),\n\t\t\t...( defaultPalette || [] ),\n\t\t],\n\t\t[ userPalette, themePalette, defaultPalette ]\n\t);\n\tif (\n\t\t! hasColorSupport( name ) ||\n\t\tshouldSkipSerialization( name, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn {};\n\t}\n\tconst extraStyles = {};\n\n\tif (\n\t\ttextColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'text' )\n\t) {\n\t\textraStyles.color = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\ttextColor\n\t\t)?.color;\n\t}\n\tif (\n\t\tbackgroundColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'background' )\n\t) {\n\t\textraStyles.backgroundColor = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\tbackgroundColor\n\t\t)?.color;\n\t}\n\n\tconst saveProps = addSaveProps( { style: extraStyles }, name, {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t\tstyle,\n\t} );\n\n\tconst hasBackgroundValue =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\tgradient ||\n\t\tstyle?.color?.gradient;\n\n\treturn {\n\t\t...saveProps,\n\t\tclassName: clsx(\n\t\t\tsaveProps.className,\n\t\t\t// Add background image classes in the editor, if not already handled by background color values.\n\t\t\t! hasBackgroundValue && getBackgroundImageClasses( style )\n\t\t),\n\t};\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'backgroundColor', 'textColor', 'gradient', 'style' ],\n\thasSupport: hasColorSupport,\n};\n\nconst MIGRATION_PATHS = {\n\tlinkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],\n\ttextColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],\n\tbackgroundColor: [\n\t\t[ 'backgroundColor' ],\n\t\t[ 'style', 'color', 'background' ],\n\t],\n\tgradient: [ [ 'gradient' ], [ 'style', 'color', 'gradient' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tlinkColor: hasLinkColorSupport( destinationBlockType ),\n\t\ttextColor: hasTextColorSupport( destinationBlockType ),\n\t\tbackgroundColor: hasBackgroundColorSupport( destinationBlockType ),\n\t\tgradient: hasGradientSupport( destinationBlockType ),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/color/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/color/addTransforms',\n\taddTransforms\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;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IACjE,UAAU,mBAAoB,oBAAqB;AAAA,EACpD;AACA,aAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": ["clsx", "InspectorControls", "blockEditorStore", "StylesColorPanel", "BlockColorContrastChecker"]
|
|
7
7
|
}
|
|
@@ -51,6 +51,7 @@ var import_spacing_visualizer = require("./spacing-visualizer.cjs");
|
|
|
51
51
|
var import_store = require("../store/index.cjs");
|
|
52
52
|
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
53
53
|
var import_utils = require("./utils.cjs");
|
|
54
|
+
var import_block_style_state = require("./block-style-state.cjs");
|
|
54
55
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
55
56
|
var DIMENSIONS_SUPPORT_KEY = "dimensions";
|
|
56
57
|
var SPACING_SUPPORT_KEY = "spacing";
|
|
@@ -92,8 +93,10 @@ function DimensionsInspectorControl({ children, resetAllFilter }) {
|
|
|
92
93
|
);
|
|
93
94
|
}
|
|
94
95
|
function DimensionsPanel({ clientId, name, setAttributes, settings }) {
|
|
95
|
-
const
|
|
96
|
-
const
|
|
96
|
+
const selectedState = (0, import_block_style_state.useBlockStyleState)();
|
|
97
|
+
const isStateSelected = !(0, import_block_style_state.isDefaultBlockStyleState)(selectedState);
|
|
98
|
+
const isEnabled = (0, import_global_styles.useHasDimensionsPanel)(settings, selectedState);
|
|
99
|
+
const style = (0, import_data.useSelect)(
|
|
97
100
|
(select) => {
|
|
98
101
|
if (!isEnabled) {
|
|
99
102
|
return void 0;
|
|
@@ -103,7 +106,12 @@ function DimensionsPanel({ clientId, name, setAttributes, settings }) {
|
|
|
103
106
|
[clientId, isEnabled]
|
|
104
107
|
);
|
|
105
108
|
const [visualizedProperty, setVisualizedProperty] = useVisualizer();
|
|
106
|
-
const
|
|
109
|
+
const value = isStateSelected ? (0, import_block_style_state.getStyleForState)(style, selectedState) : style;
|
|
110
|
+
const onChange = isStateSelected ? (newStyle) => {
|
|
111
|
+
setAttributes({
|
|
112
|
+
style: (0, import_block_style_state.setStyleForState)(style, selectedState, newStyle)
|
|
113
|
+
});
|
|
114
|
+
} : (newStyle) => {
|
|
107
115
|
setAttributes({
|
|
108
116
|
style: (0, import_utils.cleanEmptyObject)(newStyle)
|
|
109
117
|
});
|
|
@@ -137,10 +145,11 @@ function DimensionsPanel({ clientId, name, setAttributes, settings }) {
|
|
|
137
145
|
value,
|
|
138
146
|
onChange,
|
|
139
147
|
defaultControls,
|
|
140
|
-
|
|
148
|
+
styleState: selectedState,
|
|
149
|
+
onVisualize: isStateSelected ? void 0 : setVisualizedProperty
|
|
141
150
|
}
|
|
142
151
|
),
|
|
143
|
-
!!settings?.spacing?.padding && visualizedProperty === "padding" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
|
+
!isStateSelected && !!settings?.spacing?.padding && visualizedProperty === "padding" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
144
153
|
import_spacing_visualizer.PaddingVisualizer,
|
|
145
154
|
{
|
|
146
155
|
forceShow: visualizedProperty === "padding",
|
|
@@ -148,7 +157,7 @@ function DimensionsPanel({ clientId, name, setAttributes, settings }) {
|
|
|
148
157
|
value
|
|
149
158
|
}
|
|
150
159
|
),
|
|
151
|
-
!!settings?.spacing?.margin && visualizedProperty === "margin" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
160
|
+
!isStateSelected && !!settings?.spacing?.margin && visualizedProperty === "margin" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
161
|
import_spacing_visualizer.MarginVisualizer,
|
|
153
162
|
{
|
|
154
163
|
forceShow: visualizedProperty === "margin",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/dimensions.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Platform, useState, useEffect, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tDimensionsPanel as StylesDimensionsPanel,\n\tuseHasDimensionsPanel,\n} from '../components/global-styles';\nimport { MarginVisualizer, PaddingVisualizer } from './spacing-visualizer';\nimport { store as blockEditorStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport { cleanEmptyObject, shouldSkipSerialization } from './utils';\n\nexport const DIMENSIONS_SUPPORT_KEY = 'dimensions';\nexport const SPACING_SUPPORT_KEY = 'spacing';\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nexport const AXIAL_SIDES = [ 'vertical', 'horizontal' ];\n\nfunction useVisualizer() {\n\tconst [ property, setProperty ] = useState( false );\n\tconst { hideBlockInterface, showBlockInterface } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tuseEffect( () => {\n\t\tif ( ! property ) {\n\t\t\tshowBlockInterface();\n\t\t} else {\n\t\t\thideBlockInterface();\n\t\t}\n\t}, [ property, showBlockInterface, hideBlockInterface ] );\n\n\treturn [ property, setProperty ];\n}\n\nfunction DimensionsInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributes.style;\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tstyle: updatedStyle,\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"dimensions\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function DimensionsPanel( { clientId, name, setAttributes, settings } ) {\n\tconst isEnabled = useHasDimensionsPanel( settings );\n\tconst
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA2D;AAC3D,kBAAuC;AACvC,oBAAgC;AAChC,wBAAuB;AAKvB,gCAA8B;AAC9B,2BAGO;AACP,gCAAoD;AACpD,mBAA0C;AAC1C,yBAAuB;AACvB,mBAA0D;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Platform, useState, useEffect, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tDimensionsPanel as StylesDimensionsPanel,\n\tuseHasDimensionsPanel,\n} from '../components/global-styles';\nimport { MarginVisualizer, PaddingVisualizer } from './spacing-visualizer';\nimport { store as blockEditorStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport { cleanEmptyObject, shouldSkipSerialization } from './utils';\nimport {\n\tgetStyleForState,\n\tisDefaultBlockStyleState,\n\tsetStyleForState,\n\tuseBlockStyleState,\n} from './block-style-state';\n\nexport const DIMENSIONS_SUPPORT_KEY = 'dimensions';\nexport const SPACING_SUPPORT_KEY = 'spacing';\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nexport const AXIAL_SIDES = [ 'vertical', 'horizontal' ];\n\nfunction useVisualizer() {\n\tconst [ property, setProperty ] = useState( false );\n\tconst { hideBlockInterface, showBlockInterface } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tuseEffect( () => {\n\t\tif ( ! property ) {\n\t\t\tshowBlockInterface();\n\t\t} else {\n\t\t\thideBlockInterface();\n\t\t}\n\t}, [ property, showBlockInterface, hideBlockInterface ] );\n\n\treturn [ property, setProperty ];\n}\n\nfunction DimensionsInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributes.style;\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tstyle: updatedStyle,\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"dimensions\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function DimensionsPanel( { clientId, name, setAttributes, settings } ) {\n\tconst selectedState = useBlockStyleState();\n\tconst isStateSelected = ! isDefaultBlockStyleState( selectedState );\n\tconst isEnabled = useHasDimensionsPanel( settings, selectedState );\n\tconst style = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn select( blockEditorStore ).getBlockAttributes( clientId )\n\t\t\t\t?.style;\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\tconst [ visualizedProperty, setVisualizedProperty ] = useVisualizer();\n\tconst value = isStateSelected\n\t\t? getStyleForState( style, selectedState )\n\t\t: style;\n\tconst onChange = isStateSelected\n\t\t? ( newStyle ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tstyle: setStyleForState( style, selectedState, newStyle ),\n\t\t\t\t} );\n\t\t }\n\t\t: ( newStyle ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t\t} );\n\t\t };\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultDimensionsControls = getBlockSupport( name, [\n\t\tDIMENSIONS_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultSpacingControls = getBlockSupport( name, [\n\t\tSPACING_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultControls = {\n\t\t// In the block inspector, minHeight and minWidth should not\n\t\t// be shown by default unless the block explicitly opts in.\n\t\tminHeight: false,\n\t\tminWidth: false,\n\t\t...defaultDimensionsControls,\n\t\t...defaultSpacingControls,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<StylesDimensionsPanel\n\t\t\t\tas={ DimensionsInspectorControl }\n\t\t\t\tpanelId={ clientId }\n\t\t\t\tsettings={ settings }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tdefaultControls={ defaultControls }\n\t\t\t\tstyleState={ selectedState }\n\t\t\t\tonVisualize={\n\t\t\t\t\tisStateSelected ? undefined : setVisualizedProperty\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ ! isStateSelected &&\n\t\t\t\t!! settings?.spacing?.padding &&\n\t\t\t\tvisualizedProperty === 'padding' && (\n\t\t\t\t\t<PaddingVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'padding' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t{ ! isStateSelected &&\n\t\t\t\t!! settings?.spacing?.margin &&\n\t\t\t\tvisualizedProperty === 'margin' && (\n\t\t\t\t\t<MarginVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'margin' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Determine whether there is block support for dimensions.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasDimensionsSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, DIMENSIONS_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.aspectRatio ||\n\t\t\t!! support?.height ||\n\t\t\t!! support?.minHeight ||\n\t\t\t!! support?.width ||\n\t\t\t!! support?.minWidth\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\nexport default {\n\tuseBlockProps,\n\tattributeKeys: [ 'height', 'minHeight', 'width', 'style' ],\n\thasSupport( name ) {\n\t\treturn hasDimensionsSupport( name );\n\t},\n};\n\nfunction useBlockProps( { name, height, minHeight, style } ) {\n\tif (\n\t\t! hasDimensionsSupport( name, 'aspectRatio' ) ||\n\t\tshouldSkipSerialization( name, DIMENSIONS_SUPPORT_KEY, 'aspectRatio' )\n\t) {\n\t\treturn {};\n\t}\n\n\tconst className = clsx( {\n\t\t'has-aspect-ratio': !! style?.dimensions?.aspectRatio,\n\t} );\n\n\t// Allow dimensions-based inline style overrides to override any global styles rules that\n\t// might be set for the block, and therefore affect the display of the aspect ratio.\n\tconst inlineStyleOverrides = {};\n\n\t// Apply rules to unset incompatible styles.\n\t// Note that a set `aspectRatio` will win out if both an aspect ratio and height-related properties are set.\n\t// This is because the aspect ratio is a newer block support, so (in theory) any aspect ratio\n\t// that is set should be intentional and should override any existing height properties. The Cover block\n\t// and dimensions controls have logic that will manually clear the aspect ratio if height properties\n\t// are set.\n\tif ( style?.dimensions?.aspectRatio ) {\n\t\t// To ensure the aspect ratio does not get overridden by `minHeight` or `height` unset any existing rule.\n\t\tinlineStyleOverrides.minHeight = 'unset';\n\t\tinlineStyleOverrides.height = 'unset';\n\t} else if (\n\t\tminHeight ||\n\t\tstyle?.dimensions?.minHeight ||\n\t\theight ||\n\t\tstyle?.dimensions?.height\n\t) {\n\t\t// To ensure height properties do not get overridden by `aspectRatio` unset any existing rule.\n\t\tinlineStyleOverrides.aspectRatio = 'unset';\n\t}\n\n\treturn { className, style: inlineStyleOverrides };\n}\n\n/**\n * @deprecated\n */\nexport function useCustomSides() {\n\tdeprecated( 'wp.blockEditor.__experimentalUseCustomSides', {\n\t\tsince: '6.3',\n\t\tversion: '6.4',\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA2D;AAC3D,kBAAuC;AACvC,oBAAgC;AAChC,wBAAuB;AAKvB,gCAA8B;AAC9B,2BAGO;AACP,gCAAoD;AACpD,mBAA0C;AAC1C,yBAAuB;AACvB,mBAA0D;AAC1D,+BAKO;AAqCL;AAnCK,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB;AAC5B,IAAM,YAAY,CAAE,OAAO,SAAS,UAAU,MAAO;AACrD,IAAM,cAAc,CAAE,YAAY,YAAa;AAEtD,SAAS,gBAAgB;AACxB,QAAM,CAAE,UAAU,WAAY,QAAI,yBAAU,KAAM;AAClD,QAAM,EAAE,oBAAoB,mBAAmB,QAAI;AAAA,QAClD,yBAAa,aAAAA,KAAiB;AAAA,EAC/B;AACA,gCAAW,MAAM;AAChB,QAAK,CAAE,UAAW;AACjB,yBAAmB;AAAA,IACpB,OAAO;AACN,yBAAmB;AAAA,IACpB;AAAA,EACD,GAAG,CAAE,UAAU,oBAAoB,kBAAmB,CAAE;AAExD,SAAO,CAAE,UAAU,WAAY;AAChC;AAEA,SAAS,2BAA4B,EAAE,UAAU,eAAe,GAAI;AACnE,QAAM,+BAA2B;AAAA,IAChC,CAAE,eAAgB;AACjB,YAAM,gBAAgB,WAAW;AACjC,YAAM,eAAe,eAAgB,aAAc;AACnD,aAAO;AAAA,QACN,GAAG;AAAA,QAC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AA,EAC3C,CAAE;AAIF,QAAM,uBAAuB,CAAC;AAQ9B,MAAK,OAAO,YAAY,aAAc;AAErC,yBAAqB,YAAY;AACjC,yBAAqB,SAAS;AAAA,EAC/B,WACC,aACA,OAAO,YAAY,aACnB,UACA,OAAO,YAAY,QAClB;AAED,yBAAqB,cAAc;AAAA,EACpC;AAEA,SAAO,EAAE,WAAW,OAAO,qBAAqB;AACjD;AAKO,SAAS,iBAAiB;AAChC,wBAAAC,SAAY,+CAA+C;AAAA,IAC1D,OAAO;AAAA,IACP,SAAS;AAAA,EACV,CAAE;AACH;",
|
|
6
6
|
"names": ["blockEditorStore", "InspectorControls", "StylesDimensionsPanel", "clsx", "deprecated"]
|
|
7
7
|
}
|
|
@@ -30,7 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// packages/block-editor/src/hooks/layout-child.js
|
|
31
31
|
var layout_child_exports = {};
|
|
32
32
|
__export(layout_child_exports, {
|
|
33
|
-
default: () => layout_child_default
|
|
33
|
+
default: () => layout_child_default,
|
|
34
|
+
getChildLayoutStyleRules: () => getChildLayoutStyleRules,
|
|
35
|
+
getChildLayoutStyles: () => getChildLayoutStyles,
|
|
36
|
+
getResponsiveChildLayoutStyles: () => getResponsiveChildLayoutStyles
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(layout_child_exports);
|
|
36
39
|
var import_compose = require("@wordpress/compose");
|
|
@@ -45,11 +48,28 @@ var import_private_keys = require("../store/private-keys.cjs");
|
|
|
45
48
|
var import_constants = require("../components/block-visibility/constants.cjs");
|
|
46
49
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
50
|
var LAYOUT_CHILD_BLOCK_PROPS_REFERENCE = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
var RESPONSIVE_BREAKPOINTS = {
|
|
52
|
+
mobile: "@media (width <= 480px)",
|
|
53
|
+
tablet: "@media (480px < width <= 782px)"
|
|
54
|
+
};
|
|
55
|
+
function serializeRule({ selector, declarations }) {
|
|
56
|
+
return `${selector} {
|
|
57
|
+
${Object.entries(declarations).map(([property, value]) => `${property}: ${value}`).join("; ")};
|
|
58
|
+
}`;
|
|
59
|
+
}
|
|
60
|
+
function getChildLayoutStyleRules({
|
|
61
|
+
selector,
|
|
62
|
+
layout = {},
|
|
63
|
+
viewportOverrides,
|
|
64
|
+
parentLayout = {},
|
|
65
|
+
includeContainerQuery = true
|
|
66
|
+
}) {
|
|
67
|
+
const hasViewportOverrides = viewportOverrides !== void 0;
|
|
68
|
+
const effectiveLayout = hasViewportOverrides ? {
|
|
69
|
+
...layout,
|
|
70
|
+
...viewportOverrides
|
|
71
|
+
} : layout;
|
|
72
|
+
const hasViewportOverride = (key) => Object.hasOwn(viewportOverrides || {}, key);
|
|
53
73
|
const {
|
|
54
74
|
selfStretch,
|
|
55
75
|
flexSize,
|
|
@@ -57,62 +77,40 @@ function useBlockPropsChildLayoutStyles({ style }) {
|
|
|
57
77
|
rowStart,
|
|
58
78
|
columnSpan,
|
|
59
79
|
rowSpan
|
|
60
|
-
} =
|
|
61
|
-
const parentLayout = (0, import_layout.useLayout)() || {};
|
|
80
|
+
} = effectiveLayout;
|
|
62
81
|
const { columnCount, minimumColumnWidth } = parentLayout;
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
if (columnStart && typeof columnStart !== "number") {
|
|
67
|
-
throw new Error("columnStart must be a number");
|
|
68
|
-
}
|
|
69
|
-
if (rowStart && typeof rowStart !== "number") {
|
|
70
|
-
throw new Error("rowStart must be a number");
|
|
71
|
-
}
|
|
72
|
-
if (columnSpan && typeof columnSpan !== "number") {
|
|
73
|
-
throw new Error("columnSpan must be a number");
|
|
74
|
-
}
|
|
75
|
-
if (rowSpan && typeof rowSpan !== "number") {
|
|
76
|
-
throw new Error("rowSpan must be a number");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
let css = "";
|
|
80
|
-
if (shouldRenderChildLayoutStyles) {
|
|
82
|
+
const rules = [];
|
|
83
|
+
const declarations = {};
|
|
84
|
+
if (!hasViewportOverrides || hasViewportOverride("selfStretch") || hasViewportOverride("flexSize")) {
|
|
81
85
|
if (selfStretch === "fixed" && flexSize) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
box-sizing: border-box;
|
|
85
|
-
}`;
|
|
86
|
+
declarations["flex-basis"] = flexSize;
|
|
87
|
+
declarations["box-sizing"] = "border-box";
|
|
86
88
|
} else if (selfStretch === "fill") {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}`;
|
|
89
|
+
declarations["flex-grow"] = "1";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!hasViewportOverrides || hasViewportOverride("columnStart") || hasViewportOverride("columnSpan")) {
|
|
93
|
+
if (columnStart && columnSpan) {
|
|
94
|
+
declarations["grid-column"] = `${columnStart} / span ${columnSpan}`;
|
|
94
95
|
} else if (columnStart) {
|
|
95
|
-
|
|
96
|
-
grid-column: ${columnStart};
|
|
97
|
-
}`;
|
|
96
|
+
declarations["grid-column"] = `${columnStart}`;
|
|
98
97
|
} else if (columnSpan) {
|
|
99
|
-
|
|
100
|
-
grid-column: span ${columnSpan};
|
|
101
|
-
}`;
|
|
98
|
+
declarations["grid-column"] = `span ${columnSpan}`;
|
|
102
99
|
}
|
|
100
|
+
}
|
|
101
|
+
if (!hasViewportOverrides || hasViewportOverride("rowStart") || hasViewportOverride("rowSpan")) {
|
|
103
102
|
if (rowStart && rowSpan) {
|
|
104
|
-
|
|
105
|
-
grid-row: ${rowStart} / span ${rowSpan};
|
|
106
|
-
}`;
|
|
103
|
+
declarations["grid-row"] = `${rowStart} / span ${rowSpan}`;
|
|
107
104
|
} else if (rowStart) {
|
|
108
|
-
|
|
109
|
-
grid-row: ${rowStart};
|
|
110
|
-
}`;
|
|
105
|
+
declarations["grid-row"] = `${rowStart}`;
|
|
111
106
|
} else if (rowSpan) {
|
|
112
|
-
|
|
113
|
-
grid-row: span ${rowSpan};
|
|
114
|
-
}`;
|
|
107
|
+
declarations["grid-row"] = `span ${rowSpan}`;
|
|
115
108
|
}
|
|
109
|
+
}
|
|
110
|
+
if (Object.keys(declarations).length) {
|
|
111
|
+
rules.push({ selector, declarations });
|
|
112
|
+
}
|
|
113
|
+
if (includeContainerQuery && !hasViewportOverrides) {
|
|
116
114
|
if ((columnSpan || columnStart) && (minimumColumnWidth || !columnCount)) {
|
|
117
115
|
let parentColumnValue = parseFloat(minimumColumnWidth);
|
|
118
116
|
if (isNaN(parentColumnValue)) {
|
|
@@ -137,16 +135,98 @@ function useBlockPropsChildLayoutStyles({ style }) {
|
|
|
137
135
|
const containerQueryValue = numColsToBreakAt * parentColumnValue + (numColsToBreakAt - 1) * defaultGapValue;
|
|
138
136
|
const minimumContainerQueryValue = parentColumnValue * 2 + defaultGapValue - 1;
|
|
139
137
|
const gridColumnValue = columnSpan && columnSpan > 1 ? "1/-1" : "auto";
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
rules.push({
|
|
139
|
+
rulesGroup: `@container (max-width: ${Math.max(
|
|
140
|
+
containerQueryValue,
|
|
141
|
+
minimumContainerQueryValue
|
|
142
|
+
)}${parentColumnUnit})`,
|
|
143
|
+
selector,
|
|
144
|
+
declarations: {
|
|
145
|
+
"grid-column": gridColumnValue,
|
|
146
|
+
"grid-row": "auto"
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return rules;
|
|
152
|
+
}
|
|
153
|
+
function getChildLayoutStyles({
|
|
154
|
+
selector,
|
|
155
|
+
layout = {},
|
|
156
|
+
parentLayout = {},
|
|
157
|
+
includeContainerQuery = true
|
|
158
|
+
}) {
|
|
159
|
+
return getChildLayoutStyleRules({
|
|
160
|
+
selector,
|
|
161
|
+
layout,
|
|
162
|
+
parentLayout,
|
|
163
|
+
includeContainerQuery
|
|
164
|
+
}).map((rule) => {
|
|
165
|
+
const serializedRule = serializeRule(rule);
|
|
166
|
+
return rule.rulesGroup ? `${rule.rulesGroup} {
|
|
167
|
+
${serializedRule}
|
|
168
|
+
}` : serializedRule;
|
|
169
|
+
}).join("");
|
|
170
|
+
}
|
|
171
|
+
function getResponsiveChildLayoutStyles({
|
|
172
|
+
style = {},
|
|
173
|
+
selector,
|
|
174
|
+
parentLayout = {}
|
|
175
|
+
}) {
|
|
176
|
+
const baseLayout = style?.layout ?? {};
|
|
177
|
+
return Object.entries(RESPONSIVE_BREAKPOINTS).map(([viewport, mediaQuery]) => {
|
|
178
|
+
const viewportLayout = style?.[viewport]?.layout;
|
|
179
|
+
if (!viewportLayout || !Object.keys(viewportLayout).length) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
const viewportRules = getChildLayoutStyleRules({
|
|
183
|
+
selector,
|
|
184
|
+
layout: baseLayout,
|
|
185
|
+
viewportOverrides: viewportLayout,
|
|
186
|
+
parentLayout,
|
|
187
|
+
includeContainerQuery: false
|
|
188
|
+
});
|
|
189
|
+
const css = viewportRules.map(serializeRule).join("");
|
|
190
|
+
return css ? `${mediaQuery}{${css}}` : "";
|
|
191
|
+
}).filter(Boolean).join("");
|
|
192
|
+
}
|
|
193
|
+
function useBlockPropsChildLayoutStyles({ style }) {
|
|
194
|
+
const shouldRenderChildLayoutStyles = (0, import_data.useSelect)((select) => {
|
|
195
|
+
return !select(import_store.store).getSettings().disableLayoutStyles;
|
|
196
|
+
});
|
|
197
|
+
const layout = style?.layout ?? {};
|
|
198
|
+
const { columnStart, rowStart, columnSpan, rowSpan } = layout;
|
|
199
|
+
const parentLayout = (0, import_layout.useLayout)() || {};
|
|
200
|
+
const id = (0, import_compose.useInstanceId)(LAYOUT_CHILD_BLOCK_PROPS_REFERENCE);
|
|
201
|
+
const selector = `.wp-container-content-${id}`;
|
|
202
|
+
if (process.env.NODE_ENV === "development") {
|
|
203
|
+
if (columnStart && typeof columnStart !== "number") {
|
|
204
|
+
throw new Error("columnStart must be a number");
|
|
205
|
+
}
|
|
206
|
+
if (rowStart && typeof rowStart !== "number") {
|
|
207
|
+
throw new Error("rowStart must be a number");
|
|
149
208
|
}
|
|
209
|
+
if (columnSpan && typeof columnSpan !== "number") {
|
|
210
|
+
throw new Error("columnSpan must be a number");
|
|
211
|
+
}
|
|
212
|
+
if (rowSpan && typeof rowSpan !== "number") {
|
|
213
|
+
throw new Error("rowSpan must be a number");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
let css = "";
|
|
217
|
+
if (shouldRenderChildLayoutStyles) {
|
|
218
|
+
css = [
|
|
219
|
+
getChildLayoutStyles({
|
|
220
|
+
selector,
|
|
221
|
+
layout,
|
|
222
|
+
parentLayout
|
|
223
|
+
}),
|
|
224
|
+
getResponsiveChildLayoutStyles({
|
|
225
|
+
style,
|
|
226
|
+
selector,
|
|
227
|
+
parentLayout
|
|
228
|
+
})
|
|
229
|
+
].join("");
|
|
150
230
|
}
|
|
151
231
|
(0, import_utils.useStyleOverride)({ css });
|
|
152
232
|
if (!css) {
|
|
@@ -286,4 +366,10 @@ var layout_child_default = {
|
|
|
286
366
|
return true;
|
|
287
367
|
}
|
|
288
368
|
};
|
|
369
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
370
|
+
0 && (module.exports = {
|
|
371
|
+
getChildLayoutStyleRules,
|
|
372
|
+
getChildLayoutStyles,
|
|
373
|
+
getResponsiveChildLayoutStyles
|
|
374
|
+
});
|
|
289
375
|
//# sourceMappingURL=layout-child.cjs.map
|