@innoviatech/lexical-text-editor 2.0.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -288
- package/dist/components/AlignmentSelectionList.js +19 -0
- package/dist/components/ColorPicker.js +30 -0
- package/dist/components/ContentPreview.js +11 -0
- package/dist/components/DisplayControls.d.ts +16 -0
- package/dist/components/DropdownList.js +18 -0
- package/dist/components/FindReplaceModal.d.ts +11 -0
- package/dist/components/FindReplaceModal.js +120 -0
- package/dist/components/FontSelectionList.d.ts +17 -0
- package/dist/components/FontSelectionList.js +17 -0
- package/dist/components/HeadingSelectionList.js +19 -0
- package/dist/components/ImageComponent.js +111 -0
- package/dist/components/InsertDropdownList.js +17 -0
- package/dist/components/LexicalTextEditor.d.ts +10 -0
- package/dist/components/LexicalTextEditor.js +128 -0
- package/dist/components/LinkModal.js +47 -0
- package/dist/components/Separator.js +4 -0
- package/dist/components/SourceView.d.ts +13 -0
- package/dist/components/SourceView.js +50 -0
- package/dist/components/StatusBar.d.ts +14 -0
- package/dist/components/StatusBar.js +30 -0
- package/dist/components/ToolbarOverflowModal.d.ts +15 -0
- package/dist/components/common/Dialog.js +27 -0
- package/dist/components/common/Popover.d.ts +10 -1
- package/dist/components/common/Popover.js +37 -0
- package/dist/components/common/Tooltip.d.ts +7 -0
- package/dist/components/common/Tooltip.js +20 -0
- package/dist/components/ui/button.js +35 -0
- package/dist/components/ui/command.js +33 -0
- package/dist/components/ui/dialog.js +35 -0
- package/dist/components/ui/input.js +6 -0
- package/dist/components/ui/popover.js +16 -0
- package/dist/components/ui/scroll-area.js +12 -0
- package/dist/components/ui/tooltip.js +16 -0
- package/dist/constants/index.d.ts +23 -1
- package/dist/constants/index.js +224 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -1
- package/dist/lib/utils.js +5 -0
- package/dist/nodes/ExtendedTextNode.js +140 -0
- package/dist/nodes/ImageNode.js +149 -0
- package/dist/nodes/VideoNode.js +80 -0
- package/dist/nodes/YoutubeNode.js +64 -0
- package/dist/plugins/CodeBlockPlugin.d.ts +1 -0
- package/dist/plugins/CodeBlockPlugin.js +88 -0
- package/dist/plugins/ColorPlugin.js +47 -0
- package/dist/plugins/CustomOnChangePlugin.js +33 -0
- package/dist/plugins/FontFamilyPlugin.d.ts +1 -0
- package/dist/plugins/FontFamilyPlugin.js +53 -0
- package/dist/plugins/FontSizePlugin.d.ts +1 -0
- package/dist/plugins/FontSizePlugin.js +48 -0
- package/dist/plugins/ImagePlugin.js +91 -0
- package/dist/plugins/ListPlugin.js +44 -0
- package/dist/plugins/TablePlugin.d.ts +1 -0
- package/dist/plugins/TablePlugin.js +92 -0
- package/dist/plugins/ToolbarPlugin.d.ts +13 -1
- package/dist/plugins/ToolbarPlugin.js +381 -0
- package/dist/plugins/VideoPlugin.js +49 -0
- package/dist/plugins/YoutubePlugin.js +30 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/editor_screenshot.png +0 -0
- package/package.json +11 -4
- package/googlebd703883f12c69e4.html +0 -1
- package/rollup.config.js +0 -55
- package/src/components/AlignmentSelectionList.tsx +0 -61
- package/src/components/ColorPicker.tsx +0 -66
- package/src/components/ContentPreview.tsx +0 -51
- package/src/components/DropdownList.tsx +0 -57
- package/src/components/HeadingSelectionList.tsx +0 -61
- package/src/components/ImageComponent.tsx +0 -206
- package/src/components/InsertDropdownList.tsx +0 -36
- package/src/components/LexicalTextEditor.tsx +0 -119
- package/src/components/LinkModal.tsx +0 -127
- package/src/components/Separator.tsx +0 -7
- package/src/components/common/Dialog.tsx +0 -47
- package/src/components/common/Popover.tsx +0 -87
- package/src/components/common/Tooltip.tsx +0 -43
- package/src/components/ui/button.tsx +0 -58
- package/src/components/ui/command.tsx +0 -183
- package/src/components/ui/dialog.tsx +0 -142
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/popover.tsx +0 -46
- package/src/components/ui/scroll-area.tsx +0 -56
- package/src/components/ui/tooltip.tsx +0 -59
- package/src/constants/index.tsx +0 -177
- package/src/index.ts +0 -6
- package/src/lib/utils.ts +0 -6
- package/src/nodes/ExtendedTextNode.tsx +0 -174
- package/src/nodes/ImageNode.tsx +0 -232
- package/src/nodes/VideoNode.tsx +0 -134
- package/src/nodes/YoutubeNode.tsx +0 -101
- package/src/plugins/ColorPlugin.tsx +0 -85
- package/src/plugins/CustomOnChangePlugin.tsx +0 -50
- package/src/plugins/ImagePlugin.tsx +0 -189
- package/src/plugins/ListPlugin.tsx +0 -58
- package/src/plugins/ToolbarPlugin.tsx +0 -500
- package/src/plugins/VideoPlugin.tsx +0 -100
- package/src/plugins/YoutubePlugin.tsx +0 -83
- package/src/styles/lexical-editor.css +0 -1053
- package/src/types/global.d.ts +0 -34
- package/src/types/other.d.ts +0 -11
- package/src/types/react-icons.d.ts +0 -11
- package/tailwind.config.js +0 -10
- package/tsconfig.json +0 -32
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RICH_ALIGNMENT_OPTIONS } from "../constants/index";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { HiChevronDown } from "react-icons/hi2";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
6
|
+
export function AlignmentSelectionList({ onAction, alignmentSelectionMap }) {
|
|
7
|
+
const activeAlignment = RICH_ALIGNMENT_OPTIONS.find(h => alignmentSelectionMap[h.id]);
|
|
8
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
const triggerRef = useRef(null);
|
|
10
|
+
const contentRef = useRef(null);
|
|
11
|
+
return (_jsxs(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [_jsx(PopoverTrigger, { triggerRef: triggerRef, children: _jsxs("button", { type: "button", className: `lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`, onClick: () => setIsOpen((prev) => !prev), style: {
|
|
12
|
+
minWidth: 146
|
|
13
|
+
}, children: [activeAlignment?.icon, _jsx("span", { children: activeAlignment?.label }), _jsx(HiChevronDown, { className: `chevron ${isOpen ? "rotated" : ""}` })] }) }), _jsx(PopoverContent, { open: isOpen, align: "start", onClose: () => setIsOpen(false), contentRef: contentRef, children: _jsx("div", { style: {
|
|
14
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
15
|
+
}, children: RICH_ALIGNMENT_OPTIONS.map(({ id, label, icon }) => (_jsxs("button", { type: "button", className: `lexical-btn ${alignmentSelectionMap[id] ? "toolbar-active" : "toolbar"}`, onClick: () => {
|
|
16
|
+
onAction(id);
|
|
17
|
+
setIsOpen(false);
|
|
18
|
+
}, children: [icon, _jsx("span", { className: "label", children: label })] }, id))) }) })] }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { SketchPicker } from "react-color";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
export default function ColorPicker({ color, onChange, icon }) {
|
|
6
|
+
const [open, setOpen] = useState(false);
|
|
7
|
+
const triggerRef = useRef(null);
|
|
8
|
+
const popoverRef = useRef(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const handleClickOutside = (event) => {
|
|
11
|
+
if (popoverRef.current &&
|
|
12
|
+
!popoverRef.current.contains(event.target) &&
|
|
13
|
+
triggerRef.current &&
|
|
14
|
+
!triggerRef.current.contains(event.target)) {
|
|
15
|
+
setOpen(false);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
19
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
20
|
+
}, []);
|
|
21
|
+
const preventFocus = (e) => e.preventDefault();
|
|
22
|
+
return (_jsxs("div", { className: "color-picker-wrapper", children: [_jsx("button", { type: "button", ref: triggerRef, className: `size-8 lexical-btn ${open ? "toolbarActive" : "toolbar"} icon`, onClick: () => setOpen((prev) => !prev), children: icon }), open &&
|
|
23
|
+
createPortal(_jsx("div", { ref: popoverRef, className: `lexical-color-popover ${open ? "open" : ""}`, style: {
|
|
24
|
+
top: triggerRef.current?.getBoundingClientRect().bottom,
|
|
25
|
+
left: triggerRef.current?.getBoundingClientRect().left,
|
|
26
|
+
position: "absolute",
|
|
27
|
+
}, onMouseDown: preventFocus, children: _jsx(SketchPicker, { color: color, onChangeComplete: (c) => {
|
|
28
|
+
onChange(c.hex);
|
|
29
|
+
} }) }), document.body)] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { VscPreview } from "react-icons/vsc";
|
|
4
|
+
import RawDialog from "./common/Dialog";
|
|
5
|
+
export function HtmlPreview({ value }) {
|
|
6
|
+
return (_jsx("div", { className: "lexical-text-editor-html-preview", dangerouslySetInnerHTML: { __html: value } }));
|
|
7
|
+
}
|
|
8
|
+
export default function ContentPreviewDialog({ value, triggerLabel = "Preview", }) {
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
return (_jsxs("div", { className: "lexical-text-editor-dialog", children: [_jsxs("button", { type: "button", className: `lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`, onClick: () => setIsOpen((prev) => !prev), children: [_jsx(VscPreview, { size: 18 }), _jsx("span", { children: triggerLabel })] }), _jsxs(RawDialog, { open: isOpen, onClose: () => setIsOpen(false), forPreview: true, children: [_jsx("div", { className: "lte-dialog-header", children: "Content Preview" }), _jsxs("div", { className: "lte-preview-container", children: [_jsx("div", { className: "lte-preview-title", children: "CONTENT" }), _jsx(HtmlPreview, { value: value })] })] })] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Theme = "light" | "dark" | "system";
|
|
2
|
+
type ToolbarStyle = "wrap" | "collapse" | "scrollbar";
|
|
3
|
+
interface DisplayControlsProps {
|
|
4
|
+
theme: Theme;
|
|
5
|
+
toolbarStyle: ToolbarStyle | "normal";
|
|
6
|
+
onThemeChange?: (theme: Theme) => void;
|
|
7
|
+
onToolbarStyleChange?: (style: ToolbarStyle) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Small user-facing display switchers at the right edge of the status bar:
|
|
11
|
+
* theme (light / dark / system) and toolbar drawing style (wrap / collapse /
|
|
12
|
+
* scrollbar). Complements the developer props — either can change the value;
|
|
13
|
+
* the component's internal state (initialized from the props) is what renders.
|
|
14
|
+
*/
|
|
15
|
+
export default function DisplayControls({ theme, toolbarStyle: styleRaw, onThemeChange, onToolbarStyleChange, }: DisplayControlsProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RICH_TEXT_FORMAT_OPTIONS } from "../constants/index";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { HiChevronDown } from "react-icons/hi2";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
6
|
+
export function DropdownList({ onAction, selectionMap }) {
|
|
7
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
8
|
+
const triggerRef = useRef(null);
|
|
9
|
+
const contentRef = useRef(null);
|
|
10
|
+
return (_jsxs(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [_jsx(PopoverTrigger, { triggerRef: triggerRef, children: _jsxs("button", { type: "button", className: `lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`, onClick: () => setIsOpen((prev) => !prev), children: [_jsx("span", { children: "Aa" }), _jsx(HiChevronDown, { className: `chevron ${isOpen ? "rotated" : ""}` })] }) }), _jsx(PopoverContent, { open: isOpen, align: "start", onClose: () => setIsOpen(false), contentRef: contentRef, children: _jsx("div", { style: {
|
|
11
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
12
|
+
}, children: RICH_TEXT_FORMAT_OPTIONS.map(({ id, label, icon }) => (_jsxs("button", { type: "button", className: `lexical-btn ${selectionMap[id] ? "toolbar-active" : "toolbar"}`, onClick: () => {
|
|
13
|
+
onAction(id);
|
|
14
|
+
setIsOpen(false);
|
|
15
|
+
}, style: {
|
|
16
|
+
minWidth: 130
|
|
17
|
+
}, children: [icon, _jsx("span", { className: "label", children: label })] }, id))) }) })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface FindReplaceModalProps {
|
|
2
|
+
onClose: () => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Find & Replace panel.
|
|
6
|
+
* Matches are located per TextNode (a query spanning across two TextNodes is
|
|
7
|
+
* not matched). The match list is recomputed on every editor change while the
|
|
8
|
+
* panel is open, so stale node keys never reach a replace operation.
|
|
9
|
+
*/
|
|
10
|
+
export default function FindReplaceModal({ onClose }: FindReplaceModalProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import { $getRoot, $getNodeByKey, $isTextNode } from "lexical";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { IoChevronDown, IoChevronUp, IoClose } from "react-icons/io5";
|
|
6
|
+
/**
|
|
7
|
+
* Find & Replace panel.
|
|
8
|
+
* Matches are located per TextNode (a query spanning across two TextNodes is
|
|
9
|
+
* not matched). The match list is recomputed on every editor change while the
|
|
10
|
+
* panel is open, so stale node keys never reach a replace operation.
|
|
11
|
+
*/
|
|
12
|
+
export default function FindReplaceModal({ onClose }) {
|
|
13
|
+
const [editor] = useLexicalComposerContext();
|
|
14
|
+
const [query, setQuery] = useState("");
|
|
15
|
+
const [replacement, setReplacement] = useState("");
|
|
16
|
+
const [caseSensitive, setCaseSensitive] = useState(false);
|
|
17
|
+
const [matches, setMatches] = useState([]);
|
|
18
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
19
|
+
const searchInputRef = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
searchInputRef.current?.focus();
|
|
22
|
+
}, []);
|
|
23
|
+
const collectMatches = () => {
|
|
24
|
+
if (!query)
|
|
25
|
+
return [];
|
|
26
|
+
const needle = caseSensitive ? query : query.toLowerCase();
|
|
27
|
+
const result = [];
|
|
28
|
+
const textNodes = $getRoot().getAllTextNodes();
|
|
29
|
+
for (const node of textNodes) {
|
|
30
|
+
const haystack = caseSensitive
|
|
31
|
+
? node.getTextContent()
|
|
32
|
+
: node.getTextContent().toLowerCase();
|
|
33
|
+
let index = haystack.indexOf(needle);
|
|
34
|
+
while (index !== -1) {
|
|
35
|
+
result.push({ key: node.getKey(), start: index });
|
|
36
|
+
index = haystack.indexOf(needle, index + needle.length);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
// Recompute on query / case-sensitivity change
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const found = editor.getEditorState().read(collectMatches);
|
|
44
|
+
setMatches(found);
|
|
45
|
+
setCurrentIndex(0);
|
|
46
|
+
}, [editor, query, caseSensitive]);
|
|
47
|
+
// Keep match list in sync while the panel is open
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return editor.registerUpdateListener(({ editorState }) => {
|
|
50
|
+
const found = editorState.read(collectMatches);
|
|
51
|
+
setMatches(found);
|
|
52
|
+
setCurrentIndex((prev) => found.length === 0 ? 0 : Math.min(prev, found.length - 1));
|
|
53
|
+
});
|
|
54
|
+
}, [editor, query, caseSensitive]);
|
|
55
|
+
const navigate = (direction) => {
|
|
56
|
+
if (matches.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
const next = (currentIndex + direction + matches.length) % matches.length;
|
|
59
|
+
const match = matches[next];
|
|
60
|
+
setCurrentIndex(next);
|
|
61
|
+
editor.update(() => {
|
|
62
|
+
const node = $getNodeByKey(match.key);
|
|
63
|
+
if ($isTextNode(node)) {
|
|
64
|
+
node.select(match.start, match.start + query.length);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
requestAnimationFrame(() => {
|
|
68
|
+
const element = editor.getElementByKey(match.key);
|
|
69
|
+
element?.scrollIntoView({ block: "nearest" });
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const replaceCurrent = () => {
|
|
73
|
+
editor.update(() => {
|
|
74
|
+
const localMatches = collectMatches();
|
|
75
|
+
if (localMatches.length === 0) {
|
|
76
|
+
setMatches([]);
|
|
77
|
+
setCurrentIndex(0);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const index = Math.min(currentIndex, localMatches.length - 1);
|
|
81
|
+
const match = localMatches[index];
|
|
82
|
+
const node = $getNodeByKey(match.key);
|
|
83
|
+
if (!$isTextNode(node))
|
|
84
|
+
return;
|
|
85
|
+
// `moveSelection` places the caret at the end of the replaced text
|
|
86
|
+
node.spliceText(match.start, query.length, replacement, true);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const replaceAll = () => {
|
|
90
|
+
editor.update(() => {
|
|
91
|
+
const localMatches = collectMatches();
|
|
92
|
+
// Reverse order so replacing a match never shifts earlier offsets.
|
|
93
|
+
// Single `editor.update` => one undo step.
|
|
94
|
+
for (let i = localMatches.length - 1; i >= 0; i--) {
|
|
95
|
+
const match = localMatches[i];
|
|
96
|
+
const node = $getNodeByKey(match.key);
|
|
97
|
+
if ($isTextNode(node)) {
|
|
98
|
+
node.spliceText(match.start, query.length, replacement, false);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const hasQuery = query.length > 0;
|
|
104
|
+
const hasMatches = matches.length > 0;
|
|
105
|
+
return (_jsxs("div", { className: "lexical-find-replace", onKeyDown: (e) => {
|
|
106
|
+
if (e.key === "Escape") {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
onClose();
|
|
109
|
+
}
|
|
110
|
+
}, children: [_jsxs("div", { className: "lexical-fr-row", children: [_jsx("input", { ref: searchInputRef, className: "lexical-fr-input", placeholder: "Find", value: query, onChange: (e) => setQuery(e.target.value), onKeyDown: (e) => {
|
|
111
|
+
if (e.key === "Enter") {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
navigate(e.shiftKey ? -1 : 1);
|
|
114
|
+
}
|
|
115
|
+
} }), _jsx("span", { className: "lexical-fr-count", children: hasMatches
|
|
116
|
+
? `${currentIndex + 1} of ${matches.length}`
|
|
117
|
+
: hasQuery
|
|
118
|
+
? "0 results"
|
|
119
|
+
: "" })] }), _jsx("div", { className: "lexical-fr-row", children: _jsx("input", { className: "lexical-fr-input", placeholder: "Replace with", value: replacement, onChange: (e) => setReplacement(e.target.value) }) }), _jsxs("div", { className: "lexical-fr-row", children: [_jsxs("label", { className: "lexical-fr-case", children: [_jsx("input", { type: "checkbox", checked: caseSensitive, onChange: (e) => setCaseSensitive(e.target.checked) }), _jsx("span", { children: "Match case" })] }), _jsx("span", { style: { flex: 1 } }), _jsx("button", { type: "button", className: "lexical-btn toolbar", onClick: () => navigate(-1), disabled: !hasMatches, "aria-label": "Previous match", children: _jsx(IoChevronUp, {}) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", onClick: () => navigate(1), disabled: !hasMatches, "aria-label": "Next match", children: _jsx(IoChevronDown, {}) }), _jsx("button", { type: "button", className: "lexical-btn toolbar", onClick: replaceCurrent, disabled: !hasMatches, children: "Replace" }), _jsx("button", { type: "button", className: "lexical-btn toolbar", onClick: replaceAll, disabled: !hasMatches, children: "Replace All" }), _jsx("button", { type: "button", className: "lexical-btn toolbar", onClick: onClose, "aria-label": "Close find and replace", children: _jsx(IoClose, {}) })] })] }));
|
|
120
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface FontOption {
|
|
3
|
+
/** CSS value applied to the selection. Empty string resets to default. */
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
icon: ReactNode;
|
|
9
|
+
tooltipLabel: string;
|
|
10
|
+
/** Normalized current style value; empty string means "Default". */
|
|
11
|
+
currentValue: string;
|
|
12
|
+
options: FontOption[];
|
|
13
|
+
onSelect: (value: string) => void;
|
|
14
|
+
minWidth?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function FontSelectionList({ icon, tooltipLabel, currentValue, options, onSelect, minWidth }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { HiChevronDown } from "react-icons/hi2";
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
5
|
+
export function FontSelectionList({ icon, tooltipLabel, currentValue, options, onSelect, minWidth = 132 }) {
|
|
6
|
+
const activeOption = options.find((option) => option.id !== "" && option.id === currentValue);
|
|
7
|
+
const [open, setOpen] = useState(false);
|
|
8
|
+
const triggerRef = useRef(null);
|
|
9
|
+
const contentRef = useRef(null);
|
|
10
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { triggerRef: triggerRef, children: _jsxs("button", { type: "button", "aria-label": tooltipLabel, className: `lexical-btn heading-trigger font-trigger ${open ? "toolbar-active" : "toolbar"}`, style: { minWidth }, onClick: () => setOpen((prev) => !prev), children: [icon, _jsx("span", { children: activeOption?.label ?? "Default" }), _jsx(HiChevronDown, { className: `chevron ${open ? "rotated" : ""}` })] }) }), _jsx(PopoverContent, { open: open, align: "start", onClose: () => setOpen(false), contentRef: contentRef, children: _jsx("div", { style: {
|
|
11
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
12
|
+
}, children: options.map((option) => (_jsx("button", { type: "button", className: `lexical-btn ${option.id === "" && currentValue === "" ? "toolbar-active"
|
|
13
|
+
: option.id !== "" && option.id === currentValue ? "toolbar-active" : "toolbar"}`, onClick: () => {
|
|
14
|
+
onSelect(option.id);
|
|
15
|
+
setOpen(false);
|
|
16
|
+
}, children: _jsx("span", { className: "label", children: option.label }) }, option.label))) }) })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { HEADINGS } from "../constants/index";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { HiChevronDown } from "react-icons/hi2";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
6
|
+
export function HeadingSelectionList({ updateHeading, headingSelectionMap }) {
|
|
7
|
+
const activeHeading = HEADINGS.find((h) => headingSelectionMap[h.id]);
|
|
8
|
+
const [open, setOpen] = useState(false);
|
|
9
|
+
const triggerRef = useRef(null);
|
|
10
|
+
const contentRef = useRef(null);
|
|
11
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { triggerRef: triggerRef, children: _jsxs("button", { type: "button", className: `lexical-btn heading-trigger ${open ? "toolbar-active" : "toolbar"}`, onClick: () => setOpen((prev) => !prev), style: {
|
|
12
|
+
minWidth: 132
|
|
13
|
+
}, children: [activeHeading?.icon, _jsx("span", { children: activeHeading?.label }), _jsx(HiChevronDown, { className: `chevron ${open ? "rotated" : ""}` })] }) }), _jsx(PopoverContent, { open: open, align: "start", onClose: () => setOpen(false), contentRef: contentRef, children: _jsx("div", { style: {
|
|
14
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
15
|
+
}, children: HEADINGS.map(({ id, label, icon }) => (_jsxs("button", { type: "button", className: `lexical-btn ${headingSelectionMap[id] ? "toolbar-active" : "toolbar"}`, onClick: () => {
|
|
16
|
+
updateHeading(id);
|
|
17
|
+
setOpen(false);
|
|
18
|
+
}, children: [icon, _jsx("span", { className: "label", children: label })] }, id))) }) })] }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import { $getNodeByKey } from "lexical";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
export const ImageComponent = ({ src, altText, nodeKey, width, height, maxWidth, caption = "", }) => {
|
|
6
|
+
const [editor] = useLexicalComposerContext();
|
|
7
|
+
const [editingCaption, setEditingCaption] = useState(false);
|
|
8
|
+
const [captionText, setCaptionText] = useState(caption);
|
|
9
|
+
const captionInputRef = useRef(null);
|
|
10
|
+
const dragSizeRef = useRef(null);
|
|
11
|
+
const wrapperRef = useRef(null);
|
|
12
|
+
const startPos = useRef(null);
|
|
13
|
+
const onMouseDown = (e) => {
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
e.stopPropagation();
|
|
16
|
+
const img = wrapperRef.current?.querySelector("img");
|
|
17
|
+
if (!img)
|
|
18
|
+
return;
|
|
19
|
+
const renderedWidth = img.getBoundingClientRect().width;
|
|
20
|
+
const naturalRatio = img.naturalHeight / img.naturalWidth;
|
|
21
|
+
const renderedHeight = renderedWidth * naturalRatio;
|
|
22
|
+
startPos.current = {
|
|
23
|
+
x: e.clientX,
|
|
24
|
+
y: e.clientY,
|
|
25
|
+
width: renderedWidth,
|
|
26
|
+
height: renderedHeight,
|
|
27
|
+
};
|
|
28
|
+
dragSizeRef.current = {
|
|
29
|
+
width: renderedWidth,
|
|
30
|
+
height: renderedHeight,
|
|
31
|
+
ratio: naturalRatio,
|
|
32
|
+
};
|
|
33
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
34
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
35
|
+
};
|
|
36
|
+
const onMouseMove = (e) => {
|
|
37
|
+
if (!startPos.current || !dragSizeRef.current)
|
|
38
|
+
return;
|
|
39
|
+
const deltaX = e.clientX - startPos.current.x;
|
|
40
|
+
const newWidth = Math.min(maxWidth, Math.max(50, startPos.current.width + deltaX));
|
|
41
|
+
const newHeight = newWidth * dragSizeRef.current.ratio;
|
|
42
|
+
dragSizeRef.current.width = newWidth;
|
|
43
|
+
dragSizeRef.current.height = newHeight;
|
|
44
|
+
const img = wrapperRef.current?.querySelector("img");
|
|
45
|
+
if (img) {
|
|
46
|
+
img.style.width = newWidth + "px";
|
|
47
|
+
img.style.height = newHeight + "px";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const onMouseUp = () => {
|
|
51
|
+
if (!dragSizeRef.current)
|
|
52
|
+
return;
|
|
53
|
+
const { width: finalWidth, height: finalHeight } = dragSizeRef.current;
|
|
54
|
+
editor.update(() => {
|
|
55
|
+
const node = $getNodeByKey(nodeKey);
|
|
56
|
+
if (node && typeof node.updateDimensions === "function") {
|
|
57
|
+
node.updateDimensions(finalWidth, finalHeight);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
dragSizeRef.current = null;
|
|
61
|
+
startPos.current = null;
|
|
62
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
63
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
64
|
+
};
|
|
65
|
+
const saveCaption = () => {
|
|
66
|
+
setEditingCaption(false);
|
|
67
|
+
editor.update(() => {
|
|
68
|
+
const node = $getNodeByKey(nodeKey);
|
|
69
|
+
if (node && typeof node.setCaption === "function") {
|
|
70
|
+
node.setCaption(captionText);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const startCaptionEdit = () => {
|
|
75
|
+
setCaptionText(caption);
|
|
76
|
+
setEditingCaption(true);
|
|
77
|
+
setTimeout(() => captionInputRef.current?.focus(), 0);
|
|
78
|
+
};
|
|
79
|
+
return (_jsxs("div", { ref: wrapperRef, style: {
|
|
80
|
+
display: "inline-block",
|
|
81
|
+
position: "relative",
|
|
82
|
+
maxWidth,
|
|
83
|
+
}, children: [_jsx("img", { src: src, alt: altText, width: width === "inherit" ? undefined : width, height: height === "inherit" ? undefined : height, style: {
|
|
84
|
+
maxWidth: "100%",
|
|
85
|
+
display: "block",
|
|
86
|
+
} }), (caption || editingCaption) && (_jsx("div", { style: { textAlign: "center", marginTop: 4 }, children: editingCaption ? (_jsx("input", { ref: captionInputRef, className: "lte-input", style: { width: "100%", textAlign: "center" }, value: captionText, onChange: (e) => setCaptionText(e.target.value), onBlur: saveCaption, onKeyDown: (e) => {
|
|
87
|
+
if (e.key === "Enter")
|
|
88
|
+
saveCaption();
|
|
89
|
+
} })) : (_jsx("span", { style: {
|
|
90
|
+
fontSize: 13,
|
|
91
|
+
color: "#666",
|
|
92
|
+
cursor: "text",
|
|
93
|
+
display: "inline-block",
|
|
94
|
+
minWidth: 20,
|
|
95
|
+
minHeight: 18,
|
|
96
|
+
}, onClick: startCaptionEdit, children: caption })) })), !caption && !editingCaption && (_jsx("div", { style: { textAlign: "center", marginTop: 2 }, children: _jsx("span", { style: {
|
|
97
|
+
fontSize: 12,
|
|
98
|
+
color: "#999",
|
|
99
|
+
cursor: "pointer",
|
|
100
|
+
}, onClick: startCaptionEdit, children: "+ Add caption" }) })), _jsx("div", { onMouseDown: onMouseDown, style: {
|
|
101
|
+
position: "absolute",
|
|
102
|
+
bottom: caption || editingCaption ? 40 : 0,
|
|
103
|
+
right: 0,
|
|
104
|
+
width: 14,
|
|
105
|
+
height: 14,
|
|
106
|
+
background: "white",
|
|
107
|
+
border: "1px solid #999",
|
|
108
|
+
cursor: "nwse-resize",
|
|
109
|
+
borderRadius: 2,
|
|
110
|
+
} })] }));
|
|
111
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "./ui/button";
|
|
3
|
+
import { Popover, PopoverContent, PopoverTrigger, } from "./ui/popover";
|
|
4
|
+
// import { RichTextAction } from "constants";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { BsPlus } from "react-icons/bs";
|
|
7
|
+
import { HiChevronDown } from "react-icons/hi2";
|
|
8
|
+
// interface Props {
|
|
9
|
+
// onAction: (id: RichTextAction) => void,
|
|
10
|
+
// selectionMap: {
|
|
11
|
+
// [id: string]: boolean;
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
export function InsertDropdownList({}) {
|
|
15
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
16
|
+
return (_jsxs(Popover, { open: isOpen, onOpenChange: (s) => setIsOpen(s), children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { variant: isOpen ? "toolbarActive" : "toolbar", onClick: () => setIsOpen(!isOpen), size: "icon", className: "size-8 w-fit p-2 select-none border-[1px] border-gray-100", children: [_jsx(BsPlus, {}), " ", _jsx("span", { children: "Insert" }), " ", _jsx(HiChevronDown, { className: ` transition-normal duration-100 ${isOpen ? "rotate-180" : "rotate-0"}` })] }) }), _jsx(PopoverContent, { className: "p-2 w-fit flex flex-col items-start gap-1" })] }));
|
|
17
|
+
}
|
|
@@ -8,5 +8,15 @@ export interface LexiTexProps {
|
|
|
8
8
|
height?: string | null | undefined;
|
|
9
9
|
maxWidth?: string | null | undefined;
|
|
10
10
|
onImageUpload?: (file: File) => Promise<string>;
|
|
11
|
+
showWordCount?: boolean;
|
|
12
|
+
showCharCount?: boolean;
|
|
13
|
+
theme?: 'light' | 'dark' | 'system';
|
|
14
|
+
toolbarStyle?: 'wrap' | 'collapse' | 'scrollbar' | 'normal';
|
|
15
|
+
/** Show light/dark + toolbar-style switchers in the status bar so end users can change these too */
|
|
16
|
+
showDisplayControls?: boolean;
|
|
17
|
+
/** Fires when the end user changes the theme from the editor UI (not on prop changes) */
|
|
18
|
+
onThemeChange?: (theme: 'light' | 'dark' | 'system') => void;
|
|
19
|
+
/** Fires when the end user changes the toolbar style from the editor UI (not on prop changes) */
|
|
20
|
+
onToolbarStyleChange?: (style: 'wrap' | 'collapse' | 'scrollbar') => void;
|
|
11
21
|
}
|
|
12
22
|
export declare const LexicalTextEditor: React.FC<LexiTexProps>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
|
|
5
|
+
import { CodeHighlightNode, CodeNode } from "@lexical/code";
|
|
6
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
7
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
8
|
+
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
9
|
+
import { TextNode } from "lexical";
|
|
10
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
11
|
+
import { ListPlugin } from "@lexical/react/LexicalListPlugin";
|
|
12
|
+
import { ListItemNode, ListNode } from "@lexical/list";
|
|
13
|
+
import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode";
|
|
14
|
+
import { HorizontalRulePlugin } from "@lexical/react/LexicalHorizontalRulePlugin";
|
|
15
|
+
import { TablePlugin as LexicalTablePlugin } from "@lexical/react/LexicalTablePlugin";
|
|
16
|
+
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
|
|
17
|
+
import { ToolbarPlugin } from "../plugins/ToolbarPlugin";
|
|
18
|
+
import { LinkNode } from "@lexical/link";
|
|
19
|
+
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
|
|
20
|
+
import CustomOnChangePlugin from "../plugins/CustomOnChangePlugin";
|
|
21
|
+
import SourceView from "./SourceView";
|
|
22
|
+
import StatusBar from "./StatusBar";
|
|
23
|
+
import { ImageNode } from "../nodes/ImageNode";
|
|
24
|
+
import { YoutubeNode } from "../nodes/YoutubeNode";
|
|
25
|
+
import { VideoNode } from "../nodes/VideoNode";
|
|
26
|
+
import "../styles/lexical-editor.css";
|
|
27
|
+
import { ExtendedTextNode } from "../nodes/ExtendedTextNode";
|
|
28
|
+
const theme = {
|
|
29
|
+
text: {
|
|
30
|
+
bold: "lexical-bold",
|
|
31
|
+
underline: "lexical-underline",
|
|
32
|
+
italic: "lexical-italic",
|
|
33
|
+
strikethrough: "lexical-strikethrough",
|
|
34
|
+
underlineStrikethrough: "lexical-underline-strikethrough",
|
|
35
|
+
uppercase: "lexical-uppercase",
|
|
36
|
+
lowercase: "lexical-lowercase",
|
|
37
|
+
capitalize: "lexical-capitalize",
|
|
38
|
+
code: "lexical-code",
|
|
39
|
+
},
|
|
40
|
+
paragraph: "lexical-paragraph",
|
|
41
|
+
list: {
|
|
42
|
+
ul: "lexical-list-ul",
|
|
43
|
+
ol: "lexical-list-ol",
|
|
44
|
+
listitem: "lexical-listitem",
|
|
45
|
+
},
|
|
46
|
+
quote: "lexical-quote",
|
|
47
|
+
link: "lexical-link",
|
|
48
|
+
code: "lexical-code-block",
|
|
49
|
+
hr: "lexical-hr",
|
|
50
|
+
indent: "lexical-indent",
|
|
51
|
+
table: "lexical-table",
|
|
52
|
+
tableRow: "lexical-table-row",
|
|
53
|
+
tableCell: "lexical-table-cell",
|
|
54
|
+
codeHighlight: {
|
|
55
|
+
keyword: "lexical-code-token-keyword",
|
|
56
|
+
string: "lexical-code-token-string",
|
|
57
|
+
number: "lexical-code-token-number",
|
|
58
|
+
comment: "lexical-code-token-comment",
|
|
59
|
+
function: "lexical-code-token-function",
|
|
60
|
+
operator: "lexical-code-token-operator",
|
|
61
|
+
punctuation: "lexical-code-token-punctuation",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export const LexicalTextEditor = React.memo(function LexicalTextEditor({ name, value, onChange, placeholder, maxWidth = null, height = null, onImageUpload, showWordCount = true, showCharCount = true, }) {
|
|
65
|
+
const [sourceView, setSourceView] = useState(false);
|
|
66
|
+
const [fullscreen, setFullscreen] = useState(false);
|
|
67
|
+
const sourceViewApplyRef = useRef(null);
|
|
68
|
+
const toggleSourceView = () => {
|
|
69
|
+
setSourceView((prev) => {
|
|
70
|
+
if (prev) {
|
|
71
|
+
// Exit: apply pending source edits before leaving source view
|
|
72
|
+
sourceViewApplyRef.current?.();
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const toggleFullscreen = () => {
|
|
79
|
+
setFullscreen((prev) => !prev);
|
|
80
|
+
};
|
|
81
|
+
// Escape exits fullscreen
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!fullscreen)
|
|
84
|
+
return;
|
|
85
|
+
const onKeyDown = (event) => {
|
|
86
|
+
if (event.key === "Escape")
|
|
87
|
+
setFullscreen(false);
|
|
88
|
+
};
|
|
89
|
+
document.addEventListener("keydown", onKeyDown);
|
|
90
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
91
|
+
}, [fullscreen]);
|
|
92
|
+
const initialConfig = useMemo(() => ({
|
|
93
|
+
namespace: name,
|
|
94
|
+
theme: theme,
|
|
95
|
+
onError: (error) => {
|
|
96
|
+
console.error("Lexical error:", error);
|
|
97
|
+
},
|
|
98
|
+
nodes: [
|
|
99
|
+
ExtendedTextNode,
|
|
100
|
+
{
|
|
101
|
+
replace: TextNode,
|
|
102
|
+
with: (node) => new ExtendedTextNode(node.__text),
|
|
103
|
+
withKlass: ExtendedTextNode,
|
|
104
|
+
},
|
|
105
|
+
HeadingNode,
|
|
106
|
+
CodeHighlightNode,
|
|
107
|
+
CodeNode,
|
|
108
|
+
ListNode,
|
|
109
|
+
ListItemNode,
|
|
110
|
+
QuoteNode,
|
|
111
|
+
LinkNode,
|
|
112
|
+
ImageNode,
|
|
113
|
+
YoutubeNode,
|
|
114
|
+
VideoNode,
|
|
115
|
+
HorizontalRuleNode,
|
|
116
|
+
TableNode,
|
|
117
|
+
TableRowNode,
|
|
118
|
+
TableCellNode
|
|
119
|
+
],
|
|
120
|
+
}), [name]);
|
|
121
|
+
return (_jsx("div", { className: `lexical-text-editor lexical-editor-container ${fullscreen ? "lexical-fullscreen" : ""}`, style: {
|
|
122
|
+
maxWidth: fullscreen ? 'none' : (maxWidth ? maxWidth : '1090px'),
|
|
123
|
+
}, children: _jsxs(LexicalComposer, { initialConfig: initialConfig, children: [_jsx("div", { className: "lexical-toolbar-container", children: _jsx(ToolbarPlugin, { value: value, onImageUpload: onImageUpload, sourceView: sourceView, onToggleSourceView: toggleSourceView, fullscreen: fullscreen, onToggleFullscreen: toggleFullscreen }) }), _jsx("div", { className: "lexical-editor-inner", style: sourceView ? { display: 'none' } : undefined, children: _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "lexical-content-editable", style: {
|
|
124
|
+
height: height ? height : '500px',
|
|
125
|
+
} }), placeholder: _jsx("div", { className: "lexical-placeholder", children: placeholder || "Some Text" }), ErrorBoundary: LexicalErrorBoundary }) }), sourceView &&
|
|
126
|
+
_jsx(SourceView, { applyRef: sourceViewApplyRef, onExit: () => setSourceView(false) }), (showWordCount || showCharCount) &&
|
|
127
|
+
_jsx(StatusBar, { showWordCount: showWordCount, showCharCount: showCharCount }), _jsx(HistoryPlugin, {}), _jsx(ListPlugin, {}), _jsx(LexicalTablePlugin, {}), _jsx(HorizontalRulePlugin, {}), _jsx(LinkPlugin, {}), _jsx(CustomOnChangePlugin, { value: value, onChange: onChange })] }) }));
|
|
128
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { BsPencilSquare } from "react-icons/bs";
|
|
4
|
+
import { MdCheck } from "react-icons/md";
|
|
5
|
+
import { BiUnlink } from "react-icons/bi";
|
|
6
|
+
export default function LinkModal({ linkUrl, setLinkUrl, onConfirm, onCancel, removeLink, }) {
|
|
7
|
+
const [isEditMode, setEditMode] = useState(false);
|
|
8
|
+
const editorRef = useRef(null);
|
|
9
|
+
const inputRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (linkUrl === "https://")
|
|
12
|
+
setEditMode(true);
|
|
13
|
+
}, [linkUrl]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (isEditMode)
|
|
16
|
+
inputRef.current?.focus();
|
|
17
|
+
}, [isEditMode]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const handleClickOutside = (event) => {
|
|
20
|
+
if (editorRef.current &&
|
|
21
|
+
!editorRef.current.contains(event.target)) {
|
|
22
|
+
onCancel();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
26
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
27
|
+
}, [onCancel]);
|
|
28
|
+
return (_jsxs("div", { ref: editorRef, className: "lexical-text-editor-link link-editor-container", children: [_jsx("div", { className: "link-editor-input-wrapper", children: isEditMode ? (_jsx("input", { ref: inputRef, className: "link-editor-input", value: linkUrl, onChange: (e) => setLinkUrl(e.target.value), onKeyDown: (e) => {
|
|
29
|
+
if (e.key === "Enter") {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
onConfirm(linkUrl);
|
|
32
|
+
setEditMode(false);
|
|
33
|
+
}
|
|
34
|
+
else if (e.key === "Escape") {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
setEditMode(false);
|
|
37
|
+
onCancel();
|
|
38
|
+
}
|
|
39
|
+
} })) : (_jsx("a", { href: linkUrl, target: "_blank", rel: "noopener noreferrer", className: "link-editor-url", children: linkUrl })) }), _jsxs("div", { className: "link-editor-buttons", children: [_jsx("button", { type: "button", className: `lexical-btn heading-trigger toolbar`, onClick: () => {
|
|
40
|
+
if (isEditMode) {
|
|
41
|
+
onConfirm(linkUrl);
|
|
42
|
+
setEditMode(false);
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
setEditMode(true);
|
|
46
|
+
}, children: isEditMode ? _jsx(MdCheck, { size: 18 }) : _jsx(BsPencilSquare, { size: 14 }) }), _jsx("button", { type: "button", className: `lexical-btn heading-trigger toolbar`, onMouseDown: (e) => e.preventDefault(), onClick: removeLink, children: _jsx(BiUnlink, { size: 14, style: { stroke: 'black' } }) })] })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface SourceViewProps {
|
|
2
|
+
/** Registered so the toolbar toggle can apply pending edits before exiting. */
|
|
3
|
+
applyRef: React.MutableRefObject<(() => void) | null>;
|
|
4
|
+
onExit: () => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Raw HTML editing mode. The ContentEditable stays mounted (hidden) so the
|
|
8
|
+
* editor state is preserved. Edited HTML is imported into the editor state
|
|
9
|
+
* only on demand (Update / Done / toolbar toggle) — never per keystroke, so
|
|
10
|
+
* undo history is not flooded and partially typed markup is not parsed.
|
|
11
|
+
*/
|
|
12
|
+
export default function SourceView({ applyRef, onExit }: SourceViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|