@wordpress/block-library
Version:
Block library for the WordPress editor.
190 lines (189 loc) • 8.62 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 clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_components = require("@wordpress/components");
let _wordpress_ui = require("@wordpress/ui");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_data = require("@wordpress/data");
let _wordpress_core_data = require("@wordpress/core-data");
let ___utils_hooks_js = require("../utils/hooks.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/post-navigation-link/edit.jsx
function PostNavigationLinkEdit({ context: { postType }, attributes, setAttributes }) {
const { type, label, showTitle, linkLabel, arrow, taxonomy } = attributes;
const isNext = type === "next";
let placeholder = isNext ? (0, _wordpress_i18n.__)("Next") : (0, _wordpress_i18n.__)("Previous");
const displayArrow = {
none: "",
arrow: isNext ? "→" : "←",
chevron: isNext ? "»" : "«"
}[arrow];
if (showTitle) placeholder = isNext ? (0, _wordpress_i18n.__)("Next: ") : (0, _wordpress_i18n.__)("Previous: ");
const ariaLabel = isNext ? (0, _wordpress_i18n.__)("Next post") : (0, _wordpress_i18n.__)("Previous post");
const backgroundProps = (0, _wordpress_block_editor.useBackgroundProps)(attributes);
const borderProps = (0, _wordpress_block_editor.__experimentalUseBorderProps)(attributes);
const dimensionsProps = (0, _wordpress_block_editor.__experimentalGetDimensionsClassesAndStyles)(attributes);
const shadowProps = (0, _wordpress_block_editor.__experimentalGetShadowClassesAndStyles)(attributes);
const spacingProps = (0, _wordpress_block_editor.__experimentalGetSpacingClassesAndStyles)(attributes);
const blockProps = (0, _wordpress_block_editor.useBlockProps)({
className: (0, clsx.default)(backgroundProps.className, borderProps.className),
style: {
...backgroundProps.style,
...borderProps.style,
...dimensionsProps.style,
...shadowProps.style,
...spacingProps.style
}
});
const taxonomies = (0, _wordpress_data.useSelect)((select) => {
const { getTaxonomies } = select(_wordpress_core_data.store);
return getTaxonomies({
type: postType,
per_page: -1
});
}, [postType]);
const taxonomyOptions = [{
label: (0, _wordpress_i18n.__)("Unfiltered"),
value: ""
}, ...(taxonomies ?? []).filter(({ visibility }) => !!visibility?.publicly_queryable).map((item) => {
return {
value: item.slug,
label: item.name
};
})];
const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)();
return /* @__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.jsxs)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => {
setAttributes({
showTitle: false,
linkLabel: false,
arrow: "none"
});
},
dropdownMenuProps,
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
label: (0, _wordpress_i18n.__)("Display the title as a link"),
isShownByDefault: true,
hasValue: () => showTitle,
onDeselect: () => setAttributes({ showTitle: false }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Display the title as a link"),
help: (0, _wordpress_i18n.__)("If you have entered a custom label, it will be prepended before the title."),
checked: !!showTitle,
onChange: () => setAttributes({ showTitle: !showTitle })
})
}),
showTitle && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
label: (0, _wordpress_i18n.__)("Include the label as part of the link"),
isShownByDefault: true,
hasValue: () => !!linkLabel,
onDeselect: () => setAttributes({ linkLabel: false }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Include the label as part of the link"),
checked: !!linkLabel,
onChange: () => setAttributes({ linkLabel: !linkLabel })
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
label: (0, _wordpress_i18n.__)("Arrow"),
isShownByDefault: true,
hasValue: () => arrow !== "none",
onDeselect: () => setAttributes({ arrow: "none" }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToggleGroupControl, {
label: (0, _wordpress_i18n.__)("Arrow"),
value: arrow,
onChange: (value) => {
setAttributes({ arrow: value });
},
help: (0, _wordpress_i18n.__)("A decorative arrow for the next and previous link."),
isBlock: true,
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToggleGroupControlOption, {
value: "none",
label: (0, _wordpress_i18n._x)("None", "Arrow option for Next/Previous link")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToggleGroupControlOption, {
value: "arrow",
label: (0, _wordpress_i18n._x)("Arrow", "Arrow option for Next/Previous link")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToggleGroupControlOption, {
value: "chevron",
label: (0, _wordpress_i18n._x)("Chevron", "Arrow option for Next/Previous link")
})
]
})
})
]
}) }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, {
group: "advanced",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.SelectControl, {
label: (0, _wordpress_i18n.__)("Filter by taxonomy"),
items: taxonomyOptions,
itemToStringValue: (item) => `taxonomy:${item.value}`,
value: taxonomyOptions.find((item) => item.value === taxonomy) ?? taxonomyOptions[0],
onValueChange: (item) => item && setAttributes({ taxonomy: item.value }),
description: (0, _wordpress_i18n.__)("Only link to posts that have the same taxonomy terms as the current post. For example the same tags or categories.")
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...blockProps,
children: [
!isNext && displayArrow && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: `wp-block-post-navigation-link__arrow-previous is-arrow-${arrow}`,
children: displayArrow
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, {
tagName: "a",
identifier: "label",
"aria-label": ariaLabel,
placeholder,
value: label,
withoutInteractiveFormatting: true,
onChange: (newLabel) => setAttributes({ label: newLabel })
}),
showTitle && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
href: "#post-navigation-pseudo-link",
onClick: (event) => event.preventDefault(),
children: (0, _wordpress_i18n.__)("An example title")
}),
isNext && displayArrow && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: `wp-block-post-navigation-link__arrow-next is-arrow-${arrow}`,
"aria-hidden": true,
children: displayArrow
})
]
})
] });
}
exports.default = PostNavigationLinkEdit;
//# sourceMappingURL=edit.cjs.map