UNPKG

@wordpress/block-editor

Version:
150 lines (148 loc) 5.52 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/inserter/quick-inserter.js var quick_inserter_exports = {}; __export(quick_inserter_exports, { default: () => QuickInserter }); module.exports = __toCommonJS(quick_inserter_exports); var import_clsx = __toESM(require("clsx")); var import_element = require("@wordpress/element"); var import_i18n = require("@wordpress/i18n"); var import_components = require("@wordpress/components"); var import_data = require("@wordpress/data"); var import_search_results = __toESM(require("./search-results")); var import_use_insertion_point = __toESM(require("./hooks/use-insertion-point")); var import_use_block_types_state = __toESM(require("./hooks/use-block-types-state")); var import_store = require("../../store"); var import_jsx_runtime = require("react/jsx-runtime"); var SEARCH_THRESHOLD = 6; var SHOWN_BLOCK_TYPES = 6; var SHOWN_BLOCK_PATTERNS = 2; function QuickInserter({ onSelect, rootClientId, clientId, isAppender, selectBlockOnInsert, hasSearch = true }) { const [filterValue, setFilterValue] = (0, import_element.useState)(""); const [destinationRootClientId, onInsertBlocks] = (0, import_use_insertion_point.default)({ onSelect, rootClientId, clientId, isAppender, selectBlockOnInsert }); const [blockTypes] = (0, import_use_block_types_state.default)( destinationRootClientId, onInsertBlocks, true ); const { setInserterIsOpened, insertionIndex } = (0, import_data.useSelect)( (select) => { const { getSettings, getBlockIndex, getBlockCount } = select(import_store.store); const settings = getSettings(); const index = getBlockIndex(clientId); const blockCount = getBlockCount(); return { setInserterIsOpened: settings.__experimentalSetIsInserterOpened, insertionIndex: index === -1 ? blockCount : index }; }, [clientId] ); const showSearch = hasSearch && blockTypes.length > SEARCH_THRESHOLD; (0, import_element.useEffect)(() => { if (setInserterIsOpened) { setInserterIsOpened(false); } }, [setInserterIsOpened]); const onBrowseAll = () => { setInserterIsOpened({ filterValue, onSelect, rootClientId, insertionIndex }); }; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( "div", { className: (0, import_clsx.default)("block-editor-inserter__quick-inserter", { "has-search": showSearch, "has-expand": setInserterIsOpened }), children: [ showSearch && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.SearchControl, { __nextHasNoMarginBottom: true, className: "block-editor-inserter__search", value: filterValue, onChange: (value) => { setFilterValue(value); }, label: (0, import_i18n.__)("Search"), placeholder: (0, import_i18n.__)("Search") } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inserter__quick-inserter-results", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_search_results.default, { filterValue, onSelect, rootClientId, clientId, isAppender, maxBlockPatterns: !!filterValue ? SHOWN_BLOCK_PATTERNS : 0, maxBlockTypes: SHOWN_BLOCK_TYPES, isDraggable: false, selectBlockOnInsert, isQuick: true } ) }), setInserterIsOpened && /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Button, { __next40pxDefaultSize: true, className: "block-editor-inserter__quick-inserter-expand", onClick: onBrowseAll, "aria-label": (0, import_i18n.__)( "Browse all. This will open the main inserter panel in the editor toolbar." ), children: (0, import_i18n.__)("Browse all") } ) ] } ); } //# sourceMappingURL=quick-inserter.js.map