@wordpress/block-editor 8.5.7 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +5 -2
- package/build/components/block-alignment-control/constants.js +48 -0
- package/build/components/block-alignment-control/constants.js.map +1 -0
- package/build/components/block-alignment-control/ui.js +9 -40
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-alignment-control/ui.native.js +92 -0
- package/build/components/block-alignment-control/ui.native.js.map +1 -0
- package/build/components/block-alignment-matrix-control/index.js +1 -6
- package/build/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build/components/block-content-overlay/index.js +5 -74
- package/build/components/block-content-overlay/index.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.native.js +64 -0
- package/build/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js +157 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build/components/block-draggable/index.native.js +484 -0
- package/build/components/block-draggable/index.native.js.map +1 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js +130 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build/components/block-list/block-list-context.native.js +195 -0
- package/build/components/block-list/block-list-context.native.js.map +1 -0
- package/build/components/block-list/block-list-item-cell.native.js +67 -0
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build/components/block-list/block-list-item.native.js +12 -9
- package/build/components/block-list/block-list-item.native.js.map +1 -1
- package/build/components/block-list/block.native.js +29 -6
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +75 -23
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +8 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-class-names.js +1 -7
- package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +34 -4
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +2 -1
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-lock/use-block-lock.js +4 -1
- package/build/components/block-lock/use-block-lock.js.map +1 -1
- package/build/components/block-mobile-toolbar/index.native.js +9 -3
- package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build/components/block-mover/button.js +4 -4
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +39 -65
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-mover/index.native.js +17 -4
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +11 -5
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-popover/inbetween.js +191 -0
- package/build/components/block-popover/inbetween.js.map +1 -0
- package/build/components/block-popover/index.js +85 -0
- package/build/components/block-popover/index.js.map +1 -0
- package/build/components/{block-tools → block-popover}/use-popover-scroll.js +4 -1
- package/build/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build/components/block-preview/index.js +1 -1
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-styles/index.js +1 -10
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -2
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +4 -2
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +5 -5
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +14 -121
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +216 -0
- package/build/components/block-tools/selected-block-popover.js.map +1 -0
- package/build/components/border-radius-control/input-controls.js +10 -3
- package/build/components/border-radius-control/input-controls.js.map +1 -1
- package/build/components/color-style-selector/index.js +9 -0
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +149 -44
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/duotone-control/index.js +5 -1
- package/build/components/duotone-control/index.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +3 -1
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/index.js +5 -23
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/index.native.js +31 -9
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/link-control/constants.js +11 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/search-results.js +4 -3
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/use-search-handler.js +4 -4
- package/build/components/link-control/use-search-handler.js.map +1 -1
- package/build/components/list-view/block.js +15 -15
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +9 -13
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/context.js +1 -4
- package/build/components/list-view/context.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +0 -1
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +15 -32
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +12 -2
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +0 -1
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +1 -6
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +0 -4
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/url-input/index.js +11 -4
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-display-information/index.js +3 -1
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.native.js +167 -0
- package/build/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build/components/use-on-block-drop/index.native.js +95 -0
- package/build/components/use-on-block-drop/index.native.js.map +1 -0
- package/build/components/use-setting/index.js +42 -18
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +463 -44
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +14 -7
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/dimensions.js +2 -2
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/index.js +3 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/margin.js +64 -12
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +60 -12
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/settings.js +32 -0
- package/build/hooks/settings.js.map +1 -0
- package/build/hooks/style.js +14 -13
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +6 -2
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-border-props.js +22 -32
- package/build/hooks/use-border-props.js.map +1 -1
- package/build/store/actions.js +14 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +0 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +0 -26
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +47 -15
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-alignment-control/constants.js +36 -0
- package/build-module/components/block-alignment-control/constants.js.map +1 -0
- package/build-module/components/block-alignment-control/ui.js +4 -35
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-alignment-control/ui.native.js +78 -0
- package/build-module/components/block-alignment-control/ui.native.js.map +1 -0
- package/build-module/components/block-alignment-matrix-control/index.js +1 -6
- package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build-module/components/block-content-overlay/index.js +4 -70
- package/build-module/components/block-content-overlay/index.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.native.js +50 -0
- package/build-module/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js +137 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build-module/components/block-draggable/index.native.js +449 -0
- package/build-module/components/block-draggable/index.native.js.map +1 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js +120 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build-module/components/block-list/block-list-context.native.js +179 -0
- package/build-module/components/block-list/block-list-context.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item-cell.native.js +59 -0
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item.native.js +12 -9
- package/build-module/components/block-list/block-list-item.native.js.map +1 -1
- package/build-module/components/block-list/block.native.js +28 -6
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +72 -23
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +9 -5
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-class-names.js +1 -7
- package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +34 -5
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +2 -1
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-lock/use-block-lock.js +4 -1
- package/build-module/components/block-lock/use-block-lock.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/index.native.js +8 -3
- package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-mover/button.js +5 -5
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +38 -63
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +18 -5
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +10 -5
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +173 -0
- package/build-module/components/block-popover/inbetween.js.map +1 -0
- package/build-module/components/block-popover/index.js +72 -0
- package/build-module/components/block-popover/index.js.map +1 -0
- package/build-module/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/build-module/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build-module/components/block-preview/index.js +1 -1
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-styles/index.js +1 -9
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +1 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +3 -2
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +3 -3
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +16 -121
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +199 -0
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -0
- package/build-module/components/border-radius-control/input-controls.js +11 -4
- package/build-module/components/border-radius-control/input-controls.js.map +1 -1
- package/build-module/components/color-style-selector/index.js +6 -0
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +151 -46
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/duotone-control/index.js +4 -1
- package/build-module/components/duotone-control/index.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +2 -1
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/index.js +1 -3
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +32 -11
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/link-control/constants.js +5 -0
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -4
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/use-search-handler.js +5 -5
- package/build-module/components/link-control/use-search-handler.js.map +1 -1
- package/build-module/components/list-view/block.js +15 -16
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +9 -13
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/context.js +1 -4
- package/build-module/components/list-view/context.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +0 -1
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +15 -31
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +12 -2
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +0 -1
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +1 -5
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +0 -4
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/url-input/index.js +11 -4
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +3 -1
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.native.js +148 -0
- package/build-module/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build-module/components/use-on-block-drop/index.native.js +83 -0
- package/build-module/components/use-on-block-drop/index.native.js.map +1 -0
- package/build-module/components/use-setting/index.js +43 -19
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +453 -44
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +11 -6
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/dimensions.js +5 -5
- package/build-module/hooks/dimensions.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/margin.js +61 -13
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +57 -13
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/settings.js +29 -0
- package/build-module/hooks/settings.js.map +1 -0
- package/build-module/hooks/style.js +15 -14
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +6 -2
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-border-props.js +21 -30
- package/build-module/hooks/use-border-props.js.map +1 -1
- package/build-module/store/actions.js +14 -2
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +0 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +0 -24
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +44 -15
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +148 -410
- package/build-style/style.css +148 -410
- package/package.json +28 -28
- package/src/components/block-alignment-control/constants.js +45 -0
- package/src/components/block-alignment-control/ui.js +69 -109
- package/src/components/block-alignment-control/ui.native.js +86 -0
- package/src/components/block-alignment-matrix-control/index.js +1 -5
- package/src/components/block-content-overlay/index.js +9 -79
- package/src/components/block-content-overlay/style.scss +2 -11
- package/src/components/block-draggable/draggable-chip.native.js +49 -0
- package/src/components/block-draggable/dropping-insertion-point.native.js +181 -0
- package/src/components/block-draggable/dropping-insertion-point.native.scss +8 -0
- package/src/components/block-draggable/index.native.js +458 -0
- package/src/components/block-draggable/style.native.scss +19 -0
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +135 -0
- package/src/components/block-list/block-list-context.native.js +175 -0
- package/src/components/block-list/block-list-item-cell.native.js +49 -0
- package/src/components/block-list/block-list-item.native.js +7 -11
- package/src/components/block-list/block.native.js +38 -8
- package/src/components/block-list/index.native.js +54 -13
- package/src/components/block-list/style.scss +7 -18
- package/src/components/block-list/test/block-list-context.native.js +253 -0
- package/src/components/block-list/test/fixtures/block-list-context.native.js +79 -0
- package/src/components/block-list/use-block-props/index.js +10 -5
- package/src/components/block-list/use-block-props/use-block-class-names.js +1 -11
- package/src/components/block-list/use-in-between-inserter.js +1 -1
- package/src/components/block-lock/modal.js +42 -3
- package/src/components/block-lock/toolbar.js +2 -2
- package/src/components/block-lock/use-block-lock.js +4 -1
- package/src/components/block-mobile-toolbar/index.native.js +8 -1
- package/src/components/block-mover/button.js +5 -7
- package/src/components/block-mover/index.js +37 -60
- package/src/components/block-mover/index.native.js +22 -6
- package/src/components/block-mover/stories/index.js +110 -0
- package/src/components/block-mover/style.scss +48 -138
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +6 -0
- package/src/components/block-navigation/dropdown.js +12 -8
- package/src/components/block-popover/README.md +41 -0
- package/src/components/block-popover/inbetween.js +188 -0
- package/src/components/block-popover/index.js +75 -0
- package/src/components/block-popover/style.scss +28 -0
- package/src/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/src/components/block-preview/index.js +1 -4
- package/src/components/block-styles/index.js +1 -12
- package/src/components/block-switcher/style.scss +2 -43
- package/src/components/block-toolbar/style.scss +0 -12
- package/src/components/block-tools/back-compat.js +1 -1
- package/src/components/block-tools/block-selection-button.js +3 -1
- package/src/components/block-tools/index.js +6 -4
- package/src/components/block-tools/insertion-point.js +19 -152
- package/src/components/block-tools/{block-popover.js → selected-block-popover.js} +24 -151
- package/src/components/block-tools/style.scss +12 -135
- package/src/components/border-radius-control/input-controls.js +16 -8
- package/src/components/border-radius-control/style.scss +7 -3
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/color-style-selector/index.js +18 -9
- package/src/components/colors-gradients/dropdown.js +156 -62
- package/src/components/colors-gradients/style.scss +51 -23
- package/src/components/default-block-appender/style.scss +1 -2
- package/src/components/duotone-control/index.js +8 -1
- package/src/components/duotone-control/style.scss +1 -7
- package/src/components/gradients/README.md +29 -0
- package/src/components/image-editor/use-save-image.js +2 -1
- package/src/components/image-size-control/README.md +1 -1
- package/src/components/index.js +1 -3
- package/src/components/inserter/index.native.js +60 -25
- package/src/components/inserter/style.native.scss +25 -3
- package/src/components/inserter/style.scss +2 -1
- package/src/components/link-control/constants.js +11 -0
- package/src/components/link-control/search-results.js +4 -5
- package/src/components/link-control/use-search-handler.js +11 -5
- package/src/components/list-view/block.js +24 -34
- package/src/components/list-view/branch.js +10 -20
- package/src/components/list-view/context.js +1 -4
- package/src/components/list-view/drop-indicator.js +0 -1
- package/src/components/list-view/index.js +11 -41
- package/src/components/list-view/style.scss +2 -1
- package/src/components/navigable-toolbar/README.md +16 -0
- package/src/components/navigable-toolbar/index.js +12 -2
- package/src/components/preview-options/style.scss +0 -4
- package/src/components/rich-text/format-toolbar-container.js +0 -1
- package/src/components/rich-text/index.js +1 -3
- package/src/components/rich-text/index.native.js +0 -4
- package/src/components/rich-text/style.scss +2 -8
- package/src/components/url-input/index.js +9 -4
- package/src/components/use-block-display-information/index.js +2 -0
- package/src/components/use-block-drop-zone/index.native.js +173 -0
- package/src/components/use-on-block-drop/index.native.js +119 -0
- package/src/components/use-setting/index.js +57 -21
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +429 -72
- package/src/hooks/color-panel.js +13 -9
- package/src/hooks/color.scss +0 -62
- package/src/hooks/dimensions.js +44 -38
- package/src/hooks/index.js +2 -1
- package/src/hooks/margin.js +64 -15
- package/src/hooks/padding.js +60 -15
- package/src/hooks/padding.scss +12 -0
- package/src/hooks/settings.js +32 -0
- package/src/hooks/style.js +25 -39
- package/src/hooks/test/settings.js +48 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/use-border-props.js +15 -32
- package/src/store/actions.js +14 -2
- package/src/store/defaults.js +0 -1
- package/src/store/reducer.js +0 -21
- package/src/store/selectors.js +46 -15
- package/src/store/test/actions.js +0 -18
- package/src/store/test/reducer.js +0 -19
- package/src/store/test/selectors.js +17 -19
- package/src/style.scss +2 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-mobile-toolbar/index.js +0 -42
- package/build/components/block-mobile-toolbar/index.js.map +0 -1
- package/build/components/block-tools/block-popover.js +0 -327
- package/build/components/block-tools/block-popover.js.map +0 -1
- package/build/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build/components/border-style-control/index.js +0 -60
- package/build/components/border-style-control/index.js.map +0 -1
- package/build/components/colors-gradients/tools-panel-color-dropdown.js +0 -89
- package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/build/components/list-view/appender.js +0 -93
- package/build/components/list-view/appender.js.map +0 -1
- package/build/components/list-view/list-item.js +0 -62
- package/build/components/list-view/list-item.js.map +0 -1
- package/build/components/rich-text/use-caret-in-format.js +0 -43
- package/build/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build/hooks/border-color.js +0 -302
- package/build/hooks/border-color.js.map +0 -1
- package/build/hooks/border-style.js +0 -96
- package/build/hooks/border-style.js.map +0 -1
- package/build/hooks/border-width.js +0 -162
- package/build/hooks/border-width.js.map +0 -1
- package/build-module/components/block-mobile-toolbar/index.js +0 -31
- package/build-module/components/block-mobile-toolbar/index.js.map +0 -1
- package/build-module/components/block-tools/block-popover.js +0 -306
- package/build-module/components/block-tools/block-popover.js.map +0 -1
- package/build-module/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build-module/components/border-style-control/index.js +0 -50
- package/build-module/components/border-style-control/index.js.map +0 -1
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +0 -75
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/build-module/components/list-view/appender.js +0 -76
- package/build-module/components/list-view/appender.js.map +0 -1
- package/build-module/components/list-view/list-item.js +0 -47
- package/build-module/components/list-view/list-item.js.map +0 -1
- package/build-module/components/rich-text/use-caret-in-format.js +0 -33
- package/build-module/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build-module/hooks/border-color.js +0 -276
- package/build-module/hooks/border-color.js.map +0 -1
- package/build-module/hooks/border-style.js +0 -78
- package/build-module/hooks/border-style.js.map +0 -1
- package/build-module/hooks/border-width.js +0 -143
- package/build-module/hooks/border-width.js.map +0 -1
- package/src/components/block-alignment-matrix-control/style.scss +0 -10
- package/src/components/block-mobile-toolbar/index.js +0 -24
- package/src/components/block-mobile-toolbar/style.scss +0 -29
- package/src/components/border-style-control/index.js +0 -47
- package/src/components/border-style-control/style.scss +0 -18
- package/src/components/colors-gradients/tools-panel-color-dropdown.js +0 -85
- package/src/components/list-view/appender.js +0 -82
- package/src/components/list-view/list-item.js +0 -59
- package/src/components/rich-text/use-caret-in-format.js +0 -28
- package/src/hooks/border-color.js +0 -315
- package/src/hooks/border-style.js +0 -64
- package/src/hooks/border-width.js +0 -139
|
@@ -48,33 +48,17 @@ const expanded = ( state, action ) => {
|
|
|
48
48
|
export const BLOCK_LIST_ITEM_HEIGHT = 36;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
* recursive component (it renders itself), so this ensures TreeGrid is only
|
|
53
|
-
* present at the very top of the navigation grid.
|
|
51
|
+
* Show a hierarchical list of blocks.
|
|
54
52
|
*
|
|
55
|
-
* @param {Object} props
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {boolean} props.showBlockMovers
|
|
59
|
-
* @param {boolean} props.
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {boolean} props.__experimentalHideContainerBlockActions Flag to hide actions of top level blocks (like core/widget-area)
|
|
62
|
-
* @param {string} props.id Unique identifier for the root list element (primarily for a11y purposes).
|
|
63
|
-
* @param {boolean} props.expandNested Flag to determine whether nested levels are expanded by default.
|
|
64
|
-
* @param {Object} ref Forwarded ref
|
|
53
|
+
* @param {Object} props Components props.
|
|
54
|
+
* @param {string} props.id An HTML element id for the root element of ListView.
|
|
55
|
+
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
|
|
56
|
+
* @param {boolean} props.showBlockMovers Flag to enable block movers
|
|
57
|
+
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
|
|
58
|
+
* @param {Object} ref Forwarded ref
|
|
65
59
|
*/
|
|
66
60
|
function ListView(
|
|
67
|
-
{
|
|
68
|
-
blocks,
|
|
69
|
-
__experimentalFeatures,
|
|
70
|
-
__experimentalPersistentListViewFeatures,
|
|
71
|
-
__experimentalHideContainerBlockActions,
|
|
72
|
-
showNestedBlocks,
|
|
73
|
-
showBlockMovers,
|
|
74
|
-
id,
|
|
75
|
-
expandNested = false,
|
|
76
|
-
...props
|
|
77
|
-
},
|
|
61
|
+
{ id, blocks, showBlockMovers = false, isExpanded = false },
|
|
78
62
|
ref
|
|
79
63
|
) {
|
|
80
64
|
const {
|
|
@@ -131,7 +115,7 @@ function ListView(
|
|
|
131
115
|
BLOCK_LIST_ITEM_HEIGHT,
|
|
132
116
|
visibleBlockCount,
|
|
133
117
|
{
|
|
134
|
-
useWindowing:
|
|
118
|
+
useWindowing: true,
|
|
135
119
|
windowOverscan: 40,
|
|
136
120
|
}
|
|
137
121
|
);
|
|
@@ -181,25 +165,13 @@ function ListView(
|
|
|
181
165
|
|
|
182
166
|
const contextValue = useMemo(
|
|
183
167
|
() => ( {
|
|
184
|
-
__experimentalFeatures,
|
|
185
|
-
__experimentalPersistentListViewFeatures,
|
|
186
|
-
__experimentalHideContainerBlockActions,
|
|
187
168
|
isTreeGridMounted: isMounted.current,
|
|
188
169
|
draggedClientIds,
|
|
189
170
|
expandedState,
|
|
190
171
|
expand,
|
|
191
172
|
collapse,
|
|
192
173
|
} ),
|
|
193
|
-
[
|
|
194
|
-
__experimentalFeatures,
|
|
195
|
-
__experimentalPersistentListViewFeatures,
|
|
196
|
-
__experimentalHideContainerBlockActions,
|
|
197
|
-
isMounted.current,
|
|
198
|
-
draggedClientIds,
|
|
199
|
-
expandedState,
|
|
200
|
-
expand,
|
|
201
|
-
collapse,
|
|
202
|
-
]
|
|
174
|
+
[ isMounted.current, draggedClientIds, expandedState, expand, collapse ]
|
|
203
175
|
);
|
|
204
176
|
|
|
205
177
|
return (
|
|
@@ -221,12 +193,10 @@ function ListView(
|
|
|
221
193
|
<ListViewBranch
|
|
222
194
|
blocks={ clientIdsTree }
|
|
223
195
|
selectBlock={ selectEditorBlock }
|
|
224
|
-
showNestedBlocks={ showNestedBlocks }
|
|
225
196
|
showBlockMovers={ showBlockMovers }
|
|
226
197
|
fixedListWindow={ fixedListWindow }
|
|
227
198
|
selectedClientIds={ selectedClientIds }
|
|
228
|
-
|
|
229
|
-
{ ...props }
|
|
199
|
+
isExpanded={ isExpanded }
|
|
230
200
|
/>
|
|
231
201
|
</ListViewContext.Provider>
|
|
232
202
|
</TreeGrid>
|
|
@@ -396,10 +396,11 @@ $block-navigation-max-indent: 8;
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
// Reset some popover defaults for the drop indicator.
|
|
399
|
-
.block-editor-list-view-drop-indicator
|
|
399
|
+
.block-editor-list-view-drop-indicator > .components-popover__content {
|
|
400
400
|
margin-left: 0;
|
|
401
401
|
border: none;
|
|
402
402
|
box-shadow: none;
|
|
403
|
+
outline: none;
|
|
403
404
|
}
|
|
404
405
|
|
|
405
406
|
.block-editor-list-view-placeholder {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# NavigableToolbar
|
|
2
|
+
|
|
3
|
+
A toolbar that can be navigated with a keyboard
|
|
4
|
+
|
|
5
|
+
## Props
|
|
6
|
+
|
|
7
|
+
The component accepts the following props. Props not included in this set will be applied to the element wrapping NavigableMenu content.
|
|
8
|
+
|
|
9
|
+
## `focusOnMount`
|
|
10
|
+
|
|
11
|
+
Whether to immediately focus when the component mounts.
|
|
12
|
+
|
|
13
|
+
- Type: `Boolean`
|
|
14
|
+
- Required: No
|
|
15
|
+
- Default: false
|
|
16
|
+
|
|
@@ -29,7 +29,12 @@ function hasFocusWithin( container ) {
|
|
|
29
29
|
function focusFirstTabbableIn( container ) {
|
|
30
30
|
const [ firstTabbable ] = focus.tabbable.find( container );
|
|
31
31
|
if ( firstTabbable ) {
|
|
32
|
-
firstTabbable.focus(
|
|
32
|
+
firstTabbable.focus( {
|
|
33
|
+
// When focusing newly mounted toolbars,
|
|
34
|
+
// the position of the popover is often not right on the first render
|
|
35
|
+
// This prevents the layout shifts when focusing the dialogs.
|
|
36
|
+
preventScroll: true,
|
|
37
|
+
} );
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -119,7 +124,12 @@ function useToolbarFocus(
|
|
|
119
124
|
const items = getAllToolbarItemsIn( ref.current );
|
|
120
125
|
const index = initialIndex || 0;
|
|
121
126
|
if ( items[ index ] && hasFocusWithin( ref.current ) ) {
|
|
122
|
-
items[ index ].focus(
|
|
127
|
+
items[ index ].focus( {
|
|
128
|
+
// When focusing newly mounted toolbars,
|
|
129
|
+
// the position of the popover is often not right on the first render
|
|
130
|
+
// This prevents the layout shifts when focusing the dialogs.
|
|
131
|
+
preventScroll: true,
|
|
132
|
+
} );
|
|
123
133
|
}
|
|
124
134
|
} );
|
|
125
135
|
}
|
|
@@ -36,7 +36,6 @@ import { useBlockEditContext } from '../block-edit';
|
|
|
36
36
|
import FormatToolbarContainer from './format-toolbar-container';
|
|
37
37
|
import { store as blockEditorStore } from '../../store';
|
|
38
38
|
import { useUndoAutomaticChange } from './use-undo-automatic-change';
|
|
39
|
-
import { useCaretInFormat } from './use-caret-in-format';
|
|
40
39
|
import { useMarkPersistent } from './use-mark-persistent';
|
|
41
40
|
import { usePasteHandler } from './use-paste-handler';
|
|
42
41
|
import { useInputRules } from './use-input-rules';
|
|
@@ -268,7 +267,6 @@ function RichTextWrapper(
|
|
|
268
267
|
onChange,
|
|
269
268
|
} );
|
|
270
269
|
|
|
271
|
-
useCaretInFormat( { value } );
|
|
272
270
|
useMarkPersistent( { html: adjustedValue, value } );
|
|
273
271
|
|
|
274
272
|
const keyboardShortcuts = useRef( new Set() );
|
|
@@ -340,7 +338,7 @@ function RichTextWrapper(
|
|
|
340
338
|
{ isSelected && hasFormats && (
|
|
341
339
|
<FormatToolbarContainer
|
|
342
340
|
inline={ inlineToolbar }
|
|
343
|
-
anchorRef={ anchorRef
|
|
341
|
+
anchorRef={ anchorRef }
|
|
344
342
|
/>
|
|
345
343
|
) }
|
|
346
344
|
<TagName
|
|
@@ -125,7 +125,6 @@ function RichTextWrapper(
|
|
|
125
125
|
const embedHandlerPickerRef = useRef();
|
|
126
126
|
const selector = ( select ) => {
|
|
127
127
|
const {
|
|
128
|
-
isCaretWithinFormattedText,
|
|
129
128
|
getSelectionStart,
|
|
130
129
|
getSelectionEnd,
|
|
131
130
|
getSettings,
|
|
@@ -163,7 +162,6 @@ function RichTextWrapper(
|
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
return {
|
|
166
|
-
isCaretWithinFormattedText: isCaretWithinFormattedText(),
|
|
167
165
|
selectionStart: isSelected ? selectionStart.offset : undefined,
|
|
168
166
|
selectionEnd: isSelected ? selectionEnd.offset : undefined,
|
|
169
167
|
isSelected,
|
|
@@ -177,7 +175,6 @@ function RichTextWrapper(
|
|
|
177
175
|
// retrieved from the store on merge.
|
|
178
176
|
// To do: fix this somehow.
|
|
179
177
|
const {
|
|
180
|
-
isCaretWithinFormattedText,
|
|
181
178
|
selectionStart,
|
|
182
179
|
selectionEnd,
|
|
183
180
|
isSelected,
|
|
@@ -600,7 +597,6 @@ function RichTextWrapper(
|
|
|
600
597
|
__unstableIsSelected={ isSelected }
|
|
601
598
|
__unstableInputRule={ inputRule }
|
|
602
599
|
__unstableMultilineTag={ multilineTag }
|
|
603
|
-
__unstableIsCaretWithinFormattedText={ isCaretWithinFormattedText }
|
|
604
600
|
__unstableOnEnterFormattedText={ enterFormattedText }
|
|
605
601
|
__unstableOnExitFormattedText={ exitFormattedText }
|
|
606
602
|
__unstableOnCreateUndoLevel={ __unstableMarkLastChangeAsPersistent }
|
|
@@ -42,17 +42,11 @@ figcaption.block-editor-rich-text__editable [data-rich-text-placeholder]::before
|
|
|
42
42
|
min-width: auto;
|
|
43
43
|
margin-bottom: $grid-unit-10;
|
|
44
44
|
box-shadow: none;
|
|
45
|
-
|
|
46
|
-
// Block UI appearance.
|
|
47
|
-
border: $border-width solid $gray-900;
|
|
48
|
-
border-radius: $radius-block-ui;
|
|
49
|
-
background-color: $white;
|
|
45
|
+
outline: none;
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
.components-toolbar-group,
|
|
53
48
|
.components-toolbar {
|
|
54
|
-
|
|
55
|
-
border: none;
|
|
49
|
+
border-radius: $radius-block-ui;
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
.components-toolbar__control,
|
|
@@ -303,6 +303,7 @@ class URLInput extends Component {
|
|
|
303
303
|
|
|
304
304
|
// Submitting while loading should trigger onSubmit.
|
|
305
305
|
case ENTER: {
|
|
306
|
+
event.preventDefault();
|
|
306
307
|
if ( this.props.onSubmit ) {
|
|
307
308
|
this.props.onSubmit( null, event );
|
|
308
309
|
}
|
|
@@ -350,6 +351,7 @@ class URLInput extends Component {
|
|
|
350
351
|
break;
|
|
351
352
|
}
|
|
352
353
|
case ENTER: {
|
|
354
|
+
event.preventDefault();
|
|
353
355
|
if ( this.state.selectedSuggestion !== null ) {
|
|
354
356
|
this.selectLink( suggestion );
|
|
355
357
|
|
|
@@ -418,7 +420,7 @@ class URLInput extends Component {
|
|
|
418
420
|
|
|
419
421
|
renderControl() {
|
|
420
422
|
const {
|
|
421
|
-
label,
|
|
423
|
+
label = null,
|
|
422
424
|
className,
|
|
423
425
|
isFullWidth,
|
|
424
426
|
instanceId,
|
|
@@ -435,8 +437,10 @@ class URLInput extends Component {
|
|
|
435
437
|
suggestionOptionIdPrefix,
|
|
436
438
|
} = this.state;
|
|
437
439
|
|
|
440
|
+
const inputId = `url-input-control-${ instanceId }`;
|
|
441
|
+
|
|
438
442
|
const controlProps = {
|
|
439
|
-
id:
|
|
443
|
+
id: inputId, // Passes attribute to label for the for attribute
|
|
440
444
|
label,
|
|
441
445
|
className: classnames( 'block-editor-url-input', className, {
|
|
442
446
|
'is-full-width': isFullWidth,
|
|
@@ -444,6 +448,7 @@ class URLInput extends Component {
|
|
|
444
448
|
};
|
|
445
449
|
|
|
446
450
|
const inputProps = {
|
|
451
|
+
id: inputId,
|
|
447
452
|
value,
|
|
448
453
|
required: true,
|
|
449
454
|
className: 'block-editor-url-input__input',
|
|
@@ -453,7 +458,7 @@ class URLInput extends Component {
|
|
|
453
458
|
placeholder,
|
|
454
459
|
onKeyDown: this.onKeyDown,
|
|
455
460
|
role: 'combobox',
|
|
456
|
-
'aria-label': __( 'URL' ),
|
|
461
|
+
'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label
|
|
457
462
|
'aria-expanded': showSuggestions,
|
|
458
463
|
'aria-autocomplete': 'list',
|
|
459
464
|
'aria-owns': suggestionsListboxId,
|
|
@@ -533,7 +538,7 @@ class URLInput extends Component {
|
|
|
533
538
|
!! suggestions.length
|
|
534
539
|
) {
|
|
535
540
|
return (
|
|
536
|
-
<Popover position="bottom"
|
|
541
|
+
<Popover position="bottom" focusOnMount={ false }>
|
|
537
542
|
<div
|
|
538
543
|
{ ...suggestionsListProps }
|
|
539
544
|
className={ classnames(
|
|
@@ -19,6 +19,7 @@ import { store as blockEditorStore } from '../../store';
|
|
|
19
19
|
* @property {string} title Human-readable block type label.
|
|
20
20
|
* @property {WPIcon} icon Block type icon.
|
|
21
21
|
* @property {string} description A detailed block type description.
|
|
22
|
+
* @property {string} anchor HTML anchor.
|
|
22
23
|
*/
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -63,6 +64,7 @@ export default function useBlockDisplayInformation( clientId ) {
|
|
|
63
64
|
title: match.title || blockType.title,
|
|
64
65
|
icon: match.icon || blockType.icon,
|
|
65
66
|
description: match.description || blockType.description,
|
|
67
|
+
anchor: attributes?.anchor,
|
|
66
68
|
};
|
|
67
69
|
},
|
|
68
70
|
[ clientId ]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { useCallback } from '@wordpress/element';
|
|
11
|
+
import { useThrottle } from '@wordpress/compose';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as blockEditorStore } from '../../store';
|
|
17
|
+
import { useBlockListContext } from '../block-list/block-list-context';
|
|
18
|
+
import { getDistanceToNearestEdge } from '../../utils/math';
|
|
19
|
+
import useOnBlockDrop from '../use-on-block-drop';
|
|
20
|
+
|
|
21
|
+
/** @typedef {import('../../utils/math').WPPoint} WPPoint */
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The orientation of a block list.
|
|
25
|
+
*
|
|
26
|
+
* @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Given a list of blocks layouts finds the index that a block should be dropped at.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} blocksLayouts Blocks layouts object.
|
|
33
|
+
* @param {WPPoint} position The position of the item being dragged.
|
|
34
|
+
* @param {WPBlockListOrientation} orientation The orientation of a block list.
|
|
35
|
+
* @param {boolean} isRTL Check if current locale is RTL.
|
|
36
|
+
*
|
|
37
|
+
* @return {number|undefined} The block index that's closest to the drag position.
|
|
38
|
+
*/
|
|
39
|
+
export function getNearestBlockIndex(
|
|
40
|
+
blocksLayouts,
|
|
41
|
+
position,
|
|
42
|
+
orientation,
|
|
43
|
+
isRTL
|
|
44
|
+
) {
|
|
45
|
+
const allowedEdges =
|
|
46
|
+
orientation === 'horizontal'
|
|
47
|
+
? [ 'left', 'right' ]
|
|
48
|
+
: [ 'top', 'bottom' ];
|
|
49
|
+
|
|
50
|
+
const isRightToLeft = isRTL;
|
|
51
|
+
|
|
52
|
+
let candidateIndex;
|
|
53
|
+
let candidateDistance;
|
|
54
|
+
|
|
55
|
+
// Only enabled for root level blocks.
|
|
56
|
+
blocksLayouts.forEach( ( element, index ) => {
|
|
57
|
+
const { x, y, width, height } = element;
|
|
58
|
+
const rect = {
|
|
59
|
+
x: element.x,
|
|
60
|
+
y: element.y,
|
|
61
|
+
top: y,
|
|
62
|
+
right: x + width,
|
|
63
|
+
bottom: y + height,
|
|
64
|
+
left: x,
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
};
|
|
68
|
+
const [ distance, edge ] = getDistanceToNearestEdge(
|
|
69
|
+
position,
|
|
70
|
+
rect,
|
|
71
|
+
allowedEdges
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if ( candidateDistance === undefined || distance < candidateDistance ) {
|
|
75
|
+
// If the user is dropping to the trailing edge of the block
|
|
76
|
+
// add 1 to the index to represent dragging after.
|
|
77
|
+
// Take RTL languages into account where the left edge is
|
|
78
|
+
// the trailing edge.
|
|
79
|
+
const isTrailingEdge =
|
|
80
|
+
edge === 'bottom' ||
|
|
81
|
+
( ! isRightToLeft && edge === 'right' ) ||
|
|
82
|
+
( isRightToLeft && edge === 'left' );
|
|
83
|
+
const offset = isTrailingEdge ? 1 : 0;
|
|
84
|
+
|
|
85
|
+
// Update the currently known best candidate.
|
|
86
|
+
candidateDistance = distance;
|
|
87
|
+
candidateIndex = index + offset;
|
|
88
|
+
}
|
|
89
|
+
} );
|
|
90
|
+
return candidateIndex;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @typedef {Object} WPBlockDropZoneConfig
|
|
95
|
+
* @property {string} rootClientId The root client id for the block list.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A React hook that can be used to make a block list handle drag and drop.
|
|
100
|
+
*
|
|
101
|
+
* @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.
|
|
102
|
+
*
|
|
103
|
+
* @return {Object} An object that contains `targetBlockIndex` and the event
|
|
104
|
+
* handlers `onBlockDragOver`, `onBlockDragEnd` and `onBlockDrop`.
|
|
105
|
+
*/
|
|
106
|
+
export default function useBlockDropZone( {
|
|
107
|
+
// An undefined value represents a top-level block. Default to an empty
|
|
108
|
+
// string for this so that `targetRootClientId` can be easily compared to
|
|
109
|
+
// values returned by the `getRootBlockClientId` selector, which also uses
|
|
110
|
+
// an empty string to represent top-level blocks.
|
|
111
|
+
rootClientId: targetRootClientId = '',
|
|
112
|
+
} = {} ) {
|
|
113
|
+
const targetBlockIndex = useSharedValue( null );
|
|
114
|
+
|
|
115
|
+
const { getBlockListSettings, getSettings } = useSelect( blockEditorStore );
|
|
116
|
+
const {
|
|
117
|
+
blocksLayouts,
|
|
118
|
+
getBlockLayoutsOrderedByYCoord,
|
|
119
|
+
} = useBlockListContext();
|
|
120
|
+
|
|
121
|
+
const getSortedBlocksLayouts = useCallback( () => {
|
|
122
|
+
return getBlockLayoutsOrderedByYCoord( blocksLayouts.current );
|
|
123
|
+
}, [ blocksLayouts.current ] );
|
|
124
|
+
|
|
125
|
+
const isRTL = getSettings().isRTL;
|
|
126
|
+
|
|
127
|
+
const onBlockDrop = useOnBlockDrop();
|
|
128
|
+
|
|
129
|
+
const throttled = useThrottle(
|
|
130
|
+
useCallback(
|
|
131
|
+
( event ) => {
|
|
132
|
+
const sortedBlockLayouts = getSortedBlocksLayouts();
|
|
133
|
+
|
|
134
|
+
const targetIndex = getNearestBlockIndex(
|
|
135
|
+
sortedBlockLayouts,
|
|
136
|
+
{ x: event.x, y: event.y },
|
|
137
|
+
getBlockListSettings( targetRootClientId )?.orientation,
|
|
138
|
+
isRTL
|
|
139
|
+
);
|
|
140
|
+
if ( targetIndex !== null ) {
|
|
141
|
+
targetBlockIndex.value = targetIndex ?? 0;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[
|
|
145
|
+
getSortedBlocksLayouts,
|
|
146
|
+
getNearestBlockIndex,
|
|
147
|
+
getBlockListSettings,
|
|
148
|
+
targetBlockIndex,
|
|
149
|
+
]
|
|
150
|
+
),
|
|
151
|
+
200
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
onBlockDragOver( event ) {
|
|
156
|
+
throttled( event );
|
|
157
|
+
},
|
|
158
|
+
onBlockDragEnd() {
|
|
159
|
+
throttled.cancel();
|
|
160
|
+
targetBlockIndex.value = null;
|
|
161
|
+
},
|
|
162
|
+
onBlockDrop: ( event ) => {
|
|
163
|
+
if ( targetBlockIndex.value !== null ) {
|
|
164
|
+
onBlockDrop( {
|
|
165
|
+
...event,
|
|
166
|
+
targetRootClientId,
|
|
167
|
+
targetBlockIndex: targetBlockIndex.value,
|
|
168
|
+
} );
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
targetBlockIndex,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { cloneBlock } from '@wordpress/blocks';
|
|
5
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A function that returns an event handler function for block drop events.
|
|
14
|
+
*
|
|
15
|
+
* @param {Function} getBlockIndex A function that gets the index of a block.
|
|
16
|
+
* @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.
|
|
17
|
+
* @param {Function} moveBlocksToPosition A function that moves blocks.
|
|
18
|
+
* @param {Function} insertBlocks A function that inserts blocks.
|
|
19
|
+
* @param {Function} clearSelectedBlock A function that clears block selection.
|
|
20
|
+
* @return {Function} The event handler for a block drop event.
|
|
21
|
+
*/
|
|
22
|
+
export function onBlockDrop(
|
|
23
|
+
getBlockIndex,
|
|
24
|
+
getClientIdsOfDescendants,
|
|
25
|
+
moveBlocksToPosition,
|
|
26
|
+
insertBlocks,
|
|
27
|
+
clearSelectedBlock
|
|
28
|
+
) {
|
|
29
|
+
return ( {
|
|
30
|
+
blocks,
|
|
31
|
+
srcClientIds: sourceClientIds,
|
|
32
|
+
srcRootClientId: sourceRootClientId,
|
|
33
|
+
targetBlockIndex,
|
|
34
|
+
targetRootClientId,
|
|
35
|
+
type: dropType,
|
|
36
|
+
} ) => {
|
|
37
|
+
// If the user is inserting a block.
|
|
38
|
+
if ( dropType === 'inserter' ) {
|
|
39
|
+
clearSelectedBlock();
|
|
40
|
+
const blocksToInsert = blocks.map( ( block ) =>
|
|
41
|
+
cloneBlock( block )
|
|
42
|
+
);
|
|
43
|
+
insertBlocks(
|
|
44
|
+
blocksToInsert,
|
|
45
|
+
targetBlockIndex,
|
|
46
|
+
targetRootClientId,
|
|
47
|
+
true,
|
|
48
|
+
null
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// If the user is moving a block.
|
|
53
|
+
if ( dropType === 'block' ) {
|
|
54
|
+
const sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );
|
|
55
|
+
|
|
56
|
+
// If the user is dropping to the same position, return early.
|
|
57
|
+
if (
|
|
58
|
+
sourceRootClientId === targetRootClientId &&
|
|
59
|
+
sourceBlockIndex === targetBlockIndex
|
|
60
|
+
) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If the user is attempting to drop a block within its own
|
|
65
|
+
// nested blocks, return early as this would create infinite
|
|
66
|
+
// recursion.
|
|
67
|
+
if (
|
|
68
|
+
sourceClientIds.includes( targetRootClientId ) ||
|
|
69
|
+
getClientIdsOfDescendants( sourceClientIds ).some(
|
|
70
|
+
( id ) => id === targetRootClientId
|
|
71
|
+
)
|
|
72
|
+
) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isAtSameLevel = sourceRootClientId === targetRootClientId;
|
|
77
|
+
const draggedBlockCount = sourceClientIds.length;
|
|
78
|
+
|
|
79
|
+
// If the block is kept at the same level and moved downwards,
|
|
80
|
+
// subtract to take into account that the blocks being dragged
|
|
81
|
+
// were removed from the block list above the insertion point.
|
|
82
|
+
const insertIndex =
|
|
83
|
+
isAtSameLevel && sourceBlockIndex < targetBlockIndex
|
|
84
|
+
? targetBlockIndex - draggedBlockCount
|
|
85
|
+
: targetBlockIndex;
|
|
86
|
+
|
|
87
|
+
moveBlocksToPosition(
|
|
88
|
+
sourceClientIds,
|
|
89
|
+
sourceRootClientId,
|
|
90
|
+
targetRootClientId,
|
|
91
|
+
insertIndex
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A React hook for handling block drop events.
|
|
99
|
+
*
|
|
100
|
+
* @return {Function} The event handler for a block drop event.
|
|
101
|
+
*/
|
|
102
|
+
export default function useOnBlockDrop() {
|
|
103
|
+
const { getBlockIndex, getClientIdsOfDescendants } = useSelect(
|
|
104
|
+
blockEditorStore
|
|
105
|
+
);
|
|
106
|
+
const {
|
|
107
|
+
insertBlocks,
|
|
108
|
+
moveBlocksToPosition,
|
|
109
|
+
clearSelectedBlock,
|
|
110
|
+
} = useDispatch( blockEditorStore );
|
|
111
|
+
|
|
112
|
+
return onBlockDrop(
|
|
113
|
+
getBlockIndex,
|
|
114
|
+
getClientIdsOfDescendants,
|
|
115
|
+
moveBlocksToPosition,
|
|
116
|
+
insertBlocks,
|
|
117
|
+
clearSelectedBlock
|
|
118
|
+
);
|
|
119
|
+
}
|