@wordpress/block-editor
Version:
142 lines (140 loc) • 6 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/block-breadcrumb/index.js
var block_breadcrumb_exports = {};
__export(block_breadcrumb_exports, {
default: () => block_breadcrumb_default
});
module.exports = __toCommonJS(block_breadcrumb_exports);
var import_components = require("@wordpress/components");
var import_data = require("@wordpress/data");
var import_i18n = require("@wordpress/i18n");
var import_icons = require("@wordpress/icons");
var import_element = require("@wordpress/element");
var import_block_title = __toESM(require("../block-title"));
var import_store = require("../../store");
var import_lock_unlock = require("../../lock-unlock");
var import_use_block_refs = require("../block-list/use-block-props/use-block-refs");
var import_get_editor_region = __toESM(require("../../utils/get-editor-region"));
var import_jsx_runtime = require("react/jsx-runtime");
function BlockBreadcrumb({ rootLabelText }) {
const { selectBlock, clearSelectedBlock } = (0, import_data.useDispatch)(import_store.store);
const { clientId, parents, hasSelection } = (0, import_data.useSelect)((select) => {
const {
getSelectionStart,
getSelectedBlockClientId,
getEnabledBlockParents
} = (0, import_lock_unlock.unlock)(select(import_store.store));
const selectedBlockClientId = getSelectedBlockClientId();
return {
parents: getEnabledBlockParents(selectedBlockClientId),
clientId: selectedBlockClientId,
hasSelection: !!getSelectionStart().clientId
};
}, []);
const rootLabel = rootLabelText || (0, import_i18n.__)("Document");
const blockRef = (0, import_element.useRef)();
(0, import_use_block_refs.useBlockElementRef)(clientId, blockRef);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"ul",
{
className: "block-editor-block-breadcrumb",
role: "list",
"aria-label": (0, import_i18n.__)("Block breadcrumb"),
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"li",
{
className: !hasSelection ? "block-editor-block-breadcrumb__current" : void 0,
"aria-current": !hasSelection ? "true" : void 0,
children: [
hasSelection && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.Button,
{
size: "small",
className: "block-editor-block-breadcrumb__button",
onClick: () => {
const blockEditor = blockRef.current?.closest(
".editor-styles-wrapper"
);
clearSelectedBlock();
(0, import_get_editor_region.default)(blockEditor)?.focus();
},
children: rootLabel
}
),
!hasSelection && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: rootLabel }),
!!clientId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_icons.Icon,
{
icon: import_icons.chevronRightSmall,
className: "block-editor-block-breadcrumb__separator"
}
)
]
}
),
parents.map((parentClientId) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.Button,
{
size: "small",
className: "block-editor-block-breadcrumb__button",
onClick: () => selectBlock(parentClientId),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_block_title.default,
{
clientId: parentClientId,
maximumLength: 35
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_icons.Icon,
{
icon: import_icons.chevronRightSmall,
className: "block-editor-block-breadcrumb__separator"
}
)
] }, parentClientId)),
!!clientId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"li",
{
className: "block-editor-block-breadcrumb__current",
"aria-current": "true",
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_title.default, { clientId, maximumLength: 35 })
}
)
]
}
);
}
var block_breadcrumb_default = BlockBreadcrumb;
//# sourceMappingURL=index.js.map