UNPKG

@wordpress/block-library

Version:
192 lines (191 loc) • 8.7 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 _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_element = require("@wordpress/element"); let _wordpress_data = require("@wordpress/data"); let _wordpress_components = require("@wordpress/components"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_icons = require("@wordpress/icons"); let _wordpress_compose = require("@wordpress/compose"); let ___lock_unlock_ts = require("../lock-unlock.cjs"); let __preview_jsx = require("./preview.cjs"); __preview_jsx = __toESM(__preview_jsx); let __utils_js = require("./utils.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/html/modal.jsx const { Tabs: WCTabs } = (0, ___lock_unlock_ts.unlock)(_wordpress_components.privateApis); const { useNativeUndo } = (0, ___lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis); function HTMLEditModal({ onRequestClose, content, onUpdate }) { const { html, css, js } = (0, __utils_js.parseContent)(content); const [editedHtml, setEditedHtml] = (0, _wordpress_element.useState)(html); const [editedCss, setEditedCss] = (0, _wordpress_element.useState)(css); const [editedJs, setEditedJs] = (0, _wordpress_element.useState)(js); const [isFullscreen, setIsFullscreen] = (0, _wordpress_element.useState)(false); const nativeUndoRef = useNativeUndo(); const isMobileViewport = (0, _wordpress_compose.useViewportMatch)("small", "<"); const { canUserUseUnfilteredHTML } = (0, _wordpress_data.useSelect)((select) => { return { canUserUseUnfilteredHTML: select(_wordpress_block_editor.store).getSettings().__experimentalCanUserUseUnfilteredHTML }; }, []); const hasRestrictedContent = !canUserUseUnfilteredHTML && (css.trim() || js.trim()); const handleUpdate = () => { onUpdate((0, __utils_js.serializeContent)({ html: editedHtml, css: canUserUseUnfilteredHTML ? editedCss : "", js: canUserUseUnfilteredHTML ? editedJs : "" })); }; const handleUpdateAndClose = () => { handleUpdate(); onRequestClose(); }; const toggleFullscreen = () => { setIsFullscreen((prevState) => !prevState); }; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Modal, { title: (0, _wordpress_i18n.__)("Edit HTML"), onRequestClose, className: "block-library-html__modal", size: "large", isDismissible: false, shouldCloseOnClickOutside: false, isFullScreen: isFullscreen, __experimentalHideHeader: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs, { orientation: "horizontal", defaultTabId: "html", children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalVStack, { expanded: true, children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalHStack, { justify: "space-between", className: "block-library-html__modal-header", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(WCTabs.TabList, { children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.Tab, { tabId: "html", children: "HTML" }), canUserUseUnfilteredHTML && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.Tab, { tabId: "css", children: "CSS" }), canUserUseUnfilteredHTML && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.Tab, { tabId: "js", children: (0, _wordpress_i18n.__)("JavaScript") }) ] }) }), !isMobileViewport && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { __next40pxDefaultSize: true, icon: isFullscreen ? _wordpress_icons.square : _wordpress_icons.fullscreen, label: (0, _wordpress_i18n.__)("Enable/disable fullscreen"), onClick: toggleFullscreen, variant: "tertiary" }) })] }), hasRestrictedContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Notice, { status: "warning", isDismissible: false, className: "block-library-html__modal-notice", children: (0, _wordpress_i18n.__)("This block contains CSS or JavaScript that will be removed when you save because you do not have permission to use unfiltered HTML.") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.Flex, { direction: isMobileViewport ? "column" : "row", className: "block-library-html__modal-tabs", align: "stretch", gap: 8, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { ref: nativeUndoRef, className: "block-library-html__modal-content", children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.TabPanel, { tabId: "html", focusable: false, className: "block-library-html__modal-tab", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.PlainText, { value: editedHtml, onChange: setEditedHtml, placeholder: (0, _wordpress_i18n.__)("Write HTML…"), "aria-label": (0, _wordpress_i18n.__)("HTML"), className: "block-library-html__modal-editor" }) }), canUserUseUnfilteredHTML && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.TabPanel, { tabId: "css", focusable: false, className: "block-library-html__modal-tab", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.PlainText, { value: editedCss, onChange: setEditedCss, placeholder: (0, _wordpress_i18n.__)("Write CSS…"), "aria-label": (0, _wordpress_i18n.__)("CSS"), className: "block-library-html__modal-editor" }) }), canUserUseUnfilteredHTML && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WCTabs.TabPanel, { tabId: "js", focusable: false, className: "block-library-html__modal-tab", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.PlainText, { value: editedJs, onChange: setEditedJs, placeholder: (0, _wordpress_i18n.__)("Write JavaScript…"), "aria-label": (0, _wordpress_i18n.__)("JavaScript"), className: "block-library-html__modal-editor" }) }) ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "block-library-html__preview", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__preview_jsx.default, { content: (0, __utils_js.serializeContent)({ html: editedHtml, css: editedCss, js: editedJs }) }) })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalHStack, { alignment: "center", justify: "flex-end", spacing: 4, className: "block-library-html__modal-footer", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { __next40pxDefaultSize: true, variant: "tertiary", onClick: onRequestClose, children: (0, _wordpress_i18n.__)("Cancel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { __next40pxDefaultSize: true, variant: "primary", onClick: handleUpdateAndClose, children: (0, _wordpress_i18n.__)("Update") })] }) ] }) }) }) }); } exports.default = HTMLEditModal; //# sourceMappingURL=modal.cjs.map