@wordpress/block-editor 9.0.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -0
- package/build/autocompleters/block.js +3 -1
- package/build/autocompleters/block.js.map +1 -1
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-alignment-matrix-control/index.js +4 -13
- package/build/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-content-overlay/index.js +4 -82
- package/build/components/block-content-overlay/index.js.map +1 -1
- package/build/components/block-context/index.js.map +1 -1
- package/build/components/block-controls/hook.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.native.js +65 -0
- package/build/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js +157 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/index.native.js +488 -0
- package/build/components/block-draggable/index.native.js.map +1 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js +130 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build/components/block-list/block-list-context.native.js +195 -0
- package/build/components/block-list/block-list-context.native.js.map +1 -0
- package/build/components/block-list/block-list-item-cell.native.js +67 -0
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build/components/block-list/block-list-item.native.js +12 -9
- package/build/components/block-list/block-list-item.native.js.map +1 -1
- package/build/components/block-list/block-selection-button.native.js.map +1 -1
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +27 -5
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.js +34 -32
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/index.native.js +75 -23
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +8 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-custom-class-name.js.map +1 -1
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-list-appender/index.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/index.native.js +10 -3
- package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.native.js +17 -4
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +1 -1
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +19 -8
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +5 -16
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +1 -1
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-mode-toggle.js +3 -7
- package/build/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +6 -3
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +6 -3
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/menu-items.js +3 -7
- package/build/components/block-styles/menu-items.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-toolbar/index.native.js.map +1 -1
- package/build/components/block-toolbar/utils.js +5 -8
- package/build/components/block-toolbar/utils.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +1 -0
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +1 -29
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/block-types-list/index.native.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +16 -2
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/border-radius-control/input-controls.js +10 -3
- package/build/components/border-radius-control/input-controls.js.map +1 -1
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +122 -41
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +35 -60
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/convert-to-group-buttons/toolbar.js +22 -5
- package/build/components/convert-to-group-buttons/toolbar.js.map +1 -1
- package/build/components/copy-handler/index.js +17 -1
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/default-block-appender/index.js.map +1 -1
- package/build/components/default-block-appender/index.native.js.map +1 -1
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/iframe/index.js +51 -50
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +3 -1
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +3 -1
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +31 -13
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/index.native.js +1 -1
- package/build/components/inserter/index.native.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.map +1 -1
- package/build/components/inserter/menu.native.js.map +1 -1
- package/build/components/inserter/no-results.native.js.map +1 -1
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-items.js +1 -1
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inspector-popover-header/index.js +56 -0
- package/build/components/inspector-popover-header/index.js.map +1 -0
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/constants.js +11 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/index.js +4 -4
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-create-button.js +1 -3
- package/build/components/link-control/search-create-button.js.map +1 -1
- package/build/components/link-control/search-input.js +5 -3
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/search-results.js +4 -3
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +3 -7
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/use-search-handler.js +4 -4
- package/build/components/link-control/use-search-handler.js.map +1 -1
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +0 -1
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/list-view/utils.js +1 -7
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/media-placeholder/index.js +4 -6
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +20 -7
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/media-upload/index.native.js +10 -4
- package/build/components/media-upload/index.native.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +12 -2
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/plain-text/index.native.js +62 -7
- package/build/components/plain-text/index.native.js.map +1 -1
- package/build/components/preview-options/index.js +4 -0
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +5 -3
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/publish-date-time-picker/index.js +53 -0
- package/build/components/publish-date-time-picker/index.js.map +1 -0
- package/build/components/rich-text/embed-handler-picker.native.js +4 -8
- package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +0 -1
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +2 -2
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +5 -1
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/ungroup-button/index.native.js +3 -7
- package/build/components/ungroup-button/index.native.js.map +1 -1
- package/build/components/url-input/index.js +18 -4
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.native.js +167 -0
- package/build/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build/components/use-display-block-controls/index.native.js.map +1 -1
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.native.js +95 -0
- package/build/components/use-on-block-drop/index.native.js.map +1 -0
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/warning/index.js +6 -1
- package/build/components/warning/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +12 -12
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js.map +1 -1
- package/build/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build/components/writing-flow/use-input.js +15 -0
- package/build/components/writing-flow/use-input.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-select-all.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/elements/index.js +9 -0
- package/build/elements/index.js.map +1 -0
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +2 -7
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +14 -7
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color-panel.native.js.map +1 -1
- package/build/hooks/color.js +8 -88
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/dimensions.js +14 -4
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +38 -1
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +14 -13
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +6 -2
- package/build/hooks/typography.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/layouts/flex.js +5 -2
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +14 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +17 -2
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +30 -2
- package/build/store/selectors.js.map +1 -1
- package/build/utils/pasting.js.map +1 -1
- package/build/utils/transform-styles/transforms/wrap.js.map +1 -1
- package/build-module/autocompleters/block.js +4 -1
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-alignment-matrix-control/index.js +3 -11
- package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-content-overlay/index.js +3 -78
- package/build-module/components/block-content-overlay/index.js.map +1 -1
- package/build-module/components/block-context/index.js.map +1 -1
- package/build-module/components/block-controls/hook.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.native.js +51 -0
- package/build-module/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js +137 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/index.native.js +453 -0
- package/build-module/components/block-draggable/index.native.js.map +1 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js +120 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build-module/components/block-list/block-list-context.native.js +179 -0
- package/build-module/components/block-list/block-list-context.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item-cell.native.js +59 -0
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item.native.js +12 -9
- package/build-module/components/block-list/block-list-item.native.js.map +1 -1
- package/build-module/components/block-list/block-selection-button.native.js.map +1 -1
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +26 -5
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.js +35 -33
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +72 -23
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +9 -5
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-custom-class-name.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-list-appender/index.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/index.native.js +9 -3
- package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +18 -5
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +1 -1
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +19 -8
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +5 -15
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +1 -1
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-mode-toggle.js +3 -5
- package/build-module/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +9 -3
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +5 -2
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/menu-items.js +3 -5
- package/build-module/components/block-styles/menu-items.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-toolbar/utils.js +3 -5
- package/build-module/components/block-toolbar/utils.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +1 -0
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +2 -29
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/block-types-list/index.native.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +13 -2
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/border-radius-control/input-controls.js +11 -4
- package/build-module/components/border-radius-control/input-controls.js.map +1 -1
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +124 -43
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +36 -64
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/toolbar.js +23 -6
- package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -1
- package/build-module/components/copy-handler/index.js +18 -2
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/default-block-appender/index.js.map +1 -1
- package/build-module/components/default-block-appender/index.native.js.map +1 -1
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/iframe/index.js +52 -51
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +2 -1
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +4 -1
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +4 -2
- package/build-module/components/index.js.map +1 -1
- 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.map +1 -1
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +1 -1
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/library.js +2 -5
- package/build-module/components/inserter/library.js.map +1 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/menu.native.js.map +1 -1
- package/build-module/components/inserter/no-results.native.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-items.js +2 -2
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inspector-popover-header/index.js +46 -0
- package/build-module/components/inspector-popover-header/index.js.map +1 -0
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/constants.js +5 -0
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/index.js +2 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-create-button.js +1 -2
- package/build-module/components/link-control/search-create-button.js.map +1 -1
- package/build-module/components/link-control/search-input.js +3 -1
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -4
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +2 -5
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/use-search-handler.js +5 -5
- package/build-module/components/link-control/use-search-handler.js.map +1 -1
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +0 -1
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/list-view/utils.js +1 -6
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +2 -3
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +22 -9
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/media-upload/index.native.js +8 -3
- package/build-module/components/media-upload/index.native.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +12 -2
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/plain-text/index.native.js +63 -8
- package/build-module/components/plain-text/index.native.js.map +1 -1
- package/build-module/components/preview-options/index.js +4 -0
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +4 -1
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/publish-date-time-picker/index.js +40 -0
- package/build-module/components/publish-date-time-picker/index.js.map +1 -0
- package/build-module/components/rich-text/embed-handler-picker.native.js +3 -5
- package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +0 -1
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +2 -2
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +5 -1
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/rich-text/use-mark-persistent.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/ungroup-button/index.native.js +3 -5
- package/build-module/components/ungroup-button/index.native.js.map +1 -1
- package/build-module/components/url-input/index.js +15 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.native.js +148 -0
- package/build-module/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build-module/components/use-display-block-controls/index.native.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.native.js +83 -0
- package/build-module/components/use-on-block-drop/index.native.js.map +1 -0
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/warning/index.js +6 -1
- package/build-module/components/warning/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +12 -11
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-input.js +15 -0
- package/build-module/components/writing-flow/use-input.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-select-all.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/elements/index.js +2 -0
- package/build-module/elements/index.js.map +1 -0
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +2 -7
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +11 -6
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color-panel.native.js.map +1 -1
- package/build-module/hooks/color.js +8 -88
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/dimensions.js +14 -4
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +39 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +15 -14
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +6 -2
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flex.js +4 -2
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +12 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +17 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +25 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/pasting.js.map +1 -1
- package/build-module/utils/transform-styles/transforms/wrap.js.map +1 -1
- package/build-style/style-rtl.css +79 -197
- package/build-style/style.css +79 -197
- package/package.json +30 -30
- package/src/autocompleters/block.js +2 -1
- package/src/components/block-actions/index.js +2 -3
- package/src/components/block-alignment-control/ui.js +4 -6
- package/src/components/block-alignment-matrix-control/index.js +3 -9
- package/src/components/block-breadcrumb/index.js +2 -5
- package/src/components/block-compare/test/block-view.js +2 -1
- package/src/components/block-content-overlay/index.js +10 -100
- package/src/components/block-content-overlay/style.scss +2 -11
- package/src/components/block-context/index.js +4 -4
- package/src/components/block-controls/hook.js +2 -3
- package/src/components/block-draggable/draggable-chip.native.js +49 -0
- package/src/components/block-draggable/dropping-insertion-point.native.js +181 -0
- package/src/components/block-draggable/dropping-insertion-point.native.scss +8 -0
- package/src/components/block-draggable/index.js +6 -13
- package/src/components/block-draggable/index.native.js +454 -0
- package/src/components/block-draggable/style.native.scss +19 -0
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +73 -0
- package/src/components/block-draggable/test/helpers.native.js +183 -0
- package/src/components/block-draggable/test/index.native.js +493 -0
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +135 -0
- package/src/components/block-edit/test/edit.js +2 -1
- package/src/components/block-list/block-list-context.native.js +175 -0
- package/src/components/block-list/block-list-item-cell.native.js +49 -0
- package/src/components/block-list/block-list-item.native.js +11 -23
- package/src/components/block-list/block-selection-button.native.js +2 -3
- package/src/components/block-list/block.js +8 -10
- package/src/components/block-list/block.native.js +47 -23
- package/src/components/block-list/index.js +46 -47
- package/src/components/block-list/index.native.js +63 -31
- package/src/components/block-list/test/block-list-context.native.js +245 -0
- package/src/components/block-list/test/fixtures/block-list-context.native.js +79 -0
- package/src/components/block-list/use-block-props/index.js +16 -8
- package/src/components/block-list/use-block-props/use-block-custom-class-name.js +2 -3
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +2 -3
- package/src/components/block-list/use-in-between-inserter.js +3 -4
- package/src/components/block-list-appender/index.js +2 -5
- package/src/components/block-list-appender/index.native.js +2 -3
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
- package/src/components/block-mobile-toolbar/index.native.js +9 -1
- package/src/components/block-mover/button.js +2 -3
- package/src/components/block-mover/index.native.js +26 -12
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +10 -0
- package/src/components/block-parent-selector/index.js +2 -3
- package/src/components/block-pattern-setup/index.js +3 -5
- package/src/components/block-popover/inbetween.js +21 -8
- package/src/components/block-popover/index.js +2 -16
- package/src/components/block-popover/style.scss +1 -0
- package/src/components/block-preview/auto.js +4 -8
- package/src/components/block-preview/index.js +1 -4
- package/src/components/block-selection-clearer/index.js +2 -3
- package/src/components/block-settings-menu/block-mode-toggle.js +4 -8
- package/src/components/block-settings-menu/block-settings-dropdown.js +9 -9
- package/src/components/block-styles/index.js +3 -1
- package/src/components/block-styles/menu-items.js +2 -5
- package/src/components/block-switcher/block-transformations-menu.js +2 -4
- package/src/components/block-switcher/style.scss +2 -39
- package/src/components/block-toolbar/index.native.js +2 -5
- package/src/components/block-toolbar/utils.js +3 -11
- package/src/components/block-tools/block-contextual-toolbar.js +2 -5
- package/src/components/block-tools/block-selection-button.js +1 -0
- package/src/components/block-tools/index.js +2 -3
- package/src/components/block-tools/selected-block-popover.js +1 -36
- package/src/components/block-tools/style.scss +1 -12
- package/src/components/block-types-list/index.native.js +2 -4
- package/src/components/block-variation-transforms/index.js +10 -8
- package/src/components/border-radius-control/input-controls.js +16 -8
- package/src/components/border-radius-control/style.scss +3 -2
- package/src/components/color-palette/test/control.js +2 -1
- package/src/components/color-style-selector/index.js +27 -28
- package/src/components/colors/test/with-colors.js +14 -14
- package/src/components/colors/with-colors.js +8 -12
- package/src/components/colors-gradients/dropdown.js +135 -62
- package/src/components/colors-gradients/panel-color-gradient-settings.js +30 -76
- package/src/components/colors-gradients/style.scss +52 -50
- package/src/components/colors-gradients/test/control.js +10 -10
- package/src/components/convert-to-group-buttons/toolbar.js +32 -19
- package/src/components/copy-handler/README.md +7 -2
- package/src/components/copy-handler/index.js +26 -6
- package/src/components/default-block-appender/index.js +4 -6
- package/src/components/default-block-appender/index.native.js +4 -9
- package/src/components/default-style-picker/index.js +20 -21
- package/src/components/duotone-control/style.scss +1 -7
- package/src/components/font-sizes/with-font-sizes.js +2 -3
- package/src/components/iframe/index.js +62 -54
- package/src/components/image-editor/aspect-ratio-dropdown.js +2 -6
- package/src/components/image-editor/use-save-image.js +2 -1
- package/src/components/image-size-control/index.js +4 -7
- package/src/components/index.js +4 -2
- package/src/components/inner-blocks/use-inner-block-template-sync.js +2 -3
- package/src/components/inner-blocks/use-nested-settings-update.js +6 -9
- package/src/components/inserter/block-types-tab.native.js +2 -3
- package/src/components/inserter/hooks/use-block-type-impressions.native.js +2 -3
- package/src/components/inserter/hooks/use-insertion-point.js +3 -2
- package/src/components/inserter/hooks/use-patterns-state.js +4 -5
- package/src/components/inserter/index.js +4 -6
- package/src/components/inserter/index.native.js +7 -12
- package/src/components/inserter/library.js +2 -5
- package/src/components/inserter/menu.js +14 -19
- package/src/components/inserter/menu.native.js +8 -6
- package/src/components/inserter/no-results.native.js +2 -1
- package/src/components/inserter/quick-inserter.js +2 -3
- package/src/components/inserter/search-items.js +6 -6
- package/src/components/inserter/search-results.native.js +4 -6
- package/src/components/inserter/style.scss +2 -1
- package/src/components/inspector-popover-header/README.md +76 -0
- package/src/components/inspector-popover-header/index.js +56 -0
- package/src/components/inspector-popover-header/style.scss +16 -0
- package/src/components/line-height-control/index.js +1 -2
- package/src/components/link-control/constants.js +11 -0
- package/src/components/link-control/index.js +4 -4
- package/src/components/link-control/search-create-button.js +4 -2
- package/src/components/link-control/search-input.js +3 -1
- package/src/components/link-control/search-results.js +4 -5
- package/src/components/link-control/settings-drawer.js +2 -5
- package/src/components/link-control/test/fixtures/index.js +3 -4
- package/src/components/link-control/test/index.js +24 -36
- package/src/components/link-control/use-search-handler.js +13 -7
- package/src/components/list-view/block-contents.js +2 -4
- package/src/components/list-view/branch.js +22 -23
- package/src/components/list-view/drop-indicator.js +0 -1
- package/src/components/list-view/index.js +4 -8
- package/src/components/list-view/style.scss +2 -1
- package/src/components/list-view/use-block-selection.js +5 -5
- package/src/components/list-view/use-list-view-drop-zone.js +2 -1
- package/src/components/list-view/utils.js +1 -6
- package/src/components/media-placeholder/index.js +2 -3
- package/src/components/media-replace-flow/index.js +77 -48
- package/src/components/media-upload/index.native.js +6 -2
- package/src/components/media-upload/test/index.native.js +31 -6
- package/src/components/navigable-toolbar/index.js +13 -4
- package/src/components/panel-color-settings/test/index.js +2 -1
- package/src/components/plain-text/index.native.js +60 -8
- package/src/components/preview-options/index.js +4 -0
- package/src/components/preview-options/style.scss +0 -4
- package/src/components/provider/use-block-sync.js +5 -2
- package/src/components/publish-date-time-picker/README.md +52 -0
- package/src/components/publish-date-time-picker/index.js +39 -0
- package/src/components/responsive-block-control/test/index.js +3 -2
- package/src/components/rich-text/embed-handler-picker.native.js +2 -5
- package/src/components/rich-text/format-toolbar-container.js +0 -1
- package/src/components/rich-text/index.js +10 -5
- package/src/components/rich-text/index.native.js +4 -0
- package/src/components/rich-text/style.scss +2 -8
- package/src/components/rich-text/use-format-types.js +16 -16
- package/src/components/rich-text/use-mark-persistent.js +2 -3
- package/src/components/skip-to-selected-block/index.js +2 -3
- package/src/components/ungroup-button/index.native.js +4 -8
- package/src/components/url-input/index.js +24 -21
- package/src/components/use-block-display-information/index.js +4 -6
- package/src/components/use-block-drop-zone/index.js +2 -3
- package/src/components/use-block-drop-zone/index.native.js +171 -0
- package/src/components/use-block-drop-zone/test/index.js +22 -23
- package/src/components/use-display-block-controls/index.native.js +2 -3
- package/src/components/use-no-recursive-renders/test/use-no-recursive-renders.js +2 -3
- package/src/components/use-on-block-drop/index.js +2 -5
- package/src/components/use-on-block-drop/index.native.js +115 -0
- package/src/components/use-setting/index.js +8 -6
- package/src/components/warning/index.js +47 -42
- package/src/components/warning/test/__snapshots__/index.js.snap +15 -6
- package/src/components/warning/test/index.js +1 -1
- package/src/components/writing-flow/test/index.js +22 -4
- package/src/components/writing-flow/use-arrow-nav.js +22 -10
- package/src/components/writing-flow/use-click-selection.js +2 -5
- package/src/components/writing-flow/use-drag-selection.js +6 -9
- package/src/components/writing-flow/use-input.js +12 -0
- package/src/components/writing-flow/use-multi-selection.js +2 -4
- package/src/components/writing-flow/use-select-all.js +2 -5
- package/src/components/writing-flow/use-selection-observer.js +4 -6
- package/src/components/writing-flow/use-tab-nav.js +2 -5
- package/src/elements/index.js +1 -0
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +2 -11
- package/src/hooks/border.scss +0 -48
- package/src/hooks/color-panel.js +17 -13
- package/src/hooks/color-panel.native.js +2 -2
- package/src/hooks/color.js +7 -76
- package/src/hooks/color.scss +5 -58
- package/src/hooks/dimensions.js +11 -3
- package/src/hooks/font-family.js +4 -2
- package/src/hooks/gap.js +2 -3
- package/src/hooks/layout.js +54 -4
- package/src/hooks/style.js +25 -39
- package/src/hooks/test/align.js +2 -1
- package/src/hooks/test/generated-class-name.js +2 -5
- package/src/hooks/test/utils.js +2 -5
- package/src/hooks/typography.js +2 -0
- package/src/index.js +1 -0
- package/src/layouts/flex.js +11 -3
- package/src/store/actions.js +784 -728
- package/src/store/reducer.js +202 -178
- package/src/store/selectors.js +82 -54
- package/src/store/test/actions.js +2 -1
- package/src/store/test/reducer.js +8 -1
- package/src/store/test/selectors.js +17 -21
- package/src/style.scss +1 -1
- package/src/utils/pasting.js +3 -3
- package/src/utils/transform-styles/transforms/wrap.js +30 -28
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/colors/color-panel.js +0 -82
- package/build/components/colors/color-panel.js.map +0 -1
- package/build/components/colors/color-panel.native.js +0 -11
- package/build/components/colors/color-panel.native.js.map +0 -1
- package/build/components/colors-gradients/tools-panel-color-dropdown.js +0 -89
- package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/build-module/components/colors/color-panel.js +0 -70
- package/build-module/components/colors/color-panel.js.map +0 -1
- package/build-module/components/colors/color-panel.native.js +0 -4
- package/build-module/components/colors/color-panel.native.js.map +0 -1
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +0 -75
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/src/components/block-alignment-matrix-control/style.scss +0 -10
- package/src/components/colors/color-panel.js +0 -91
- package/src/components/colors/color-panel.native.js +0 -3
- package/src/components/colors-gradients/tools-panel-color-dropdown.js +0 -85
package/src/store/actions.js
CHANGED
|
@@ -33,24 +33,26 @@ import { mapRichTextSettings } from './utils';
|
|
|
33
33
|
* in actions which may result in no blocks remaining in the editor (removal,
|
|
34
34
|
* replacement, etc).
|
|
35
35
|
*/
|
|
36
|
-
const ensureDefaultBlock =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const ensureDefaultBlock =
|
|
37
|
+
() =>
|
|
38
|
+
( { select, dispatch } ) => {
|
|
39
|
+
// To avoid a focus loss when removing the last block, assure there is
|
|
40
|
+
// always a default block if the last of the blocks have been removed.
|
|
41
|
+
const count = select.getBlockCount();
|
|
42
|
+
if ( count > 0 ) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
// If there's an custom appender, don't insert default block.
|
|
47
|
+
// We have to remember to manually move the focus elsewhere to
|
|
48
|
+
// prevent it from being lost though.
|
|
49
|
+
const { __unstableHasCustomAppender } = select.getSettings();
|
|
50
|
+
if ( __unstableHasCustomAppender ) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
+
dispatch.insertDefaultBlock();
|
|
55
|
+
};
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Action that resets blocks state to the specified array of blocks, taking precedence
|
|
@@ -58,10 +60,12 @@ const ensureDefaultBlock = () => ( { select, dispatch } ) => {
|
|
|
58
60
|
*
|
|
59
61
|
* @param {Array} blocks Array of blocks.
|
|
60
62
|
*/
|
|
61
|
-
export const resetBlocks =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
63
|
+
export const resetBlocks =
|
|
64
|
+
( blocks ) =>
|
|
65
|
+
( { dispatch } ) => {
|
|
66
|
+
dispatch( { type: 'RESET_BLOCKS', blocks } );
|
|
67
|
+
dispatch( validateBlocksToTemplate( blocks ) );
|
|
68
|
+
};
|
|
65
69
|
|
|
66
70
|
/**
|
|
67
71
|
* Block validity is a function of blocks state (at the point of a
|
|
@@ -71,28 +75,27 @@ export const resetBlocks = ( blocks ) => ( { dispatch } ) => {
|
|
|
71
75
|
*
|
|
72
76
|
* @param {Array} blocks Array of blocks.
|
|
73
77
|
*/
|
|
74
|
-
export const validateBlocksToTemplate =
|
|
75
|
-
|
|
76
|
-
dispatch
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
};
|
|
78
|
+
export const validateBlocksToTemplate =
|
|
79
|
+
( blocks ) =>
|
|
80
|
+
( { select, dispatch } ) => {
|
|
81
|
+
const template = select.getTemplate();
|
|
82
|
+
const templateLock = select.getTemplateLock();
|
|
83
|
+
|
|
84
|
+
// Unlocked templates are considered always valid because they act
|
|
85
|
+
// as default values only.
|
|
86
|
+
const isBlocksValidToTemplate =
|
|
87
|
+
! template ||
|
|
88
|
+
templateLock !== 'all' ||
|
|
89
|
+
doBlocksMatchTemplate( blocks, template );
|
|
90
|
+
|
|
91
|
+
// Update if validity has changed.
|
|
92
|
+
const isValidTemplate = select.isValidTemplate();
|
|
93
|
+
|
|
94
|
+
if ( isBlocksValidToTemplate !== isValidTemplate ) {
|
|
95
|
+
dispatch.setTemplateValidity( isBlocksValidToTemplate );
|
|
96
|
+
return isBlocksValidToTemplate;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
96
99
|
|
|
97
100
|
/**
|
|
98
101
|
* A block selection object.
|
|
@@ -228,12 +231,15 @@ export function selectBlock( clientId, initialPosition = 0 ) {
|
|
|
228
231
|
*
|
|
229
232
|
* @param {string} clientId Block client ID.
|
|
230
233
|
*/
|
|
231
|
-
export const selectPreviousBlock =
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
export const selectPreviousBlock =
|
|
235
|
+
( clientId ) =>
|
|
236
|
+
( { select, dispatch } ) => {
|
|
237
|
+
const previousBlockClientId =
|
|
238
|
+
select.getPreviousBlockClientId( clientId );
|
|
239
|
+
if ( previousBlockClientId ) {
|
|
240
|
+
dispatch.selectBlock( previousBlockClientId, -1 );
|
|
241
|
+
}
|
|
242
|
+
};
|
|
237
243
|
|
|
238
244
|
/**
|
|
239
245
|
* Yields action objects used in signalling that the block following the given
|
|
@@ -241,12 +247,14 @@ export const selectPreviousBlock = ( clientId ) => ( { select, dispatch } ) => {
|
|
|
241
247
|
*
|
|
242
248
|
* @param {string} clientId Block client ID.
|
|
243
249
|
*/
|
|
244
|
-
export const selectNextBlock =
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
+
export const selectNextBlock =
|
|
251
|
+
( clientId ) =>
|
|
252
|
+
( { select, dispatch } ) => {
|
|
253
|
+
const nextBlockClientId = select.getNextBlockClientId( clientId );
|
|
254
|
+
if ( nextBlockClientId ) {
|
|
255
|
+
dispatch.selectBlock( nextBlockClientId );
|
|
256
|
+
}
|
|
257
|
+
};
|
|
250
258
|
|
|
251
259
|
/**
|
|
252
260
|
* Action that starts block multi-selection.
|
|
@@ -277,37 +285,35 @@ export function stopMultiSelect() {
|
|
|
277
285
|
* @param {string} end Last block of the multiselection.
|
|
278
286
|
* @param {number|null} __experimentalInitialPosition Optional initial position. Pass as null to skip focus within editor canvas.
|
|
279
287
|
*/
|
|
280
|
-
export const multiSelect =
|
|
281
|
-
start,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
288
|
+
export const multiSelect =
|
|
289
|
+
( start, end, __experimentalInitialPosition = 0 ) =>
|
|
290
|
+
( { select, dispatch } ) => {
|
|
291
|
+
const startBlockRootClientId = select.getBlockRootClientId( start );
|
|
292
|
+
const endBlockRootClientId = select.getBlockRootClientId( end );
|
|
293
|
+
|
|
294
|
+
// Only allow block multi-selections at the same level.
|
|
295
|
+
if ( startBlockRootClientId !== endBlockRootClientId ) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
292
298
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
+
dispatch( {
|
|
300
|
+
type: 'MULTI_SELECT',
|
|
301
|
+
start,
|
|
302
|
+
end,
|
|
303
|
+
initialPosition: __experimentalInitialPosition,
|
|
304
|
+
} );
|
|
299
305
|
|
|
300
|
-
|
|
306
|
+
const blockCount = select.getSelectedBlockCount();
|
|
301
307
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
};
|
|
308
|
+
speak(
|
|
309
|
+
sprintf(
|
|
310
|
+
/* translators: %s: number of selected blocks */
|
|
311
|
+
_n( '%s block selected.', '%s blocks selected.', blockCount ),
|
|
312
|
+
blockCount
|
|
313
|
+
),
|
|
314
|
+
'assertive'
|
|
315
|
+
);
|
|
316
|
+
};
|
|
311
317
|
|
|
312
318
|
/**
|
|
313
319
|
* Action that clears the block selection.
|
|
@@ -377,42 +383,38 @@ function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
|
|
|
377
383
|
*
|
|
378
384
|
* @return {Object} Action object.
|
|
379
385
|
*/
|
|
380
|
-
export const replaceBlocks =
|
|
381
|
-
clientIds,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
clientIds = castArray( clientIds );
|
|
389
|
-
blocks = getBlocksWithDefaultStylesApplied(
|
|
390
|
-
castArray( blocks ),
|
|
391
|
-
select.getSettings()
|
|
392
|
-
);
|
|
393
|
-
const rootClientId = select.getBlockRootClientId( first( clientIds ) );
|
|
394
|
-
// Replace is valid if the new blocks can be inserted in the root block.
|
|
395
|
-
for ( let index = 0; index < blocks.length; index++ ) {
|
|
396
|
-
const block = blocks[ index ];
|
|
397
|
-
const canInsertBlock = select.canInsertBlockType(
|
|
398
|
-
block.name,
|
|
399
|
-
rootClientId
|
|
386
|
+
export const replaceBlocks =
|
|
387
|
+
( clientIds, blocks, indexToSelect, initialPosition = 0, meta ) =>
|
|
388
|
+
( { select, dispatch } ) => {
|
|
389
|
+
/* eslint-enable jsdoc/valid-types */
|
|
390
|
+
clientIds = castArray( clientIds );
|
|
391
|
+
blocks = getBlocksWithDefaultStylesApplied(
|
|
392
|
+
castArray( blocks ),
|
|
393
|
+
select.getSettings()
|
|
400
394
|
);
|
|
401
|
-
|
|
402
|
-
|
|
395
|
+
const rootClientId = select.getBlockRootClientId( first( clientIds ) );
|
|
396
|
+
// Replace is valid if the new blocks can be inserted in the root block.
|
|
397
|
+
for ( let index = 0; index < blocks.length; index++ ) {
|
|
398
|
+
const block = blocks[ index ];
|
|
399
|
+
const canInsertBlock = select.canInsertBlockType(
|
|
400
|
+
block.name,
|
|
401
|
+
rootClientId
|
|
402
|
+
);
|
|
403
|
+
if ( ! canInsertBlock ) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
403
406
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
};
|
|
407
|
+
dispatch( {
|
|
408
|
+
type: 'REPLACE_BLOCKS',
|
|
409
|
+
clientIds,
|
|
410
|
+
blocks,
|
|
411
|
+
time: Date.now(),
|
|
412
|
+
indexToSelect,
|
|
413
|
+
initialPosition,
|
|
414
|
+
meta,
|
|
415
|
+
} );
|
|
416
|
+
dispatch( ensureDefaultBlock() );
|
|
417
|
+
};
|
|
416
418
|
|
|
417
419
|
/**
|
|
418
420
|
* Action that replaces a single block with one or more replacement blocks.
|
|
@@ -434,18 +436,18 @@ export function replaceBlock( clientId, block ) {
|
|
|
434
436
|
*
|
|
435
437
|
* @return {Function} Action creator.
|
|
436
438
|
*/
|
|
437
|
-
const createOnMove =
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
} ) => {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
439
|
+
const createOnMove =
|
|
440
|
+
( type ) =>
|
|
441
|
+
( clientIds, rootClientId ) =>
|
|
442
|
+
( { select, dispatch } ) => {
|
|
443
|
+
// If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
444
|
+
const canMoveBlocks = select.canMoveBlocks( clientIds, rootClientId );
|
|
445
|
+
if ( ! canMoveBlocks ) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
446
448
|
|
|
447
|
-
|
|
448
|
-
};
|
|
449
|
+
dispatch( { type, clientIds: castArray( clientIds ), rootClientId } );
|
|
450
|
+
};
|
|
449
451
|
|
|
450
452
|
export const moveBlocksDown = createOnMove( 'MOVE_BLOCKS_DOWN' );
|
|
451
453
|
export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' );
|
|
@@ -458,51 +460,51 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' );
|
|
|
458
460
|
* @param {?string} toRootClientId Root client ID destination.
|
|
459
461
|
* @param {number} index The index to move the blocks to.
|
|
460
462
|
*/
|
|
461
|
-
export const moveBlocksToPosition =
|
|
462
|
-
clientIds,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
index
|
|
466
|
-
) => ( { select, dispatch } ) => {
|
|
467
|
-
const canMoveBlocks = select.canMoveBlocks( clientIds, fromRootClientId );
|
|
468
|
-
|
|
469
|
-
// If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
470
|
-
if ( ! canMoveBlocks ) {
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// If moving inside the same root block the move is always possible.
|
|
475
|
-
if ( fromRootClientId !== toRootClientId ) {
|
|
476
|
-
const canRemoveBlocks = select.canRemoveBlocks(
|
|
463
|
+
export const moveBlocksToPosition =
|
|
464
|
+
( clientIds, fromRootClientId = '', toRootClientId = '', index ) =>
|
|
465
|
+
( { select, dispatch } ) => {
|
|
466
|
+
const canMoveBlocks = select.canMoveBlocks(
|
|
477
467
|
clientIds,
|
|
478
468
|
fromRootClientId
|
|
479
469
|
);
|
|
480
470
|
|
|
481
|
-
// If
|
|
482
|
-
|
|
483
|
-
if ( ! canRemoveBlocks ) {
|
|
471
|
+
// If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
472
|
+
if ( ! canMoveBlocks ) {
|
|
484
473
|
return;
|
|
485
474
|
}
|
|
486
475
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
476
|
+
// If moving inside the same root block the move is always possible.
|
|
477
|
+
if ( fromRootClientId !== toRootClientId ) {
|
|
478
|
+
const canRemoveBlocks = select.canRemoveBlocks(
|
|
479
|
+
clientIds,
|
|
480
|
+
fromRootClientId
|
|
481
|
+
);
|
|
491
482
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
483
|
+
// If we're moving to another block, it means we're deleting blocks from
|
|
484
|
+
// the original block, so we need to check if removing is possible.
|
|
485
|
+
if ( ! canRemoveBlocks ) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const canInsertBlocks = select.canInsertBlocks(
|
|
490
|
+
clientIds,
|
|
491
|
+
toRootClientId
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
// If moving to other parent block, the move is possible if we can insert a block of the same type inside the new parent block.
|
|
495
|
+
if ( ! canInsertBlocks ) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
495
498
|
}
|
|
496
|
-
}
|
|
497
499
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
};
|
|
500
|
+
dispatch( {
|
|
501
|
+
type: 'MOVE_BLOCKS_TO_POSITION',
|
|
502
|
+
fromRootClientId,
|
|
503
|
+
toRootClientId,
|
|
504
|
+
clientIds,
|
|
505
|
+
index,
|
|
506
|
+
} );
|
|
507
|
+
};
|
|
506
508
|
|
|
507
509
|
/**
|
|
508
510
|
* Action that moves given block to a new position.
|
|
@@ -566,48 +568,56 @@ export function insertBlock(
|
|
|
566
568
|
* @param {?Object} meta Optional Meta values to be passed to the action object.
|
|
567
569
|
* @return {Object} Action object.
|
|
568
570
|
*/
|
|
569
|
-
export const insertBlocks =
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
initialPosition
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
571
|
+
export const insertBlocks =
|
|
572
|
+
(
|
|
573
|
+
blocks,
|
|
574
|
+
index,
|
|
575
|
+
rootClientId,
|
|
576
|
+
updateSelection = true,
|
|
577
|
+
initialPosition = 0,
|
|
578
|
+
meta
|
|
579
|
+
) =>
|
|
580
|
+
( { select, dispatch } ) => {
|
|
581
|
+
/* eslint-enable jsdoc/valid-types */
|
|
582
|
+
if ( isObject( initialPosition ) ) {
|
|
583
|
+
meta = initialPosition;
|
|
584
|
+
initialPosition = 0;
|
|
585
|
+
deprecated(
|
|
586
|
+
"meta argument in wp.data.dispatch('core/block-editor')",
|
|
587
|
+
{
|
|
588
|
+
since: '5.8',
|
|
589
|
+
hint: 'The meta argument is now the 6th argument of the function',
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
}
|
|
586
593
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
594
|
+
blocks = getBlocksWithDefaultStylesApplied(
|
|
595
|
+
castArray( blocks ),
|
|
596
|
+
select.getSettings()
|
|
597
|
+
);
|
|
598
|
+
const allowedBlocks = [];
|
|
599
|
+
for ( const block of blocks ) {
|
|
600
|
+
const isValid = select.canInsertBlockType(
|
|
601
|
+
block.name,
|
|
602
|
+
rootClientId
|
|
603
|
+
);
|
|
604
|
+
if ( isValid ) {
|
|
605
|
+
allowedBlocks.push( block );
|
|
606
|
+
}
|
|
596
607
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
};
|
|
608
|
+
if ( allowedBlocks.length ) {
|
|
609
|
+
dispatch( {
|
|
610
|
+
type: 'INSERT_BLOCKS',
|
|
611
|
+
blocks: allowedBlocks,
|
|
612
|
+
index,
|
|
613
|
+
rootClientId,
|
|
614
|
+
time: Date.now(),
|
|
615
|
+
updateSelection,
|
|
616
|
+
initialPosition: updateSelection ? initialPosition : null,
|
|
617
|
+
meta,
|
|
618
|
+
} );
|
|
619
|
+
}
|
|
620
|
+
};
|
|
611
621
|
|
|
612
622
|
/**
|
|
613
623
|
* Action that shows the insertion point.
|
|
@@ -663,321 +673,333 @@ export function setTemplateValidity( isValid ) {
|
|
|
663
673
|
*
|
|
664
674
|
* @return {Object} Action object.
|
|
665
675
|
*/
|
|
666
|
-
export const synchronizeTemplate =
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
676
|
+
export const synchronizeTemplate =
|
|
677
|
+
() =>
|
|
678
|
+
( { select, dispatch } ) => {
|
|
679
|
+
dispatch( { type: 'SYNCHRONIZE_TEMPLATE' } );
|
|
680
|
+
const blocks = select.getBlocks();
|
|
681
|
+
const template = select.getTemplate();
|
|
682
|
+
const updatedBlockList = synchronizeBlocksWithTemplate(
|
|
683
|
+
blocks,
|
|
684
|
+
template
|
|
685
|
+
);
|
|
671
686
|
|
|
672
|
-
|
|
673
|
-
};
|
|
687
|
+
dispatch.resetBlocks( updatedBlockList );
|
|
688
|
+
};
|
|
674
689
|
|
|
675
690
|
/**
|
|
676
691
|
* Delete the current selection.
|
|
677
692
|
*
|
|
678
693
|
* @param {boolean} isForward
|
|
679
694
|
*/
|
|
680
|
-
export const __unstableDeleteSelection =
|
|
681
|
-
|
|
682
|
-
select,
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
)
|
|
697
|
-
return false;
|
|
698
|
-
|
|
699
|
-
const anchorRootClientId = select.getBlockRootClientId(
|
|
700
|
-
selectionAnchor.clientId
|
|
701
|
-
);
|
|
702
|
-
const focusRootClientId = select.getBlockRootClientId(
|
|
703
|
-
selectionFocus.clientId
|
|
704
|
-
);
|
|
705
|
-
|
|
706
|
-
// It's not mergeable if the selection doesn't start and end in the same
|
|
707
|
-
// block list. Maybe in the future it should be allowed.
|
|
708
|
-
if ( anchorRootClientId !== focusRootClientId ) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
const blockOrder = select.getBlockOrder( anchorRootClientId );
|
|
713
|
-
const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
|
|
714
|
-
const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
|
|
695
|
+
export const __unstableDeleteSelection =
|
|
696
|
+
( isForward ) =>
|
|
697
|
+
( { registry, select, dispatch } ) => {
|
|
698
|
+
const selectionAnchor = select.getSelectionStart();
|
|
699
|
+
const selectionFocus = select.getSelectionEnd();
|
|
700
|
+
|
|
701
|
+
if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
|
|
702
|
+
|
|
703
|
+
// It's not mergeable if there's no rich text selection.
|
|
704
|
+
if (
|
|
705
|
+
! selectionAnchor.attributeKey ||
|
|
706
|
+
! selectionFocus.attributeKey ||
|
|
707
|
+
typeof selectionAnchor.offset === 'undefined' ||
|
|
708
|
+
typeof selectionFocus.offset === 'undefined'
|
|
709
|
+
)
|
|
710
|
+
return false;
|
|
715
711
|
|
|
716
|
-
|
|
717
|
-
|
|
712
|
+
const anchorRootClientId = select.getBlockRootClientId(
|
|
713
|
+
selectionAnchor.clientId
|
|
714
|
+
);
|
|
715
|
+
const focusRootClientId = select.getBlockRootClientId(
|
|
716
|
+
selectionFocus.clientId
|
|
717
|
+
);
|
|
718
718
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
selectionEnd = selectionFocus;
|
|
725
|
-
}
|
|
719
|
+
// It's not mergeable if the selection doesn't start and end in the same
|
|
720
|
+
// block list. Maybe in the future it should be allowed.
|
|
721
|
+
if ( anchorRootClientId !== focusRootClientId ) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
726
724
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
725
|
+
const blockOrder = select.getBlockOrder( anchorRootClientId );
|
|
726
|
+
const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
|
|
727
|
+
const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
|
|
730
728
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
729
|
+
// Reassign selection start and end based on order.
|
|
730
|
+
let selectionStart, selectionEnd;
|
|
734
731
|
|
|
735
|
-
|
|
736
|
-
|
|
732
|
+
if ( anchorIndex > focusIndex ) {
|
|
733
|
+
selectionStart = selectionFocus;
|
|
734
|
+
selectionEnd = selectionAnchor;
|
|
735
|
+
} else {
|
|
736
|
+
selectionStart = selectionAnchor;
|
|
737
|
+
selectionEnd = selectionFocus;
|
|
738
|
+
}
|
|
737
739
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
+
const targetSelection = isForward ? selectionEnd : selectionStart;
|
|
741
|
+
const targetBlock = select.getBlock( targetSelection.clientId );
|
|
742
|
+
const targetBlockType = getBlockType( targetBlock.name );
|
|
740
743
|
|
|
741
|
-
|
|
742
|
-
|
|
744
|
+
if ( ! targetBlockType.merge ) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
743
747
|
|
|
744
|
-
|
|
745
|
-
|
|
748
|
+
const selectionA = selectionStart;
|
|
749
|
+
const selectionB = selectionEnd;
|
|
746
750
|
|
|
747
|
-
|
|
748
|
-
blockAType
|
|
749
|
-
const attributeDefinitionB =
|
|
750
|
-
blockBType.attributes[ selectionB.attributeKey ];
|
|
751
|
+
const blockA = select.getBlock( selectionA.clientId );
|
|
752
|
+
const blockAType = getBlockType( blockA.name );
|
|
751
753
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
...mapRichTextSettings( attributeDefinitionA ),
|
|
755
|
-
} );
|
|
756
|
-
let valueB = create( {
|
|
757
|
-
html: htmlB,
|
|
758
|
-
...mapRichTextSettings( attributeDefinitionB ),
|
|
759
|
-
} );
|
|
754
|
+
const blockB = select.getBlock( selectionB.clientId );
|
|
755
|
+
const blockBType = getBlockType( blockB.name );
|
|
760
756
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const START_OF_SELECTED_AREA = '\u0086';
|
|
757
|
+
const htmlA = blockA.attributes[ selectionA.attributeKey ];
|
|
758
|
+
const htmlB = blockB.attributes[ selectionB.attributeKey ];
|
|
764
759
|
|
|
765
|
-
|
|
766
|
-
|
|
760
|
+
const attributeDefinitionA =
|
|
761
|
+
blockAType.attributes[ selectionA.attributeKey ];
|
|
762
|
+
const attributeDefinitionB =
|
|
763
|
+
blockBType.attributes[ selectionB.attributeKey ];
|
|
767
764
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
[ selectionA.attributeKey ]: toHTMLString( {
|
|
771
|
-
value: valueA,
|
|
765
|
+
let valueA = create( {
|
|
766
|
+
html: htmlA,
|
|
772
767
|
...mapRichTextSettings( attributeDefinitionA ),
|
|
773
|
-
} )
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
[ selectionB.attributeKey ]: toHTMLString( {
|
|
777
|
-
value: valueB,
|
|
768
|
+
} );
|
|
769
|
+
let valueB = create( {
|
|
770
|
+
html: htmlB,
|
|
778
771
|
...mapRichTextSettings( attributeDefinitionB ),
|
|
779
|
-
} )
|
|
780
|
-
} );
|
|
772
|
+
} );
|
|
781
773
|
|
|
782
|
-
|
|
774
|
+
// A robust way to retain selection position through various transforms
|
|
775
|
+
// is to insert a special character at the position and then recover it.
|
|
776
|
+
const START_OF_SELECTED_AREA = '\u0086';
|
|
783
777
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
const blocksWithTheSameType =
|
|
787
|
-
blockA.name === blockB.name
|
|
788
|
-
? [ followingBlock ]
|
|
789
|
-
: switchToBlockType( followingBlock, targetBlockType.name );
|
|
778
|
+
valueA = remove( valueA, selectionA.offset, valueA.text.length );
|
|
779
|
+
valueB = insert( valueB, START_OF_SELECTED_AREA, 0, selectionB.offset );
|
|
790
780
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
781
|
+
// Clone the blocks so we don't manipulate the original.
|
|
782
|
+
const cloneA = cloneBlock( blockA, {
|
|
783
|
+
[ selectionA.attributeKey ]: toHTMLString( {
|
|
784
|
+
value: valueA,
|
|
785
|
+
...mapRichTextSettings( attributeDefinitionA ),
|
|
786
|
+
} ),
|
|
787
|
+
} );
|
|
788
|
+
const cloneB = cloneBlock( blockB, {
|
|
789
|
+
[ selectionB.attributeKey ]: toHTMLString( {
|
|
790
|
+
value: valueB,
|
|
791
|
+
...mapRichTextSettings( attributeDefinitionB ),
|
|
792
|
+
} ),
|
|
793
|
+
} );
|
|
795
794
|
|
|
796
|
-
|
|
795
|
+
const followingBlock = isForward ? cloneA : cloneB;
|
|
797
796
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
} else {
|
|
805
|
-
const blockToMerge = blocksWithTheSameType.shift();
|
|
806
|
-
updatedAttributes = targetBlockType.merge(
|
|
807
|
-
cloneA.attributes,
|
|
808
|
-
blockToMerge.attributes
|
|
809
|
-
);
|
|
810
|
-
}
|
|
797
|
+
// We can only merge blocks with similar types
|
|
798
|
+
// thus, we transform the block to merge first
|
|
799
|
+
const blocksWithTheSameType =
|
|
800
|
+
blockA.name === blockB.name
|
|
801
|
+
? [ followingBlock ]
|
|
802
|
+
: switchToBlockType( followingBlock, targetBlockType.name );
|
|
811
803
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
);
|
|
804
|
+
// If the block types can not match, do nothing
|
|
805
|
+
if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
817
808
|
|
|
818
|
-
|
|
819
|
-
const convertedValue = create( {
|
|
820
|
-
html: convertedHtml,
|
|
821
|
-
...mapRichTextSettings( targetBlockType.attributes[ newAttributeKey ] ),
|
|
822
|
-
} );
|
|
823
|
-
const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
|
|
824
|
-
const newValue = remove( convertedValue, newOffset, newOffset + 1 );
|
|
825
|
-
const newHtml = toHTMLString( {
|
|
826
|
-
value: newValue,
|
|
827
|
-
...mapRichTextSettings( targetBlockType.attributes[ newAttributeKey ] ),
|
|
828
|
-
} );
|
|
809
|
+
let updatedAttributes;
|
|
829
810
|
|
|
830
|
-
|
|
811
|
+
if ( isForward ) {
|
|
812
|
+
const blockToMerge = blocksWithTheSameType.pop();
|
|
813
|
+
updatedAttributes = targetBlockType.merge(
|
|
814
|
+
blockToMerge.attributes,
|
|
815
|
+
cloneB.attributes
|
|
816
|
+
);
|
|
817
|
+
} else {
|
|
818
|
+
const blockToMerge = blocksWithTheSameType.shift();
|
|
819
|
+
updatedAttributes = targetBlockType.merge(
|
|
820
|
+
cloneA.attributes,
|
|
821
|
+
blockToMerge.attributes
|
|
822
|
+
);
|
|
823
|
+
}
|
|
831
824
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
...targetBlock,
|
|
838
|
-
attributes: {
|
|
839
|
-
...targetBlock.attributes,
|
|
840
|
-
...updatedAttributes,
|
|
841
|
-
},
|
|
842
|
-
},
|
|
843
|
-
...( isForward ? [] : blocksWithTheSameType ),
|
|
844
|
-
];
|
|
845
|
-
|
|
846
|
-
registry.batch( () => {
|
|
847
|
-
dispatch.selectionChange(
|
|
848
|
-
targetBlock.clientId,
|
|
849
|
-
newAttributeKey,
|
|
850
|
-
newOffset,
|
|
851
|
-
newOffset
|
|
825
|
+
const newAttributeKey = findKey(
|
|
826
|
+
updatedAttributes,
|
|
827
|
+
( v ) =>
|
|
828
|
+
typeof v === 'string' &&
|
|
829
|
+
v.indexOf( START_OF_SELECTED_AREA ) !== -1
|
|
852
830
|
);
|
|
853
831
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
832
|
+
const convertedHtml = updatedAttributes[ newAttributeKey ];
|
|
833
|
+
const convertedValue = create( {
|
|
834
|
+
html: convertedHtml,
|
|
835
|
+
...mapRichTextSettings(
|
|
836
|
+
targetBlockType.attributes[ newAttributeKey ]
|
|
837
|
+
),
|
|
838
|
+
} );
|
|
839
|
+
const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
|
|
840
|
+
const newValue = remove( convertedValue, newOffset, newOffset + 1 );
|
|
841
|
+
const newHtml = toHTMLString( {
|
|
842
|
+
value: newValue,
|
|
843
|
+
...mapRichTextSettings(
|
|
844
|
+
targetBlockType.attributes[ newAttributeKey ]
|
|
845
|
+
),
|
|
846
|
+
} );
|
|
847
|
+
|
|
848
|
+
updatedAttributes[ newAttributeKey ] = newHtml;
|
|
849
|
+
|
|
850
|
+
const selectedBlockClientIds = select.getSelectedBlockClientIds();
|
|
851
|
+
const replacement = [
|
|
852
|
+
...( isForward ? blocksWithTheSameType : [] ),
|
|
853
|
+
{
|
|
854
|
+
// Preserve the original client ID.
|
|
855
|
+
...targetBlock,
|
|
856
|
+
attributes: {
|
|
857
|
+
...targetBlock.attributes,
|
|
858
|
+
...updatedAttributes,
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
...( isForward ? [] : blocksWithTheSameType ),
|
|
862
|
+
];
|
|
863
|
+
|
|
864
|
+
registry.batch( () => {
|
|
865
|
+
dispatch.selectionChange(
|
|
866
|
+
targetBlock.clientId,
|
|
867
|
+
newAttributeKey,
|
|
868
|
+
newOffset,
|
|
869
|
+
newOffset
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
dispatch.replaceBlocks(
|
|
873
|
+
selectedBlockClientIds,
|
|
874
|
+
replacement,
|
|
875
|
+
0, // If we don't pass the `indexToSelect` it will default to the last block.
|
|
876
|
+
select.getSelectedBlocksInitialCaretPosition()
|
|
877
|
+
);
|
|
878
|
+
} );
|
|
879
|
+
};
|
|
862
880
|
|
|
863
881
|
/**
|
|
864
882
|
* Split the current selection.
|
|
865
883
|
*/
|
|
866
|
-
export const __unstableSplitSelection =
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
selectionAnchor.clientId
|
|
883
|
-
);
|
|
884
|
-
const focusRootClientId = select.getBlockRootClientId(
|
|
885
|
-
selectionFocus.clientId
|
|
886
|
-
);
|
|
884
|
+
export const __unstableSplitSelection =
|
|
885
|
+
() =>
|
|
886
|
+
( { select, dispatch } ) => {
|
|
887
|
+
const selectionAnchor = select.getSelectionStart();
|
|
888
|
+
const selectionFocus = select.getSelectionEnd();
|
|
889
|
+
|
|
890
|
+
if ( selectionAnchor.clientId === selectionFocus.clientId ) return;
|
|
891
|
+
|
|
892
|
+
// Can't split if the selection is not set.
|
|
893
|
+
if (
|
|
894
|
+
! selectionAnchor.attributeKey ||
|
|
895
|
+
! selectionFocus.attributeKey ||
|
|
896
|
+
typeof selectionAnchor.offset === 'undefined' ||
|
|
897
|
+
typeof selectionFocus.offset === 'undefined'
|
|
898
|
+
)
|
|
899
|
+
return;
|
|
887
900
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
901
|
+
const anchorRootClientId = select.getBlockRootClientId(
|
|
902
|
+
selectionAnchor.clientId
|
|
903
|
+
);
|
|
904
|
+
const focusRootClientId = select.getBlockRootClientId(
|
|
905
|
+
selectionFocus.clientId
|
|
906
|
+
);
|
|
893
907
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
908
|
+
// It's not splittable if the selection doesn't start and end in the same
|
|
909
|
+
// block list. Maybe in the future it should be allowed.
|
|
910
|
+
if ( anchorRootClientId !== focusRootClientId ) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
897
913
|
|
|
898
|
-
|
|
899
|
-
|
|
914
|
+
const blockOrder = select.getBlockOrder( anchorRootClientId );
|
|
915
|
+
const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
|
|
916
|
+
const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
|
|
900
917
|
|
|
901
|
-
|
|
902
|
-
selectionStart
|
|
903
|
-
selectionEnd = selectionAnchor;
|
|
904
|
-
} else {
|
|
905
|
-
selectionStart = selectionAnchor;
|
|
906
|
-
selectionEnd = selectionFocus;
|
|
907
|
-
}
|
|
918
|
+
// Reassign selection start and end based on order.
|
|
919
|
+
let selectionStart, selectionEnd;
|
|
908
920
|
|
|
909
|
-
|
|
910
|
-
|
|
921
|
+
if ( anchorIndex > focusIndex ) {
|
|
922
|
+
selectionStart = selectionFocus;
|
|
923
|
+
selectionEnd = selectionAnchor;
|
|
924
|
+
} else {
|
|
925
|
+
selectionStart = selectionAnchor;
|
|
926
|
+
selectionEnd = selectionFocus;
|
|
927
|
+
}
|
|
911
928
|
|
|
912
|
-
|
|
913
|
-
|
|
929
|
+
const selectionA = selectionStart;
|
|
930
|
+
const selectionB = selectionEnd;
|
|
914
931
|
|
|
915
|
-
|
|
916
|
-
|
|
932
|
+
const blockA = select.getBlock( selectionA.clientId );
|
|
933
|
+
const blockAType = getBlockType( blockA.name );
|
|
917
934
|
|
|
918
|
-
|
|
919
|
-
|
|
935
|
+
const blockB = select.getBlock( selectionB.clientId );
|
|
936
|
+
const blockBType = getBlockType( blockB.name );
|
|
920
937
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
const attributeDefinitionB =
|
|
924
|
-
blockBType.attributes[ selectionB.attributeKey ];
|
|
938
|
+
const htmlA = blockA.attributes[ selectionA.attributeKey ];
|
|
939
|
+
const htmlB = blockB.attributes[ selectionB.attributeKey ];
|
|
925
940
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
let valueB = create( {
|
|
931
|
-
html: htmlB,
|
|
932
|
-
...mapRichTextSettings( attributeDefinitionB ),
|
|
933
|
-
} );
|
|
941
|
+
const attributeDefinitionA =
|
|
942
|
+
blockAType.attributes[ selectionA.attributeKey ];
|
|
943
|
+
const attributeDefinitionB =
|
|
944
|
+
blockBType.attributes[ selectionB.attributeKey ];
|
|
934
945
|
|
|
935
|
-
|
|
936
|
-
|
|
946
|
+
let valueA = create( {
|
|
947
|
+
html: htmlA,
|
|
948
|
+
...mapRichTextSettings( attributeDefinitionA ),
|
|
949
|
+
} );
|
|
950
|
+
let valueB = create( {
|
|
951
|
+
html: htmlB,
|
|
952
|
+
...mapRichTextSettings( attributeDefinitionB ),
|
|
953
|
+
} );
|
|
937
954
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
...
|
|
949
|
-
|
|
955
|
+
valueA = remove( valueA, selectionA.offset, valueA.text.length );
|
|
956
|
+
valueB = remove( valueB, 0, selectionB.offset );
|
|
957
|
+
|
|
958
|
+
dispatch.replaceBlocks(
|
|
959
|
+
select.getSelectedBlockClientIds(),
|
|
960
|
+
[
|
|
961
|
+
{
|
|
962
|
+
// Preserve the original client ID.
|
|
963
|
+
...blockA,
|
|
964
|
+
attributes: {
|
|
965
|
+
...blockA.attributes,
|
|
966
|
+
[ selectionA.attributeKey ]: toHTMLString( {
|
|
967
|
+
value: valueA,
|
|
968
|
+
...mapRichTextSettings( attributeDefinitionA ),
|
|
969
|
+
} ),
|
|
970
|
+
},
|
|
950
971
|
},
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
972
|
+
createBlock( getDefaultBlockName() ),
|
|
973
|
+
{
|
|
974
|
+
// Preserve the original client ID.
|
|
975
|
+
...blockB,
|
|
976
|
+
attributes: {
|
|
977
|
+
...blockB.attributes,
|
|
978
|
+
[ selectionB.attributeKey ]: toHTMLString( {
|
|
979
|
+
value: valueB,
|
|
980
|
+
...mapRichTextSettings( attributeDefinitionB ),
|
|
981
|
+
} ),
|
|
982
|
+
},
|
|
962
983
|
},
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
};
|
|
984
|
+
],
|
|
985
|
+
1, // If we don't pass the `indexToSelect` it will default to the last block.
|
|
986
|
+
select.getSelectedBlocksInitialCaretPosition()
|
|
987
|
+
);
|
|
988
|
+
};
|
|
969
989
|
|
|
970
990
|
/**
|
|
971
991
|
* Expand the selection to cover the entire blocks, removing partial selection.
|
|
972
992
|
*/
|
|
973
|
-
export const __unstableExpandSelection =
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
993
|
+
export const __unstableExpandSelection =
|
|
994
|
+
() =>
|
|
995
|
+
( { select, dispatch } ) => {
|
|
996
|
+
const selectionAnchor = select.getSelectionStart();
|
|
997
|
+
const selectionFocus = select.getSelectionEnd();
|
|
998
|
+
dispatch.selectionChange( {
|
|
999
|
+
start: { clientId: selectionAnchor.clientId },
|
|
1000
|
+
end: { clientId: selectionFocus.clientId },
|
|
1001
|
+
} );
|
|
1002
|
+
};
|
|
981
1003
|
|
|
982
1004
|
/**
|
|
983
1005
|
* Action that merges two blocks.
|
|
@@ -985,139 +1007,146 @@ export const __unstableExpandSelection = () => ( { select, dispatch } ) => {
|
|
|
985
1007
|
* @param {string} firstBlockClientId Client ID of the first block to merge.
|
|
986
1008
|
* @param {string} secondBlockClientId Client ID of the second block to merge.
|
|
987
1009
|
*/
|
|
988
|
-
export const mergeBlocks =
|
|
989
|
-
|
|
990
|
-
dispatch
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
const blockB = select.getBlock( clientIdB );
|
|
1006
|
-
const blockBType = getBlockType( blockB.name );
|
|
1007
|
-
const { clientId, attributeKey, offset } = select.getSelectionStart();
|
|
1008
|
-
const selectedBlockType = clientId === clientIdA ? blockAType : blockBType;
|
|
1009
|
-
const attributeDefinition = selectedBlockType.attributes[ attributeKey ];
|
|
1010
|
-
const canRestoreTextSelection =
|
|
1011
|
-
( clientId === clientIdA || clientId === clientIdB ) &&
|
|
1012
|
-
attributeKey !== undefined &&
|
|
1013
|
-
offset !== undefined &&
|
|
1014
|
-
// We cannot restore text selection if the RichText identifier
|
|
1015
|
-
// is not a defined block attribute key. This can be the case if the
|
|
1016
|
-
// fallback intance ID is used to store selection (and no RichText
|
|
1017
|
-
// identifier is set), or when the identifier is wrong.
|
|
1018
|
-
!! attributeDefinition;
|
|
1019
|
-
|
|
1020
|
-
if ( ! attributeDefinition ) {
|
|
1021
|
-
if ( typeof attributeKey === 'number' ) {
|
|
1022
|
-
window.console.error(
|
|
1023
|
-
`RichText needs an identifier prop that is the block attribute key of the attribute it controls. Its type is expected to be a string, but was ${ typeof attributeKey }`
|
|
1024
|
-
);
|
|
1025
|
-
} else {
|
|
1026
|
-
window.console.error(
|
|
1027
|
-
'The RichText identifier prop does not match any attributes defined by the block.'
|
|
1028
|
-
);
|
|
1010
|
+
export const mergeBlocks =
|
|
1011
|
+
( firstBlockClientId, secondBlockClientId ) =>
|
|
1012
|
+
( { select, dispatch } ) => {
|
|
1013
|
+
const blocks = [ firstBlockClientId, secondBlockClientId ];
|
|
1014
|
+
dispatch( { type: 'MERGE_BLOCKS', blocks } );
|
|
1015
|
+
|
|
1016
|
+
const [ clientIdA, clientIdB ] = blocks;
|
|
1017
|
+
const blockA = select.getBlock( clientIdA );
|
|
1018
|
+
const blockAType = getBlockType( blockA.name );
|
|
1019
|
+
|
|
1020
|
+
// Only focus the previous block if it's not mergeable.
|
|
1021
|
+
if ( blockAType && ! blockAType.merge ) {
|
|
1022
|
+
dispatch.selectBlock( blockA.clientId );
|
|
1023
|
+
return;
|
|
1029
1024
|
}
|
|
1030
|
-
}
|
|
1031
1025
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1026
|
+
const blockB = select.getBlock( clientIdB );
|
|
1027
|
+
const blockBType = getBlockType( blockB.name );
|
|
1028
|
+
const { clientId, attributeKey, offset } = select.getSelectionStart();
|
|
1029
|
+
const selectedBlockType =
|
|
1030
|
+
clientId === clientIdA ? blockAType : blockBType;
|
|
1031
|
+
const attributeDefinition =
|
|
1032
|
+
selectedBlockType.attributes[ attributeKey ];
|
|
1033
|
+
const canRestoreTextSelection =
|
|
1034
|
+
( clientId === clientIdA || clientId === clientIdB ) &&
|
|
1035
|
+
attributeKey !== undefined &&
|
|
1036
|
+
offset !== undefined &&
|
|
1037
|
+
// We cannot restore text selection if the RichText identifier
|
|
1038
|
+
// is not a defined block attribute key. This can be the case if the
|
|
1039
|
+
// fallback intance ID is used to store selection (and no RichText
|
|
1040
|
+
// identifier is set), or when the identifier is wrong.
|
|
1041
|
+
!! attributeDefinition;
|
|
1042
|
+
|
|
1043
|
+
if ( ! attributeDefinition ) {
|
|
1044
|
+
if ( typeof attributeKey === 'number' ) {
|
|
1045
|
+
window.console.error(
|
|
1046
|
+
`RichText needs an identifier prop that is the block attribute key of the attribute it controls. Its type is expected to be a string, but was ${ typeof attributeKey }`
|
|
1047
|
+
);
|
|
1048
|
+
} else {
|
|
1049
|
+
window.console.error(
|
|
1050
|
+
'The RichText identifier prop does not match any attributes defined by the block.'
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1035
1054
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1055
|
+
// A robust way to retain selection position through various transforms
|
|
1056
|
+
// is to insert a special character at the position and then recover it.
|
|
1057
|
+
const START_OF_SELECTED_AREA = '\u0086';
|
|
1058
|
+
|
|
1059
|
+
// Clone the blocks so we don't insert the character in a "live" block.
|
|
1060
|
+
const cloneA = cloneBlock( blockA );
|
|
1061
|
+
const cloneB = cloneBlock( blockB );
|
|
1062
|
+
|
|
1063
|
+
if ( canRestoreTextSelection ) {
|
|
1064
|
+
const selectedBlock = clientId === clientIdA ? cloneA : cloneB;
|
|
1065
|
+
const html = selectedBlock.attributes[ attributeKey ];
|
|
1066
|
+
const value = insert(
|
|
1067
|
+
create( {
|
|
1068
|
+
html,
|
|
1069
|
+
...mapRichTextSettings( attributeDefinition ),
|
|
1070
|
+
} ),
|
|
1071
|
+
START_OF_SELECTED_AREA,
|
|
1072
|
+
offset,
|
|
1073
|
+
offset
|
|
1074
|
+
);
|
|
1039
1075
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
const html = selectedBlock.attributes[ attributeKey ];
|
|
1043
|
-
const value = insert(
|
|
1044
|
-
create( {
|
|
1045
|
-
html,
|
|
1076
|
+
selectedBlock.attributes[ attributeKey ] = toHTMLString( {
|
|
1077
|
+
value,
|
|
1046
1078
|
...mapRichTextSettings( attributeDefinition ),
|
|
1047
|
-
} )
|
|
1048
|
-
|
|
1049
|
-
offset,
|
|
1050
|
-
offset
|
|
1051
|
-
);
|
|
1052
|
-
|
|
1053
|
-
selectedBlock.attributes[ attributeKey ] = toHTMLString( {
|
|
1054
|
-
value,
|
|
1055
|
-
...mapRichTextSettings( attributeDefinition ),
|
|
1056
|
-
} );
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// We can only merge blocks with similar types
|
|
1060
|
-
// thus, we transform the block to merge first.
|
|
1061
|
-
const blocksWithTheSameType =
|
|
1062
|
-
blockA.name === blockB.name
|
|
1063
|
-
? [ cloneB ]
|
|
1064
|
-
: switchToBlockType( cloneB, blockA.name );
|
|
1079
|
+
} );
|
|
1080
|
+
}
|
|
1065
1081
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1082
|
+
// We can only merge blocks with similar types
|
|
1083
|
+
// thus, we transform the block to merge first.
|
|
1084
|
+
const blocksWithTheSameType =
|
|
1085
|
+
blockA.name === blockB.name
|
|
1086
|
+
? [ cloneB ]
|
|
1087
|
+
: switchToBlockType( cloneB, blockA.name );
|
|
1070
1088
|
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
);
|
|
1089
|
+
// If the block types can not match, do nothing.
|
|
1090
|
+
if ( ! blocksWithTheSameType || ! blocksWithTheSameType.length ) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1076
1093
|
|
|
1077
|
-
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
typeof v === 'string' &&
|
|
1082
|
-
v.indexOf( START_OF_SELECTED_AREA ) !== -1
|
|
1094
|
+
// Calling the merge to update the attributes and remove the block to be merged.
|
|
1095
|
+
const updatedAttributes = blockAType.merge(
|
|
1096
|
+
cloneA.attributes,
|
|
1097
|
+
blocksWithTheSameType[ 0 ].attributes
|
|
1083
1098
|
);
|
|
1084
|
-
const convertedHtml = updatedAttributes[ newAttributeKey ];
|
|
1085
|
-
const convertedValue = create( {
|
|
1086
|
-
html: convertedHtml,
|
|
1087
|
-
...mapRichTextSettings( blockAType.attributes[ newAttributeKey ] ),
|
|
1088
|
-
} );
|
|
1089
|
-
const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
|
|
1090
|
-
const newValue = remove( convertedValue, newOffset, newOffset + 1 );
|
|
1091
|
-
const newHtml = toHTMLString( {
|
|
1092
|
-
value: newValue,
|
|
1093
|
-
...mapRichTextSettings( blockAType.attributes[ newAttributeKey ] ),
|
|
1094
|
-
} );
|
|
1095
|
-
|
|
1096
|
-
updatedAttributes[ newAttributeKey ] = newHtml;
|
|
1097
1099
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1100
|
+
if ( canRestoreTextSelection ) {
|
|
1101
|
+
const newAttributeKey = findKey(
|
|
1102
|
+
updatedAttributes,
|
|
1103
|
+
( v ) =>
|
|
1104
|
+
typeof v === 'string' &&
|
|
1105
|
+
v.indexOf( START_OF_SELECTED_AREA ) !== -1
|
|
1106
|
+
);
|
|
1107
|
+
const convertedHtml = updatedAttributes[ newAttributeKey ];
|
|
1108
|
+
const convertedValue = create( {
|
|
1109
|
+
html: convertedHtml,
|
|
1110
|
+
...mapRichTextSettings(
|
|
1111
|
+
blockAType.attributes[ newAttributeKey ]
|
|
1112
|
+
),
|
|
1113
|
+
} );
|
|
1114
|
+
const newOffset = convertedValue.text.indexOf(
|
|
1115
|
+
START_OF_SELECTED_AREA
|
|
1116
|
+
);
|
|
1117
|
+
const newValue = remove( convertedValue, newOffset, newOffset + 1 );
|
|
1118
|
+
const newHtml = toHTMLString( {
|
|
1119
|
+
value: newValue,
|
|
1120
|
+
...mapRichTextSettings(
|
|
1121
|
+
blockAType.attributes[ newAttributeKey ]
|
|
1122
|
+
),
|
|
1123
|
+
} );
|
|
1124
|
+
|
|
1125
|
+
updatedAttributes[ newAttributeKey ] = newHtml;
|
|
1126
|
+
|
|
1127
|
+
dispatch.selectionChange(
|
|
1128
|
+
blockA.clientId,
|
|
1129
|
+
newAttributeKey,
|
|
1130
|
+
newOffset,
|
|
1131
|
+
newOffset
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1105
1134
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1135
|
+
dispatch.replaceBlocks(
|
|
1136
|
+
[ blockA.clientId, blockB.clientId ],
|
|
1137
|
+
[
|
|
1138
|
+
{
|
|
1139
|
+
...blockA,
|
|
1140
|
+
attributes: {
|
|
1141
|
+
...blockA.attributes,
|
|
1142
|
+
...updatedAttributes,
|
|
1143
|
+
},
|
|
1114
1144
|
},
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
};
|
|
1145
|
+
...blocksWithTheSameType.slice( 1 ),
|
|
1146
|
+
],
|
|
1147
|
+
0 // If we don't pass the `indexToSelect` it will default to the last block.
|
|
1148
|
+
);
|
|
1149
|
+
};
|
|
1121
1150
|
|
|
1122
1151
|
/**
|
|
1123
1152
|
* Yields action objects used in signalling that the blocks corresponding to
|
|
@@ -1127,32 +1156,34 @@ export const mergeBlocks = ( firstBlockClientId, secondBlockClientId ) => ( {
|
|
|
1127
1156
|
* @param {boolean} selectPrevious True if the previous block should be
|
|
1128
1157
|
* selected when a block is removed.
|
|
1129
1158
|
*/
|
|
1130
|
-
export const removeBlocks =
|
|
1131
|
-
|
|
1132
|
-
dispatch
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1159
|
+
export const removeBlocks =
|
|
1160
|
+
( clientIds, selectPrevious = true ) =>
|
|
1161
|
+
( { select, dispatch } ) => {
|
|
1162
|
+
if ( ! clientIds || ! clientIds.length ) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1137
1165
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1166
|
+
clientIds = castArray( clientIds );
|
|
1167
|
+
const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
|
|
1168
|
+
const canRemoveBlocks = select.canRemoveBlocks(
|
|
1169
|
+
clientIds,
|
|
1170
|
+
rootClientId
|
|
1171
|
+
);
|
|
1141
1172
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1173
|
+
if ( ! canRemoveBlocks ) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1145
1176
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1177
|
+
if ( selectPrevious ) {
|
|
1178
|
+
dispatch.selectPreviousBlock( clientIds[ 0 ] );
|
|
1179
|
+
}
|
|
1149
1180
|
|
|
1150
|
-
|
|
1181
|
+
dispatch( { type: 'REMOVE_BLOCKS', clientIds } );
|
|
1151
1182
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
};
|
|
1183
|
+
// To avoid a focus loss when removing the last block, assure there is
|
|
1184
|
+
// always a default block if the last of the blocks have been removed.
|
|
1185
|
+
dispatch( ensureDefaultBlock() );
|
|
1186
|
+
};
|
|
1156
1187
|
|
|
1157
1188
|
/**
|
|
1158
1189
|
* Returns an action object used in signalling that the block with the
|
|
@@ -1329,19 +1360,19 @@ export function selectionChange(
|
|
|
1329
1360
|
* to append.
|
|
1330
1361
|
* @param {?number} index Optional index where to insert the default block.
|
|
1331
1362
|
*/
|
|
1332
|
-
export const insertDefaultBlock =
|
|
1333
|
-
|
|
1334
|
-
} ) => {
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1363
|
+
export const insertDefaultBlock =
|
|
1364
|
+
( attributes, rootClientId, index ) =>
|
|
1365
|
+
( { dispatch } ) => {
|
|
1366
|
+
// Abort if there is no default block type (if it has been unregistered).
|
|
1367
|
+
const defaultBlockName = getDefaultBlockName();
|
|
1368
|
+
if ( ! defaultBlockName ) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1340
1371
|
|
|
1341
|
-
|
|
1372
|
+
const block = createBlock( defaultBlockName, attributes );
|
|
1342
1373
|
|
|
1343
|
-
|
|
1344
|
-
};
|
|
1374
|
+
return dispatch.insertBlock( block, index, rootClientId );
|
|
1375
|
+
};
|
|
1345
1376
|
|
|
1346
1377
|
/**
|
|
1347
1378
|
* Action that changes the nested settings of a given block.
|
|
@@ -1416,57 +1447,60 @@ export function __unstableMarkNextChangeAsNotPersistent() {
|
|
|
1416
1447
|
* consequence of it, so it is recommended to be called at the next idle period to ensure all
|
|
1417
1448
|
* selection changes have been recorded.
|
|
1418
1449
|
*/
|
|
1419
|
-
export const __unstableMarkAutomaticChange =
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1450
|
+
export const __unstableMarkAutomaticChange =
|
|
1451
|
+
() =>
|
|
1452
|
+
( { dispatch } ) => {
|
|
1453
|
+
dispatch( { type: 'MARK_AUTOMATIC_CHANGE' } );
|
|
1454
|
+
const { requestIdleCallback = ( cb ) => setTimeout( cb, 100 ) } =
|
|
1455
|
+
window;
|
|
1456
|
+
requestIdleCallback( () => {
|
|
1457
|
+
dispatch( { type: 'MARK_AUTOMATIC_CHANGE_FINAL' } );
|
|
1458
|
+
} );
|
|
1459
|
+
};
|
|
1426
1460
|
|
|
1427
1461
|
/**
|
|
1428
1462
|
* Action that enables or disables the navigation mode.
|
|
1429
1463
|
*
|
|
1430
1464
|
* @param {string} isNavigationMode Enable/Disable navigation mode.
|
|
1431
1465
|
*/
|
|
1432
|
-
export const setNavigationMode =
|
|
1433
|
-
|
|
1434
|
-
} ) => {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
};
|
|
1466
|
+
export const setNavigationMode =
|
|
1467
|
+
( isNavigationMode = true ) =>
|
|
1468
|
+
( { dispatch } ) => {
|
|
1469
|
+
dispatch( { type: 'SET_NAVIGATION_MODE', isNavigationMode } );
|
|
1470
|
+
|
|
1471
|
+
if ( isNavigationMode ) {
|
|
1472
|
+
speak(
|
|
1473
|
+
__(
|
|
1474
|
+
'You are currently in navigation mode. Navigate blocks using the Tab key and Arrow keys. Use Left and Right Arrow keys to move between nesting levels. To exit navigation mode and edit the selected block, press Enter.'
|
|
1475
|
+
)
|
|
1476
|
+
);
|
|
1477
|
+
} else {
|
|
1478
|
+
speak(
|
|
1479
|
+
__(
|
|
1480
|
+
'You are currently in edit mode. To return to the navigation mode, press Escape.'
|
|
1481
|
+
)
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1451
1485
|
|
|
1452
1486
|
/**
|
|
1453
1487
|
* Action that enables or disables the block moving mode.
|
|
1454
1488
|
*
|
|
1455
1489
|
* @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
|
|
1456
1490
|
*/
|
|
1457
|
-
export const setBlockMovingClientId =
|
|
1458
|
-
|
|
1459
|
-
} ) => {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
};
|
|
1491
|
+
export const setBlockMovingClientId =
|
|
1492
|
+
( hasBlockMovingClientId = null ) =>
|
|
1493
|
+
( { dispatch } ) => {
|
|
1494
|
+
dispatch( { type: 'SET_BLOCK_MOVING_MODE', hasBlockMovingClientId } );
|
|
1495
|
+
|
|
1496
|
+
if ( hasBlockMovingClientId ) {
|
|
1497
|
+
speak(
|
|
1498
|
+
__(
|
|
1499
|
+
'Use the Tab key and Arrow keys to choose new block location. Use Left and Right Arrow keys to move between nesting levels. Once location is selected press Enter or Space to move the block.'
|
|
1500
|
+
)
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1470
1504
|
|
|
1471
1505
|
/**
|
|
1472
1506
|
* Action that duplicates a list of blocks.
|
|
@@ -1474,93 +1508,101 @@ export const setBlockMovingClientId = ( hasBlockMovingClientId = null ) => ( {
|
|
|
1474
1508
|
* @param {string[]} clientIds
|
|
1475
1509
|
* @param {boolean} updateSelection
|
|
1476
1510
|
*/
|
|
1477
|
-
export const duplicateBlocks =
|
|
1478
|
-
|
|
1479
|
-
dispatch
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
}
|
|
1511
|
+
export const duplicateBlocks =
|
|
1512
|
+
( clientIds, updateSelection = true ) =>
|
|
1513
|
+
( { select, dispatch } ) => {
|
|
1514
|
+
if ( ! clientIds || ! clientIds.length ) {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1484
1517
|
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1518
|
+
// Return early if blocks don't exist.
|
|
1519
|
+
const blocks = select.getBlocksByClientId( clientIds );
|
|
1520
|
+
if ( some( blocks, ( block ) => ! block ) ) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1490
1523
|
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1524
|
+
// Return early if blocks don't support multiple usage.
|
|
1525
|
+
const blockNames = blocks.map( ( block ) => block.name );
|
|
1526
|
+
if (
|
|
1527
|
+
blockNames.some(
|
|
1528
|
+
( blockName ) =>
|
|
1529
|
+
! hasBlockSupport( blockName, 'multiple', true )
|
|
1530
|
+
)
|
|
1531
|
+
) {
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1500
1534
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
);
|
|
1505
|
-
const clonedBlocks = blocks.map( ( block ) =>
|
|
1506
|
-
__experimentalCloneSanitizedBlock( block )
|
|
1507
|
-
);
|
|
1508
|
-
dispatch.insertBlocks(
|
|
1509
|
-
clonedBlocks,
|
|
1510
|
-
lastSelectedIndex + 1,
|
|
1511
|
-
rootClientId,
|
|
1512
|
-
updateSelection
|
|
1513
|
-
);
|
|
1514
|
-
if ( clonedBlocks.length > 1 && updateSelection ) {
|
|
1515
|
-
dispatch.multiSelect(
|
|
1516
|
-
first( clonedBlocks ).clientId,
|
|
1517
|
-
last( clonedBlocks ).clientId
|
|
1535
|
+
const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
|
|
1536
|
+
const lastSelectedIndex = select.getBlockIndex(
|
|
1537
|
+
last( castArray( clientIds ) )
|
|
1518
1538
|
);
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1539
|
+
const clonedBlocks = blocks.map( ( block ) =>
|
|
1540
|
+
__experimentalCloneSanitizedBlock( block )
|
|
1541
|
+
);
|
|
1542
|
+
dispatch.insertBlocks(
|
|
1543
|
+
clonedBlocks,
|
|
1544
|
+
lastSelectedIndex + 1,
|
|
1545
|
+
rootClientId,
|
|
1546
|
+
updateSelection
|
|
1547
|
+
);
|
|
1548
|
+
if ( clonedBlocks.length > 1 && updateSelection ) {
|
|
1549
|
+
dispatch.multiSelect(
|
|
1550
|
+
first( clonedBlocks ).clientId,
|
|
1551
|
+
last( clonedBlocks ).clientId
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
return clonedBlocks.map( ( block ) => block.clientId );
|
|
1555
|
+
};
|
|
1522
1556
|
|
|
1523
1557
|
/**
|
|
1524
1558
|
* Action that inserts an empty block before a given block.
|
|
1525
1559
|
*
|
|
1526
1560
|
* @param {string} clientId
|
|
1527
1561
|
*/
|
|
1528
|
-
export const insertBeforeBlock =
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1562
|
+
export const insertBeforeBlock =
|
|
1563
|
+
( clientId ) =>
|
|
1564
|
+
( { select, dispatch } ) => {
|
|
1565
|
+
if ( ! clientId ) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
const rootClientId = select.getBlockRootClientId( clientId );
|
|
1569
|
+
const isLocked = select.getTemplateLock( rootClientId );
|
|
1570
|
+
if ( isLocked ) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1537
1573
|
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1574
|
+
const firstSelectedIndex = select.getBlockIndex( clientId );
|
|
1575
|
+
return dispatch.insertDefaultBlock(
|
|
1576
|
+
{},
|
|
1577
|
+
rootClientId,
|
|
1578
|
+
firstSelectedIndex
|
|
1579
|
+
);
|
|
1580
|
+
};
|
|
1541
1581
|
|
|
1542
1582
|
/**
|
|
1543
1583
|
* Action that inserts an empty block after a given block.
|
|
1544
1584
|
*
|
|
1545
1585
|
* @param {string} clientId
|
|
1546
1586
|
*/
|
|
1547
|
-
export const insertAfterBlock =
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1587
|
+
export const insertAfterBlock =
|
|
1588
|
+
( clientId ) =>
|
|
1589
|
+
( { select, dispatch } ) => {
|
|
1590
|
+
if ( ! clientId ) {
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
const rootClientId = select.getBlockRootClientId( clientId );
|
|
1594
|
+
const isLocked = select.getTemplateLock( rootClientId );
|
|
1595
|
+
if ( isLocked ) {
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1556
1598
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
};
|
|
1599
|
+
const firstSelectedIndex = select.getBlockIndex( clientId );
|
|
1600
|
+
return dispatch.insertDefaultBlock(
|
|
1601
|
+
{},
|
|
1602
|
+
rootClientId,
|
|
1603
|
+
firstSelectedIndex + 1
|
|
1604
|
+
);
|
|
1605
|
+
};
|
|
1564
1606
|
|
|
1565
1607
|
/**
|
|
1566
1608
|
* Action that toggles the highlighted block state.
|
|
@@ -1581,11 +1623,13 @@ export function toggleBlockHighlight( clientId, isHighlighted ) {
|
|
|
1581
1623
|
*
|
|
1582
1624
|
* @param {string} clientId Target block client ID.
|
|
1583
1625
|
*/
|
|
1584
|
-
export const flashBlock =
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1626
|
+
export const flashBlock =
|
|
1627
|
+
( clientId ) =>
|
|
1628
|
+
async ( { dispatch } ) => {
|
|
1629
|
+
dispatch( toggleBlockHighlight( clientId, true ) );
|
|
1630
|
+
await new Promise( ( resolve ) => setTimeout( resolve, 150 ) );
|
|
1631
|
+
dispatch( toggleBlockHighlight( clientId, false ) );
|
|
1632
|
+
};
|
|
1589
1633
|
|
|
1590
1634
|
/**
|
|
1591
1635
|
* Action that sets whether a block has controlled inner blocks.
|
|
@@ -1603,3 +1647,15 @@ export function setHasControlledInnerBlocks(
|
|
|
1603
1647
|
clientId,
|
|
1604
1648
|
};
|
|
1605
1649
|
}
|
|
1650
|
+
|
|
1651
|
+
/**
|
|
1652
|
+
* Action that sets whether given blocks are visible on the canvas.
|
|
1653
|
+
*
|
|
1654
|
+
* @param {Record<string,boolean>} updates For each block's clientId, its new visibility setting.
|
|
1655
|
+
*/
|
|
1656
|
+
export function setBlockVisibility( updates ) {
|
|
1657
|
+
return {
|
|
1658
|
+
type: 'SET_BLOCK_VISIBILITY',
|
|
1659
|
+
updates,
|
|
1660
|
+
};
|
|
1661
|
+
}
|