@wordpress/block-editor 12.16.0 → 12.16.1-next.79a6196f.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/LICENSE.md +1 -1
- package/README.md +3 -6
- package/build/components/block-canvas/index.js +0 -2
- package/build/components/block-canvas/index.js.map +1 -1
- package/build/components/block-card/index.js +1 -1
- package/build/components/block-card/index.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.js +6 -1
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-draggable/index.js +76 -6
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/index.native.js +0 -6
- package/build/components/block-draggable/index.native.js.map +1 -1
- package/build/components/block-draggable/use-scroll-when-dragging.native.js +1 -1
- package/build/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -1
- package/build/components/block-editing-mode/index.js +2 -3
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-inspector/index.js +1 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-item-cell.native.js +1 -0
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build/components/block-list/block.js +245 -102
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +46 -20
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +3 -5
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/private-block-context.js +14 -0
- package/build/components/block-list/private-block-context.js.map +1 -0
- package/build/components/block-list/use-block-props/index.js +33 -96
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +3 -2
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-list/use-scroll-upon-insertion.native.js +41 -0
- package/build/components/block-list/use-scroll-upon-insertion.native.js.map +1 -0
- package/build/components/block-lock/toolbar.js +21 -27
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/index.js +2 -1
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +4 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-switcher/index.js +4 -4
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +1 -2
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-toolbar-popover.js +0 -2
- package/build/components/block-tools/block-toolbar-popover.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +29 -2
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/border-radius-control/linked-button.js +1 -1
- package/build/components/border-radius-control/linked-button.js.map +1 -1
- package/build/components/colors/utils.js +10 -2
- package/build/components/colors/utils.js.map +1 -1
- package/build/components/colors/with-colors.js +6 -2
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/font-sizes/utils.js +10 -2
- package/build/components/font-sizes/utils.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 +4 -3
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +2 -1
- package/build/components/global-styles/effects-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +1 -4
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/get-global-styles-changes.js +192 -0
- package/build/components/global-styles/get-global-styles-changes.js.map +1 -0
- package/build/components/global-styles/hooks.js +3 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/image-settings-panel.js +7 -1
- package/build/components/global-styles/image-settings-panel.js.map +1 -1
- package/build/components/global-styles/index.js +7 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +33 -15
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +22 -8
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +8 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/height-control/index.js +6 -2
- package/build/components/height-control/index.js.map +1 -1
- package/build/components/image-size-control/index.js +2 -2
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.native.js +6 -5
- package/build/components/index.native.js.map +1 -1
- package/build/components/inner-blocks/index.js +61 -22
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +18 -4
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +5 -6
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js +5 -9
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +10 -9
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/patterns-filter.js +10 -10
- package/build/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js +9 -9
- package/build/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/utils.js +10 -14
- package/build/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +4 -14
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/index.js +1 -2
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/library.js +3 -7
- package/build/components/inserter/library.js.map +1 -1
- package/build/components/inserter/menu.js +14 -28
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/tabs.js +21 -21
- package/build/components/inserter/tabs.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +1 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inserter-list-item/index.js +2 -4
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +3 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls-tabs/index.js +34 -23
- package/build/components/inspector-controls-tabs/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +4 -0
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +57 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/media-upload-progress/constants.js +19 -0
- package/build/components/media-upload-progress/constants.js.map +1 -0
- package/build/components/media-upload-progress/index.native.js +42 -17
- package/build/components/media-upload-progress/index.native.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +9 -14
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/plain-text/index.native.js +8 -3
- package/build/components/plain-text/index.native.js.map +1 -1
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +7 -1
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/rich-text/index.js +17 -7
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +16 -24
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/rich-text/use-input-rules.js +2 -2
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/rich-text/use-mark-persistent.js +1 -1
- package/build/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build/components/url-input/index.js +9 -6
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-commands/index.js +14 -18
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +51 -22
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-moving-animation/index.js +100 -92
- package/build/components/use-moving-animation/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +8 -11
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/writing-flow/index.js +0 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-drag-selection.js +15 -4
- package/build/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +73 -27
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +7 -4
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/align.js +1 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/anchor.js +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/aria-label.js +9 -1
- package/build/hooks/aria-label.js.map +1 -1
- package/build/hooks/background.js +185 -20
- package/build/hooks/background.js.map +1 -1
- package/build/hooks/border.js +5 -10
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +13 -11
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/custom-class-name.js +1 -1
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/custom-class-name.native.js +9 -1
- package/build/hooks/custom-class-name.native.js.map +1 -1
- package/build/hooks/dimensions.js +4 -9
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/font-family.js +7 -3
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +1 -1
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/index.js +4 -4
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +5 -3
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/layout.js +10 -4
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +1 -1
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +4 -9
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/typography.native.js +43 -18
- package/build/hooks/typography.native.js.map +1 -1
- package/build/hooks/use-typography-props.js +10 -2
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +48 -5
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +2 -4
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +0 -2
- package/build/private-apis.native.js.map +1 -1
- package/build/store/actions.js +0 -16
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +51 -5
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +12 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +14 -6
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +1 -13
- package/build/store/selectors.js.map +1 -1
- package/build/store/undo-ignore.js +12 -0
- package/build/store/undo-ignore.js.map +1 -0
- package/build/store/utils.js +1 -1
- package/build/store/utils.js.map +1 -1
- package/build/utils/get-px-from-css-unit.js +16 -0
- package/build/utils/get-px-from-css-unit.js.map +1 -0
- package/build/utils/index.js +2 -2
- package/build/utils/index.js.map +1 -1
- package/build/utils/object.js +17 -38
- package/build/utils/object.js.map +1 -1
- package/build/utils/use-can-block-toolbar-be-focused.js +46 -0
- package/build/utils/use-can-block-toolbar-be-focused.js.map +1 -0
- package/build-module/components/block-canvas/index.js +0 -2
- package/build-module/components/block-canvas/index.js.map +1 -1
- package/build-module/components/block-card/index.js +1 -1
- package/build-module/components/block-card/index.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +6 -1
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-draggable/index.js +76 -6
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/index.native.js +1 -7
- package/build-module/components/block-draggable/index.native.js.map +1 -1
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js +1 -1
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +3 -4
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +1 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-item-cell.native.js +1 -0
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build-module/components/block-list/block.js +249 -106
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +48 -22
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +3 -5
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/private-block-context.js +6 -0
- package/build-module/components/block-list/private-block-context.js.map +1 -0
- package/build-module/components/block-list/use-block-props/index.js +34 -97
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +3 -2
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-list/use-scroll-upon-insertion.native.js +33 -0
- package/build-module/components/block-list/use-scroll-upon-insertion.native.js.map +1 -0
- package/build-module/components/block-lock/toolbar.js +22 -28
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/index.js +2 -1
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -5
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +4 -4
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +1 -2
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-toolbar-popover.js +0 -2
- package/build-module/components/block-tools/block-toolbar-popover.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +30 -3
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/border-radius-control/linked-button.js +1 -1
- package/build-module/components/border-radius-control/linked-button.js.map +1 -1
- package/build-module/components/colors/utils.js +9 -1
- package/build-module/components/colors/utils.js.map +1 -1
- package/build-module/components/colors/with-colors.js +5 -1
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/font-sizes/utils.js +9 -1
- package/build-module/components/font-sizes/utils.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 +5 -4
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +3 -2
- package/build-module/components/global-styles/effects-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +2 -5
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/get-global-styles-changes.js +184 -0
- package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +3 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/image-settings-panel.js +7 -1
- package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
- package/build-module/components/global-styles/index.js +1 -0
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +35 -17
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +15 -1
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +7 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/height-control/index.js +6 -2
- package/build-module/components/height-control/index.js.map +1 -1
- package/build-module/components/image-size-control/index.js +2 -2
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.native.js +2 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +62 -23
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +18 -4
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +5 -6
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inner-blocks/use-nested-settings-update.js +6 -10
- package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +11 -10
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/patterns-filter.js +11 -11
- package/build-module/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js +11 -11
- package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/utils.js +7 -11
- package/build-module/components/inserter/block-patterns-tab/utils.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +4 -14
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +2 -2
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/index.js +1 -2
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/library.js +3 -7
- package/build-module/components/inserter/library.js.map +1 -1
- package/build-module/components/inserter/menu.js +14 -28
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/tabs.js +22 -22
- package/build-module/components/inserter/tabs.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +2 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +2 -4
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +3 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/index.js +35 -24
- package/build-module/components/inspector-controls-tabs/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +4 -0
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +58 -4
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/media-upload-progress/constants.js +7 -0
- package/build-module/components/media-upload-progress/constants.js.map +1 -0
- package/build-module/components/media-upload-progress/index.native.js +37 -8
- package/build-module/components/media-upload-progress/index.native.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +9 -14
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/plain-text/index.native.js +6 -1
- package/build-module/components/plain-text/index.native.js.map +1 -1
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +7 -1
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/rich-text/index.js +17 -7
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +16 -23
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-input-rules.js +2 -2
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/rich-text/use-mark-persistent.js +1 -1
- package/build-module/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
- package/build-module/components/url-input/index.js +9 -6
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +14 -18
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +51 -23
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-moving-animation/index.js +102 -94
- package/build-module/components/use-moving-animation/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +8 -11
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/writing-flow/index.js +0 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-drag-selection.js +15 -4
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +73 -27
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +7 -4
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/align.js +1 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/anchor.js +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/aria-label.js +7 -1
- package/build-module/hooks/aria-label.js.map +1 -1
- package/build-module/hooks/background.js +181 -19
- package/build-module/hooks/background.js.map +1 -1
- package/build-module/hooks/border.js +2 -8
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +11 -9
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/custom-class-name.js +1 -1
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/custom-class-name.native.js +7 -1
- package/build-module/hooks/custom-class-name.native.js.map +1 -1
- package/build-module/hooks/dimensions.js +1 -7
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/font-family.js +6 -2
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +1 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/index.js +5 -5
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +6 -4
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/layout.js +9 -3
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +1 -1
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +1 -7
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/typography.native.js +43 -17
- package/build-module/hooks/typography.native.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +9 -1
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +47 -5
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +2 -4
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +0 -2
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/actions.js +0 -15
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +49 -4
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +11 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +14 -6
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +1 -12
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/undo-ignore.js +5 -0
- package/build-module/store/undo-ignore.js.map +1 -0
- package/build-module/store/utils.js +2 -2
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/get-px-from-css-unit.js +9 -0
- package/build-module/utils/get-px-from-css-unit.js.map +1 -0
- package/build-module/utils/index.js +1 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/object.js +16 -37
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/use-can-block-toolbar-be-focused.js +40 -0
- package/build-module/utils/use-can-block-toolbar-be-focused.js.map +1 -0
- package/build-style/content-rtl.css +7 -6
- package/build-style/content.css +7 -6
- package/build-style/style-rtl.css +51 -8
- package/build-style/style.css +51 -8
- package/package.json +31 -31
- package/src/components/alignment-control/README.md +0 -5
- package/src/components/block-alignment-control/README.md +0 -5
- package/src/components/block-alignment-matrix-control/README.md +0 -10
- package/src/components/block-breadcrumb/README.md +0 -5
- package/src/components/block-canvas/index.js +0 -2
- package/src/components/block-canvas/style.scss +6 -0
- package/src/components/block-caption/README.md +0 -5
- package/src/components/block-card/README.md +0 -5
- package/src/components/block-card/index.js +1 -1
- package/src/components/block-draggable/draggable-chip.js +11 -1
- package/src/components/block-draggable/index.js +116 -4
- package/src/components/block-draggable/index.native.js +0 -5
- package/src/components/block-draggable/style.scss +35 -0
- package/src/components/block-draggable/test/helpers.native.js +8 -7
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +1 -1
- package/src/components/block-editing-mode/index.js +3 -3
- package/src/components/block-icon/README.md +0 -5
- package/src/components/block-inspector/README.md +0 -5
- package/src/components/block-inspector/index.js +3 -1
- package/src/components/block-list/block-list-item-cell.native.js +5 -1
- package/src/components/block-list/block.js +290 -119
- package/src/components/block-list/block.native.js +55 -21
- package/src/components/block-list/content.scss +14 -10
- package/src/components/block-list/index.native.js +3 -5
- package/src/components/block-list/{block-list-block-context.js → private-block-context.js} +1 -1
- package/src/components/block-list/use-block-props/index.js +32 -128
- package/src/components/block-list/use-in-between-inserter.js +4 -1
- package/src/components/block-list/use-scroll-upon-insertion.native.js +52 -0
- package/src/components/block-lock/toolbar.js +23 -34
- package/src/components/block-mover/README.md +0 -5
- package/src/components/block-mover/index.js +1 -1
- package/src/components/block-parent-selector/README.md +0 -5
- package/src/components/block-patterns-list/README.md +0 -5
- package/src/components/block-patterns-list/index.js +8 -5
- package/src/components/block-switcher/index.js +49 -59
- package/src/components/block-toolbar/README.md +0 -5
- package/src/components/block-toolbar/index.js +1 -2
- package/src/components/block-tools/block-toolbar-popover.js +4 -10
- package/src/components/block-types-list/README.md +0 -5
- package/src/components/block-variation-picker/README.md +0 -5
- package/src/components/block-variation-transforms/README.md +0 -5
- package/src/components/block-variation-transforms/index.js +49 -3
- package/src/components/border-radius-control/linked-button.js +1 -1
- package/src/components/caption/README.md +0 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +0 -1
- package/src/components/colors/utils.js +8 -1
- package/src/components/colors/with-colors.js +3 -1
- package/src/components/contrast-checker/README.md +0 -4
- package/src/components/copy-handler/README.md +0 -10
- package/src/components/font-sizes/utils.js +7 -1
- package/src/components/global-styles/border-panel.js +2 -1
- package/src/components/global-styles/color-panel.js +2 -1
- package/src/components/global-styles/dimensions-panel.js +4 -3
- package/src/components/global-styles/effects-panel.js +2 -1
- package/src/components/global-styles/filters-panel.js +2 -5
- package/src/components/global-styles/get-global-styles-changes.js +210 -0
- package/src/components/global-styles/hooks.js +5 -0
- package/src/components/global-styles/image-settings-panel.js +6 -0
- package/src/components/global-styles/index.js +1 -0
- package/src/components/global-styles/test/get-global-styles-changes.js +234 -0
- package/src/components/global-styles/typography-panel.js +47 -14
- package/src/components/global-styles/use-global-styles-output.js +9 -5
- package/src/components/global-styles/utils.js +7 -0
- package/src/components/height-control/README.md +2 -7
- package/src/components/height-control/index.js +4 -0
- package/src/components/image-size-control/index.js +5 -2
- package/src/components/index.native.js +2 -2
- package/src/components/inner-blocks/index.js +68 -29
- package/src/components/inner-blocks/index.native.js +19 -7
- package/src/components/inner-blocks/use-inner-block-template-sync.js +5 -7
- package/src/components/inner-blocks/use-nested-settings-update.js +6 -13
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +2 -2
- package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +15 -15
- package/src/components/inserter/block-patterns-tab/patterns-filter.js +15 -13
- package/src/components/inserter/block-patterns-tab/use-pattern-categories.js +15 -18
- package/src/components/inserter/block-patterns-tab/utils.js +11 -12
- package/src/components/inserter/hooks/use-block-types-state.js +9 -11
- package/src/components/inserter/hooks/use-patterns-state.js +2 -2
- package/src/components/inserter/index.js +0 -1
- package/src/components/inserter/library.js +2 -8
- package/src/components/inserter/menu.js +13 -31
- package/src/components/inserter/style.scss +6 -4
- package/src/components/inserter/tabs.js +34 -25
- package/src/components/inserter-draggable-blocks/index.js +2 -2
- package/src/components/inserter-list-item/index.js +6 -6
- package/src/components/inspector-controls/block-support-tools-panel.js +2 -0
- package/src/components/inspector-controls-tabs/index.js +39 -28
- package/src/components/inspector-controls-tabs/style.scss +3 -2
- package/src/components/letter-spacing-control/README.md +0 -5
- package/src/components/line-height-control/README.md +0 -5
- package/src/components/list-view/README.md +0 -5
- package/src/components/list-view/block-select-button.js +4 -0
- package/src/components/list-view/block.js +73 -2
- package/src/components/list-view/style.scss +6 -0
- package/src/components/media-upload-progress/constants.js +6 -0
- package/src/components/media-upload-progress/index.native.js +66 -14
- package/src/components/media-upload-progress/test/index.native.js +2 -2
- package/src/components/multi-selection-inspector/README.md +0 -5
- package/src/components/navigable-toolbar/index.js +13 -11
- package/src/components/plain-text/index.native.js +6 -1
- package/src/components/provider/index.js +1 -1
- package/src/components/provider/test/use-block-sync.js +20 -17
- package/src/components/provider/use-block-sync.js +6 -0
- package/src/components/rich-text/index.js +18 -6
- package/src/components/rich-text/native/index.native.js +16 -24
- package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +3 -3
- package/src/components/rich-text/native/test/index.native.js +72 -5
- package/src/components/rich-text/use-input-rules.js +2 -2
- package/src/components/rich-text/use-mark-persistent.js +1 -2
- package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
- package/src/components/text-decoration-control/README.md +40 -0
- package/src/components/text-transform-control/README.md +0 -4
- package/src/components/ungroup-button/README.md +0 -5
- package/src/components/unit-control/README.md +0 -4
- package/src/components/url-input/index.js +11 -11
- package/src/components/use-block-commands/index.js +18 -21
- package/src/components/use-block-drop-zone/index.js +85 -34
- package/src/components/use-moving-animation/index.js +107 -103
- package/src/components/use-on-block-drop/index.js +7 -23
- package/src/components/use-on-block-drop/test/index.js +12 -26
- package/src/components/use-resize-canvas/README.md +0 -4
- package/src/components/use-settings/README.md +0 -4
- package/src/components/writing-flow/index.js +0 -1
- package/src/components/writing-flow/use-drag-selection.js +18 -4
- package/src/components/writing-flow/use-selection-observer.js +99 -37
- package/src/components/writing-flow/use-tab-nav.js +7 -7
- package/src/hooks/align.js +1 -5
- package/src/hooks/anchor.js +1 -5
- package/src/hooks/aria-label.js +8 -5
- package/src/hooks/background.js +253 -21
- package/src/hooks/border.js +2 -13
- package/src/hooks/color.js +19 -14
- package/src/hooks/custom-class-name.js +1 -5
- package/src/hooks/custom-class-name.native.js +8 -5
- package/src/hooks/dimensions.js +1 -7
- package/src/hooks/font-family.js +4 -7
- package/src/hooks/font-size.js +1 -6
- package/src/hooks/index.js +19 -5
- package/src/hooks/index.native.js +17 -4
- package/src/hooks/layout.js +5 -2
- package/src/hooks/style.js +1 -6
- package/src/hooks/test/anchor.js +4 -9
- package/src/hooks/test/custom-class-name.js +3 -8
- package/src/hooks/test/style.js +4 -14
- package/src/hooks/typography.js +1 -7
- package/src/hooks/typography.native.js +31 -33
- package/src/hooks/use-typography-props.js +7 -1
- package/src/hooks/utils.js +76 -6
- package/src/private-apis.js +2 -4
- package/src/private-apis.native.js +0 -2
- package/src/store/actions.js +0 -15
- package/src/store/private-actions.js +44 -4
- package/src/store/private-selectors.js +11 -0
- package/src/store/reducer.js +16 -5
- package/src/store/selectors.js +5 -13
- package/src/store/undo-ignore.js +4 -0
- package/src/store/utils.js +2 -2
- package/src/style.scss +1 -0
- package/src/utils/get-px-from-css-unit.js +8 -0
- package/src/utils/index.js +1 -1
- package/src/utils/object.js +16 -35
- package/src/utils/test/object.js +1 -96
- package/src/utils/use-can-block-toolbar-be-focused.js +48 -0
- package/build/components/block-list/block-list-block-context.js +0 -14
- package/build/components/block-list/block-list-block-context.js.map +0 -1
- package/build/hooks/custom-fields.js +0 -106
- package/build/hooks/custom-fields.js.map +0 -1
- package/build/utils/parse-css-unit-to-px.js +0 -302
- package/build/utils/parse-css-unit-to-px.js.map +0 -1
- package/build/utils/use-should-contextual-toolbar-show.js +0 -63
- package/build/utils/use-should-contextual-toolbar-show.js.map +0 -1
- package/build-module/components/block-list/block-list-block-context.js +0 -6
- package/build-module/components/block-list/block-list-block-context.js.map +0 -1
- package/build-module/hooks/custom-fields.js +0 -99
- package/build-module/hooks/custom-fields.js.map +0 -1
- package/build-module/utils/parse-css-unit-to-px.js +0 -294
- package/build-module/utils/parse-css-unit-to-px.js.map +0 -1
- package/build-module/utils/use-should-contextual-toolbar-show.js +0 -57
- package/build-module/utils/use-should-contextual-toolbar-show.js.map +0 -1
- package/src/hooks/custom-fields.js +0 -115
- package/src/utils/parse-css-unit-to-px.js +0 -329
- package/src/utils/test/parse-css-unit-to-px.js +0 -172
- package/src/utils/use-should-contextual-toolbar-show.js +0 -85
|
@@ -5,7 +5,7 @@ import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
|
|
|
5
5
|
import { useCallback, useState } from '@wordpress/element';
|
|
6
6
|
import { useThrottle, __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
|
|
7
7
|
import { isRTL } from '@wordpress/i18n';
|
|
8
|
-
import { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';
|
|
8
|
+
import { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock, store as blocksStore } from '@wordpress/blocks';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
@@ -131,6 +131,38 @@ export function getDropTargetPosition(blocksData, position, orientation = 'verti
|
|
|
131
131
|
return [isNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex, 'replace'];
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Check if the dragged blocks can be dropped on the target.
|
|
136
|
+
* @param {Function} getBlockType
|
|
137
|
+
* @param {Object[]} allowedBlocks
|
|
138
|
+
* @param {string[]} draggedBlockNames
|
|
139
|
+
* @param {string} targetBlockName
|
|
140
|
+
* @return {boolean} Whether the dragged blocks can be dropped on the target.
|
|
141
|
+
*/
|
|
142
|
+
export function isDropTargetValid(getBlockType, allowedBlocks, draggedBlockNames, targetBlockName) {
|
|
143
|
+
// At root level allowedBlocks is undefined and all blocks are allowed.
|
|
144
|
+
// Otherwise, check if all dragged blocks are allowed.
|
|
145
|
+
let areBlocksAllowed = true;
|
|
146
|
+
if (allowedBlocks) {
|
|
147
|
+
const allowedBlockNames = allowedBlocks?.map(({
|
|
148
|
+
name
|
|
149
|
+
}) => name);
|
|
150
|
+
areBlocksAllowed = draggedBlockNames.every(name => allowedBlockNames?.includes(name));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Work out if dragged blocks have an allowed parent and if so
|
|
154
|
+
// check target block matches the allowed parent.
|
|
155
|
+
const draggedBlockTypes = draggedBlockNames.map(name => getBlockType(name));
|
|
156
|
+
const targetMatchesDraggedBlockParents = draggedBlockTypes.every(block => {
|
|
157
|
+
const [allowedParentName] = block?.parent || [];
|
|
158
|
+
if (!allowedParentName) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return allowedParentName === targetBlockName;
|
|
162
|
+
});
|
|
163
|
+
return areBlocksAllowed && targetMatchesDraggedBlockParents;
|
|
164
|
+
}
|
|
165
|
+
|
|
134
166
|
/**
|
|
135
167
|
* @typedef {Object} WPBlockDropZoneConfig
|
|
136
168
|
* @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.
|
|
@@ -148,7 +180,9 @@ export default function useBlockDropZone({
|
|
|
148
180
|
// string for this so that `targetRootClientId` can be easily compared to
|
|
149
181
|
// values returned by the `getRootBlockClientId` selector, which also uses
|
|
150
182
|
// an empty string to represent top-level blocks.
|
|
151
|
-
rootClientId: targetRootClientId = ''
|
|
183
|
+
rootClientId: targetRootClientId = '',
|
|
184
|
+
parentClientId: parentBlockClientId = '',
|
|
185
|
+
isDisabled = false
|
|
152
186
|
} = {}) {
|
|
153
187
|
const registry = useRegistry();
|
|
154
188
|
const [dropTarget, setDropTarget] = useState({
|
|
@@ -156,28 +190,15 @@ export default function useBlockDropZone({
|
|
|
156
190
|
operation: 'insert'
|
|
157
191
|
});
|
|
158
192
|
const {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
rootBlockIndex
|
|
162
|
-
} = useSelect(select => {
|
|
163
|
-
const {
|
|
164
|
-
__unstableIsWithinBlockOverlay,
|
|
165
|
-
__unstableHasActiveBlockOverlayActive,
|
|
166
|
-
getBlockIndex,
|
|
167
|
-
getBlockParents,
|
|
168
|
-
getBlockEditingMode
|
|
169
|
-
} = select(blockEditorStore);
|
|
170
|
-
const blockEditingMode = getBlockEditingMode(targetRootClientId);
|
|
171
|
-
return {
|
|
172
|
-
parentBlockClientId: getBlockParents(targetRootClientId, true)[0] || '',
|
|
173
|
-
rootBlockIndex: getBlockIndex(targetRootClientId),
|
|
174
|
-
isDisabled: blockEditingMode !== 'default' || __unstableHasActiveBlockOverlayActive(targetRootClientId) || __unstableIsWithinBlockOverlay(targetRootClientId)
|
|
175
|
-
};
|
|
176
|
-
}, [targetRootClientId]);
|
|
193
|
+
getBlockType
|
|
194
|
+
} = useSelect(blocksStore);
|
|
177
195
|
const {
|
|
178
196
|
getBlockListSettings,
|
|
179
197
|
getBlocks,
|
|
180
|
-
getBlockIndex
|
|
198
|
+
getBlockIndex,
|
|
199
|
+
getDraggedBlockClientIds,
|
|
200
|
+
getBlockNamesByClientId,
|
|
201
|
+
getAllowedBlocks
|
|
181
202
|
} = useSelect(blockEditorStore);
|
|
182
203
|
const {
|
|
183
204
|
showInsertionPoint,
|
|
@@ -187,6 +208,13 @@ export default function useBlockDropZone({
|
|
|
187
208
|
operation: dropTarget.operation
|
|
188
209
|
});
|
|
189
210
|
const throttled = useThrottle(useCallback((event, ownerDocument) => {
|
|
211
|
+
const allowedBlocks = getAllowedBlocks(targetRootClientId);
|
|
212
|
+
const targetBlockName = getBlockNamesByClientId([targetRootClientId])[0];
|
|
213
|
+
const draggedBlockNames = getBlockNamesByClientId(getDraggedBlockClientIds());
|
|
214
|
+
const isBlockDroppingAllowed = isDropTargetValid(getBlockType, allowedBlocks, draggedBlockNames, targetBlockName);
|
|
215
|
+
if (!isBlockDroppingAllowed) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
190
218
|
const blocks = getBlocks(targetRootClientId);
|
|
191
219
|
|
|
192
220
|
// The block list is empty, don't show the insertion point but still allow dropping.
|
|
@@ -217,7 +245,7 @@ export default function useBlockDropZone({
|
|
|
217
245
|
dropZoneElement,
|
|
218
246
|
parentBlockClientId,
|
|
219
247
|
parentBlockOrientation: parentBlockClientId ? getBlockListSettings(parentBlockClientId)?.orientation : undefined,
|
|
220
|
-
rootBlockIndex
|
|
248
|
+
rootBlockIndex: getBlockIndex(targetRootClientId)
|
|
221
249
|
});
|
|
222
250
|
registry.batch(() => {
|
|
223
251
|
setDropTarget({
|
|
@@ -229,7 +257,7 @@ export default function useBlockDropZone({
|
|
|
229
257
|
operation
|
|
230
258
|
});
|
|
231
259
|
});
|
|
232
|
-
}, [
|
|
260
|
+
}, [getAllowedBlocks, targetRootClientId, getBlockNamesByClientId, getDraggedBlockClientIds, getBlockType, getBlocks, getBlockListSettings, dropZoneElement, parentBlockClientId, getBlockIndex, registry, showInsertionPoint]), 200);
|
|
233
261
|
return useDropZone({
|
|
234
262
|
dropZoneElement,
|
|
235
263
|
isDisabled,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","useSelect","useRegistry","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","store","blockEditorStore","THRESHOLD_DISTANCE","MINIMUM_HEIGHT_FOR_THRESHOLD","MINIMUM_WIDTH_FOR_THRESHOLD","getDropTargetPosition","blocksData","position","orientation","options","allowedEdges","nearestIndex","insertPosition","minDistance","Infinity","dropZoneElement","parentBlockOrientation","rootBlockIndex","rect","getBoundingClientRect","distance","edge","height","isRightToLeft","width","forEach","blockIndex","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","useBlockDropZone","rootClientId","targetRootClientId","registry","dropTarget","setDropTarget","index","operation","isDisabled","parentBlockClientId","select","__unstableIsWithinBlockOverlay","__unstableHasActiveBlockOverlayActive","getBlockIndex","getBlockParents","getBlockEditingMode","blockEditingMode","getBlockListSettings","getBlocks","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","blocks","length","batch","map","block","clientId","getElementById","targetIndex","x","clientX","y","clientY","undefined","insertionPointClientId","includes","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\nconst THRESHOLD_DISTANCE = 30;\nconst MINIMUM_HEIGHT_FOR_THRESHOLD = 120;\nconst MINIMUM_WIDTH_FOR_THRESHOLD = 120;\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @param {Object} options Additional options.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical',\n\toptions = {}\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\n\tconst {\n\t\tdropZoneElement,\n\t\tparentBlockOrientation,\n\t\trootBlockIndex = 0,\n\t} = options;\n\n\t// Allow before/after when dragging over the top/bottom edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation !== 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'top',\n\t\t\t'bottom',\n\t\t] );\n\n\t\t// If dragging over the top or bottom of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group or Cover.\n\t\tif (\n\t\t\trect.height > MINIMUM_HEIGHT_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif ( edge === 'top' ) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif ( edge === 'bottom' ) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isRightToLeft = isRTL();\n\n\t// Allow before/after when dragging over the left/right edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation === 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'left',\n\t\t\t'right',\n\t\t] );\n\n\t\t// If dragging over the left or right of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group.\n\t\tif (\n\t\t\trect.width > MINIMUM_WIDTH_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'left' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'left' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tblocksData.forEach(\n\t\t( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif (\n\t\t\t\tisUnmodifiedDefaultBlock &&\n\t\t\t\tisPointContainedByRect( position, rect )\n\t\t\t) {\n\t\t\t\tdistance = 0;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\tdropZoneElement,\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst registry = useRegistry();\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst { isDisabled, parentBlockClientId, rootBlockIndex } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\t__unstableIsWithinBlockOverlay,\n\t\t\t\t__unstableHasActiveBlockOverlayActive,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockParents,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst blockEditingMode = getBlockEditingMode( targetRootClientId );\n\t\t\treturn {\n\t\t\t\tparentBlockClientId:\n\t\t\t\t\tgetBlockParents( targetRootClientId, true )[ 0 ] || '',\n\t\t\t\trootBlockIndex: getBlockIndex( targetRootClientId ),\n\t\t\t\tisDisabled:\n\t\t\t\t\tblockEditingMode !== 'default' ||\n\t\t\t\t\t__unstableHasActiveBlockOverlayActive(\n\t\t\t\t\t\ttargetRootClientId\n\t\t\t\t\t) ||\n\t\t\t\t\t__unstableIsWithinBlockOverlay( targetRootClientId ),\n\t\t\t};\n\t\t},\n\t\t[ targetRootClientId ]\n\t);\n\n\tconst { getBlockListSettings, getBlocks, getBlockIndex } =\n\t\tuseSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop(\n\t\tdropTarget.operation === 'before' || dropTarget.operation === 'after'\n\t\t\t? parentBlockClientId\n\t\t\t: targetRootClientId,\n\t\tdropTarget.index,\n\t\t{\n\t\t\toperation: dropTarget.operation,\n\t\t}\n\t);\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tshowInsertionPoint( targetRootClientId, 0, {\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation ] = getDropTargetPosition(\n\t\t\t\t\tblocksData,\n\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\t\t{\n\t\t\t\t\t\tdropZoneElement,\n\t\t\t\t\t\tparentBlockClientId,\n\t\t\t\t\t\tparentBlockOrientation: parentBlockClientId\n\t\t\t\t\t\t\t? getBlockListSettings( parentBlockClientId )\n\t\t\t\t\t\t\t\t\t?.orientation\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\trootBlockIndex,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\n\t\t\t\t\tconst insertionPointClientId = [\n\t\t\t\t\t\t'before',\n\t\t\t\t\t\t'after',\n\t\t\t\t\t].includes( operation )\n\t\t\t\t\t\t? parentBlockClientId\n\t\t\t\t\t\t: targetRootClientId;\n\n\t\t\t\t\tshowInsertionPoint( insertionPointClientId, targetIndex, {\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tdropZoneElement,\n\t\t\t\tgetBlocks,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tregistry,\n\t\t\t\tshowInsertionPoint,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tparentBlockClientId,\n\t\t\t\trootBlockIndex,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tdropZoneElement,\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,WAAW,EACXC,yBAAyB,IAAIC,WAAW,QAClC,oBAAoB;AAC3B,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,wBAAwB,IAAIC,2BAA2B,QAAQ,mBAAmB;;AAE3F;AACA;AACA;AACA,OAAOC,cAAc,MAAM,sBAAsB;AACjD,SACCC,wBAAwB,EACxBC,sBAAsB,QAChB,kBAAkB;AACzB,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AAEvD,MAAMC,kBAAkB,GAAG,EAAE;AAC7B,MAAMC,4BAA4B,GAAG,GAAG;AACxC,MAAMC,2BAA2B,GAAG,GAAG;;AAEvC;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACpCC,UAAU,EACVC,QAAQ,EACRC,WAAW,GAAG,UAAU,EACxBC,OAAO,GAAG,CAAC,CAAC,EACX;EACD,MAAMC,YAAY,GACjBF,WAAW,KAAK,YAAY,GACzB,CAAE,MAAM,EAAE,OAAO,CAAE,GACnB,CAAE,KAAK,EAAE,QAAQ,CAAE;EAEvB,IAAIG,Y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ry","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","store","blocksStore","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","blockEditorStore","THRESHOLD_DISTANCE","MINIMUM_HEIGHT_FOR_THRESHOLD","MINIMUM_WIDTH_FOR_THRESHOLD","getDropTargetPosition","blocksData","position","orientation","options","allowedEdges","nearestIndex","insertPosition","minDistance","Infinity","dropZoneElement","parentBlockOrientation","rootBlockIndex","rect","getBoundingClientRect","distance","edge","height","isRightToLeft","width","forEach","blockIndex","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","isDropTargetValid","getBlockType","allowedBlocks","draggedBlockNames","targetBlockName","areBlocksAllowed","allowedBlockNames","map","name","every","includes","draggedBlockTypes","targetMatchesDraggedBlockParents","block","allowedParentName","parent","useBlockDropZone","rootClientId","targetRootClientId","parentClientId","parentBlockClientId","isDisabled","registry","dropTarget","setDropTarget","index","operation","getBlockListSettings","getBlocks","getBlockIndex","getDraggedBlockClientIds","getBlockNamesByClientId","getAllowedBlocks","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","isBlockDroppingAllowed","blocks","length","batch","clientId","getElementById","targetIndex","x","clientX","y","clientY","undefined","insertionPointClientId","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport {\n\tisUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\nconst THRESHOLD_DISTANCE = 30;\nconst MINIMUM_HEIGHT_FOR_THRESHOLD = 120;\nconst MINIMUM_WIDTH_FOR_THRESHOLD = 120;\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @param {Object} options Additional options.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical',\n\toptions = {}\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\n\tconst {\n\t\tdropZoneElement,\n\t\tparentBlockOrientation,\n\t\trootBlockIndex = 0,\n\t} = options;\n\n\t// Allow before/after when dragging over the top/bottom edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation !== 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'top',\n\t\t\t'bottom',\n\t\t] );\n\n\t\t// If dragging over the top or bottom of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group or Cover.\n\t\tif (\n\t\t\trect.height > MINIMUM_HEIGHT_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif ( edge === 'top' ) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif ( edge === 'bottom' ) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isRightToLeft = isRTL();\n\n\t// Allow before/after when dragging over the left/right edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation === 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'left',\n\t\t\t'right',\n\t\t] );\n\n\t\t// If dragging over the left or right of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group.\n\t\tif (\n\t\t\trect.width > MINIMUM_WIDTH_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'left' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'left' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tblocksData.forEach(\n\t\t( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif (\n\t\t\t\tisUnmodifiedDefaultBlock &&\n\t\t\t\tisPointContainedByRect( position, rect )\n\t\t\t) {\n\t\t\t\tdistance = 0;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * Check if the dragged blocks can be dropped on the target.\n * @param {Function} getBlockType\n * @param {Object[]} allowedBlocks\n * @param {string[]} draggedBlockNames\n * @param {string} targetBlockName\n * @return {boolean} Whether the dragged blocks can be dropped on the target.\n */\nexport function isDropTargetValid(\n\tgetBlockType,\n\tallowedBlocks,\n\tdraggedBlockNames,\n\ttargetBlockName\n) {\n\t// At root level allowedBlocks is undefined and all blocks are allowed.\n\t// Otherwise, check if all dragged blocks are allowed.\n\tlet areBlocksAllowed = true;\n\tif ( allowedBlocks ) {\n\t\tconst allowedBlockNames = allowedBlocks?.map( ( { name } ) => name );\n\n\t\tareBlocksAllowed = draggedBlockNames.every( ( name ) =>\n\t\t\tallowedBlockNames?.includes( name )\n\t\t);\n\t}\n\n\t// Work out if dragged blocks have an allowed parent and if so\n\t// check target block matches the allowed parent.\n\tconst draggedBlockTypes = draggedBlockNames.map( ( name ) =>\n\t\tgetBlockType( name )\n\t);\n\tconst targetMatchesDraggedBlockParents = draggedBlockTypes.every(\n\t\t( block ) => {\n\t\t\tconst [ allowedParentName ] = block?.parent || [];\n\t\t\tif ( ! allowedParentName ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn allowedParentName === targetBlockName;\n\t\t}\n\t);\n\n\treturn areBlocksAllowed && targetMatchesDraggedBlockParents;\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\tdropZoneElement,\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n\tparentClientId: parentBlockClientId = '',\n\tisDisabled = false,\n} = {} ) {\n\tconst registry = useRegistry();\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst { getBlockType } = useSelect( blocksStore );\n\tconst {\n\t\tgetBlockListSettings,\n\t\tgetBlocks,\n\t\tgetBlockIndex,\n\t\tgetDraggedBlockClientIds,\n\t\tgetBlockNamesByClientId,\n\t\tgetAllowedBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop(\n\t\tdropTarget.operation === 'before' || dropTarget.operation === 'after'\n\t\t\t? parentBlockClientId\n\t\t\t: targetRootClientId,\n\t\tdropTarget.index,\n\t\t{\n\t\t\toperation: dropTarget.operation,\n\t\t}\n\t);\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst allowedBlocks = getAllowedBlocks( targetRootClientId );\n\t\t\t\tconst targetBlockName = getBlockNamesByClientId( [\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t] )[ 0 ];\n\t\t\t\tconst draggedBlockNames = getBlockNamesByClientId(\n\t\t\t\t\tgetDraggedBlockClientIds()\n\t\t\t\t);\n\t\t\t\tconst isBlockDroppingAllowed = isDropTargetValid(\n\t\t\t\t\tgetBlockType,\n\t\t\t\t\tallowedBlocks,\n\t\t\t\t\tdraggedBlockNames,\n\t\t\t\t\ttargetBlockName\n\t\t\t\t);\n\t\t\t\tif ( ! isBlockDroppingAllowed ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tshowInsertionPoint( targetRootClientId, 0, {\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation ] = getDropTargetPosition(\n\t\t\t\t\tblocksData,\n\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\t\t{\n\t\t\t\t\t\tdropZoneElement,\n\t\t\t\t\t\tparentBlockClientId,\n\t\t\t\t\t\tparentBlockOrientation: parentBlockClientId\n\t\t\t\t\t\t\t? getBlockListSettings( parentBlockClientId )\n\t\t\t\t\t\t\t\t\t?.orientation\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\trootBlockIndex: getBlockIndex( targetRootClientId ),\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\n\t\t\t\t\tconst insertionPointClientId = [\n\t\t\t\t\t\t'before',\n\t\t\t\t\t\t'after',\n\t\t\t\t\t].includes( operation )\n\t\t\t\t\t\t? parentBlockClientId\n\t\t\t\t\t\t: targetRootClientId;\n\n\t\t\t\t\tshowInsertionPoint( insertionPointClientId, targetIndex, {\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tgetAllowedBlocks,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tgetBlockNamesByClientId,\n\t\t\t\tgetDraggedBlockClientIds,\n\t\t\t\tgetBlockType,\n\t\t\t\tgetBlocks,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tdropZoneElement,\n\t\t\t\tparentBlockClientId,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tregistry,\n\t\t\t\tshowInsertionPoint,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tdropZoneElement,\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,WAAW,EACXC,yBAAyB,IAAIC,WAAW,QAClC,oBAAoB;AAC3B,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SACCC,wBAAwB,IAAIC,2BAA2B,EACvDC,KAAK,IAAIC,WAAW,QACd,mBAAmB;;AAE1B;AACA;AACA;AACA,OAAOC,cAAc,MAAM,sBAAsB;AACjD,SACCC,wBAAwB,EACxBC,sBAAsB,QAChB,kBAAkB;AACzB,SAASJ,KAAK,IAAIK,gBAAgB,QAAQ,aAAa;AAEvD,MAAMC,kBAAkB,GAAG,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CAAC;IACrB;EACD,CAAE,CAAC;AACJ"}
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Controller } from '@react-spring/web';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import { useReducedMotion } from '@wordpress/compose';
|
|
9
|
+
import { useLayoutEffect, useMemo, useRef } from '@wordpress/element';
|
|
11
10
|
import { getScrollContainer } from '@wordpress/dom';
|
|
11
|
+
import { useSelect } from '@wordpress/data';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as blockEditorStore } from '../../store';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* If the block count exceeds the threshold, we disable the reordering animation
|
|
20
|
+
* to avoid laginess.
|
|
18
21
|
*/
|
|
19
|
-
const
|
|
20
|
-
|
|
22
|
+
const BLOCK_ANIMATION_THRESHOLD = 200;
|
|
23
|
+
function getAbsolutePosition(element) {
|
|
21
24
|
return {
|
|
22
25
|
top: element.offsetTop,
|
|
23
26
|
left: element.offsetLeft
|
|
24
27
|
};
|
|
25
|
-
}
|
|
28
|
+
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Hook used to compute the styles required to move a div into a new position.
|
|
@@ -35,107 +38,112 @@ const getAbsolutePosition = element => {
|
|
|
35
38
|
* - It uses the "resetAnimation" flag to reset the animation
|
|
36
39
|
* from the beginning in order to animate to the new destination point.
|
|
37
40
|
*
|
|
38
|
-
* @param {Object}
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {
|
|
41
|
-
* @param {boolean} $1.enableAnimation Enable/Disable animation.
|
|
42
|
-
* @param {*} $1.triggerAnimationOnChange Variable used to trigger the animation if it changes.
|
|
41
|
+
* @param {Object} $1 Options
|
|
42
|
+
* @param {*} $1.triggerAnimationOnChange Variable used to trigger the animation if it changes.
|
|
43
|
+
* @param {string} $1.clientId
|
|
43
44
|
*/
|
|
44
45
|
function useMovingAnimation({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
enableAnimation,
|
|
48
|
-
triggerAnimationOnChange
|
|
46
|
+
triggerAnimationOnChange,
|
|
47
|
+
clientId
|
|
49
48
|
}) {
|
|
50
49
|
const ref = useRef();
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
const {
|
|
51
|
+
isTyping,
|
|
52
|
+
getGlobalBlockCount,
|
|
53
|
+
isBlockSelected,
|
|
54
|
+
isFirstMultiSelectedBlock,
|
|
55
|
+
isBlockMultiSelected,
|
|
56
|
+
isAncestorMultiSelected
|
|
57
|
+
} = useSelect(blockEditorStore);
|
|
59
58
|
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
// Whenever the trigger changes, we need to take a snapshot of the current
|
|
60
|
+
// position of the block to use it as a destination point for the animation.
|
|
61
|
+
const {
|
|
62
|
+
previous,
|
|
63
|
+
prevRect
|
|
64
|
+
} = useMemo(() => ({
|
|
65
|
+
previous: ref.current && getAbsolutePosition(ref.current),
|
|
66
|
+
prevRect: ref.current && ref.current.getBoundingClientRect()
|
|
67
|
+
}),
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
[triggerAnimationOnChange]);
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
if (!previous || !ref.current) {
|
|
72
|
+
return;
|
|
65
73
|
}
|
|
66
74
|
const scrollContainer = getScrollContainer(ref.current);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const isSelected = isBlockSelected(clientId);
|
|
76
|
+
const adjustScrolling = isSelected || isFirstMultiSelectedBlock(clientId);
|
|
77
|
+
function preserveScrollPosition() {
|
|
78
|
+
if (adjustScrolling && prevRect) {
|
|
79
|
+
const blockRect = ref.current.getBoundingClientRect();
|
|
80
|
+
const diff = blockRect.top - prevRect.top;
|
|
81
|
+
if (diff) {
|
|
82
|
+
scrollContainer.scrollTop += diff;
|
|
83
|
+
}
|
|
76
84
|
}
|
|
77
|
-
};
|
|
78
|
-
}, [triggerAnimationOnChange, adjustScrolling]);
|
|
79
|
-
useLayoutEffect(() => {
|
|
80
|
-
if (triggeredAnimation) {
|
|
81
|
-
endAnimation();
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
|
|
87
|
+
// We disable the animation if the user has a preference for reduced
|
|
88
|
+
// motion, if the user is typing (insertion by Enter), or if the block
|
|
89
|
+
// count exceeds the threshold (insertion caused all the blocks that
|
|
90
|
+
// follow to animate).
|
|
91
|
+
// To do: consider enableing the _moving_ animation even for large
|
|
92
|
+
// posts, while only disabling the _insertion_ animation?
|
|
93
|
+
const disableAnimation = window.matchMedia('(prefers-reduced-motion: reduce)').matches || isTyping() || getGlobalBlockCount() > BLOCK_ANIMATION_THRESHOLD;
|
|
94
|
+
if (disableAnimation) {
|
|
89
95
|
// If the animation is disabled and the scroll needs to be adjusted,
|
|
90
96
|
// just move directly to the final scroll position.
|
|
91
97
|
preserveScrollPosition();
|
|
92
98
|
return;
|
|
93
99
|
}
|
|
100
|
+
const isPartOfSelection = isSelected || isBlockMultiSelected(clientId) || isAncestorMultiSelected(clientId);
|
|
101
|
+
// Make sure the other blocks move under the selected block(s).
|
|
102
|
+
const zIndex = isPartOfSelection ? '1' : '';
|
|
103
|
+
const controller = new Controller({
|
|
104
|
+
x: 0,
|
|
105
|
+
y: 0,
|
|
106
|
+
config: {
|
|
107
|
+
mass: 5,
|
|
108
|
+
tension: 2000,
|
|
109
|
+
friction: 200
|
|
110
|
+
},
|
|
111
|
+
onChange({
|
|
112
|
+
value
|
|
113
|
+
}) {
|
|
114
|
+
if (!ref.current) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let {
|
|
118
|
+
x,
|
|
119
|
+
y
|
|
120
|
+
} = value;
|
|
121
|
+
x = Math.round(x);
|
|
122
|
+
y = Math.round(y);
|
|
123
|
+
const finishedMoving = x === 0 && y === 0;
|
|
124
|
+
ref.current.style.transformOrigin = 'center center';
|
|
125
|
+
ref.current.style.transform = finishedMoving ? null // Set to `null` to explicitly remove the transform.
|
|
126
|
+
: `translate3d(${x}px,${y}px,0)`;
|
|
127
|
+
ref.current.style.zIndex = zIndex;
|
|
128
|
+
preserveScrollPosition();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
94
131
|
ref.current.style.transform = undefined;
|
|
95
132
|
const destination = getAbsolutePosition(ref.current);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
y: Math.round(previous.top - destination.top)
|
|
100
|
-
});
|
|
101
|
-
}, [triggerAnimationOnChange]);
|
|
102
|
-
function onChange({
|
|
103
|
-
value
|
|
104
|
-
}) {
|
|
105
|
-
if (!ref.current) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
let {
|
|
109
|
-
x,
|
|
110
|
-
y
|
|
111
|
-
} = value;
|
|
112
|
-
x = Math.round(x);
|
|
113
|
-
y = Math.round(y);
|
|
114
|
-
const finishedMoving = x === 0 && y === 0;
|
|
115
|
-
ref.current.style.transformOrigin = 'center center';
|
|
116
|
-
ref.current.style.transform = finishedMoving ? null // Set to `null` to explicitly remove the transform.
|
|
117
|
-
: `translate3d(${x}px,${y}px,0)`;
|
|
118
|
-
ref.current.style.zIndex = isSelected ? '1' : '';
|
|
119
|
-
preserveScrollPosition();
|
|
120
|
-
}
|
|
121
|
-
useSpring({
|
|
122
|
-
from: {
|
|
123
|
-
x: transform.x,
|
|
124
|
-
y: transform.y
|
|
125
|
-
},
|
|
126
|
-
to: {
|
|
133
|
+
const x = Math.round(previous.left - destination.left);
|
|
134
|
+
const y = Math.round(previous.top - destination.top);
|
|
135
|
+
controller.start({
|
|
127
136
|
x: 0,
|
|
128
|
-
y: 0
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
137
|
+
y: 0,
|
|
138
|
+
from: {
|
|
139
|
+
x,
|
|
140
|
+
y
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return () => {
|
|
144
|
+
controller.stop();
|
|
145
|
+
};
|
|
146
|
+
}, [previous, prevRect, clientId, isTyping, getGlobalBlockCount, isBlockSelected, isFirstMultiSelectedBlock, isBlockMultiSelected, isAncestorMultiSelected]);
|
|
139
147
|
return ref;
|
|
140
148
|
}
|
|
141
149
|
export default useMovingAnimation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Controller","useLayoutEffect","useMemo","useRef","getScrollContainer","useSelect","store","blockEditorStore","BLOCK_ANIMATION_THRESHOLD","getAbsolutePosition","element","top","offsetTop","left","offsetLeft","useMovingAnimation","triggerAnimationOnChange","clientId","ref","isTyping","getGlobalBlockCount","isBlockSelected","isFirstMultiSelectedBlock","isBlockMultiSelected","isAncestorMultiSelected","previous","prevRect","current","getBoundingClientRect","scrollContainer","isSelected","adjustScrolling","preserveScrollPosition","blockRect","diff","scrollTop","disableAnimation","window","matchMedia","matches","isPartOfSelection","zIndex","controller","x","y","config","mass","tension","friction","onChange","value","Math","round","finishedMoving","style","transformOrigin","transform","undefined","destination","start","from","stop"],"sources":["@wordpress/block-editor/src/components/use-moving-animation/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Controller } from '@react-spring/web';\n\n/**\n * WordPress dependencies\n */\nimport { useLayoutEffect, useMemo, useRef } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * If the block count exceeds the threshold, we disable the reordering animation\n * to avoid laginess.\n */\nconst BLOCK_ANIMATION_THRESHOLD = 200;\n\nfunction getAbsolutePosition( element ) {\n\treturn {\n\t\ttop: element.offsetTop,\n\t\tleft: element.offsetLeft,\n\t};\n}\n\n/**\n * Hook used to compute the styles required to move a div into a new position.\n *\n * The way this animation works is the following:\n * - It first renders the element as if there was no animation.\n * - It takes a snapshot of the position of the block to use it\n * as a destination point for the animation.\n * - It restores the element to the previous position using a CSS transform\n * - It uses the \"resetAnimation\" flag to reset the animation\n * from the beginning in order to animate to the new destination point.\n *\n * @param {Object} $1 Options\n * @param {*} $1.triggerAnimationOnChange Variable used to trigger the animation if it changes.\n * @param {string} $1.clientId\n */\nfunction useMovingAnimation( { triggerAnimationOnChange, clientId } ) {\n\tconst ref = useRef();\n\tconst {\n\t\tisTyping,\n\t\tgetGlobalBlockCount,\n\t\tisBlockSelected,\n\t\tisFirstMultiSelectedBlock,\n\t\tisBlockMultiSelected,\n\t\tisAncestorMultiSelected,\n\t} = useSelect( blockEditorStore );\n\n\t// Whenever the trigger changes, we need to take a snapshot of the current\n\t// position of the block to use it as a destination point for the animation.\n\tconst { previous, prevRect } = useMemo(\n\t\t() => ( {\n\t\t\tprevious: ref.current && getAbsolutePosition( ref.current ),\n\t\t\tprevRect: ref.current && ref.current.getBoundingClientRect(),\n\t\t} ),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[ triggerAnimationOnChange ]\n\t);\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! previous || ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst scrollContainer = getScrollContainer( ref.current );\n\t\tconst isSelected = isBlockSelected( clientId );\n\t\tconst adjustScrolling =\n\t\t\tisSelected || isFirstMultiSelectedBlock( clientId );\n\n\t\tfunction preserveScrollPosition() {\n\t\t\tif ( adjustScrolling && prevRect ) {\n\t\t\t\tconst blockRect = ref.current.getBoundingClientRect();\n\t\t\t\tconst diff = blockRect.top - prevRect.top;\n\n\t\t\t\tif ( diff ) {\n\t\t\t\t\tscrollContainer.scrollTop += diff;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We disable the animation if the user has a preference for reduced\n\t\t// motion, if the user is typing (insertion by Enter), or if the block\n\t\t// count exceeds the threshold (insertion caused all the blocks that\n\t\t// follow to animate).\n\t\t// To do: consider enableing the _moving_ animation even for large\n\t\t// posts, while only disabling the _insertion_ animation?\n\t\tconst disableAnimation =\n\t\t\twindow.matchMedia( '(prefers-reduced-motion: reduce)' ).matches ||\n\t\t\tisTyping() ||\n\t\t\tgetGlobalBlockCount() > BLOCK_ANIMATION_THRESHOLD;\n\n\t\tif ( disableAnimation ) {\n\t\t\t// If the animation is disabled and the scroll needs to be adjusted,\n\t\t\t// just move directly to the final scroll position.\n\t\t\tpreserveScrollPosition();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isPartOfSelection =\n\t\t\tisSelected ||\n\t\t\tisBlockMultiSelected( clientId ) ||\n\t\t\tisAncestorMultiSelected( clientId );\n\t\t// Make sure the other blocks move under the selected block(s).\n\t\tconst zIndex = isPartOfSelection ? '1' : '';\n\n\t\tconst controller = new Controller( {\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t\tconfig: { mass: 5, tension: 2000, friction: 200 },\n\t\t\tonChange( { value } ) {\n\t\t\t\tif ( ! ref.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet { x, y } = value;\n\t\t\t\tx = Math.round( x );\n\t\t\t\ty = Math.round( y );\n\t\t\t\tconst finishedMoving = x === 0 && y === 0;\n\t\t\t\tref.current.style.transformOrigin = 'center center';\n\t\t\t\tref.current.style.transform = finishedMoving\n\t\t\t\t\t? null // Set to `null` to explicitly remove the transform.\n\t\t\t\t\t: `translate3d(${ x }px,${ y }px,0)`;\n\t\t\t\tref.current.style.zIndex = zIndex;\n\t\t\t\tpreserveScrollPosition();\n\t\t\t},\n\t\t} );\n\n\t\tref.current.style.transform = undefined;\n\t\tconst destination = getAbsolutePosition( ref.current );\n\n\t\tconst x = Math.round( previous.left - destination.left );\n\t\tconst y = Math.round( previous.top - destination.top );\n\n\t\tcontroller.start( { x: 0, y: 0, from: { x, y } } );\n\n\t\treturn () => {\n\t\t\tcontroller.stop();\n\t\t};\n\t}, [\n\t\tprevious,\n\t\tprevRect,\n\t\tclientId,\n\t\tisTyping,\n\t\tgetGlobalBlockCount,\n\t\tisBlockSelected,\n\t\tisFirstMultiSelectedBlock,\n\t\tisBlockMultiSelected,\n\t\tisAncestorMultiSelected,\n\t] );\n\n\treturn ref;\n}\n\nexport default useMovingAnimation;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,mBAAmB;;AAE9C;AACA;AACA;AACA,SAASC,eAAe,EAAEC,OAAO,EAAEC,MAAM,QAAQ,oBAAoB;AACrE,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAAG,GAAG;AAErC,SAASC,mBAAmBA,CAAEC,OAAO,EAAG;EACvC,OAAO;IACNC,GAAG,EAAED,OAAO,CAACE,SAAS;IACtBC,IAAI,EAAEH,OAAO,CAACI;EACf,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAAE;EAAEC,wBAAwB;EAAEC;AAAS,CAAC,EAAG;EACrE,MAAMC,GAAG,GAAGf,MAAM,CAAC,CAAC;EACpB,MAAM;IACLgB,QAA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AAI,CAACC,KAAK,CAAE3B,QAAQ,CAACZ,IAAI,GAAG6C,WAAW,CAAC7C,IAAK,CAAC;IACxD,MAAM+B,CAAC,GAAGO,IAAI,CAACC,KAAK,CAAE3B,QAAQ,CAACd,GAAG,GAAG+C,WAAW,CAAC/C,GAAI,CAAC;IAEtD+B,UAAU,CAACiB,KAAK,CAAE;MAAEhB,CAAC,EAAE,CAAC;MAAEC,CAAC,EAAE,CAAC;MAAEgB,IAAI,EAAE;QAAEjB,CAAC;QAAEC;MAAE;IAAE,CAAE,CAAC;IAElD,OAAO,MAAM;MACZF,UAAU,CAACmB,IAAI,CAAC,CAAC;IAClB,CAAC;EACF,CAAC,EAAE,CACFpC,QAAQ,EACRC,QAAQ,EACRT,QAAQ,EACRE,QAAQ,EACRC,mBAAmB,EACnBC,eAAe,EACfC,yBAAyB,EACzBC,oBAAoB,EACpBC,uBAAuB,CACtB,CAAC;EAEH,OAAON,GAAG;AACX;AAEA,eAAeH,kBAAkB"}
|
|
@@ -99,17 +99,16 @@ export function onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex,
|
|
|
99
99
|
* A function that returns an event handler function for block-related file drop events.
|
|
100
100
|
*
|
|
101
101
|
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {boolean} hasUploadPermissions Whether the user has upload permissions.
|
|
102
|
+
* @param {Function} getSettings A function that gets the block editor settings.
|
|
104
103
|
* @param {Function} updateBlockAttributes A function that updates a block's attributes.
|
|
105
104
|
* @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.
|
|
106
105
|
* @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
|
|
107
106
|
*
|
|
108
107
|
* @return {Function} The event handler for a block-related file drop event.
|
|
109
108
|
*/
|
|
110
|
-
export function onFilesDrop(targetRootClientId,
|
|
109
|
+
export function onFilesDrop(targetRootClientId, getSettings, updateBlockAttributes, canInsertBlockType, insertOrReplaceBlocks) {
|
|
111
110
|
return files => {
|
|
112
|
-
if (!
|
|
111
|
+
if (!getSettings().mediaUpload) {
|
|
113
112
|
return;
|
|
114
113
|
}
|
|
115
114
|
const transformation = findTransform(getBlockTransforms('from'), transform => transform.type === 'files' && canInsertBlockType(transform.blockName, targetRootClientId) && transform.isMatch(files));
|
|
@@ -123,13 +122,11 @@ export function onFilesDrop(targetRootClientId, targetBlockIndex, hasUploadPermi
|
|
|
123
122
|
/**
|
|
124
123
|
* A function that returns an event handler function for block-related HTML drop events.
|
|
125
124
|
*
|
|
126
|
-
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
|
|
127
|
-
* @param {number} targetBlockIndex The index where the block(s) will be inserted.
|
|
128
125
|
* @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
|
|
129
126
|
*
|
|
130
127
|
* @return {Function} The event handler for a block-related HTML drop event.
|
|
131
128
|
*/
|
|
132
|
-
export function onHTMLDrop(
|
|
129
|
+
export function onHTMLDrop(insertOrReplaceBlocks) {
|
|
133
130
|
return HTML => {
|
|
134
131
|
const blocks = pasteHandler({
|
|
135
132
|
HTML,
|
|
@@ -155,13 +152,13 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, opt
|
|
|
155
152
|
const {
|
|
156
153
|
operation = 'insert'
|
|
157
154
|
} = options;
|
|
158
|
-
const hasUploadPermissions = useSelect(select => select(blockEditorStore).getSettings().mediaUpload, []);
|
|
159
155
|
const {
|
|
160
156
|
canInsertBlockType,
|
|
161
157
|
getBlockIndex,
|
|
162
158
|
getClientIdsOfDescendants,
|
|
163
159
|
getBlockOrder,
|
|
164
|
-
getBlocksByClientId
|
|
160
|
+
getBlocksByClientId,
|
|
161
|
+
getSettings
|
|
165
162
|
} = useSelect(blockEditorStore);
|
|
166
163
|
const {
|
|
167
164
|
insertBlocks,
|
|
@@ -197,8 +194,8 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, opt
|
|
|
197
194
|
}
|
|
198
195
|
}, [operation, getBlockOrder, getBlocksByClientId, moveBlocksToPosition, registry, removeBlocks, replaceBlocks, targetBlockIndex, targetRootClientId]);
|
|
199
196
|
const _onDrop = onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock);
|
|
200
|
-
const _onFilesDrop = onFilesDrop(targetRootClientId,
|
|
201
|
-
const _onHTMLDrop = onHTMLDrop(
|
|
197
|
+
const _onFilesDrop = onFilesDrop(targetRootClientId, getSettings, updateBlockAttributes, canInsertBlockType, insertOrReplaceBlocks);
|
|
198
|
+
const _onHTMLDrop = onHTMLDrop(insertOrReplaceBlocks);
|
|
202
199
|
return event => {
|
|
203
200
|
const files = getFilesFromDataTransfer(event.dataTransfer);
|
|
204
201
|
const html = event.dataTransfer.getData('text/html');
|