@wordpress/block-editor 11.1.0 → 11.3.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 +12 -0
- package/LICENSE.md +1 -1
- package/README.md +28 -4
- package/build/components/alignment-control/ui.js +1 -1
- package/build/components/alignment-control/ui.js.map +1 -1
- package/build/components/autocomplete/index.js +2 -7
- package/build/components/autocomplete/index.js.map +1 -1
- package/build/components/block-actions/index.js +9 -0
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-alignment-matrix-control/index.js +2 -2
- package/build/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build/components/block-card/index.js +2 -4
- package/build/components/block-card/index.js.map +1 -1
- package/build/components/block-edit/index.js +8 -0
- package/build/components/block-edit/index.js.map +1 -1
- package/build/components/block-inspector/index.js +18 -15
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +5 -0
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +0 -1
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-mover/mover-description.js +2 -2
- package/build/components/block-mover/mover-description.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +3 -1
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +1 -1
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/use-patterns-setup.js +2 -2
- package/build/components/block-pattern-setup/use-patterns-setup.js.map +1 -1
- package/build/components/block-patterns-list/index.js +31 -3
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-preview/auto.js +9 -14
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +32 -8
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +1 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings/container.native.js +7 -33
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +12 -3
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +2 -8
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-styles/index.js +3 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-switcher/utils.js +1 -1
- package/build/components/block-switcher/utils.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +55 -47
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +43 -10
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-vertical-alignment-control/icons.js +15 -1
- package/build/components/block-vertical-alignment-control/icons.js.map +1 -1
- package/build/components/block-vertical-alignment-control/ui.js +9 -4
- package/build/components/block-vertical-alignment-control/ui.js.map +1 -1
- package/build/components/color-style-selector/index.js +3 -1
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +3 -4
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/default-style-picker/index.js +1 -0
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/font-family/index.js +1 -7
- package/build/components/font-family/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +1 -1
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/font-sizes/utils.js +1 -1
- package/build/components/font-sizes/utils.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js +5 -8
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/global-styles/context.js +22 -0
- package/build/components/global-styles/context.js.map +1 -0
- package/build/components/global-styles/hooks.js +142 -0
- package/build/components/global-styles/hooks.js.map +1 -0
- package/build/components/global-styles/index.js +42 -0
- package/build/components/global-styles/index.js.map +1 -0
- package/build/components/global-styles/typography-utils.js +92 -0
- package/build/components/global-styles/typography-utils.js.map +1 -0
- package/build/components/global-styles/use-global-styles-output.js +974 -0
- package/build/components/global-styles/use-global-styles-output.js.map +1 -0
- package/build/components/global-styles/utils.js +340 -0
- package/build/components/global-styles/utils.js.map +1 -0
- package/build/components/height-control/index.js +13 -1
- package/build/components/height-control/index.js.map +1 -1
- package/build/components/iframe/index.js +37 -8
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-compatibility-styles.js +6 -1
- package/build/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build/components/image-editor/constants.js +1 -1
- package/build/components/image-editor/constants.js.map +1 -1
- package/build/components/image-editor/context.js +1 -2
- package/build/components/image-editor/context.js.map +1 -1
- package/build/components/image-editor/cropper.js +3 -1
- package/build/components/image-editor/cropper.js.map +1 -1
- package/build/components/image-editor/index.js +13 -9
- package/build/components/image-editor/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +11 -35
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/image-size-control/index.js +2 -7
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +8 -24
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +22 -32
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +8 -23
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-block-context.js +53 -0
- package/build/components/inner-blocks/use-block-context.js.map +1 -0
- package/build/components/inserter/block-patterns-explorer/explorer.js +0 -1
- package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +11 -5
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +2 -2
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +1 -7
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/index.js +8 -6
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +142 -56
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +74 -21
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-panel.js +11 -13
- package/build/components/inserter/media-tab/media-panel.js.map +1 -1
- package/build/components/inserter/media-tab/media-tab.js +6 -3
- package/build/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build/components/inserter/media-tab/utils.js +26 -15
- package/build/components/inserter/media-tab/utils.js.map +1 -1
- package/build/components/inserter/menu.js +12 -5
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/preview-panel.js +5 -3
- package/build/components/inserter/preview-panel.js.map +1 -1
- package/build/components/inserter/search-results.js +2 -7
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/inserter-list-item/index.js +1 -9
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/inspector-controls/fill.js +15 -2
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +14 -1
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +7 -1
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls/index.js +2 -2
- package/build/components/inspector-controls/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +14 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls/slot.native.js +14 -1
- package/build/components/inspector-controls/slot.native.js.map +1 -1
- package/build/components/inspector-controls-tabs/advanced-controls-panel.js +1 -1
- package/build/components/inspector-controls-tabs/advanced-controls-panel.js.map +1 -1
- package/build/components/inspector-controls-tabs/index.js +2 -2
- package/build/components/inspector-controls-tabs/index.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +46 -0
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +6 -4
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +20 -22
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/justify-content-control/ui.js +8 -1
- package/build/components/justify-content-control/ui.js.map +1 -1
- package/build/components/link-control/index.js +45 -17
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -0
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block.js +1 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-upload/index.native.js +4 -1
- package/build/components/media-upload/index.native.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +49 -38
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +38 -5
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/block-select-button.js +10 -4
- package/build/components/off-canvas-editor/block-select-button.js.map +1 -1
- package/build/components/off-canvas-editor/block.js +13 -52
- package/build/components/off-canvas-editor/block.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +25 -10
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +15 -17
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/link-ui.js +2 -2
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js +1 -1
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -1
- package/build/components/provider/index.js +22 -8
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +5 -6
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/rich-text/use-before-input-rules.js +11 -3
- package/build/components/rich-text/use-before-input-rules.js.map +1 -1
- package/build/components/rich-text/use-enter.js +4 -5
- package/build/components/rich-text/use-enter.js.map +1 -1
- package/build/components/rich-text/utils.js +1 -1
- package/build/components/rich-text/utils.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +2 -8
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/components/tool-selector/index.js +3 -1
- package/build/components/tool-selector/index.js.map +1 -1
- package/build/components/url-input/button.js +1 -0
- package/build/components/url-input/button.js.map +1 -1
- package/build/components/url-input/index.js +15 -1
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +7 -8
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/url-popover/link-editor.js +1 -0
- package/build/components/url-popover/link-editor.js.map +1 -1
- package/build/components/use-block-display-information/index.js +1 -1
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/components/use-paste-styles/index.js +188 -0
- package/build/components/use-paste-styles/index.js.map +1 -0
- package/build/components/writing-flow/use-arrow-nav.js +22 -29
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/experiments.js +45 -0
- package/build/experiments.js.map +1 -0
- package/build/experiments.native.js +40 -0
- package/build/experiments.native.js.map +1 -0
- package/build/hooks/anchor.js +2 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +1 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/child-layout.js +5 -1
- package/build/hooks/child-layout.js.map +1 -1
- package/build/hooks/color-panel.js +1 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +3 -3
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/custom-class-name.js +2 -1
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/dimensions.js +7 -5
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/margin.js +1 -0
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +1 -1
- package/build/hooks/padding.js +1 -0
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/position.js +395 -0
- package/build/hooks/position.js.map +1 -0
- package/build/hooks/supports.js +328 -0
- package/build/hooks/supports.js.map +1 -0
- package/build/hooks/typography.js +1 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-color-props.js +3 -3
- package/build/hooks/use-color-props.js.map +1 -1
- package/build/hooks/utils.js +69 -3
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +10 -1
- package/build/index.js.map +1 -1
- package/build/layouts/constrained.js +3 -0
- package/build/layouts/constrained.js.map +1 -1
- package/build/layouts/flex.js +59 -9
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +0 -18
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +3 -30
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -2
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +11 -2
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +78 -0
- package/build/store/private-actions.js.map +1 -0
- package/build/store/private-selectors.js +18 -0
- package/build/store/private-selectors.js.map +1 -0
- package/build/store/reducer.js +7 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +68 -40
- package/build/store/selectors.js.map +1 -1
- package/build/utils/block-variation-transforms.js +1 -1
- package/build/utils/block-variation-transforms.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +1 -1
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build/utils/transform-styles/index.js +1 -7
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/alignment-control/ui.js +1 -1
- package/build-module/components/alignment-control/ui.js.map +1 -1
- package/build-module/components/autocomplete/index.js +2 -6
- package/build-module/components/autocomplete/index.js.map +1 -1
- package/build-module/components/block-actions/index.js +6 -0
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-alignment-matrix-control/index.js +2 -2
- package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build-module/components/block-card/index.js +2 -4
- package/build-module/components/block-card/index.js.map +1 -1
- package/build-module/components/block-edit/index.js +7 -0
- package/build-module/components/block-edit/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +17 -15
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +5 -0
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +0 -1
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-mover/mover-description.js +2 -2
- package/build-module/components/block-mover/mover-description.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +3 -1
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +1 -1
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/use-patterns-setup.js +2 -2
- package/build-module/components/block-pattern-setup/use-patterns-setup.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +32 -3
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +9 -14
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +31 -8
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +1 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +6 -30
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +12 -3
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +2 -7
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-switcher/utils.js +1 -1
- package/build-module/components/block-switcher/utils.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +55 -48
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +42 -11
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-vertical-alignment-control/icons.js +12 -0
- package/build-module/components/block-vertical-alignment-control/icons.js.map +1 -1
- package/build-module/components/block-vertical-alignment-control/ui.js +10 -5
- package/build-module/components/block-vertical-alignment-control/ui.js.map +1 -1
- package/build-module/components/color-style-selector/index.js +3 -1
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +4 -5
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +1 -0
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/font-family/index.js +1 -6
- package/build-module/components/font-family/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +1 -1
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/font-sizes/utils.js +1 -1
- package/build-module/components/font-sizes/utils.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js +5 -7
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/global-styles/context.js +12 -0
- package/build-module/components/global-styles/context.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +121 -0
- package/build-module/components/global-styles/hooks.js.map +1 -0
- package/build-module/components/global-styles/index.js +4 -0
- package/build-module/components/global-styles/index.js.map +1 -0
- package/build-module/components/global-styles/typography-utils.js +84 -0
- package/build-module/components/global-styles/typography-utils.js.map +1 -0
- package/build-module/components/global-styles/use-global-styles-output.js +930 -0
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -0
- package/build-module/components/global-styles/utils.js +321 -0
- package/build-module/components/global-styles/utils.js.map +1 -0
- package/build-module/components/height-control/index.js +14 -1
- package/build-module/components/height-control/index.js.map +1 -1
- package/build-module/components/iframe/index.js +36 -9
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-compatibility-styles.js +6 -1
- package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build-module/components/image-editor/constants.js +1 -1
- package/build-module/components/image-editor/constants.js.map +1 -1
- package/build-module/components/image-editor/context.js +1 -2
- package/build-module/components/image-editor/context.js.map +1 -1
- package/build-module/components/image-editor/cropper.js +3 -1
- package/build-module/components/image-editor/cropper.js.map +1 -1
- package/build-module/components/image-editor/index.js +13 -3
- package/build-module/components/image-editor/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +12 -37
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +2 -6
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +2 -3
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +21 -32
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +9 -22
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-block-context.js +43 -0
- package/build-module/components/inner-blocks/use-block-context.js.map +1 -0
- package/build-module/components/inserter/block-patterns-explorer/explorer.js +0 -1
- package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +11 -5
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +1 -6
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/index.js +8 -6
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +145 -56
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +74 -24
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-panel.js +14 -14
- package/build-module/components/inserter/media-tab/media-panel.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-tab.js +7 -4
- package/build-module/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build-module/components/inserter/media-tab/utils.js +27 -15
- package/build-module/components/inserter/media-tab/utils.js.map +1 -1
- package/build-module/components/inserter/menu.js +12 -5
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/preview-panel.js +5 -3
- package/build-module/components/inserter/preview-panel.js.map +1 -1
- package/build-module/components/inserter/search-results.js +2 -6
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +1 -9
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +14 -2
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +13 -1
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +7 -1
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls/index.js +2 -2
- package/build-module/components/inspector-controls/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +13 -1
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls/slot.native.js +13 -1
- package/build-module/components/inspector-controls/slot.native.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/advanced-controls-panel.js +1 -1
- package/build-module/components/inspector-controls-tabs/advanced-controls-panel.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/index.js +2 -2
- package/build-module/components/inspector-controls-tabs/index.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +33 -0
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build-module/components/inspector-controls-tabs/settings-tab.js +2 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +6 -4
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +20 -22
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/justify-content-control/ui.js +9 -2
- package/build-module/components/justify-content-control/ui.js.map +1 -1
- package/build-module/components/link-control/index.js +45 -16
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -0
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block.js +1 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-upload/index.native.js +4 -1
- package/build-module/components/media-upload/index.native.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +46 -36
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +37 -7
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-select-button.js +9 -4
- package/build-module/components/off-canvas-editor/block-select-button.js.map +1 -1
- package/build-module/components/off-canvas-editor/block.js +15 -52
- package/build-module/components/off-canvas-editor/block.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +23 -11
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +15 -16
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/link-ui.js +2 -2
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +1 -1
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/provider/index.js +17 -8
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +4 -4
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-before-input-rules.js +10 -2
- package/build-module/components/rich-text/use-before-input-rules.js.map +1 -1
- package/build-module/components/rich-text/use-enter.js +4 -5
- package/build-module/components/rich-text/use-enter.js.map +1 -1
- package/build-module/components/rich-text/utils.js +1 -1
- package/build-module/components/rich-text/utils.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +2 -7
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/tool-selector/index.js +3 -1
- package/build-module/components/tool-selector/index.js.map +1 -1
- package/build-module/components/url-input/button.js +1 -0
- package/build-module/components/url-input/button.js.map +1 -1
- package/build-module/components/url-input/index.js +14 -1
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +8 -8
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/url-popover/link-editor.js +1 -0
- package/build-module/components/url-popover/link-editor.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +1 -1
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/components/use-paste-styles/index.js +174 -0
- package/build-module/components/use-paste-styles/index.js.map +1 -0
- package/build-module/components/writing-flow/use-arrow-nav.js +22 -29
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/experiments.js +25 -0
- package/build-module/experiments.js.map +1 -0
- package/build-module/experiments.native.js +23 -0
- package/build-module/experiments.native.js.map +1 -0
- package/build-module/hooks/anchor.js +2 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +1 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/child-layout.js +5 -1
- package/build-module/hooks/child-layout.js.map +1 -1
- package/build-module/hooks/color-panel.js +1 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +3 -3
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/custom-class-name.js +2 -1
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/dimensions.js +6 -5
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/margin.js +1 -0
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +1 -1
- package/build-module/hooks/padding.js +1 -0
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/position.js +354 -0
- package/build-module/hooks/position.js.map +1 -0
- package/build-module/hooks/supports.js +257 -0
- package/build-module/hooks/supports.js.map +1 -0
- package/build-module/hooks/typography.js +1 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-color-props.js +3 -3
- package/build-module/hooks/use-color-props.js.map +1 -1
- package/build-module/hooks/utils.js +70 -4
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/constrained.js +3 -0
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/layouts/flex.js +60 -10
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +0 -18
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +2 -26
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -2
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +8 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +66 -0
- package/build-module/store/private-actions.js.map +1 -0
- package/build-module/store/private-selectors.js +11 -0
- package/build-module/store/private-selectors.js.map +1 -0
- package/build-module/store/reducer.js +7 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +55 -30
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/block-variation-transforms.js +1 -1
- package/build-module/utils/block-variation-transforms.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +1 -1
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +1 -6
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +340 -3
- package/build-style/content.css +340 -3
- package/build-style/style-rtl.css +125 -272
- package/build-style/style.css +125 -272
- package/package.json +30 -29
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +3 -3
- package/src/components/alignment-control/test/index.js +5 -15
- package/src/components/alignment-control/ui.js +1 -1
- package/src/components/autocomplete/index.js +3 -6
- package/src/components/block-actions/index.js +5 -0
- package/src/components/block-alignment-control/test/index.js +3 -11
- package/src/components/block-alignment-matrix-control/index.js +1 -2
- package/src/components/block-card/index.js +1 -4
- package/src/components/block-content-overlay/content.scss +4 -4
- package/src/components/block-edit/index.js +15 -1
- package/src/components/block-icon/content.scss +31 -0
- package/src/components/block-inspector/index.js +15 -17
- package/src/components/block-list/use-in-between-inserter.js +5 -0
- package/src/components/block-lock/modal.js +0 -1
- package/src/components/block-mover/mover-description.js +2 -2
- package/src/components/block-mover/stories/index.js +3 -3
- package/src/components/block-navigation/dropdown.js +1 -1
- package/src/components/block-pattern-setup/index.js +1 -4
- package/src/components/block-pattern-setup/use-patterns-setup.js +2 -5
- package/src/components/block-patterns-list/index.js +29 -3
- package/src/components/block-preview/README.md +9 -9
- package/src/components/block-preview/auto.js +10 -14
- package/src/components/block-preview/content.scss +23 -0
- package/src/components/block-preview/index.js +40 -10
- package/src/components/block-preview/style.scss +0 -23
- package/src/components/block-selection-clearer/index.js +1 -1
- package/src/components/block-selection-clearer/test/index.js +6 -6
- package/src/components/block-settings/container.native.js +7 -26
- package/src/components/block-settings-menu/block-settings-dropdown.js +14 -2
- package/src/components/block-settings-menu-controls/index.js +2 -10
- package/src/components/block-styles/index.js +4 -1
- package/src/components/block-switcher/test/index.js +43 -44
- package/src/components/block-switcher/utils.js +1 -1
- package/src/components/block-tools/selected-block-popover.js +77 -80
- package/src/components/block-tools/style.scss +0 -1
- package/src/components/block-tools/use-block-toolbar-popover-props.js +68 -12
- package/src/components/block-variation-picker/{style.scss → content.scss} +0 -0
- package/src/components/block-vertical-alignment-control/icons.js +12 -0
- package/src/components/block-vertical-alignment-control/test/index.js +3 -11
- package/src/components/block-vertical-alignment-control/ui.js +16 -6
- package/src/components/button-block-appender/{style.scss → content.scss} +0 -0
- package/src/components/color-style-selector/index.js +1 -1
- package/src/components/colors/test/with-colors.js +2 -8
- package/src/components/date-format-picker/index.js +23 -24
- package/src/components/date-format-picker/style.scss +0 -6
- package/src/components/default-block-appender/content.scss +18 -0
- package/src/components/default-block-appender/test/index.js +2 -8
- package/src/components/default-style-picker/index.js +1 -0
- package/src/components/font-family/index.js +1 -6
- package/src/components/font-sizes/fluid-utils.js +1 -1
- package/src/components/font-sizes/utils.js +1 -1
- package/src/components/font-sizes/with-font-sizes.js +33 -33
- package/src/components/global-styles/README.md +77 -0
- package/src/components/global-styles/context.js +15 -0
- package/src/components/global-styles/hooks.js +145 -0
- package/src/components/global-styles/index.js +7 -0
- package/src/components/global-styles/test/typography-utils.js +393 -0
- package/src/components/global-styles/test/use-global-styles-output.js +814 -0
- package/src/components/global-styles/test/utils.js +206 -0
- package/src/components/global-styles/typography-utils.js +87 -0
- package/src/components/global-styles/use-global-styles-output.js +1088 -0
- package/src/components/global-styles/utils.js +373 -0
- package/src/components/height-control/README.md +55 -0
- package/src/components/height-control/index.js +13 -1
- package/src/components/iframe/index.js +52 -19
- package/src/components/iframe/use-compatibility-styles.js +6 -0
- package/src/components/image-editor/constants.js +1 -1
- package/src/components/image-editor/context.js +5 -9
- package/src/components/image-editor/cropper.js +3 -1
- package/src/components/image-editor/index.js +13 -4
- package/src/components/image-editor/use-transform-image.js +14 -55
- package/src/components/image-size-control/index.js +2 -6
- package/src/components/index.js +2 -6
- package/src/components/inner-blocks/index.js +29 -33
- package/src/components/inner-blocks/index.native.js +27 -47
- package/src/components/inner-blocks/use-block-context.js +47 -0
- package/src/components/inserter/block-patterns-explorer/explorer.js +0 -1
- package/src/components/inserter/block-patterns-tab.js +14 -4
- package/src/components/inserter/block-types-tab.js +3 -4
- package/src/components/inserter/hooks/use-patterns-state.js +1 -6
- package/src/components/inserter/index.js +46 -42
- package/src/components/inserter/media-tab/hooks.js +167 -65
- package/src/components/inserter/media-tab/media-list.js +94 -26
- package/src/components/inserter/media-tab/media-panel.js +9 -20
- package/src/components/inserter/media-tab/media-tab.js +12 -4
- package/src/components/inserter/media-tab/utils.js +20 -10
- package/src/components/inserter/menu.js +9 -4
- package/src/components/inserter/preview-panel.js +4 -2
- package/src/components/inserter/search-results.js +2 -6
- package/src/components/inserter/stories/index.js +9 -9
- package/src/components/inserter/style.scss +58 -11
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +117 -0
- package/src/components/inserter/test/index.native.js +255 -1
- package/src/components/inserter-list-item/index.js +0 -7
- package/src/components/inspector-controls/README.md +3 -7
- package/src/components/inspector-controls/fill.js +15 -1
- package/src/components/inspector-controls/fill.native.js +14 -1
- package/src/components/inspector-controls/groups.js +5 -0
- package/src/components/inspector-controls/index.js +2 -6
- package/src/components/inspector-controls/slot.js +14 -1
- package/src/components/inspector-controls/slot.native.js +14 -1
- package/src/components/inspector-controls-tabs/advanced-controls-panel.js +1 -1
- package/src/components/inspector-controls-tabs/index.js +2 -4
- package/src/components/inspector-controls-tabs/position-controls-panel.js +37 -0
- package/src/components/inspector-controls-tabs/settings-tab.js +2 -0
- package/src/components/inspector-controls-tabs/style.scss +15 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +5 -7
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +24 -18
- package/src/components/justify-content-control/ui.js +9 -0
- package/src/components/link-control/index.js +59 -23
- package/src/components/link-control/search-input.js +1 -0
- package/src/components/link-control/style.scss +8 -24
- package/src/components/link-control/test/index.js +134 -5
- package/src/components/list-view/block.js +1 -1
- package/src/components/list-view/style.scss +13 -3
- package/src/components/list-view/use-list-view-drop-zone.js +1 -1
- package/src/components/media-replace-flow/test/index.js +4 -12
- package/src/components/media-upload/index.native.js +2 -2
- package/src/components/off-canvas-editor/README.md +2 -2
- package/src/components/off-canvas-editor/appender.js +82 -76
- package/src/components/off-canvas-editor/block-contents.js +84 -23
- package/src/components/off-canvas-editor/block-select-button.js +12 -1
- package/src/components/off-canvas-editor/block.js +31 -102
- package/src/components/off-canvas-editor/branch.js +32 -5
- package/src/components/off-canvas-editor/index.js +19 -24
- package/src/components/off-canvas-editor/link-ui.js +2 -2
- package/src/components/off-canvas-editor/style.scss +5 -1
- package/src/components/off-canvas-editor/use-list-view-drop-zone.js +1 -1
- package/src/components/provider/index.js +33 -11
- package/src/components/provider/index.native.js +4 -3
- package/src/components/provider/test/experimental-provider.js +94 -0
- package/src/components/provider/test/use-block-sync.js +10 -0
- package/src/components/responsive-block-control/test/index.js +1 -5
- package/src/components/rich-text/use-before-input-rules.js +10 -2
- package/src/components/rich-text/use-enter.js +4 -4
- package/src/components/rich-text/utils.js +1 -1
- package/src/components/spacing-sizes-control/utils.js +2 -7
- package/src/components/tool-selector/index.js +1 -1
- package/src/components/url-input/README.md +5 -0
- package/src/components/url-input/button.js +1 -0
- package/src/components/url-input/index.js +15 -1
- package/src/components/url-input/test/button.js +24 -24
- package/src/components/url-popover/image-url-input-ui.js +7 -8
- package/src/components/url-popover/link-editor.js +1 -0
- package/src/components/url-popover/style.scss +0 -10
- package/src/components/use-block-display-information/index.js +1 -1
- package/src/components/use-paste-styles/index.js +230 -0
- package/src/components/warning/{style.scss → content.scss} +0 -0
- package/src/components/warning/test/index.js +1 -5
- package/src/components/writing-flow/use-arrow-nav.js +20 -28
- package/src/content.scss +8 -0
- package/src/experiments.js +27 -0
- package/src/experiments.native.js +25 -0
- package/src/hooks/anchor.js +2 -1
- package/src/hooks/border.js +1 -1
- package/src/hooks/child-layout.js +6 -1
- package/src/hooks/color-panel.js +1 -1
- package/src/hooks/color.js +3 -3
- package/src/hooks/custom-class-name.js +2 -1
- package/src/hooks/dimensions.js +6 -6
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.scss +4 -0
- package/src/hooks/margin.js +1 -0
- package/src/hooks/metadata.js +1 -2
- package/src/hooks/padding.js +1 -0
- package/src/hooks/position.js +391 -0
- package/src/hooks/position.scss +18 -0
- package/src/hooks/supports.js +302 -0
- package/src/hooks/test/__snapshots__/align.native.js.snap +73 -0
- package/src/hooks/test/align.native.js +133 -0
- package/src/hooks/test/utils.js +104 -0
- package/src/hooks/typography.js +1 -1
- package/src/hooks/use-color-props.js +3 -3
- package/src/hooks/utils.js +68 -2
- package/src/index.js +1 -0
- package/src/layouts/constrained.js +3 -0
- package/src/layouts/flex.js +66 -14
- package/src/layouts/flow.js +0 -9
- package/src/store/actions.js +2 -26
- package/src/store/defaults.js +7 -2
- package/src/store/index.js +8 -2
- package/src/store/private-actions.js +65 -0
- package/src/store/private-selectors.js +10 -0
- package/src/store/reducer.js +8 -3
- package/src/store/selectors.js +108 -57
- package/src/store/test/actions.js +0 -18
- package/src/store/test/private-actions.js +22 -0
- package/src/store/test/private-selectors.js +24 -0
- package/src/store/test/reducer.js +45 -3
- package/src/store/test/selectors.js +64 -39
- package/src/style.scss +5 -6
- package/src/utils/block-variation-transforms.js +1 -1
- package/src/utils/parse-css-unit-to-px.js +3 -1
- package/src/utils/test/parse-css-unit-to-px.js +16 -24
- package/src/utils/transform-styles/index.js +1 -6
- package/build/components/inner-blocks/get-block-context.js +0 -45
- package/build/components/inner-blocks/get-block-context.js.map +0 -1
- package/build/components/off-canvas-editor/block-edit-button.js +0 -50
- package/build/components/off-canvas-editor/block-edit-button.js.map +0 -1
- package/build-module/components/inner-blocks/get-block-context.js +0 -37
- package/build-module/components/inner-blocks/get-block-context.js.map +0 -1
- package/build-module/components/off-canvas-editor/block-edit-button.js +0 -35
- package/build-module/components/off-canvas-editor/block-edit-button.js.map +0 -1
- package/src/components/inner-blocks/get-block-context.js +0 -39
- package/src/components/off-canvas-editor/block-edit-button.js +0 -27
|
@@ -0,0 +1,1088 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { get, isEmpty, kebabCase, set } from 'lodash';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
__EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,
|
|
11
|
+
__EXPERIMENTAL_ELEMENTS as ELEMENTS,
|
|
12
|
+
getBlockTypes,
|
|
13
|
+
store as blocksStore,
|
|
14
|
+
} from '@wordpress/blocks';
|
|
15
|
+
import { useSelect } from '@wordpress/data';
|
|
16
|
+
import { useContext, useMemo } from '@wordpress/element';
|
|
17
|
+
import { getCSSRules } from '@wordpress/style-engine';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
|
|
23
|
+
import { getTypographyFontSizeValue } from './typography-utils';
|
|
24
|
+
import { GlobalStylesContext } from './context';
|
|
25
|
+
import { useGlobalSetting } from './hooks';
|
|
26
|
+
import { PresetDuotoneFilter } from '../duotone/components';
|
|
27
|
+
import { getGapCSSValue } from '../../hooks/gap';
|
|
28
|
+
import { store as blockEditorStore } from '../../store';
|
|
29
|
+
|
|
30
|
+
// List of block support features that can have their related styles
|
|
31
|
+
// generated under their own feature level selector rather than the block's.
|
|
32
|
+
const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
|
33
|
+
__experimentalBorder: 'border',
|
|
34
|
+
color: 'color',
|
|
35
|
+
spacing: 'spacing',
|
|
36
|
+
typography: 'typography',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function compileStyleValue( uncompiledValue ) {
|
|
40
|
+
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
41
|
+
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
42
|
+
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
|
|
43
|
+
|
|
44
|
+
if ( uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX ) ) {
|
|
45
|
+
const variable = uncompiledValue
|
|
46
|
+
.slice( VARIABLE_REFERENCE_PREFIX.length )
|
|
47
|
+
.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
|
|
48
|
+
.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );
|
|
49
|
+
return `var(--wp--${ variable })`;
|
|
50
|
+
}
|
|
51
|
+
return uncompiledValue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Transform given preset tree into a set of style declarations.
|
|
56
|
+
*
|
|
57
|
+
* @param {Object} blockPresets
|
|
58
|
+
* @param {Object} mergedSettings Merged theme.json settings.
|
|
59
|
+
*
|
|
60
|
+
* @return {Array<Object>} An array of style declarations.
|
|
61
|
+
*/
|
|
62
|
+
function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
|
|
63
|
+
return PRESET_METADATA.reduce(
|
|
64
|
+
( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
|
|
65
|
+
const presetByOrigin = get( blockPresets, path, [] );
|
|
66
|
+
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
|
|
67
|
+
if ( presetByOrigin[ origin ] ) {
|
|
68
|
+
presetByOrigin[ origin ].forEach( ( value ) => {
|
|
69
|
+
if ( valueKey && ! valueFunc ) {
|
|
70
|
+
declarations.push(
|
|
71
|
+
`--wp--preset--${ cssVarInfix }--${ kebabCase(
|
|
72
|
+
value.slug
|
|
73
|
+
) }: ${ value[ valueKey ] }`
|
|
74
|
+
);
|
|
75
|
+
} else if (
|
|
76
|
+
valueFunc &&
|
|
77
|
+
typeof valueFunc === 'function'
|
|
78
|
+
) {
|
|
79
|
+
declarations.push(
|
|
80
|
+
`--wp--preset--${ cssVarInfix }--${ kebabCase(
|
|
81
|
+
value.slug
|
|
82
|
+
) }: ${ valueFunc( value, mergedSettings ) }`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
} );
|
|
86
|
+
}
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
return declarations;
|
|
90
|
+
},
|
|
91
|
+
[]
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Transform given preset tree into a set of preset class declarations.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} blockSelector
|
|
99
|
+
* @param {Object} blockPresets
|
|
100
|
+
* @return {string} CSS declarations for the preset classes.
|
|
101
|
+
*/
|
|
102
|
+
function getPresetsClasses( blockSelector, blockPresets = {} ) {
|
|
103
|
+
return PRESET_METADATA.reduce(
|
|
104
|
+
( declarations, { path, cssVarInfix, classes } ) => {
|
|
105
|
+
if ( ! classes ) {
|
|
106
|
+
return declarations;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const presetByOrigin = get( blockPresets, path, [] );
|
|
110
|
+
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
|
|
111
|
+
if ( presetByOrigin[ origin ] ) {
|
|
112
|
+
presetByOrigin[ origin ].forEach( ( { slug } ) => {
|
|
113
|
+
classes.forEach( ( { classSuffix, propertyName } ) => {
|
|
114
|
+
const classSelectorToUse = `.has-${ kebabCase(
|
|
115
|
+
slug
|
|
116
|
+
) }-${ classSuffix }`;
|
|
117
|
+
const selectorToUse = blockSelector
|
|
118
|
+
.split( ',' ) // Selector can be "h1, h2, h3"
|
|
119
|
+
.map(
|
|
120
|
+
( selector ) =>
|
|
121
|
+
`${ selector }${ classSelectorToUse }`
|
|
122
|
+
)
|
|
123
|
+
.join( ',' );
|
|
124
|
+
const value = `var(--wp--preset--${ cssVarInfix }--${ kebabCase(
|
|
125
|
+
slug
|
|
126
|
+
) })`;
|
|
127
|
+
declarations += `${ selectorToUse }{${ propertyName }: ${ value } !important;}`;
|
|
128
|
+
} );
|
|
129
|
+
} );
|
|
130
|
+
}
|
|
131
|
+
} );
|
|
132
|
+
return declarations;
|
|
133
|
+
},
|
|
134
|
+
''
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getPresetsSvgFilters( blockPresets = {} ) {
|
|
139
|
+
return PRESET_METADATA.filter(
|
|
140
|
+
// Duotone are the only type of filters for now.
|
|
141
|
+
( metadata ) => metadata.path.at( -1 ) === 'duotone'
|
|
142
|
+
).flatMap( ( metadata ) => {
|
|
143
|
+
const presetByOrigin = get( blockPresets, metadata.path, {} );
|
|
144
|
+
return [ 'default', 'theme' ]
|
|
145
|
+
.filter( ( origin ) => presetByOrigin[ origin ] )
|
|
146
|
+
.flatMap( ( origin ) =>
|
|
147
|
+
presetByOrigin[ origin ].map( ( preset ) => (
|
|
148
|
+
<PresetDuotoneFilter
|
|
149
|
+
preset={ preset }
|
|
150
|
+
key={ preset.slug }
|
|
151
|
+
/>
|
|
152
|
+
) )
|
|
153
|
+
);
|
|
154
|
+
} );
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function flattenTree( input = {}, prefix, token ) {
|
|
158
|
+
let result = [];
|
|
159
|
+
Object.keys( input ).forEach( ( key ) => {
|
|
160
|
+
const newKey = prefix + kebabCase( key.replace( '/', '-' ) );
|
|
161
|
+
const newLeaf = input[ key ];
|
|
162
|
+
|
|
163
|
+
if ( newLeaf instanceof Object ) {
|
|
164
|
+
const newPrefix = newKey + token;
|
|
165
|
+
result = [ ...result, ...flattenTree( newLeaf, newPrefix, token ) ];
|
|
166
|
+
} else {
|
|
167
|
+
result.push( `${ newKey }: ${ newLeaf }` );
|
|
168
|
+
}
|
|
169
|
+
} );
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Gets variation selector string from feature selector.
|
|
175
|
+
*
|
|
176
|
+
* @param {string} featureSelector The feature selector.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} styleVariationSelector The style variation selector.
|
|
179
|
+
* @return {string} Combined selector string.
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
function concatFeatureVariationSelectorString(
|
|
183
|
+
featureSelector,
|
|
184
|
+
styleVariationSelector
|
|
185
|
+
) {
|
|
186
|
+
const featureSelectors = featureSelector.split( ',' );
|
|
187
|
+
const combinedSelectors = [];
|
|
188
|
+
featureSelectors.forEach( ( selector ) => {
|
|
189
|
+
combinedSelectors.push(
|
|
190
|
+
`${ styleVariationSelector.trim() }${ selector.trim() }`
|
|
191
|
+
);
|
|
192
|
+
} );
|
|
193
|
+
return combinedSelectors.join( ', ' );
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Transform given style tree into a set of style declarations.
|
|
198
|
+
*
|
|
199
|
+
* @param {Object} blockStyles Block styles.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} selector The selector these declarations should attach to.
|
|
202
|
+
*
|
|
203
|
+
* @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
|
|
204
|
+
*
|
|
205
|
+
* @param {Object} tree A theme.json tree containing layout definitions.
|
|
206
|
+
*
|
|
207
|
+
* @return {Array} An array of style declarations.
|
|
208
|
+
*/
|
|
209
|
+
export function getStylesDeclarations(
|
|
210
|
+
blockStyles = {},
|
|
211
|
+
selector = '',
|
|
212
|
+
useRootPaddingAlign,
|
|
213
|
+
tree = {}
|
|
214
|
+
) {
|
|
215
|
+
const isRoot = ROOT_BLOCK_SELECTOR === selector;
|
|
216
|
+
const output = Object.entries( STYLE_PROPERTY ).reduce(
|
|
217
|
+
(
|
|
218
|
+
declarations,
|
|
219
|
+
[ key, { value, properties, useEngine, rootOnly } ]
|
|
220
|
+
) => {
|
|
221
|
+
if ( rootOnly && ! isRoot ) {
|
|
222
|
+
return declarations;
|
|
223
|
+
}
|
|
224
|
+
const pathToValue = value;
|
|
225
|
+
if ( pathToValue[ 0 ] === 'elements' || useEngine ) {
|
|
226
|
+
return declarations;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const styleValue = get( blockStyles, pathToValue );
|
|
230
|
+
|
|
231
|
+
// Root-level padding styles don't currently support strings with CSS shorthand values.
|
|
232
|
+
// This may change: https://github.com/WordPress/gutenberg/issues/40132.
|
|
233
|
+
if (
|
|
234
|
+
key === '--wp--style--root--padding' &&
|
|
235
|
+
( typeof styleValue === 'string' || ! useRootPaddingAlign )
|
|
236
|
+
) {
|
|
237
|
+
return declarations;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if ( !! properties && typeof styleValue !== 'string' ) {
|
|
241
|
+
Object.entries( properties ).forEach( ( entry ) => {
|
|
242
|
+
const [ name, prop ] = entry;
|
|
243
|
+
|
|
244
|
+
if ( ! get( styleValue, [ prop ], false ) ) {
|
|
245
|
+
// Do not create a declaration
|
|
246
|
+
// for sub-properties that don't have any value.
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const cssProperty = name.startsWith( '--' )
|
|
251
|
+
? name
|
|
252
|
+
: kebabCase( name );
|
|
253
|
+
declarations.push(
|
|
254
|
+
`${ cssProperty }: ${ compileStyleValue(
|
|
255
|
+
get( styleValue, [ prop ] )
|
|
256
|
+
) }`
|
|
257
|
+
);
|
|
258
|
+
} );
|
|
259
|
+
} else if ( get( blockStyles, pathToValue, false ) ) {
|
|
260
|
+
const cssProperty = key.startsWith( '--' )
|
|
261
|
+
? key
|
|
262
|
+
: kebabCase( key );
|
|
263
|
+
declarations.push(
|
|
264
|
+
`${ cssProperty }: ${ compileStyleValue(
|
|
265
|
+
get( blockStyles, pathToValue )
|
|
266
|
+
) }`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return declarations;
|
|
271
|
+
},
|
|
272
|
+
[]
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
// The goal is to move everything to server side generated engine styles
|
|
276
|
+
// This is temporary as we absorb more and more styles into the engine.
|
|
277
|
+
const extraRules = getCSSRules( blockStyles );
|
|
278
|
+
extraRules.forEach( ( rule ) => {
|
|
279
|
+
// Don't output padding properties if padding variables are set.
|
|
280
|
+
if (
|
|
281
|
+
isRoot &&
|
|
282
|
+
useRootPaddingAlign &&
|
|
283
|
+
rule.key.startsWith( 'padding' )
|
|
284
|
+
) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const cssProperty = rule.key.startsWith( '--' )
|
|
288
|
+
? rule.key
|
|
289
|
+
: kebabCase( rule.key );
|
|
290
|
+
|
|
291
|
+
let ruleValue = rule.value;
|
|
292
|
+
if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
|
|
293
|
+
const refPath = ruleValue.ref.split( '.' );
|
|
294
|
+
ruleValue = get( tree, refPath );
|
|
295
|
+
// Presence of another ref indicates a reference to another dynamic value.
|
|
296
|
+
// Pointing to another dynamic value is not supported.
|
|
297
|
+
if ( ! ruleValue || !! ruleValue?.ref ) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Calculate fluid typography rules where available.
|
|
303
|
+
if ( cssProperty === 'font-size' ) {
|
|
304
|
+
/*
|
|
305
|
+
* getTypographyFontSizeValue() will check
|
|
306
|
+
* if fluid typography has been activated and also
|
|
307
|
+
* whether the incoming value can be converted to a fluid value.
|
|
308
|
+
* Values that already have a "clamp()" function will not pass the test,
|
|
309
|
+
* and therefore the original $value will be returned.
|
|
310
|
+
*/
|
|
311
|
+
ruleValue = getTypographyFontSizeValue(
|
|
312
|
+
{ size: ruleValue },
|
|
313
|
+
tree?.settings?.typography
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
output.push( `${ cssProperty }: ${ ruleValue }` );
|
|
318
|
+
} );
|
|
319
|
+
|
|
320
|
+
return output;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Get generated CSS for layout styles by looking up layout definitions provided
|
|
325
|
+
* in theme.json, and outputting common layout styles, and specific blockGap values.
|
|
326
|
+
*
|
|
327
|
+
* @param {Object} props
|
|
328
|
+
* @param {Object} props.tree A theme.json tree containing layout definitions.
|
|
329
|
+
* @param {Object} props.style A style object containing spacing values.
|
|
330
|
+
* @param {string} props.selector Selector used to group together layout styling rules.
|
|
331
|
+
* @param {boolean} props.hasBlockGapSupport Whether or not the theme opts-in to blockGap support.
|
|
332
|
+
* @param {boolean} props.hasFallbackGapSupport Whether or not the theme allows fallback gap styles.
|
|
333
|
+
* @param {?string} props.fallbackGapValue An optional fallback gap value if no real gap value is available.
|
|
334
|
+
* @return {string} Generated CSS rules for the layout styles.
|
|
335
|
+
*/
|
|
336
|
+
export function getLayoutStyles( {
|
|
337
|
+
tree,
|
|
338
|
+
style,
|
|
339
|
+
selector,
|
|
340
|
+
hasBlockGapSupport,
|
|
341
|
+
hasFallbackGapSupport,
|
|
342
|
+
fallbackGapValue,
|
|
343
|
+
} ) {
|
|
344
|
+
let ruleset = '';
|
|
345
|
+
let gapValue = hasBlockGapSupport
|
|
346
|
+
? getGapCSSValue( style?.spacing?.blockGap )
|
|
347
|
+
: '';
|
|
348
|
+
|
|
349
|
+
// Ensure a fallback gap value for the root layout definitions,
|
|
350
|
+
// and use a fallback value if one is provided for the current block.
|
|
351
|
+
if ( hasFallbackGapSupport ) {
|
|
352
|
+
if ( selector === ROOT_BLOCK_SELECTOR ) {
|
|
353
|
+
gapValue = ! gapValue ? '0.5em' : gapValue;
|
|
354
|
+
} else if ( ! hasBlockGapSupport && fallbackGapValue ) {
|
|
355
|
+
gapValue = fallbackGapValue;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if ( gapValue && tree?.settings?.layout?.definitions ) {
|
|
360
|
+
Object.values( tree.settings.layout.definitions ).forEach(
|
|
361
|
+
( { className, name, spacingStyles } ) => {
|
|
362
|
+
// Allow outputting fallback gap styles for flex layout type when block gap support isn't available.
|
|
363
|
+
if ( ! hasBlockGapSupport && 'flex' !== name ) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if ( spacingStyles?.length ) {
|
|
368
|
+
spacingStyles.forEach( ( spacingStyle ) => {
|
|
369
|
+
const declarations = [];
|
|
370
|
+
|
|
371
|
+
if ( spacingStyle.rules ) {
|
|
372
|
+
Object.entries( spacingStyle.rules ).forEach(
|
|
373
|
+
( [ cssProperty, cssValue ] ) => {
|
|
374
|
+
declarations.push(
|
|
375
|
+
`${ cssProperty }: ${
|
|
376
|
+
cssValue ? cssValue : gapValue
|
|
377
|
+
}`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if ( declarations.length ) {
|
|
384
|
+
let combinedSelector = '';
|
|
385
|
+
|
|
386
|
+
if ( ! hasBlockGapSupport ) {
|
|
387
|
+
// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
|
|
388
|
+
combinedSelector =
|
|
389
|
+
selector === ROOT_BLOCK_SELECTOR
|
|
390
|
+
? `:where(.${ className }${
|
|
391
|
+
spacingStyle?.selector || ''
|
|
392
|
+
})`
|
|
393
|
+
: `:where(${ selector }.${ className }${
|
|
394
|
+
spacingStyle?.selector || ''
|
|
395
|
+
})`;
|
|
396
|
+
} else {
|
|
397
|
+
combinedSelector =
|
|
398
|
+
selector === ROOT_BLOCK_SELECTOR
|
|
399
|
+
? `${ selector } .${ className }${
|
|
400
|
+
spacingStyle?.selector || ''
|
|
401
|
+
}`
|
|
402
|
+
: `${ selector }.${ className }${
|
|
403
|
+
spacingStyle?.selector || ''
|
|
404
|
+
}`;
|
|
405
|
+
}
|
|
406
|
+
ruleset += `${ combinedSelector } { ${ declarations.join(
|
|
407
|
+
'; '
|
|
408
|
+
) }; }`;
|
|
409
|
+
}
|
|
410
|
+
} );
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
// For backwards compatibility, ensure the legacy block gap CSS variable is still available.
|
|
415
|
+
if ( selector === ROOT_BLOCK_SELECTOR && hasBlockGapSupport ) {
|
|
416
|
+
ruleset += `${ selector } { --wp--style--block-gap: ${ gapValue }; }`;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Output base styles
|
|
421
|
+
if (
|
|
422
|
+
selector === ROOT_BLOCK_SELECTOR &&
|
|
423
|
+
tree?.settings?.layout?.definitions
|
|
424
|
+
) {
|
|
425
|
+
const validDisplayModes = [ 'block', 'flex', 'grid' ];
|
|
426
|
+
Object.values( tree.settings.layout.definitions ).forEach(
|
|
427
|
+
( { className, displayMode, baseStyles } ) => {
|
|
428
|
+
if (
|
|
429
|
+
displayMode &&
|
|
430
|
+
validDisplayModes.includes( displayMode )
|
|
431
|
+
) {
|
|
432
|
+
ruleset += `${ selector } .${ className } { display:${ displayMode }; }`;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if ( baseStyles?.length ) {
|
|
436
|
+
baseStyles.forEach( ( baseStyle ) => {
|
|
437
|
+
const declarations = [];
|
|
438
|
+
|
|
439
|
+
if ( baseStyle.rules ) {
|
|
440
|
+
Object.entries( baseStyle.rules ).forEach(
|
|
441
|
+
( [ cssProperty, cssValue ] ) => {
|
|
442
|
+
declarations.push(
|
|
443
|
+
`${ cssProperty }: ${ cssValue }`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if ( declarations.length ) {
|
|
450
|
+
const combinedSelector = `${ selector } .${ className }${
|
|
451
|
+
baseStyle?.selector || ''
|
|
452
|
+
}`;
|
|
453
|
+
ruleset += `${ combinedSelector } { ${ declarations.join(
|
|
454
|
+
'; '
|
|
455
|
+
) }; }`;
|
|
456
|
+
}
|
|
457
|
+
} );
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return ruleset;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
467
|
+
const nodes = [];
|
|
468
|
+
|
|
469
|
+
if ( ! tree?.styles ) {
|
|
470
|
+
return nodes;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const pickStyleKeys = ( treeToPickFrom ) =>
|
|
474
|
+
Object.fromEntries(
|
|
475
|
+
Object.entries( treeToPickFrom ?? {} ).filter( ( [ key ] ) =>
|
|
476
|
+
[
|
|
477
|
+
'border',
|
|
478
|
+
'color',
|
|
479
|
+
'dimensions',
|
|
480
|
+
'spacing',
|
|
481
|
+
'typography',
|
|
482
|
+
'filter',
|
|
483
|
+
'outline',
|
|
484
|
+
'shadow',
|
|
485
|
+
].includes( key )
|
|
486
|
+
)
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
// Top-level.
|
|
490
|
+
const styles = pickStyleKeys( tree.styles );
|
|
491
|
+
if ( !! styles ) {
|
|
492
|
+
nodes.push( {
|
|
493
|
+
styles,
|
|
494
|
+
selector: ROOT_BLOCK_SELECTOR,
|
|
495
|
+
} );
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
Object.entries( ELEMENTS ).forEach( ( [ name, selector ] ) => {
|
|
499
|
+
if ( !! tree.styles?.elements[ name ] ) {
|
|
500
|
+
nodes.push( {
|
|
501
|
+
styles: tree.styles?.elements[ name ],
|
|
502
|
+
selector,
|
|
503
|
+
} );
|
|
504
|
+
}
|
|
505
|
+
} );
|
|
506
|
+
|
|
507
|
+
// Iterate over blocks: they can have styles & elements.
|
|
508
|
+
Object.entries( tree.styles?.blocks ?? {} ).forEach(
|
|
509
|
+
( [ blockName, node ] ) => {
|
|
510
|
+
const blockStyles = pickStyleKeys( node );
|
|
511
|
+
|
|
512
|
+
if ( node?.variations ) {
|
|
513
|
+
const variations = {};
|
|
514
|
+
Object.keys( node.variations ).forEach( ( variation ) => {
|
|
515
|
+
variations[ variation ] = pickStyleKeys(
|
|
516
|
+
node.variations[ variation ]
|
|
517
|
+
);
|
|
518
|
+
} );
|
|
519
|
+
blockStyles.variations = variations;
|
|
520
|
+
}
|
|
521
|
+
if (
|
|
522
|
+
!! blockStyles &&
|
|
523
|
+
!! blockSelectors?.[ blockName ]?.selector
|
|
524
|
+
) {
|
|
525
|
+
nodes.push( {
|
|
526
|
+
duotoneSelector:
|
|
527
|
+
blockSelectors[ blockName ].duotoneSelector,
|
|
528
|
+
fallbackGapValue:
|
|
529
|
+
blockSelectors[ blockName ].fallbackGapValue,
|
|
530
|
+
hasLayoutSupport:
|
|
531
|
+
blockSelectors[ blockName ].hasLayoutSupport,
|
|
532
|
+
selector: blockSelectors[ blockName ].selector,
|
|
533
|
+
styles: blockStyles,
|
|
534
|
+
featureSelectors:
|
|
535
|
+
blockSelectors[ blockName ].featureSelectors,
|
|
536
|
+
styleVariationSelectors:
|
|
537
|
+
blockSelectors[ blockName ].styleVariationSelectors,
|
|
538
|
+
} );
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
Object.entries( node?.elements ?? {} ).forEach(
|
|
542
|
+
( [ elementName, value ] ) => {
|
|
543
|
+
if (
|
|
544
|
+
!! value &&
|
|
545
|
+
!! blockSelectors?.[ blockName ] &&
|
|
546
|
+
!! ELEMENTS?.[ elementName ]
|
|
547
|
+
) {
|
|
548
|
+
nodes.push( {
|
|
549
|
+
styles: value,
|
|
550
|
+
selector: blockSelectors[ blockName ].selector
|
|
551
|
+
.split( ',' )
|
|
552
|
+
.map( ( sel ) => {
|
|
553
|
+
const elementSelectors =
|
|
554
|
+
ELEMENTS[ elementName ].split( ',' );
|
|
555
|
+
return elementSelectors.map(
|
|
556
|
+
( elementSelector ) =>
|
|
557
|
+
sel + ' ' + elementSelector
|
|
558
|
+
);
|
|
559
|
+
} )
|
|
560
|
+
.join( ',' ),
|
|
561
|
+
} );
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
return nodes;
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
export const getNodesWithSettings = ( tree, blockSelectors ) => {
|
|
572
|
+
const nodes = [];
|
|
573
|
+
|
|
574
|
+
if ( ! tree?.settings ) {
|
|
575
|
+
return nodes;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const pickPresets = ( treeToPickFrom ) => {
|
|
579
|
+
const presets = {};
|
|
580
|
+
PRESET_METADATA.forEach( ( { path } ) => {
|
|
581
|
+
const value = get( treeToPickFrom, path, false );
|
|
582
|
+
if ( value !== false ) {
|
|
583
|
+
set( presets, path, value );
|
|
584
|
+
}
|
|
585
|
+
} );
|
|
586
|
+
return presets;
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// Top-level.
|
|
590
|
+
const presets = pickPresets( tree.settings );
|
|
591
|
+
const custom = tree.settings?.custom;
|
|
592
|
+
if ( ! isEmpty( presets ) || !! custom ) {
|
|
593
|
+
nodes.push( {
|
|
594
|
+
presets,
|
|
595
|
+
custom,
|
|
596
|
+
selector: ROOT_BLOCK_SELECTOR,
|
|
597
|
+
} );
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Blocks.
|
|
601
|
+
Object.entries( tree.settings?.blocks ?? {} ).forEach(
|
|
602
|
+
( [ blockName, node ] ) => {
|
|
603
|
+
const blockPresets = pickPresets( node );
|
|
604
|
+
const blockCustom = node.custom;
|
|
605
|
+
if ( ! isEmpty( blockPresets ) || !! blockCustom ) {
|
|
606
|
+
nodes.push( {
|
|
607
|
+
presets: blockPresets,
|
|
608
|
+
custom: blockCustom,
|
|
609
|
+
selector: blockSelectors[ blockName ].selector,
|
|
610
|
+
} );
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
return nodes;
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
export const toCustomProperties = ( tree, blockSelectors ) => {
|
|
619
|
+
const settings = getNodesWithSettings( tree, blockSelectors );
|
|
620
|
+
let ruleset = '';
|
|
621
|
+
settings.forEach( ( { presets, custom, selector } ) => {
|
|
622
|
+
const declarations = getPresetsDeclarations( presets, tree?.settings );
|
|
623
|
+
const customProps = flattenTree( custom, '--wp--custom--', '--' );
|
|
624
|
+
if ( customProps.length > 0 ) {
|
|
625
|
+
declarations.push( ...customProps );
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if ( declarations.length > 0 ) {
|
|
629
|
+
ruleset = ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
|
|
630
|
+
}
|
|
631
|
+
} );
|
|
632
|
+
|
|
633
|
+
return ruleset;
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
export const toStyles = (
|
|
637
|
+
tree,
|
|
638
|
+
blockSelectors,
|
|
639
|
+
hasBlockGapSupport,
|
|
640
|
+
hasFallbackGapSupport,
|
|
641
|
+
disableLayoutStyles = false
|
|
642
|
+
) => {
|
|
643
|
+
const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
|
|
644
|
+
const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
|
|
645
|
+
const useRootPaddingAlign = tree?.settings?.useRootPaddingAwareAlignments;
|
|
646
|
+
const { contentSize, wideSize } = tree?.settings?.layout || {};
|
|
647
|
+
|
|
648
|
+
/*
|
|
649
|
+
* Reset default browser margin on the root body element.
|
|
650
|
+
* This is set on the root selector **before** generating the ruleset
|
|
651
|
+
* from the `theme.json`. This is to ensure that if the `theme.json` declares
|
|
652
|
+
* `margin` in its `spacing` declaration for the `body` element then these
|
|
653
|
+
* user-generated values take precedence in the CSS cascade.
|
|
654
|
+
* @link https://github.com/WordPress/gutenberg/issues/36147.
|
|
655
|
+
*/
|
|
656
|
+
let ruleset = 'body {margin: 0;';
|
|
657
|
+
|
|
658
|
+
if ( contentSize ) {
|
|
659
|
+
ruleset += ` --wp--style--global--content-size: ${ contentSize };`;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if ( wideSize ) {
|
|
663
|
+
ruleset += ` --wp--style--global--wide-size: ${ wideSize };`;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if ( useRootPaddingAlign ) {
|
|
667
|
+
ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
|
|
668
|
+
.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
|
|
669
|
+
.has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }
|
|
670
|
+
.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
|
|
671
|
+
.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }
|
|
672
|
+
.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
|
|
673
|
+
.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0;`;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
ruleset += '}';
|
|
677
|
+
|
|
678
|
+
nodesWithStyles.forEach(
|
|
679
|
+
( {
|
|
680
|
+
selector,
|
|
681
|
+
duotoneSelector,
|
|
682
|
+
styles,
|
|
683
|
+
fallbackGapValue,
|
|
684
|
+
hasLayoutSupport,
|
|
685
|
+
featureSelectors,
|
|
686
|
+
styleVariationSelectors,
|
|
687
|
+
} ) => {
|
|
688
|
+
// Process styles for block support features with custom feature level
|
|
689
|
+
// CSS selectors set.
|
|
690
|
+
if ( featureSelectors ) {
|
|
691
|
+
Object.entries( featureSelectors ).forEach(
|
|
692
|
+
( [ featureName, featureSelector ] ) => {
|
|
693
|
+
if ( styles?.[ featureName ] ) {
|
|
694
|
+
const featureStyles = {
|
|
695
|
+
[ featureName ]: styles[ featureName ],
|
|
696
|
+
};
|
|
697
|
+
const featureDeclarations =
|
|
698
|
+
getStylesDeclarations( featureStyles );
|
|
699
|
+
delete styles[ featureName ];
|
|
700
|
+
|
|
701
|
+
if ( !! featureDeclarations.length ) {
|
|
702
|
+
ruleset =
|
|
703
|
+
ruleset +
|
|
704
|
+
`${ featureSelector }{${ featureDeclarations.join(
|
|
705
|
+
';'
|
|
706
|
+
) } }`;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
if ( styleVariationSelectors ) {
|
|
714
|
+
Object.entries( styleVariationSelectors ).forEach(
|
|
715
|
+
( [ styleVariationName, styleVariationSelector ] ) => {
|
|
716
|
+
if ( styles?.variations?.[ styleVariationName ] ) {
|
|
717
|
+
// If the block uses any custom selectors for block support, add those first.
|
|
718
|
+
if ( featureSelectors ) {
|
|
719
|
+
Object.entries( featureSelectors ).forEach(
|
|
720
|
+
( [ featureName, featureSelector ] ) => {
|
|
721
|
+
if (
|
|
722
|
+
styles?.variations?.[
|
|
723
|
+
styleVariationName
|
|
724
|
+
]?.[ featureName ]
|
|
725
|
+
) {
|
|
726
|
+
const featureStyles = {
|
|
727
|
+
[ featureName ]:
|
|
728
|
+
styles.variations[
|
|
729
|
+
styleVariationName
|
|
730
|
+
][ featureName ],
|
|
731
|
+
};
|
|
732
|
+
const featureDeclarations =
|
|
733
|
+
getStylesDeclarations(
|
|
734
|
+
featureStyles
|
|
735
|
+
);
|
|
736
|
+
delete styles.variations[
|
|
737
|
+
styleVariationName
|
|
738
|
+
][ featureName ];
|
|
739
|
+
|
|
740
|
+
if (
|
|
741
|
+
!! featureDeclarations.length
|
|
742
|
+
) {
|
|
743
|
+
ruleset =
|
|
744
|
+
ruleset +
|
|
745
|
+
`${ concatFeatureVariationSelectorString(
|
|
746
|
+
featureSelector,
|
|
747
|
+
styleVariationSelector
|
|
748
|
+
) }{${ featureDeclarations.join(
|
|
749
|
+
';'
|
|
750
|
+
) } }`;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
// Otherwise add regular selectors.
|
|
757
|
+
const styleVariationDeclarations =
|
|
758
|
+
getStylesDeclarations(
|
|
759
|
+
styles?.variations?.[ styleVariationName ],
|
|
760
|
+
styleVariationSelector,
|
|
761
|
+
useRootPaddingAlign,
|
|
762
|
+
tree
|
|
763
|
+
);
|
|
764
|
+
if ( !! styleVariationDeclarations.length ) {
|
|
765
|
+
ruleset =
|
|
766
|
+
ruleset +
|
|
767
|
+
`${ styleVariationSelector }{${ styleVariationDeclarations.join(
|
|
768
|
+
';'
|
|
769
|
+
) }}`;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const duotoneStyles = {};
|
|
777
|
+
if ( styles?.filter ) {
|
|
778
|
+
duotoneStyles.filter = styles.filter;
|
|
779
|
+
delete styles.filter;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Process duotone styles (they use color.__experimentalDuotone selector).
|
|
783
|
+
if ( duotoneSelector ) {
|
|
784
|
+
const duotoneDeclarations =
|
|
785
|
+
getStylesDeclarations( duotoneStyles );
|
|
786
|
+
if ( duotoneDeclarations.length > 0 ) {
|
|
787
|
+
ruleset =
|
|
788
|
+
ruleset +
|
|
789
|
+
`${ duotoneSelector }{${ duotoneDeclarations.join(
|
|
790
|
+
';'
|
|
791
|
+
) };}`;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Process blockGap and layout styles.
|
|
796
|
+
if (
|
|
797
|
+
! disableLayoutStyles &&
|
|
798
|
+
( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
|
|
799
|
+
) {
|
|
800
|
+
ruleset += getLayoutStyles( {
|
|
801
|
+
tree,
|
|
802
|
+
style: styles,
|
|
803
|
+
selector,
|
|
804
|
+
hasBlockGapSupport,
|
|
805
|
+
hasFallbackGapSupport,
|
|
806
|
+
fallbackGapValue,
|
|
807
|
+
} );
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// Process the remaining block styles (they use either normal block class or __experimentalSelector).
|
|
811
|
+
const declarations = getStylesDeclarations(
|
|
812
|
+
styles,
|
|
813
|
+
selector,
|
|
814
|
+
useRootPaddingAlign,
|
|
815
|
+
tree
|
|
816
|
+
);
|
|
817
|
+
if ( declarations?.length ) {
|
|
818
|
+
ruleset =
|
|
819
|
+
ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// Check for pseudo selector in `styles` and handle separately.
|
|
823
|
+
const pseudoSelectorStyles = Object.entries( styles ).filter(
|
|
824
|
+
( [ key ] ) => key.startsWith( ':' )
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
if ( pseudoSelectorStyles?.length ) {
|
|
828
|
+
pseudoSelectorStyles.forEach(
|
|
829
|
+
( [ pseudoKey, pseudoStyle ] ) => {
|
|
830
|
+
const pseudoDeclarations =
|
|
831
|
+
getStylesDeclarations( pseudoStyle );
|
|
832
|
+
|
|
833
|
+
if ( ! pseudoDeclarations?.length ) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// `selector` maybe provided in a form
|
|
838
|
+
// where block level selectors have sub element
|
|
839
|
+
// selectors appended to them as a comma separated
|
|
840
|
+
// string.
|
|
841
|
+
// e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
|
|
842
|
+
// Split and append pseudo selector to create
|
|
843
|
+
// the proper rules to target the elements.
|
|
844
|
+
const _selector = selector
|
|
845
|
+
.split( ',' )
|
|
846
|
+
.map( ( sel ) => sel + pseudoKey )
|
|
847
|
+
.join( ',' );
|
|
848
|
+
|
|
849
|
+
const pseudoRule = `${ _selector }{${ pseudoDeclarations.join(
|
|
850
|
+
';'
|
|
851
|
+
) };}`;
|
|
852
|
+
|
|
853
|
+
ruleset = ruleset + pseudoRule;
|
|
854
|
+
}
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
/* Add alignment / layout styles */
|
|
861
|
+
ruleset =
|
|
862
|
+
ruleset +
|
|
863
|
+
'.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
|
|
864
|
+
ruleset =
|
|
865
|
+
ruleset +
|
|
866
|
+
'.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
|
|
867
|
+
ruleset =
|
|
868
|
+
ruleset +
|
|
869
|
+
'.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
|
|
870
|
+
|
|
871
|
+
if ( hasBlockGapSupport ) {
|
|
872
|
+
// Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
|
|
873
|
+
const gapValue =
|
|
874
|
+
getGapCSSValue( tree?.styles?.spacing?.blockGap ) || '0.5em';
|
|
875
|
+
ruleset =
|
|
876
|
+
ruleset +
|
|
877
|
+
'.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
|
|
878
|
+
ruleset =
|
|
879
|
+
ruleset +
|
|
880
|
+
`.wp-site-blocks > * + * { margin-block-start: ${ gapValue }; }`;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
nodesWithSettings.forEach( ( { selector, presets } ) => {
|
|
884
|
+
if ( ROOT_BLOCK_SELECTOR === selector ) {
|
|
885
|
+
// Do not add extra specificity for top-level classes.
|
|
886
|
+
selector = '';
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
const classes = getPresetsClasses( selector, presets );
|
|
890
|
+
if ( ! isEmpty( classes ) ) {
|
|
891
|
+
ruleset = ruleset + classes;
|
|
892
|
+
}
|
|
893
|
+
} );
|
|
894
|
+
|
|
895
|
+
return ruleset;
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
export function toSvgFilters( tree, blockSelectors ) {
|
|
899
|
+
const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
|
|
900
|
+
return nodesWithSettings.flatMap( ( { presets } ) => {
|
|
901
|
+
return getPresetsSvgFilters( presets );
|
|
902
|
+
} );
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
export const getBlockSelectors = ( blockTypes, getBlockStyles ) => {
|
|
906
|
+
const result = {};
|
|
907
|
+
blockTypes.forEach( ( blockType ) => {
|
|
908
|
+
const name = blockType.name;
|
|
909
|
+
const selector =
|
|
910
|
+
blockType?.supports?.__experimentalSelector ??
|
|
911
|
+
'.wp-block-' + name.replace( 'core/', '' ).replace( '/', '-' );
|
|
912
|
+
const duotoneSelector =
|
|
913
|
+
blockType?.supports?.color?.__experimentalDuotone ?? null;
|
|
914
|
+
const hasLayoutSupport = !! blockType?.supports?.__experimentalLayout;
|
|
915
|
+
const fallbackGapValue =
|
|
916
|
+
blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
|
|
917
|
+
|
|
918
|
+
const blockStyleVariations = getBlockStyles( name );
|
|
919
|
+
const styleVariationSelectors = {};
|
|
920
|
+
if ( blockStyleVariations?.length ) {
|
|
921
|
+
blockStyleVariations.forEach( ( variation ) => {
|
|
922
|
+
const styleVariationSelector = `.is-style-${ variation.name }${ selector }`;
|
|
923
|
+
styleVariationSelectors[ variation.name ] =
|
|
924
|
+
styleVariationSelector;
|
|
925
|
+
} );
|
|
926
|
+
}
|
|
927
|
+
// For each block support feature add any custom selectors.
|
|
928
|
+
const featureSelectors = {};
|
|
929
|
+
Object.entries( BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS ).forEach(
|
|
930
|
+
( [ featureKey, featureName ] ) => {
|
|
931
|
+
const featureSelector =
|
|
932
|
+
blockType?.supports?.[ featureKey ]?.__experimentalSelector;
|
|
933
|
+
|
|
934
|
+
if ( featureSelector ) {
|
|
935
|
+
featureSelectors[ featureName ] = scopeSelector(
|
|
936
|
+
selector,
|
|
937
|
+
featureSelector
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
);
|
|
942
|
+
|
|
943
|
+
result[ name ] = {
|
|
944
|
+
duotoneSelector,
|
|
945
|
+
fallbackGapValue,
|
|
946
|
+
featureSelectors: Object.keys( featureSelectors ).length
|
|
947
|
+
? featureSelectors
|
|
948
|
+
: undefined,
|
|
949
|
+
hasLayoutSupport,
|
|
950
|
+
name,
|
|
951
|
+
selector,
|
|
952
|
+
styleVariationSelectors: Object.keys( styleVariationSelectors )
|
|
953
|
+
.length
|
|
954
|
+
? styleVariationSelectors
|
|
955
|
+
: undefined,
|
|
956
|
+
};
|
|
957
|
+
} );
|
|
958
|
+
|
|
959
|
+
return result;
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* If there is a separator block whose color is defined in theme.json via background,
|
|
964
|
+
* update the separator color to the same value by using border color.
|
|
965
|
+
*
|
|
966
|
+
* @param {Object} config Theme.json configuration file object.
|
|
967
|
+
* @return {Object} configTheme.json configuration file object updated.
|
|
968
|
+
*/
|
|
969
|
+
function updateConfigWithSeparator( config ) {
|
|
970
|
+
const needsSeparatorStyleUpdate =
|
|
971
|
+
config.styles?.blocks[ 'core/separator' ] &&
|
|
972
|
+
config.styles?.blocks[ 'core/separator' ].color?.background &&
|
|
973
|
+
! config.styles?.blocks[ 'core/separator' ].color?.text &&
|
|
974
|
+
! config.styles?.blocks[ 'core/separator' ].border?.color;
|
|
975
|
+
if ( needsSeparatorStyleUpdate ) {
|
|
976
|
+
return {
|
|
977
|
+
...config,
|
|
978
|
+
styles: {
|
|
979
|
+
...config.styles,
|
|
980
|
+
blocks: {
|
|
981
|
+
...config.styles.blocks,
|
|
982
|
+
'core/separator': {
|
|
983
|
+
...config.styles.blocks[ 'core/separator' ],
|
|
984
|
+
color: {
|
|
985
|
+
...config.styles.blocks[ 'core/separator' ].color,
|
|
986
|
+
text: config.styles?.blocks[ 'core/separator' ]
|
|
987
|
+
.color.background,
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
},
|
|
991
|
+
},
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
return config;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const processCSSNesting = ( css, blockSelector ) => {
|
|
998
|
+
let processedCSS = '';
|
|
999
|
+
|
|
1000
|
+
// Split CSS nested rules.
|
|
1001
|
+
const parts = css.split( '&' );
|
|
1002
|
+
parts.forEach( ( part ) => {
|
|
1003
|
+
processedCSS += ! part.includes( '{' )
|
|
1004
|
+
? blockSelector + '{' + part + '}' // If the part doesn't contain braces, it applies to the root level.
|
|
1005
|
+
: blockSelector + part; // Prepend the selector, which effectively replaces the "&" character.
|
|
1006
|
+
} );
|
|
1007
|
+
return processedCSS;
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
export function useGlobalStylesOutput() {
|
|
1011
|
+
let { merged: mergedConfig } = useContext( GlobalStylesContext );
|
|
1012
|
+
|
|
1013
|
+
const [ blockGap ] = useGlobalSetting( 'spacing.blockGap' );
|
|
1014
|
+
const hasBlockGapSupport = blockGap !== null;
|
|
1015
|
+
const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
1016
|
+
const disableLayoutStyles = useSelect( ( select ) => {
|
|
1017
|
+
const { getSettings } = select( blockEditorStore );
|
|
1018
|
+
return !! getSettings().disableLayoutStyles;
|
|
1019
|
+
} );
|
|
1020
|
+
|
|
1021
|
+
const getBlockStyles = useSelect( ( select ) => {
|
|
1022
|
+
return select( blocksStore ).getBlockStyles;
|
|
1023
|
+
}, [] );
|
|
1024
|
+
|
|
1025
|
+
return useMemo( () => {
|
|
1026
|
+
if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
|
|
1027
|
+
return [];
|
|
1028
|
+
}
|
|
1029
|
+
mergedConfig = updateConfigWithSeparator( mergedConfig );
|
|
1030
|
+
|
|
1031
|
+
const blockSelectors = getBlockSelectors(
|
|
1032
|
+
getBlockTypes(),
|
|
1033
|
+
getBlockStyles
|
|
1034
|
+
);
|
|
1035
|
+
|
|
1036
|
+
const customProperties = toCustomProperties(
|
|
1037
|
+
mergedConfig,
|
|
1038
|
+
blockSelectors
|
|
1039
|
+
);
|
|
1040
|
+
const globalStyles = toStyles(
|
|
1041
|
+
mergedConfig,
|
|
1042
|
+
blockSelectors,
|
|
1043
|
+
hasBlockGapSupport,
|
|
1044
|
+
hasFallbackGapSupport,
|
|
1045
|
+
disableLayoutStyles
|
|
1046
|
+
);
|
|
1047
|
+
|
|
1048
|
+
const filters = toSvgFilters( mergedConfig, blockSelectors );
|
|
1049
|
+
const stylesheets = [
|
|
1050
|
+
{
|
|
1051
|
+
css: customProperties,
|
|
1052
|
+
isGlobalStyles: true,
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
css: globalStyles,
|
|
1056
|
+
isGlobalStyles: true,
|
|
1057
|
+
},
|
|
1058
|
+
// Load custom CSS in own stylesheet so that any invalid CSS entered in the input won't break all the global styles in the editor.
|
|
1059
|
+
{
|
|
1060
|
+
css: mergedConfig.styles.css ?? '',
|
|
1061
|
+
isGlobalStyles: true,
|
|
1062
|
+
},
|
|
1063
|
+
];
|
|
1064
|
+
|
|
1065
|
+
// Loop through the blocks to check if there are custom CSS values.
|
|
1066
|
+
// If there are, get the block selector and push the selector together with
|
|
1067
|
+
// the CSS value to the 'stylesheets' array.
|
|
1068
|
+
getBlockTypes().forEach( ( blockType ) => {
|
|
1069
|
+
if ( mergedConfig.styles.blocks[ blockType.name ]?.css ) {
|
|
1070
|
+
const selector = blockSelectors[ blockType.name ].selector;
|
|
1071
|
+
stylesheets.push( {
|
|
1072
|
+
css: processCSSNesting(
|
|
1073
|
+
mergedConfig.styles.blocks[ blockType.name ]?.css,
|
|
1074
|
+
selector
|
|
1075
|
+
),
|
|
1076
|
+
isGlobalStyles: true,
|
|
1077
|
+
} );
|
|
1078
|
+
}
|
|
1079
|
+
} );
|
|
1080
|
+
|
|
1081
|
+
return [ stylesheets, mergedConfig.settings, filters ];
|
|
1082
|
+
}, [
|
|
1083
|
+
hasBlockGapSupport,
|
|
1084
|
+
hasFallbackGapSupport,
|
|
1085
|
+
mergedConfig,
|
|
1086
|
+
disableLayoutStyles,
|
|
1087
|
+
] );
|
|
1088
|
+
}
|