@wordpress/block-library
Version:
Block library for the WordPress editor.
77 lines (76 loc) • 4.09 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_data = require("@wordpress/data");
let _wordpress_components = require("@wordpress/components");
let _wordpress_element = require("@wordpress/element");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_icons = require("@wordpress/icons");
let __convert_to_blocks_button_jsx = require("./convert-to-blocks-button.cjs");
__convert_to_blocks_button_jsx = __toESM(__convert_to_blocks_button_jsx);
let __modal_jsx = require("./modal.cjs");
__modal_jsx = __toESM(__modal_jsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/freeform/edit.jsx
function FreeformEdit({ attributes, setAttributes, clientId }) {
const { content } = attributes;
const [isOpen, setOpen] = (0, _wordpress_element.useState)(false);
const editButtonRef = (0, _wordpress_element.useRef)(null);
const canRemove = (0, _wordpress_data.useSelect)((select) => select(_wordpress_block_editor.store).canRemoveBlock(clientId), [clientId]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
canRemove && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__convert_to_blocks_button_jsx.default, { clientId }) }) }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
ref: editButtonRef,
onClick: () => setOpen(true),
children: (0, _wordpress_i18n.__)("Edit")
}) }) }),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...(0, _wordpress_block_editor.useBlockProps)(),
children: [content ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_element.RawHTML, { children: content }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Placeholder, {
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockIcon, { icon: _wordpress_icons.classic }),
label: (0, _wordpress_i18n.__)("Classic"),
instructions: (0, _wordpress_i18n.__)("Use the classic editor to add content."),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
__next40pxDefaultSize: true,
variant: "primary",
onClick: () => setOpen(true),
children: (0, _wordpress_i18n.__)("Edit contents")
})
}), isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__modal_jsx.default, {
clientId,
content,
onClose: () => {
setOpen(false);
if (editButtonRef.current) editButtonRef.current.focus();
},
onChange: (newContent) => setAttributes({ content: newContent })
})]
})
] });
}
exports.default = FreeformEdit;
//# sourceMappingURL=edit.cjs.map