Нет описания

imageCommand.tsx 962B

12345678910111213141516171819202122232425262728
  1. import * as React from "react";
  2. import {Command} from "../types";
  3. import {insertText} from "../util/MarkdownUtil";
  4. import {buildNewDraftState, getMarkdownStateFromDraftState} from "../util/DraftUtil";
  5. export const imageCommand: Command = {
  6. buttonContentBuilder: ({ iconProvider }) => iconProvider("image"),
  7. buttonProps: { "aria-label": "Insert a picture" },
  8. execute: (state) => {
  9. const {text, selection} = getMarkdownStateFromDraftState(state);
  10. const {newText, insertionLength} = insertText(text, "![", selection.start);
  11. const finalText = insertText(newText, "](image-url)", selection.end + insertionLength).newText;
  12. return buildNewDraftState(
  13. state,
  14. {
  15. text: finalText,
  16. selection: {
  17. start: selection.start + insertionLength,
  18. end: selection.end + insertionLength,
  19. },
  20. },
  21. );
  22. },
  23. };