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