UNPKG

mui-tiptap

Version:

A Material-UI (MUI) styled WYSIWYG rich text editor, using Tiptap

43 lines (42 loc) 2.13 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const AddPhotoAlternate_1 = __importDefault(require("@mui/icons-material/AddPhotoAlternate")); const context_1 = require("../context"); const MenuButton_1 = __importDefault(require("./MenuButton")); /** * Render a button for adding an image to the editor content. You must provide * your own `onClick` prop in order to specify *how* the image is added. For * instance, you might open a popup for the user to provide an image URL, or you * might trigger a file upload via file input dialog. * * Once the image URL is ready (after the user has filled it out or after an * upload has completed), you can typically use something like: * * editor.chain().focus().setImage({ src: url }).run() * * See Tiptap's example here https://tiptap.dev/api/nodes/image. */ function MenuButtonAddImage(_a) { var props = __rest(_a, []); const editor = (0, context_1.useRichTextEditorContext)(); return ((0, jsx_runtime_1.jsx)(MenuButton_1.default, Object.assign({ tooltipLabel: "Insert image", IconComponent: AddPhotoAlternate_1.default, disabled: !(editor === null || editor === void 0 ? void 0 : editor.isEditable) || // We can use any URL here for testing `can` (to see if an image can be // added to the editor currently) !editor.can().setImage({ src: "http://example.com" }) }, props))); } exports.default = MenuButtonAddImage;