@wordpress/block-editor 13.4.0 → 14.0.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 +11 -0
- package/README.md +11 -1
- package/build/components/block-breadcrumb/index.js +3 -1
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-draggable/index.js +2 -2
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-refs.js +24 -32
- package/build/components/block-list/use-block-props/use-block-refs.js.map +1 -1
- package/build/components/block-mover/index.js +1 -2
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-popover/cover.js +1 -1
- package/build/components/block-popover/cover.js.map +1 -1
- package/build/components/block-popover/inbetween.js +2 -2
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +2 -2
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +1 -2
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +1 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js +15 -16
- package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build/components/block-tools/zoom-out-toolbar.js +0 -1
- package/build/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build/components/child-layout-control/index.js +3 -1
- package/build/components/child-layout-control/index.js.map +1 -1
- package/build/components/dimensions-tool/scale-tool.js +1 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -1
- package/build/components/font-family/index.js +12 -0
- package/build/components/font-family/index.js.map +1 -1
- package/build/components/global-styles/background-panel.js +55 -51
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +1 -0
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/global-styles/theme-file-uri-utils.js +0 -59
- package/build/components/global-styles/theme-file-uri-utils.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +0 -1
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +58 -39
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +96 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/grid/grid-item-movers.js +30 -26
- package/build/components/grid/grid-item-movers.js.map +1 -1
- package/build/components/grid/grid-item-resizer.js +14 -15
- package/build/components/grid/grid-item-resizer.js.map +1 -1
- package/build/components/grid/grid-visualizer.js +1 -1
- package/build/components/grid/grid-visualizer.js.map +1 -1
- package/build/components/grid/use-grid-layout-sync.js +56 -20
- package/build/components/grid/use-grid-layout-sync.js.map +1 -1
- package/build/components/iframe/index.js +4 -8
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/category-tabs/index.js +29 -2
- package/build/components/inserter/category-tabs/index.js.map +1 -1
- package/build/components/inserter/menu.js +2 -2
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/line-height-control/index.js +0 -15
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/search-input.js +0 -1
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/media-replace-flow/index.js +3 -1
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/resolution-tool/index.js +1 -0
- package/build/components/resolution-tool/index.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js +4 -2
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -6
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/url-input/button.js +0 -1
- package/build/components/url-input/button.js.map +1 -1
- package/build/components/url-input/index.js +1 -11
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/link-editor.js +0 -1
- package/build/components/url-popover/link-editor.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +30 -4
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +3 -6
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +1 -3
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/components/use-settings/index.js +2 -1
- package/build/components/use-settings/index.js.map +1 -1
- package/build/hooks/block-bindings.js +248 -36
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/block-hooks.js +1 -0
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/block-style-variation.js +2 -2
- package/build/hooks/block-style-variation.js.map +1 -1
- package/build/hooks/contrast-checker.js +6 -6
- package/build/hooks/contrast-checker.js.map +1 -1
- package/build/hooks/duotone.js +3 -3
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +7 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/line-height.js +0 -1
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/spacing-visualizer.js +1 -1
- package/build/hooks/spacing-visualizer.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +4 -0
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/use-zoom-out.js +1 -1
- package/build/hooks/use-zoom-out.js.map +1 -1
- package/build/hooks/utils.js +20 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/private-apis.js +0 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +9 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +4 -4
- package/build/store/selectors.js.map +1 -1
- package/build/utils/get-editor-region.js +1 -1
- package/build/utils/get-editor-region.js.map +1 -1
- package/build/utils/get-px-from-css-unit.js +1 -1
- package/build/utils/get-px-from-css-unit.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js +4 -2
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +3 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-refs.js +24 -34
- package/build-module/components/block-list/use-block-props/use-block-refs.js.map +1 -1
- package/build-module/components/block-mover/index.js +1 -2
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-popover/cover.js +1 -1
- package/build-module/components/block-popover/cover.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +1 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +1 -1
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +1 -2
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +1 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js +16 -17
- package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-toolbar.js +0 -1
- package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +3 -1
- package/build-module/components/child-layout-control/index.js.map +1 -1
- package/build-module/components/dimensions-tool/scale-tool.js +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -1
- package/build-module/components/font-family/index.js +11 -0
- package/build-module/components/font-family/index.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +55 -51
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +1 -0
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/global-styles/theme-file-uri-utils.js +0 -58
- package/build-module/components/global-styles/theme-file-uri-utils.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +0 -1
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +57 -38
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +92 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/grid/grid-item-movers.js +30 -26
- package/build-module/components/grid/grid-item-movers.js.map +1 -1
- package/build-module/components/grid/grid-item-resizer.js +14 -15
- package/build-module/components/grid/grid-item-resizer.js.map +1 -1
- package/build-module/components/grid/grid-visualizer.js +1 -1
- package/build-module/components/grid/grid-visualizer.js.map +1 -1
- package/build-module/components/grid/use-grid-layout-sync.js +56 -20
- package/build-module/components/grid/use-grid-layout-sync.js.map +1 -1
- package/build-module/components/iframe/index.js +4 -8
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/category-tabs/index.js +30 -3
- package/build-module/components/inserter/category-tabs/index.js.map +1 -1
- package/build-module/components/inserter/menu.js +2 -2
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/line-height-control/index.js +0 -14
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/search-input.js +0 -1
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +3 -1
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +1 -0
- package/build-module/components/resolution-tool/index.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js +5 -3
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -6
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/url-input/button.js +0 -1
- package/build-module/components/url-input/button.js.map +1 -1
- package/build-module/components/url-input/index.js +1 -11
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/link-editor.js +0 -1
- package/build-module/components/url-popover/link-editor.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +30 -4
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +3 -6
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +1 -3
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/components/use-settings/index.js +2 -1
- package/build-module/components/use-settings/index.js.map +1 -1
- package/build-module/hooks/block-bindings.js +253 -40
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/block-hooks.js +1 -0
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/block-style-variation.js +3 -3
- package/build-module/hooks/block-style-variation.js.map +1 -1
- package/build-module/hooks/contrast-checker.js +7 -7
- package/build-module/hooks/contrast-checker.js.map +1 -1
- package/build-module/hooks/duotone.js +4 -4
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +2 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/line-height.js +0 -1
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/spacing-visualizer.js +1 -1
- package/build-module/hooks/spacing-visualizer.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +3 -0
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/use-zoom-out.js +1 -1
- package/build-module/hooks/use-zoom-out.js.map +1 -1
- package/build-module/hooks/utils.js +19 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/private-apis.js +1 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +9 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +4 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/get-editor-region.js +1 -1
- package/build-module/utils/get-editor-region.js.map +1 -1
- package/build-module/utils/get-px-from-css-unit.js +1 -1
- package/build-module/utils/get-px-from-css-unit.js.map +1 -1
- package/build-style/content-rtl.css +5 -12
- package/build-style/content.css +5 -12
- package/build-style/default-editor-styles-rtl.css +3 -0
- package/build-style/default-editor-styles.css +3 -0
- package/build-style/style-rtl.css +88 -46
- package/build-style/style.css +88 -46
- package/package.json +31 -31
- package/src/autocompleters/style.scss +4 -0
- package/src/components/block-breadcrumb/index.js +4 -2
- package/src/components/block-canvas/style.scss +1 -0
- package/src/components/block-draggable/index.js +3 -3
- package/src/components/block-list/use-block-props/use-block-refs.js +27 -43
- package/src/components/block-mover/index.js +5 -2
- package/src/components/block-popover/cover.js +1 -1
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +1 -1
- package/src/components/block-tools/block-selection-button.js +1 -2
- package/src/components/block-tools/index.js +5 -6
- package/src/components/block-tools/use-block-toolbar-popover-props.js +1 -1
- package/src/components/block-tools/zoom-out-mode-inserters.js +14 -18
- package/src/components/block-tools/zoom-out-toolbar.js +0 -1
- package/src/components/button-block-appender/content.scss +1 -1
- package/src/components/child-layout-control/index.js +2 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
- package/src/components/colors-gradients/test/control.js +3 -2
- package/src/components/dimensions-tool/scale-tool.js +1 -0
- package/src/components/font-family/README.md +8 -0
- package/src/components/font-family/index.js +16 -0
- package/src/components/font-family/stories/index.story.js +54 -0
- package/src/components/global-styles/background-panel.js +69 -61
- package/src/components/global-styles/image-settings-panel.js +1 -0
- package/src/components/global-styles/style.scss +0 -10
- package/src/components/global-styles/test/theme-file-uri-utils.js +1 -26
- package/src/components/global-styles/test/use-global-styles-output.js +49 -4
- package/src/components/global-styles/test/utils.js +120 -0
- package/src/components/global-styles/theme-file-uri-utils.js +0 -59
- package/src/components/global-styles/typography-panel.js +0 -1
- package/src/components/global-styles/use-global-styles-output.js +67 -48
- package/src/components/global-styles/utils.js +112 -0
- package/src/components/grid/grid-item-movers.js +46 -44
- package/src/components/grid/grid-item-resizer.js +11 -17
- package/src/components/grid/grid-visualizer.js +1 -1
- package/src/components/grid/style.scss +60 -10
- package/src/components/grid/use-grid-layout-sync.js +68 -14
- package/src/components/iframe/content.scss +2 -2
- package/src/components/iframe/index.js +3 -7
- package/src/components/inserter/category-tabs/index.js +35 -2
- package/src/components/inserter/menu.js +2 -2
- package/src/components/inserter/style.scss +16 -11
- package/src/components/inspector-controls/README.md +5 -0
- package/src/components/line-height-control/README.md +0 -8
- package/src/components/line-height-control/index.js +1 -21
- package/src/components/line-height-control/stories/index.story.js +0 -1
- package/src/components/line-height-control/test/index.js +1 -7
- package/src/components/link-control/search-input.js +0 -1
- package/src/components/media-replace-flow/README.md +7 -0
- package/src/components/media-replace-flow/index.js +3 -1
- package/src/components/resolution-tool/index.js +1 -0
- package/src/components/responsive-block-control/test/index.js +5 -1
- package/src/components/skip-to-selected-block/index.js +5 -3
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -6
- package/src/components/tabbed-sidebar/style.scss +1 -19
- package/src/components/url-input/README.md +0 -5
- package/src/components/url-input/button.js +0 -1
- package/src/components/url-input/index.js +1 -15
- package/src/components/url-popover/link-editor.js +0 -1
- package/src/components/use-block-drop-zone/index.js +66 -14
- package/src/components/use-on-block-drop/index.js +1 -9
- package/src/components/use-resize-canvas/index.js +1 -3
- package/src/components/use-settings/index.js +2 -1
- package/src/hooks/block-bindings.js +303 -52
- package/src/hooks/block-bindings.scss +13 -2
- package/src/hooks/block-hooks.js +1 -0
- package/src/hooks/block-hooks.scss +1 -0
- package/src/hooks/block-style-variation.js +3 -3
- package/src/hooks/contrast-checker.js +7 -7
- package/src/hooks/duotone.js +4 -4
- package/src/hooks/index.js +2 -1
- package/src/hooks/line-height.js +0 -1
- package/src/hooks/spacing-visualizer.js +1 -1
- package/src/hooks/use-bindings-attributes.js +4 -0
- package/src/hooks/use-editor-wrapper-styles.native.scss +1 -0
- package/src/hooks/use-zoom-out.js +1 -1
- package/src/hooks/utils.js +14 -1
- package/src/index.js +1 -0
- package/src/private-apis.js +1 -2
- package/src/store/actions.js +13 -5
- package/src/store/selectors.js +4 -4
- package/src/style.scss +1 -1
- package/src/utils/get-editor-region.js +1 -1
- package/src/utils/get-px-from-css-unit.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -30
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +0 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -23
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +0 -1
- package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -25
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
scopeFeatureSelectors,
|
|
25
25
|
appendToSelector,
|
|
26
26
|
getBlockStyleVariationSelector,
|
|
27
|
+
compileStyleValue,
|
|
28
|
+
getResolvedValue,
|
|
27
29
|
} from './utils';
|
|
28
30
|
import { getBlockCSSSelector } from './get-block-css-selector';
|
|
29
31
|
import { getTypographyFontSizeValue } from './typography-utils';
|
|
@@ -36,7 +38,6 @@ import { store as blockEditorStore } from '../../store';
|
|
|
36
38
|
import { LAYOUT_DEFINITIONS } from '../../layouts/definitions';
|
|
37
39
|
import { getValueFromObjectPath, setImmutably } from '../../utils/object';
|
|
38
40
|
import { unlock } from '../../lock-unlock';
|
|
39
|
-
import { setThemeFileUris } from './theme-file-uri-utils';
|
|
40
41
|
|
|
41
42
|
// Elements that rely on class names in their selectors.
|
|
42
43
|
const ELEMENT_CLASS_NAMES = {
|
|
@@ -54,21 +55,6 @@ const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
|
|
54
55
|
};
|
|
55
56
|
const { kebabCase } = unlock( componentsPrivateApis );
|
|
56
57
|
|
|
57
|
-
function compileStyleValue( uncompiledValue ) {
|
|
58
|
-
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
59
|
-
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
60
|
-
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
|
|
61
|
-
|
|
62
|
-
if ( uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX ) ) {
|
|
63
|
-
const variable = uncompiledValue
|
|
64
|
-
.slice( VARIABLE_REFERENCE_PREFIX.length )
|
|
65
|
-
.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
|
|
66
|
-
.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );
|
|
67
|
-
return `var(--wp--${ variable })`;
|
|
68
|
-
}
|
|
69
|
-
return uncompiledValue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
58
|
/**
|
|
73
59
|
* Transform given preset tree into a set of style declarations.
|
|
74
60
|
*
|
|
@@ -395,21 +381,40 @@ export function getStylesDeclarations(
|
|
|
395
381
|
);
|
|
396
382
|
|
|
397
383
|
/*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
384
|
+
* Preprocess background image values.
|
|
385
|
+
*
|
|
386
|
+
* Note: As we absorb more and more styles into the engine, we could simplify this function.
|
|
387
|
+
* A refactor is for the style engine to handle ref resolution (and possibly defaults)
|
|
388
|
+
* via a public util used internally and externally. Theme.json tree and defaults could be passed
|
|
389
|
+
* as options.
|
|
400
390
|
*/
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
391
|
+
if ( !! blockStyles.background ) {
|
|
392
|
+
/*
|
|
393
|
+
* Resolve dynamic values before they are compiled by the style engine,
|
|
394
|
+
* which doesn't (yet) resolve dynamic values.
|
|
395
|
+
*/
|
|
396
|
+
if ( blockStyles.background?.backgroundImage ) {
|
|
397
|
+
blockStyles.background.backgroundImage = getResolvedValue(
|
|
398
|
+
blockStyles.background.backgroundImage,
|
|
399
|
+
tree
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/*
|
|
404
|
+
* Set default values for block background styles.
|
|
405
|
+
* Top-level styles are an exception as they are applied to the body.
|
|
406
|
+
*/
|
|
407
|
+
if ( ! isRoot && !! blockStyles.background?.backgroundImage?.id ) {
|
|
408
|
+
blockStyles = {
|
|
409
|
+
...blockStyles,
|
|
410
|
+
background: {
|
|
411
|
+
...blockStyles.background,
|
|
412
|
+
...setBackgroundStyleDefaults( blockStyles.background ),
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
409
416
|
}
|
|
410
417
|
|
|
411
|
-
// The goal is to move everything to server side generated engine styles
|
|
412
|
-
// This is temporary as we absorb more and more styles into the engine.
|
|
413
418
|
const extraRules = getCSSRules( blockStyles );
|
|
414
419
|
extraRules.forEach( ( rule ) => {
|
|
415
420
|
// Don't output padding properties if padding variables are set or if we're not editing a full template.
|
|
@@ -424,18 +429,7 @@ export function getStylesDeclarations(
|
|
|
424
429
|
? rule.key
|
|
425
430
|
: kebabCase( rule.key );
|
|
426
431
|
|
|
427
|
-
let ruleValue = rule.value;
|
|
428
|
-
if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
|
|
429
|
-
const refPath = ruleValue.ref.split( '.' );
|
|
430
|
-
ruleValue = compileStyleValue(
|
|
431
|
-
getValueFromObjectPath( tree, refPath )
|
|
432
|
-
);
|
|
433
|
-
// Presence of another ref indicates a reference to another dynamic value.
|
|
434
|
-
// Pointing to another dynamic value is not supported.
|
|
435
|
-
if ( ! ruleValue || ruleValue?.ref ) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
432
|
+
let ruleValue = getResolvedValue( rule.value, tree, null );
|
|
439
433
|
|
|
440
434
|
// Calculate fluid typography rules where available.
|
|
441
435
|
if ( cssProperty === 'font-size' ) {
|
|
@@ -1327,9 +1321,17 @@ function updateConfigWithSeparator( config ) {
|
|
|
1327
1321
|
export function processCSSNesting( css, blockSelector ) {
|
|
1328
1322
|
let processedCSS = '';
|
|
1329
1323
|
|
|
1324
|
+
if ( ! css || css.trim() === '' ) {
|
|
1325
|
+
return processedCSS;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1330
1328
|
// Split CSS nested rules.
|
|
1331
1329
|
const parts = css.split( '&' );
|
|
1332
1330
|
parts.forEach( ( part ) => {
|
|
1331
|
+
if ( ! part || part.trim() === '' ) {
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1333
1335
|
const isRootCss = ! part.includes( '{' );
|
|
1334
1336
|
if ( isRootCss ) {
|
|
1335
1337
|
// If the part doesn't contain braces, it applies to the root level.
|
|
@@ -1342,11 +1344,32 @@ export function processCSSNesting( css, blockSelector ) {
|
|
|
1342
1344
|
}
|
|
1343
1345
|
|
|
1344
1346
|
const [ nestedSelector, cssValue ] = splittedPart;
|
|
1345
|
-
const combinedSelector = nestedSelector.startsWith( ' ' )
|
|
1346
|
-
? scopeSelector( blockSelector, nestedSelector )
|
|
1347
|
-
: appendToSelector( blockSelector, nestedSelector );
|
|
1348
1347
|
|
|
1349
|
-
|
|
1348
|
+
// Handle pseudo elements such as ::before, ::after, etc. Regex will also
|
|
1349
|
+
// capture any leading combinator such as >, +, or ~, as well as spaces.
|
|
1350
|
+
// This allows pseudo elements as descendants e.g. `.parent ::before`.
|
|
1351
|
+
const matches = nestedSelector.match( /([>+~\s]*::[a-zA-Z-]+)/ );
|
|
1352
|
+
const pseudoPart = matches ? matches[ 1 ] : '';
|
|
1353
|
+
const withoutPseudoElement = matches
|
|
1354
|
+
? nestedSelector.replace( pseudoPart, '' ).trim()
|
|
1355
|
+
: nestedSelector.trim();
|
|
1356
|
+
|
|
1357
|
+
let combinedSelector;
|
|
1358
|
+
if ( withoutPseudoElement === '' ) {
|
|
1359
|
+
// Only contained a pseudo element to use the block selector to form
|
|
1360
|
+
// the final `:root :where()` selector.
|
|
1361
|
+
combinedSelector = blockSelector;
|
|
1362
|
+
} else {
|
|
1363
|
+
// If the nested selector is a descendant of the block scope it with the
|
|
1364
|
+
// block selector. Otherwise append it to the block selector.
|
|
1365
|
+
combinedSelector = nestedSelector.startsWith( ' ' )
|
|
1366
|
+
? scopeSelector( blockSelector, withoutPseudoElement )
|
|
1367
|
+
: appendToSelector( blockSelector, withoutPseudoElement );
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// Build final rule, re-adding any pseudo element outside the `:where()`
|
|
1371
|
+
// to maintain valid CSS selector.
|
|
1372
|
+
processedCSS += `:root :where(${ combinedSelector })${ pseudoPart }{${ cssValue.trim() }}`;
|
|
1350
1373
|
}
|
|
1351
1374
|
} );
|
|
1352
1375
|
return processedCSS;
|
|
@@ -1369,10 +1392,6 @@ export function useGlobalStylesOutputWithConfig(
|
|
|
1369
1392
|
disableRootPadding
|
|
1370
1393
|
) {
|
|
1371
1394
|
const [ blockGap ] = useGlobalSetting( 'spacing.blockGap' );
|
|
1372
|
-
mergedConfig = setThemeFileUris(
|
|
1373
|
-
mergedConfig,
|
|
1374
|
-
mergedConfig?._links?.[ 'wp:theme-file' ]
|
|
1375
|
-
);
|
|
1376
1395
|
const hasBlockGapSupport = blockGap !== null;
|
|
1377
1396
|
const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
1378
1397
|
const disableLayoutStyles = useSelect( ( select ) => {
|
|
@@ -525,3 +525,115 @@ export function getBlockStyleVariationSelector( variation, blockSelector ) {
|
|
|
525
525
|
|
|
526
526
|
return result.join( ',' );
|
|
527
527
|
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Converts style preset values `var:` to CSS custom var values.
|
|
531
|
+
* TODO: Export and use the style engine util: getCSSVarFromStyleValue().
|
|
532
|
+
*
|
|
533
|
+
* Example:
|
|
534
|
+
*
|
|
535
|
+
* compileStyleValue( 'var:preset|color|primary' ) // returns 'var(--wp--color-primary)'
|
|
536
|
+
*
|
|
537
|
+
* @param {string} uncompiledValue A block style value.
|
|
538
|
+
* @return {string} The compiled, or original value.
|
|
539
|
+
*/
|
|
540
|
+
export function compileStyleValue( uncompiledValue ) {
|
|
541
|
+
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
542
|
+
if (
|
|
543
|
+
'string' === typeof uncompiledValue &&
|
|
544
|
+
uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX )
|
|
545
|
+
) {
|
|
546
|
+
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
547
|
+
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
|
|
548
|
+
const variable = uncompiledValue
|
|
549
|
+
.slice( VARIABLE_REFERENCE_PREFIX.length )
|
|
550
|
+
.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
|
|
551
|
+
.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );
|
|
552
|
+
return `var(--wp--${ variable })`;
|
|
553
|
+
}
|
|
554
|
+
return uncompiledValue;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Looks up a theme file URI based on a relative path.
|
|
559
|
+
*
|
|
560
|
+
* @param {string} file A relative path.
|
|
561
|
+
* @param {Array<Object>} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths.
|
|
562
|
+
* @return {string} A resolved theme file URI, if one is found in the themeFileURIs collection.
|
|
563
|
+
*/
|
|
564
|
+
export function getResolvedThemeFilePath( file, themeFileURIs ) {
|
|
565
|
+
if ( ! file || ! themeFileURIs || ! Array.isArray( themeFileURIs ) ) {
|
|
566
|
+
return file;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const uri = themeFileURIs.find(
|
|
570
|
+
( themeFileUri ) => themeFileUri?.name === file
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
if ( ! uri?.href ) {
|
|
574
|
+
return file;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return uri?.href;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Resolves ref values in theme JSON.
|
|
582
|
+
*
|
|
583
|
+
* @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.
|
|
584
|
+
* @param {Object} tree A theme.json object.
|
|
585
|
+
* @return {*} The resolved value or incoming ruleValue.
|
|
586
|
+
*/
|
|
587
|
+
export function getResolvedRefValue( ruleValue, tree ) {
|
|
588
|
+
if ( ! ruleValue || ! tree ) {
|
|
589
|
+
return ruleValue;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
|
|
593
|
+
const refPath = ruleValue.ref.split( '.' );
|
|
594
|
+
const resolvedRuleValue = compileStyleValue(
|
|
595
|
+
getValueFromObjectPath( tree, refPath )
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
/*
|
|
599
|
+
* Presence of another ref indicates a reference to another dynamic value.
|
|
600
|
+
* Pointing to another dynamic value is not supported.
|
|
601
|
+
*/
|
|
602
|
+
if ( resolvedRuleValue?.ref ) {
|
|
603
|
+
return undefined;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if ( ! resolvedRuleValue ) {
|
|
607
|
+
return ruleValue;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return resolvedRuleValue;
|
|
611
|
+
}
|
|
612
|
+
return ruleValue;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Resolves ref and relative path values in theme JSON.
|
|
617
|
+
*
|
|
618
|
+
* @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.
|
|
619
|
+
* @param {Object} tree A theme.json object.
|
|
620
|
+
* @return {*} The resolved value or incoming ruleValue.
|
|
621
|
+
*/
|
|
622
|
+
export function getResolvedValue( ruleValue, tree ) {
|
|
623
|
+
if ( ! ruleValue || ! tree ) {
|
|
624
|
+
return ruleValue;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Resolve ref values.
|
|
628
|
+
const resolvedValue = getResolvedRefValue( ruleValue, tree );
|
|
629
|
+
|
|
630
|
+
// Resolve relative paths.
|
|
631
|
+
if ( resolvedValue?.url ) {
|
|
632
|
+
resolvedValue.url = getResolvedThemeFilePath(
|
|
633
|
+
resolvedValue.url,
|
|
634
|
+
tree?._links?.[ 'wp:theme-file' ]
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return resolvedValue;
|
|
639
|
+
}
|
|
@@ -55,28 +55,29 @@ export function GridItemMovers( {
|
|
|
55
55
|
return (
|
|
56
56
|
<BlockControls group="parent">
|
|
57
57
|
<ToolbarGroup className="block-editor-grid-item-mover__move-button-container">
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
58
|
+
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-left">
|
|
59
|
+
<GridItemMover
|
|
60
|
+
icon={ chevronLeft }
|
|
61
|
+
label={ __( 'Move left' ) }
|
|
62
|
+
description={ __( 'Move left' ) }
|
|
63
|
+
isDisabled={ columnStart <= 1 }
|
|
64
|
+
onClick={ () => {
|
|
65
|
+
onChange( {
|
|
66
|
+
columnStart: columnStart - 1,
|
|
67
|
+
} );
|
|
68
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
69
|
+
moveBlocksToPosition(
|
|
70
|
+
[ blockClientId ],
|
|
71
|
+
gridClientId,
|
|
72
|
+
gridClientId,
|
|
73
|
+
getNumberOfBlocksBeforeCell(
|
|
74
|
+
columnStart - 1,
|
|
75
|
+
rowStart
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
} }
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
80
81
|
<div className="block-editor-grid-item-mover__move-vertical-button-container">
|
|
81
82
|
<GridItemMover
|
|
82
83
|
className="is-up-button"
|
|
@@ -123,28 +124,29 @@ export function GridItemMovers( {
|
|
|
123
124
|
} }
|
|
124
125
|
/>
|
|
125
126
|
</div>
|
|
126
|
-
<
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
127
|
+
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-right">
|
|
128
|
+
<GridItemMover
|
|
129
|
+
icon={ chevronRight }
|
|
130
|
+
label={ __( 'Move right' ) }
|
|
131
|
+
description={ __( 'Move right' ) }
|
|
132
|
+
isDisabled={ columnCount && columnEnd >= columnCount }
|
|
133
|
+
onClick={ () => {
|
|
134
|
+
onChange( {
|
|
135
|
+
columnStart: columnStart + 1,
|
|
136
|
+
} );
|
|
137
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
138
|
+
moveBlocksToPosition(
|
|
139
|
+
[ blockClientId ],
|
|
140
|
+
gridClientId,
|
|
141
|
+
gridClientId,
|
|
142
|
+
getNumberOfBlocksBeforeCell(
|
|
143
|
+
columnStart + 1,
|
|
144
|
+
rowStart
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
} }
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
148
150
|
</ToolbarGroup>
|
|
149
151
|
</BlockControls>
|
|
150
152
|
);
|
|
@@ -7,7 +7,7 @@ import { useState, useEffect } from '@wordpress/element';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
|
|
11
11
|
import BlockPopoverCover from '../block-popover/cover';
|
|
12
12
|
import { getComputedCSS, getGridTracks, getClosestTrack } from './utils';
|
|
13
13
|
|
|
@@ -98,7 +98,7 @@ function GridItemResizerInner( {
|
|
|
98
98
|
<BlockPopoverCover
|
|
99
99
|
className="block-editor-grid-item-resizer"
|
|
100
100
|
clientId={ clientId }
|
|
101
|
-
__unstablePopoverSlot="block-
|
|
101
|
+
__unstablePopoverSlot="__unstable-block-tools-after"
|
|
102
102
|
additionalStyles={ styles }
|
|
103
103
|
>
|
|
104
104
|
<ResizableBox
|
|
@@ -119,6 +119,15 @@ function GridItemResizerInner( {
|
|
|
119
119
|
} }
|
|
120
120
|
bounds={ bounds }
|
|
121
121
|
boundsByDirection
|
|
122
|
+
onPointerDown={ ( { target, pointerId } ) => {
|
|
123
|
+
/*
|
|
124
|
+
* Captures the pointer to avoid hiccups while dragging over objects
|
|
125
|
+
* like iframes and ensures that the event to end the drag is
|
|
126
|
+
* captured by the target (resize handle) whether or not it’s under
|
|
127
|
+
* the pointer.
|
|
128
|
+
*/
|
|
129
|
+
target.setPointerCapture( pointerId );
|
|
130
|
+
} }
|
|
122
131
|
onResizeStart={ ( event, direction ) => {
|
|
123
132
|
/*
|
|
124
133
|
* The container justification and alignment need to be set
|
|
@@ -126,21 +135,6 @@ function GridItemResizerInner( {
|
|
|
126
135
|
* so that it resizes in the right direction.
|
|
127
136
|
*/
|
|
128
137
|
setResizeDirection( direction );
|
|
129
|
-
|
|
130
|
-
/*
|
|
131
|
-
* The mouseup event on the resize handle doesn't trigger if the mouse
|
|
132
|
-
* isn't directly above the handle, so we try to detect if it happens
|
|
133
|
-
* outside the grid and dispatch a mouseup event on the handle.
|
|
134
|
-
*/
|
|
135
|
-
blockElement.ownerDocument.addEventListener(
|
|
136
|
-
'mouseup',
|
|
137
|
-
() => {
|
|
138
|
-
event.target.dispatchEvent(
|
|
139
|
-
new Event( 'mouseup', { bubbles: true } )
|
|
140
|
-
);
|
|
141
|
-
},
|
|
142
|
-
{ once: true }
|
|
143
|
-
);
|
|
144
138
|
} }
|
|
145
139
|
onResizeStop={ ( event, direction, boxElement ) => {
|
|
146
140
|
const columnGap = parseFloat(
|
|
@@ -13,7 +13,7 @@ import { __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
|
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
|
|
17
17
|
import BlockPopoverCover from '../block-popover/cover';
|
|
18
18
|
import { range, GridRect, getGridInfo } from './utils';
|
|
19
19
|
import { store as blockEditorStore } from '../../store';
|
|
@@ -105,7 +105,6 @@
|
|
|
105
105
|
.block-editor-grid-item-mover-button {
|
|
106
106
|
width: $block-toolbar-height * 0.5;
|
|
107
107
|
min-width: 0 !important; // overrides default button width.
|
|
108
|
-
overflow: hidden;
|
|
109
108
|
padding-left: 0;
|
|
110
109
|
padding-right: 0;
|
|
111
110
|
|
|
@@ -155,7 +154,7 @@
|
|
|
155
154
|
justify-content: space-around;
|
|
156
155
|
|
|
157
156
|
> .block-editor-grid-item-mover-button.block-editor-grid-item-mover-button {
|
|
158
|
-
height: $block-toolbar-height * 0.5 - $grid-unit-05;
|
|
157
|
+
height: $block-toolbar-height * 0.5 - $grid-unit-05 !important; // overrides toolbar button height.
|
|
159
158
|
width: 100%;
|
|
160
159
|
min-width: 0 !important; // overrides default button width.
|
|
161
160
|
|
|
@@ -173,18 +172,53 @@
|
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
174
|
|
|
175
|
+
.editor-collapsible-block-toolbar {
|
|
176
|
+
.block-editor-grid-item-mover__move-vertical-button-container {
|
|
177
|
+
// Move up a little to prevent the toolbar shift when focus is on the vertical movers.
|
|
178
|
+
@include break-small() {
|
|
179
|
+
height: $grid-unit-50;
|
|
180
|
+
position: relative;
|
|
181
|
+
top: -5px; // Should be -4px, but that causes scrolling when focus lands on the movers, in a 60px header.
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
176
186
|
.show-icon-labels {
|
|
177
187
|
|
|
178
|
-
.block-editor-grid-item-
|
|
179
|
-
|
|
180
|
-
padding-right: 12px;
|
|
181
|
-
}
|
|
188
|
+
.block-editor-grid-item-mover__move-horizontal-button-container {
|
|
189
|
+
position: relative;
|
|
182
190
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
&::before {
|
|
192
|
+
@include break-small() {
|
|
193
|
+
content: "";
|
|
194
|
+
height: 100%;
|
|
195
|
+
width: $border-width;
|
|
196
|
+
background: $gray-200;
|
|
197
|
+
position: absolute;
|
|
198
|
+
top: 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@include break-medium() {
|
|
202
|
+
background: $gray-900;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
&.is-left {
|
|
207
|
+
padding-right: 6px;
|
|
187
208
|
|
|
209
|
+
&::before {
|
|
210
|
+
right: 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&.is-right {
|
|
215
|
+
padding-left: 6px;
|
|
216
|
+
|
|
217
|
+
&::before {
|
|
218
|
+
left: 0;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
188
222
|
|
|
189
223
|
.block-editor-grid-item-mover__move-vertical-button-container {
|
|
190
224
|
&::before {
|
|
@@ -208,5 +242,21 @@
|
|
|
208
242
|
}
|
|
209
243
|
}
|
|
210
244
|
|
|
245
|
+
.block-editor-grid-item-mover-button {
|
|
246
|
+
white-space: nowrap;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.editor-collapsible-block-toolbar {
|
|
250
|
+
.block-editor-grid-item-mover__move-horizontal-button-container::before {
|
|
251
|
+
height: $grid-unit-30;
|
|
252
|
+
background: $gray-300;
|
|
253
|
+
top: $grid-unit-05;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.block-editor-grid-item-mover__move-vertical-button-container::before {
|
|
257
|
+
background: $gray-300;
|
|
258
|
+
width: calc(100% - #{$grid-unit-30});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
211
261
|
}
|
|
212
262
|
|
|
@@ -10,6 +10,7 @@ import { usePrevious } from '@wordpress/compose';
|
|
|
10
10
|
*/
|
|
11
11
|
import { store as blockEditorStore } from '../../store';
|
|
12
12
|
import { GridRect } from './utils';
|
|
13
|
+
import { setImmutably } from '../../utils/object';
|
|
13
14
|
|
|
14
15
|
export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
15
16
|
const { gridLayout, blockOrder, selectedBlockLayout } = useSelect(
|
|
@@ -26,7 +27,8 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
|
26
27
|
[ gridClientId ]
|
|
27
28
|
);
|
|
28
29
|
|
|
29
|
-
const { getBlockAttributes } =
|
|
30
|
+
const { getBlockAttributes, getBlockRootClientId } =
|
|
31
|
+
useSelect( blockEditorStore );
|
|
30
32
|
const { updateBlockAttributes, __unstableMarkNextChangeAsNotPersistent } =
|
|
31
33
|
useDispatch( blockEditorStore );
|
|
32
34
|
|
|
@@ -37,6 +39,10 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
|
37
39
|
);
|
|
38
40
|
|
|
39
41
|
const previouslySelectedBlockRect = usePrevious( selectedBlockRect );
|
|
42
|
+
const previousIsManualPlacement = usePrevious(
|
|
43
|
+
gridLayout.isManualPlacement
|
|
44
|
+
);
|
|
45
|
+
const previousBlockOrder = usePrevious( blockOrder );
|
|
40
46
|
|
|
41
47
|
useEffect( () => {
|
|
42
48
|
const updates = {};
|
|
@@ -120,20 +126,65 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
|
120
126
|
},
|
|
121
127
|
};
|
|
122
128
|
}
|
|
129
|
+
|
|
130
|
+
// Unset grid layout attributes for blocks removed from the grid.
|
|
131
|
+
for ( const clientId of previousBlockOrder ?? [] ) {
|
|
132
|
+
if ( ! blockOrder.includes( clientId ) ) {
|
|
133
|
+
const rootClientId = getBlockRootClientId( clientId );
|
|
134
|
+
|
|
135
|
+
// Block was removed from the editor, so nothing to do.
|
|
136
|
+
if ( rootClientId === null ) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Check if the block is being moved to another grid.
|
|
141
|
+
// If so, do nothing and let the new grid parent handle
|
|
142
|
+
// the attributes.
|
|
143
|
+
const rootAttributes = getBlockAttributes( rootClientId );
|
|
144
|
+
if ( rootAttributes?.layout?.type === 'grid' ) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const attributes = getBlockAttributes( clientId );
|
|
149
|
+
const {
|
|
150
|
+
columnStart,
|
|
151
|
+
rowStart,
|
|
152
|
+
columnSpan,
|
|
153
|
+
rowSpan,
|
|
154
|
+
...layout
|
|
155
|
+
} = attributes.style?.layout ?? {};
|
|
156
|
+
|
|
157
|
+
if ( columnStart || rowStart || columnSpan || rowSpan ) {
|
|
158
|
+
const hasEmptyLayoutAttribute =
|
|
159
|
+
Object.keys( layout ).length === 0;
|
|
160
|
+
|
|
161
|
+
updates[ clientId ] = setImmutably(
|
|
162
|
+
attributes,
|
|
163
|
+
[ 'style', 'layout' ],
|
|
164
|
+
hasEmptyLayoutAttribute ? undefined : layout
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
123
169
|
} else {
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
attributes
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
layout
|
|
135
|
-
|
|
136
|
-
|
|
170
|
+
// Remove all of the columnStart and rowStart values
|
|
171
|
+
// when switching from manual to auto mode,
|
|
172
|
+
if ( previousIsManualPlacement === true ) {
|
|
173
|
+
for ( const clientId of blockOrder ) {
|
|
174
|
+
const attributes = getBlockAttributes( clientId );
|
|
175
|
+
const { columnStart, rowStart, ...layout } =
|
|
176
|
+
attributes.style?.layout ?? {};
|
|
177
|
+
// Only update attributes if columnStart or rowStart are set.
|
|
178
|
+
if ( columnStart || rowStart ) {
|
|
179
|
+
const hasEmptyLayoutAttribute =
|
|
180
|
+
Object.keys( layout ).length === 0;
|
|
181
|
+
|
|
182
|
+
updates[ clientId ] = setImmutably(
|
|
183
|
+
attributes,
|
|
184
|
+
[ 'style', 'layout' ],
|
|
185
|
+
hasEmptyLayoutAttribute ? undefined : layout
|
|
186
|
+
);
|
|
187
|
+
}
|
|
137
188
|
}
|
|
138
189
|
}
|
|
139
190
|
|
|
@@ -160,11 +211,14 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
|
160
211
|
// Actual deps to sync:
|
|
161
212
|
gridClientId,
|
|
162
213
|
gridLayout,
|
|
214
|
+
previousBlockOrder,
|
|
163
215
|
blockOrder,
|
|
164
216
|
previouslySelectedBlockRect,
|
|
217
|
+
previousIsManualPlacement,
|
|
165
218
|
// These won't change, but the linter thinks they might:
|
|
166
219
|
__unstableMarkNextChangeAsNotPersistent,
|
|
167
220
|
getBlockAttributes,
|
|
221
|
+
getBlockRootClientId,
|
|
168
222
|
updateBlockAttributes,
|
|
169
223
|
] );
|
|
170
224
|
}
|