@wordpress/block-library
Version:
Block library for the WordPress editor.
140 lines (139 loc) • 7.65 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_components = require("@wordpress/components");
let _wordpress_i18n = require("@wordpress/i18n");
let __use_archive_label_js = require("./use-archive-label.cjs");
let __use_post_type_label_js = require("./use-post-type-label.cjs");
let ___utils_hooks_js = require("../utils/hooks.cjs");
let ___utils_deprecated_text_align_attributes_js = require("../utils/deprecated-text-align-attributes.cjs");
___utils_deprecated_text_align_attributes_js = __toESM(___utils_deprecated_text_align_attributes_js);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/query-title/edit.jsx
const SUPPORTED_TYPES = [
"archive",
"search",
"post-type"
];
function QueryTitleEdit(props) {
(0, ___utils_deprecated_text_align_attributes_js.default)(props);
const { attributes: { type, level, levelOptions, showPrefix, showSearchTerm }, setAttributes, context: { query } } = props;
const { archiveTypeLabel, archiveNameLabel } = (0, __use_archive_label_js.useArchiveLabel)();
const { postTypeLabel } = (0, __use_post_type_label_js.usePostTypeLabel)(query?.postType);
const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)();
const TagName = level === 0 ? "p" : `h${level}`;
const blockProps = (0, _wordpress_block_editor.useBlockProps)({ className: "wp-block-query-title__placeholder" });
if (!SUPPORTED_TYPES.includes(type)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
...blockProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.Warning, { children: (0, _wordpress_i18n.__)("Provided type is not supported.") })
});
let titleElement;
if (type === "archive") {
let title;
if (archiveTypeLabel) {
if (showPrefix) {
if (archiveNameLabel) title = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._x)("%1$s: %2$s", "archive label"), archiveTypeLabel, archiveNameLabel);
else title = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("%s: Name"), archiveTypeLabel);
} else if (archiveNameLabel) title = archiveNameLabel;
else title = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("%s name"), archiveTypeLabel);
} else title = showPrefix ? (0, _wordpress_i18n.__)("Archive type: Name") : (0, _wordpress_i18n.__)("Archive title");
titleElement = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => setAttributes({ showPrefix: true }),
dropdownMenuProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => !showPrefix,
label: (0, _wordpress_i18n.__)("Show archive type in title"),
onDeselect: () => setAttributes({ showPrefix: true }),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Show archive type in title"),
onChange: () => setAttributes({ showPrefix: !showPrefix }),
checked: showPrefix
})
})
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagName, {
...blockProps,
children: title
})] });
}
if (type === "search") titleElement = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => setAttributes({ showSearchTerm: true }),
dropdownMenuProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => !showSearchTerm,
label: (0, _wordpress_i18n.__)("Show search term in title"),
onDeselect: () => setAttributes({ showSearchTerm: true }),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Show search term in title"),
onChange: () => setAttributes({ showSearchTerm: !showSearchTerm }),
checked: showSearchTerm
})
})
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagName, {
...blockProps,
children: showSearchTerm ? (0, _wordpress_i18n.__)("Search results for: “search term”") : (0, _wordpress_i18n.__)("Search results")
})] });
if (type === "post-type") {
let title;
if (postTypeLabel) {
if (showPrefix) title = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Post Type: \"%s\""), postTypeLabel);
else title = postTypeLabel;
} else title = showPrefix ? (0, _wordpress_i18n.__)("Post Type: Name") : (0, _wordpress_i18n.__)("Name");
titleElement = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => setAttributes({ showPrefix: true }),
dropdownMenuProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => !showPrefix,
label: (0, _wordpress_i18n.__)("Show post type label"),
onDeselect: () => setAttributes({ showPrefix: true }),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Show post type label"),
onChange: () => setAttributes({ showPrefix: !showPrefix }),
checked: showPrefix
})
})
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagName, {
...blockProps,
children: title
})] });
}
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "block",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.HeadingLevelDropdown, {
value: level,
options: levelOptions,
onChange: (newLevel) => setAttributes({ level: newLevel })
})
}), titleElement] });
}
exports.default = QueryTitleEdit;
//# sourceMappingURL=edit.cjs.map