@wordpress/block-editor 8.3.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +56 -18
- package/build/components/alignment-control/index.js +13 -6
- package/build/components/alignment-control/index.js.map +1 -1
- package/build/components/block-alignment-control/index.js +13 -6
- package/build/components/block-alignment-control/index.js.map +1 -1
- package/build/components/block-draggable/index.js +2 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-icon/index.js +4 -0
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +6 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-html.js +4 -1
- package/build/components/block-list/block-html.js.map +1 -1
- package/build/components/block-list/block.js +4 -1
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -6
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +22 -6
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build/components/block-list-appender/index.js +6 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-lock/index.js +32 -0
- package/build/components/block-lock/index.js.map +1 -0
- package/build/components/block-lock/menu-item.js +67 -0
- package/build/components/block-lock/menu-item.js.map +1 -0
- package/build/components/block-lock/modal.js +134 -0
- package/build/components/block-lock/modal.js.map +1 -0
- package/build/components/block-lock/toolbar.js +78 -0
- package/build/components/block-lock/toolbar.js.map +1 -0
- package/build/components/block-mover/index.js +4 -0
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +75 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +19 -9
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-switcher/index.js +1 -1
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-title/index.js +2 -2
- package/build/components/block-title/index.js.map +1 -1
- package/build/components/block-title/use-block-display-title.js +8 -6
- package/build/components/block-title/use-block-display-title.js.map +1 -1
- package/build/components/block-toolbar/block-name-context.js +17 -0
- package/build/components/block-toolbar/block-name-context.js.map +1 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build/components/block-toolbar/index.js +24 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/index.js +0 -16
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +92 -47
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/block-vertical-alignment-control/index.js +13 -6
- package/build/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build/components/border-radius-control/index.js +0 -1
- package/build/components/border-radius-control/index.js.map +1 -1
- package/build/components/border-radius-control/utils.js +1 -1
- package/build/components/border-radius-control/utils.js.map +1 -1
- package/build/components/colors-gradients/control.js +3 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/contrast-checker/index.js +4 -0
- package/build/components/contrast-checker/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.js +8 -0
- package/build/components/convert-to-group-buttons/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/toolbar.js +105 -0
- package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build/components/copy-handler/index.js +4 -0
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +132 -0
- package/build/components/date-format-picker/index.js.map +1 -0
- package/build/components/font-sizes/font-size-picker.js +4 -0
- package/build/components/font-sizes/font-size-picker.js.map +1 -1
- package/build/components/iframe/index.js +6 -9
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +27 -0
- package/build/components/index.js.map +1 -1
- package/build/components/justify-content-control/index.js +13 -6
- package/build/components/justify-content-control/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/line-height-control/index.js +15 -6
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +24 -23
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +38 -13
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +16 -13
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +7 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +9 -2
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/media-replace-flow/index.js +4 -0
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/multi-selection-inspector/index.js +1 -1
- package/build/components/multi-selection-inspector/index.js.map +1 -1
- package/build/components/rich-text/index.js +27 -5
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +13 -9
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/rich-text/split-value.js +12 -2
- package/build/components/rich-text/split-value.js.map +1 -1
- package/build/components/rich-text/use-firefox-compat.js +49 -0
- package/build/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +34 -2
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js +4 -0
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +11 -27
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/writing-flow/index.js +9 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +3 -44
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js +68 -0
- package/build/components/writing-flow/use-click-selection.js.map +1 -0
- package/build/components/writing-flow/use-drag-selection.js +134 -0
- package/build/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build/components/writing-flow/use-input.js +116 -0
- package/build/components/writing-flow/use-input.js.map +1 -0
- package/build/components/writing-flow/use-multi-selection.js +18 -38
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +161 -0
- package/build/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build/components/writing-flow/use-tab-nav.js +1 -8
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/anchor.js +7 -6
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border-color.js +3 -3
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border.js +0 -14
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +20 -17
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/font-family.js +5 -1
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +4 -2
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/gap.js +77 -5
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +7 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +34 -3
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/utils.js +29 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +82 -15
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +22 -13
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +297 -51
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +25 -13
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +171 -21
- package/build/store/selectors.js.map +1 -1
- package/build/utils/dom.js +2 -1
- package/build/utils/dom.js.map +1 -1
- package/build-module/components/alignment-control/index.js +12 -4
- package/build-module/components/alignment-control/index.js.map +1 -1
- package/build-module/components/block-alignment-control/index.js +12 -4
- package/build-module/components/block-alignment-control/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +2 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-icon/index.js +4 -0
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +6 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-html.js +5 -2
- package/build-module/components/block-list/block-html.js.map +1 -1
- package/build-module/components/block-list/block.js +5 -2
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +22 -6
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +6 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-lock/index.js +4 -0
- package/build-module/components/block-lock/index.js.map +1 -0
- package/build-module/components/block-lock/menu-item.js +53 -0
- package/build-module/components/block-lock/menu-item.js.map +1 -0
- package/build-module/components/block-lock/modal.js +119 -0
- package/build-module/components/block-lock/modal.js.map +1 -0
- package/build-module/components/block-lock/toolbar.js +63 -0
- package/build-module/components/block-lock/toolbar.js.map +1 -0
- package/build-module/components/block-mover/index.js +4 -0
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +75 -12
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +18 -9
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +2 -2
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-title/index.js +2 -2
- package/build-module/components/block-title/index.js.map +1 -1
- package/build-module/components/block-title/use-block-display-title.js +8 -6
- package/build-module/components/block-title/use-block-display-title.js.map +1 -1
- package/build-module/components/block-toolbar/block-name-context.js +9 -0
- package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build-module/components/block-toolbar/index.js +19 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/index.js +0 -16
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +95 -49
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/block-vertical-alignment-control/index.js +12 -4
- package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build-module/components/border-radius-control/index.js +0 -1
- package/build-module/components/border-radius-control/index.js.map +1 -1
- package/build-module/components/border-radius-control/utils.js +1 -1
- package/build-module/components/border-radius-control/utils.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +3 -1
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/contrast-checker/index.js +4 -0
- package/build-module/components/contrast-checker/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.js +2 -1
- package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
- package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build-module/components/copy-handler/index.js +4 -0
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +122 -0
- package/build-module/components/date-format-picker/index.js.map +1 -0
- package/build-module/components/font-sizes/font-size-picker.js +4 -0
- package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -9
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +3 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/justify-content-control/index.js +12 -4
- package/build-module/components/justify-content-control/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/line-height-control/index.js +14 -5
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +24 -23
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +36 -13
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +16 -13
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +7 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +10 -3
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +4 -0
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/multi-selection-inspector/index.js +2 -2
- package/build-module/components/multi-selection-inspector/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +26 -5
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +13 -9
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/rich-text/split-value.js +12 -2
- package/build-module/components/rich-text/split-value.js.map +1 -1
- package/build-module/components/rich-text/use-firefox-compat.js +39 -0
- package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +35 -4
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js +4 -0
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +12 -28
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/writing-flow/index.js +5 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js +57 -0
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-drag-selection.js +124 -0
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-input.js +104 -0
- package/build-module/components/writing-flow/use-input.js.map +1 -0
- package/build-module/components/writing-flow/use-multi-selection.js +18 -37
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +150 -0
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build-module/components/writing-flow/use-tab-nav.js +1 -9
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/anchor.js +7 -6
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border-color.js +5 -5
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border.js +0 -12
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +19 -18
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/font-family.js +3 -1
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +4 -3
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/gap.js +75 -7
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +7 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +33 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/utils.js +26 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +81 -16
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +20 -13
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +286 -49
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +25 -13
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +162 -20
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/dom.js +2 -1
- package/build-module/utils/dom.js.map +1 -1
- package/build-style/style-rtl.css +214 -24
- package/build-style/style.css +214 -24
- package/build-types/utils/dom.d.ts.map +1 -1
- package/package.json +28 -27
- package/src/components/alignment-control/index.js +9 -4
- package/src/components/block-alignment-control/index.js +9 -4
- package/src/components/block-draggable/index.js +2 -5
- package/src/components/block-icon/index.js +3 -0
- package/src/components/block-inspector/index.js +4 -0
- package/src/components/block-list/block-html.js +8 -4
- package/src/components/block-list/block.js +5 -1
- package/src/components/block-list/style.scss +4 -5
- package/src/components/block-list/use-block-props/index.js +0 -5
- package/src/components/block-list/use-block-props/use-focus-first-element.js +27 -6
- package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
- package/src/components/block-list-appender/index.js +5 -0
- package/src/components/block-lock/index.js +3 -0
- package/src/components/block-lock/menu-item.js +59 -0
- package/src/components/block-lock/modal.js +170 -0
- package/src/components/block-lock/style.scss +70 -0
- package/src/components/block-lock/toolbar.js +68 -0
- package/src/components/block-mover/index.js +3 -0
- package/src/components/block-mover/style.scss +4 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +109 -9
- package/src/components/block-settings-menu-controls/index.js +33 -12
- package/src/components/block-switcher/index.js +2 -2
- package/src/components/block-switcher/style.scss +8 -1
- package/src/components/block-switcher/test/index.js +2 -2
- package/src/components/block-title/README.md +6 -1
- package/src/components/block-title/index.js +2 -2
- package/src/components/block-title/test/index.js +43 -1
- package/src/components/block-title/use-block-display-title.js +10 -7
- package/src/components/block-toolbar/block-name-context.js +8 -0
- package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
- package/src/components/block-toolbar/index.js +24 -2
- package/src/components/block-toolbar/style.scss +10 -0
- package/src/components/block-tools/index.js +0 -19
- package/src/components/block-tools/style.scss +27 -0
- package/src/components/block-variation-transforms/index.js +105 -36
- package/src/components/block-variation-transforms/style.scss +1 -1
- package/src/components/block-vertical-alignment-control/index.js +9 -4
- package/src/components/border-radius-control/index.js +0 -1
- package/src/components/border-radius-control/test/utils.js +4 -0
- package/src/components/border-radius-control/utils.js +2 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +70 -4
- package/src/components/colors-gradients/control.js +1 -1
- package/src/components/colors-gradients/style.scss +6 -0
- package/src/components/contrast-checker/index.js +3 -0
- package/src/components/convert-to-group-buttons/index.js +6 -1
- package/src/components/convert-to-group-buttons/toolbar.js +87 -0
- package/src/components/copy-handler/index.js +3 -0
- package/src/components/date-format-picker/README.md +58 -0
- package/src/components/date-format-picker/index.js +161 -0
- package/src/components/date-format-picker/style.scss +31 -0
- package/src/components/font-sizes/font-size-picker.js +3 -0
- package/src/components/iframe/index.js +5 -7
- package/src/components/index.js +3 -0
- package/src/components/justify-content-control/index.js +9 -4
- package/src/components/keyboard-shortcuts/index.js +1 -1
- package/src/components/line-height-control/index.js +11 -6
- package/src/components/link-control/README.md +1 -1
- package/src/components/list-view/block-select-button.js +21 -30
- package/src/components/list-view/block.js +55 -13
- package/src/components/list-view/branch.js +37 -15
- package/src/components/list-view/index.js +6 -0
- package/src/components/list-view/style.scss +56 -14
- package/src/components/list-view/use-block-selection.js +15 -2
- package/src/components/media-placeholder/README.md +8 -0
- package/src/components/media-replace-flow/index.js +3 -0
- package/src/components/multi-selection-inspector/index.js +2 -2
- package/src/components/rich-text/index.js +25 -2
- package/src/components/rich-text/index.native.js +24 -8
- package/src/components/rich-text/split-value.js +5 -1
- package/src/components/rich-text/use-firefox-compat.js +39 -0
- package/src/components/rich-text/use-input-rules.js +40 -3
- package/src/components/skip-to-selected-block/index.js +3 -0
- package/src/components/url-input/style.scss +3 -2
- package/src/components/url-popover/image-url-input-ui.js +16 -29
- package/src/components/writing-flow/index.js +8 -0
- package/src/components/writing-flow/readme.md +28 -0
- package/src/components/writing-flow/use-arrow-nav.js +4 -53
- package/src/components/writing-flow/use-click-selection.js +65 -0
- package/src/components/writing-flow/use-drag-selection.js +126 -0
- package/src/components/writing-flow/use-input.js +112 -0
- package/src/components/writing-flow/use-multi-selection.js +13 -36
- package/src/components/writing-flow/use-selection-observer.js +153 -0
- package/src/components/writing-flow/use-tab-nav.js +1 -11
- package/src/hooks/anchor.js +8 -6
- package/src/hooks/border-color.js +5 -5
- package/src/hooks/border.js +0 -13
- package/src/hooks/color.js +51 -24
- package/src/hooks/font-family.js +5 -2
- package/src/hooks/font-size.js +10 -7
- package/src/hooks/gap.js +91 -12
- package/src/hooks/layout.js +11 -1
- package/src/hooks/style.js +40 -4
- package/src/hooks/test/gap.js +66 -0
- package/src/hooks/test/style.js +94 -0
- package/src/hooks/test/utils.js +1 -1
- package/src/hooks/utils.js +26 -0
- package/src/layouts/flex.js +93 -6
- package/src/layouts/flow.js +28 -12
- package/src/store/actions.js +349 -32
- package/src/store/defaults.js +7 -1
- package/src/store/reducer.js +25 -10
- package/src/store/selectors.js +207 -25
- package/src/store/test/selectors.js +305 -5
- package/src/style.scss +2 -0
- package/src/utils/dom.js +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
- package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
- package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/image-url-input-ui.js"],"names":["find","isEmpty","each","map","__","useRef","useState","useCallback","ToolbarButton","Button","NavigableMenu","MenuItem","ToggleControl","TextControl","SVG","Path","link","linkIcon","close","URLPopover","LINK_DESTINATION_NONE","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_ATTACHMENT","NEW_TAB_REL","icon","ImageURLInputUI","linkDestination","onChangeUrl","url","mediaType","mediaUrl","mediaLink","linkTarget","linkClass","rel","isOpen","setIsOpen","openLinkUI","isEditingLink","setIsEditingLink","urlInput","setUrlInput","autocompleteRef","startEditLink","stopEditLink","closeLinkUI","removeNewTabRel","currentRel","newRel","undefined","relVal","regExp","RegExp","replace","trim","getUpdatedLinkTargetSettings","value","newLinkTarget","updatedRel","onFocusOutside","event","autocompleteElement","current","contains","target","onSubmitLinkChange","selectedDestination","getLinkDestinations","destination","href","preventDefault","onLinkRemove","linkDestinations","title","push","onSetHref","linkDestinationInput","onSetNewTab","updatedLinkTarget","onSetLinkRel","onSetLinkClass","advancedOptions","linkEditorValue","urlLabel","__experimentalImageURLInputUI"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,EAAwBC,IAAxB,EAA8BC,GAA9B,QAAyC,QAAzC;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,QAAjB,EAA2BC,WAA3B,QAA8C,oBAA9C;AACA,SACCC,aADD,EAECC,MAFD,EAGCC,aAHD,EAICC,QAJD,EAKCC,aALD,EAMCC,WAND,EAOCC,GAPD,EAQCC,IARD,QASO,uBATP;AAUA,SAASC,IAAI,IAAIC,QAAjB,EAA2BC,KAA3B,QAAwC,kBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,SAAvB;AAEA,MAAMC,qBAAqB,GAAG,MAA9B;AACA,MAAMC,uBAAuB,GAAG,QAAhC;AACA,MAAMC,sBAAsB,GAAG,OAA/B;AACA,MAAMC,2BAA2B,GAAG,YAApC;AACA,MAAMC,WAAW,GAAG,CAAE,YAAF,EAAgB,UAAhB,CAApB;AAEA,MAAMC,IAAI,GACT,cAAC,GAAD;AAAK,EAAA,OAAO,EAAC,WAAb;AAAy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E;AAHX,IAPD,CAlCF,CATF,CADD;AA8DA,CAjRD;;AAmRA,SAAS9C,eAAe,IAAI2D,6BAA5B","sourcesContent":["/**\n * External dependencies\n */\nimport { find, isEmpty, each, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useCallback } from '@wordpress/element';\nimport {\n\tToolbarButton,\n\tButton,\n\tNavigableMenu,\n\tMenuItem,\n\tToggleControl,\n\tTextControl,\n\tSVG,\n\tPath,\n} from '@wordpress/components';\nimport { link as linkIcon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport URLPopover from './index';\n\nconst LINK_DESTINATION_NONE = 'none';\nconst LINK_DESTINATION_CUSTOM = 'custom';\nconst LINK_DESTINATION_MEDIA = 'media';\nconst LINK_DESTINATION_ATTACHMENT = 'attachment';\nconst NEW_TAB_REL = [ 'noreferrer', 'noopener' ];\n\nconst icon = (\n\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t<Path d=\"M0,0h24v24H0V0z\" fill=\"none\" />\n\t\t<Path d=\"m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z\" />\n\t\t<Path d=\"m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z\" />\n\t</SVG>\n);\n\nconst ImageURLInputUI = ( {\n\tlinkDestination,\n\tonChangeUrl,\n\turl,\n\tmediaType = 'image',\n\tmediaUrl,\n\tmediaLink,\n\tlinkTarget,\n\tlinkClass,\n\trel,\n} ) => {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst openLinkUI = useCallback( () => {\n\t\tsetIsOpen( true );\n\t} );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState( false );\n\tconst [ urlInput, setUrlInput ] = useState( null );\n\n\tconst autocompleteRef = useRef( null );\n\n\tconst startEditLink = useCallback( () => {\n\t\tif (\n\t\t\tlinkDestination === LINK_DESTINATION_MEDIA ||\n\t\t\tlinkDestination === LINK_DESTINATION_ATTACHMENT\n\t\t) {\n\t\t\tsetUrlInput( '' );\n\t\t}\n\t\tsetIsEditingLink( true );\n\t} );\n\n\tconst stopEditLink = useCallback( () => {\n\t\tsetIsEditingLink( false );\n\t} );\n\n\tconst closeLinkUI = useCallback( () => {\n\t\tsetUrlInput( null );\n\t\tstopEditLink();\n\t\tsetIsOpen( false );\n\t} );\n\n\tconst removeNewTabRel = ( currentRel ) => {\n\t\tlet newRel = currentRel;\n\n\t\tif ( currentRel !== undefined && ! isEmpty( newRel ) ) {\n\t\t\tif ( ! isEmpty( newRel ) ) {\n\t\t\t\teach( NEW_TAB_REL, ( relVal ) => {\n\t\t\t\t\tconst regExp = new RegExp( '\\\\b' + relVal + '\\\\b', 'gi' );\n\t\t\t\t\tnewRel = newRel.replace( regExp, '' );\n\t\t\t\t} );\n\n\t\t\t\t// Only trim if NEW_TAB_REL values was replaced.\n\t\t\t\tif ( newRel !== currentRel ) {\n\t\t\t\t\tnewRel = newRel.trim();\n\t\t\t\t}\n\n\t\t\t\tif ( isEmpty( newRel ) ) {\n\t\t\t\t\tnewRel = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn newRel;\n\t};\n\n\tconst getUpdatedLinkTargetSettings = ( value ) => {\n\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\tlet updatedRel;\n\t\tif ( ! newLinkTarget && ! rel ) {\n\t\t\tupdatedRel = undefined;\n\t\t} else {\n\t\t\tupdatedRel = removeNewTabRel( rel );\n\t\t}\n\n\t\treturn {\n\t\t\tlinkTarget: newLinkTarget,\n\t\t\trel: updatedRel,\n\t\t};\n\t};\n\n\tconst onFocusOutside = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\t// The autocomplete suggestions list renders in a separate popover (in a portal),\n\t\t\t// so onFocusOutside fails to detect that a click on a suggestion occurred in the\n\t\t\t// LinkContainer. Detect clicks on autocomplete suggestions using a ref here, and\n\t\t\t// return to avoid the popover being closed.\n\t\t\tconst autocompleteElement = autocompleteRef.current;\n\t\t\tif (\n\t\t\t\tautocompleteElement &&\n\t\t\t\tautocompleteElement.contains( event.target )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetIsOpen( false );\n\t\t\tsetUrlInput( null );\n\t\t\tstopEditLink();\n\t\t};\n\t} );\n\n\tconst onSubmitLinkChange = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\tif ( urlInput ) {\n\t\t\t\t// It is possible the entered URL actually matches a named link destination.\n\t\t\t\t// This check will ensure our link destination is correct.\n\t\t\t\tconst selectedDestination =\n\t\t\t\t\tgetLinkDestinations().find(\n\t\t\t\t\t\t( destination ) => destination.url === urlInput\n\t\t\t\t\t)?.linkDestination || LINK_DESTINATION_CUSTOM;\n\n\t\t\t\tonChangeUrl( {\n\t\t\t\t\thref: urlInput,\n\t\t\t\t\tlinkDestination: selectedDestination,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tstopEditLink();\n\t\t\tsetUrlInput( null );\n\t\t\tevent.preventDefault();\n\t\t};\n\t} );\n\n\tconst onLinkRemove = useCallback( () => {\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: LINK_DESTINATION_NONE,\n\t\t\thref: '',\n\t\t} );\n\t} );\n\n\tconst getLinkDestinations = () => {\n\t\tconst linkDestinations = [\n\t\t\t{\n\t\t\t\tlinkDestination: LINK_DESTINATION_MEDIA,\n\t\t\t\ttitle: __( 'Media File' ),\n\t\t\t\turl: mediaType === 'image' ? mediaUrl : undefined,\n\t\t\t\ticon,\n\t\t\t},\n\t\t];\n\t\tif ( mediaType === 'image' && mediaLink ) {\n\t\t\tlinkDestinations.push( {\n\t\t\t\tlinkDestination: LINK_DESTINATION_ATTACHMENT,\n\t\t\t\ttitle: __( 'Attachment Page' ),\n\t\t\t\turl: mediaType === 'image' ? mediaLink : undefined,\n\t\t\t\ticon: (\n\t\t\t\t\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t<Path d=\"M0 0h24v24H0V0z\" fill=\"none\" />\n\t\t\t\t\t\t<Path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t),\n\t\t\t} );\n\t\t}\n\t\treturn linkDestinations;\n\t};\n\n\tconst onSetHref = ( value ) => {\n\t\tconst linkDestinations = getLinkDestinations();\n\t\tlet linkDestinationInput;\n\t\tif ( ! value ) {\n\t\t\tlinkDestinationInput = LINK_DESTINATION_NONE;\n\t\t} else {\n\t\t\tlinkDestinationInput = (\n\t\t\t\tfind( linkDestinations, ( destination ) => {\n\t\t\t\t\treturn destination.url === value;\n\t\t\t\t} ) || { linkDestination: LINK_DESTINATION_CUSTOM }\n\t\t\t).linkDestination;\n\t\t}\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: linkDestinationInput,\n\t\t\thref: value,\n\t\t} );\n\t};\n\n\tconst onSetNewTab = ( value ) => {\n\t\tconst updatedLinkTarget = getUpdatedLinkTargetSettings( value );\n\t\tonChangeUrl( updatedLinkTarget );\n\t};\n\n\tconst onSetLinkRel = ( value ) => {\n\t\tonChangeUrl( { rel: value } );\n\t};\n\n\tconst onSetLinkClass = ( value ) => {\n\t\tonChangeUrl( { linkClass: value } );\n\t};\n\n\tconst advancedOptions = (\n\t\t<>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonChange={ onSetNewTab }\n\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link Rel' ) }\n\t\t\t\tvalue={ removeNewTabRel( rel ) || '' }\n\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link CSS Class' ) }\n\t\t\t\tvalue={ linkClass || '' }\n\t\t\t\tonChange={ onSetLinkClass }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst linkEditorValue = urlInput !== null ? urlInput : url;\n\n\tconst urlLabel = (\n\t\tfind( getLinkDestinations(), [ 'linkDestination', linkDestination ] ) ||\n\t\t{}\n\t).title;\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarButton\n\t\t\t\ticon={ linkIcon }\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ url ? __( 'Edit link' ) : __( 'Insert link' ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t\tonClick={ openLinkUI }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<URLPopover\n\t\t\t\t\tonFocusOutside={ onFocusOutside() }\n\t\t\t\t\tonClose={ closeLinkUI }\n\t\t\t\t\trenderSettings={ () => advancedOptions }\n\t\t\t\t\tadditionalControls={\n\t\t\t\t\t\t! linkEditorValue && (\n\t\t\t\t\t\t\t<NavigableMenu>\n\t\t\t\t\t\t\t\t{ map( getLinkDestinations(), ( link ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ link.linkDestination }\n\t\t\t\t\t\t\t\t\t\ticon={ link.icon }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetUrlInput( null );\n\t\t\t\t\t\t\t\t\t\t\tonSetHref( link.url );\n\t\t\t\t\t\t\t\t\t\t\tstopEditLink();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ link.title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ ( ! url || isEditingLink ) && (\n\t\t\t\t\t\t<URLPopover.LinkEditor\n\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\tvalue={ linkEditorValue }\n\t\t\t\t\t\t\tonChangeInputValue={ setUrlInput }\n\t\t\t\t\t\t\tonSubmit={ onSubmitLinkChange() }\n\t\t\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ url && ! isEditingLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<URLPopover.LinkViewer\n\t\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t\tonEditLinkClick={ startEditLink }\n\t\t\t\t\t\t\t\turlLabel={ urlLabel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\t\t\tlabel={ __( 'Remove link' ) }\n\t\t\t\t\t\t\t\tonClick={ onLinkRemove }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</URLPopover>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport { ImageURLInputUI as __experimentalImageURLInputUI };\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/image-url-input-ui.js"],"names":["find","map","__","useRef","useState","useCallback","ToolbarButton","Button","NavigableMenu","MenuItem","ToggleControl","TextControl","SVG","Path","link","linkIcon","close","URLPopover","LINK_DESTINATION_NONE","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_ATTACHMENT","NEW_TAB_REL","icon","ImageURLInputUI","linkDestination","onChangeUrl","url","mediaType","mediaUrl","mediaLink","linkTarget","linkClass","rel","isOpen","setIsOpen","openLinkUI","isEditingLink","setIsEditingLink","urlInput","setUrlInput","autocompleteRef","startEditLink","stopEditLink","closeLinkUI","getUpdatedLinkTargetSettings","value","newLinkTarget","undefined","updatedRel","rels","split","forEach","relVal","includes","push","join","filter","length","onFocusOutside","event","autocompleteElement","current","contains","target","onSubmitLinkChange","selectedDestination","getLinkDestinations","destination","href","preventDefault","onLinkRemove","linkDestinations","title","onSetHref","linkDestinationInput","onSetNewTab","updatedLinkTarget","onSetLinkRel","onSetLinkClass","advancedOptions","linkEditorValue","urlLabel","__experimentalImageURLInputUI"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,GAAf,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,QAAjB,EAA2BC,WAA3B,QAA8C,oBAA9C;AACA,SACCC,aADD,EAECC,MAFD,EAGCC,aAHD,EAICC,QAJD,EAKCC,aALD,EAMCC,WAND,EAOCC,GAPD,EAQCC,IARD,QASO,uBATP;AAUA,SAASC,IAAI,IAAIC,QAAjB,EAA2BC,KAA3B,QAAwC,kBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,SAAvB;AAEA,MAAMC,qBAAqB,GAAG,MAA9B;AACA,MAAMC,uBAAuB,GAAG,QAAhC;AACA,MAAMC,sBAAsB,GAAG,OAA/B;AACA,MAAMC,2BAA2B,GAAG,YAApC;AACA,MAAMC,WAAW,GAAG,CAAE,YAAF,EAAgB,UAAhB,CAApB;AAEA,MAAMC,IAAI,GACT,cAAC,GAAD;AAAK,EAAA,OAAO,EAAC,WAAb;AAAyB,EAAA,KAAK,EAAC;AAA/B,GACC,cAAC,IAAD;AAAM,EAAA,CAAC,EAAC,iBAAR;AAA0B,EAAA,IAAI,EAAC;AAA/B,EADD,EAEC,cAAC,IAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAFD,EAGC,cAAC,IAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EAHD,CADD;;AAQA,MAAMC,eAAe,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eADZ;AAEC,MAAA,IAAI,EAAGX,IAAI,CAACS,IAFb;AAGC,MAAA,OAAO,EAAG,MAAM;AACfiB,QAAAA,WAAW,CAAE,IAAF,CAAX;AACAkC,QAAAA,SAAS,CAAE5D,IAAI,CAACa,GAAP,CAAT;AACAgB,QAAAA,YAAY;AACZ;AAPF,OASG7B,IAAI,CAAC2D,KATR,CADI,CADN;AANH,KAwBG,CAAE,CAAE9C,GAAF,IAASU,aAAX,KACD,cAAC,UAAD,CAAY,UAAZ;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,KAAK,EAAG4C,eAFT;AAGC,IAAA,kBAAkB,EAAGzC,WAHtB;AAIC,IAAA,QAAQ,EAAGyB,kBAAkB,EAJ9B;AAKC,IAAA,eAAe,EAAGxB;AALnB,IAzBF,EAiCGd,GAAG,IAAI,CAAEU,aAAT,IACD,8BACC,cAAC,UAAD,CAAY,UAAZ;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,GAAG,EAAGV,GAFP;AAGC,IAAA,eAAe,EAAGe,aAHnB;AAIC,IAAA,QAAQ,EAAGwC;AAJZ,IADD,EAOC,cAAC,MAAD;AACC,IAAA,IAAI,EAAGlE,KADR;AAEC,IAAA,KAAK,EAAGd,EAAE,CAAE,aAAF,CAFX;AAGC,IAAA,OAAO,EAAGqE;AAHX,IAPD,CAlCF,CATF,CADD;AA8DA,CApQD;;AAsQA,SAAS/C,eAAe,IAAI2D,6BAA5B","sourcesContent":["/**\n * External dependencies\n */\nimport { find, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useCallback } from '@wordpress/element';\nimport {\n\tToolbarButton,\n\tButton,\n\tNavigableMenu,\n\tMenuItem,\n\tToggleControl,\n\tTextControl,\n\tSVG,\n\tPath,\n} from '@wordpress/components';\nimport { link as linkIcon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport URLPopover from './index';\n\nconst LINK_DESTINATION_NONE = 'none';\nconst LINK_DESTINATION_CUSTOM = 'custom';\nconst LINK_DESTINATION_MEDIA = 'media';\nconst LINK_DESTINATION_ATTACHMENT = 'attachment';\nconst NEW_TAB_REL = [ 'noreferrer', 'noopener' ];\n\nconst icon = (\n\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t<Path d=\"M0,0h24v24H0V0z\" fill=\"none\" />\n\t\t<Path d=\"m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z\" />\n\t\t<Path d=\"m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z\" />\n\t</SVG>\n);\n\nconst ImageURLInputUI = ( {\n\tlinkDestination,\n\tonChangeUrl,\n\turl,\n\tmediaType = 'image',\n\tmediaUrl,\n\tmediaLink,\n\tlinkTarget,\n\tlinkClass,\n\trel,\n} ) => {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst openLinkUI = useCallback( () => {\n\t\tsetIsOpen( true );\n\t} );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState( false );\n\tconst [ urlInput, setUrlInput ] = useState( null );\n\n\tconst autocompleteRef = useRef( null );\n\n\tconst startEditLink = useCallback( () => {\n\t\tif (\n\t\t\tlinkDestination === LINK_DESTINATION_MEDIA ||\n\t\t\tlinkDestination === LINK_DESTINATION_ATTACHMENT\n\t\t) {\n\t\t\tsetUrlInput( '' );\n\t\t}\n\t\tsetIsEditingLink( true );\n\t} );\n\n\tconst stopEditLink = useCallback( () => {\n\t\tsetIsEditingLink( false );\n\t} );\n\n\tconst closeLinkUI = useCallback( () => {\n\t\tsetUrlInput( null );\n\t\tstopEditLink();\n\t\tsetIsOpen( false );\n\t} );\n\n\tconst getUpdatedLinkTargetSettings = ( value ) => {\n\t\tconst newLinkTarget = value ? '_blank' : undefined;\n\n\t\tlet updatedRel;\n\t\tif ( newLinkTarget ) {\n\t\t\tconst rels = ( rel ?? '' ).split( ' ' );\n\t\t\tNEW_TAB_REL.forEach( ( relVal ) => {\n\t\t\t\tif ( ! rels.includes( relVal ) ) {\n\t\t\t\t\trels.push( relVal );\n\t\t\t\t}\n\t\t\t} );\n\t\t\tupdatedRel = rels.join( ' ' );\n\t\t} else {\n\t\t\tconst rels = ( rel ?? '' )\n\t\t\t\t.split( ' ' )\n\t\t\t\t.filter(\n\t\t\t\t\t( relVal ) => NEW_TAB_REL.includes( relVal ) === false\n\t\t\t\t);\n\t\t\tupdatedRel = rels.length ? rels.join( ' ' ) : undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tlinkTarget: newLinkTarget,\n\t\t\trel: updatedRel,\n\t\t};\n\t};\n\n\tconst onFocusOutside = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\t// The autocomplete suggestions list renders in a separate popover (in a portal),\n\t\t\t// so onFocusOutside fails to detect that a click on a suggestion occurred in the\n\t\t\t// LinkContainer. Detect clicks on autocomplete suggestions using a ref here, and\n\t\t\t// return to avoid the popover being closed.\n\t\t\tconst autocompleteElement = autocompleteRef.current;\n\t\t\tif (\n\t\t\t\tautocompleteElement &&\n\t\t\t\tautocompleteElement.contains( event.target )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetIsOpen( false );\n\t\t\tsetUrlInput( null );\n\t\t\tstopEditLink();\n\t\t};\n\t} );\n\n\tconst onSubmitLinkChange = useCallback( () => {\n\t\treturn ( event ) => {\n\t\t\tif ( urlInput ) {\n\t\t\t\t// It is possible the entered URL actually matches a named link destination.\n\t\t\t\t// This check will ensure our link destination is correct.\n\t\t\t\tconst selectedDestination =\n\t\t\t\t\tgetLinkDestinations().find(\n\t\t\t\t\t\t( destination ) => destination.url === urlInput\n\t\t\t\t\t)?.linkDestination || LINK_DESTINATION_CUSTOM;\n\n\t\t\t\tonChangeUrl( {\n\t\t\t\t\thref: urlInput,\n\t\t\t\t\tlinkDestination: selectedDestination,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tstopEditLink();\n\t\t\tsetUrlInput( null );\n\t\t\tevent.preventDefault();\n\t\t};\n\t} );\n\n\tconst onLinkRemove = useCallback( () => {\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: LINK_DESTINATION_NONE,\n\t\t\thref: '',\n\t\t} );\n\t} );\n\n\tconst getLinkDestinations = () => {\n\t\tconst linkDestinations = [\n\t\t\t{\n\t\t\t\tlinkDestination: LINK_DESTINATION_MEDIA,\n\t\t\t\ttitle: __( 'Media File' ),\n\t\t\t\turl: mediaType === 'image' ? mediaUrl : undefined,\n\t\t\t\ticon,\n\t\t\t},\n\t\t];\n\t\tif ( mediaType === 'image' && mediaLink ) {\n\t\t\tlinkDestinations.push( {\n\t\t\t\tlinkDestination: LINK_DESTINATION_ATTACHMENT,\n\t\t\t\ttitle: __( 'Attachment Page' ),\n\t\t\t\turl: mediaType === 'image' ? mediaLink : undefined,\n\t\t\t\ticon: (\n\t\t\t\t\t<SVG viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t<Path d=\"M0 0h24v24H0V0z\" fill=\"none\" />\n\t\t\t\t\t\t<Path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t),\n\t\t\t} );\n\t\t}\n\t\treturn linkDestinations;\n\t};\n\n\tconst onSetHref = ( value ) => {\n\t\tconst linkDestinations = getLinkDestinations();\n\t\tlet linkDestinationInput;\n\t\tif ( ! value ) {\n\t\t\tlinkDestinationInput = LINK_DESTINATION_NONE;\n\t\t} else {\n\t\t\tlinkDestinationInput = (\n\t\t\t\tfind( linkDestinations, ( destination ) => {\n\t\t\t\t\treturn destination.url === value;\n\t\t\t\t} ) || { linkDestination: LINK_DESTINATION_CUSTOM }\n\t\t\t).linkDestination;\n\t\t}\n\t\tonChangeUrl( {\n\t\t\tlinkDestination: linkDestinationInput,\n\t\t\thref: value,\n\t\t} );\n\t};\n\n\tconst onSetNewTab = ( value ) => {\n\t\tconst updatedLinkTarget = getUpdatedLinkTargetSettings( value );\n\t\tonChangeUrl( updatedLinkTarget );\n\t};\n\n\tconst onSetLinkRel = ( value ) => {\n\t\tonChangeUrl( { rel: value } );\n\t};\n\n\tconst onSetLinkClass = ( value ) => {\n\t\tonChangeUrl( { linkClass: value } );\n\t};\n\n\tconst advancedOptions = (\n\t\t<>\n\t\t\t<ToggleControl\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonChange={ onSetNewTab }\n\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link Rel' ) }\n\t\t\t\tvalue={ rel ?? '' }\n\t\t\t\tonChange={ onSetLinkRel }\n\t\t\t/>\n\t\t\t<TextControl\n\t\t\t\tlabel={ __( 'Link CSS Class' ) }\n\t\t\t\tvalue={ linkClass || '' }\n\t\t\t\tonChange={ onSetLinkClass }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst linkEditorValue = urlInput !== null ? urlInput : url;\n\n\tconst urlLabel = (\n\t\tfind( getLinkDestinations(), [ 'linkDestination', linkDestination ] ) ||\n\t\t{}\n\t).title;\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarButton\n\t\t\t\ticon={ linkIcon }\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ url ? __( 'Edit link' ) : __( 'Insert link' ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t\tonClick={ openLinkUI }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<URLPopover\n\t\t\t\t\tonFocusOutside={ onFocusOutside() }\n\t\t\t\t\tonClose={ closeLinkUI }\n\t\t\t\t\trenderSettings={ () => advancedOptions }\n\t\t\t\t\tadditionalControls={\n\t\t\t\t\t\t! linkEditorValue && (\n\t\t\t\t\t\t\t<NavigableMenu>\n\t\t\t\t\t\t\t\t{ map( getLinkDestinations(), ( link ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ link.linkDestination }\n\t\t\t\t\t\t\t\t\t\ticon={ link.icon }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetUrlInput( null );\n\t\t\t\t\t\t\t\t\t\t\tonSetHref( link.url );\n\t\t\t\t\t\t\t\t\t\t\tstopEditLink();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ link.title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ ( ! url || isEditingLink ) && (\n\t\t\t\t\t\t<URLPopover.LinkEditor\n\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\tvalue={ linkEditorValue }\n\t\t\t\t\t\t\tonChangeInputValue={ setUrlInput }\n\t\t\t\t\t\t\tonSubmit={ onSubmitLinkChange() }\n\t\t\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ url && ! isEditingLink && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<URLPopover.LinkViewer\n\t\t\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__link-container-content\"\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t\tonEditLinkClick={ startEditLink }\n\t\t\t\t\t\t\t\turlLabel={ urlLabel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ close }\n\t\t\t\t\t\t\t\tlabel={ __( 'Remove link' ) }\n\t\t\t\t\t\t\t\tonClick={ onLinkRemove }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</URLPopover>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport { ImageURLInputUI as __experimentalImageURLInputUI };\n"]}
|
|
@@ -21,11 +21,15 @@ import useMultiSelection from './use-multi-selection';
|
|
|
21
21
|
import useTabNav from './use-tab-nav';
|
|
22
22
|
import useArrowNav from './use-arrow-nav';
|
|
23
23
|
import useSelectAll from './use-select-all';
|
|
24
|
+
import useDragSelection from './use-drag-selection';
|
|
25
|
+
import useSelectionObserver from './use-selection-observer';
|
|
26
|
+
import useClickSelection from './use-click-selection';
|
|
27
|
+
import useInput from './use-input';
|
|
24
28
|
import { store as blockEditorStore } from '../../store';
|
|
25
29
|
export function useWritingFlow() {
|
|
26
30
|
const [before, ref, after] = useTabNav();
|
|
27
31
|
const hasMultiSelection = useSelect(select => select(blockEditorStore).hasMultiSelection(), []);
|
|
28
|
-
return [before, useMergeRefs([ref, useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
|
|
32
|
+
return [before, useMergeRefs([ref, useInput(), useDragSelection(), useSelectionObserver(), useClickSelection(), useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
|
|
29
33
|
node.tabIndex = -1;
|
|
30
34
|
node.contentEditable = hasMultiSelection;
|
|
31
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,OAAO,SAASC,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","useDragSelection","useSelectionObserver","useClickSelection","useInput","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,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F,QARH,CAFD,EAYGV,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAed,UAAU,CAAEsB,WAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport useDragSelection from './use-drag-selection';\nimport useSelectionObserver from './use-selection-observer';\nimport useClickSelection from './use-click-selection';\nimport useInput from './use-input';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseInput(),\n\t\t\tuseDragSelection(),\n\t\t\tuseSelectionObserver(),\n\t\t\tuseClickSelection(),\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
|
|
@@ -8,7 +8,7 @@ import { find, reverse } from 'lodash';
|
|
|
8
8
|
|
|
9
9
|
import { computeCaretRect, focus, isHorizontalEdge, isVerticalEdge, placeCaretAtHorizontalEdge, placeCaretAtVerticalEdge, isRTL } from '@wordpress/dom';
|
|
10
10
|
import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';
|
|
11
|
-
import { useSelect
|
|
11
|
+
import { useSelect } from '@wordpress/data';
|
|
12
12
|
import { useRefEffect } from '@wordpress/compose';
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
@@ -101,19 +101,12 @@ export function getClosestTabbable(target, isReverse, containerElement, onlyVert
|
|
|
101
101
|
export default function useArrowNav() {
|
|
102
102
|
const {
|
|
103
103
|
getSelectedBlockClientId,
|
|
104
|
-
getMultiSelectedBlocksStartClientId,
|
|
105
104
|
getMultiSelectedBlocksEndClientId,
|
|
106
105
|
getPreviousBlockClientId,
|
|
107
106
|
getNextBlockClientId,
|
|
108
|
-
getFirstMultiSelectedBlockClientId,
|
|
109
|
-
getLastMultiSelectedBlockClientId,
|
|
110
107
|
getSettings,
|
|
111
108
|
hasMultiSelection
|
|
112
109
|
} = useSelect(blockEditorStore);
|
|
113
|
-
const {
|
|
114
|
-
multiSelect,
|
|
115
|
-
selectBlock
|
|
116
|
-
} = useDispatch(blockEditorStore);
|
|
117
110
|
return useRefEffect(node => {
|
|
118
111
|
// Here a DOMRect is stored while moving the caret vertically so
|
|
119
112
|
// vertical position of the start position can be restored. This is to
|
|
@@ -123,33 +116,6 @@ export default function useArrowNav() {
|
|
|
123
116
|
function onMouseDown() {
|
|
124
117
|
verticalRect = null;
|
|
125
118
|
}
|
|
126
|
-
|
|
127
|
-
function expandSelection(isReverse) {
|
|
128
|
-
const selectedBlockClientId = getSelectedBlockClientId();
|
|
129
|
-
const selectionStartClientId = getMultiSelectedBlocksStartClientId();
|
|
130
|
-
const selectionEndClientId = getMultiSelectedBlocksEndClientId();
|
|
131
|
-
const selectionBeforeEndClientId = getPreviousBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
132
|
-
const selectionAfterEndClientId = getNextBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
133
|
-
const nextSelectionEndClientId = isReverse ? selectionBeforeEndClientId : selectionAfterEndClientId;
|
|
134
|
-
|
|
135
|
-
if (nextSelectionEndClientId) {
|
|
136
|
-
if (selectionStartClientId === nextSelectionEndClientId) {
|
|
137
|
-
selectBlock(nextSelectionEndClientId);
|
|
138
|
-
} else {
|
|
139
|
-
multiSelect(selectionStartClientId || selectedBlockClientId, nextSelectionEndClientId);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function moveSelection(isReverse) {
|
|
145
|
-
const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
|
|
146
|
-
const selectedLastClientId = getLastMultiSelectedBlockClientId();
|
|
147
|
-
const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId;
|
|
148
|
-
|
|
149
|
-
if (focusedBlockClientId) {
|
|
150
|
-
selectBlock(focusedBlockClientId);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
119
|
/**
|
|
154
120
|
* Returns true if the given target field is the last in its block which
|
|
155
121
|
* can be considered for tab transition. For example, in a block with
|
|
@@ -192,12 +158,6 @@ export default function useArrowNav() {
|
|
|
192
158
|
} = ownerDocument;
|
|
193
159
|
|
|
194
160
|
if (hasMultiSelection()) {
|
|
195
|
-
if (isNav) {
|
|
196
|
-
const action = isShift ? expandSelection : moveSelection;
|
|
197
|
-
action(isReverse);
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
161
|
return;
|
|
202
162
|
} // When presing any key other than up or down, the initial vertical
|
|
203
163
|
// position must ALWAYS be reset. The vertical position is saved so
|
|
@@ -245,10 +205,9 @@ export default function useArrowNav() {
|
|
|
245
205
|
|
|
246
206
|
if ( // Ensure that there is a target block.
|
|
247
207
|
(isReverse && selectionBeforeEndClientId || !isReverse && selectionAfterEndClientId) && isTabbableEdge(target, isReverse) && isNavEdge(target, isReverse)) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
event.preventDefault();
|
|
208
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
209
|
+
|
|
210
|
+
node.focus();
|
|
252
211
|
}
|
|
253
212
|
} else if (isVertical && isVerticalEdge(target, isReverse) && !keepCaretInsideBlock) {
|
|
254
213
|
const closestTabbable = getClosestTabbable(target, isReverse, node, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useDispatch","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getFirstMultiSelectedBlockClientId","getLastMultiSelectedBlockClientId","getSettings","hasMultiSelection","multiSelect","selectBlock","verticalRect","onMouseDown","expandSelection","selectedBlockClientId","selectionStartClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","nextSelectionEndClientId","moveSelection","selectedFirstClientId","selectedLastClientId","focusedBlockClientId","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","action","preventDefault","defaultPrevented","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKZ,EAAZ,IAAkBY,OAAO,KAAKX,IAAjD,CADsE,CAGtE;;AACA,MAAKa,UAAU,IAAI,CAAED,WAArB,EAAmC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KAHD;AAIA,GAnMkB,EAmMhB,EAnMgB,CAAnB;AAoMA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetFirstMultiSelectedBlockClientId,\n\t\tgetLastMultiSelectedBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction expandSelection( isReverse ) {\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst selectionStartClientId = getMultiSelectedBlocksStartClientId();\n\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst nextSelectionEndClientId = isReverse\n\t\t\t\t? selectionBeforeEndClientId\n\t\t\t\t: selectionAfterEndClientId;\n\n\t\t\tif ( nextSelectionEndClientId ) {\n\t\t\t\tif ( selectionStartClientId === nextSelectionEndClientId ) {\n\t\t\t\t\tselectBlock( nextSelectionEndClientId );\n\t\t\t\t} else {\n\t\t\t\t\tmultiSelect(\n\t\t\t\t\t\tselectionStartClientId || selectedBlockClientId,\n\t\t\t\t\t\tnextSelectionEndClientId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction moveSelection( isReverse ) {\n\t\t\tconst selectedFirstClientId = getFirstMultiSelectedBlockClientId();\n\t\t\tconst selectedLastClientId = getLastMultiSelectedBlockClientId();\n\t\t\tconst focusedBlockClientId = isReverse\n\t\t\t\t? selectedFirstClientId\n\t\t\t\t: selectedLastClientId;\n\n\t\t\tif ( focusedBlockClientId ) {\n\t\t\t\tselectBlock( focusedBlockClientId );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( isNav ) {\n\t\t\t\t\tconst action = isShift ? expandSelection : moveSelection;\n\t\t\t\t\taction( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\t// Shift key is down, and there is multi selection or we're\n\t\t\t\t\t// at the end of the current block.\n\t\t\t\t\texpandSelection( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKX,EAAZ,IAAkBW,OAAO,KAAKV,IAAjD,CADsE,CAGtE;;AACA,MAAKY,UAAU,IAAI,CAAED,WAArB,EAAmC;AAClC,WAAO,IAAP;AACA,GANqE,CAQtE;;;AACA,QAAM;AAAEE,IAAAA;AAAF,MAAcJ,OAApB;AACA,SAAOI,OAAO,KAAK,OAAZ,IAAuBA,OAAO,KAAK,UAA1C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CACNC,MADM,EAENC,SAFM,EAGNC,gBAHM,EAINC,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,IACNmB,UAAU,IACVjB,cAAc,CAAEoB,MAAF,EAAUC,SAAV,CADd,IAEA,CAAE+C,oBAHI,EAIL;AACD,cAAMnB,eAAe,GAAG9B,kBAAkB,CACzCC,MADyC,EAEzCC,SAFyC,EAGzCU,IAHyC,EAIzC,IAJyC,CAA1C;;AAOA,YAAKkB,eAAL,EAAuB;AACtB/C,UAAAA,wBAAwB,CACvB+C,eADuB,EAEvB5B,SAFuB,EAGvByB,YAHuB,CAAxB;AAKAK,UAAAA,KAAK,CAACsB,cAAN;AACA;AACD,OApBM,MAoBA,IACNjB,YAAY,IACZS,WAAW,CAACS,YAAZ,GAA2BC,WAD3B,IAEA5E,gBAAgB,CAAEqB,MAAF,EAAU+C,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMnB,eAAe,GAAG9B,kBAAkB,CACzCC,MADyC,EAEzC+C,YAFyC,EAGzCpC,IAHyC,CAA1C;AAKA9B,QAAAA,0BAA0B,CAAEgD,eAAF,EAAmB5B,SAAnB,CAA1B;AACA8B,QAAAA,KAAK,CAACsB,cAAN;AACA;AACD;;AAED1C,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,WAAvB,EAAoC7B,WAApC;AACAhB,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,SAAvB,EAAkC1B,SAAlC;AACA,WAAO,MAAM;AACZnB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,WAA1B,EAAuC9B,WAAvC;AACAhB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,SAA1B,EAAqC3B,SAArC;AACA,KAHD;AAIA,GAtJkB,EAsJhB,EAtJgB,CAAnB;AAuJA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
import { getBlockClientId } from '../../utils/dom';
|
|
12
|
+
export default function useClickSelection() {
|
|
13
|
+
const {
|
|
14
|
+
multiSelect,
|
|
15
|
+
selectBlock
|
|
16
|
+
} = useDispatch(blockEditorStore);
|
|
17
|
+
const {
|
|
18
|
+
isSelectionEnabled,
|
|
19
|
+
getBlockParents,
|
|
20
|
+
getBlockSelectionStart,
|
|
21
|
+
hasMultiSelection
|
|
22
|
+
} = useSelect(blockEditorStore);
|
|
23
|
+
return useRefEffect(node => {
|
|
24
|
+
function onMouseDown(event) {
|
|
25
|
+
// The main button.
|
|
26
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
27
|
+
if (!isSelectionEnabled() || event.button !== 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const startClientId = getBlockSelectionStart();
|
|
32
|
+
const clickedClientId = getBlockClientId(event.target);
|
|
33
|
+
|
|
34
|
+
if (event.shiftKey) {
|
|
35
|
+
if (startClientId !== clickedClientId) {
|
|
36
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
37
|
+
|
|
38
|
+
node.focus();
|
|
39
|
+
}
|
|
40
|
+
} else if (hasMultiSelection()) {
|
|
41
|
+
// Allow user to escape out of a multi-selection to a
|
|
42
|
+
// singular selection of a block via click. This is handled
|
|
43
|
+
// here since focus handling excludes blocks when there is
|
|
44
|
+
// multiselection, as focus can be incurred by starting a
|
|
45
|
+
// multiselection (focus moved to first block's multi-
|
|
46
|
+
// controls).
|
|
47
|
+
selectBlock(clickedClientId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
node.addEventListener('mousedown', onMouseDown);
|
|
52
|
+
return () => {
|
|
53
|
+
node.removeEventListener('mousedown', onMouseDown);
|
|
54
|
+
};
|
|
55
|
+
}, [multiSelect, selectBlock, isSelectionEnabled, getBlockParents, getBlockSelectionStart, hasMultiSelection]);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=use-click-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-click-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","useClickSelection","multiSelect","selectBlock","isSelectionEnabled","getBlockParents","getBlockSelectionStart","hasMultiSelection","node","onMouseDown","event","button","startClientId","clickedClientId","target","shiftKey","contentEditable","focus","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA,eAAe,SAASC,iBAAT,GAA6B;AAC3C,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,MAA+BP,WAAW,CAAEG,gBAAF,CAAhD;AACA,QAAM;AACLK,IAAAA,kBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,sBAHK;AAILC,IAAAA;AAJK,MAKFZ,SAAS,CAAEI,gBAAF,CALb;AAMA,SAAOF,YAAY,CAChBW,IAAF,IAAY;AACX,aAASC,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;AACA;AACA,UAAK,CAAEN,kBAAkB,EAApB,IAA0BM,KAAK,CAACC,MAAN,KAAiB,CAAhD,EAAoD;AACnD;AACA;;AAED,YAAMC,aAAa,GAAGN,sBAAsB,EAA5C;AACA,YAAMO,eAAe,GAAGb,gBAAgB,CAAEU,KAAK,CAACI,MAAR,CAAxC;;AAEA,UAAKJ,KAAK,CAACK,QAAX,EAAsB;AACrB,YAAKH,aAAa,KAAKC,eAAvB,EAAyC;AACxCL,UAAAA,IAAI,CAACQ,eAAL,GAAuB,IAAvB,CADwC,CAExC;;AACAR,UAAAA,IAAI,CAACS,KAAL;AACA;AACD,OAND,MAMO,IAAKV,iBAAiB,EAAtB,EAA2B;AACjC;AACA;AACA;AACA;AACA;AACA;AACAJ,QAAAA,WAAW,CAAEU,eAAF,CAAX;AACA;AACD;;AAEDL,IAAAA,IAAI,CAACU,gBAAL,CAAuB,WAAvB,EAAoCT,WAApC;AAEA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACW,mBAAL,CAA0B,WAA1B,EAAuCV,WAAvC;AACA,KAFD;AAGA,GAlCiB,EAmClB,CACCP,WADD,EAECC,WAFD,EAGCC,kBAHD,EAICC,eAJD,EAKCC,sBALD,EAMCC,iBAND,CAnCkB,CAAnB;AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onMouseDown( event ) {\n\t\t\t\t// The main button.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\n\t\t\t\tif ( ! isSelectionEnabled() || event.button !== 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startClientId = getBlockSelectionStart();\n\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\n\t\t\t\tif ( event.shiftKey ) {\n\t\t\t\t\tif ( startClientId !== clickedClientId ) {\n\t\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\t\tnode.focus();\n\t\t\t\t\t}\n\t\t\t\t} else if ( hasMultiSelection() ) {\n\t\t\t\t\t// Allow user to escape out of a multi-selection to a\n\t\t\t\t\t// singular selection of a block via click. This is handled\n\t\t\t\t\t// here since focus handling excludes blocks when there is\n\t\t\t\t\t// multiselection, as focus can be incurred by starting a\n\t\t\t\t\t// multiselection (focus moved to first block's multi-\n\t\t\t\t\t// controls).\n\t\t\t\t\tselectBlock( clickedClientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockParents,\n\t\t\tgetBlockSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
/**
|
|
12
|
+
* Sets the `contenteditable` wrapper element to `value`.
|
|
13
|
+
*
|
|
14
|
+
* @param {HTMLElement} node Block element.
|
|
15
|
+
* @param {boolean} value `contentEditable` value (true or false)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function setContentEditableWrapper(node, value) {
|
|
19
|
+
node.contentEditable = value; // Firefox doesn't automatically move focus.
|
|
20
|
+
|
|
21
|
+
if (value) node.focus();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sets a multi-selection based on the native selection across blocks.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export default function useDragSelection() {
|
|
29
|
+
const {
|
|
30
|
+
startMultiSelect,
|
|
31
|
+
stopMultiSelect
|
|
32
|
+
} = useDispatch(blockEditorStore);
|
|
33
|
+
const {
|
|
34
|
+
isSelectionEnabled,
|
|
35
|
+
hasMultiSelection
|
|
36
|
+
} = useSelect(blockEditorStore);
|
|
37
|
+
return useRefEffect(node => {
|
|
38
|
+
const {
|
|
39
|
+
ownerDocument
|
|
40
|
+
} = node;
|
|
41
|
+
const {
|
|
42
|
+
defaultView
|
|
43
|
+
} = ownerDocument;
|
|
44
|
+
let anchorElement;
|
|
45
|
+
let rafId;
|
|
46
|
+
|
|
47
|
+
function onMouseUp() {
|
|
48
|
+
stopMultiSelect(); // Equivalent to attaching the listener once.
|
|
49
|
+
|
|
50
|
+
defaultView.removeEventListener('mouseup', onMouseUp); // The browser selection won't have updated yet at this point,
|
|
51
|
+
// so wait until the next animation frame to get the browser
|
|
52
|
+
// selection.
|
|
53
|
+
|
|
54
|
+
rafId = defaultView.requestAnimationFrame(() => {
|
|
55
|
+
if (hasMultiSelection()) {
|
|
56
|
+
return;
|
|
57
|
+
} // If the selection is complete (on mouse up), and no
|
|
58
|
+
// multiple blocks have been selected, set focus back to the
|
|
59
|
+
// anchor element. if the anchor element contains the
|
|
60
|
+
// selection. Additionally, the contentEditable wrapper can
|
|
61
|
+
// now be disabled again.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
setContentEditableWrapper(node, false);
|
|
65
|
+
const selection = defaultView.getSelection();
|
|
66
|
+
|
|
67
|
+
if (selection.rangeCount) {
|
|
68
|
+
const {
|
|
69
|
+
commonAncestorContainer
|
|
70
|
+
} = selection.getRangeAt(0);
|
|
71
|
+
|
|
72
|
+
if (anchorElement.contains(commonAncestorContainer)) {
|
|
73
|
+
anchorElement.focus();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function onMouseLeave(_ref) {
|
|
80
|
+
let {
|
|
81
|
+
buttons,
|
|
82
|
+
target
|
|
83
|
+
} = _ref;
|
|
84
|
+
|
|
85
|
+
// The primary button must be pressed to initiate selection.
|
|
86
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
87
|
+
if (buttons !== 1) {
|
|
88
|
+
return;
|
|
89
|
+
} // Check the attribute, not the contentEditable attribute. All
|
|
90
|
+
// child elements of the content editable wrapper are editable
|
|
91
|
+
// and return true for this property. We only want to start
|
|
92
|
+
// multi selecting when the mouse leaves the wrapper.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if (!target.getAttribute('contenteditable')) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!isSelectionEnabled()) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
anchorElement = ownerDocument.activeElement;
|
|
104
|
+
startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
|
|
105
|
+
// `mouseleave` (from a block). The selection ends when
|
|
106
|
+
// `mouseup` happens anywhere in the window.
|
|
107
|
+
|
|
108
|
+
defaultView.addEventListener('mouseup', onMouseUp); // Allow cross contentEditable selection by temporarily making
|
|
109
|
+
// all content editable. We can't rely on using the store and
|
|
110
|
+
// React because re-rending happens too slowly. We need to be
|
|
111
|
+
// able to select across instances immediately.
|
|
112
|
+
|
|
113
|
+
setContentEditableWrapper(node, true);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
node.addEventListener('mouseout', onMouseLeave);
|
|
117
|
+
return () => {
|
|
118
|
+
node.removeEventListener('mouseout', onMouseLeave);
|
|
119
|
+
defaultView.removeEventListener('mouseup', onMouseUp);
|
|
120
|
+
defaultView.cancelAnimationFrame(rafId);
|
|
121
|
+
};
|
|
122
|
+
}, [startMultiSelect, stopMultiSelect, isSelectionEnabled, hasMultiSelection]);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=use-drag-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-drag-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","setContentEditableWrapper","node","value","contentEditable","focus","useDragSelection","startMultiSelect","stopMultiSelect","isSelectionEnabled","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onMouseUp","removeEventListener","requestAnimationFrame","selection","getSelection","rangeCount","commonAncestorContainer","getRangeAt","contains","onMouseLeave","buttons","target","getAttribute","activeElement","addEventListener","cancelAnimationFrame"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAoCC,IAApC,EAA0CC,KAA1C,EAAk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C,QAAAA;AAAX,OAAsB;;AAC5C;AACA;AACA,UAAKD,OAAO,KAAK,CAAjB,EAAqB;AACpB;AACA,OAL2C,CAO5C;AACA;AACA;AACA;;;AACA,UAAK,CAAEC,MAAM,CAACC,YAAP,CAAqB,iBAArB,CAAP,EAAkD;AACjD;AACA;;AAED,UAAK,CAAElB,kBAAkB,EAAzB,EAA8B;AAC7B;AACA;;AAEDI,MAAAA,aAAa,GAAGF,aAAa,CAACiB,aAA9B;AACArB,MAAAA,gBAAgB,GApB4B,CAsB5C;AACA;AACA;;AACAK,MAAAA,WAAW,CAACiB,gBAAZ,CAA8B,SAA9B,EAAyCd,SAAzC,EAzB4C,CA2B5C;AACA;AACA;AACA;;AACAd,MAAAA,yBAAyB,CAAEC,IAAF,EAAQ,IAAR,CAAzB;AACA;;AAEDA,IAAAA,IAAI,CAAC2B,gBAAL,CAAuB,UAAvB,EAAmCL,YAAnC;AAEA,WAAO,MAAM;AACZtB,MAAAA,IAAI,CAACc,mBAAL,CAA0B,UAA1B,EAAsCQ,YAAtC;AACAZ,MAAAA,WAAW,CAACI,mBAAZ,CAAiC,SAAjC,EAA4CD,SAA5C;AACAH,MAAAA,WAAW,CAACkB,oBAAZ,CAAkChB,KAAlC;AACA,KAJD;AAKA,GApFiB,EAqFlB,CACCP,gBADD,EAECC,eAFD,EAGCC,kBAHD,EAICC,iBAJD,CArFkB,CAAnB;AA4FA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useDragSelection() {\n\tconst { startMultiSelect, stopMultiSelect } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { isSelectionEnabled, hasMultiSelection } = useSelect(\n\t\tblockEditorStore\n\t);\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tlet anchorElement;\n\t\t\tlet rafId;\n\n\t\t\tfunction onMouseUp() {\n\t\t\t\tstopMultiSelect();\n\t\t\t\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\t// The browser selection won't have updated yet at this point,\n\t\t\t\t// so wait until the next animation frame to get the browser\n\t\t\t\t// selection.\n\t\t\t\trafId = defaultView.requestAnimationFrame( () => {\n\t\t\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the selection is complete (on mouse up), and no\n\t\t\t\t\t// multiple blocks have been selected, set focus back to the\n\t\t\t\t\t// anchor element. if the anchor element contains the\n\t\t\t\t\t// selection. Additionally, the contentEditable wrapper can\n\t\t\t\t\t// now be disabled again.\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tanchorElement.contains( commonAncestorContainer )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons, target } ) {\n\t\t\t\t// The primary button must be pressed to initiate selection.\n\t\t\t\t// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n\t\t\t\tif ( buttons !== 1 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Check the attribute, not the contentEditable attribute. All\n\t\t\t\t// child elements of the content editable wrapper are editable\n\t\t\t\t// and return true for this property. We only want to start\n\t\t\t\t// multi selecting when the mouse leaves the wrapper.\n\t\t\t\tif ( ! target.getAttribute( 'contenteditable' ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isSelectionEnabled() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tanchorElement = ownerDocument.activeElement;\n\t\t\t\tstartMultiSelect();\n\n\t\t\t\t// `onSelectionStart` is called after `mousedown` and\n\t\t\t\t// `mouseleave` (from a block). The selection ends when\n\t\t\t\t// `mouseup` happens anywhere in the window.\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onMouseUp );\n\n\t\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t\t// able to select across instances immediately.\n\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mouseout', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mouseout', onMouseLeave );\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tisSelectionEnabled,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
|
|
7
|
+
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { store as blockEditorStore } from '../../store';
|
|
13
|
+
/**
|
|
14
|
+
* Handles input for selections across blocks.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function useInput() {
|
|
18
|
+
const {
|
|
19
|
+
__unstableIsFullySelected,
|
|
20
|
+
getSelectedBlockClientIds,
|
|
21
|
+
__unstableIsSelectionMergeable,
|
|
22
|
+
hasMultiSelection
|
|
23
|
+
} = useSelect(blockEditorStore);
|
|
24
|
+
const {
|
|
25
|
+
replaceBlocks,
|
|
26
|
+
__unstableSplitSelection,
|
|
27
|
+
removeBlocks,
|
|
28
|
+
__unstableDeleteSelection,
|
|
29
|
+
__unstableExpandSelection
|
|
30
|
+
} = useDispatch(blockEditorStore);
|
|
31
|
+
return useRefEffect(node => {
|
|
32
|
+
function onKeyDown(event) {
|
|
33
|
+
if (event.defaultPrevented) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!hasMultiSelection()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (event.keyCode === ENTER) {
|
|
42
|
+
node.contentEditable = false;
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
|
|
45
|
+
if (__unstableIsFullySelected()) {
|
|
46
|
+
replaceBlocks(getSelectedBlockClientIds(), createBlock(getDefaultBlockName()));
|
|
47
|
+
} else {
|
|
48
|
+
__unstableSplitSelection();
|
|
49
|
+
}
|
|
50
|
+
} else if (event.keyCode === BACKSPACE || event.keyCode === DELETE) {
|
|
51
|
+
node.contentEditable = false;
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
|
|
54
|
+
if (__unstableIsFullySelected()) {
|
|
55
|
+
removeBlocks(getSelectedBlockClientIds());
|
|
56
|
+
} else if (__unstableIsSelectionMergeable()) {
|
|
57
|
+
__unstableDeleteSelection(event.keyCode === DELETE);
|
|
58
|
+
} else {
|
|
59
|
+
__unstableExpandSelection();
|
|
60
|
+
}
|
|
61
|
+
} else if ( // If key.length is longer than 1, it's a control key that doesn't
|
|
62
|
+
// input anything.
|
|
63
|
+
event.key.length === 1 && !(event.metaKey || event.ctrlKey)) {
|
|
64
|
+
node.contentEditable = false;
|
|
65
|
+
|
|
66
|
+
if (__unstableIsSelectionMergeable()) {
|
|
67
|
+
__unstableDeleteSelection(event.keyCode === DELETE);
|
|
68
|
+
} else {
|
|
69
|
+
event.preventDefault(); // Safari does not stop default behaviour with either
|
|
70
|
+
// event.preventDefault() or node.contentEditable = false, so
|
|
71
|
+
// remove the selection to stop browser manipulation.
|
|
72
|
+
|
|
73
|
+
node.ownerDocument.defaultView.getSelection().removeAllRanges();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onCompositionStart(event) {
|
|
79
|
+
if (!hasMultiSelection()) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
node.contentEditable = false;
|
|
84
|
+
|
|
85
|
+
if (__unstableIsSelectionMergeable()) {
|
|
86
|
+
__unstableDeleteSelection();
|
|
87
|
+
} else {
|
|
88
|
+
event.preventDefault(); // Safari does not stop default behaviour with either
|
|
89
|
+
// event.preventDefault() or node.contentEditable = false, so
|
|
90
|
+
// remove the selection to stop browser manipulation.
|
|
91
|
+
|
|
92
|
+
node.ownerDocument.defaultView.getSelection().removeAllRanges();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
node.addEventListener('keydown', onKeyDown);
|
|
97
|
+
node.addEventListener('compositionstart', onCompositionStart);
|
|
98
|
+
return () => {
|
|
99
|
+
node.removeEventListener('keydown', onKeyDown);
|
|
100
|
+
node.removeEventListener('compositionstart', onCompositionStart);
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=use-input.js.map
|