UNPKG

@wordpress/block-library

Version:
63 lines (62 loc) • 2.67 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_components = require("@wordpress/components"); let _wordpress_ui = require("@wordpress/ui"); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_data = require("@wordpress/data"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_core_data = require("@wordpress/core-data"); let ___lock_unlock_ts = require("../lock-unlock.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/utils/edit-original-inspector-button.tsx const { PrivateBlockInspectorEditOriginal } = (0, ___lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis); /** * The block inspector's "Edit original" button for a block that renders an * entity, such as a synced pattern or a template part. It opens the entity * for editing, and only shows for users who can edit it, on a block that * isn't locked against editing. * * @param props Component props. * @param props.clientId Client ID of the block that renders the entity. * @param props.postType The entity's post type. * @param props.postId The entity's ID. */ function EditOriginalInspectorButton({ clientId, postType, postId }) { const { canUserEdit, onNavigateToEntityRecord } = (0, _wordpress_data.useSelect)((select) => { const { canEditBlock, getSettings } = select(_wordpress_block_editor.store); return { canUserEdit: canEditBlock(clientId) && (!postId || !!select(_wordpress_core_data.store).canUser("update", { kind: "postType", name: postType, id: postId })), onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord }; }, [ clientId, postType, postId ]); if (!canUserEdit || !onNavigateToEntityRecord) return null; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PrivateBlockInspectorEditOriginal.Fill, { children: ({ clientId: inspectedClientId }) => inspectedClientId === clientId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Stack, { direction: "column", className: "block-editor-block-inspector-edit-contents", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { className: "block-editor-block-inspector-edit-contents__button", __next40pxDefaultSize: true, variant: "secondary", onClick: () => onNavigateToEntityRecord({ postId, postType }), accessibleWhenDisabled: true, disabled: !postId, children: (0, _wordpress_i18n.__)("Edit original") }) }) }); } exports.default = EditOriginalInspectorButton; //# sourceMappingURL=edit-original-inspector-button.cjs.map