@wordpress/block-library
Version:
Block library for the WordPress editor.
293 lines (291 loc) • 11.2 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-library/src/post-navigation-link/edit.js
var edit_exports = {};
__export(edit_exports, {
default: () => PostNavigationLinkEdit
});
module.exports = __toCommonJS(edit_exports);
var import_clsx = __toESM(require("clsx"));
var import_components = require("@wordpress/components");
var import_block_editor = require("@wordpress/block-editor");
var import_i18n = require("@wordpress/i18n");
var import_data = require("@wordpress/data");
var import_core_data = require("@wordpress/core-data");
var import_hooks = require("../utils/hooks");
var import_jsx_runtime = require("react/jsx-runtime");
function PostNavigationLinkEdit({
context: { postType },
attributes: {
type,
label,
showTitle,
textAlign,
linkLabel,
arrow,
taxonomy
},
setAttributes
}) {
const blockEditingMode = (0, import_block_editor.useBlockEditingMode)();
const showControls = blockEditingMode === "default";
const isNext = type === "next";
let placeholder = isNext ? (0, import_i18n.__)("Next") : (0, import_i18n.__)("Previous");
const arrowMap = {
none: "",
arrow: isNext ? "\u2192" : "\u2190",
chevron: isNext ? "\xBB" : "\xAB"
};
const displayArrow = arrowMap[arrow];
if (showTitle) {
placeholder = isNext ? (
/* translators: Label before for next and previous post. There is a space after the colon. */
(0, import_i18n.__)("Next: ")
) : (
/* translators: Label before for next and previous post. There is a space after the colon. */
(0, import_i18n.__)("Previous: ")
);
}
const ariaLabel = isNext ? (0, import_i18n.__)("Next post") : (0, import_i18n.__)("Previous post");
const blockProps = (0, import_block_editor.useBlockProps)({
className: (0, import_clsx.default)({
[`has-text-align-${textAlign}`]: textAlign
})
});
const taxonomies = (0, import_data.useSelect)(
(select) => {
const { getTaxonomies } = select(import_core_data.store);
const filteredTaxonomies = getTaxonomies({
type: postType,
per_page: -1
});
return filteredTaxonomies;
},
[postType]
);
const getTaxonomyOptions = () => {
const selectOption = {
label: (0, import_i18n.__)("Unfiltered"),
value: ""
};
const taxonomyOptions = (taxonomies ?? []).filter(({ visibility }) => !!visibility?.publicly_queryable).map((item) => {
return {
value: item.slug,
label: item.name
};
});
return [selectOption, ...taxonomyOptions];
};
const dropdownMenuProps = (0, import_hooks.useToolsPanelDropdownMenuProps)();
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
import_components.__experimentalToolsPanel,
{
label: (0, import_i18n.__)("Settings"),
resetAll: () => {
setAttributes({
showTitle: false,
linkLabel: false,
arrow: "none"
});
},
dropdownMenuProps,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToolsPanelItem,
{
label: (0, import_i18n.__)("Display the title as a link"),
isShownByDefault: true,
hasValue: () => showTitle,
onDeselect: () => setAttributes({ showTitle: false }),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.ToggleControl,
{
__nextHasNoMarginBottom: true,
label: (0, import_i18n.__)("Display the title as a link"),
help: (0, import_i18n.__)(
"If you have entered a custom label, it will be prepended before the title."
),
checked: !!showTitle,
onChange: () => setAttributes({
showTitle: !showTitle
})
}
)
}
),
showTitle && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToolsPanelItem,
{
label: (0, import_i18n.__)(
"Include the label as part of the link"
),
isShownByDefault: true,
hasValue: () => !!linkLabel,
onDeselect: () => setAttributes({ linkLabel: false }),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.ToggleControl,
{
__nextHasNoMarginBottom: true,
label: (0, import_i18n.__)(
"Include the label as part of the link"
),
checked: !!linkLabel,
onChange: () => setAttributes({
linkLabel: !linkLabel
})
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToolsPanelItem,
{
label: (0, import_i18n.__)("Arrow"),
isShownByDefault: true,
hasValue: () => arrow !== "none",
onDeselect: () => setAttributes({ arrow: "none" }),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
import_components.__experimentalToggleGroupControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: (0, import_i18n.__)("Arrow"),
value: arrow,
onChange: (value) => {
setAttributes({ arrow: value });
},
help: (0, import_i18n.__)(
"A decorative arrow for the next and previous link."
),
isBlock: true,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToggleGroupControlOption,
{
value: "none",
label: (0, import_i18n._x)(
"None",
"Arrow option for Next/Previous link"
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToggleGroupControlOption,
{
value: "arrow",
label: (0, import_i18n._x)(
"Arrow",
"Arrow option for Next/Previous link"
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalToggleGroupControlOption,
{
value: "chevron",
label: (0, import_i18n._x)(
"Chevron",
"Arrow option for Next/Previous link"
)
}
)
]
}
)
}
)
]
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.InspectorControls, { group: "advanced", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.SelectControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: (0, import_i18n.__)("Filter by taxonomy"),
value: taxonomy,
options: getTaxonomyOptions(),
onChange: (value) => setAttributes({
taxonomy: value
}),
help: (0, import_i18n.__)(
"Only link to posts that have the same taxonomy terms as the current post. For example the same tags or categories."
)
}
) }),
showControls && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockControls, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_block_editor.AlignmentToolbar,
{
value: textAlign,
onChange: (nextAlign) => {
setAttributes({ textAlign: nextAlign });
}
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...blockProps, children: [
!isNext && displayArrow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"span",
{
className: `wp-block-post-navigation-link__arrow-previous is-arrow-${arrow}`,
children: displayArrow
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_block_editor.RichText,
{
tagName: "a",
identifier: "label",
"aria-label": ariaLabel,
placeholder,
value: label,
withoutInteractiveFormatting: true,
onChange: (newLabel) => setAttributes({ label: newLabel })
}
),
showTitle && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"a",
{
href: "#post-navigation-pseudo-link",
onClick: (event) => event.preventDefault(),
children: (0, import_i18n.__)("An example title")
}
),
isNext && displayArrow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"span",
{
className: `wp-block-post-navigation-link__arrow-next is-arrow-${arrow}`,
"aria-hidden": true,
children: displayArrow
}
)
] })
] });
}
//# sourceMappingURL=edit.js.map