@wordpress/block-editor 7.0.4 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +31 -0
- package/build/components/alignment-control/ui.js +1 -2
- package/build/components/alignment-control/ui.js.map +1 -1
- package/build/components/block-icon/index.js +5 -1
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -0
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/index.native.js +1 -1
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +21 -8
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +0 -1
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-patterns-list/index.js +1 -8
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-settings/container.native.js +5 -2
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/preview.native.js +2 -2
- package/build/components/block-styles/preview.native.js.map +1 -1
- package/build/components/colors-gradients/control.js +8 -47
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +81 -6
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/duotone-control/index.js +5 -2
- package/build/components/duotone-control/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +27 -15
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/iframe/index.js +1 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +20 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +2 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inner-blocks/index.js +5 -4
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +4 -3
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/explorer.js +62 -0
- package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +111 -0
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
- package/build/components/inserter/block-patterns-explorer/sidebar.js +78 -0
- package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
- package/build/components/inserter/block-patterns-tab.js +74 -45
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
- package/build/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build/components/inserter/pattern-panel.js +19 -10
- package/build/components/inserter/pattern-panel.js.map +1 -1
- package/build/components/inspector-controls/groups.js +3 -1
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +9 -6
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/link-control/index.js +88 -35
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/link-preview.js +19 -6
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/link-control/search-input.js +12 -3
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block.js +49 -23
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +92 -73
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +39 -16
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +1 -1
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +8 -58
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/rich-text/embed-handler-picker.native.js +1 -0
- package/build/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build/components/rich-text/format-edit.js +28 -2
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/format-toolbar/index.js +2 -1
- package/build/components/rich-text/format-toolbar/index.js.map +1 -1
- package/build/components/url-input/index.js +11 -4
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-setting/index.js +48 -9
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/border.js +5 -5
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +2 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/duotone.js +16 -5
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/font-appearance.js +49 -6
- package/build/hooks/font-appearance.js.map +1 -1
- package/build/hooks/font-family.js +37 -16
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +51 -9
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/index.js +8 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +8 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/letter-spacing.js +44 -7
- package/build/hooks/letter-spacing.js.map +1 -1
- package/build/hooks/line-height.js +45 -8
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/margin.js +1 -1
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +1 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/text-decoration.js +42 -6
- package/build/hooks/text-decoration.js.map +1 -1
- package/build/hooks/text-transform.js +42 -6
- package/build/hooks/text-transform.js.map +1 -1
- package/build/hooks/typography.js +108 -8
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-cached-truthy.js +29 -0
- package/build/hooks/use-cached-truthy.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/layouts/flex.js +120 -28
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +303 -265
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +1 -3
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +23 -22
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +44 -35
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/alignment-control/ui.js +1 -2
- package/build-module/components/alignment-control/ui.js.map +1 -1
- package/build-module/components/block-icon/index.js +5 -1
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +4 -0
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +1 -1
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +21 -8
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +0 -1
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +1 -6
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +6 -3
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +24 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/preview.native.js +2 -2
- package/build-module/components/block-styles/preview.native.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +12 -53
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +82 -6
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/duotone-control/index.js +5 -2
- package/build-module/components/duotone-control/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +23 -15
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +3 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +6 -5
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +5 -4
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/explorer.js +50 -0
- package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -0
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +92 -0
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -0
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js +69 -0
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -0
- package/build-module/components/inserter/block-patterns-tab.js +75 -46
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-type-impressions.native.js +4 -7
- package/build-module/components/inserter/hooks/use-block-type-impressions.native.js.map +1 -1
- package/build-module/components/inserter/pattern-panel.js +21 -13
- package/build-module/components/inserter/pattern-panel.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +3 -1
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +9 -6
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/link-control/index.js +88 -36
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +19 -7
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/link-control/search-input.js +11 -3
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block.js +49 -24
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +92 -73
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +41 -18
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +1 -1
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +8 -58
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/rich-text/embed-handler-picker.native.js +1 -0
- package/build-module/components/rich-text/embed-handler-picker.native.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +28 -3
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar/index.js +2 -1
- package/build-module/components/rich-text/format-toolbar/index.js.map +1 -1
- package/build-module/components/url-input/index.js +11 -4
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +48 -9
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/border.js +5 -5
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +2 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/duotone.js +16 -5
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/font-appearance.js +45 -6
- package/build-module/hooks/font-appearance.js.map +1 -1
- package/build-module/hooks/font-family.js +33 -16
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +47 -9
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/letter-spacing.js +40 -7
- package/build-module/hooks/letter-spacing.js.map +1 -1
- package/build-module/hooks/line-height.js +41 -8
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/margin.js +1 -1
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +1 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/text-decoration.js +38 -6
- package/build-module/hooks/text-decoration.js.map +1 -1
- package/build-module/hooks/text-transform.js +38 -6
- package/build-module/hooks/text-transform.js.map +1 -1
- package/build-module/hooks/typography.js +117 -17
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-cached-truthy.js +21 -0
- package/build-module/hooks/use-cached-truthy.js.map +1 -0
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flex.js +124 -32
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +266 -241
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +1 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +23 -22
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +42 -30
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +160 -57
- package/build-style/style.css +160 -57
- package/package.json +13 -14
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +0 -2
- package/src/components/alignment-control/ui.js +1 -4
- package/src/components/block-draggable/style.scss +19 -4
- package/src/components/block-icon/index.js +4 -1
- package/src/components/block-inspector/index.js +5 -0
- package/src/components/block-list/index.native.js +1 -1
- package/src/components/block-list/use-block-props/use-multi-selection.js +27 -7
- package/src/components/block-navigation/dropdown.js +0 -1
- package/src/components/block-patterns-list/index.js +1 -8
- package/src/components/block-patterns-list/style.scss +22 -12
- package/src/components/block-settings/container.native.js +7 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +19 -7
- package/src/components/block-styles/preview.native.js +2 -2
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +1 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +88 -63
- package/src/components/colors-gradients/control.js +19 -62
- package/src/components/colors-gradients/panel-color-gradient-settings.js +76 -6
- package/src/components/colors-gradients/style.scss +3 -14
- package/src/components/colors-gradients/test/control.js +0 -16
- package/src/components/duotone-control/index.js +6 -0
- package/src/components/duotone-control/style.scss +27 -12
- package/src/components/font-appearance-control/index.js +22 -14
- package/src/components/iframe/index.js +1 -1
- package/src/components/index.js +3 -4
- package/src/components/index.native.js +1 -4
- package/src/components/inner-blocks/index.js +4 -4
- package/src/components/inner-blocks/index.native.js +7 -4
- package/src/components/inserter/block-patterns-explorer/explorer.js +50 -0
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +122 -0
- package/src/components/inserter/block-patterns-explorer/sidebar.js +73 -0
- package/src/components/inserter/block-patterns-tab.js +107 -80
- package/src/components/inserter/hooks/use-block-type-impressions.native.js +14 -21
- package/src/components/inserter/pattern-panel.js +33 -16
- package/src/components/inserter/style.scss +64 -1
- package/src/components/inserter/test/block-types-tab.native.js +1 -1
- package/src/components/inserter/test/fixtures/index.native.js +12 -0
- package/src/components/inspector-controls/groups.js +4 -0
- package/src/components/letter-spacing-control/index.js +12 -6
- package/src/components/link-control/README.md +7 -0
- package/src/components/link-control/index.js +99 -34
- package/src/components/link-control/link-preview.js +21 -9
- package/src/components/link-control/search-input.js +9 -3
- package/src/components/link-control/style.scss +32 -16
- package/src/components/link-control/test/index.js +179 -4
- package/src/components/list-view/block.js +67 -23
- package/src/components/list-view/branch.js +113 -91
- package/src/components/list-view/index.js +58 -19
- package/src/components/list-view/leaf.js +1 -1
- package/src/components/list-view/style.scss +14 -3
- package/src/components/list-view/use-list-view-client-ids.js +7 -66
- package/src/components/rich-text/embed-handler-picker.native.js +1 -0
- package/src/components/rich-text/format-edit.js +36 -2
- package/src/components/rich-text/format-toolbar/index.js +3 -0
- package/src/components/url-input/index.js +14 -4
- package/src/components/use-setting/index.js +49 -11
- package/src/hooks/border.js +8 -11
- package/src/hooks/color-panel.js +1 -0
- package/src/hooks/duotone.js +21 -7
- package/src/hooks/font-appearance.js +38 -7
- package/src/hooks/font-family.js +29 -13
- package/src/hooks/font-size.js +42 -6
- package/src/hooks/index.js +1 -0
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/layout.scss +3 -1
- package/src/hooks/letter-spacing.js +35 -7
- package/src/hooks/line-height.js +37 -9
- package/src/hooks/margin.js +1 -1
- package/src/hooks/padding.js +1 -1
- package/src/hooks/text-decoration.js +34 -6
- package/src/hooks/text-transform.js +34 -6
- package/src/hooks/typography.js +165 -15
- package/src/hooks/typography.scss +16 -0
- package/src/hooks/use-cached-truthy.js +20 -0
- package/src/index.js +1 -0
- package/src/layouts/flex.js +137 -41
- package/src/store/actions.js +223 -391
- package/src/store/index.js +1 -2
- package/src/store/reducer.js +36 -18
- package/src/store/selectors.js +52 -47
- package/src/store/test/actions.js +395 -694
- package/src/store/test/selectors.js +79 -21
- package/src/style.scss +1 -1
- package/src/utils/test/parse-css-unit-to-px.js +127 -167
- package/build/components/text-decoration-and-transform/index.js +0 -39
- package/build/components/text-decoration-and-transform/index.js.map +0 -1
- package/build/store/controls.js +0 -44
- package/build/store/controls.js.map +0 -1
- package/build-module/components/text-decoration-and-transform/index.js +0 -30
- package/build-module/components/text-decoration-and-transform/index.js.map +0 -1
- package/build-module/store/controls.js +0 -32
- package/build-module/store/controls.js.map +0 -1
- package/src/components/text-decoration-and-transform/index.js +0 -36
- package/src/components/text-decoration-and-transform/style.scss +0 -3
- package/src/store/controls.js +0 -39
|
@@ -9,56 +9,57 @@ import { castArray, findKey, first, isObject, last, some } from 'lodash';
|
|
|
9
9
|
import { cloneBlock, __experimentalCloneSanitizedBlock, createBlock, doBlocksMatchTemplate, getBlockType, getDefaultBlockName, hasBlockSupport, switchToBlockType, synchronizeBlocksWithTemplate } from '@wordpress/blocks';
|
|
10
10
|
import { speak } from '@wordpress/a11y';
|
|
11
11
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
12
|
-
import { controls } from '@wordpress/data';
|
|
13
12
|
import { create, insert, remove, toHTMLString } from '@wordpress/rich-text';
|
|
14
13
|
import deprecated from '@wordpress/deprecated';
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { __unstableMarkAutomaticChangeFinalControl } from '../store/controls';
|
|
20
|
-
import { STORE_NAME as blockEditorStoreName } from './constants';
|
|
21
|
-
/**
|
|
22
|
-
* Generator which will yield a default block insert action if there
|
|
23
|
-
* are no other blocks at the root of the editor. This generator should be used
|
|
15
|
+
* Action which will insert a default block insert action if there
|
|
16
|
+
* are no other blocks at the root of the editor. This action should be used
|
|
24
17
|
* in actions which may result in no blocks remaining in the editor (removal,
|
|
25
18
|
* replacement, etc).
|
|
26
19
|
*/
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
const ensureDefaultBlock = () => ({
|
|
22
|
+
select,
|
|
23
|
+
dispatch
|
|
24
|
+
}) => {
|
|
25
|
+
// To avoid a focus loss when removing the last block, assure there is
|
|
30
26
|
// always a default block if the last of the blocks have been removed.
|
|
27
|
+
const count = select.getBlockCount();
|
|
31
28
|
|
|
32
|
-
if (count
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// prevent it from being lost though.
|
|
29
|
+
if (count > 0) {
|
|
30
|
+
return;
|
|
31
|
+
} // If there's an custom appender, don't insert default block.
|
|
32
|
+
// We have to remember to manually move the focus elsewhere to
|
|
33
|
+
// prevent it from being lost though.
|
|
38
34
|
|
|
39
|
-
if (__unstableHasCustomAppender) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
35
|
|
|
43
|
-
|
|
36
|
+
const {
|
|
37
|
+
__unstableHasCustomAppender
|
|
38
|
+
} = select.getSettings();
|
|
39
|
+
|
|
40
|
+
if (__unstableHasCustomAppender) {
|
|
41
|
+
return;
|
|
44
42
|
}
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
dispatch.insertDefaultBlock();
|
|
45
|
+
};
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* content reflected as an edit in state.
|
|
47
|
+
* Action that resets blocks state to the specified array of blocks, taking precedence
|
|
48
|
+
* over any other content reflected as an edit in state.
|
|
50
49
|
*
|
|
51
50
|
* @param {Array} blocks Array of blocks.
|
|
52
51
|
*/
|
|
53
52
|
|
|
54
53
|
|
|
55
|
-
export
|
|
56
|
-
|
|
54
|
+
export const resetBlocks = blocks => ({
|
|
55
|
+
dispatch
|
|
56
|
+
}) => {
|
|
57
|
+
dispatch({
|
|
57
58
|
type: 'RESET_BLOCKS',
|
|
58
59
|
blocks
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
}
|
|
60
|
+
});
|
|
61
|
+
dispatch(validateBlocksToTemplate(blocks));
|
|
62
|
+
};
|
|
62
63
|
/**
|
|
63
64
|
* Block validity is a function of blocks state (at the point of a
|
|
64
65
|
* reset) and the template setting. As a compromise to its placement
|
|
@@ -68,20 +69,23 @@ export function* resetBlocks(blocks) {
|
|
|
68
69
|
* @param {Array} blocks Array of blocks.
|
|
69
70
|
*/
|
|
70
71
|
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
export const validateBlocksToTemplate = blocks => ({
|
|
73
|
+
select,
|
|
74
|
+
dispatch
|
|
75
|
+
}) => {
|
|
76
|
+
const template = select.getTemplate();
|
|
77
|
+
const templateLock = select.getTemplateLock(); // Unlocked templates are considered always valid because they act
|
|
74
78
|
// as default values only.
|
|
75
79
|
|
|
76
80
|
const isBlocksValidToTemplate = !template || templateLock !== 'all' || doBlocksMatchTemplate(blocks, template); // Update if validity has changed.
|
|
77
81
|
|
|
78
|
-
const isValidTemplate =
|
|
82
|
+
const isValidTemplate = select.isValidTemplate();
|
|
79
83
|
|
|
80
84
|
if (isBlocksValidToTemplate !== isValidTemplate) {
|
|
81
|
-
|
|
85
|
+
dispatch.setTemplateValidity(isBlocksValidToTemplate);
|
|
82
86
|
return isBlocksValidToTemplate;
|
|
83
87
|
}
|
|
84
|
-
}
|
|
88
|
+
};
|
|
85
89
|
/**
|
|
86
90
|
* A block selection object.
|
|
87
91
|
*
|
|
@@ -138,8 +142,7 @@ export function receiveBlocks(blocks) {
|
|
|
138
142
|
};
|
|
139
143
|
}
|
|
140
144
|
/**
|
|
141
|
-
*
|
|
142
|
-
* attributes with the specified client IDs have been updated.
|
|
145
|
+
* Action that updates attributes of multiple blocks with the specified client IDs.
|
|
143
146
|
*
|
|
144
147
|
* @param {string|string[]} clientIds Block client IDs.
|
|
145
148
|
* @param {Object} attributes Block attributes to be merged. Should be keyed by clientIds if
|
|
@@ -157,8 +160,7 @@ export function updateBlockAttributes(clientIds, attributes, uniqueByBlock = fal
|
|
|
157
160
|
};
|
|
158
161
|
}
|
|
159
162
|
/**
|
|
160
|
-
*
|
|
161
|
-
* specified client ID has been updated.
|
|
163
|
+
* Action that updates the block with the specified client ID.
|
|
162
164
|
*
|
|
163
165
|
* @param {string} clientId Block client ID.
|
|
164
166
|
* @param {Object} updates Block attributes to be merged.
|
|
@@ -203,14 +205,16 @@ export function selectBlock(clientId, initialPosition = 0) {
|
|
|
203
205
|
* @param {string} clientId Block client ID.
|
|
204
206
|
*/
|
|
205
207
|
|
|
206
|
-
export
|
|
207
|
-
|
|
208
|
+
export const selectPreviousBlock = clientId => ({
|
|
209
|
+
select,
|
|
210
|
+
dispatch
|
|
211
|
+
}) => {
|
|
212
|
+
const previousBlockClientId = select.getPreviousBlockClientId(clientId);
|
|
208
213
|
|
|
209
214
|
if (previousBlockClientId) {
|
|
210
|
-
|
|
211
|
-
return [previousBlockClientId];
|
|
215
|
+
dispatch.selectBlock(previousBlockClientId, -1);
|
|
212
216
|
}
|
|
213
|
-
}
|
|
217
|
+
};
|
|
214
218
|
/**
|
|
215
219
|
* Yields action objects used in signalling that the block following the given
|
|
216
220
|
* clientId should be selected.
|
|
@@ -218,16 +222,18 @@ export function* selectPreviousBlock(clientId) {
|
|
|
218
222
|
* @param {string} clientId Block client ID.
|
|
219
223
|
*/
|
|
220
224
|
|
|
221
|
-
export
|
|
222
|
-
|
|
225
|
+
export const selectNextBlock = clientId => ({
|
|
226
|
+
select,
|
|
227
|
+
dispatch
|
|
228
|
+
}) => {
|
|
229
|
+
const nextBlockClientId = select.getNextBlockClientId(clientId);
|
|
223
230
|
|
|
224
231
|
if (nextBlockClientId) {
|
|
225
|
-
|
|
226
|
-
return [nextBlockClientId];
|
|
232
|
+
dispatch.selectBlock(nextBlockClientId);
|
|
227
233
|
}
|
|
228
|
-
}
|
|
234
|
+
};
|
|
229
235
|
/**
|
|
230
|
-
*
|
|
236
|
+
* Action that starts block multi-selection.
|
|
231
237
|
*
|
|
232
238
|
* @return {Object} Action object.
|
|
233
239
|
*/
|
|
@@ -238,7 +244,7 @@ export function startMultiSelect() {
|
|
|
238
244
|
};
|
|
239
245
|
}
|
|
240
246
|
/**
|
|
241
|
-
*
|
|
247
|
+
* Action that stops block multi-selection.
|
|
242
248
|
*
|
|
243
249
|
* @return {Object} Action object.
|
|
244
250
|
*/
|
|
@@ -249,32 +255,35 @@ export function stopMultiSelect() {
|
|
|
249
255
|
};
|
|
250
256
|
}
|
|
251
257
|
/**
|
|
252
|
-
*
|
|
258
|
+
* Action that changes block multi-selection.
|
|
253
259
|
*
|
|
254
260
|
* @param {string} start First block of the multi selection.
|
|
255
261
|
* @param {string} end Last block of the multiselection.
|
|
256
262
|
*/
|
|
257
263
|
|
|
258
|
-
export
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
export const multiSelect = (start, end) => ({
|
|
265
|
+
select,
|
|
266
|
+
dispatch
|
|
267
|
+
}) => {
|
|
268
|
+
const startBlockRootClientId = select.getBlockRootClientId(start);
|
|
269
|
+
const endBlockRootClientId = select.getBlockRootClientId(end); // Only allow block multi-selections at the same level.
|
|
261
270
|
|
|
262
271
|
if (startBlockRootClientId !== endBlockRootClientId) {
|
|
263
272
|
return;
|
|
264
273
|
}
|
|
265
274
|
|
|
266
|
-
|
|
275
|
+
dispatch({
|
|
267
276
|
type: 'MULTI_SELECT',
|
|
268
277
|
start,
|
|
269
278
|
end
|
|
270
|
-
};
|
|
271
|
-
const blockCount =
|
|
279
|
+
});
|
|
280
|
+
const blockCount = select.getSelectedBlockCount();
|
|
272
281
|
speak(sprintf(
|
|
273
282
|
/* translators: %s: number of selected blocks */
|
|
274
283
|
_n('%s block selected.', '%s blocks selected.', blockCount), blockCount), 'assertive');
|
|
275
|
-
}
|
|
284
|
+
};
|
|
276
285
|
/**
|
|
277
|
-
*
|
|
286
|
+
* Action that clears the block selection.
|
|
278
287
|
*
|
|
279
288
|
* @return {Object} Action object.
|
|
280
289
|
*/
|
|
@@ -285,7 +294,7 @@ export function clearSelectedBlock() {
|
|
|
285
294
|
};
|
|
286
295
|
}
|
|
287
296
|
/**
|
|
288
|
-
*
|
|
297
|
+
* Action that enables or disables block selection.
|
|
289
298
|
*
|
|
290
299
|
* @param {boolean} [isSelectionEnabled=true] Whether block selection should
|
|
291
300
|
* be enabled.
|
|
@@ -337,8 +346,7 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
|
|
|
337
346
|
/* eslint-disable jsdoc/valid-types */
|
|
338
347
|
|
|
339
348
|
/**
|
|
340
|
-
*
|
|
341
|
-
* one or more replacement blocks.
|
|
349
|
+
* Action that replaces given blocks with one or more replacement blocks.
|
|
342
350
|
*
|
|
343
351
|
* @param {(string|string[])} clientIds Block client ID(s) to replace.
|
|
344
352
|
* @param {(Object|Object[])} blocks Replacement block(s).
|
|
@@ -346,26 +354,29 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
|
|
|
346
354
|
* @param {0|-1|null} initialPosition Index of caret after in the selected block after the operation.
|
|
347
355
|
* @param {?Object} meta Optional Meta values to be passed to the action object.
|
|
348
356
|
*
|
|
349
|
-
* @
|
|
357
|
+
* @return {Object} Action object.
|
|
350
358
|
*/
|
|
351
359
|
|
|
352
360
|
|
|
353
|
-
export
|
|
361
|
+
export const replaceBlocks = (clientIds, blocks, indexToSelect, initialPosition = 0, meta) => ({
|
|
362
|
+
select,
|
|
363
|
+
dispatch
|
|
364
|
+
}) => {
|
|
354
365
|
/* eslint-enable jsdoc/valid-types */
|
|
355
366
|
clientIds = castArray(clientIds);
|
|
356
|
-
blocks = getBlocksWithDefaultStylesApplied(castArray(blocks),
|
|
357
|
-
const rootClientId =
|
|
367
|
+
blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), select.getSettings());
|
|
368
|
+
const rootClientId = select.getBlockRootClientId(first(clientIds)); // Replace is valid if the new blocks can be inserted in the root block.
|
|
358
369
|
|
|
359
370
|
for (let index = 0; index < blocks.length; index++) {
|
|
360
371
|
const block = blocks[index];
|
|
361
|
-
const canInsertBlock =
|
|
372
|
+
const canInsertBlock = select.canInsertBlockType(block.name, rootClientId);
|
|
362
373
|
|
|
363
374
|
if (!canInsertBlock) {
|
|
364
375
|
return;
|
|
365
376
|
}
|
|
366
377
|
}
|
|
367
378
|
|
|
368
|
-
|
|
379
|
+
dispatch({
|
|
369
380
|
type: 'REPLACE_BLOCKS',
|
|
370
381
|
clientIds,
|
|
371
382
|
blocks,
|
|
@@ -373,12 +384,11 @@ export function* replaceBlocks(clientIds, blocks, indexToSelect, initialPosition
|
|
|
373
384
|
indexToSelect,
|
|
374
385
|
initialPosition,
|
|
375
386
|
meta
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
}
|
|
387
|
+
});
|
|
388
|
+
dispatch(ensureDefaultBlock());
|
|
389
|
+
};
|
|
379
390
|
/**
|
|
380
|
-
*
|
|
381
|
-
* with one or more replacement blocks.
|
|
391
|
+
* Action that replaces a single block with one or more replacement blocks.
|
|
382
392
|
*
|
|
383
393
|
* @param {(string|string[])} clientId Block client ID to replace.
|
|
384
394
|
* @param {(Object|Object[])} block Replacement block(s).
|
|
@@ -398,87 +408,83 @@ export function replaceBlock(clientId, block) {
|
|
|
398
408
|
* @return {Function} Action creator.
|
|
399
409
|
*/
|
|
400
410
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
411
|
+
const createOnMove = type => (clientIds, rootClientId) => ({
|
|
412
|
+
select,
|
|
413
|
+
dispatch
|
|
414
|
+
}) => {
|
|
415
|
+
// If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
416
|
+
const canMoveBlocks = select.canMoveBlocks(clientIds, rootClientId);
|
|
404
417
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
418
|
+
if (!canMoveBlocks) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
408
421
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
422
|
+
dispatch({
|
|
423
|
+
type,
|
|
424
|
+
clientIds: castArray(clientIds),
|
|
425
|
+
rootClientId
|
|
426
|
+
});
|
|
427
|
+
};
|
|
416
428
|
|
|
417
429
|
export const moveBlocksDown = createOnMove('MOVE_BLOCKS_DOWN');
|
|
418
430
|
export const moveBlocksUp = createOnMove('MOVE_BLOCKS_UP');
|
|
419
431
|
/**
|
|
420
|
-
*
|
|
421
|
-
* a new position.
|
|
432
|
+
* Action that moves given blocks to a new position.
|
|
422
433
|
*
|
|
423
434
|
* @param {?string} clientIds The client IDs of the blocks.
|
|
424
435
|
* @param {?string} fromRootClientId Root client ID source.
|
|
425
436
|
* @param {?string} toRootClientId Root client ID destination.
|
|
426
437
|
* @param {number} index The index to move the blocks to.
|
|
427
|
-
*
|
|
428
|
-
* @yield {Object} Action object.
|
|
429
438
|
*/
|
|
430
439
|
|
|
431
|
-
export
|
|
432
|
-
|
|
433
|
-
|
|
440
|
+
export const moveBlocksToPosition = (clientIds, fromRootClientId = '', toRootClientId = '', index) => ({
|
|
441
|
+
select,
|
|
442
|
+
dispatch
|
|
443
|
+
}) => {
|
|
444
|
+
const canMoveBlocks = select.canMoveBlocks(clientIds, fromRootClientId); // If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
434
445
|
|
|
435
446
|
if (!canMoveBlocks) {
|
|
436
447
|
return;
|
|
448
|
+
} // If moving inside the same root block the move is always possible.
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
if (fromRootClientId !== toRootClientId) {
|
|
452
|
+
const canRemoveBlocks = select.canRemoveBlocks(clientIds, fromRootClientId); // If we're moving to another block, it means we're deleting blocks from
|
|
453
|
+
// the original block, so we need to check if removing is possible.
|
|
454
|
+
|
|
455
|
+
if (!canRemoveBlocks) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const canInsertBlocks = select.canInsertBlocks(clientIds, toRootClientId); // 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.
|
|
460
|
+
|
|
461
|
+
if (!canInsertBlocks) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
437
464
|
}
|
|
438
465
|
|
|
439
|
-
|
|
466
|
+
dispatch({
|
|
440
467
|
type: 'MOVE_BLOCKS_TO_POSITION',
|
|
441
468
|
fromRootClientId,
|
|
442
469
|
toRootClientId,
|
|
443
470
|
clientIds,
|
|
444
471
|
index
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
if (fromRootClientId === toRootClientId) {
|
|
448
|
-
yield action;
|
|
449
|
-
return;
|
|
450
|
-
} // If we're moving to another block, it means we're deleting blocks from
|
|
451
|
-
// the original block, so we need to check if removing is possible.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (!canRemoveBlocks) {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const canInsertBlocks = yield controls.select(blockEditorStoreName, 'canInsertBlocks', clientIds, toRootClientId); // 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.
|
|
459
|
-
|
|
460
|
-
if (canInsertBlocks) {
|
|
461
|
-
yield action;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
472
|
+
});
|
|
473
|
+
};
|
|
464
474
|
/**
|
|
465
|
-
*
|
|
466
|
-
* new position.
|
|
475
|
+
* Action that moves given block to a new position.
|
|
467
476
|
*
|
|
468
477
|
* @param {?string} clientId The client ID of the block.
|
|
469
478
|
* @param {?string} fromRootClientId Root client ID source.
|
|
470
479
|
* @param {?string} toRootClientId Root client ID destination.
|
|
471
480
|
* @param {number} index The index to move the block to.
|
|
472
|
-
*
|
|
473
|
-
* @yield {Object} Action object.
|
|
474
481
|
*/
|
|
475
482
|
|
|
476
|
-
export function
|
|
477
|
-
|
|
483
|
+
export function moveBlockToPosition(clientId, fromRootClientId = '', toRootClientId = '', index) {
|
|
484
|
+
return moveBlocksToPosition([clientId], fromRootClientId, toRootClientId, index);
|
|
478
485
|
}
|
|
479
486
|
/**
|
|
480
|
-
*
|
|
481
|
-
* inserted, optionally at a specific index respective a root block list.
|
|
487
|
+
* Action that inserts a single block, optionally at a specific index respective a root block list.
|
|
482
488
|
*
|
|
483
489
|
* @param {Object} block Block object to insert.
|
|
484
490
|
* @param {?number} index Index at which block should be inserted.
|
|
@@ -489,14 +495,13 @@ export function* moveBlockToPosition(clientId, fromRootClientId = '', toRootClie
|
|
|
489
495
|
* @return {Object} Action object.
|
|
490
496
|
*/
|
|
491
497
|
|
|
492
|
-
export function insertBlock(block, index, rootClientId, updateSelection
|
|
498
|
+
export function insertBlock(block, index, rootClientId, updateSelection, meta) {
|
|
493
499
|
return insertBlocks([block], index, rootClientId, updateSelection, 0, meta);
|
|
494
500
|
}
|
|
495
501
|
/* eslint-disable jsdoc/valid-types */
|
|
496
502
|
|
|
497
503
|
/**
|
|
498
|
-
*
|
|
499
|
-
* be inserted, optionally at a specific index respective a root block list.
|
|
504
|
+
* Action that inserts an array of blocks, optionally at a specific index respective a root block list.
|
|
500
505
|
*
|
|
501
506
|
* @param {Object[]} blocks Block objects to insert.
|
|
502
507
|
* @param {?number} index Index at which block should be inserted.
|
|
@@ -507,7 +512,10 @@ export function insertBlock(block, index, rootClientId, updateSelection = true,
|
|
|
507
512
|
* @return {Object} Action object.
|
|
508
513
|
*/
|
|
509
514
|
|
|
510
|
-
export
|
|
515
|
+
export const insertBlocks = (blocks, index, rootClientId, updateSelection = true, initialPosition = 0, meta) => ({
|
|
516
|
+
select,
|
|
517
|
+
dispatch
|
|
518
|
+
}) => {
|
|
511
519
|
/* eslint-enable jsdoc/valid-types */
|
|
512
520
|
if (isObject(initialPosition)) {
|
|
513
521
|
meta = initialPosition;
|
|
@@ -519,11 +527,11 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
|
|
|
519
527
|
});
|
|
520
528
|
}
|
|
521
529
|
|
|
522
|
-
blocks = getBlocksWithDefaultStylesApplied(castArray(blocks),
|
|
530
|
+
blocks = getBlocksWithDefaultStylesApplied(castArray(blocks), select.getSettings());
|
|
523
531
|
const allowedBlocks = [];
|
|
524
532
|
|
|
525
533
|
for (const block of blocks) {
|
|
526
|
-
const isValid =
|
|
534
|
+
const isValid = select.canInsertBlockType(block.name, rootClientId);
|
|
527
535
|
|
|
528
536
|
if (isValid) {
|
|
529
537
|
allowedBlocks.push(block);
|
|
@@ -531,7 +539,7 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
|
|
|
531
539
|
}
|
|
532
540
|
|
|
533
541
|
if (allowedBlocks.length) {
|
|
534
|
-
|
|
542
|
+
dispatch({
|
|
535
543
|
type: 'INSERT_BLOCKS',
|
|
536
544
|
blocks: allowedBlocks,
|
|
537
545
|
index,
|
|
@@ -540,12 +548,11 @@ export function* insertBlocks(blocks, index, rootClientId, updateSelection = tru
|
|
|
540
548
|
updateSelection,
|
|
541
549
|
initialPosition: updateSelection ? initialPosition : null,
|
|
542
550
|
meta
|
|
543
|
-
};
|
|
551
|
+
});
|
|
544
552
|
}
|
|
545
|
-
}
|
|
553
|
+
};
|
|
546
554
|
/**
|
|
547
|
-
*
|
|
548
|
-
* be shown.
|
|
555
|
+
* Action that shows the insertion point.
|
|
549
556
|
*
|
|
550
557
|
* @param {?string} rootClientId Optional root client ID of block list on
|
|
551
558
|
* which to insert.
|
|
@@ -567,7 +574,7 @@ export function showInsertionPoint(rootClientId, index, __unstableOptions = {})
|
|
|
567
574
|
};
|
|
568
575
|
}
|
|
569
576
|
/**
|
|
570
|
-
*
|
|
577
|
+
* Action that hides the insertion point.
|
|
571
578
|
*
|
|
572
579
|
* @return {Object} Action object.
|
|
573
580
|
*/
|
|
@@ -578,7 +585,7 @@ export function hideInsertionPoint() {
|
|
|
578
585
|
};
|
|
579
586
|
}
|
|
580
587
|
/**
|
|
581
|
-
*
|
|
588
|
+
* Action that resets the template validity.
|
|
582
589
|
*
|
|
583
590
|
* @param {boolean} isValid template validity flag.
|
|
584
591
|
*
|
|
@@ -592,49 +599,55 @@ export function setTemplateValidity(isValid) {
|
|
|
592
599
|
};
|
|
593
600
|
}
|
|
594
601
|
/**
|
|
595
|
-
*
|
|
602
|
+
* Action that synchronizes the template with the list of blocks.
|
|
596
603
|
*
|
|
597
604
|
* @return {Object} Action object.
|
|
598
605
|
*/
|
|
599
606
|
|
|
600
|
-
export
|
|
601
|
-
|
|
607
|
+
export const synchronizeTemplate = () => ({
|
|
608
|
+
select,
|
|
609
|
+
dispatch
|
|
610
|
+
}) => {
|
|
611
|
+
dispatch({
|
|
602
612
|
type: 'SYNCHRONIZE_TEMPLATE'
|
|
603
|
-
};
|
|
604
|
-
const blocks =
|
|
605
|
-
const template =
|
|
613
|
+
});
|
|
614
|
+
const blocks = select.getBlocks();
|
|
615
|
+
const template = select.getTemplate();
|
|
606
616
|
const updatedBlockList = synchronizeBlocksWithTemplate(blocks, template);
|
|
607
|
-
|
|
608
|
-
}
|
|
617
|
+
dispatch.resetBlocks(updatedBlockList);
|
|
618
|
+
};
|
|
609
619
|
/**
|
|
610
|
-
*
|
|
620
|
+
* Action that merges two blocks.
|
|
611
621
|
*
|
|
612
622
|
* @param {string} firstBlockClientId Client ID of the first block to merge.
|
|
613
623
|
* @param {string} secondBlockClientId Client ID of the second block to merge.
|
|
614
624
|
*/
|
|
615
625
|
|
|
616
|
-
export
|
|
626
|
+
export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => ({
|
|
627
|
+
select,
|
|
628
|
+
dispatch
|
|
629
|
+
}) => {
|
|
617
630
|
const blocks = [firstBlockClientId, secondBlockClientId];
|
|
618
|
-
|
|
631
|
+
dispatch({
|
|
619
632
|
type: 'MERGE_BLOCKS',
|
|
620
633
|
blocks
|
|
621
|
-
};
|
|
634
|
+
});
|
|
622
635
|
const [clientIdA, clientIdB] = blocks;
|
|
623
|
-
const blockA =
|
|
636
|
+
const blockA = select.getBlock(clientIdA);
|
|
624
637
|
const blockAType = getBlockType(blockA.name); // Only focus the previous block if it's not mergeable
|
|
625
638
|
|
|
626
639
|
if (blockAType && !blockAType.merge) {
|
|
627
|
-
|
|
640
|
+
dispatch.selectBlock(blockA.clientId);
|
|
628
641
|
return;
|
|
629
642
|
}
|
|
630
643
|
|
|
631
|
-
const blockB =
|
|
644
|
+
const blockB = select.getBlock(clientIdB);
|
|
632
645
|
const blockBType = getBlockType(blockB.name);
|
|
633
646
|
const {
|
|
634
647
|
clientId,
|
|
635
648
|
attributeKey,
|
|
636
649
|
offset
|
|
637
|
-
} =
|
|
650
|
+
} = select.getSelectionStart();
|
|
638
651
|
const selectedBlockType = clientId === clientIdA ? blockAType : blockBType;
|
|
639
652
|
const attributeDefinition = selectedBlockType.attributes[attributeKey];
|
|
640
653
|
const canRestoreTextSelection = (clientId === clientIdA || clientId === clientIdB) && attributeKey !== undefined && offset !== undefined && // We cannot restore text selection if the RichText identifier
|
|
@@ -712,16 +725,16 @@ export function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
|
|
|
712
725
|
preserveWhiteSpace
|
|
713
726
|
});
|
|
714
727
|
updatedAttributes[newAttributeKey] = newHtml;
|
|
715
|
-
|
|
728
|
+
dispatch.selectionChange(blockA.clientId, newAttributeKey, newOffset, newOffset);
|
|
716
729
|
}
|
|
717
730
|
|
|
718
|
-
|
|
731
|
+
dispatch.replaceBlocks([blockA.clientId, blockB.clientId], [{ ...blockA,
|
|
719
732
|
attributes: { ...blockA.attributes,
|
|
720
733
|
...updatedAttributes
|
|
721
734
|
}
|
|
722
735
|
}, ...blocksWithTheSameType.slice(1)], 0 // If we don't pass the `indexToSelect` it will default to the last block.
|
|
723
736
|
);
|
|
724
|
-
}
|
|
737
|
+
};
|
|
725
738
|
/**
|
|
726
739
|
* Yields action objects used in signalling that the blocks corresponding to
|
|
727
740
|
* the set of specified client IDs are to be removed.
|
|
@@ -731,36 +744,34 @@ export function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
|
|
|
731
744
|
* selected when a block is removed.
|
|
732
745
|
*/
|
|
733
746
|
|
|
734
|
-
export
|
|
747
|
+
export const removeBlocks = (clientIds, selectPrevious = true) => ({
|
|
748
|
+
select,
|
|
749
|
+
dispatch
|
|
750
|
+
}) => {
|
|
735
751
|
if (!clientIds || !clientIds.length) {
|
|
736
752
|
return;
|
|
737
753
|
}
|
|
738
754
|
|
|
739
755
|
clientIds = castArray(clientIds);
|
|
740
|
-
const rootClientId =
|
|
741
|
-
const canRemoveBlocks =
|
|
756
|
+
const rootClientId = select.getBlockRootClientId(clientIds[0]);
|
|
757
|
+
const canRemoveBlocks = select.canRemoveBlocks(clientIds, rootClientId);
|
|
742
758
|
|
|
743
759
|
if (!canRemoveBlocks) {
|
|
744
760
|
return;
|
|
745
761
|
}
|
|
746
762
|
|
|
747
|
-
let previousBlockId;
|
|
748
|
-
|
|
749
763
|
if (selectPrevious) {
|
|
750
|
-
|
|
751
|
-
} else {
|
|
752
|
-
previousBlockId = yield controls.select(blockEditorStoreName, 'getPreviousBlockClientId', clientIds[0]);
|
|
764
|
+
dispatch.selectPreviousBlock(clientIds[0]);
|
|
753
765
|
}
|
|
754
766
|
|
|
755
|
-
|
|
767
|
+
dispatch({
|
|
756
768
|
type: 'REMOVE_BLOCKS',
|
|
757
769
|
clientIds
|
|
758
|
-
}; // To avoid a focus loss when removing the last block, assure there is
|
|
770
|
+
}); // To avoid a focus loss when removing the last block, assure there is
|
|
759
771
|
// always a default block if the last of the blocks have been removed.
|
|
760
772
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
}
|
|
773
|
+
dispatch(ensureDefaultBlock());
|
|
774
|
+
};
|
|
764
775
|
/**
|
|
765
776
|
* Returns an action object used in signalling that the block with the
|
|
766
777
|
* specified client ID is to be removed.
|
|
@@ -884,8 +895,7 @@ export function exitFormattedText() {
|
|
|
884
895
|
};
|
|
885
896
|
}
|
|
886
897
|
/**
|
|
887
|
-
*
|
|
888
|
-
* position.
|
|
898
|
+
* Action that changes the position of the user caret.
|
|
889
899
|
*
|
|
890
900
|
* @param {string} clientId The selected block client ID.
|
|
891
901
|
* @param {string} attributeKey The selected block attribute key.
|
|
@@ -905,8 +915,7 @@ export function selectionChange(clientId, attributeKey, startOffset, endOffset)
|
|
|
905
915
|
};
|
|
906
916
|
}
|
|
907
917
|
/**
|
|
908
|
-
*
|
|
909
|
-
* type should be added to the block list.
|
|
918
|
+
* Action that adds a new block of the default type to the block list.
|
|
910
919
|
*
|
|
911
920
|
* @param {?Object} attributes Optional attributes of the block to assign.
|
|
912
921
|
* @param {?string} rootClientId Optional root client ID of block list on which
|
|
@@ -928,7 +937,7 @@ export function insertDefaultBlock(attributes, rootClientId, index) {
|
|
|
928
937
|
return insertBlock(block, index, rootClientId);
|
|
929
938
|
}
|
|
930
939
|
/**
|
|
931
|
-
*
|
|
940
|
+
* Action that changes the nested settings of a given block.
|
|
932
941
|
*
|
|
933
942
|
* @param {string} clientId Client ID of the block whose nested setting are
|
|
934
943
|
* being received.
|
|
@@ -945,7 +954,7 @@ export function updateBlockListSettings(clientId, settings) {
|
|
|
945
954
|
};
|
|
946
955
|
}
|
|
947
956
|
/**
|
|
948
|
-
*
|
|
957
|
+
* Action that updates the block editor settings.
|
|
949
958
|
*
|
|
950
959
|
* @param {Object} settings Updated settings
|
|
951
960
|
*
|
|
@@ -959,7 +968,7 @@ export function updateSettings(settings) {
|
|
|
959
968
|
};
|
|
960
969
|
}
|
|
961
970
|
/**
|
|
962
|
-
*
|
|
971
|
+
* Action that signals that a temporary reusable block has been saved
|
|
963
972
|
* in order to switch its temporary id with the real id.
|
|
964
973
|
*
|
|
965
974
|
* @param {string} id Reusable block's id.
|
|
@@ -976,7 +985,7 @@ export function __unstableSaveReusableBlock(id, updatedId) {
|
|
|
976
985
|
};
|
|
977
986
|
}
|
|
978
987
|
/**
|
|
979
|
-
*
|
|
988
|
+
* Action that marks the last block change explicitly as persistent.
|
|
980
989
|
*
|
|
981
990
|
* @return {Object} Action object.
|
|
982
991
|
*/
|
|
@@ -987,7 +996,7 @@ export function __unstableMarkLastChangeAsPersistent() {
|
|
|
987
996
|
};
|
|
988
997
|
}
|
|
989
998
|
/**
|
|
990
|
-
*
|
|
999
|
+
* Action that signals that the next block change should be marked explicitly as not persistent.
|
|
991
1000
|
*
|
|
992
1001
|
* @return {Object} Action object.
|
|
993
1002
|
*/
|
|
@@ -998,138 +1007,156 @@ export function __unstableMarkNextChangeAsNotPersistent() {
|
|
|
998
1007
|
};
|
|
999
1008
|
}
|
|
1000
1009
|
/**
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1005
|
-
* it is recommended to be called at the next idle period to ensure all
|
|
1010
|
+
* Action that marks the last block change as an automatic change, meaning it was not
|
|
1011
|
+
* performed by the user, and can be undone using the `Escape` and `Backspace` keys.
|
|
1012
|
+
* This action must be called after the change was made, and any actions that are a
|
|
1013
|
+
* consequence of it, so it is recommended to be called at the next idle period to ensure all
|
|
1006
1014
|
* selection changes have been recorded.
|
|
1007
1015
|
*/
|
|
1008
1016
|
|
|
1009
|
-
export
|
|
1010
|
-
|
|
1017
|
+
export const __unstableMarkAutomaticChange = () => ({
|
|
1018
|
+
dispatch
|
|
1019
|
+
}) => {
|
|
1020
|
+
dispatch({
|
|
1011
1021
|
type: 'MARK_AUTOMATIC_CHANGE'
|
|
1012
|
-
};
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1022
|
+
});
|
|
1023
|
+
const {
|
|
1024
|
+
requestIdleCallback = cb => setTimeout(cb, 100)
|
|
1025
|
+
} = window;
|
|
1026
|
+
requestIdleCallback(() => {
|
|
1027
|
+
dispatch({
|
|
1028
|
+
type: 'MARK_AUTOMATIC_CHANGE_FINAL'
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
};
|
|
1020
1032
|
/**
|
|
1021
|
-
*
|
|
1033
|
+
* Action that enables or disables the navigation mode.
|
|
1022
1034
|
*
|
|
1023
1035
|
* @param {string} isNavigationMode Enable/Disable navigation mode.
|
|
1024
1036
|
*/
|
|
1025
1037
|
|
|
1026
|
-
export
|
|
1027
|
-
|
|
1038
|
+
export const setNavigationMode = (isNavigationMode = true) => ({
|
|
1039
|
+
dispatch
|
|
1040
|
+
}) => {
|
|
1041
|
+
dispatch({
|
|
1028
1042
|
type: 'SET_NAVIGATION_MODE',
|
|
1029
1043
|
isNavigationMode
|
|
1030
|
-
};
|
|
1044
|
+
});
|
|
1031
1045
|
|
|
1032
1046
|
if (isNavigationMode) {
|
|
1033
1047
|
speak(__('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.'));
|
|
1034
1048
|
} else {
|
|
1035
1049
|
speak(__('You are currently in edit mode. To return to the navigation mode, press Escape.'));
|
|
1036
1050
|
}
|
|
1037
|
-
}
|
|
1051
|
+
};
|
|
1038
1052
|
/**
|
|
1039
|
-
*
|
|
1053
|
+
* Action that enables or disables the block moving mode.
|
|
1040
1054
|
*
|
|
1041
1055
|
* @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
|
|
1042
1056
|
*/
|
|
1043
1057
|
|
|
1044
|
-
export
|
|
1045
|
-
|
|
1058
|
+
export const setBlockMovingClientId = (hasBlockMovingClientId = null) => ({
|
|
1059
|
+
dispatch
|
|
1060
|
+
}) => {
|
|
1061
|
+
dispatch({
|
|
1046
1062
|
type: 'SET_BLOCK_MOVING_MODE',
|
|
1047
1063
|
hasBlockMovingClientId
|
|
1048
|
-
};
|
|
1064
|
+
});
|
|
1049
1065
|
|
|
1050
1066
|
if (hasBlockMovingClientId) {
|
|
1051
1067
|
speak(__('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.'));
|
|
1052
1068
|
}
|
|
1053
|
-
}
|
|
1069
|
+
};
|
|
1054
1070
|
/**
|
|
1055
|
-
*
|
|
1071
|
+
* Action that duplicates a list of blocks.
|
|
1056
1072
|
*
|
|
1057
1073
|
* @param {string[]} clientIds
|
|
1058
1074
|
* @param {boolean} updateSelection
|
|
1059
1075
|
*/
|
|
1060
1076
|
|
|
1061
|
-
export
|
|
1062
|
-
|
|
1077
|
+
export const duplicateBlocks = (clientIds, updateSelection = true) => ({
|
|
1078
|
+
select,
|
|
1079
|
+
dispatch
|
|
1080
|
+
}) => {
|
|
1081
|
+
if (!clientIds || !clientIds.length) {
|
|
1063
1082
|
return;
|
|
1064
|
-
}
|
|
1083
|
+
} // Return early if blocks don't exist.
|
|
1084
|
+
|
|
1065
1085
|
|
|
1066
|
-
const blocks =
|
|
1067
|
-
const rootClientId = yield controls.select(blockEditorStoreName, 'getBlockRootClientId', clientIds[0]); // Return early if blocks don't exist.
|
|
1086
|
+
const blocks = select.getBlocksByClientId(clientIds);
|
|
1068
1087
|
|
|
1069
1088
|
if (some(blocks, block => !block)) {
|
|
1070
1089
|
return;
|
|
1071
|
-
}
|
|
1090
|
+
} // Return early if blocks don't support multiple usage.
|
|
1072
1091
|
|
|
1073
|
-
const blockNames = blocks.map(block => block.name); // Return early if blocks don't support multiple usage.
|
|
1074
1092
|
|
|
1075
|
-
|
|
1093
|
+
const blockNames = blocks.map(block => block.name);
|
|
1094
|
+
|
|
1095
|
+
if (blockNames.some(blockName => !hasBlockSupport(blockName, 'multiple', true))) {
|
|
1076
1096
|
return;
|
|
1077
1097
|
}
|
|
1078
1098
|
|
|
1079
|
-
const
|
|
1099
|
+
const rootClientId = select.getBlockRootClientId(clientIds[0]);
|
|
1100
|
+
const lastSelectedIndex = select.getBlockIndex(last(castArray(clientIds)), rootClientId);
|
|
1080
1101
|
const clonedBlocks = blocks.map(block => __experimentalCloneSanitizedBlock(block));
|
|
1081
|
-
|
|
1102
|
+
dispatch.insertBlocks(clonedBlocks, lastSelectedIndex + 1, rootClientId, updateSelection);
|
|
1082
1103
|
|
|
1083
1104
|
if (clonedBlocks.length > 1 && updateSelection) {
|
|
1084
|
-
|
|
1105
|
+
dispatch.multiSelect(first(clonedBlocks).clientId, last(clonedBlocks).clientId);
|
|
1085
1106
|
}
|
|
1086
1107
|
|
|
1087
1108
|
return clonedBlocks.map(block => block.clientId);
|
|
1088
|
-
}
|
|
1109
|
+
};
|
|
1089
1110
|
/**
|
|
1090
|
-
*
|
|
1111
|
+
* Action that inserts an empty block before a given block.
|
|
1091
1112
|
*
|
|
1092
1113
|
* @param {string} clientId
|
|
1093
1114
|
*/
|
|
1094
1115
|
|
|
1095
|
-
export
|
|
1116
|
+
export const insertBeforeBlock = clientId => ({
|
|
1117
|
+
select,
|
|
1118
|
+
dispatch
|
|
1119
|
+
}) => {
|
|
1096
1120
|
if (!clientId) {
|
|
1097
1121
|
return;
|
|
1098
1122
|
}
|
|
1099
1123
|
|
|
1100
|
-
const rootClientId =
|
|
1101
|
-
const isLocked =
|
|
1124
|
+
const rootClientId = select.getBlockRootClientId(clientId);
|
|
1125
|
+
const isLocked = select.getTemplateLock(rootClientId);
|
|
1102
1126
|
|
|
1103
1127
|
if (isLocked) {
|
|
1104
1128
|
return;
|
|
1105
1129
|
}
|
|
1106
1130
|
|
|
1107
|
-
const firstSelectedIndex =
|
|
1108
|
-
return
|
|
1109
|
-
}
|
|
1131
|
+
const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
|
|
1132
|
+
return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex);
|
|
1133
|
+
};
|
|
1110
1134
|
/**
|
|
1111
|
-
*
|
|
1135
|
+
* Action that inserts an empty block after a given block.
|
|
1112
1136
|
*
|
|
1113
1137
|
* @param {string} clientId
|
|
1114
1138
|
*/
|
|
1115
1139
|
|
|
1116
|
-
export
|
|
1140
|
+
export const insertAfterBlock = clientId => ({
|
|
1141
|
+
select,
|
|
1142
|
+
dispatch
|
|
1143
|
+
}) => {
|
|
1117
1144
|
if (!clientId) {
|
|
1118
1145
|
return;
|
|
1119
1146
|
}
|
|
1120
1147
|
|
|
1121
|
-
const rootClientId =
|
|
1122
|
-
const isLocked =
|
|
1148
|
+
const rootClientId = select.getBlockRootClientId(clientId);
|
|
1149
|
+
const isLocked = select.getTemplateLock(rootClientId);
|
|
1123
1150
|
|
|
1124
1151
|
if (isLocked) {
|
|
1125
1152
|
return;
|
|
1126
1153
|
}
|
|
1127
1154
|
|
|
1128
|
-
const firstSelectedIndex =
|
|
1129
|
-
return
|
|
1130
|
-
}
|
|
1155
|
+
const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
|
|
1156
|
+
return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex + 1);
|
|
1157
|
+
};
|
|
1131
1158
|
/**
|
|
1132
|
-
*
|
|
1159
|
+
* Action that toggles the highlighted block state.
|
|
1133
1160
|
*
|
|
1134
1161
|
* @param {string} clientId The block's clientId.
|
|
1135
1162
|
* @param {boolean} isHighlighted The highlight state.
|
|
@@ -1143,22 +1170,20 @@ export function toggleBlockHighlight(clientId, isHighlighted) {
|
|
|
1143
1170
|
};
|
|
1144
1171
|
}
|
|
1145
1172
|
/**
|
|
1146
|
-
*
|
|
1147
|
-
* given clientId should appear to "flash" by rhythmically highlighting it.
|
|
1173
|
+
* Action that "flashes" the block with a given `clientId` by rhythmically highlighting it.
|
|
1148
1174
|
*
|
|
1149
1175
|
* @param {string} clientId Target block client ID.
|
|
1150
1176
|
*/
|
|
1151
1177
|
|
|
1152
|
-
export
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1178
|
+
export const flashBlock = clientId => async ({
|
|
1179
|
+
dispatch
|
|
1180
|
+
}) => {
|
|
1181
|
+
dispatch(toggleBlockHighlight(clientId, true));
|
|
1182
|
+
await new Promise(resolve => setTimeout(resolve, 150));
|
|
1183
|
+
dispatch(toggleBlockHighlight(clientId, false));
|
|
1184
|
+
};
|
|
1160
1185
|
/**
|
|
1161
|
-
*
|
|
1186
|
+
* Action that sets whether a block has controlled inner blocks.
|
|
1162
1187
|
*
|
|
1163
1188
|
* @param {string} clientId The block's clientId.
|
|
1164
1189
|
* @param {boolean} hasControlledInnerBlocks True if the block's inner blocks are controlled.
|