@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
package/build/store/actions.js
CHANGED
|
@@ -5,32 +5,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.resetBlocks = resetBlocks;
|
|
9
|
-
exports.validateBlocksToTemplate = validateBlocksToTemplate;
|
|
10
8
|
exports.resetSelection = resetSelection;
|
|
11
9
|
exports.receiveBlocks = receiveBlocks;
|
|
12
10
|
exports.updateBlockAttributes = updateBlockAttributes;
|
|
13
11
|
exports.updateBlock = updateBlock;
|
|
14
12
|
exports.selectBlock = selectBlock;
|
|
15
|
-
exports.selectPreviousBlock = selectPreviousBlock;
|
|
16
|
-
exports.selectNextBlock = selectNextBlock;
|
|
17
13
|
exports.startMultiSelect = startMultiSelect;
|
|
18
14
|
exports.stopMultiSelect = stopMultiSelect;
|
|
19
|
-
exports.multiSelect = multiSelect;
|
|
20
15
|
exports.clearSelectedBlock = clearSelectedBlock;
|
|
21
16
|
exports.toggleSelection = toggleSelection;
|
|
22
|
-
exports.replaceBlocks = replaceBlocks;
|
|
23
17
|
exports.replaceBlock = replaceBlock;
|
|
24
|
-
exports.moveBlocksToPosition = moveBlocksToPosition;
|
|
25
18
|
exports.moveBlockToPosition = moveBlockToPosition;
|
|
26
19
|
exports.insertBlock = insertBlock;
|
|
27
|
-
exports.insertBlocks = insertBlocks;
|
|
28
20
|
exports.showInsertionPoint = showInsertionPoint;
|
|
29
21
|
exports.hideInsertionPoint = hideInsertionPoint;
|
|
30
22
|
exports.setTemplateValidity = setTemplateValidity;
|
|
31
|
-
exports.synchronizeTemplate = synchronizeTemplate;
|
|
32
|
-
exports.mergeBlocks = mergeBlocks;
|
|
33
|
-
exports.removeBlocks = removeBlocks;
|
|
34
23
|
exports.removeBlock = removeBlock;
|
|
35
24
|
exports.replaceInnerBlocks = replaceInnerBlocks;
|
|
36
25
|
exports.toggleBlockMode = toggleBlockMode;
|
|
@@ -47,17 +36,9 @@ exports.updateSettings = updateSettings;
|
|
|
47
36
|
exports.__unstableSaveReusableBlock = __unstableSaveReusableBlock;
|
|
48
37
|
exports.__unstableMarkLastChangeAsPersistent = __unstableMarkLastChangeAsPersistent;
|
|
49
38
|
exports.__unstableMarkNextChangeAsNotPersistent = __unstableMarkNextChangeAsNotPersistent;
|
|
50
|
-
exports.__unstableMarkAutomaticChange = __unstableMarkAutomaticChange;
|
|
51
|
-
exports.__unstableMarkAutomaticChangeFinal = __unstableMarkAutomaticChangeFinal;
|
|
52
|
-
exports.setNavigationMode = setNavigationMode;
|
|
53
|
-
exports.setBlockMovingClientId = setBlockMovingClientId;
|
|
54
|
-
exports.duplicateBlocks = duplicateBlocks;
|
|
55
|
-
exports.insertBeforeBlock = insertBeforeBlock;
|
|
56
|
-
exports.insertAfterBlock = insertAfterBlock;
|
|
57
39
|
exports.toggleBlockHighlight = toggleBlockHighlight;
|
|
58
|
-
exports.flashBlock = flashBlock;
|
|
59
40
|
exports.setHasControlledInnerBlocks = setHasControlledInnerBlocks;
|
|
60
|
-
exports.moveBlocksUp = exports.moveBlocksDown = void 0;
|
|
41
|
+
exports.flashBlock = exports.insertAfterBlock = exports.insertBeforeBlock = exports.duplicateBlocks = exports.setBlockMovingClientId = exports.setNavigationMode = exports.__unstableMarkAutomaticChange = exports.removeBlocks = exports.mergeBlocks = exports.synchronizeTemplate = exports.insertBlocks = exports.moveBlocksToPosition = exports.moveBlocksUp = exports.moveBlocksDown = exports.replaceBlocks = exports.multiSelect = exports.selectNextBlock = exports.selectPreviousBlock = exports.validateBlocksToTemplate = exports.resetBlocks = void 0;
|
|
61
42
|
|
|
62
43
|
var _lodash = require("lodash");
|
|
63
44
|
|
|
@@ -67,16 +48,10 @@ var _a11y = require("@wordpress/a11y");
|
|
|
67
48
|
|
|
68
49
|
var _i18n = require("@wordpress/i18n");
|
|
69
50
|
|
|
70
|
-
var _data = require("@wordpress/data");
|
|
71
|
-
|
|
72
51
|
var _richText = require("@wordpress/rich-text");
|
|
73
52
|
|
|
74
53
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
75
54
|
|
|
76
|
-
var _controls = require("../store/controls");
|
|
77
|
-
|
|
78
|
-
var _constants = require("./constants");
|
|
79
|
-
|
|
80
55
|
/**
|
|
81
56
|
* External dependencies
|
|
82
57
|
*/
|
|
@@ -86,49 +61,53 @@ var _constants = require("./constants");
|
|
|
86
61
|
*/
|
|
87
62
|
|
|
88
63
|
/**
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Generator which will yield a default block insert action if there
|
|
94
|
-
* are no other blocks at the root of the editor. This generator should be used
|
|
64
|
+
* Action which will insert a default block insert action if there
|
|
65
|
+
* are no other blocks at the root of the editor. This action should be used
|
|
95
66
|
* in actions which may result in no blocks remaining in the editor (removal,
|
|
96
67
|
* replacement, etc).
|
|
97
68
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
69
|
+
const ensureDefaultBlock = () => ({
|
|
70
|
+
select,
|
|
71
|
+
dispatch
|
|
72
|
+
}) => {
|
|
73
|
+
// To avoid a focus loss when removing the last block, assure there is
|
|
100
74
|
// always a default block if the last of the blocks have been removed.
|
|
75
|
+
const count = select.getBlockCount();
|
|
101
76
|
|
|
102
|
-
if (count
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// prevent it from being lost though.
|
|
77
|
+
if (count > 0) {
|
|
78
|
+
return;
|
|
79
|
+
} // If there's an custom appender, don't insert default block.
|
|
80
|
+
// We have to remember to manually move the focus elsewhere to
|
|
81
|
+
// prevent it from being lost though.
|
|
108
82
|
|
|
109
|
-
if (__unstableHasCustomAppender) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
83
|
|
|
113
|
-
|
|
84
|
+
const {
|
|
85
|
+
__unstableHasCustomAppender
|
|
86
|
+
} = select.getSettings();
|
|
87
|
+
|
|
88
|
+
if (__unstableHasCustomAppender) {
|
|
89
|
+
return;
|
|
114
90
|
}
|
|
115
|
-
|
|
91
|
+
|
|
92
|
+
dispatch.insertDefaultBlock();
|
|
93
|
+
};
|
|
116
94
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* content reflected as an edit in state.
|
|
95
|
+
* Action that resets blocks state to the specified array of blocks, taking precedence
|
|
96
|
+
* over any other content reflected as an edit in state.
|
|
120
97
|
*
|
|
121
98
|
* @param {Array} blocks Array of blocks.
|
|
122
99
|
*/
|
|
123
100
|
|
|
124
101
|
|
|
125
|
-
|
|
126
|
-
|
|
102
|
+
const resetBlocks = blocks => ({
|
|
103
|
+
dispatch
|
|
104
|
+
}) => {
|
|
105
|
+
dispatch({
|
|
127
106
|
type: 'RESET_BLOCKS',
|
|
128
107
|
blocks
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
}
|
|
108
|
+
});
|
|
109
|
+
dispatch(validateBlocksToTemplate(blocks));
|
|
110
|
+
};
|
|
132
111
|
/**
|
|
133
112
|
* Block validity is a function of blocks state (at the point of a
|
|
134
113
|
* reset) and the template setting. As a compromise to its placement
|
|
@@ -139,20 +118,25 @@ function* resetBlocks(blocks) {
|
|
|
139
118
|
*/
|
|
140
119
|
|
|
141
120
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
121
|
+
exports.resetBlocks = resetBlocks;
|
|
122
|
+
|
|
123
|
+
const validateBlocksToTemplate = blocks => ({
|
|
124
|
+
select,
|
|
125
|
+
dispatch
|
|
126
|
+
}) => {
|
|
127
|
+
const template = select.getTemplate();
|
|
128
|
+
const templateLock = select.getTemplateLock(); // Unlocked templates are considered always valid because they act
|
|
145
129
|
// as default values only.
|
|
146
130
|
|
|
147
131
|
const isBlocksValidToTemplate = !template || templateLock !== 'all' || (0, _blocks.doBlocksMatchTemplate)(blocks, template); // Update if validity has changed.
|
|
148
132
|
|
|
149
|
-
const isValidTemplate =
|
|
133
|
+
const isValidTemplate = select.isValidTemplate();
|
|
150
134
|
|
|
151
135
|
if (isBlocksValidToTemplate !== isValidTemplate) {
|
|
152
|
-
|
|
136
|
+
dispatch.setTemplateValidity(isBlocksValidToTemplate);
|
|
153
137
|
return isBlocksValidToTemplate;
|
|
154
138
|
}
|
|
155
|
-
}
|
|
139
|
+
};
|
|
156
140
|
/**
|
|
157
141
|
* A block selection object.
|
|
158
142
|
*
|
|
@@ -178,6 +162,8 @@ function* validateBlocksToTemplate(blocks) {
|
|
|
178
162
|
*/
|
|
179
163
|
|
|
180
164
|
|
|
165
|
+
exports.validateBlocksToTemplate = validateBlocksToTemplate;
|
|
166
|
+
|
|
181
167
|
function resetSelection(selectionStart, selectionEnd, initialPosition) {
|
|
182
168
|
/* eslint-enable jsdoc/valid-types */
|
|
183
169
|
return {
|
|
@@ -211,8 +197,7 @@ function receiveBlocks(blocks) {
|
|
|
211
197
|
};
|
|
212
198
|
}
|
|
213
199
|
/**
|
|
214
|
-
*
|
|
215
|
-
* attributes with the specified client IDs have been updated.
|
|
200
|
+
* Action that updates attributes of multiple blocks with the specified client IDs.
|
|
216
201
|
*
|
|
217
202
|
* @param {string|string[]} clientIds Block client IDs.
|
|
218
203
|
* @param {Object} attributes Block attributes to be merged. Should be keyed by clientIds if
|
|
@@ -231,8 +216,7 @@ function updateBlockAttributes(clientIds, attributes, uniqueByBlock = false) {
|
|
|
231
216
|
};
|
|
232
217
|
}
|
|
233
218
|
/**
|
|
234
|
-
*
|
|
235
|
-
* specified client ID has been updated.
|
|
219
|
+
* Action that updates the block with the specified client ID.
|
|
236
220
|
*
|
|
237
221
|
* @param {string} clientId Block client ID.
|
|
238
222
|
* @param {Object} updates Block attributes to be merged.
|
|
@@ -280,14 +264,16 @@ function selectBlock(clientId, initialPosition = 0) {
|
|
|
280
264
|
*/
|
|
281
265
|
|
|
282
266
|
|
|
283
|
-
|
|
284
|
-
|
|
267
|
+
const selectPreviousBlock = clientId => ({
|
|
268
|
+
select,
|
|
269
|
+
dispatch
|
|
270
|
+
}) => {
|
|
271
|
+
const previousBlockClientId = select.getPreviousBlockClientId(clientId);
|
|
285
272
|
|
|
286
273
|
if (previousBlockClientId) {
|
|
287
|
-
|
|
288
|
-
return [previousBlockClientId];
|
|
274
|
+
dispatch.selectBlock(previousBlockClientId, -1);
|
|
289
275
|
}
|
|
290
|
-
}
|
|
276
|
+
};
|
|
291
277
|
/**
|
|
292
278
|
* Yields action objects used in signalling that the block following the given
|
|
293
279
|
* clientId should be selected.
|
|
@@ -296,28 +282,34 @@ function* selectPreviousBlock(clientId) {
|
|
|
296
282
|
*/
|
|
297
283
|
|
|
298
284
|
|
|
299
|
-
|
|
300
|
-
|
|
285
|
+
exports.selectPreviousBlock = selectPreviousBlock;
|
|
286
|
+
|
|
287
|
+
const selectNextBlock = clientId => ({
|
|
288
|
+
select,
|
|
289
|
+
dispatch
|
|
290
|
+
}) => {
|
|
291
|
+
const nextBlockClientId = select.getNextBlockClientId(clientId);
|
|
301
292
|
|
|
302
293
|
if (nextBlockClientId) {
|
|
303
|
-
|
|
304
|
-
return [nextBlockClientId];
|
|
294
|
+
dispatch.selectBlock(nextBlockClientId);
|
|
305
295
|
}
|
|
306
|
-
}
|
|
296
|
+
};
|
|
307
297
|
/**
|
|
308
|
-
*
|
|
298
|
+
* Action that starts block multi-selection.
|
|
309
299
|
*
|
|
310
300
|
* @return {Object} Action object.
|
|
311
301
|
*/
|
|
312
302
|
|
|
313
303
|
|
|
304
|
+
exports.selectNextBlock = selectNextBlock;
|
|
305
|
+
|
|
314
306
|
function startMultiSelect() {
|
|
315
307
|
return {
|
|
316
308
|
type: 'START_MULTI_SELECT'
|
|
317
309
|
};
|
|
318
310
|
}
|
|
319
311
|
/**
|
|
320
|
-
*
|
|
312
|
+
* Action that stops block multi-selection.
|
|
321
313
|
*
|
|
322
314
|
* @return {Object} Action object.
|
|
323
315
|
*/
|
|
@@ -329,45 +321,50 @@ function stopMultiSelect() {
|
|
|
329
321
|
};
|
|
330
322
|
}
|
|
331
323
|
/**
|
|
332
|
-
*
|
|
324
|
+
* Action that changes block multi-selection.
|
|
333
325
|
*
|
|
334
326
|
* @param {string} start First block of the multi selection.
|
|
335
327
|
* @param {string} end Last block of the multiselection.
|
|
336
328
|
*/
|
|
337
329
|
|
|
338
330
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
331
|
+
const multiSelect = (start, end) => ({
|
|
332
|
+
select,
|
|
333
|
+
dispatch
|
|
334
|
+
}) => {
|
|
335
|
+
const startBlockRootClientId = select.getBlockRootClientId(start);
|
|
336
|
+
const endBlockRootClientId = select.getBlockRootClientId(end); // Only allow block multi-selections at the same level.
|
|
342
337
|
|
|
343
338
|
if (startBlockRootClientId !== endBlockRootClientId) {
|
|
344
339
|
return;
|
|
345
340
|
}
|
|
346
341
|
|
|
347
|
-
|
|
342
|
+
dispatch({
|
|
348
343
|
type: 'MULTI_SELECT',
|
|
349
344
|
start,
|
|
350
345
|
end
|
|
351
|
-
};
|
|
352
|
-
const blockCount =
|
|
346
|
+
});
|
|
347
|
+
const blockCount = select.getSelectedBlockCount();
|
|
353
348
|
(0, _a11y.speak)((0, _i18n.sprintf)(
|
|
354
349
|
/* translators: %s: number of selected blocks */
|
|
355
350
|
(0, _i18n._n)('%s block selected.', '%s blocks selected.', blockCount), blockCount), 'assertive');
|
|
356
|
-
}
|
|
351
|
+
};
|
|
357
352
|
/**
|
|
358
|
-
*
|
|
353
|
+
* Action that clears the block selection.
|
|
359
354
|
*
|
|
360
355
|
* @return {Object} Action object.
|
|
361
356
|
*/
|
|
362
357
|
|
|
363
358
|
|
|
359
|
+
exports.multiSelect = multiSelect;
|
|
360
|
+
|
|
364
361
|
function clearSelectedBlock() {
|
|
365
362
|
return {
|
|
366
363
|
type: 'CLEAR_SELECTED_BLOCK'
|
|
367
364
|
};
|
|
368
365
|
}
|
|
369
366
|
/**
|
|
370
|
-
*
|
|
367
|
+
* Action that enables or disables block selection.
|
|
371
368
|
*
|
|
372
369
|
* @param {boolean} [isSelectionEnabled=true] Whether block selection should
|
|
373
370
|
* be enabled.
|
|
@@ -420,8 +417,7 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
|
|
|
420
417
|
/* eslint-disable jsdoc/valid-types */
|
|
421
418
|
|
|
422
419
|
/**
|
|
423
|
-
*
|
|
424
|
-
* one or more replacement blocks.
|
|
420
|
+
* Action that replaces given blocks with one or more replacement blocks.
|
|
425
421
|
*
|
|
426
422
|
* @param {(string|string[])} clientIds Block client ID(s) to replace.
|
|
427
423
|
* @param {(Object|Object[])} blocks Replacement block(s).
|
|
@@ -429,26 +425,29 @@ function getBlocksWithDefaultStylesApplied(blocks, blockEditorSettings) {
|
|
|
429
425
|
* @param {0|-1|null} initialPosition Index of caret after in the selected block after the operation.
|
|
430
426
|
* @param {?Object} meta Optional Meta values to be passed to the action object.
|
|
431
427
|
*
|
|
432
|
-
* @
|
|
428
|
+
* @return {Object} Action object.
|
|
433
429
|
*/
|
|
434
430
|
|
|
435
431
|
|
|
436
|
-
|
|
432
|
+
const replaceBlocks = (clientIds, blocks, indexToSelect, initialPosition = 0, meta) => ({
|
|
433
|
+
select,
|
|
434
|
+
dispatch
|
|
435
|
+
}) => {
|
|
437
436
|
/* eslint-enable jsdoc/valid-types */
|
|
438
437
|
clientIds = (0, _lodash.castArray)(clientIds);
|
|
439
|
-
blocks = getBlocksWithDefaultStylesApplied((0, _lodash.castArray)(blocks),
|
|
440
|
-
const rootClientId =
|
|
438
|
+
blocks = getBlocksWithDefaultStylesApplied((0, _lodash.castArray)(blocks), select.getSettings());
|
|
439
|
+
const rootClientId = select.getBlockRootClientId((0, _lodash.first)(clientIds)); // Replace is valid if the new blocks can be inserted in the root block.
|
|
441
440
|
|
|
442
441
|
for (let index = 0; index < blocks.length; index++) {
|
|
443
442
|
const block = blocks[index];
|
|
444
|
-
const canInsertBlock =
|
|
443
|
+
const canInsertBlock = select.canInsertBlockType(block.name, rootClientId);
|
|
445
444
|
|
|
446
445
|
if (!canInsertBlock) {
|
|
447
446
|
return;
|
|
448
447
|
}
|
|
449
448
|
}
|
|
450
449
|
|
|
451
|
-
|
|
450
|
+
dispatch({
|
|
452
451
|
type: 'REPLACE_BLOCKS',
|
|
453
452
|
clientIds,
|
|
454
453
|
blocks,
|
|
@@ -456,12 +455,11 @@ function* replaceBlocks(clientIds, blocks, indexToSelect, initialPosition = 0, m
|
|
|
456
455
|
indexToSelect,
|
|
457
456
|
initialPosition,
|
|
458
457
|
meta
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
}
|
|
458
|
+
});
|
|
459
|
+
dispatch(ensureDefaultBlock());
|
|
460
|
+
};
|
|
462
461
|
/**
|
|
463
|
-
*
|
|
464
|
-
* with one or more replacement blocks.
|
|
462
|
+
* Action that replaces a single block with one or more replacement blocks.
|
|
465
463
|
*
|
|
466
464
|
* @param {(string|string[])} clientId Block client ID to replace.
|
|
467
465
|
* @param {(Object|Object[])} block Replacement block(s).
|
|
@@ -470,6 +468,8 @@ function* replaceBlocks(clientIds, blocks, indexToSelect, initialPosition = 0, m
|
|
|
470
468
|
*/
|
|
471
469
|
|
|
472
470
|
|
|
471
|
+
exports.replaceBlocks = replaceBlocks;
|
|
472
|
+
|
|
473
473
|
function replaceBlock(clientId, block) {
|
|
474
474
|
return replaceBlocks(clientId, block);
|
|
475
475
|
}
|
|
@@ -483,91 +483,89 @@ function replaceBlock(clientId, block) {
|
|
|
483
483
|
*/
|
|
484
484
|
|
|
485
485
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
486
|
+
const createOnMove = type => (clientIds, rootClientId) => ({
|
|
487
|
+
select,
|
|
488
|
+
dispatch
|
|
489
|
+
}) => {
|
|
490
|
+
// If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
491
|
+
const canMoveBlocks = select.canMoveBlocks(clientIds, rootClientId);
|
|
489
492
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
+
if (!canMoveBlocks) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
493
496
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
497
|
+
dispatch({
|
|
498
|
+
type,
|
|
499
|
+
clientIds: (0, _lodash.castArray)(clientIds),
|
|
500
|
+
rootClientId
|
|
501
|
+
});
|
|
502
|
+
};
|
|
501
503
|
|
|
502
504
|
const moveBlocksDown = createOnMove('MOVE_BLOCKS_DOWN');
|
|
503
505
|
exports.moveBlocksDown = moveBlocksDown;
|
|
504
506
|
const moveBlocksUp = createOnMove('MOVE_BLOCKS_UP');
|
|
505
507
|
/**
|
|
506
|
-
*
|
|
507
|
-
* a new position.
|
|
508
|
+
* Action that moves given blocks to a new position.
|
|
508
509
|
*
|
|
509
510
|
* @param {?string} clientIds The client IDs of the blocks.
|
|
510
511
|
* @param {?string} fromRootClientId Root client ID source.
|
|
511
512
|
* @param {?string} toRootClientId Root client ID destination.
|
|
512
513
|
* @param {number} index The index to move the blocks to.
|
|
513
|
-
*
|
|
514
|
-
* @yield {Object} Action object.
|
|
515
514
|
*/
|
|
516
515
|
|
|
517
516
|
exports.moveBlocksUp = moveBlocksUp;
|
|
518
517
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
const moveBlocksToPosition = (clientIds, fromRootClientId = '', toRootClientId = '', index) => ({
|
|
519
|
+
select,
|
|
520
|
+
dispatch
|
|
521
|
+
}) => {
|
|
522
|
+
const canMoveBlocks = select.canMoveBlocks(clientIds, fromRootClientId); // If one of the blocks is locked or the parent is locked, we cannot move any block.
|
|
522
523
|
|
|
523
524
|
if (!canMoveBlocks) {
|
|
524
525
|
return;
|
|
526
|
+
} // If moving inside the same root block the move is always possible.
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
if (fromRootClientId !== toRootClientId) {
|
|
530
|
+
const canRemoveBlocks = select.canRemoveBlocks(clientIds, fromRootClientId); // If we're moving to another block, it means we're deleting blocks from
|
|
531
|
+
// the original block, so we need to check if removing is possible.
|
|
532
|
+
|
|
533
|
+
if (!canRemoveBlocks) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
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.
|
|
538
|
+
|
|
539
|
+
if (!canInsertBlocks) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
525
542
|
}
|
|
526
543
|
|
|
527
|
-
|
|
544
|
+
dispatch({
|
|
528
545
|
type: 'MOVE_BLOCKS_TO_POSITION',
|
|
529
546
|
fromRootClientId,
|
|
530
547
|
toRootClientId,
|
|
531
548
|
clientIds,
|
|
532
549
|
index
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
if (fromRootClientId === toRootClientId) {
|
|
536
|
-
yield action;
|
|
537
|
-
return;
|
|
538
|
-
} // If we're moving to another block, it means we're deleting blocks from
|
|
539
|
-
// the original block, so we need to check if removing is possible.
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (!canRemoveBlocks) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const canInsertBlocks = yield _data.controls.select(_constants.STORE_NAME, '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.
|
|
547
|
-
|
|
548
|
-
if (canInsertBlocks) {
|
|
549
|
-
yield action;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
552
|
/**
|
|
553
|
-
*
|
|
554
|
-
* new position.
|
|
553
|
+
* Action that moves given block to a new position.
|
|
555
554
|
*
|
|
556
555
|
* @param {?string} clientId The client ID of the block.
|
|
557
556
|
* @param {?string} fromRootClientId Root client ID source.
|
|
558
557
|
* @param {?string} toRootClientId Root client ID destination.
|
|
559
558
|
* @param {number} index The index to move the block to.
|
|
560
|
-
*
|
|
561
|
-
* @yield {Object} Action object.
|
|
562
559
|
*/
|
|
563
560
|
|
|
564
561
|
|
|
565
|
-
|
|
566
|
-
|
|
562
|
+
exports.moveBlocksToPosition = moveBlocksToPosition;
|
|
563
|
+
|
|
564
|
+
function moveBlockToPosition(clientId, fromRootClientId = '', toRootClientId = '', index) {
|
|
565
|
+
return moveBlocksToPosition([clientId], fromRootClientId, toRootClientId, index);
|
|
567
566
|
}
|
|
568
567
|
/**
|
|
569
|
-
*
|
|
570
|
-
* inserted, optionally at a specific index respective a root block list.
|
|
568
|
+
* Action that inserts a single block, optionally at a specific index respective a root block list.
|
|
571
569
|
*
|
|
572
570
|
* @param {Object} block Block object to insert.
|
|
573
571
|
* @param {?number} index Index at which block should be inserted.
|
|
@@ -579,14 +577,13 @@ function* moveBlockToPosition(clientId, fromRootClientId = '', toRootClientId =
|
|
|
579
577
|
*/
|
|
580
578
|
|
|
581
579
|
|
|
582
|
-
function insertBlock(block, index, rootClientId, updateSelection
|
|
580
|
+
function insertBlock(block, index, rootClientId, updateSelection, meta) {
|
|
583
581
|
return insertBlocks([block], index, rootClientId, updateSelection, 0, meta);
|
|
584
582
|
}
|
|
585
583
|
/* eslint-disable jsdoc/valid-types */
|
|
586
584
|
|
|
587
585
|
/**
|
|
588
|
-
*
|
|
589
|
-
* be inserted, optionally at a specific index respective a root block list.
|
|
586
|
+
* Action that inserts an array of blocks, optionally at a specific index respective a root block list.
|
|
590
587
|
*
|
|
591
588
|
* @param {Object[]} blocks Block objects to insert.
|
|
592
589
|
* @param {?number} index Index at which block should be inserted.
|
|
@@ -598,7 +595,10 @@ function insertBlock(block, index, rootClientId, updateSelection = true, meta) {
|
|
|
598
595
|
*/
|
|
599
596
|
|
|
600
597
|
|
|
601
|
-
|
|
598
|
+
const insertBlocks = (blocks, index, rootClientId, updateSelection = true, initialPosition = 0, meta) => ({
|
|
599
|
+
select,
|
|
600
|
+
dispatch
|
|
601
|
+
}) => {
|
|
602
602
|
/* eslint-enable jsdoc/valid-types */
|
|
603
603
|
if ((0, _lodash.isObject)(initialPosition)) {
|
|
604
604
|
meta = initialPosition;
|
|
@@ -610,11 +610,11 @@ function* insertBlocks(blocks, index, rootClientId, updateSelection = true, init
|
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
blocks = getBlocksWithDefaultStylesApplied((0, _lodash.castArray)(blocks),
|
|
613
|
+
blocks = getBlocksWithDefaultStylesApplied((0, _lodash.castArray)(blocks), select.getSettings());
|
|
614
614
|
const allowedBlocks = [];
|
|
615
615
|
|
|
616
616
|
for (const block of blocks) {
|
|
617
|
-
const isValid =
|
|
617
|
+
const isValid = select.canInsertBlockType(block.name, rootClientId);
|
|
618
618
|
|
|
619
619
|
if (isValid) {
|
|
620
620
|
allowedBlocks.push(block);
|
|
@@ -622,7 +622,7 @@ function* insertBlocks(blocks, index, rootClientId, updateSelection = true, init
|
|
|
622
622
|
}
|
|
623
623
|
|
|
624
624
|
if (allowedBlocks.length) {
|
|
625
|
-
|
|
625
|
+
dispatch({
|
|
626
626
|
type: 'INSERT_BLOCKS',
|
|
627
627
|
blocks: allowedBlocks,
|
|
628
628
|
index,
|
|
@@ -631,12 +631,11 @@ function* insertBlocks(blocks, index, rootClientId, updateSelection = true, init
|
|
|
631
631
|
updateSelection,
|
|
632
632
|
initialPosition: updateSelection ? initialPosition : null,
|
|
633
633
|
meta
|
|
634
|
-
};
|
|
634
|
+
});
|
|
635
635
|
}
|
|
636
|
-
}
|
|
636
|
+
};
|
|
637
637
|
/**
|
|
638
|
-
*
|
|
639
|
-
* be shown.
|
|
638
|
+
* Action that shows the insertion point.
|
|
640
639
|
*
|
|
641
640
|
* @param {?string} rootClientId Optional root client ID of block list on
|
|
642
641
|
* which to insert.
|
|
@@ -647,6 +646,8 @@ function* insertBlocks(blocks, index, rootClientId, updateSelection = true, init
|
|
|
647
646
|
*/
|
|
648
647
|
|
|
649
648
|
|
|
649
|
+
exports.insertBlocks = insertBlocks;
|
|
650
|
+
|
|
650
651
|
function showInsertionPoint(rootClientId, index, __unstableOptions = {}) {
|
|
651
652
|
const {
|
|
652
653
|
__unstableWithInserter
|
|
@@ -659,7 +660,7 @@ function showInsertionPoint(rootClientId, index, __unstableOptions = {}) {
|
|
|
659
660
|
};
|
|
660
661
|
}
|
|
661
662
|
/**
|
|
662
|
-
*
|
|
663
|
+
* Action that hides the insertion point.
|
|
663
664
|
*
|
|
664
665
|
* @return {Object} Action object.
|
|
665
666
|
*/
|
|
@@ -671,7 +672,7 @@ function hideInsertionPoint() {
|
|
|
671
672
|
};
|
|
672
673
|
}
|
|
673
674
|
/**
|
|
674
|
-
*
|
|
675
|
+
* Action that resets the template validity.
|
|
675
676
|
*
|
|
676
677
|
* @param {boolean} isValid template validity flag.
|
|
677
678
|
*
|
|
@@ -686,51 +687,59 @@ function setTemplateValidity(isValid) {
|
|
|
686
687
|
};
|
|
687
688
|
}
|
|
688
689
|
/**
|
|
689
|
-
*
|
|
690
|
+
* Action that synchronizes the template with the list of blocks.
|
|
690
691
|
*
|
|
691
692
|
* @return {Object} Action object.
|
|
692
693
|
*/
|
|
693
694
|
|
|
694
695
|
|
|
695
|
-
|
|
696
|
-
|
|
696
|
+
const synchronizeTemplate = () => ({
|
|
697
|
+
select,
|
|
698
|
+
dispatch
|
|
699
|
+
}) => {
|
|
700
|
+
dispatch({
|
|
697
701
|
type: 'SYNCHRONIZE_TEMPLATE'
|
|
698
|
-
};
|
|
699
|
-
const blocks =
|
|
700
|
-
const template =
|
|
702
|
+
});
|
|
703
|
+
const blocks = select.getBlocks();
|
|
704
|
+
const template = select.getTemplate();
|
|
701
705
|
const updatedBlockList = (0, _blocks.synchronizeBlocksWithTemplate)(blocks, template);
|
|
702
|
-
|
|
703
|
-
}
|
|
706
|
+
dispatch.resetBlocks(updatedBlockList);
|
|
707
|
+
};
|
|
704
708
|
/**
|
|
705
|
-
*
|
|
709
|
+
* Action that merges two blocks.
|
|
706
710
|
*
|
|
707
711
|
* @param {string} firstBlockClientId Client ID of the first block to merge.
|
|
708
712
|
* @param {string} secondBlockClientId Client ID of the second block to merge.
|
|
709
713
|
*/
|
|
710
714
|
|
|
711
715
|
|
|
712
|
-
|
|
716
|
+
exports.synchronizeTemplate = synchronizeTemplate;
|
|
717
|
+
|
|
718
|
+
const mergeBlocks = (firstBlockClientId, secondBlockClientId) => ({
|
|
719
|
+
select,
|
|
720
|
+
dispatch
|
|
721
|
+
}) => {
|
|
713
722
|
const blocks = [firstBlockClientId, secondBlockClientId];
|
|
714
|
-
|
|
723
|
+
dispatch({
|
|
715
724
|
type: 'MERGE_BLOCKS',
|
|
716
725
|
blocks
|
|
717
|
-
};
|
|
726
|
+
});
|
|
718
727
|
const [clientIdA, clientIdB] = blocks;
|
|
719
|
-
const blockA =
|
|
728
|
+
const blockA = select.getBlock(clientIdA);
|
|
720
729
|
const blockAType = (0, _blocks.getBlockType)(blockA.name); // Only focus the previous block if it's not mergeable
|
|
721
730
|
|
|
722
731
|
if (blockAType && !blockAType.merge) {
|
|
723
|
-
|
|
732
|
+
dispatch.selectBlock(blockA.clientId);
|
|
724
733
|
return;
|
|
725
734
|
}
|
|
726
735
|
|
|
727
|
-
const blockB =
|
|
736
|
+
const blockB = select.getBlock(clientIdB);
|
|
728
737
|
const blockBType = (0, _blocks.getBlockType)(blockB.name);
|
|
729
738
|
const {
|
|
730
739
|
clientId,
|
|
731
740
|
attributeKey,
|
|
732
741
|
offset
|
|
733
|
-
} =
|
|
742
|
+
} = select.getSelectionStart();
|
|
734
743
|
const selectedBlockType = clientId === clientIdA ? blockAType : blockBType;
|
|
735
744
|
const attributeDefinition = selectedBlockType.attributes[attributeKey];
|
|
736
745
|
const canRestoreTextSelection = (clientId === clientIdA || clientId === clientIdB) && attributeKey !== undefined && offset !== undefined && // We cannot restore text selection if the RichText identifier
|
|
@@ -808,16 +817,16 @@ function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
|
|
|
808
817
|
preserveWhiteSpace
|
|
809
818
|
});
|
|
810
819
|
updatedAttributes[newAttributeKey] = newHtml;
|
|
811
|
-
|
|
820
|
+
dispatch.selectionChange(blockA.clientId, newAttributeKey, newOffset, newOffset);
|
|
812
821
|
}
|
|
813
822
|
|
|
814
|
-
|
|
823
|
+
dispatch.replaceBlocks([blockA.clientId, blockB.clientId], [{ ...blockA,
|
|
815
824
|
attributes: { ...blockA.attributes,
|
|
816
825
|
...updatedAttributes
|
|
817
826
|
}
|
|
818
827
|
}, ...blocksWithTheSameType.slice(1)], 0 // If we don't pass the `indexToSelect` it will default to the last block.
|
|
819
828
|
);
|
|
820
|
-
}
|
|
829
|
+
};
|
|
821
830
|
/**
|
|
822
831
|
* Yields action objects used in signalling that the blocks corresponding to
|
|
823
832
|
* the set of specified client IDs are to be removed.
|
|
@@ -828,36 +837,36 @@ function* mergeBlocks(firstBlockClientId, secondBlockClientId) {
|
|
|
828
837
|
*/
|
|
829
838
|
|
|
830
839
|
|
|
831
|
-
|
|
840
|
+
exports.mergeBlocks = mergeBlocks;
|
|
841
|
+
|
|
842
|
+
const removeBlocks = (clientIds, selectPrevious = true) => ({
|
|
843
|
+
select,
|
|
844
|
+
dispatch
|
|
845
|
+
}) => {
|
|
832
846
|
if (!clientIds || !clientIds.length) {
|
|
833
847
|
return;
|
|
834
848
|
}
|
|
835
849
|
|
|
836
850
|
clientIds = (0, _lodash.castArray)(clientIds);
|
|
837
|
-
const rootClientId =
|
|
838
|
-
const canRemoveBlocks =
|
|
851
|
+
const rootClientId = select.getBlockRootClientId(clientIds[0]);
|
|
852
|
+
const canRemoveBlocks = select.canRemoveBlocks(clientIds, rootClientId);
|
|
839
853
|
|
|
840
854
|
if (!canRemoveBlocks) {
|
|
841
855
|
return;
|
|
842
856
|
}
|
|
843
857
|
|
|
844
|
-
let previousBlockId;
|
|
845
|
-
|
|
846
858
|
if (selectPrevious) {
|
|
847
|
-
|
|
848
|
-
} else {
|
|
849
|
-
previousBlockId = yield _data.controls.select(_constants.STORE_NAME, 'getPreviousBlockClientId', clientIds[0]);
|
|
859
|
+
dispatch.selectPreviousBlock(clientIds[0]);
|
|
850
860
|
}
|
|
851
861
|
|
|
852
|
-
|
|
862
|
+
dispatch({
|
|
853
863
|
type: 'REMOVE_BLOCKS',
|
|
854
864
|
clientIds
|
|
855
|
-
}; // To avoid a focus loss when removing the last block, assure there is
|
|
865
|
+
}); // To avoid a focus loss when removing the last block, assure there is
|
|
856
866
|
// always a default block if the last of the blocks have been removed.
|
|
857
867
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
868
|
+
dispatch(ensureDefaultBlock());
|
|
869
|
+
};
|
|
861
870
|
/**
|
|
862
871
|
* Returns an action object used in signalling that the block with the
|
|
863
872
|
* specified client ID is to be removed.
|
|
@@ -870,6 +879,8 @@ function* removeBlocks(clientIds, selectPrevious = true) {
|
|
|
870
879
|
*/
|
|
871
880
|
|
|
872
881
|
|
|
882
|
+
exports.removeBlocks = removeBlocks;
|
|
883
|
+
|
|
873
884
|
function removeBlock(clientId, selectPrevious) {
|
|
874
885
|
return removeBlocks([clientId], selectPrevious);
|
|
875
886
|
}
|
|
@@ -990,8 +1001,7 @@ function exitFormattedText() {
|
|
|
990
1001
|
};
|
|
991
1002
|
}
|
|
992
1003
|
/**
|
|
993
|
-
*
|
|
994
|
-
* position.
|
|
1004
|
+
* Action that changes the position of the user caret.
|
|
995
1005
|
*
|
|
996
1006
|
* @param {string} clientId The selected block client ID.
|
|
997
1007
|
* @param {string} attributeKey The selected block attribute key.
|
|
@@ -1012,8 +1022,7 @@ function selectionChange(clientId, attributeKey, startOffset, endOffset) {
|
|
|
1012
1022
|
};
|
|
1013
1023
|
}
|
|
1014
1024
|
/**
|
|
1015
|
-
*
|
|
1016
|
-
* type should be added to the block list.
|
|
1025
|
+
* Action that adds a new block of the default type to the block list.
|
|
1017
1026
|
*
|
|
1018
1027
|
* @param {?Object} attributes Optional attributes of the block to assign.
|
|
1019
1028
|
* @param {?string} rootClientId Optional root client ID of block list on which
|
|
@@ -1036,7 +1045,7 @@ function insertDefaultBlock(attributes, rootClientId, index) {
|
|
|
1036
1045
|
return insertBlock(block, index, rootClientId);
|
|
1037
1046
|
}
|
|
1038
1047
|
/**
|
|
1039
|
-
*
|
|
1048
|
+
* Action that changes the nested settings of a given block.
|
|
1040
1049
|
*
|
|
1041
1050
|
* @param {string} clientId Client ID of the block whose nested setting are
|
|
1042
1051
|
* being received.
|
|
@@ -1054,7 +1063,7 @@ function updateBlockListSettings(clientId, settings) {
|
|
|
1054
1063
|
};
|
|
1055
1064
|
}
|
|
1056
1065
|
/**
|
|
1057
|
-
*
|
|
1066
|
+
* Action that updates the block editor settings.
|
|
1058
1067
|
*
|
|
1059
1068
|
* @param {Object} settings Updated settings
|
|
1060
1069
|
*
|
|
@@ -1069,7 +1078,7 @@ function updateSettings(settings) {
|
|
|
1069
1078
|
};
|
|
1070
1079
|
}
|
|
1071
1080
|
/**
|
|
1072
|
-
*
|
|
1081
|
+
* Action that signals that a temporary reusable block has been saved
|
|
1073
1082
|
* in order to switch its temporary id with the real id.
|
|
1074
1083
|
*
|
|
1075
1084
|
* @param {string} id Reusable block's id.
|
|
@@ -1087,7 +1096,7 @@ function __unstableSaveReusableBlock(id, updatedId) {
|
|
|
1087
1096
|
};
|
|
1088
1097
|
}
|
|
1089
1098
|
/**
|
|
1090
|
-
*
|
|
1099
|
+
* Action that marks the last block change explicitly as persistent.
|
|
1091
1100
|
*
|
|
1092
1101
|
* @return {Object} Action object.
|
|
1093
1102
|
*/
|
|
@@ -1099,7 +1108,7 @@ function __unstableMarkLastChangeAsPersistent() {
|
|
|
1099
1108
|
};
|
|
1100
1109
|
}
|
|
1101
1110
|
/**
|
|
1102
|
-
*
|
|
1111
|
+
* Action that signals that the next block change should be marked explicitly as not persistent.
|
|
1103
1112
|
*
|
|
1104
1113
|
* @return {Object} Action object.
|
|
1105
1114
|
*/
|
|
@@ -1111,151 +1120,180 @@ function __unstableMarkNextChangeAsNotPersistent() {
|
|
|
1111
1120
|
};
|
|
1112
1121
|
}
|
|
1113
1122
|
/**
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
* it is recommended to be called at the next idle period to ensure all
|
|
1123
|
+
* Action that marks the last block change as an automatic change, meaning it was not
|
|
1124
|
+
* performed by the user, and can be undone using the `Escape` and `Backspace` keys.
|
|
1125
|
+
* This action must be called after the change was made, and any actions that are a
|
|
1126
|
+
* consequence of it, so it is recommended to be called at the next idle period to ensure all
|
|
1119
1127
|
* selection changes have been recorded.
|
|
1120
1128
|
*/
|
|
1121
1129
|
|
|
1122
1130
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1131
|
+
const __unstableMarkAutomaticChange = () => ({
|
|
1132
|
+
dispatch
|
|
1133
|
+
}) => {
|
|
1134
|
+
dispatch({
|
|
1125
1135
|
type: 'MARK_AUTOMATIC_CHANGE'
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1136
|
+
});
|
|
1137
|
+
const {
|
|
1138
|
+
requestIdleCallback = cb => setTimeout(cb, 100)
|
|
1139
|
+
} = window;
|
|
1140
|
+
requestIdleCallback(() => {
|
|
1141
|
+
dispatch({
|
|
1142
|
+
type: 'MARK_AUTOMATIC_CHANGE_FINAL'
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
};
|
|
1135
1146
|
/**
|
|
1136
|
-
*
|
|
1147
|
+
* Action that enables or disables the navigation mode.
|
|
1137
1148
|
*
|
|
1138
1149
|
* @param {string} isNavigationMode Enable/Disable navigation mode.
|
|
1139
1150
|
*/
|
|
1140
1151
|
|
|
1141
1152
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1153
|
+
exports.__unstableMarkAutomaticChange = __unstableMarkAutomaticChange;
|
|
1154
|
+
|
|
1155
|
+
const setNavigationMode = (isNavigationMode = true) => ({
|
|
1156
|
+
dispatch
|
|
1157
|
+
}) => {
|
|
1158
|
+
dispatch({
|
|
1144
1159
|
type: 'SET_NAVIGATION_MODE',
|
|
1145
1160
|
isNavigationMode
|
|
1146
|
-
};
|
|
1161
|
+
});
|
|
1147
1162
|
|
|
1148
1163
|
if (isNavigationMode) {
|
|
1149
1164
|
(0, _a11y.speak)((0, _i18n.__)('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.'));
|
|
1150
1165
|
} else {
|
|
1151
1166
|
(0, _a11y.speak)((0, _i18n.__)('You are currently in edit mode. To return to the navigation mode, press Escape.'));
|
|
1152
1167
|
}
|
|
1153
|
-
}
|
|
1168
|
+
};
|
|
1154
1169
|
/**
|
|
1155
|
-
*
|
|
1170
|
+
* Action that enables or disables the block moving mode.
|
|
1156
1171
|
*
|
|
1157
1172
|
* @param {string|null} hasBlockMovingClientId Enable/Disable block moving mode.
|
|
1158
1173
|
*/
|
|
1159
1174
|
|
|
1160
1175
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1176
|
+
exports.setNavigationMode = setNavigationMode;
|
|
1177
|
+
|
|
1178
|
+
const setBlockMovingClientId = (hasBlockMovingClientId = null) => ({
|
|
1179
|
+
dispatch
|
|
1180
|
+
}) => {
|
|
1181
|
+
dispatch({
|
|
1163
1182
|
type: 'SET_BLOCK_MOVING_MODE',
|
|
1164
1183
|
hasBlockMovingClientId
|
|
1165
|
-
};
|
|
1184
|
+
});
|
|
1166
1185
|
|
|
1167
1186
|
if (hasBlockMovingClientId) {
|
|
1168
1187
|
(0, _a11y.speak)((0, _i18n.__)('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.'));
|
|
1169
1188
|
}
|
|
1170
|
-
}
|
|
1189
|
+
};
|
|
1171
1190
|
/**
|
|
1172
|
-
*
|
|
1191
|
+
* Action that duplicates a list of blocks.
|
|
1173
1192
|
*
|
|
1174
1193
|
* @param {string[]} clientIds
|
|
1175
1194
|
* @param {boolean} updateSelection
|
|
1176
1195
|
*/
|
|
1177
1196
|
|
|
1178
1197
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1198
|
+
exports.setBlockMovingClientId = setBlockMovingClientId;
|
|
1199
|
+
|
|
1200
|
+
const duplicateBlocks = (clientIds, updateSelection = true) => ({
|
|
1201
|
+
select,
|
|
1202
|
+
dispatch
|
|
1203
|
+
}) => {
|
|
1204
|
+
if (!clientIds || !clientIds.length) {
|
|
1181
1205
|
return;
|
|
1182
|
-
}
|
|
1206
|
+
} // Return early if blocks don't exist.
|
|
1183
1207
|
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1208
|
+
|
|
1209
|
+
const blocks = select.getBlocksByClientId(clientIds);
|
|
1186
1210
|
|
|
1187
1211
|
if ((0, _lodash.some)(blocks, block => !block)) {
|
|
1188
1212
|
return;
|
|
1189
|
-
}
|
|
1213
|
+
} // Return early if blocks don't support multiple usage.
|
|
1190
1214
|
|
|
1191
|
-
const blockNames = blocks.map(block => block.name); // Return early if blocks don't support multiple usage.
|
|
1192
1215
|
|
|
1193
|
-
|
|
1216
|
+
const blockNames = blocks.map(block => block.name);
|
|
1217
|
+
|
|
1218
|
+
if (blockNames.some(blockName => !(0, _blocks.hasBlockSupport)(blockName, 'multiple', true))) {
|
|
1194
1219
|
return;
|
|
1195
1220
|
}
|
|
1196
1221
|
|
|
1197
|
-
const
|
|
1222
|
+
const rootClientId = select.getBlockRootClientId(clientIds[0]);
|
|
1223
|
+
const lastSelectedIndex = select.getBlockIndex((0, _lodash.last)((0, _lodash.castArray)(clientIds)), rootClientId);
|
|
1198
1224
|
const clonedBlocks = blocks.map(block => (0, _blocks.__experimentalCloneSanitizedBlock)(block));
|
|
1199
|
-
|
|
1225
|
+
dispatch.insertBlocks(clonedBlocks, lastSelectedIndex + 1, rootClientId, updateSelection);
|
|
1200
1226
|
|
|
1201
1227
|
if (clonedBlocks.length > 1 && updateSelection) {
|
|
1202
|
-
|
|
1228
|
+
dispatch.multiSelect((0, _lodash.first)(clonedBlocks).clientId, (0, _lodash.last)(clonedBlocks).clientId);
|
|
1203
1229
|
}
|
|
1204
1230
|
|
|
1205
1231
|
return clonedBlocks.map(block => block.clientId);
|
|
1206
|
-
}
|
|
1232
|
+
};
|
|
1207
1233
|
/**
|
|
1208
|
-
*
|
|
1234
|
+
* Action that inserts an empty block before a given block.
|
|
1209
1235
|
*
|
|
1210
1236
|
* @param {string} clientId
|
|
1211
1237
|
*/
|
|
1212
1238
|
|
|
1213
1239
|
|
|
1214
|
-
|
|
1240
|
+
exports.duplicateBlocks = duplicateBlocks;
|
|
1241
|
+
|
|
1242
|
+
const insertBeforeBlock = clientId => ({
|
|
1243
|
+
select,
|
|
1244
|
+
dispatch
|
|
1245
|
+
}) => {
|
|
1215
1246
|
if (!clientId) {
|
|
1216
1247
|
return;
|
|
1217
1248
|
}
|
|
1218
1249
|
|
|
1219
|
-
const rootClientId =
|
|
1220
|
-
const isLocked =
|
|
1250
|
+
const rootClientId = select.getBlockRootClientId(clientId);
|
|
1251
|
+
const isLocked = select.getTemplateLock(rootClientId);
|
|
1221
1252
|
|
|
1222
1253
|
if (isLocked) {
|
|
1223
1254
|
return;
|
|
1224
1255
|
}
|
|
1225
1256
|
|
|
1226
|
-
const firstSelectedIndex =
|
|
1227
|
-
return
|
|
1228
|
-
}
|
|
1257
|
+
const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
|
|
1258
|
+
return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex);
|
|
1259
|
+
};
|
|
1229
1260
|
/**
|
|
1230
|
-
*
|
|
1261
|
+
* Action that inserts an empty block after a given block.
|
|
1231
1262
|
*
|
|
1232
1263
|
* @param {string} clientId
|
|
1233
1264
|
*/
|
|
1234
1265
|
|
|
1235
1266
|
|
|
1236
|
-
|
|
1267
|
+
exports.insertBeforeBlock = insertBeforeBlock;
|
|
1268
|
+
|
|
1269
|
+
const insertAfterBlock = clientId => ({
|
|
1270
|
+
select,
|
|
1271
|
+
dispatch
|
|
1272
|
+
}) => {
|
|
1237
1273
|
if (!clientId) {
|
|
1238
1274
|
return;
|
|
1239
1275
|
}
|
|
1240
1276
|
|
|
1241
|
-
const rootClientId =
|
|
1242
|
-
const isLocked =
|
|
1277
|
+
const rootClientId = select.getBlockRootClientId(clientId);
|
|
1278
|
+
const isLocked = select.getTemplateLock(rootClientId);
|
|
1243
1279
|
|
|
1244
1280
|
if (isLocked) {
|
|
1245
1281
|
return;
|
|
1246
1282
|
}
|
|
1247
1283
|
|
|
1248
|
-
const firstSelectedIndex =
|
|
1249
|
-
return
|
|
1250
|
-
}
|
|
1284
|
+
const firstSelectedIndex = select.getBlockIndex(clientId, rootClientId);
|
|
1285
|
+
return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex + 1);
|
|
1286
|
+
};
|
|
1251
1287
|
/**
|
|
1252
|
-
*
|
|
1288
|
+
* Action that toggles the highlighted block state.
|
|
1253
1289
|
*
|
|
1254
1290
|
* @param {string} clientId The block's clientId.
|
|
1255
1291
|
* @param {boolean} isHighlighted The highlight state.
|
|
1256
1292
|
*/
|
|
1257
1293
|
|
|
1258
1294
|
|
|
1295
|
+
exports.insertAfterBlock = insertAfterBlock;
|
|
1296
|
+
|
|
1259
1297
|
function toggleBlockHighlight(clientId, isHighlighted) {
|
|
1260
1298
|
return {
|
|
1261
1299
|
type: 'TOGGLE_BLOCK_HIGHLIGHT',
|
|
@@ -1264,29 +1302,29 @@ function toggleBlockHighlight(clientId, isHighlighted) {
|
|
|
1264
1302
|
};
|
|
1265
1303
|
}
|
|
1266
1304
|
/**
|
|
1267
|
-
*
|
|
1268
|
-
* given clientId should appear to "flash" by rhythmically highlighting it.
|
|
1305
|
+
* Action that "flashes" the block with a given `clientId` by rhythmically highlighting it.
|
|
1269
1306
|
*
|
|
1270
1307
|
* @param {string} clientId Target block client ID.
|
|
1271
1308
|
*/
|
|
1272
1309
|
|
|
1273
1310
|
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1311
|
+
const flashBlock = clientId => async ({
|
|
1312
|
+
dispatch
|
|
1313
|
+
}) => {
|
|
1314
|
+
dispatch(toggleBlockHighlight(clientId, true));
|
|
1315
|
+
await new Promise(resolve => setTimeout(resolve, 150));
|
|
1316
|
+
dispatch(toggleBlockHighlight(clientId, false));
|
|
1317
|
+
};
|
|
1282
1318
|
/**
|
|
1283
|
-
*
|
|
1319
|
+
* Action that sets whether a block has controlled inner blocks.
|
|
1284
1320
|
*
|
|
1285
1321
|
* @param {string} clientId The block's clientId.
|
|
1286
1322
|
* @param {boolean} hasControlledInnerBlocks True if the block's inner blocks are controlled.
|
|
1287
1323
|
*/
|
|
1288
1324
|
|
|
1289
1325
|
|
|
1326
|
+
exports.flashBlock = flashBlock;
|
|
1327
|
+
|
|
1290
1328
|
function setHasControlledInnerBlocks(clientId, hasControlledInnerBlocks) {
|
|
1291
1329
|
return {
|
|
1292
1330
|
type: 'SET_HAS_CONTROLLED_INNER_BLOCKS',
|