@wordpress/block-library
Version:
Block library for the WordPress editor.
118 lines (117 loc) • 5.4 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
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 __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let _wordpress_html_entities = require("@wordpress/html-entities");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_core_data = require("@wordpress/core-data");
let __use_post_terms_js = require("./use-post-terms.cjs");
__use_post_terms_js = __toESM(__use_post_terms_js);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/post-terms/edit.jsx
const ALLOWED_FORMATS = [
"core/bold",
"core/image",
"core/italic",
"core/link",
"core/strikethrough",
"core/text-color"
];
function PostTermsEdit({ attributes, clientId, context, isSelected, setAttributes, insertBlocksAfter }) {
const { term, separator, prefix, suffix } = attributes;
const { postId, postType } = context;
const selectedTerm = (0, _wordpress_data.useSelect)((select) => {
if (!term) return {};
const { getTaxonomy } = select(_wordpress_core_data.store);
const taxonomy = getTaxonomy(term);
return taxonomy?.visibility?.publicly_queryable ? taxonomy : {};
}, [term]);
const { postTerms, hasPostTerms, isLoading } = (0, __use_post_terms_js.default)({
postId,
term: selectedTerm
});
const hasPost = postId && postType;
const blockInformation = (0, _wordpress_block_editor.useBlockDisplayInformation)(clientId);
const blockProps = (0, _wordpress_block_editor.useBlockProps)({ className: term && `taxonomy-${term}` });
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, {
group: "advanced",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.TextControl, {
autoComplete: "off",
label: (0, _wordpress_i18n.__)("Separator"),
value: separator || "",
onChange: (nextValue) => {
setAttributes({ separator: nextValue });
},
help: (0, _wordpress_i18n.__)("Enter character(s) used to separate terms.")
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...blockProps,
children: [
isLoading && hasPost && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {}),
!isLoading && (isSelected || prefix) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, {
identifier: "prefix",
allowedFormats: ALLOWED_FORMATS,
className: "wp-block-post-terms__prefix",
"aria-label": (0, _wordpress_i18n.__)("Prefix"),
placeholder: (0, _wordpress_i18n.__)("Prefix") + " ",
value: prefix,
onChange: (value) => setAttributes({ prefix: value }),
tagName: "span"
}),
(!hasPost || !term) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: blockInformation.title }),
hasPost && !isLoading && hasPostTerms && postTerms.map((postTerm) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
href: postTerm.link,
onClick: (event) => event.preventDefault(),
rel: "tag",
children: (0, _wordpress_html_entities.decodeEntities)(postTerm.name)
}, postTerm.id)).reduce((prev, curr) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
prev,
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "wp-block-post-terms__separator",
children: separator || " "
}),
curr
] })),
hasPost && !isLoading && !hasPostTerms && (selectedTerm?.labels?.no_terms || (0, _wordpress_i18n.__)("Term items not found.")),
!isLoading && (isSelected || suffix) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, {
identifier: "suffix",
allowedFormats: ALLOWED_FORMATS,
className: "wp-block-post-terms__suffix",
"aria-label": (0, _wordpress_i18n.__)("Suffix"),
placeholder: " " + (0, _wordpress_i18n.__)("Suffix"),
value: suffix,
onChange: (value) => setAttributes({ suffix: value }),
tagName: "span",
__unstableOnSplitAtEnd: insertBlocksAfter ? () => insertBlocksAfter((0, _wordpress_blocks.createBlock)((0, _wordpress_blocks.getDefaultBlockName)())) : void 0
})
]
})] });
}
exports.default = PostTermsEdit;
//# sourceMappingURL=edit.cjs.map