2022-11-25 14:34:55 +00:00
|
|
|
import { $generateHtmlFromNodes, $generateNodesFromDOM } from "@lexical/html";
|
|
|
|
import { $isLinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
|
|
|
|
import {
|
2023-01-26 22:51:03 +00:00
|
|
|
$isListNode,
|
2022-11-25 14:34:55 +00:00
|
|
|
INSERT_ORDERED_LIST_COMMAND,
|
|
|
|
INSERT_UNORDERED_LIST_COMMAND,
|
|
|
|
ListNode,
|
2023-01-26 22:51:03 +00:00
|
|
|
REMOVE_LIST_COMMAND,
|
2022-11-25 14:34:55 +00:00
|
|
|
} from "@lexical/list";
|
|
|
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
|
|
import { $createHeadingNode, $isHeadingNode } from "@lexical/rich-text";
|
2023-01-26 22:51:03 +00:00
|
|
|
import { $isAtNodeEnd, $wrapNodes } from "@lexical/selection";
|
2022-11-25 14:34:55 +00:00
|
|
|
import { $getNearestNodeOfType, mergeRegister } from "@lexical/utils";
|
2023-01-09 14:15:11 +00:00
|
|
|
import classNames from "classnames";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { EditorState, GridSelection, LexicalEditor, NodeSelection, RangeSelection } from "lexical";
|
2022-11-25 14:34:55 +00:00
|
|
|
import {
|
|
|
|
$createParagraphNode,
|
|
|
|
$getRoot,
|
2023-01-26 22:51:03 +00:00
|
|
|
$getSelection,
|
2022-11-25 14:34:55 +00:00
|
|
|
$insertNodes,
|
2023-01-26 22:51:03 +00:00
|
|
|
$isRangeSelection,
|
|
|
|
FORMAT_TEXT_COMMAND,
|
|
|
|
SELECTION_CHANGE_COMMAND,
|
2022-11-25 14:34:55 +00:00
|
|
|
} from "lexical";
|
|
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
|
import { createPortal } from "react-dom";
|
|
|
|
|
2023-01-26 22:51:03 +00:00
|
|
|
import { Button } from "../../button";
|
|
|
|
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../../form/dropdown";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Bold, ChevronDown, Italic, Link } from "../../icon";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { TextEditorProps } from "../Editor";
|
2023-01-09 14:15:11 +00:00
|
|
|
import { AddVariablesDropdown } from "./AddVariablesDropdown";
|
2022-11-25 14:34:55 +00:00
|
|
|
|
|
|
|
const LowPriority = 1;
|
|
|
|
|
|
|
|
const supportedBlockTypes = new Set(["paragraph", "h1", "h2", "ul", "ol"]);
|
|
|
|
|
|
|
|
interface BlockType {
|
|
|
|
[key: string]: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const blockTypeToBlockName: BlockType = {
|
|
|
|
paragraph: "Normal",
|
2023-01-09 14:15:11 +00:00
|
|
|
ol: "Numbered List",
|
2022-11-25 14:34:55 +00:00
|
|
|
ul: "Bulleted List",
|
2023-01-09 14:15:11 +00:00
|
|
|
h1: "Large Heading",
|
|
|
|
h2: "Small Heading",
|
2022-11-25 14:34:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function positionEditorElement(editor: HTMLInputElement, rect: DOMRect | null) {
|
|
|
|
if (rect === null) {
|
|
|
|
editor.style.opacity = "0";
|
|
|
|
editor.style.top = "-1000px";
|
|
|
|
editor.style.left = "-1000px";
|
|
|
|
} else {
|
|
|
|
editor.style.opacity = "1";
|
|
|
|
editor.style.top = `${rect.top + rect.height + window.pageYOffset + 10}px`;
|
|
|
|
editor.style.left = `${rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2}px`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FloatingLinkEditor({ editor }: { editor: LexicalEditor }) {
|
|
|
|
const editorRef = useRef<HTMLInputElement>(null);
|
|
|
|
const mouseDownRef = useRef(false);
|
|
|
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
|
|
const [linkUrl, setLinkUrl] = useState("");
|
2023-04-26 16:36:04 +00:00
|
|
|
const [isEditMode, setEditMode] = useState(true);
|
2022-11-25 14:34:55 +00:00
|
|
|
const [lastSelection, setLastSelection] = useState<RangeSelection | NodeSelection | GridSelection | null>(
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
const updateLinkEditor = useCallback(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
const node = getSelectedNode(selection);
|
|
|
|
const parent = node.getParent();
|
|
|
|
if ($isLinkNode(parent)) {
|
|
|
|
setLinkUrl(parent.getURL());
|
|
|
|
} else if ($isLinkNode(node)) {
|
|
|
|
setLinkUrl(node.getURL());
|
|
|
|
} else {
|
|
|
|
setLinkUrl("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const editorElem = editorRef.current;
|
|
|
|
const nativeSelection = window.getSelection();
|
|
|
|
const activeElement = document.activeElement;
|
|
|
|
|
|
|
|
if (editorElem === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rootElement = editor.getRootElement();
|
|
|
|
if (
|
|
|
|
selection !== null &&
|
|
|
|
!nativeSelection?.isCollapsed &&
|
|
|
|
rootElement !== null &&
|
|
|
|
rootElement.contains(nativeSelection?.anchorNode || null)
|
|
|
|
) {
|
|
|
|
const domRange = nativeSelection?.getRangeAt(0);
|
|
|
|
let rect: DOMRect | undefined;
|
|
|
|
if (nativeSelection?.anchorNode === rootElement) {
|
|
|
|
let inner: Element = rootElement;
|
|
|
|
while (inner.firstElementChild != null) {
|
|
|
|
inner = inner.firstElementChild;
|
|
|
|
}
|
|
|
|
rect = inner.getBoundingClientRect();
|
|
|
|
} else {
|
|
|
|
rect = domRange?.getBoundingClientRect();
|
|
|
|
}
|
|
|
|
if (!mouseDownRef.current) {
|
|
|
|
positionEditorElement(editorElem, rect || null);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLastSelection(selection);
|
|
|
|
} else if (!activeElement || activeElement.className !== "link-input") {
|
|
|
|
positionEditorElement(editorElem, null);
|
|
|
|
setLastSelection(null);
|
|
|
|
setEditMode(false);
|
|
|
|
setLinkUrl("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, [editor]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return mergeRegister(
|
|
|
|
editor.registerUpdateListener(({ editorState }: { editorState: EditorState }) => {
|
|
|
|
editorState.read(() => {
|
|
|
|
updateLinkEditor();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
editor.registerCommand(
|
|
|
|
SELECTION_CHANGE_COMMAND,
|
|
|
|
() => {
|
|
|
|
updateLinkEditor();
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
LowPriority
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}, [editor, updateLinkEditor]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
editor.getEditorState().read(() => {
|
|
|
|
updateLinkEditor();
|
|
|
|
});
|
|
|
|
}, [editor, updateLinkEditor]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isEditMode && inputRef.current) {
|
|
|
|
inputRef.current.focus();
|
|
|
|
}
|
|
|
|
}, [isEditMode]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div ref={editorRef} className="link-editor">
|
|
|
|
{isEditMode ? (
|
|
|
|
<input
|
|
|
|
ref={inputRef}
|
|
|
|
className="link-input"
|
|
|
|
value={linkUrl}
|
|
|
|
onChange={(event) => {
|
|
|
|
setLinkUrl(event.target.value);
|
|
|
|
}}
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
if (event.key === "Enter") {
|
|
|
|
event.preventDefault();
|
|
|
|
if (lastSelection !== null) {
|
|
|
|
if (linkUrl !== "") {
|
|
|
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
|
|
|
|
}
|
|
|
|
setEditMode(false);
|
|
|
|
}
|
|
|
|
} else if (event.key === "Escape") {
|
|
|
|
event.preventDefault();
|
|
|
|
setEditMode(false);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="link-input">
|
|
|
|
<a href={linkUrl} target="_blank" rel="noopener noreferrer">
|
|
|
|
{linkUrl}
|
|
|
|
</a>
|
|
|
|
<div
|
|
|
|
className="link-edit"
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onMouseDown={(event) => event.preventDefault()}
|
|
|
|
onClick={() => {
|
|
|
|
setEditMode(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedNode(selection: RangeSelection) {
|
|
|
|
const anchor = selection.anchor;
|
|
|
|
const focus = selection.focus;
|
|
|
|
const anchorNode = selection.anchor.getNode();
|
|
|
|
const focusNode = selection.focus.getNode();
|
|
|
|
if (anchorNode === focusNode) {
|
|
|
|
return anchorNode;
|
|
|
|
}
|
|
|
|
const isBackward = selection.isBackward();
|
|
|
|
if (isBackward) {
|
|
|
|
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
|
|
} else {
|
|
|
|
return $isAtNodeEnd(anchor) ? focusNode : anchorNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-09 14:15:11 +00:00
|
|
|
export default function ToolbarPlugin(props: TextEditorProps) {
|
|
|
|
const [editor] = useLexicalComposerContext();
|
|
|
|
const toolbarRef = useRef(null);
|
|
|
|
const [blockType, setBlockType] = useState("paragraph");
|
|
|
|
const [isLink, setIsLink] = useState(false);
|
|
|
|
const [isBold, setIsBold] = useState(false);
|
|
|
|
const [isItalic, setIsItalic] = useState(false);
|
2022-11-25 14:34:55 +00:00
|
|
|
|
|
|
|
const formatParagraph = () => {
|
|
|
|
if (blockType !== "paragraph") {
|
|
|
|
editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
$wrapNodes(selection, () => $createParagraphNode());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const formatLargeHeading = () => {
|
|
|
|
if (blockType !== "h1") {
|
|
|
|
editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
$wrapNodes(selection, () => $createHeadingNode("h1"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const formatSmallHeading = () => {
|
|
|
|
if (blockType !== "h2") {
|
|
|
|
editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
$wrapNodes(selection, () => $createHeadingNode("h2"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const formatBulletList = () => {
|
|
|
|
if (blockType !== "ul") {
|
|
|
|
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
|
|
} else {
|
|
|
|
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const formatNumberedList = () => {
|
|
|
|
if (blockType !== "ol") {
|
|
|
|
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
|
|
} else {
|
|
|
|
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-09 14:15:11 +00:00
|
|
|
const format = (newBlockType: string) => {
|
|
|
|
switch (newBlockType) {
|
|
|
|
case "paragraph":
|
|
|
|
formatParagraph();
|
|
|
|
break;
|
|
|
|
case "ul":
|
|
|
|
formatBulletList();
|
|
|
|
break;
|
|
|
|
case "ol":
|
|
|
|
formatNumberedList();
|
|
|
|
break;
|
|
|
|
case "h1":
|
|
|
|
formatLargeHeading();
|
|
|
|
break;
|
|
|
|
case "h2":
|
|
|
|
formatSmallHeading();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2022-11-25 14:34:55 +00:00
|
|
|
|
|
|
|
const updateToolbar = useCallback(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
const anchorNode = selection.anchor.getNode();
|
|
|
|
const element = anchorNode.getKey() === "root" ? anchorNode : anchorNode.getTopLevelElementOrThrow();
|
|
|
|
const elementKey = element.getKey();
|
|
|
|
const elementDOM = editor.getElementByKey(elementKey);
|
|
|
|
if (elementDOM !== null) {
|
|
|
|
if ($isListNode(element)) {
|
|
|
|
const parentList = $getNearestNodeOfType(anchorNode, ListNode);
|
|
|
|
const type = parentList ? parentList.getTag() : element.getTag();
|
|
|
|
setBlockType(type);
|
|
|
|
} else {
|
|
|
|
const type = $isHeadingNode(element) ? element.getTag() : element.getType();
|
|
|
|
setBlockType(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setIsBold(selection.hasFormat("bold"));
|
|
|
|
setIsItalic(selection.hasFormat("italic"));
|
|
|
|
|
|
|
|
const node = getSelectedNode(selection);
|
|
|
|
const parent = node.getParent();
|
|
|
|
if ($isLinkNode(parent) || $isLinkNode(node)) {
|
|
|
|
setIsLink(true);
|
|
|
|
} else {
|
|
|
|
setIsLink(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [editor]);
|
|
|
|
|
|
|
|
const addVariable = (variable: string) => {
|
|
|
|
editor.update(() => {
|
|
|
|
const selection = $getSelection();
|
|
|
|
if ($isRangeSelection(selection)) {
|
|
|
|
editor.update(() => {
|
|
|
|
const formatedVariable = `{${variable.toUpperCase().replace(/ /g, "_")}}`;
|
|
|
|
selection?.insertRawText(formatedVariable);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-04-18 10:08:09 +00:00
|
|
|
if (!props.firstRender) {
|
|
|
|
editor.update(() => {
|
|
|
|
const root = $getRoot();
|
|
|
|
if (root) {
|
|
|
|
editor.update(() => {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
// Create a new TextNode
|
|
|
|
const dom = parser.parseFromString(props.getText(), "text/html");
|
|
|
|
|
|
|
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
|
|
const paragraph = $createParagraphNode();
|
|
|
|
root.clear().append(paragraph);
|
|
|
|
paragraph.select();
|
|
|
|
$insertNodes(nodes);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [props.updateTemplate]);
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (props.setFirstRender) {
|
|
|
|
props.setFirstRender(false);
|
|
|
|
editor.update(() => {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const dom = parser.parseFromString(props.getText(), "text/html");
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
const nodes = $generateNodesFromDOM(editor, dom);
|
2022-11-25 14:34:55 +00:00
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
$getRoot().select();
|
|
|
|
$insertNodes(nodes);
|
|
|
|
|
|
|
|
editor.registerUpdateListener(({ editorState, prevEditorState }) => {
|
|
|
|
editorState.read(() => {
|
|
|
|
const textInHtml = $generateHtmlFromNodes(editor).replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
props.setText(textInHtml);
|
|
|
|
});
|
|
|
|
if (!prevEditorState._selection) editor.blur();
|
2022-11-25 14:34:55 +00:00
|
|
|
});
|
|
|
|
});
|
2023-04-18 10:08:09 +00:00
|
|
|
}
|
2022-11-25 14:34:55 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return mergeRegister(
|
|
|
|
editor.registerUpdateListener(({ editorState }) => {
|
|
|
|
editorState.read(() => {
|
|
|
|
updateToolbar();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
editor.registerCommand(
|
|
|
|
SELECTION_CHANGE_COMMAND,
|
|
|
|
(_payload, newEditor) => {
|
|
|
|
updateToolbar();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
LowPriority
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}, [editor, updateToolbar]);
|
|
|
|
|
|
|
|
const insertLink = useCallback(() => {
|
|
|
|
if (!isLink) {
|
|
|
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, "https://");
|
|
|
|
} else {
|
|
|
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
|
|
}
|
|
|
|
}, [editor, isLink]);
|
2023-04-13 02:10:23 +00:00
|
|
|
|
|
|
|
if (!props.editable) return <></>;
|
2022-11-25 14:34:55 +00:00
|
|
|
return (
|
|
|
|
<div className="toolbar flex" ref={toolbarRef}>
|
|
|
|
<>
|
2023-01-09 14:15:11 +00:00
|
|
|
{!props.excludedToolbarItems?.includes("blockType") && supportedBlockTypes.has(blockType) && (
|
2022-11-25 14:34:55 +00:00
|
|
|
<>
|
2023-01-09 14:15:11 +00:00
|
|
|
<Dropdown>
|
2023-04-05 18:14:46 +00:00
|
|
|
<DropdownMenuTrigger className="text-subtle">
|
2023-01-09 14:15:11 +00:00
|
|
|
<>
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className={"icon" + blockType} />
|
|
|
|
<span className="text text-default hidden sm:flex">
|
2023-01-09 14:15:11 +00:00
|
|
|
{blockTypeToBlockName[blockType as keyof BlockType]}
|
|
|
|
</span>
|
2023-04-12 15:26:31 +00:00
|
|
|
<ChevronDown className="text-default ml-2 h-4 w-4" />
|
2023-01-09 14:15:11 +00:00
|
|
|
</>
|
|
|
|
</DropdownMenuTrigger>
|
2023-04-05 18:14:46 +00:00
|
|
|
<DropdownMenuContent align="start">
|
2023-01-09 14:15:11 +00:00
|
|
|
{Object.keys(blockTypeToBlockName).map((key) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuItem key={key} className="outline-none hover:ring-0 focus:ring-0">
|
|
|
|
<Button
|
|
|
|
color="minimal"
|
|
|
|
type="button"
|
|
|
|
onClick={() => format(key)}
|
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"w-full rounded-none focus:ring-0",
|
|
|
|
blockType === key ? "bg-subtle w-full" : ""
|
2023-01-09 14:15:11 +00:00
|
|
|
)}>
|
|
|
|
<>
|
|
|
|
<span className={"icon block-type " + key} />
|
|
|
|
<span>{blockTypeToBlockName[key]}</span>
|
|
|
|
</>
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
2022-11-25 14:34:55 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<>
|
2023-01-09 14:15:11 +00:00
|
|
|
{!props.excludedToolbarItems?.includes("bold") && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<Button
|
|
|
|
color="minimal"
|
|
|
|
variant="icon"
|
2023-01-09 14:15:11 +00:00
|
|
|
type="button"
|
2023-04-12 15:26:31 +00:00
|
|
|
StartIcon={Bold}
|
2023-01-09 14:15:11 +00:00
|
|
|
onClick={() => {
|
2022-11-25 14:34:55 +00:00
|
|
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
2023-01-09 14:15:11 +00:00
|
|
|
}}
|
2023-04-05 18:14:46 +00:00
|
|
|
className={isBold ? "bg-subtle" : ""}
|
|
|
|
/>
|
2023-01-09 14:15:11 +00:00
|
|
|
)}
|
|
|
|
{!props.excludedToolbarItems?.includes("italic") && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<Button
|
|
|
|
color="minimal"
|
|
|
|
variant="icon"
|
2023-01-09 14:15:11 +00:00
|
|
|
type="button"
|
2023-04-12 15:26:31 +00:00
|
|
|
StartIcon={Italic}
|
2023-01-09 14:15:11 +00:00
|
|
|
onClick={() => {
|
|
|
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
|
|
}}
|
2023-04-05 18:14:46 +00:00
|
|
|
className={isItalic ? "bg-subtle" : ""}
|
|
|
|
/>
|
2023-01-09 14:15:11 +00:00
|
|
|
)}
|
|
|
|
{!props.excludedToolbarItems?.includes("link") && (
|
|
|
|
<>
|
2023-04-05 18:14:46 +00:00
|
|
|
<Button
|
|
|
|
color="minimal"
|
|
|
|
variant="icon"
|
2023-01-09 14:15:11 +00:00
|
|
|
type="button"
|
2023-04-12 15:26:31 +00:00
|
|
|
StartIcon={Link}
|
2023-01-09 14:15:11 +00:00
|
|
|
onClick={insertLink}
|
2023-04-05 18:14:46 +00:00
|
|
|
className={isLink ? "bg-subtle" : ""}
|
|
|
|
/>
|
2023-01-09 14:15:11 +00:00
|
|
|
{isLink && createPortal(<FloatingLinkEditor editor={editor} />, document.body)}{" "}
|
|
|
|
</>
|
|
|
|
)}
|
2022-11-25 14:34:55 +00:00
|
|
|
</>
|
2023-01-09 14:15:11 +00:00
|
|
|
{props.variables && (
|
|
|
|
<div className="ml-auto">
|
|
|
|
<AddVariablesDropdown
|
|
|
|
addVariable={addVariable}
|
|
|
|
isTextEditor={true}
|
|
|
|
variables={props.variables || []}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-25 14:34:55 +00:00
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|