UNPKG

@wordpress/block-editor

Version:
88 lines (86 loc) 2.83 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/writing-flow/use-multi-selection.js var use_multi_selection_exports = {}; __export(use_multi_selection_exports, { default: () => useMultiSelection }); module.exports = __toCommonJS(use_multi_selection_exports); var import_compose = require("@wordpress/compose"); var import_data = require("@wordpress/data"); var import_store = require("../../store"); function selector(select) { const { isMultiSelecting, getMultiSelectedBlockClientIds, hasMultiSelection, getSelectedBlockClientId, getSelectedBlocksInitialCaretPosition, __unstableIsFullySelected } = select(import_store.store); return { isMultiSelecting: isMultiSelecting(), multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(), hasMultiSelection: hasMultiSelection(), selectedBlockClientId: getSelectedBlockClientId(), initialPosition: getSelectedBlocksInitialCaretPosition(), isFullSelection: __unstableIsFullySelected() }; } function useMultiSelection() { const { initialPosition, isMultiSelecting, multiSelectedBlockClientIds, hasMultiSelection, selectedBlockClientId, isFullSelection } = (0, import_data.useSelect)(selector, []); return (0, import_compose.useRefEffect)( (node) => { const { ownerDocument } = node; const { defaultView } = ownerDocument; if (initialPosition === void 0 || initialPosition === null) { return; } if (!hasMultiSelection || isMultiSelecting) { return; } const { length } = multiSelectedBlockClientIds; if (length < 2) { return; } if (!isFullSelection) { return; } node.contentEditable = true; node.focus(); defaultView.getSelection().removeAllRanges(); }, [ hasMultiSelection, isMultiSelecting, multiSelectedBlockClientIds, selectedBlockClientId, initialPosition, isFullSelection ] ); } //# sourceMappingURL=use-multi-selection.js.map