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