UNPKG

@wordpress/block-editor

Version:
121 lines (119 loc) 4.59 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js var zoom_out_mode_inserters_exports = {}; __export(zoom_out_mode_inserters_exports, { default: () => zoom_out_mode_inserters_default }); module.exports = __toCommonJS(zoom_out_mode_inserters_exports); var import_data = require("@wordpress/data"); var import_element = require("@wordpress/element"); var import_inbetween = __toESM(require("../block-popover/inbetween.cjs")); var import_zoom_out_mode_inserter_button = __toESM(require("./zoom-out-mode-inserter-button.cjs")); var import_store = require("../../store/index.cjs"); var import_lock_unlock = require("../../lock-unlock.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function ZoomOutModeInserters() { const [isReady, setIsReady] = (0, import_element.useState)(false); const { hasSelection, blockOrder, setInserterIsOpened, sectionRootClientId, selectedBlockClientId, blockInsertionPoint, insertionPointVisible } = (0, import_data.useSelect)((select) => { const { getSettings, getBlockOrder, getSelectionStart, getSelectedBlockClientId, getSectionRootClientId, getBlockInsertionPoint, isBlockInsertionPointVisible } = (0, import_lock_unlock.unlock)(select(import_store.store)); const root = getSectionRootClientId(); return { hasSelection: !!getSelectionStart().clientId, blockOrder: getBlockOrder(root), sectionRootClientId: root, setInserterIsOpened: getSettings().__experimentalSetIsInserterOpened, selectedBlockClientId: getSelectedBlockClientId(), blockInsertionPoint: getBlockInsertionPoint(), insertionPointVisible: isBlockInsertionPointVisible() }; }, []); const { showInsertionPoint } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store)); (0, import_element.useEffect)(() => { const timeout = setTimeout(() => { setIsReady(true); }, 500); return () => { clearTimeout(timeout); }; }, []); if (!isReady || !hasSelection) { return null; } const previousClientId = selectedBlockClientId; const index = blockOrder.findIndex( (clientId) => selectedBlockClientId === clientId ); const insertionIndex = index + 1; const nextClientId = blockOrder[insertionIndex]; if (insertionPointVisible && blockInsertionPoint?.index === insertionIndex) { return null; } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_inbetween.default, { previousClientId, nextClientId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_zoom_out_mode_inserter_button.default, { onClick: () => { setInserterIsOpened({ rootClientId: sectionRootClientId, insertionIndex, tab: "patterns", category: "all" }); showInsertionPoint(sectionRootClientId, insertionIndex, { operation: "insert" }); } } ) } ); } var zoom_out_mode_inserters_default = ZoomOutModeInserters; //# sourceMappingURL=zoom-out-mode-inserters.cjs.map