@wordpress/block-editor 16.0.0 → 16.1.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 +18 -0
- package/README.md +8 -0
- package/build/components/alignment-control/ui.cjs +2 -4
- package/build/components/alignment-control/ui.cjs.map +2 -2
- package/build/components/background-image-control/index.cjs +40 -10
- package/build/components/background-image-control/index.cjs.map +2 -2
- package/build/components/block-alignment-control/ui.cjs +5 -3
- package/build/components/block-alignment-control/ui.cjs.map +2 -2
- package/build/components/block-inspector/index.cjs +73 -46
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-list/block-html.cjs +4 -1
- package/build/components/block-list/block-html.cjs.map +2 -2
- package/build/components/block-list/use-block-props/index.cjs +5 -2
- 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 +2 -3
- package/build/components/block-list/use-block-props/use-focus-handler.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs +48 -0
- package/build/components/block-list/use-block-props/use-register-block-event-handlers.cjs.map +7 -0
- package/build/components/block-parent-selector/index.cjs +2 -2
- package/build/components/block-parent-selector/index.cjs.map +2 -2
- package/build/components/block-toolbar/switch-section-style.cjs +4 -2
- package/build/components/block-toolbar/switch-section-style.cjs.map +3 -3
- package/build/components/block-tools/empty-block-inserter.cjs +2 -7
- package/build/components/block-tools/empty-block-inserter.cjs.map +2 -2
- package/build/components/block-vertical-alignment-control/ui.cjs +3 -5
- package/build/components/block-vertical-alignment-control/ui.cjs.map +2 -2
- package/build/components/border-radius-control/utils.cjs +8 -58
- package/build/components/border-radius-control/utils.cjs.map +2 -2
- package/build/components/colors-gradients/control.cjs +5 -3
- package/build/components/colors-gradients/control.cjs.map +2 -2
- package/build/components/dimension-control/index.cjs +30 -20
- package/build/components/dimension-control/index.cjs.map +3 -3
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs +9 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +3 -3
- package/build/components/editor-styles/index.cjs +9 -1
- package/build/components/editor-styles/index.cjs.map +2 -2
- package/build/components/global-styles/background-panel.cjs +66 -25
- package/build/components/global-styles/background-panel.cjs.map +3 -3
- package/build/components/global-styles/border-panel.cjs +153 -55
- package/build/components/global-styles/border-panel.cjs.map +3 -3
- package/build/components/global-styles/color-gradient-dropdown-item.cjs +46 -14
- package/build/components/global-styles/color-gradient-dropdown-item.cjs.map +3 -3
- package/build/components/global-styles/color-panel.cjs +63 -17
- package/build/components/global-styles/color-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +242 -64
- package/build/components/global-styles/dimensions-panel.cjs.map +3 -3
- package/build/components/global-styles/filters-panel.cjs +59 -20
- package/build/components/global-styles/filters-panel.cjs.map +3 -3
- package/build/components/global-styles/hooks.cjs +4 -1
- package/build/components/global-styles/hooks.cjs.map +2 -2
- package/build/components/global-styles/inheritance/index.cjs +142 -0
- package/build/components/global-styles/inheritance/index.cjs.map +7 -0
- package/build/components/global-styles/inherited-value-context.cjs +173 -0
- package/build/components/global-styles/inherited-value-context.cjs.map +7 -0
- package/build/components/global-styles/shadow-panel-components.cjs +38 -20
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/global-styles/state-control.cjs +1 -1
- package/build/components/global-styles/state-control.cjs.map +2 -2
- package/build/components/global-styles/typography-panel.cjs +271 -78
- package/build/components/global-styles/typography-panel.cjs.map +3 -3
- package/build/components/inspector-controls-tabs/styles-tab.cjs +10 -1
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
- package/build/components/line-height-control/index.cjs +1 -1
- package/build/components/line-height-control/index.cjs.map +2 -2
- package/build/components/link-control/index.cjs +3 -1
- package/build/components/link-control/index.cjs.map +2 -2
- package/build/components/preset-input-control/index.cjs +2 -1
- package/build/components/preset-input-control/index.cjs.map +2 -2
- package/build/components/provider/block-refs-provider.cjs +8 -2
- package/build/components/provider/block-refs-provider.cjs.map +2 -2
- package/build/components/provider/index.cjs +1 -1
- package/build/components/provider/index.cjs.map +2 -2
- package/build/components/provider/use-block-sync.cjs +18 -6
- package/build/components/provider/use-block-sync.cjs.map +2 -2
- package/build/components/provider/use-media-upload-settings.cjs +3 -1
- package/build/components/provider/use-media-upload-settings.cjs.map +2 -2
- package/build/components/rich-text/index.cjs +23 -13
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/spacing-sizes-control/utils.cjs +6 -19
- package/build/components/spacing-sizes-control/utils.cjs.map +2 -2
- package/build/components/text-indent-control/index.cjs +8 -2
- package/build/components/text-indent-control/index.cjs.map +2 -2
- package/build/components/url-input/index.cjs +303 -344
- package/build/components/url-input/index.cjs.map +3 -3
- package/build/components/writing-flow/index.cjs +2 -0
- package/build/components/writing-flow/index.cjs.map +3 -3
- package/build/components/writing-flow/use-arrow-nav.cjs +24 -1
- package/build/components/writing-flow/use-arrow-nav.cjs.map +2 -2
- package/build/components/writing-flow/use-click-selection.cjs +28 -2
- package/build/components/writing-flow/use-click-selection.cjs.map +2 -2
- package/build/components/writing-flow/use-editable-root-event-handlers.cjs +179 -0
- package/build/components/writing-flow/use-editable-root-event-handlers.cjs.map +7 -0
- package/build/components/writing-flow/use-editable-root.cjs +5 -42
- package/build/components/writing-flow/use-editable-root.cjs.map +2 -2
- package/build/components/writing-flow/use-home-end.cjs +1 -1
- package/build/components/writing-flow/use-home-end.cjs.map +2 -2
- package/build/components/writing-flow/use-selection-observer.cjs +17 -13
- package/build/components/writing-flow/use-selection-observer.cjs.map +2 -2
- package/build/components/writing-flow/utils.cjs +3 -14
- package/build/components/writing-flow/utils.cjs.map +2 -2
- package/build/hooks/background.cjs +13 -10
- package/build/hooks/background.cjs.map +2 -2
- package/build/hooks/block-style-variation.cjs +4 -45
- package/build/hooks/block-style-variation.cjs.map +3 -3
- package/build/hooks/border.cjs +19 -4
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/custom-css.cjs +6 -2
- package/build/hooks/custom-css.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +15 -4
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/duotone.cjs +26 -14
- package/build/hooks/duotone.cjs.map +3 -3
- package/build/hooks/elements.cjs +14 -4
- package/build/hooks/elements.cjs.map +2 -2
- package/build/hooks/line-height.cjs +1 -2
- package/build/hooks/line-height.cjs.map +2 -2
- package/build/hooks/typography.cjs +13 -4
- package/build/hooks/typography.cjs.map +2 -2
- package/build/private-apis.cjs +9 -5
- package/build/private-apis.cjs.map +3 -3
- package/build/store/actions.cjs +9 -4
- package/build/store/actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +28 -1
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/reducer.cjs +6 -6
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +23 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build/utils/native-undo.cjs +55 -0
- package/build/utils/native-undo.cjs.map +7 -0
- package/build-module/components/alignment-control/ui.mjs +2 -4
- package/build-module/components/alignment-control/ui.mjs.map +2 -2
- package/build-module/components/background-image-control/index.mjs +43 -10
- package/build-module/components/background-image-control/index.mjs.map +2 -2
- package/build-module/components/block-alignment-control/ui.mjs +5 -3
- package/build-module/components/block-alignment-control/ui.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +74 -46
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-list/block-html.mjs +4 -1
- package/build-module/components/block-list/block-html.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/index.mjs +5 -2
- 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 +2 -3
- 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-register-block-event-handlers.mjs +28 -0
- package/build-module/components/block-list/use-block-props/use-register-block-event-handlers.mjs.map +7 -0
- package/build-module/components/block-parent-selector/index.mjs +2 -2
- package/build-module/components/block-parent-selector/index.mjs.map +2 -2
- package/build-module/components/block-toolbar/switch-section-style.mjs +4 -2
- package/build-module/components/block-toolbar/switch-section-style.mjs.map +2 -2
- package/build-module/components/block-tools/empty-block-inserter.mjs +2 -7
- package/build-module/components/block-tools/empty-block-inserter.mjs.map +2 -2
- package/build-module/components/block-vertical-alignment-control/ui.mjs +4 -6
- package/build-module/components/block-vertical-alignment-control/ui.mjs.map +2 -2
- package/build-module/components/border-radius-control/utils.mjs +11 -53
- package/build-module/components/border-radius-control/utils.mjs.map +2 -2
- package/build-module/components/colors-gradients/control.mjs +5 -3
- package/build-module/components/colors-gradients/control.mjs.map +2 -2
- package/build-module/components/dimension-control/index.mjs +30 -20
- package/build-module/components/dimension-control/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +10 -6
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
- package/build-module/components/editor-styles/index.mjs +9 -1
- package/build-module/components/editor-styles/index.mjs.map +2 -2
- package/build-module/components/global-styles/background-panel.mjs +71 -29
- package/build-module/components/global-styles/background-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +157 -56
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/color-gradient-dropdown-item.mjs +51 -15
- package/build-module/components/global-styles/color-gradient-dropdown-item.mjs.map +2 -2
- package/build-module/components/global-styles/color-panel.mjs +63 -17
- package/build-module/components/global-styles/color-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +248 -66
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/filters-panel.mjs +64 -21
- package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
- package/build-module/components/global-styles/hooks.mjs +4 -1
- package/build-module/components/global-styles/hooks.mjs.map +2 -2
- package/build-module/components/global-styles/inheritance/index.mjs +108 -0
- package/build-module/components/global-styles/inheritance/index.mjs.map +7 -0
- package/build-module/components/global-styles/inherited-value-context.mjs +141 -0
- package/build-module/components/global-styles/inherited-value-context.mjs.map +7 -0
- package/build-module/components/global-styles/shadow-panel-components.mjs +38 -20
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/global-styles/state-control.mjs +1 -1
- package/build-module/components/global-styles/state-control.mjs.map +2 -2
- package/build-module/components/global-styles/typography-panel.mjs +276 -79
- package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +6 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/line-height-control/index.mjs +1 -1
- package/build-module/components/line-height-control/index.mjs.map +2 -2
- package/build-module/components/link-control/index.mjs +4 -2
- package/build-module/components/link-control/index.mjs.map +2 -2
- package/build-module/components/preset-input-control/index.mjs +2 -1
- package/build-module/components/preset-input-control/index.mjs.map +2 -2
- package/build-module/components/provider/block-refs-provider.mjs +8 -2
- package/build-module/components/provider/block-refs-provider.mjs.map +2 -2
- package/build-module/components/provider/index.mjs +1 -1
- package/build-module/components/provider/index.mjs.map +2 -2
- package/build-module/components/provider/use-block-sync.mjs +18 -6
- package/build-module/components/provider/use-block-sync.mjs.map +2 -2
- package/build-module/components/provider/use-media-upload-settings.mjs +3 -1
- package/build-module/components/provider/use-media-upload-settings.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +28 -14
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/spacing-sizes-control/utils.mjs +6 -18
- package/build-module/components/spacing-sizes-control/utils.mjs.map +2 -2
- package/build-module/components/text-indent-control/index.mjs +8 -2
- package/build-module/components/text-indent-control/index.mjs.map +2 -2
- package/build-module/components/url-input/index.mjs +306 -353
- package/build-module/components/url-input/index.mjs.map +2 -2
- package/build-module/components/writing-flow/index.mjs +2 -0
- package/build-module/components/writing-flow/index.mjs.map +2 -2
- package/build-module/components/writing-flow/use-arrow-nav.mjs +24 -1
- package/build-module/components/writing-flow/use-arrow-nav.mjs.map +2 -2
- package/build-module/components/writing-flow/use-click-selection.mjs +28 -2
- package/build-module/components/writing-flow/use-click-selection.mjs.map +2 -2
- package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs +154 -0
- package/build-module/components/writing-flow/use-editable-root-event-handlers.mjs.map +7 -0
- package/build-module/components/writing-flow/use-editable-root.mjs +5 -37
- package/build-module/components/writing-flow/use-editable-root.mjs.map +2 -2
- package/build-module/components/writing-flow/use-home-end.mjs +1 -1
- package/build-module/components/writing-flow/use-home-end.mjs.map +2 -2
- package/build-module/components/writing-flow/use-selection-observer.mjs +18 -14
- package/build-module/components/writing-flow/use-selection-observer.mjs.map +2 -2
- package/build-module/components/writing-flow/utils.mjs +2 -11
- package/build-module/components/writing-flow/utils.mjs.map +2 -2
- package/build-module/hooks/background.mjs +13 -10
- package/build-module/hooks/background.mjs.map +2 -2
- package/build-module/hooks/block-style-variation.mjs +8 -44
- package/build-module/hooks/block-style-variation.mjs.map +2 -2
- package/build-module/hooks/border.mjs +19 -4
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/custom-css.mjs +7 -3
- package/build-module/hooks/custom-css.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +15 -4
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/duotone.mjs +20 -9
- package/build-module/hooks/duotone.mjs.map +2 -2
- package/build-module/hooks/elements.mjs +14 -4
- package/build-module/hooks/elements.mjs.map +2 -2
- package/build-module/hooks/line-height.mjs +1 -2
- package/build-module/hooks/line-height.mjs.map +2 -2
- package/build-module/hooks/typography.mjs +13 -4
- package/build-module/hooks/typography.mjs.map +2 -2
- package/build-module/private-apis.mjs +7 -3
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +9 -4
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +29 -1
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +6 -6
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +23 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/utils/native-undo.mjs +29 -0
- package/build-module/utils/native-undo.mjs.map +7 -0
- package/build-style/content-rtl.css +10 -18
- package/build-style/content.css +10 -18
- package/build-style/style-rtl.css +150 -7
- package/build-style/style.css +150 -7
- package/package.json +40 -41
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +1 -1
- package/src/components/alignment-control/ui.js +2 -4
- package/src/components/background-image-control/index.js +74 -37
- package/src/components/background-image-control/style.scss +13 -4
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +3 -3
- package/src/components/block-alignment-control/test/index.js +1 -1
- package/src/components/block-alignment-control/ui.js +4 -2
- package/src/components/block-breadcrumb/test/__snapshots__/index.js.snap +1 -1
- package/src/components/block-compare/test/__snapshots__/block-view.js.snap +1 -1
- package/src/components/block-icon/test/__snapshots__/index.js.snap +1 -1
- package/src/components/block-inspector/index.js +60 -31
- package/src/components/block-list/block-html.js +5 -0
- package/src/components/block-list/content.scss +1 -11
- package/src/components/block-list/use-block-props/index.js +5 -1
- package/src/components/block-list/use-block-props/use-focus-handler.js +9 -8
- package/src/components/block-list/use-block-props/use-register-block-event-handlers.js +45 -0
- package/src/components/block-parent-selector/index.js +5 -2
- package/src/components/block-toolbar/switch-section-style.js +5 -2
- package/src/components/block-tools/empty-block-inserter.js +3 -7
- package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
- package/src/components/block-vertical-alignment-control/test/index.js +18 -2
- package/src/components/block-vertical-alignment-control/ui.js +3 -5
- package/src/components/border-radius-control/test/utils.js +0 -41
- package/src/components/border-radius-control/utils.js +16 -107
- package/src/components/button-block-appender/content.scss +6 -2
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/colors-gradients/control.js +6 -3
- package/src/components/default-block-appender/test/__snapshots__/index.js.snap +1 -1
- package/src/components/dimension-control/index.js +13 -1
- package/src/components/dimensions-tool/aspect-ratio-tool.js +13 -6
- package/src/components/editor-styles/index.js +16 -1
- package/src/components/global-styles/background-panel.js +107 -34
- package/src/components/global-styles/border-panel.js +219 -48
- package/src/components/global-styles/color-gradient-dropdown-item.js +93 -28
- package/src/components/global-styles/color-panel.js +92 -11
- package/src/components/global-styles/dimensions-panel.js +422 -71
- package/src/components/global-styles/filters-panel.js +88 -28
- package/src/components/global-styles/hooks.js +8 -1
- package/src/components/global-styles/inheritance/index.js +204 -0
- package/src/components/global-styles/inheritance/style.scss +184 -0
- package/src/components/global-styles/inheritance/test/index.js +281 -0
- package/src/components/global-styles/inherited-value-context.js +271 -0
- package/src/components/global-styles/shadow-panel-components.js +48 -26
- package/src/components/global-styles/state-control.js +2 -2
- package/src/components/global-styles/test/background-panel.js +338 -1
- package/src/components/global-styles/test/border-panel.js +441 -0
- package/src/components/global-styles/test/color-panel.js +182 -2
- package/src/components/global-styles/test/dimensions-panel.js +753 -0
- package/src/components/global-styles/test/filters-panel.js +194 -0
- package/src/components/global-styles/test/inherited-value-context-core.js +98 -0
- package/src/components/global-styles/test/inherited-value-context.js +454 -0
- package/src/components/global-styles/test/typography-panel-core.js +185 -0
- package/src/components/global-styles/test/typography-panel.js +849 -12
- package/src/components/global-styles/typography-panel.js +449 -100
- package/src/components/image-editor/style.scss +33 -0
- package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
- package/src/components/inspector-controls-tabs/styles-tab.js +5 -1
- package/src/components/line-height-control/index.js +1 -1
- package/src/components/link-control/index.js +7 -2
- package/src/components/preset-input-control/index.js +4 -1
- package/src/components/provider/block-refs-provider.js +12 -2
- package/src/components/provider/index.js +2 -2
- package/src/components/provider/use-block-sync.js +18 -6
- package/src/components/provider/use-media-upload-settings.js +2 -0
- package/src/components/rich-text/index.js +37 -16
- package/src/components/spacing-sizes-control/test/utils.js +16 -5
- package/src/components/spacing-sizes-control/utils.js +11 -28
- package/src/components/text-indent-control/index.js +8 -0
- package/src/components/url-input/index.js +363 -431
- package/src/components/url-input/test/index.js +592 -0
- package/src/components/warning/test/__snapshots__/index.js.snap +1 -1
- package/src/components/writing-flow/index.js +2 -0
- package/src/components/writing-flow/use-arrow-nav.js +51 -1
- package/src/components/writing-flow/use-click-selection.js +54 -3
- package/src/components/writing-flow/use-editable-root-event-handlers.js +266 -0
- package/src/components/writing-flow/use-editable-root.js +7 -77
- package/src/components/writing-flow/use-home-end.js +17 -9
- package/src/components/writing-flow/use-selection-observer.js +32 -15
- package/src/components/writing-flow/utils.js +3 -24
- package/src/hooks/background.js +26 -21
- package/src/hooks/block-fields/rich-text/styles.scss +1 -1
- package/src/hooks/block-style-variation.js +8 -74
- package/src/hooks/border.js +19 -4
- package/src/hooks/custom-css.js +15 -6
- package/src/hooks/dimensions.js +17 -4
- package/src/hooks/duotone.js +26 -8
- package/src/hooks/elements.js +14 -3
- package/src/hooks/line-height.js +0 -1
- package/src/hooks/test/inherited-value-wiring.js +411 -0
- package/src/hooks/test/preset-round-trip.js +456 -0
- package/src/hooks/typography.js +35 -23
- package/src/private-apis.js +11 -2
- package/src/store/actions.js +10 -4
- package/src/store/private-selectors.js +57 -1
- package/src/store/reducer.js +9 -9
- package/src/store/selectors.js +56 -8
- package/src/store/test/private-selectors.js +160 -1
- package/src/style.scss +2 -0
- package/src/utils/native-undo.js +56 -0
- package/build/components/duotone/utils.cjs +0 -87
- package/build/components/duotone/utils.cjs.map +0 -7
- package/build-module/components/duotone/utils.mjs +0 -59
- package/build-module/components/duotone/utils.mjs.map +0 -7
- package/src/components/duotone/utils.js +0 -90
- package/src/hooks/test/get-variation-styles-with-ref-values.js +0 -91
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { click } from '@ariakit/test';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
getInheritanceProps,
|
|
17
|
+
InheritanceResetButton,
|
|
18
|
+
InheritanceToolsPanelItem,
|
|
19
|
+
} from '../';
|
|
20
|
+
|
|
21
|
+
describe( 'InheritanceResetButton', () => {
|
|
22
|
+
test( 'renders an always-visible reset button labelled for the inherited value', () => {
|
|
23
|
+
render( <InheritanceResetButton onResetToInherited={ () => {} } /> );
|
|
24
|
+
expect(
|
|
25
|
+
screen.getByRole( 'button', {
|
|
26
|
+
name: 'Reset to inherited value',
|
|
27
|
+
} )
|
|
28
|
+
).toBeVisible();
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
test( 'invokes the reset handler when activated', async () => {
|
|
32
|
+
const onResetToInherited = jest.fn();
|
|
33
|
+
render(
|
|
34
|
+
<InheritanceResetButton onResetToInherited={ onResetToInherited } />
|
|
35
|
+
);
|
|
36
|
+
await click(
|
|
37
|
+
screen.getByRole( 'button', { name: 'Reset to inherited value' } )
|
|
38
|
+
);
|
|
39
|
+
expect( onResetToInherited ).toHaveBeenCalledTimes( 1 );
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
test( 'does not expose a menu or a push-to-Global-Styles action', () => {
|
|
43
|
+
render( <InheritanceResetButton onResetToInherited={ () => {} } /> );
|
|
44
|
+
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument();
|
|
45
|
+
expect(
|
|
46
|
+
screen.queryByRole( 'menuitem', { name: /Make default/ } )
|
|
47
|
+
).not.toBeInTheDocument();
|
|
48
|
+
} );
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
describe( 'getInheritanceProps', () => {
|
|
52
|
+
test( 'returns explicit false state when neither flag is set', () => {
|
|
53
|
+
expect( getInheritanceProps( false, false ) ).toEqual( {
|
|
54
|
+
isInherited: false,
|
|
55
|
+
hasLocalOverride: false,
|
|
56
|
+
} );
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
test( 'returns ONLY the inherited className when isInherited is set', () => {
|
|
60
|
+
// The inherited state is conveyed purely through the className hook
|
|
61
|
+
// (`is-inherited-from-global-styles`), which the SCSS uses to apply
|
|
62
|
+
// the dotted-underline label treatment. No dot is rendered.
|
|
63
|
+
expect( getInheritanceProps( true, false ) ).toEqual( {
|
|
64
|
+
className: 'is-inherited-from-global-styles',
|
|
65
|
+
isInherited: true,
|
|
66
|
+
hasLocalOverride: false,
|
|
67
|
+
} );
|
|
68
|
+
} );
|
|
69
|
+
|
|
70
|
+
test( 'returns the local-override className when hasLocalOverride is set', () => {
|
|
71
|
+
expect( getInheritanceProps( false, true ) ).toEqual( {
|
|
72
|
+
className: 'has-local-override-from-global-styles',
|
|
73
|
+
isInherited: false,
|
|
74
|
+
hasLocalOverride: true,
|
|
75
|
+
} );
|
|
76
|
+
} );
|
|
77
|
+
|
|
78
|
+
test( 'returns ONLY the local-override className when both flags are passed (mutual exclusion)', () => {
|
|
79
|
+
// A buggy caller could pass both as `true`. The visual
|
|
80
|
+
// contract is mutual exclusion — local-override always wins.
|
|
81
|
+
const result = getInheritanceProps( true, true );
|
|
82
|
+
expect( result.className ).toContain(
|
|
83
|
+
'has-local-override-from-global-styles'
|
|
84
|
+
);
|
|
85
|
+
expect( result.isInherited ).toBe( false );
|
|
86
|
+
expect( result.hasLocalOverride ).toBe( true );
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
test( 'coerces truthy/falsy non-boolean inputs', () => {
|
|
90
|
+
// Common pattern: callers pass an undefined or null inherited
|
|
91
|
+
// value that we want to treat as "no local override" rather
|
|
92
|
+
// than letting it slip through as truthy.
|
|
93
|
+
expect( getInheritanceProps( undefined, undefined ) ).toEqual( {
|
|
94
|
+
isInherited: false,
|
|
95
|
+
hasLocalOverride: false,
|
|
96
|
+
} );
|
|
97
|
+
expect( getInheritanceProps( null, null ) ).toEqual( {
|
|
98
|
+
isInherited: false,
|
|
99
|
+
hasLocalOverride: false,
|
|
100
|
+
} );
|
|
101
|
+
expect( getInheritanceProps( '', '' ) ).toEqual( {
|
|
102
|
+
isInherited: false,
|
|
103
|
+
hasLocalOverride: false,
|
|
104
|
+
} );
|
|
105
|
+
// Truthy non-boolean
|
|
106
|
+
expect( getInheritanceProps( 'inherited', 0 ) ).toEqual( {
|
|
107
|
+
className: 'is-inherited-from-global-styles',
|
|
108
|
+
isInherited: true,
|
|
109
|
+
hasLocalOverride: false,
|
|
110
|
+
} );
|
|
111
|
+
expect( getInheritanceProps( 0, 'local' ) ).toEqual( {
|
|
112
|
+
className: 'has-local-override-from-global-styles',
|
|
113
|
+
isInherited: false,
|
|
114
|
+
hasLocalOverride: true,
|
|
115
|
+
} );
|
|
116
|
+
} );
|
|
117
|
+
|
|
118
|
+
test( 'merges a base className with the inherited class hook', () => {
|
|
119
|
+
expect( getInheritanceProps( true, false, 'single-column' ) ).toEqual( {
|
|
120
|
+
className: 'single-column is-inherited-from-global-styles',
|
|
121
|
+
isInherited: true,
|
|
122
|
+
hasLocalOverride: false,
|
|
123
|
+
} );
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
test( 'merges a base className with the local-override class hook', () => {
|
|
127
|
+
expect( getInheritanceProps( false, true, 'single-column' ) ).toEqual( {
|
|
128
|
+
className: 'single-column has-local-override-from-global-styles',
|
|
129
|
+
isInherited: false,
|
|
130
|
+
hasLocalOverride: true,
|
|
131
|
+
} );
|
|
132
|
+
} );
|
|
133
|
+
|
|
134
|
+
test( 'returns just the base className when neither flag is set', () => {
|
|
135
|
+
expect( getInheritanceProps( false, false, 'single-column' ) ).toEqual(
|
|
136
|
+
{
|
|
137
|
+
className: 'single-column',
|
|
138
|
+
isInherited: false,
|
|
139
|
+
hasLocalOverride: false,
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
} );
|
|
143
|
+
} );
|
|
144
|
+
|
|
145
|
+
describe( 'InheritanceToolsPanelItem inherited state', () => {
|
|
146
|
+
function renderInheritedItem( label, labelClassName ) {
|
|
147
|
+
return render(
|
|
148
|
+
<ToolsPanel label="Panel" panelId="panel">
|
|
149
|
+
<InheritanceToolsPanelItem
|
|
150
|
+
{ ...getInheritanceProps( true, false ) }
|
|
151
|
+
label={ label }
|
|
152
|
+
panelId="panel"
|
|
153
|
+
isShownByDefault
|
|
154
|
+
hasValue={ () => false }
|
|
155
|
+
>
|
|
156
|
+
<div className={ labelClassName }>{ label }</div>
|
|
157
|
+
</InheritanceToolsPanelItem>
|
|
158
|
+
</ToolsPanel>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The SCSS treatment keys off the label class, and controls on a bare
|
|
163
|
+
// `UnitControl`/`NumberControl` expose `input-control__label` rather than
|
|
164
|
+
// the usual `base-control__label`, so guard both.
|
|
165
|
+
test.each( [
|
|
166
|
+
[ 'base-control', 'components-base-control__label' ],
|
|
167
|
+
[ 'input-control', 'components-input-control__label' ],
|
|
168
|
+
] )(
|
|
169
|
+
'nests the %s label inside the inherited-from-global-styles item',
|
|
170
|
+
( _name, labelClassName ) => {
|
|
171
|
+
renderInheritedItem( 'Line height', labelClassName );
|
|
172
|
+
const label = screen.getByText( 'Line height' );
|
|
173
|
+
expect( label ).toHaveClass( labelClassName );
|
|
174
|
+
expect(
|
|
175
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
176
|
+
label.closest( '.is-inherited-from-global-styles' )
|
|
177
|
+
).not.toBeNull();
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
test( 'does not render a reset dot in the inherited state', () => {
|
|
182
|
+
renderInheritedItem( 'Line height', 'components-base-control__label' );
|
|
183
|
+
expect(
|
|
184
|
+
screen.queryByRole( 'button', {
|
|
185
|
+
name: 'Reset to inherited value',
|
|
186
|
+
} )
|
|
187
|
+
).not.toBeInTheDocument();
|
|
188
|
+
} );
|
|
189
|
+
} );
|
|
190
|
+
|
|
191
|
+
describe( 'InheritanceToolsPanelItem local-override reset dot', () => {
|
|
192
|
+
function renderItem( props ) {
|
|
193
|
+
return render(
|
|
194
|
+
<ToolsPanel label="Panel" panelId="panel">
|
|
195
|
+
<InheritanceToolsPanelItem
|
|
196
|
+
label="Line height"
|
|
197
|
+
panelId="panel"
|
|
198
|
+
isShownByDefault
|
|
199
|
+
hasValue={ () => false }
|
|
200
|
+
{ ...props }
|
|
201
|
+
>
|
|
202
|
+
<div className="components-base-control__label">
|
|
203
|
+
Line height
|
|
204
|
+
</div>
|
|
205
|
+
</InheritanceToolsPanelItem>
|
|
206
|
+
</ToolsPanel>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
test( 'renders the reset dot as a sibling of the control, not inside the label', () => {
|
|
211
|
+
renderItem( {
|
|
212
|
+
hasLocalOverride: true,
|
|
213
|
+
onDeselect: () => {},
|
|
214
|
+
} );
|
|
215
|
+
const resetButton = screen.getByRole( 'button', {
|
|
216
|
+
name: 'Reset to inherited value',
|
|
217
|
+
} );
|
|
218
|
+
expect( resetButton ).toBeVisible();
|
|
219
|
+
|
|
220
|
+
// The reset dot is a plain sibling; it must never be nested inside
|
|
221
|
+
// the label (which would create an interactive-in-label a11y issue).
|
|
222
|
+
expect(
|
|
223
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
224
|
+
resetButton.closest( '.components-base-control__label' )
|
|
225
|
+
).toBeNull();
|
|
226
|
+
} );
|
|
227
|
+
|
|
228
|
+
test( 'does not render the item reset dot when showLocalOverrideActionsInLabel is false', () => {
|
|
229
|
+
// Color/background render their own reset control next to a custom
|
|
230
|
+
// toggle, so the item must not render a second one.
|
|
231
|
+
renderItem( {
|
|
232
|
+
hasLocalOverride: true,
|
|
233
|
+
showLocalOverrideActionsInLabel: false,
|
|
234
|
+
onDeselect: () => {},
|
|
235
|
+
} );
|
|
236
|
+
expect(
|
|
237
|
+
screen.queryByRole( 'button', {
|
|
238
|
+
name: 'Reset to inherited value',
|
|
239
|
+
} )
|
|
240
|
+
).not.toBeInTheDocument();
|
|
241
|
+
} );
|
|
242
|
+
|
|
243
|
+
test( 'the reset dot invokes the deselect handler', async () => {
|
|
244
|
+
const onDeselect = jest.fn();
|
|
245
|
+
renderItem( { hasLocalOverride: true, onDeselect } );
|
|
246
|
+
await click(
|
|
247
|
+
screen.getByRole( 'button', { name: 'Reset to inherited value' } )
|
|
248
|
+
);
|
|
249
|
+
expect( onDeselect ).toHaveBeenCalled();
|
|
250
|
+
} );
|
|
251
|
+
|
|
252
|
+
test( 'does not offset the reset dot by default', () => {
|
|
253
|
+
renderItem( { hasLocalOverride: true, onDeselect: () => {} } );
|
|
254
|
+
const resetButton = screen.getByRole( 'button', {
|
|
255
|
+
name: 'Reset to inherited value',
|
|
256
|
+
} );
|
|
257
|
+
const affordance =
|
|
258
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
259
|
+
resetButton.closest( '.global-styles-inheritance-affordance' );
|
|
260
|
+
expect( affordance ).not.toHaveClass(
|
|
261
|
+
'global-styles-inheritance-affordance--offset-toggle'
|
|
262
|
+
);
|
|
263
|
+
} );
|
|
264
|
+
|
|
265
|
+
test( 'offsets the reset dot when the control has an inline-end toggle', () => {
|
|
266
|
+
renderItem( {
|
|
267
|
+
hasLocalOverride: true,
|
|
268
|
+
hasInlineEndToggle: true,
|
|
269
|
+
onDeselect: () => {},
|
|
270
|
+
} );
|
|
271
|
+
const resetButton = screen.getByRole( 'button', {
|
|
272
|
+
name: 'Reset to inherited value',
|
|
273
|
+
} );
|
|
274
|
+
const affordance =
|
|
275
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
276
|
+
resetButton.closest( '.global-styles-inheritance-affordance' );
|
|
277
|
+
expect( affordance ).toHaveClass(
|
|
278
|
+
'global-styles-inheritance-affordance--offset-toggle'
|
|
279
|
+
);
|
|
280
|
+
} );
|
|
281
|
+
} );
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useContext, useMemo } from '@wordpress/element';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
7
|
+
import { privateApis as globalStylesEnginePrivateApis } from '@wordpress/global-styles-engine';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { store as blockEditorStore } from '../../store';
|
|
13
|
+
import {
|
|
14
|
+
globalStylesDataKey,
|
|
15
|
+
globalStylesLinksDataKey,
|
|
16
|
+
} from '../../store/private-keys';
|
|
17
|
+
import { getVariationNameFromClass } from '../../hooks/block-style-variation';
|
|
18
|
+
import { useBlockEditContext } from '../block-edit/context';
|
|
19
|
+
import BlockContext from '../block-context';
|
|
20
|
+
import { unlock } from '../../lock-unlock';
|
|
21
|
+
import { isGlobalStylesInheritanceEnabled } from './inheritance';
|
|
22
|
+
|
|
23
|
+
const { resolveStyle } = unlock( globalStylesEnginePrivateApis );
|
|
24
|
+
|
|
25
|
+
// Undefined so the panels fall back to their `inheritedValue = value` default.
|
|
26
|
+
const NO_RESOLVED_STYLE = { value: undefined, sources: undefined };
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reads the Global Styles payload and returns it as a `GlobalStylesConfig`
|
|
30
|
+
* (`{ styles, _links }`), the shape `resolveStyle` expects. `_links` carries
|
|
31
|
+
* the theme-file map used to resolve pointers such as background images.
|
|
32
|
+
*
|
|
33
|
+
* @return {?Object} Global Styles config, or `null` before the payload settles.
|
|
34
|
+
*/
|
|
35
|
+
function useRawGlobalStyles() {
|
|
36
|
+
const { rawGlobalStylesData, links } = useSelect( ( select ) => {
|
|
37
|
+
const settings = select( blockEditorStore ).getSettings();
|
|
38
|
+
return {
|
|
39
|
+
rawGlobalStylesData: settings[ globalStylesDataKey ] ?? null,
|
|
40
|
+
links: settings[ globalStylesLinksDataKey ] ?? null,
|
|
41
|
+
};
|
|
42
|
+
}, [] );
|
|
43
|
+
return useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
rawGlobalStylesData
|
|
46
|
+
? { styles: rawGlobalStylesData, _links: links ?? undefined }
|
|
47
|
+
: null,
|
|
48
|
+
[ rawGlobalStylesData, links ]
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Blocks whose heading level is handed down by a parent through block context
|
|
54
|
+
* rather than held in their own `level` attribute, mapped to that context key
|
|
55
|
+
* and the level they fall back to.
|
|
56
|
+
*
|
|
57
|
+
* Accordion Heading is the only one: the parent Accordion owns the level, and
|
|
58
|
+
* the child's `level` attribute has no default and is absent on pattern-,
|
|
59
|
+
* template- and paste-inserted blocks.
|
|
60
|
+
*/
|
|
61
|
+
const CONTEXT_HEADING_LEVEL_BLOCKS = {
|
|
62
|
+
'core/accordion-heading': {
|
|
63
|
+
contextKey: 'core/accordion-heading-level',
|
|
64
|
+
fallbackLevel: 3,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Resolves the heading level that selects a block's `h1`-`h6` element layer.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} blockName Block name.
|
|
72
|
+
* @param {?number} levelAttribute The block's own `level` attribute, if it has one.
|
|
73
|
+
* @param {?number} contextLevel Level supplied by a parent through block context.
|
|
74
|
+
* @return {?number} Resolved heading level, or `undefined` when the block has none.
|
|
75
|
+
*/
|
|
76
|
+
function getHeadingLevel( blockName, levelAttribute, contextLevel ) {
|
|
77
|
+
const contextOwned = CONTEXT_HEADING_LEVEL_BLOCKS[ blockName ];
|
|
78
|
+
if ( ! contextOwned ) {
|
|
79
|
+
return levelAttribute;
|
|
80
|
+
}
|
|
81
|
+
// Mirrors the block's own chain (Accordion Heading saves `h${ level || 3 }`),
|
|
82
|
+
// so `0` coerces to the fallback instead of reading as a level-0 state.
|
|
83
|
+
return levelAttribute || contextLevel || contextOwned.fallbackLevel;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Reads the heading level a parent supplies through block context.
|
|
88
|
+
*
|
|
89
|
+
* Only the blocks in `CONTEXT_HEADING_LEVEL_BLOCKS` read a key: the value
|
|
90
|
+
* reaches every descendant, so an ordinary Heading inside an Accordion Panel
|
|
91
|
+
* must not pick it up. Returns a primitive so callers can use it as a
|
|
92
|
+
* `useSelect` dependency.
|
|
93
|
+
*
|
|
94
|
+
* @param {?string} blockName Block name.
|
|
95
|
+
* @return {?number} Level from block context, or `undefined`.
|
|
96
|
+
*/
|
|
97
|
+
function useContextHeadingLevel( blockName ) {
|
|
98
|
+
const blockContext = useContext( BlockContext );
|
|
99
|
+
const contextKey = CONTEXT_HEADING_LEVEL_BLOCKS[ blockName ]?.contextKey;
|
|
100
|
+
return contextKey ? blockContext[ contextKey ] : undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Maps a block to the root-level Global Styles *element* layers that paint it
|
|
105
|
+
* on the canvas, in addition to (or instead of) the block's own class — e.g. a
|
|
106
|
+
* Button renders `.wp-element-button`, a level-2 Heading renders `<h2>`.
|
|
107
|
+
*
|
|
108
|
+
* Keys are ordered low to high precedence, so a level-specific `h2` wins over
|
|
109
|
+
* the generic `heading`. A level of `0` (e.g. a Site or Post Title rendered as
|
|
110
|
+
* a paragraph) renders no heading tag, so no element layer applies.
|
|
111
|
+
*
|
|
112
|
+
* Hand-maintained by necessity: the block-to-element relationship is not
|
|
113
|
+
* inferable from block metadata. `supports.color.link` and friends mark blocks
|
|
114
|
+
* that *contain* an element, not blocks that *are* one, and only the inverse
|
|
115
|
+
* element-to-selector map exists (`__EXPERIMENTAL_ELEMENTS`). Standardizing it
|
|
116
|
+
* as a block property is tracked in
|
|
117
|
+
* https://github.com/WordPress/gutenberg/issues/80438.
|
|
118
|
+
*
|
|
119
|
+
* Only blocks that *are* a link fold the `link` layer (e.g. Read More, Login/out
|
|
120
|
+
* and the pagination links render `<a>` as their whole selves). Blocks that
|
|
121
|
+
* merely *contain* a link — the heading family, Paragraph, Group, and the
|
|
122
|
+
* hybrid blocks with a Link colour control (Post Author Name, Post Date, …) —
|
|
123
|
+
* get no `link` layer: their inner-link control reads the
|
|
124
|
+
* `inheritedValue.elements.link` passthrough instead, so folding `link` in would
|
|
125
|
+
* bleed link color into the block's own text.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} blockName Block name.
|
|
128
|
+
* @param {?number} headingLevel Resolved heading level, from `getHeadingLevel`.
|
|
129
|
+
* @return {string[]} Ordered element keys, low to high precedence.
|
|
130
|
+
*/
|
|
131
|
+
function getElementLayers( blockName, headingLevel ) {
|
|
132
|
+
switch ( blockName ) {
|
|
133
|
+
case 'core/button':
|
|
134
|
+
return [ 'button' ];
|
|
135
|
+
case 'core/accordion-heading':
|
|
136
|
+
case 'core/heading':
|
|
137
|
+
case 'core/post-title':
|
|
138
|
+
case 'core/site-title':
|
|
139
|
+
case 'core/query-title':
|
|
140
|
+
case 'core/comments-title':
|
|
141
|
+
case 'core/term-name':
|
|
142
|
+
case 'core/site-tagline':
|
|
143
|
+
if ( headingLevel === 0 ) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
return headingLevel
|
|
147
|
+
? [ 'heading', `h${ headingLevel }` ]
|
|
148
|
+
: [ 'heading' ];
|
|
149
|
+
// Whole-block link blocks: the entire block renders as an `<a>`, so the
|
|
150
|
+
// root `styles.elements.link` layer paints it, mirroring how `button`
|
|
151
|
+
// paints Button. For the blocks whose `color.text` support is disabled
|
|
152
|
+
// this is inert at the (hidden) text control while their typography
|
|
153
|
+
// controls now reflect the link element; Read More (`color.text: true`)
|
|
154
|
+
// surfaces the inherited link color at its Text control.
|
|
155
|
+
case 'core/read-more':
|
|
156
|
+
case 'core/loginout':
|
|
157
|
+
case 'core/post-navigation-link':
|
|
158
|
+
case 'core/query-pagination-next':
|
|
159
|
+
case 'core/query-pagination-previous':
|
|
160
|
+
case 'core/query-pagination-numbers':
|
|
161
|
+
case 'core/comments-pagination-next':
|
|
162
|
+
case 'core/comments-pagination-previous':
|
|
163
|
+
case 'core/comments-pagination-numbers':
|
|
164
|
+
case 'core/comment-edit-link':
|
|
165
|
+
case 'core/comment-reply-link':
|
|
166
|
+
case 'core/post-comments-link':
|
|
167
|
+
return [ 'link' ];
|
|
168
|
+
default:
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Internal hook that derives the active block-style-variation slug from a
|
|
175
|
+
* block's `className` by matching registered styles via
|
|
176
|
+
* `getVariationNameFromClass`, together with the element layers that paint
|
|
177
|
+
* the block. Both come from a single store subscription.
|
|
178
|
+
*
|
|
179
|
+
* The lookup is scoped to a single `useSelect` subscription; the
|
|
180
|
+
* `@wordpress/blocks` registered-styles slice changes only when a block's
|
|
181
|
+
* styles are (un)registered, so this subscription is cold in steady-state
|
|
182
|
+
* editor use.
|
|
183
|
+
*
|
|
184
|
+
* The block's `clientId` comes from the block edit context rather than an
|
|
185
|
+
* argument: these panels always render inside `BlockEditContextProvider`, so
|
|
186
|
+
* the caller does not have to thread it through.
|
|
187
|
+
*
|
|
188
|
+
* @param {?string} blockName Block name (e.g. `core/heading`).
|
|
189
|
+
* @param {?string} className Space-separated class string from block attributes.
|
|
190
|
+
* @return {{ variationName: ?string, headingLevel: ?number }} Variation slug
|
|
191
|
+
* (without the `is-style-` prefix) and the block's heading level, if any.
|
|
192
|
+
*/
|
|
193
|
+
function useVariationAndElements( blockName, className ) {
|
|
194
|
+
const { clientId } = useBlockEditContext();
|
|
195
|
+
const contextHeadingLevel = useContextHeadingLevel( blockName );
|
|
196
|
+
return useSelect(
|
|
197
|
+
( select ) => {
|
|
198
|
+
if ( ! blockName ) {
|
|
199
|
+
return { variationName: null, headingLevel: undefined };
|
|
200
|
+
}
|
|
201
|
+
const registeredStyles =
|
|
202
|
+
select( blocksStore ).getBlockStyles( blockName );
|
|
203
|
+
const { level } =
|
|
204
|
+
select( blockEditorStore ).getBlockAttributes( clientId ) || {};
|
|
205
|
+
// Primitives only: `useSelect` shallow-compares this object, so
|
|
206
|
+
// returning a fresh array here would re-render on every action.
|
|
207
|
+
return {
|
|
208
|
+
variationName: className
|
|
209
|
+
? getVariationNameFromClass( className, registeredStyles )
|
|
210
|
+
: null,
|
|
211
|
+
headingLevel: getHeadingLevel(
|
|
212
|
+
blockName,
|
|
213
|
+
level,
|
|
214
|
+
contextHeadingLevel
|
|
215
|
+
),
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
[ blockName, className, clientId, contextHeadingLevel ]
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Hook: computes the merged, cascade-resolved `inheritedValue` payload and
|
|
224
|
+
* source map for a selected block, ready to hand to a shared Global Styles
|
|
225
|
+
* panel via props.
|
|
226
|
+
*
|
|
227
|
+
* It reads the merged Global Styles payload and the block's applied variation,
|
|
228
|
+
* then folds the Root ‹ Block-type ‹ applied-variation cascade (resolving
|
|
229
|
+
* `{ ref }` envelopes and theme-file pointers) via the pure `resolveStyle`
|
|
230
|
+
* resolver in `@wordpress/global-styles-engine`. All store access lives here;
|
|
231
|
+
* the panels stay presentational.
|
|
232
|
+
*
|
|
233
|
+
* Before the `globalStylesDataKey` payload settles (hydration) or when
|
|
234
|
+
* `blockName` is missing, the hook returns empty value and source objects, so
|
|
235
|
+
* each panel's `inheritedValue = value` default preserves pre-feature behavior.
|
|
236
|
+
*
|
|
237
|
+
* @param {?string} blockName Selected block name (e.g. `core/heading`).
|
|
238
|
+
* @param {?string} className Block `className` used to detect an applied variation.
|
|
239
|
+
* @param {?Object} [selectedState] Selected block style state (`{ viewport, pseudo }`), or null for the default state.
|
|
240
|
+
* @return {{ value: Object, sources: Object }} Merged panel-scoped payload and source map.
|
|
241
|
+
*/
|
|
242
|
+
export function useResolvedStyle( blockName, className, selectedState = null ) {
|
|
243
|
+
const { variationName, headingLevel } = useVariationAndElements(
|
|
244
|
+
blockName,
|
|
245
|
+
className
|
|
246
|
+
);
|
|
247
|
+
const globalStyles = useRawGlobalStyles();
|
|
248
|
+
|
|
249
|
+
return useMemo( () => {
|
|
250
|
+
// Skip the cascade merge entirely when the experiment is off.
|
|
251
|
+
if ( ! isGlobalStylesInheritanceEnabled() ) {
|
|
252
|
+
return NO_RESOLVED_STYLE;
|
|
253
|
+
}
|
|
254
|
+
if ( ! blockName ) {
|
|
255
|
+
return { value: {}, sources: {} };
|
|
256
|
+
}
|
|
257
|
+
return resolveStyle( globalStyles, {
|
|
258
|
+
blockName,
|
|
259
|
+
variationName,
|
|
260
|
+
elements: getElementLayers( blockName, headingLevel ),
|
|
261
|
+
viewport: selectedState?.viewport ?? null,
|
|
262
|
+
pseudoState: selectedState?.pseudo ?? null,
|
|
263
|
+
} );
|
|
264
|
+
}, [
|
|
265
|
+
blockName,
|
|
266
|
+
variationName,
|
|
267
|
+
headingLevel,
|
|
268
|
+
globalStyles,
|
|
269
|
+
selectedState,
|
|
270
|
+
] );
|
|
271
|
+
}
|
|
@@ -22,6 +22,11 @@ import clsx from 'clsx';
|
|
|
22
22
|
|
|
23
23
|
import { Tooltip } from '@wordpress/ui';
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Internal dependencies
|
|
27
|
+
*/
|
|
28
|
+
import { InheritanceResetButton } from './inheritance';
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Shared reference to an empty array for cases where it is important to avoid
|
|
27
32
|
* returning a new array reference on every invocation.
|
|
@@ -119,7 +124,15 @@ export function ShadowIndicator( { type, label, isActive, onSelect, shadow } ) {
|
|
|
119
124
|
);
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
export function ShadowPopover( {
|
|
127
|
+
export function ShadowPopover( {
|
|
128
|
+
shadow,
|
|
129
|
+
onShadowChange,
|
|
130
|
+
settings,
|
|
131
|
+
className,
|
|
132
|
+
hasLocalValue = !! shadow,
|
|
133
|
+
hasLocalOverride = false,
|
|
134
|
+
onReset,
|
|
135
|
+
} ) {
|
|
123
136
|
const popoverProps = {
|
|
124
137
|
placement: 'left-start',
|
|
125
138
|
offset: 36,
|
|
@@ -129,8 +142,15 @@ export function ShadowPopover( { shadow, onShadowChange, settings } ) {
|
|
|
129
142
|
return (
|
|
130
143
|
<Dropdown
|
|
131
144
|
popoverProps={ popoverProps }
|
|
132
|
-
className=
|
|
133
|
-
|
|
145
|
+
className={ clsx(
|
|
146
|
+
'block-editor-global-styles__shadow-dropdown',
|
|
147
|
+
className
|
|
148
|
+
) }
|
|
149
|
+
renderToggle={ renderShadowToggle( shadow, onShadowChange, {
|
|
150
|
+
hasLocalValue,
|
|
151
|
+
hasLocalOverride,
|
|
152
|
+
onReset: onReset ?? ( () => onShadowChange( undefined ) ),
|
|
153
|
+
} ) }
|
|
134
154
|
renderContent={ () => (
|
|
135
155
|
<DropdownContentWrapper paddingSize="medium">
|
|
136
156
|
<ShadowPopoverContainer
|
|
@@ -144,7 +164,8 @@ export function ShadowPopover( { shadow, onShadowChange, settings } ) {
|
|
|
144
164
|
);
|
|
145
165
|
}
|
|
146
166
|
|
|
147
|
-
function renderShadowToggle( shadow, onShadowChange ) {
|
|
167
|
+
function renderShadowToggle( shadow, onShadowChange, resetConfig ) {
|
|
168
|
+
const { hasLocalValue, hasLocalOverride, onReset } = resetConfig;
|
|
148
169
|
return function ShadowToggle( { onToggle, isOpen } ) {
|
|
149
170
|
const shadowButtonRef = useRef( undefined );
|
|
150
171
|
|
|
@@ -158,20 +179,13 @@ function renderShadowToggle( shadow, onShadowChange ) {
|
|
|
158
179
|
ref: shadowButtonRef,
|
|
159
180
|
};
|
|
160
181
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
shadowButtonRef.current?.focus();
|
|
169
|
-
},
|
|
170
|
-
className: clsx(
|
|
171
|
-
'block-editor-global-styles__shadow-editor__remove-button',
|
|
172
|
-
{ 'is-open': isOpen }
|
|
173
|
-
),
|
|
174
|
-
label: __( 'Remove' ),
|
|
182
|
+
const handleReset = () => {
|
|
183
|
+
if ( isOpen ) {
|
|
184
|
+
onToggle();
|
|
185
|
+
}
|
|
186
|
+
onReset();
|
|
187
|
+
// Return focus to parent button.
|
|
188
|
+
shadowButtonRef.current?.focus();
|
|
175
189
|
};
|
|
176
190
|
|
|
177
191
|
return (
|
|
@@ -186,14 +200,22 @@ function renderShadowToggle( shadow, onShadowChange ) {
|
|
|
186
200
|
<FlexItem>{ __( 'Drop shadow' ) }</FlexItem>
|
|
187
201
|
</HStack>
|
|
188
202
|
</Button>
|
|
189
|
-
{
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
{ hasLocalValue &&
|
|
204
|
+
( hasLocalOverride ? (
|
|
205
|
+
<InheritanceResetButton
|
|
206
|
+
className="block-editor-global-styles__shadow-editor__remove-button"
|
|
207
|
+
onResetToInherited={ handleReset }
|
|
208
|
+
/>
|
|
209
|
+
) : (
|
|
210
|
+
<Button
|
|
211
|
+
__next40pxDefaultSize
|
|
212
|
+
size="small"
|
|
213
|
+
icon={ reset }
|
|
214
|
+
label={ __( 'Remove' ) }
|
|
215
|
+
className="block-editor-global-styles__shadow-editor__remove-button"
|
|
216
|
+
onClick={ handleReset }
|
|
217
|
+
/>
|
|
218
|
+
) ) }
|
|
197
219
|
</>
|
|
198
220
|
);
|
|
199
221
|
};
|
|
@@ -86,8 +86,8 @@ export default function StateControl( {
|
|
|
86
86
|
: __( 'Default' );
|
|
87
87
|
const icon = showText ? chevronDown : moreVertical;
|
|
88
88
|
const toggleProps = showText
|
|
89
|
-
? { size: 'compact',
|
|
90
|
-
: { size: '
|
|
89
|
+
? { size: 'compact', iconPosition: 'right' }
|
|
90
|
+
: { size: 'small' };
|
|
91
91
|
|
|
92
92
|
return (
|
|
93
93
|
<Stack
|