UNPKG

@wordpress/block-library

Version:
177 lines (176 loc) • 7.6 kB
"use strict"; 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_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_data = require("@wordpress/data"); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_icons = require("@wordpress/icons"); let _wordpress_dom = require("@wordpress/dom"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/home-link/edit.jsx const preventDefault = (event) => event.preventDefault(); function HomeEdit({ attributes, setAttributes, context }) { const { homeUrl, onNavigateToEntityRecord, frontPageId, frontPageTemplateId } = (0, _wordpress_data.useSelect)((select) => { const { getEntityRecord, getDefaultTemplateId, canUser } = select(_wordpress_core_data.store); const baseUrl = getEntityRecord("root", "__unstableBase")?.home; const site = canUser("read", { kind: "root", name: "site" }) ? getEntityRecord("root", "site") : null; const resolvedFrontPageId = site?.show_on_front === "page" ? site?.page_on_front : null; const resolvedFrontPageTemplateId = !resolvedFrontPageId ? getDefaultTemplateId({ slug: "front-page" }) : null; return { homeUrl: baseUrl, onNavigateToEntityRecord: select(_wordpress_block_editor.store).getSettings().onNavigateToEntityRecord, frontPageId: resolvedFrontPageId, frontPageTemplateId: resolvedFrontPageTemplateId }; }, []); const { textColor, backgroundColor, style } = context; const { label, opensInNewTab, description } = attributes; const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); const blockProps = (0, _wordpress_block_editor.useBlockProps)({ className: (0, clsx.default)("wp-block-navigation-item", { "has-text-color": !!textColor || !!style?.color?.text, [`has-${textColor}-color`]: !!textColor, "has-background": !!backgroundColor || !!style?.color?.background, [`has-${backgroundColor}-background-color`]: !!backgroundColor }), style: { color: style?.color?.text, backgroundColor: style?.color?.background } }); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { group: "content", children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToolsPanel, { label: (0, _wordpress_i18n.__)("Settings"), resetAll: () => { setAttributes({ label: "", opensInNewTab: false, description: "" }); }, dropdownMenuProps, children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { hasValue: () => !!label, label: (0, _wordpress_i18n.__)("Text"), onDeselect: () => setAttributes({ label: "" }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.TextControl, { label: (0, _wordpress_i18n.__)("Text"), value: label ? (0, _wordpress_dom.__unstableStripHTML)(label) : "", onChange: (labelValue) => { setAttributes({ label: labelValue }); }, autoComplete: "off" }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { hasValue: () => !!opensInNewTab, label: (0, _wordpress_i18n.__)("Open in new tab"), onDeselect: () => setAttributes({ opensInNewTab: false }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.CheckboxControl, { label: (0, _wordpress_i18n.__)("Open in new tab"), checked: opensInNewTab, onChange: (value) => setAttributes({ opensInNewTab: value }) }) }), onNavigateToEntityRecord && (frontPageId || frontPageTemplateId) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { variant: "secondary", onClick: () => { if (frontPageId) onNavigateToEntityRecord({ postId: frontPageId, postType: "page" }); else onNavigateToEntityRecord({ postId: frontPageTemplateId, postType: "wp_template" }); }, __next40pxDefaultSize: true, className: "navigation-link-to__action-button", children: (0, _wordpress_i18n.__)("Edit") }), homeUrl && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { variant: "secondary", href: homeUrl, target: "_blank", icon: _wordpress_icons.external, iconPosition: "right", __next40pxDefaultSize: true, className: "navigation-link-to__action-button", children: (0, _wordpress_i18n.__)("View") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { hasValue: () => !!description, label: (0, _wordpress_i18n.__)("Description"), onDeselect: () => setAttributes({ description: "" }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.TextareaControl, { label: (0, _wordpress_i18n.__)("Description"), value: description || "", onChange: (descriptionValue) => { setAttributes({ description: descriptionValue }); }, help: (0, _wordpress_i18n.__)("The description will be displayed in the menu if the current theme supports it.") }) }) ] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...blockProps, children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", { className: "wp-block-home-link__content wp-block-navigation-item__content", href: homeUrl, onClick: preventDefault, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, { identifier: "label", className: "wp-block-home-link__label", value: label ?? (0, _wordpress_i18n.__)("Home"), onChange: (labelValue) => { setAttributes({ label: labelValue }); }, "aria-label": (0, _wordpress_i18n.__)("Home link text"), placeholder: (0, _wordpress_i18n.__)("Add label…"), withoutInteractiveFormatting: true }), description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "wp-block-navigation-item__description", children: description })] }) })] }); } exports.default = HomeEdit; //# sourceMappingURL=edit.cjs.map