@wordpress/block-editor
Version:
126 lines (124 loc) • 5.23 kB
JavaScript
;
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/list-view/appender.js
var appender_exports = {};
__export(appender_exports, {
Appender: () => Appender
});
module.exports = __toCommonJS(appender_exports);
var import_compose = require("@wordpress/compose");
var import_a11y = require("@wordpress/a11y");
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_i18n = require("@wordpress/i18n");
var import_store = require("../../store");
var import_use_block_display_title = __toESM(require("../block-title/use-block-display-title"));
var import_context = require("./context");
var import_inserter = __toESM(require("../inserter"));
var import_aria_referenced_text = __toESM(require("./aria-referenced-text"));
var import_lock_unlock = require("../../lock-unlock");
var import_jsx_runtime = require("react/jsx-runtime");
var Appender = (0, import_element.forwardRef)(
({ nestingLevel, blockCount, clientId, ...props }, ref) => {
const { insertedBlock, setInsertedBlock } = (0, import_context.useListViewContext)();
const instanceId = (0, import_compose.useInstanceId)(Appender);
const { directInsert, hideInserter } = (0, import_data.useSelect)(
(select) => {
const { getBlockListSettings, getTemplateLock, isZoomOut } = (0, import_lock_unlock.unlock)(select(import_store.store));
const settings = getBlockListSettings(clientId);
const directInsertValue = settings?.directInsert || false;
const hideInserterValue = !!getTemplateLock(clientId) || isZoomOut();
return {
directInsert: directInsertValue,
hideInserter: hideInserterValue
};
},
[clientId]
);
const blockTitle = (0, import_use_block_display_title.default)({
clientId,
context: "list-view"
});
const insertedBlockTitle = (0, import_use_block_display_title.default)({
clientId: insertedBlock?.clientId,
context: "list-view"
});
(0, import_element.useEffect)(() => {
if (!insertedBlockTitle?.length) {
return;
}
(0, import_a11y.speak)(
(0, import_i18n.sprintf)(
// translators: %s: name of block being inserted (i.e. Paragraph, Image, Group etc)
(0, import_i18n.__)("%s block inserted"),
insertedBlockTitle
),
"assertive"
);
}, [insertedBlockTitle]);
if (hideInserter) {
return null;
}
const descriptionId = `list-view-appender__${instanceId}`;
const description = (0, import_i18n.sprintf)(
/* translators: 1: The name of the block. 2: The numerical position of the block. 3: The level of nesting for the block. */
(0, import_i18n.__)("Append to %1$s block at position %2$d, Level %3$d"),
blockTitle,
blockCount + 1,
nestingLevel
);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "list-view-appender", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_inserter.default,
{
ref,
rootClientId: clientId,
position: "bottom right",
isAppender: true,
selectBlockOnInsert: false,
shouldDirectInsert: directInsert,
__experimentalIsQuick: true,
...props,
toggleProps: { "aria-describedby": descriptionId },
onSelectOrClose: (maybeInsertedBlock) => {
if (maybeInsertedBlock?.clientId) {
setInsertedBlock(maybeInsertedBlock);
}
}
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_aria_referenced_text.default, { id: descriptionId, children: description })
] });
}
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Appender
});
//# sourceMappingURL=appender.js.map