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