@wordpress/block-editor 13.1.0 → 13.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 +21 -17
- package/README.md +1 -2
- package/build/components/block-breadcrumb/index.js +12 -1
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-lock/modal.js +67 -67
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +0 -1
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/button.js +1 -1
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +12 -6
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +2 -2
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-patterns-paging/index.js +5 -7
- package/build/components/block-patterns-paging/index.js.map +1 -1
- package/build/components/block-quick-navigation/index.js +20 -17
- package/build/components/block-quick-navigation/index.js.map +1 -1
- package/build/components/block-rename/modal.js +4 -12
- package/build/components/block-rename/modal.js.map +1 -1
- package/build/components/block-toolbar/shuffle.js +4 -1
- package/build/components/block-toolbar/shuffle.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +7 -58
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/block-toolbar-breadcrumb.js +9 -2
- package/build/components/block-tools/block-toolbar-breadcrumb.js.map +1 -1
- package/build/components/block-tools/index.js +14 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/use-show-block-tools.js +4 -2
- package/build/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js +5 -4
- package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build/components/block-tools/zoom-out-popover.js +57 -0
- package/build/components/block-tools/zoom-out-popover.js.map +1 -0
- package/build/components/block-tools/zoom-out-toolbar.js +138 -0
- package/build/components/block-tools/zoom-out-toolbar.js.map +1 -0
- package/build/components/button-block-appender/index.js +3 -1
- package/build/components/button-block-appender/index.js.map +1 -1
- package/build/components/child-layout-control/index.js +193 -127
- package/build/components/child-layout-control/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +10 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/dimensions-tool/index.js +6 -4
- package/build/components/dimensions-tool/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +26 -61
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/global-styles/background-panel.js +178 -116
- package/build/components/global-styles/background-panel.js.map +1 -1
- package/build/components/global-styles/border-panel.js +2 -1
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +2 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +2 -1
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +2 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +8 -0
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +2 -1
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +50 -12
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +50 -0
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +25 -9
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +17 -7
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/grid/grid-item-movers.js +94 -0
- package/build/components/grid/grid-item-movers.js.map +1 -0
- package/build/components/{grid-visualizer → grid}/grid-item-resizer.js +18 -56
- package/build/components/grid/grid-item-resizer.js.map +1 -0
- package/build/components/grid/grid-visualizer.js +305 -0
- package/build/components/grid/grid-visualizer.js.map +1 -0
- package/build/components/{grid-visualizer → grid}/index.js +14 -0
- package/build/components/grid/index.js.map +1 -0
- package/build/components/grid/use-get-number-of-blocks-before-cell.js +40 -0
- package/build/components/grid/use-get-number-of-blocks-before-cell.js.map +1 -0
- package/build/components/grid/use-grid-layout-sync.js +169 -0
- package/build/components/grid/use-grid-layout-sync.js.map +1 -0
- package/build/components/grid/utils.js +145 -0
- package/build/components/grid/utils.js.map +1 -0
- package/build/components/image-editor/aspect-ratio-dropdown.js +0 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/inner-blocks/index.js +1 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +1 -19
- package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
- package/build/components/inserter/menu.js +26 -4
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +2 -1
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +2 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/link-control/link-preview.js +1 -1
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/media-placeholder/index.js +19 -23
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +3 -1
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/rich-text/event-listeners/input-rules.js +1 -0
- package/build/components/rich-text/event-listeners/input-rules.js.map +1 -1
- package/build/components/rich-text/index.native.js +10 -4
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +14 -0
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +5 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/tabbed-sidebar/index.js +66 -0
- package/build/components/tabbed-sidebar/index.js.map +1 -0
- package/build/components/url-popover/index.js +3 -0
- package/build/components/url-popover/index.js.map +1 -1
- package/build/hooks/background.js +26 -4
- package/build/hooks/background.js.map +1 -1
- package/build/hooks/block-hooks.js +11 -17
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/block-style-variation.js +195 -11
- package/build/hooks/block-style-variation.js.map +1 -1
- package/build/hooks/duotone.js +16 -11
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/grid-visualizer.js +65 -0
- package/build/hooks/grid-visualizer.js.map +1 -0
- package/build/hooks/index.js +15 -2
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout-child.js +65 -40
- package/build/hooks/layout-child.js.map +1 -1
- package/build/hooks/position.js +2 -9
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +16 -6
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/hooks/utils.js +5 -2
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/constrained.js +44 -2
- package/build/layouts/constrained.js.map +1 -1
- package/build/layouts/grid.js +92 -76
- package/build/layouts/grid.js.map +1 -1
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +6 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +17 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +0 -2
- package/build/store/defaults.js.map +1 -1
- package/build/store/defaults.native.js +0 -3
- package/build/store/defaults.native.js.map +1 -1
- package/build/store/private-keys.js +2 -1
- package/build/store/private-keys.js.map +1 -1
- package/build/utils/format-font-style.js +45 -0
- package/build/utils/format-font-style.js.map +1 -0
- package/build/utils/format-font-weight.js +68 -0
- package/build/utils/format-font-weight.js.map +1 -0
- package/build/utils/get-editor-region.js +34 -0
- package/build/utils/get-editor-region.js.map +1 -0
- package/build/utils/get-font-styles-and-weights.js +167 -0
- package/build/utils/get-font-styles-and-weights.js.map +1 -0
- package/build/utils/pasting.js +5 -13
- package/build/utils/pasting.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js +12 -1
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-lock/modal.js +67 -67
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +0 -1
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/button.js +1 -1
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +12 -6
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +2 -2
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-patterns-paging/index.js +5 -7
- package/build-module/components/block-patterns-paging/index.js.map +1 -1
- package/build-module/components/block-quick-navigation/index.js +20 -17
- package/build-module/components/block-quick-navigation/index.js.map +1 -1
- package/build-module/components/block-rename/modal.js +5 -13
- package/build-module/components/block-rename/modal.js.map +1 -1
- package/build-module/components/block-toolbar/shuffle.js +4 -1
- package/build-module/components/block-toolbar/shuffle.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +10 -61
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/block-toolbar-breadcrumb.js +9 -2
- package/build-module/components/block-tools/block-toolbar-breadcrumb.js.map +1 -1
- package/build-module/components/block-tools/index.js +14 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/use-show-block-tools.js +4 -2
- package/build-module/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js +5 -4
- package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-popover.js +48 -0
- package/build-module/components/block-tools/zoom-out-popover.js.map +1 -0
- package/build-module/components/block-tools/zoom-out-toolbar.js +131 -0
- package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -0
- package/build-module/components/button-block-appender/index.js +3 -1
- package/build-module/components/button-block-appender/index.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +194 -128
- package/build-module/components/child-layout-control/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +11 -3
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/dimensions-tool/index.js +6 -4
- package/build-module/components/dimensions-tool/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +28 -63
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/global-styles/background-panel.js +181 -119
- package/build-module/components/global-styles/background-panel.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +3 -2
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +3 -2
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +3 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +3 -2
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +8 -0
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +3 -2
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +52 -14
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +48 -0
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +25 -9
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +15 -6
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/grid/grid-item-movers.js +87 -0
- package/build-module/components/grid/grid-item-movers.js.map +1 -0
- package/build-module/components/{grid-visualizer → grid}/grid-item-resizer.js +13 -51
- package/build-module/components/grid/grid-item-resizer.js.map +1 -0
- package/build-module/components/grid/grid-visualizer.js +297 -0
- package/build-module/components/grid/grid-visualizer.js.map +1 -0
- package/build-module/components/grid/index.js +5 -0
- package/build-module/components/grid/index.js.map +1 -0
- package/build-module/components/grid/use-get-number-of-blocks-before-cell.js +33 -0
- package/build-module/components/grid/use-get-number-of-blocks-before-cell.js.map +1 -0
- package/build-module/components/grid/use-grid-layout-sync.js +162 -0
- package/build-module/components/grid/use-grid-layout-sync.js.map +1 -0
- package/build-module/components/grid/utils.js +131 -0
- package/build-module/components/grid/utils.js.map +1 -0
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +0 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +1 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +1 -19
- package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
- package/build-module/components/inserter/menu.js +26 -4
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +2 -1
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -2
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +1 -1
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +19 -23
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +3 -1
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/rich-text/event-listeners/input-rules.js +1 -1
- package/build-module/components/rich-text/event-listeners/input-rules.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +11 -5
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +14 -0
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +5 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/tabbed-sidebar/index.js +60 -0
- package/build-module/components/tabbed-sidebar/index.js.map +1 -0
- package/build-module/components/url-popover/index.js +3 -0
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/hooks/background.js +26 -4
- package/build-module/hooks/background.js.map +1 -1
- package/build-module/hooks/block-hooks.js +11 -17
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/block-style-variation.js +193 -11
- package/build-module/hooks/block-style-variation.js.map +1 -1
- package/build-module/hooks/duotone.js +16 -11
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/grid-visualizer.js +64 -0
- package/build-module/hooks/grid-visualizer.js.map +1 -0
- package/build-module/hooks/index.js +3 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout-child.js +63 -38
- package/build-module/hooks/layout-child.js.map +1 -1
- package/build-module/hooks/position.js +2 -9
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +16 -6
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/hooks/utils.js +5 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/constrained.js +44 -2
- package/build-module/layouts/constrained.js.map +1 -1
- package/build-module/layouts/grid.js +92 -76
- package/build-module/layouts/grid.js.map +1 -1
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +8 -3
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +17 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +0 -2
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/defaults.native.js +0 -3
- package/build-module/store/defaults.native.js.map +1 -1
- package/build-module/store/private-keys.js +1 -0
- package/build-module/store/private-keys.js.map +1 -1
- package/build-module/utils/format-font-style.js +39 -0
- package/build-module/utils/format-font-style.js.map +1 -0
- package/build-module/utils/format-font-weight.js +62 -0
- package/build-module/utils/format-font-weight.js.map +1 -0
- package/build-module/utils/get-editor-region.js +28 -0
- package/build-module/utils/get-editor-region.js.map +1 -0
- package/build-module/utils/get-font-styles-and-weights.js +160 -0
- package/build-module/utils/get-font-styles-and-weights.js.map +1 -0
- package/build-module/utils/pasting.js +5 -13
- package/build-module/utils/pasting.js.map +1 -1
- package/build-style/content-rtl.css +1 -0
- package/build-style/content.css +1 -0
- package/build-style/style-rtl.css +238 -106
- package/build-style/style.css +238 -106
- package/package.json +32 -32
- package/src/components/block-breadcrumb/index.js +16 -1
- package/src/components/block-lock/modal.js +95 -82
- package/src/components/block-lock/style.scss +11 -1
- package/src/components/block-lock/toolbar.js +0 -1
- package/src/components/block-mover/button.js +1 -1
- package/src/components/block-mover/index.js +37 -24
- package/src/components/block-pattern-setup/setup-toolbar.js +2 -2
- package/src/components/block-patterns-paging/index.js +8 -11
- package/src/components/block-patterns-paging/style.scss +18 -0
- package/src/components/block-quick-navigation/index.js +21 -28
- package/src/components/block-rename/modal.js +2 -8
- package/src/components/block-switcher/test/index.js +6 -6
- package/src/components/block-toolbar/shuffle.js +4 -1
- package/src/components/block-toolbar/style.scss +1 -11
- package/src/components/block-tools/block-selection-button.js +11 -83
- package/src/components/block-tools/block-toolbar-breadcrumb.js +9 -4
- package/src/components/block-tools/index.js +21 -1
- package/src/components/block-tools/style.scss +15 -0
- package/src/components/block-tools/use-show-block-tools.js +14 -6
- package/src/components/block-tools/zoom-out-mode-inserters.js +5 -4
- package/src/components/block-tools/zoom-out-popover.js +49 -0
- package/src/components/block-tools/zoom-out-toolbar.js +140 -0
- package/src/components/button-block-appender/index.js +2 -1
- package/src/components/child-layout-control/index.js +243 -160
- package/src/components/date-format-picker/index.js +10 -1
- package/src/components/date-format-picker/style.scss +0 -9
- package/src/components/dimensions-tool/index.js +97 -89
- package/src/components/font-appearance-control/index.js +29 -83
- package/src/components/font-appearance-control/style.scss +3 -5
- package/src/components/global-styles/background-panel.js +249 -170
- package/src/components/global-styles/border-panel.js +3 -2
- package/src/components/global-styles/color-panel.js +3 -2
- package/src/components/global-styles/dimensions-panel.js +3 -2
- package/src/components/global-styles/filters-panel.js +3 -2
- package/src/components/global-styles/hooks.js +9 -0
- package/src/components/global-styles/image-settings-panel.js +3 -2
- package/src/components/global-styles/style.scss +105 -20
- package/src/components/global-styles/test/typography-utils.js +269 -0
- package/src/components/global-styles/test/use-global-styles-output.js +38 -3
- package/src/components/global-styles/typography-panel.js +49 -12
- package/src/components/global-styles/typography-utils.js +63 -0
- package/src/components/global-styles/use-global-styles-output.js +25 -9
- package/src/components/global-styles/utils.js +17 -6
- package/src/components/grid/grid-item-movers.js +112 -0
- package/src/components/{grid-visualizer → grid}/grid-item-resizer.js +15 -52
- package/src/components/grid/grid-visualizer.js +384 -0
- package/src/components/grid/index.js +4 -0
- package/src/components/grid/style.scss +98 -0
- package/src/components/grid/use-get-number-of-blocks-before-cell.js +30 -0
- package/src/components/grid/use-grid-layout-sync.js +170 -0
- package/src/components/grid/utils.js +178 -0
- package/src/components/iframe/content.scss +1 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +0 -1
- package/src/components/inner-blocks/index.js +4 -1
- package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +1 -16
- package/src/components/inserter/menu.js +47 -13
- package/src/components/inserter/quick-inserter.js +6 -1
- package/src/components/inserter/style.scss +1 -49
- package/src/components/inspector-controls/block-support-tools-panel.js +3 -3
- package/src/components/link-control/link-preview.js +1 -1
- package/src/components/media-placeholder/index.js +22 -32
- package/src/components/navigable-toolbar/index.js +3 -1
- package/src/components/rich-text/event-listeners/input-rules.js +1 -1
- package/src/components/rich-text/index.native.js +10 -8
- package/src/components/rich-text/native/index.native.js +17 -0
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +6 -1
- package/src/components/tabbed-sidebar/README.md +76 -0
- package/src/components/tabbed-sidebar/index.js +70 -0
- package/src/components/tabbed-sidebar/style.scss +53 -0
- package/src/components/url-popover/index.js +3 -0
- package/src/hooks/background.js +25 -10
- package/src/hooks/block-hooks.js +9 -16
- package/src/hooks/block-style-variation.js +226 -9
- package/src/hooks/duotone.js +16 -12
- package/src/hooks/grid-visualizer.js +64 -0
- package/src/hooks/index.js +3 -0
- package/src/hooks/layout-child.js +75 -39
- package/src/hooks/position.js +3 -10
- package/src/hooks/test/get-variation-styles-with-ref-values.js +91 -0
- package/src/hooks/use-bindings-attributes.js +18 -4
- package/src/hooks/utils.js +5 -1
- package/src/layouts/constrained.js +43 -2
- package/src/layouts/grid.js +175 -88
- package/src/lock-unlock.js +1 -1
- package/src/private-apis.js +12 -1
- package/src/store/actions.js +21 -1
- package/src/store/defaults.js +0 -2
- package/src/store/defaults.native.js +0 -3
- package/src/store/private-keys.js +1 -0
- package/src/style.scss +2 -2
- package/src/utils/format-font-style.js +40 -0
- package/src/utils/format-font-weight.js +63 -0
- package/src/utils/get-editor-region.js +31 -0
- package/src/utils/get-font-styles-and-weights.js +191 -0
- package/src/utils/pasting.js +5 -12
- package/src/utils/test/format-font-style.js +34 -0
- package/src/utils/test/format-font-weight.js +66 -0
- package/src/utils/test/get-font-styles-and-weights.js +513 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/grid-visualizer/grid-item-resizer.js.map +0 -1
- package/build/components/grid-visualizer/grid-visualizer.js +0 -92
- package/build/components/grid-visualizer/grid-visualizer.js.map +0 -1
- package/build/components/grid-visualizer/index.js.map +0 -1
- package/build/components/grid-visualizer/utils.js +0 -10
- package/build/components/grid-visualizer/utils.js.map +0 -1
- package/build-module/components/grid-visualizer/grid-item-resizer.js.map +0 -1
- package/build-module/components/grid-visualizer/grid-visualizer.js +0 -84
- package/build-module/components/grid-visualizer/grid-visualizer.js.map +0 -1
- package/build-module/components/grid-visualizer/index.js +0 -3
- package/build-module/components/grid-visualizer/index.js.map +0 -1
- package/build-module/components/grid-visualizer/utils.js +0 -4
- package/build-module/components/grid-visualizer/utils.js.map +0 -1
- package/src/components/grid-visualizer/grid-visualizer.js +0 -101
- package/src/components/grid-visualizer/index.js +0 -2
- package/src/components/grid-visualizer/style.scss +0 -34
- package/src/components/grid-visualizer/utils.js +0 -5
- package/src/hooks/position.scss +0 -18
- /package/src/components/font-sizes/{README.MD → README.md} +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useState, useEffect, forwardRef, useMemo } from '@wordpress/element';
|
|
10
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
+
import { __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
|
|
17
|
+
import BlockPopoverCover from '../block-popover/cover';
|
|
18
|
+
import { range, GridRect, getGridInfo } from './utils';
|
|
19
|
+
import { store as blockEditorStore } from '../../store';
|
|
20
|
+
import { useGetNumberOfBlocksBeforeCell } from './use-get-number-of-blocks-before-cell';
|
|
21
|
+
import ButtonBlockAppender from '../button-block-appender';
|
|
22
|
+
|
|
23
|
+
export function GridVisualizer( { clientId, contentRef, parentLayout } ) {
|
|
24
|
+
const isDistractionFree = useSelect(
|
|
25
|
+
( select ) =>
|
|
26
|
+
select( blockEditorStore ).getSettings().isDistractionFree,
|
|
27
|
+
[]
|
|
28
|
+
);
|
|
29
|
+
const gridElement = useBlockElement( clientId );
|
|
30
|
+
|
|
31
|
+
if ( isDistractionFree || ! gridElement ) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isManualGrid =
|
|
36
|
+
parentLayout?.isManualPlacement &&
|
|
37
|
+
window.__experimentalEnableGridInteractivity;
|
|
38
|
+
return (
|
|
39
|
+
<GridVisualizerGrid
|
|
40
|
+
gridClientId={ clientId }
|
|
41
|
+
gridElement={ gridElement }
|
|
42
|
+
isManualGrid={ isManualGrid }
|
|
43
|
+
ref={ contentRef }
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const GridVisualizerGrid = forwardRef(
|
|
49
|
+
( { gridClientId, gridElement, isManualGrid }, ref ) => {
|
|
50
|
+
const [ gridInfo, setGridInfo ] = useState( () =>
|
|
51
|
+
getGridInfo( gridElement )
|
|
52
|
+
);
|
|
53
|
+
const [ isDroppingAllowed, setIsDroppingAllowed ] = useState( false );
|
|
54
|
+
|
|
55
|
+
useEffect( () => {
|
|
56
|
+
const observers = [];
|
|
57
|
+
for ( const element of [ gridElement, ...gridElement.children ] ) {
|
|
58
|
+
const observer = new window.ResizeObserver( () => {
|
|
59
|
+
setGridInfo( getGridInfo( gridElement ) );
|
|
60
|
+
} );
|
|
61
|
+
observer.observe( element );
|
|
62
|
+
observers.push( observer );
|
|
63
|
+
}
|
|
64
|
+
return () => {
|
|
65
|
+
for ( const observer of observers ) {
|
|
66
|
+
observer.disconnect();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, [ gridElement ] );
|
|
70
|
+
|
|
71
|
+
useEffect( () => {
|
|
72
|
+
function onGlobalDrag() {
|
|
73
|
+
setIsDroppingAllowed( true );
|
|
74
|
+
}
|
|
75
|
+
function onGlobalDragEnd() {
|
|
76
|
+
setIsDroppingAllowed( false );
|
|
77
|
+
}
|
|
78
|
+
document.addEventListener( 'drag', onGlobalDrag );
|
|
79
|
+
document.addEventListener( 'dragend', onGlobalDragEnd );
|
|
80
|
+
return () => {
|
|
81
|
+
document.removeEventListener( 'drag', onGlobalDrag );
|
|
82
|
+
document.removeEventListener( 'dragend', onGlobalDragEnd );
|
|
83
|
+
};
|
|
84
|
+
}, [] );
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<BlockPopoverCover
|
|
88
|
+
className={ clsx( 'block-editor-grid-visualizer', {
|
|
89
|
+
'is-dropping-allowed': isDroppingAllowed,
|
|
90
|
+
} ) }
|
|
91
|
+
clientId={ gridClientId }
|
|
92
|
+
__unstablePopoverSlot="block-toolbar"
|
|
93
|
+
>
|
|
94
|
+
<div
|
|
95
|
+
ref={ ref }
|
|
96
|
+
className="block-editor-grid-visualizer__grid"
|
|
97
|
+
style={ gridInfo.style }
|
|
98
|
+
>
|
|
99
|
+
{ isManualGrid ? (
|
|
100
|
+
<ManualGridVisualizer
|
|
101
|
+
gridClientId={ gridClientId }
|
|
102
|
+
gridInfo={ gridInfo }
|
|
103
|
+
/>
|
|
104
|
+
) : (
|
|
105
|
+
Array.from( { length: gridInfo.numItems }, ( _, i ) => (
|
|
106
|
+
<GridVisualizerCell
|
|
107
|
+
key={ i }
|
|
108
|
+
color={ gridInfo.currentColor }
|
|
109
|
+
/>
|
|
110
|
+
) )
|
|
111
|
+
) }
|
|
112
|
+
</div>
|
|
113
|
+
</BlockPopoverCover>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
function ManualGridVisualizer( { gridClientId, gridInfo } ) {
|
|
119
|
+
const [ highlightedRect, setHighlightedRect ] = useState( null );
|
|
120
|
+
|
|
121
|
+
const gridItems = useSelect(
|
|
122
|
+
( select ) => select( blockEditorStore ).getBlocks( gridClientId ),
|
|
123
|
+
[ gridClientId ]
|
|
124
|
+
);
|
|
125
|
+
const occupiedRects = useMemo( () => {
|
|
126
|
+
const rects = [];
|
|
127
|
+
for ( const block of gridItems ) {
|
|
128
|
+
const {
|
|
129
|
+
columnStart,
|
|
130
|
+
rowStart,
|
|
131
|
+
columnSpan = 1,
|
|
132
|
+
rowSpan = 1,
|
|
133
|
+
} = block.attributes.style?.layout || {};
|
|
134
|
+
if ( ! columnStart || ! rowStart ) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
rects.push(
|
|
138
|
+
new GridRect( {
|
|
139
|
+
columnStart,
|
|
140
|
+
rowStart,
|
|
141
|
+
columnSpan,
|
|
142
|
+
rowSpan,
|
|
143
|
+
} )
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return rects;
|
|
147
|
+
}, [ gridItems ] );
|
|
148
|
+
|
|
149
|
+
return range( 1, gridInfo.numRows ).map( ( row ) =>
|
|
150
|
+
range( 1, gridInfo.numColumns ).map( ( column ) => {
|
|
151
|
+
const isCellOccupied = occupiedRects.some( ( rect ) =>
|
|
152
|
+
rect.contains( column, row )
|
|
153
|
+
);
|
|
154
|
+
const isHighlighted =
|
|
155
|
+
highlightedRect?.contains( column, row ) ?? false;
|
|
156
|
+
return (
|
|
157
|
+
<GridVisualizerCell
|
|
158
|
+
key={ `${ row }-${ column }` }
|
|
159
|
+
color={ gridInfo.currentColor }
|
|
160
|
+
className={ isHighlighted && 'is-highlighted' }
|
|
161
|
+
>
|
|
162
|
+
{ isCellOccupied ? (
|
|
163
|
+
<GridVisualizerDropZone
|
|
164
|
+
column={ column }
|
|
165
|
+
row={ row }
|
|
166
|
+
gridClientId={ gridClientId }
|
|
167
|
+
gridInfo={ gridInfo }
|
|
168
|
+
setHighlightedRect={ setHighlightedRect }
|
|
169
|
+
/>
|
|
170
|
+
) : (
|
|
171
|
+
<GridVisualizerAppender
|
|
172
|
+
column={ column }
|
|
173
|
+
row={ row }
|
|
174
|
+
gridClientId={ gridClientId }
|
|
175
|
+
gridInfo={ gridInfo }
|
|
176
|
+
setHighlightedRect={ setHighlightedRect }
|
|
177
|
+
/>
|
|
178
|
+
) }
|
|
179
|
+
</GridVisualizerCell>
|
|
180
|
+
);
|
|
181
|
+
} )
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function GridVisualizerCell( { color, children, className } ) {
|
|
186
|
+
return (
|
|
187
|
+
<div
|
|
188
|
+
className={ clsx(
|
|
189
|
+
'block-editor-grid-visualizer__cell',
|
|
190
|
+
className
|
|
191
|
+
) }
|
|
192
|
+
style={ {
|
|
193
|
+
boxShadow: `inset 0 0 0 1px color-mix(in srgb, ${ color } 20%, #0000)`,
|
|
194
|
+
color,
|
|
195
|
+
} }
|
|
196
|
+
>
|
|
197
|
+
{ children }
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function useGridVisualizerDropZone(
|
|
203
|
+
column,
|
|
204
|
+
row,
|
|
205
|
+
gridClientId,
|
|
206
|
+
gridInfo,
|
|
207
|
+
setHighlightedRect
|
|
208
|
+
) {
|
|
209
|
+
const { getBlockAttributes, getBlockRootClientId } =
|
|
210
|
+
useSelect( blockEditorStore );
|
|
211
|
+
const {
|
|
212
|
+
updateBlockAttributes,
|
|
213
|
+
moveBlocksToPosition,
|
|
214
|
+
__unstableMarkNextChangeAsNotPersistent,
|
|
215
|
+
} = useDispatch( blockEditorStore );
|
|
216
|
+
|
|
217
|
+
const getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(
|
|
218
|
+
gridClientId,
|
|
219
|
+
gridInfo.numColumns
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
return useDropZoneWithValidation( {
|
|
223
|
+
validateDrag( srcClientId ) {
|
|
224
|
+
const attributes = getBlockAttributes( srcClientId );
|
|
225
|
+
const rect = new GridRect( {
|
|
226
|
+
columnStart: column,
|
|
227
|
+
rowStart: row,
|
|
228
|
+
columnSpan: attributes.style?.layout?.columnSpan,
|
|
229
|
+
rowSpan: attributes.style?.layout?.rowSpan,
|
|
230
|
+
} );
|
|
231
|
+
const isInBounds = new GridRect( {
|
|
232
|
+
columnSpan: gridInfo.numColumns,
|
|
233
|
+
rowSpan: gridInfo.numRows,
|
|
234
|
+
} ).containsRect( rect );
|
|
235
|
+
return isInBounds;
|
|
236
|
+
},
|
|
237
|
+
onDragEnter( srcClientId ) {
|
|
238
|
+
const attributes = getBlockAttributes( srcClientId );
|
|
239
|
+
setHighlightedRect(
|
|
240
|
+
new GridRect( {
|
|
241
|
+
columnStart: column,
|
|
242
|
+
rowStart: row,
|
|
243
|
+
columnSpan: attributes.style?.layout?.columnSpan,
|
|
244
|
+
rowSpan: attributes.style?.layout?.rowSpan,
|
|
245
|
+
} )
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
onDragLeave() {
|
|
249
|
+
// onDragEnter can be called before onDragLeave if the user moves
|
|
250
|
+
// their mouse quickly, so only clear the highlight if it was set
|
|
251
|
+
// by this cell.
|
|
252
|
+
setHighlightedRect( ( prevHighlightedRect ) =>
|
|
253
|
+
prevHighlightedRect?.columnStart === column &&
|
|
254
|
+
prevHighlightedRect?.rowStart === row
|
|
255
|
+
? null
|
|
256
|
+
: prevHighlightedRect
|
|
257
|
+
);
|
|
258
|
+
},
|
|
259
|
+
onDrop( srcClientId ) {
|
|
260
|
+
setHighlightedRect( null );
|
|
261
|
+
const attributes = getBlockAttributes( srcClientId );
|
|
262
|
+
updateBlockAttributes( srcClientId, {
|
|
263
|
+
style: {
|
|
264
|
+
...attributes.style,
|
|
265
|
+
layout: {
|
|
266
|
+
...attributes.style?.layout,
|
|
267
|
+
columnStart: column,
|
|
268
|
+
rowStart: row,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
} );
|
|
272
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
273
|
+
moveBlocksToPosition(
|
|
274
|
+
[ srcClientId ],
|
|
275
|
+
getBlockRootClientId( srcClientId ),
|
|
276
|
+
gridClientId,
|
|
277
|
+
getNumberOfBlocksBeforeCell( column, row )
|
|
278
|
+
);
|
|
279
|
+
},
|
|
280
|
+
} );
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function GridVisualizerDropZone( {
|
|
284
|
+
column,
|
|
285
|
+
row,
|
|
286
|
+
gridClientId,
|
|
287
|
+
gridInfo,
|
|
288
|
+
setHighlightedRect,
|
|
289
|
+
} ) {
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
className="block-editor-grid-visualizer__drop-zone"
|
|
293
|
+
ref={ useGridVisualizerDropZone(
|
|
294
|
+
column,
|
|
295
|
+
row,
|
|
296
|
+
gridClientId,
|
|
297
|
+
gridInfo,
|
|
298
|
+
setHighlightedRect
|
|
299
|
+
) }
|
|
300
|
+
/>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function GridVisualizerAppender( {
|
|
305
|
+
column,
|
|
306
|
+
row,
|
|
307
|
+
gridClientId,
|
|
308
|
+
gridInfo,
|
|
309
|
+
setHighlightedRect,
|
|
310
|
+
} ) {
|
|
311
|
+
const {
|
|
312
|
+
updateBlockAttributes,
|
|
313
|
+
moveBlocksToPosition,
|
|
314
|
+
__unstableMarkNextChangeAsNotPersistent,
|
|
315
|
+
} = useDispatch( blockEditorStore );
|
|
316
|
+
|
|
317
|
+
const getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(
|
|
318
|
+
gridClientId,
|
|
319
|
+
gridInfo.numColumns
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<ButtonBlockAppender
|
|
324
|
+
rootClientId={ gridClientId }
|
|
325
|
+
className="block-editor-grid-visualizer__appender"
|
|
326
|
+
ref={ useGridVisualizerDropZone(
|
|
327
|
+
column,
|
|
328
|
+
row,
|
|
329
|
+
gridClientId,
|
|
330
|
+
gridInfo,
|
|
331
|
+
setHighlightedRect
|
|
332
|
+
) }
|
|
333
|
+
style={ {
|
|
334
|
+
color: gridInfo.currentColor,
|
|
335
|
+
} }
|
|
336
|
+
onSelect={ ( block ) => {
|
|
337
|
+
if ( ! block ) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
updateBlockAttributes( block.clientId, {
|
|
341
|
+
style: {
|
|
342
|
+
layout: {
|
|
343
|
+
columnStart: column,
|
|
344
|
+
rowStart: row,
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
} );
|
|
348
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
349
|
+
moveBlocksToPosition(
|
|
350
|
+
[ block.clientId ],
|
|
351
|
+
gridClientId,
|
|
352
|
+
gridClientId,
|
|
353
|
+
getNumberOfBlocksBeforeCell( column, row )
|
|
354
|
+
);
|
|
355
|
+
} }
|
|
356
|
+
/>
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function useDropZoneWithValidation( {
|
|
361
|
+
validateDrag,
|
|
362
|
+
onDragEnter,
|
|
363
|
+
onDragLeave,
|
|
364
|
+
onDrop,
|
|
365
|
+
} ) {
|
|
366
|
+
const { getDraggedBlockClientIds } = useSelect( blockEditorStore );
|
|
367
|
+
return useDropZone( {
|
|
368
|
+
onDragEnter() {
|
|
369
|
+
const [ srcClientId ] = getDraggedBlockClientIds();
|
|
370
|
+
if ( srcClientId && validateDrag( srcClientId ) ) {
|
|
371
|
+
onDragEnter( srcClientId );
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
onDragLeave() {
|
|
375
|
+
onDragLeave();
|
|
376
|
+
},
|
|
377
|
+
onDrop() {
|
|
378
|
+
const [ srcClientId ] = getDraggedBlockClientIds();
|
|
379
|
+
if ( srcClientId && validateDrag( srcClientId ) ) {
|
|
380
|
+
onDrop( srcClientId );
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
} );
|
|
384
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
.block-editor-grid-visualizer {
|
|
2
|
+
// Specificity to override the z-index and pointer-events set by .components-popover.
|
|
3
|
+
&.block-editor-grid-visualizer.block-editor-grid-visualizer {
|
|
4
|
+
z-index: z-index(".block-editor-grid-visualizer");
|
|
5
|
+
|
|
6
|
+
.components-popover__content * {
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&.is-dropping-allowed {
|
|
11
|
+
.block-editor-grid-visualizer__drop-zone {
|
|
12
|
+
pointer-events: all;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
.block-editor-inserter * {
|
|
16
|
+
pointer-events: auto;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.block-editor-grid-visualizer__grid {
|
|
22
|
+
display: grid;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.block-editor-grid-visualizer__cell {
|
|
26
|
+
display: grid;
|
|
27
|
+
position: relative;
|
|
28
|
+
|
|
29
|
+
.block-editor-inserter {
|
|
30
|
+
color: inherit;
|
|
31
|
+
z-index: 32;
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 0;
|
|
34
|
+
bottom: 0;
|
|
35
|
+
left: 0;
|
|
36
|
+
right: 0;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
|
|
39
|
+
.block-editor-grid-visualizer__appender {
|
|
40
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 20%, #0000);
|
|
41
|
+
color: inherit;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
height: 100%;
|
|
44
|
+
width: 100%;
|
|
45
|
+
padding: 0 !important;
|
|
46
|
+
opacity: 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&.is-highlighted {
|
|
52
|
+
.block-editor-inserter,
|
|
53
|
+
.block-editor-grid-visualizer__drop-zone {
|
|
54
|
+
background: var(--wp-admin-theme-color);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:hover .block-editor-grid-visualizer__appender,
|
|
59
|
+
.block-editor-grid-visualizer__appender:focus {
|
|
60
|
+
opacity: 1;
|
|
61
|
+
background-color: color-mix(in srgb, currentColor 20%, #0000);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.block-editor-grid-visualizer__drop-zone {
|
|
66
|
+
background: rgba($gray-400, 0.1);
|
|
67
|
+
width: 100%;
|
|
68
|
+
height: 100%;
|
|
69
|
+
grid-column: 1;
|
|
70
|
+
grid-row: 1;
|
|
71
|
+
|
|
72
|
+
// Make drop zone 8x8 at minimum so that it's easier to drag into. This will overflow the parent.
|
|
73
|
+
min-width: $grid-unit-10;
|
|
74
|
+
min-height: $grid-unit-10;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.block-editor-grid-item-resizer {
|
|
78
|
+
// Specificity to override the z-index and pointer-events set by .components-popover.
|
|
79
|
+
&.block-editor-grid-item-resizer.block-editor-grid-item-resizer {
|
|
80
|
+
z-index: z-index(".block-editor-grid-visualizer");
|
|
81
|
+
|
|
82
|
+
.components-popover__content * {
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.block-editor-grid-item-resizer__box {
|
|
89
|
+
border: $border-width solid var(--wp-admin-theme-color);
|
|
90
|
+
|
|
91
|
+
.components-resizable-box__handle {
|
|
92
|
+
// Specificity to override the pointer-events set by .components-popover.
|
|
93
|
+
&.components-resizable-box__handle.components-resizable-box__handle {
|
|
94
|
+
pointer-events: all;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { store as blockEditorStore } from '../../store';
|
|
10
|
+
|
|
11
|
+
export function useGetNumberOfBlocksBeforeCell( gridClientId, numColumns ) {
|
|
12
|
+
const { getBlockOrder, getBlockAttributes } = useSelect( blockEditorStore );
|
|
13
|
+
|
|
14
|
+
const getNumberOfBlocksBeforeCell = ( column, row ) => {
|
|
15
|
+
const targetIndex = ( row - 1 ) * numColumns + column - 1;
|
|
16
|
+
|
|
17
|
+
let count = 0;
|
|
18
|
+
for ( const clientId of getBlockOrder( gridClientId ) ) {
|
|
19
|
+
const { columnStart, rowStart } =
|
|
20
|
+
getBlockAttributes( clientId ).style?.layout ?? {};
|
|
21
|
+
const cellIndex = ( rowStart - 1 ) * numColumns + columnStart - 1;
|
|
22
|
+
if ( cellIndex < targetIndex ) {
|
|
23
|
+
count++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return count;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return getNumberOfBlocksBeforeCell;
|
|
30
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
+
import { useEffect } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
import { GridRect } from './utils';
|
|
12
|
+
|
|
13
|
+
export function useGridLayoutSync( { clientId: gridClientId } ) {
|
|
14
|
+
const { gridLayout, blockOrder } = useSelect(
|
|
15
|
+
( select ) => {
|
|
16
|
+
const { getBlockAttributes, getBlockOrder } =
|
|
17
|
+
select( blockEditorStore );
|
|
18
|
+
return {
|
|
19
|
+
gridLayout: getBlockAttributes( gridClientId ).layout ?? {},
|
|
20
|
+
blockOrder: getBlockOrder( gridClientId ),
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
[ gridClientId ]
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const { getBlockAttributes } = useSelect( blockEditorStore );
|
|
27
|
+
const { updateBlockAttributes, __unstableMarkNextChangeAsNotPersistent } =
|
|
28
|
+
useDispatch( blockEditorStore );
|
|
29
|
+
|
|
30
|
+
useEffect( () => {
|
|
31
|
+
const updates = {};
|
|
32
|
+
|
|
33
|
+
const { columnCount, rowCount, isManualPlacement } = gridLayout;
|
|
34
|
+
|
|
35
|
+
if ( isManualPlacement ) {
|
|
36
|
+
const rects = [];
|
|
37
|
+
|
|
38
|
+
// Respect the position of blocks that already have a columnStart and rowStart value.
|
|
39
|
+
for ( const clientId of blockOrder ) {
|
|
40
|
+
const attributes = getBlockAttributes( clientId );
|
|
41
|
+
const {
|
|
42
|
+
columnStart,
|
|
43
|
+
rowStart,
|
|
44
|
+
columnSpan = 1,
|
|
45
|
+
rowSpan = 1,
|
|
46
|
+
} = attributes.style?.layout || {};
|
|
47
|
+
if ( ! columnStart || ! rowStart ) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
rects.push(
|
|
51
|
+
new GridRect( {
|
|
52
|
+
columnStart,
|
|
53
|
+
rowStart,
|
|
54
|
+
columnSpan,
|
|
55
|
+
rowSpan,
|
|
56
|
+
} )
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// When in manual mode, ensure that every block has a columnStart and rowStart value.
|
|
61
|
+
for ( const clientId of blockOrder ) {
|
|
62
|
+
const attributes = getBlockAttributes( clientId );
|
|
63
|
+
const {
|
|
64
|
+
columnStart,
|
|
65
|
+
rowStart,
|
|
66
|
+
columnSpan = 1,
|
|
67
|
+
rowSpan = 1,
|
|
68
|
+
} = attributes.style?.layout || {};
|
|
69
|
+
if ( columnStart && rowStart ) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const [ newColumnStart, newRowStart ] = getFirstEmptyCell(
|
|
73
|
+
rects,
|
|
74
|
+
columnCount,
|
|
75
|
+
columnSpan,
|
|
76
|
+
rowSpan
|
|
77
|
+
);
|
|
78
|
+
rects.push(
|
|
79
|
+
new GridRect( {
|
|
80
|
+
columnStart: newColumnStart,
|
|
81
|
+
rowStart: newRowStart,
|
|
82
|
+
columnSpan,
|
|
83
|
+
rowSpan,
|
|
84
|
+
} )
|
|
85
|
+
);
|
|
86
|
+
updates[ clientId ] = {
|
|
87
|
+
style: {
|
|
88
|
+
...attributes.style,
|
|
89
|
+
layout: {
|
|
90
|
+
...attributes.style?.layout,
|
|
91
|
+
columnStart: newColumnStart,
|
|
92
|
+
rowStart: newRowStart,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Ensure there's enough rows to fit all blocks.
|
|
99
|
+
const bottomMostRow = Math.max( ...rects.map( ( r ) => r.rowEnd ) );
|
|
100
|
+
if ( ! rowCount || rowCount < bottomMostRow ) {
|
|
101
|
+
updates[ gridClientId ] = {
|
|
102
|
+
layout: {
|
|
103
|
+
...gridLayout,
|
|
104
|
+
rowCount: bottomMostRow,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
// When in auto mode, remove all of the columnStart and rowStart values.
|
|
110
|
+
for ( const clientId of blockOrder ) {
|
|
111
|
+
const attributes = getBlockAttributes( clientId );
|
|
112
|
+
const { columnStart, rowStart, ...layout } =
|
|
113
|
+
attributes.style?.layout || {};
|
|
114
|
+
// Only update attributes if columnStart or rowStart are set.
|
|
115
|
+
if ( columnStart || rowStart ) {
|
|
116
|
+
updates[ clientId ] = {
|
|
117
|
+
style: {
|
|
118
|
+
...attributes.style,
|
|
119
|
+
layout,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Remove row styles in auto mode
|
|
126
|
+
if ( rowCount ) {
|
|
127
|
+
updates[ gridClientId ] = {
|
|
128
|
+
layout: {
|
|
129
|
+
...gridLayout,
|
|
130
|
+
rowCount: undefined,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if ( Object.keys( updates ).length ) {
|
|
137
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
138
|
+
updateBlockAttributes(
|
|
139
|
+
Object.keys( updates ),
|
|
140
|
+
updates,
|
|
141
|
+
/* uniqueByBlock: */ true
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}, [
|
|
145
|
+
// Actual deps to sync:
|
|
146
|
+
gridClientId,
|
|
147
|
+
gridLayout,
|
|
148
|
+
blockOrder,
|
|
149
|
+
// Needed for linter:
|
|
150
|
+
__unstableMarkNextChangeAsNotPersistent,
|
|
151
|
+
getBlockAttributes,
|
|
152
|
+
updateBlockAttributes,
|
|
153
|
+
] );
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getFirstEmptyCell( rects, columnCount, columnSpan = 1, rowSpan = 1 ) {
|
|
157
|
+
for ( let row = 1; ; row++ ) {
|
|
158
|
+
for ( let column = 1; column <= columnCount; column++ ) {
|
|
159
|
+
const rect = new GridRect( {
|
|
160
|
+
columnStart: column,
|
|
161
|
+
rowStart: row,
|
|
162
|
+
columnSpan,
|
|
163
|
+
rowSpan,
|
|
164
|
+
} );
|
|
165
|
+
if ( ! rects.some( ( r ) => r.intersectsRect( rect ) ) ) {
|
|
166
|
+
return [ column, row ];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|