@collabchron/notiq 0.2.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 +71 -0
- package/components.json +21 -0
- package/eslint.config.mjs +16 -0
- package/next.config.ts +12 -0
- package/package.json +108 -0
- package/postcss.config.mjs +5 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/images/icons/plus.svg +10 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/actions.ts +2 -0
- package/src/app/api/ai/route.ts +175 -0
- package/src/app/api/edgestore/[...edgestore]/route.ts +28 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +205 -0
- package/src/app/layout.tsx +38 -0
- package/src/app/page.tsx +12 -0
- package/src/components/editor/Core.tsx +220 -0
- package/src/components/editor/hooks/instructions-messages.ts +300 -0
- package/src/components/editor/hooks/use-mobile.ts +19 -0
- package/src/components/editor/hooks/useReport.ts +67 -0
- package/src/components/editor/hooks/useResizeObservert.ts +22 -0
- package/src/components/editor/index.tsx +39 -0
- package/src/components/editor/lexical-on-change.tsx +28 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +92 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +65 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +105 -0
- package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +143 -0
- package/src/components/editor/nodes/EquationNode/EquationNode.tsx +170 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +228 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +137 -0
- package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +317 -0
- package/src/components/editor/nodes/ExcalidrawNode/index.tsx +204 -0
- package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +134 -0
- package/src/components/editor/nodes/Hint/HintComponet.tsx +221 -0
- package/src/components/editor/nodes/Hint/index.tsx +190 -0
- package/src/components/editor/nodes/ImageNode/index.tsx +328 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +383 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +94 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +309 -0
- package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +146 -0
- package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +79 -0
- package/src/components/editor/nodes/PollNode/index.tsx +204 -0
- package/src/components/editor/nodes/Stepper/index.tsx +260 -0
- package/src/components/editor/nodes/TweetNode/index.tsx +214 -0
- package/src/components/editor/nodes/index.ts +81 -0
- package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +350 -0
- package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +56 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +70 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +192 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +217 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +26 -0
- package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +76 -0
- package/src/components/editor/plugins/CollapsiblePlugin/index.ts +228 -0
- package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +44 -0
- package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +52 -0
- package/src/components/editor/plugins/EquationsPlugin/index.tsx +85 -0
- package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +98 -0
- package/src/components/editor/plugins/FigmaPlugin/index.tsx +42 -0
- package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +445 -0
- package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +275 -0
- package/src/components/editor/plugins/ImagesPlugin/index.tsx +222 -0
- package/src/components/editor/plugins/InlineImagePlugin/index.tsx +351 -0
- package/src/components/editor/plugins/LayoutPlugin/index.tsx +238 -0
- package/src/components/editor/plugins/LinkPlugin/index.tsx +36 -0
- package/src/components/editor/plugins/LinkWithMetaData/index.tsx +271 -0
- package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +11 -0
- package/src/components/editor/plugins/MarkdownTransformers/index.tsx +304 -0
- package/src/components/editor/plugins/PollPlugin/index.tsx +49 -0
- package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +180 -0
- package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +253 -0
- package/src/components/editor/plugins/SlashCommand/index.tsx +621 -0
- package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +127 -0
- package/src/components/editor/plugins/TabFocusPlugin/index.ts +58 -0
- package/src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx +759 -0
- package/src/components/editor/plugins/TableCellResizer/index.tsx +438 -0
- package/src/components/editor/plugins/TableHoverActionsPlugin/index.tsx +314 -0
- package/src/components/editor/plugins/TablePlugin/index.tsx +99 -0
- package/src/components/editor/plugins/ToolbarPlugin/index.tsx +522 -0
- package/src/components/editor/plugins/TwitterPlugin/index.ts +35 -0
- package/src/components/editor/plugins/YouTubeNode/index.tsx +179 -0
- package/src/components/editor/plugins/YouTubePlugin/index.ts +41 -0
- package/src/components/editor/themes/editor-theme.ts +113 -0
- package/src/components/editor/themes/theme.css +377 -0
- package/src/components/editor/utils/ai.ts +291 -0
- package/src/components/editor/utils/canUseDOM.ts +12 -0
- package/src/components/editor/utils/editorFormatting.ts +282 -0
- package/src/components/editor/utils/environment.ts +50 -0
- package/src/components/editor/utils/extract-data.ts +166 -0
- package/src/components/editor/utils/getAllLexicalChildren.ts +13 -0
- package/src/components/editor/utils/getDOMRangeRect.ts +27 -0
- package/src/components/editor/utils/getSelectedNode.ts +27 -0
- package/src/components/editor/utils/gif.ts +29 -0
- package/src/components/editor/utils/invariant.ts +15 -0
- package/src/components/editor/utils/setFloatingElemPosition.ts +51 -0
- package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +40 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +51 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +15 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +114 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +6 -0
- package/src/components/editor/utils/url.ts +109 -0
- package/src/components/editor/utils/useLayoutEffect.ts +13 -0
- package/src/components/providers/QueryProvider.tsx +15 -0
- package/src/components/providers/SharedHistoryContext.tsx +28 -0
- package/src/components/providers/ToolbarContext.tsx +123 -0
- package/src/components/providers/theme-provider.tsx +11 -0
- package/src/components/theme/ModeToggle.tsx +40 -0
- package/src/components/ui/FileInput.tsx +40 -0
- package/src/components/ui/Input.css +32 -0
- package/src/components/ui/Select.css +42 -0
- package/src/components/ui/Select.tsx +36 -0
- package/src/components/ui/TextInput.tsx +48 -0
- package/src/components/ui/ai/ai-button.tsx +574 -0
- package/src/components/ui/ai/border.tsx +99 -0
- package/src/components/ui/ai/placeholder-input-vanish.tsx +282 -0
- package/src/components/ui/button.tsx +89 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/command.tsx +153 -0
- package/src/components/ui/dialog/Dialog.css +25 -0
- package/src/components/ui/dialog/Dialog.tsx +34 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/drop-downs/background-color.tsx +183 -0
- package/src/components/ui/drop-downs/block-format.tsx +159 -0
- package/src/components/ui/drop-downs/code.tsx +42 -0
- package/src/components/ui/drop-downs/color.tsx +177 -0
- package/src/components/ui/drop-downs/font-size.tsx +138 -0
- package/src/components/ui/drop-downs/font.tsx +155 -0
- package/src/components/ui/drop-downs/index.tsx +122 -0
- package/src/components/ui/drop-downs/insert-node.tsx +213 -0
- package/src/components/ui/drop-downs/text-align.tsx +123 -0
- package/src/components/ui/drop-downs/text-format.tsx +104 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/equation/EquationEditor.css +38 -0
- package/src/components/ui/equation/EquationEditor.tsx +56 -0
- package/src/components/ui/equation/KatexEquationAlterer.css +41 -0
- package/src/components/ui/equation/KatexEquationAlterer.tsx +83 -0
- package/src/components/ui/equation/KatexRenderer.tsx +66 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.css +64 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.tsx +234 -0
- package/src/components/ui/excalidraw/Modal.css +62 -0
- package/src/components/ui/excalidraw/Modal.tsx +110 -0
- package/src/components/ui/hover-card.tsx +29 -0
- package/src/components/ui/image/error-image.tsx +17 -0
- package/src/components/ui/image/file-upload.tsx +240 -0
- package/src/components/ui/image/image-resizer.tsx +297 -0
- package/src/components/ui/image/image-toolbar.tsx +264 -0
- package/src/components/ui/image/index.tsx +408 -0
- package/src/components/ui/image/lazy-image.tsx +68 -0
- package/src/components/ui/image/lazy-video.tsx +71 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/models/custom-dialog.tsx +320 -0
- package/src/components/ui/models/insert-gif.tsx +90 -0
- package/src/components/ui/models/insert-image.tsx +52 -0
- package/src/components/ui/models/insert-poll.tsx +29 -0
- package/src/components/ui/models/insert-table.tsx +62 -0
- package/src/components/ui/models/use-model.tsx +91 -0
- package/src/components/ui/poll/poll-component.tsx +304 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/progress.tsx +28 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/stepper/step.tsx +179 -0
- package/src/components/ui/stepper/stepper.tsx +89 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/toggle.tsx +71 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/components/ui/write/text-format-floting-toolbar.tsx +346 -0
- package/src/lib/edgestore.ts +9 -0
- package/src/lib/pinecone-client.ts +0 -0
- package/src/lib/utils.ts +6 -0
- package/src/utils/docSerialization.ts +77 -0
- package/src/utils/emoji-list.ts +16615 -0
- package/src/utils/getDOMRangeRect.ts +27 -0
- package/src/utils/getSelectedNode.ts +27 -0
- package/src/utils/getThemeSelector.ts +25 -0
- package/src/utils/isMobileWidth.ts +7 -0
- package/src/utils/joinClasses.ts +13 -0
- package/src/utils/setFloatingElemPosition.ts +74 -0
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/utils/swipe.ts +127 -0
- package/src/utils/url.ts +38 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import React, { Dispatch, useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
$getNodeByKey,
|
|
5
|
+
$getSelection,
|
|
6
|
+
$isElementNode,
|
|
7
|
+
$isLineBreakNode,
|
|
8
|
+
$isRangeSelection,
|
|
9
|
+
$isRootOrShadowRoot,
|
|
10
|
+
CAN_REDO_COMMAND,
|
|
11
|
+
CAN_UNDO_COMMAND,
|
|
12
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
13
|
+
FORMAT_TEXT_COMMAND,
|
|
14
|
+
LexicalEditor,
|
|
15
|
+
NodeKey,
|
|
16
|
+
REDO_COMMAND,
|
|
17
|
+
SELECTION_CHANGE_COMMAND,
|
|
18
|
+
UNDO_COMMAND,
|
|
19
|
+
} from "lexical";
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
useToolbarState,
|
|
23
|
+
blockTypeToBlockName,
|
|
24
|
+
} from "@/components/providers/ToolbarContext";
|
|
25
|
+
import { cn } from "@/lib/utils";
|
|
26
|
+
|
|
27
|
+
import { Bold, Code, Italic, Link, Mic, Redo, Redo2Icon, Underline, Undo, Undo2Icon } from "lucide-react";
|
|
28
|
+
|
|
29
|
+
import { Separator } from "@/components/ui/separator";
|
|
30
|
+
import { Button } from "@/components/ui/button";
|
|
31
|
+
import {
|
|
32
|
+
$findMatchingParent,
|
|
33
|
+
$getNearestNodeOfType,
|
|
34
|
+
$isEditorIsNestedEditor,
|
|
35
|
+
mergeRegister,
|
|
36
|
+
} from "@lexical/utils";
|
|
37
|
+
import {
|
|
38
|
+
$getSelectionStyleValueForProperty,
|
|
39
|
+
$isParentElementRTL,
|
|
40
|
+
} from "@lexical/selection";
|
|
41
|
+
import { getSelectedNode } from "../../utils/getSelectedNode";
|
|
42
|
+
import { $isLinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
|
|
43
|
+
import { $isTableNode, $isTableSelection } from "@lexical/table";
|
|
44
|
+
import { $isListNode, ListNode } from "@lexical/list";
|
|
45
|
+
import { $isHeadingNode } from "@lexical/rich-text";
|
|
46
|
+
import { $isCodeNode, CODE_LANGUAGE_MAP } from "@lexical/code";
|
|
47
|
+
import dynamic from "next/dynamic";
|
|
48
|
+
import { Toggle } from "@/components/ui/toggle";
|
|
49
|
+
import { SHORTCUTS } from "../ShortcutsPlugin/shortcuts";
|
|
50
|
+
import { sanitizeUrl } from "../../utils/url";
|
|
51
|
+
import CodeList from "@/components/ui/drop-downs/code"
|
|
52
|
+
import { SPEECH_TO_TEXT_COMMAND, SUPPORT_SPEECH_RECOGNITION } from "../SpeechToTextPlugin";
|
|
53
|
+
import { ModeToggle } from "@/components/theme/ModeToggle";
|
|
54
|
+
const BlockFormatDropDown = dynamic(
|
|
55
|
+
() => import("@/components/ui/drop-downs/block-format")
|
|
56
|
+
);
|
|
57
|
+
const FontDropDown = dynamic(
|
|
58
|
+
() => import("@/components/ui/drop-downs/font")
|
|
59
|
+
);
|
|
60
|
+
const FontSize = dynamic(
|
|
61
|
+
() => import("@/components/ui/drop-downs/font-size")
|
|
62
|
+
);
|
|
63
|
+
const Color = dynamic(() => import("@/components/ui/drop-downs/color"));
|
|
64
|
+
const BackgroundColor = dynamic(() => import("@/components/ui/drop-downs/background-color"));
|
|
65
|
+
const TextFormat = dynamic(
|
|
66
|
+
() => import("@/components/ui/drop-downs/text-format")
|
|
67
|
+
);
|
|
68
|
+
const InsertNode = dynamic(
|
|
69
|
+
() => import("@/components/ui/drop-downs/insert-node")
|
|
70
|
+
);
|
|
71
|
+
const TextAlign = dynamic(
|
|
72
|
+
() => import("@/components/ui/drop-downs/text-align")
|
|
73
|
+
);
|
|
74
|
+
// import { type } from './../../../providers/ToolbarContext';
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
const rootTypeToRootName = {
|
|
78
|
+
root: 'Root',
|
|
79
|
+
table: 'Table',
|
|
80
|
+
};
|
|
81
|
+
export default function index({
|
|
82
|
+
editor,
|
|
83
|
+
activeEditor,
|
|
84
|
+
setActiveEditor,
|
|
85
|
+
setIsLinkEditMode,
|
|
86
|
+
}: {
|
|
87
|
+
editor: LexicalEditor;
|
|
88
|
+
activeEditor: LexicalEditor;
|
|
89
|
+
setActiveEditor: Dispatch<LexicalEditor>;
|
|
90
|
+
setIsLinkEditMode: Dispatch<boolean>;
|
|
91
|
+
}) {
|
|
92
|
+
const [isEditable, setIsEditable] = useState(() => editor.isEditable());
|
|
93
|
+
const [isSpeechToText, setIsSpeechToText] = useState(false);
|
|
94
|
+
const [selectedElementKey, setSelectedElementKey] = useState<NodeKey | null>(
|
|
95
|
+
null
|
|
96
|
+
);
|
|
97
|
+
const { toolbarState, updateToolbarState } = useToolbarState();
|
|
98
|
+
|
|
99
|
+
const $updateToolbar = useCallback(() => {
|
|
100
|
+
const currentEditor = activeEditor || editor;
|
|
101
|
+
|
|
102
|
+
if (!currentEditor) return;
|
|
103
|
+
|
|
104
|
+
currentEditor.read(() => {
|
|
105
|
+
const selection = $getSelection();
|
|
106
|
+
if ($isRangeSelection(selection)) {
|
|
107
|
+
if (activeEditor !== editor && $isEditorIsNestedEditor(activeEditor)) {
|
|
108
|
+
const rootElement = activeEditor.getRootElement();
|
|
109
|
+
updateToolbarState(
|
|
110
|
+
"isImageCaption",
|
|
111
|
+
!!rootElement?.parentElement?.classList.contains(
|
|
112
|
+
"image-caption-container"
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
updateToolbarState("isImageCaption", false);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const anchorNode = selection.anchor.getNode();
|
|
120
|
+
let element =
|
|
121
|
+
anchorNode.getKey() === "root"
|
|
122
|
+
? anchorNode
|
|
123
|
+
: $findMatchingParent(anchorNode, (e) => {
|
|
124
|
+
const parent = e.getParent();
|
|
125
|
+
return parent !== null && $isRootOrShadowRoot(parent);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (element === null) {
|
|
129
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const elementKey = element.getKey();
|
|
133
|
+
const elementDOM = currentEditor.getElementByKey(elementKey);
|
|
134
|
+
|
|
135
|
+
const node = getSelectedNode(selection);
|
|
136
|
+
const parent = node.getParent();
|
|
137
|
+
const isLink = $isLinkNode(parent) || $isLineBreakNode(node);
|
|
138
|
+
updateToolbarState("isLink", isLink);
|
|
139
|
+
|
|
140
|
+
const tableNode = $findMatchingParent(node, $isTableNode);
|
|
141
|
+
if ($isTableNode(tableNode)) {
|
|
142
|
+
updateToolbarState("rootType", "table");
|
|
143
|
+
} else {
|
|
144
|
+
updateToolbarState("rootType", "root");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (elementDOM !== null) {
|
|
148
|
+
setSelectedElementKey(elementKey);
|
|
149
|
+
if ($isListNode(element)) {
|
|
150
|
+
const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode);
|
|
151
|
+
const type = parentList
|
|
152
|
+
? parentList.getListType()
|
|
153
|
+
: element.getListType();
|
|
154
|
+
updateToolbarState("blockType", type);
|
|
155
|
+
} else {
|
|
156
|
+
const type = $isHeadingNode(element)
|
|
157
|
+
? element.getTag()
|
|
158
|
+
: element.getType();
|
|
159
|
+
if (type in blockTypeToBlockName) {
|
|
160
|
+
updateToolbarState(
|
|
161
|
+
"blockType",
|
|
162
|
+
type as keyof typeof blockTypeToBlockName
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
if ($isCodeNode(element)) {
|
|
166
|
+
const language =
|
|
167
|
+
element.getLanguage() as keyof typeof CODE_LANGUAGE_MAP;
|
|
168
|
+
updateToolbarState(
|
|
169
|
+
"codeLanguage",
|
|
170
|
+
language ? CODE_LANGUAGE_MAP[language] || language : ""
|
|
171
|
+
);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
updateToolbarState(
|
|
178
|
+
"fontColor",
|
|
179
|
+
$getSelectionStyleValueForProperty(selection, "color", "#000")
|
|
180
|
+
);
|
|
181
|
+
updateToolbarState(
|
|
182
|
+
"bgColor",
|
|
183
|
+
$getSelectionStyleValueForProperty(
|
|
184
|
+
selection,
|
|
185
|
+
"background-color",
|
|
186
|
+
"#fff"
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
updateToolbarState(
|
|
190
|
+
"fontFamily",
|
|
191
|
+
$getSelectionStyleValueForProperty(selection, "font-family", "Arial")
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
let matchingParent;
|
|
195
|
+
if ($isLinkNode(parent)) {
|
|
196
|
+
matchingParent = $findMatchingParent(
|
|
197
|
+
node,
|
|
198
|
+
(parentNode) => $isElementNode(parentNode) && !parentNode.isInline()
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
updateToolbarState(
|
|
203
|
+
"elementFormat",
|
|
204
|
+
$isElementNode(matchingParent)
|
|
205
|
+
? matchingParent.getFormatType()
|
|
206
|
+
: $isElementNode(node)
|
|
207
|
+
? node.getFormatType()
|
|
208
|
+
: parent?.getFormatType() || "left"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
213
|
+
updateToolbarState("isBold", selection.hasFormat("bold"));
|
|
214
|
+
updateToolbarState("isItalic", selection.hasFormat("italic"));
|
|
215
|
+
updateToolbarState("isUnderline", selection.hasFormat("underline"));
|
|
216
|
+
updateToolbarState("isStrikethrough", selection.hasFormat("strikethrough"));
|
|
217
|
+
updateToolbarState("isSubscript", selection.hasFormat("subscript"));
|
|
218
|
+
updateToolbarState("isSuperscript", selection.hasFormat("superscript"));
|
|
219
|
+
updateToolbarState("isCode", selection.hasFormat("code"));
|
|
220
|
+
updateToolbarState(
|
|
221
|
+
"fontSize",
|
|
222
|
+
$getSelectionStyleValueForProperty(selection, "font-size", "15px")
|
|
223
|
+
);
|
|
224
|
+
updateToolbarState("isLowercase", selection.hasFormat("lowercase"));
|
|
225
|
+
updateToolbarState("isUppercase", selection.hasFormat("uppercase"));
|
|
226
|
+
updateToolbarState("isCapitalize", selection.hasFormat("capitalize"));
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}, [activeEditor, editor, updateToolbarState]);
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
return editor.registerCommand(
|
|
233
|
+
SELECTION_CHANGE_COMMAND,
|
|
234
|
+
(_payload, newEditor) => {
|
|
235
|
+
setActiveEditor(newEditor);
|
|
236
|
+
$updateToolbar();
|
|
237
|
+
return false;
|
|
238
|
+
},
|
|
239
|
+
COMMAND_PRIORITY_CRITICAL
|
|
240
|
+
);
|
|
241
|
+
}, [editor, $updateToolbar, setActiveEditor]);
|
|
242
|
+
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
activeEditor.getEditorState().read(() => {
|
|
245
|
+
$updateToolbar();
|
|
246
|
+
});
|
|
247
|
+
}, [activeEditor, $updateToolbar]);
|
|
248
|
+
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
return mergeRegister(
|
|
251
|
+
editor.registerEditableListener((editable) => {
|
|
252
|
+
setIsEditable(editable);
|
|
253
|
+
}),
|
|
254
|
+
activeEditor.registerUpdateListener(({ editorState }) => {
|
|
255
|
+
editorState.read(() => {
|
|
256
|
+
$updateToolbar();
|
|
257
|
+
});
|
|
258
|
+
}),
|
|
259
|
+
activeEditor.registerCommand<boolean>(
|
|
260
|
+
CAN_UNDO_COMMAND,
|
|
261
|
+
(payload) => {
|
|
262
|
+
updateToolbarState("canUndo", payload);
|
|
263
|
+
return false;
|
|
264
|
+
},
|
|
265
|
+
COMMAND_PRIORITY_CRITICAL
|
|
266
|
+
),
|
|
267
|
+
activeEditor.registerCommand<boolean>(
|
|
268
|
+
CAN_REDO_COMMAND,
|
|
269
|
+
(payload) => {
|
|
270
|
+
updateToolbarState("canRedo", payload);
|
|
271
|
+
return false;
|
|
272
|
+
},
|
|
273
|
+
COMMAND_PRIORITY_CRITICAL
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
}, [$updateToolbar, activeEditor, editor, updateToolbarState]);
|
|
277
|
+
|
|
278
|
+
const insertLink = useCallback(() => {
|
|
279
|
+
if (!toolbarState.isLink) {
|
|
280
|
+
setIsLinkEditMode(true);
|
|
281
|
+
activeEditor.dispatchCommand(
|
|
282
|
+
TOGGLE_LINK_COMMAND,
|
|
283
|
+
sanitizeUrl("https://")
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
setIsLinkEditMode(false);
|
|
287
|
+
activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
288
|
+
}
|
|
289
|
+
}, [activeEditor, setIsLinkEditMode, toolbarState.isLink]);
|
|
290
|
+
const onCodeLanguageSelect = useCallback(
|
|
291
|
+
(value: string) => {
|
|
292
|
+
activeEditor.update(() => {
|
|
293
|
+
if (selectedElementKey !== null) {
|
|
294
|
+
const node = $getNodeByKey(selectedElementKey);
|
|
295
|
+
if ($isCodeNode(node)) {
|
|
296
|
+
node.setLanguage(value);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
[activeEditor, selectedElementKey]
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<nav
|
|
307
|
+
className={cn(
|
|
308
|
+
"z-[200] fixed top-0 left-0 w-full",
|
|
309
|
+
)}
|
|
310
|
+
>
|
|
311
|
+
<div className="flex justify-center p-4">
|
|
312
|
+
<div
|
|
313
|
+
className={cn(
|
|
314
|
+
"group flex flex-row items-center gap-x-2 dark:border dark:border-gray-500/20",
|
|
315
|
+
"rounded-2xl h-14 px-4 py-2 shadow-md",
|
|
316
|
+
"overflow-x-auto whitespace-nowrap max-w-full scrollbar-none",
|
|
317
|
+
"[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]"
|
|
318
|
+
)}
|
|
319
|
+
>
|
|
320
|
+
<div className="flex flex-row gap-x-2">
|
|
321
|
+
<Button
|
|
322
|
+
size={"Toolbar"}
|
|
323
|
+
variant={"outline"}
|
|
324
|
+
disabled={!toolbarState.canUndo || !isEditable}
|
|
325
|
+
onClick={() => {
|
|
326
|
+
activeEditor.dispatchCommand(UNDO_COMMAND, undefined);
|
|
327
|
+
}}
|
|
328
|
+
tip={false ? "Undo (⌘Z)" : "Undo (Ctrl+Z)"}
|
|
329
|
+
type="button"
|
|
330
|
+
aria-label="Undo"
|
|
331
|
+
className="border-none"
|
|
332
|
+
>
|
|
333
|
+
<Undo2Icon className=" size-4" />
|
|
334
|
+
</Button>
|
|
335
|
+
<Button
|
|
336
|
+
variant={"outline"}
|
|
337
|
+
size={"Toolbar"}
|
|
338
|
+
disabled={!toolbarState.canRedo || !isEditable}
|
|
339
|
+
onClick={() => {
|
|
340
|
+
activeEditor.dispatchCommand(REDO_COMMAND, undefined);
|
|
341
|
+
}}
|
|
342
|
+
tip={false ? "Redo (⇧⌘Z)" : "Redo (Ctrl+Y)"}
|
|
343
|
+
type="button"
|
|
344
|
+
className="toolbar-item border-none"
|
|
345
|
+
aria-label="Redo"
|
|
346
|
+
>
|
|
347
|
+
<Redo2Icon className=" size-4" />
|
|
348
|
+
</Button>
|
|
349
|
+
</div>
|
|
350
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
351
|
+
{toolbarState.blockType in blockTypeToBlockName &&
|
|
352
|
+
activeEditor === editor && (
|
|
353
|
+
<div className="flex flex-row gap-x-[5px] items-center">
|
|
354
|
+
<BlockFormatDropDown
|
|
355
|
+
disabled={!isEditable}
|
|
356
|
+
blockType={toolbarState.blockType}
|
|
357
|
+
editor={activeEditor}
|
|
358
|
+
/>
|
|
359
|
+
<Separator orientation={"vertical"} />
|
|
360
|
+
</div>
|
|
361
|
+
)}
|
|
362
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
363
|
+
{toolbarState.blockType == "code" ? (
|
|
364
|
+
<CodeList
|
|
365
|
+
onCodeLanguageSelect={onCodeLanguageSelect}
|
|
366
|
+
codeLanguage={toolbarState.codeLanguage}
|
|
367
|
+
disabled={!isEditable}
|
|
368
|
+
/>
|
|
369
|
+
) : (
|
|
370
|
+
<div className="flex flex-row items-center">
|
|
371
|
+
<FontDropDown
|
|
372
|
+
disabled={!isEditable}
|
|
373
|
+
style={{ fontFamily: toolbarState.fontFamily }}
|
|
374
|
+
value={toolbarState.fontFamily}
|
|
375
|
+
editor={activeEditor}
|
|
376
|
+
/>
|
|
377
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
378
|
+
<FontSize
|
|
379
|
+
selectionFontSize={toolbarState.fontSize.slice(0, -2)}
|
|
380
|
+
editor={activeEditor}
|
|
381
|
+
disabled={!isEditable}
|
|
382
|
+
/>
|
|
383
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
384
|
+
<div className="flex flex-row gap-x-1">
|
|
385
|
+
<Toggle
|
|
386
|
+
disabled={!isEditable}
|
|
387
|
+
variant={"outline"}
|
|
388
|
+
size={"Toolbar"}
|
|
389
|
+
pressed={toolbarState.isBold}
|
|
390
|
+
onPressedChange={() => {
|
|
391
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
|
392
|
+
}}
|
|
393
|
+
tip={`Bold ${SHORTCUTS.BOLD}`}
|
|
394
|
+
aria-label={`Format text as bold. Shortcut: ${SHORTCUTS.BOLD}`}
|
|
395
|
+
>
|
|
396
|
+
<Bold />
|
|
397
|
+
</Toggle>
|
|
398
|
+
<Toggle
|
|
399
|
+
variant={"outline"}
|
|
400
|
+
size={"Toolbar"}
|
|
401
|
+
disabled={!isEditable}
|
|
402
|
+
pressed={toolbarState.isItalic}
|
|
403
|
+
onPressedChange={() => {
|
|
404
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
405
|
+
}}
|
|
406
|
+
tip={`Italic (${SHORTCUTS.ITALIC})`}
|
|
407
|
+
type="button"
|
|
408
|
+
aria-label={`Format text as italics. Shortcut: ${SHORTCUTS.ITALIC}`}
|
|
409
|
+
>
|
|
410
|
+
<Italic />
|
|
411
|
+
</Toggle>
|
|
412
|
+
<Toggle
|
|
413
|
+
disabled={!isEditable}
|
|
414
|
+
variant={"outline"}
|
|
415
|
+
size={"Toolbar"}
|
|
416
|
+
pressed={toolbarState.isUnderline}
|
|
417
|
+
onPressedChange={() => {
|
|
418
|
+
activeEditor.dispatchCommand(
|
|
419
|
+
FORMAT_TEXT_COMMAND,
|
|
420
|
+
"underline"
|
|
421
|
+
);
|
|
422
|
+
}}
|
|
423
|
+
tip={`Underline (${SHORTCUTS.UNDERLINE})`}
|
|
424
|
+
type="button"
|
|
425
|
+
aria-label={`Format text to underlined. Shortcut: ${SHORTCUTS.UNDERLINE}`}
|
|
426
|
+
>
|
|
427
|
+
<Underline />
|
|
428
|
+
</Toggle>
|
|
429
|
+
<Toggle
|
|
430
|
+
disabled={!isEditable}
|
|
431
|
+
variant={"outline"}
|
|
432
|
+
size={"Toolbar"}
|
|
433
|
+
pressed={toolbarState.isCode}
|
|
434
|
+
onPressedChange={() => {
|
|
435
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, "code");
|
|
436
|
+
}}
|
|
437
|
+
tip={`Insert code block (${SHORTCUTS.INSERT_CODE_BLOCK})`}
|
|
438
|
+
type="button"
|
|
439
|
+
aria-label="Insert code block"
|
|
440
|
+
>
|
|
441
|
+
<Code />
|
|
442
|
+
</Toggle>
|
|
443
|
+
<Toggle
|
|
444
|
+
variant={"outline"}
|
|
445
|
+
size={"Toolbar"}
|
|
446
|
+
disabled={!isEditable}
|
|
447
|
+
onPressedChange={insertLink}
|
|
448
|
+
pressed={toolbarState.isLink}
|
|
449
|
+
aria-label="Insert link"
|
|
450
|
+
tip={`Insert link (${SHORTCUTS.INSERT_LINK})`}
|
|
451
|
+
type="button"
|
|
452
|
+
>
|
|
453
|
+
<Link />
|
|
454
|
+
</Toggle>
|
|
455
|
+
</div>
|
|
456
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
457
|
+
<Color
|
|
458
|
+
disabled={!isEditable}
|
|
459
|
+
color={toolbarState.fontColor}
|
|
460
|
+
bgColor={toolbarState.bgColor}
|
|
461
|
+
editor={editor}
|
|
462
|
+
/>
|
|
463
|
+
<BackgroundColor
|
|
464
|
+
disabled={!isEditable}
|
|
465
|
+
color={toolbarState.fontColor}
|
|
466
|
+
bgColor={toolbarState.bgColor}
|
|
467
|
+
editor={editor}
|
|
468
|
+
/>
|
|
469
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
470
|
+
<TextFormat
|
|
471
|
+
disabled={!isEditable}
|
|
472
|
+
editor={editor}
|
|
473
|
+
toolbarState={toolbarState}
|
|
474
|
+
/>
|
|
475
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
476
|
+
<InsertNode disabled={!isEditable} editor={editor} />
|
|
477
|
+
</div>
|
|
478
|
+
)}
|
|
479
|
+
<Separator className="h-6 mx-2" orientation="vertical" />
|
|
480
|
+
|
|
481
|
+
<TextAlign
|
|
482
|
+
disabled={!isEditable}
|
|
483
|
+
value={toolbarState.elementFormat}
|
|
484
|
+
editor={activeEditor}
|
|
485
|
+
isRTL={toolbarState.isRTL}
|
|
486
|
+
/>
|
|
487
|
+
|
|
488
|
+
{SUPPORT_SPEECH_RECOGNITION && (
|
|
489
|
+
<Button
|
|
490
|
+
variant={"outline"}
|
|
491
|
+
size={"Toolbar"}
|
|
492
|
+
type="button"
|
|
493
|
+
onClick={() => {
|
|
494
|
+
editor.dispatchCommand(SPEECH_TO_TEXT_COMMAND, !isSpeechToText);
|
|
495
|
+
setIsSpeechToText(!isSpeechToText);
|
|
496
|
+
}}
|
|
497
|
+
className={`
|
|
498
|
+
relative inline-flex items-center justify-center
|
|
499
|
+
p-3 rounded-lg border-none font-medium
|
|
500
|
+
transition-all duration-300 ease-in-out
|
|
501
|
+
active:scale-95
|
|
502
|
+
${isSpeechToText
|
|
503
|
+
? "border-none animate-pulse bg-gray-800"
|
|
504
|
+
: 'bg-transparent hover:bg-gray-900 cursor-pointer border-none shadow-sm hover:shadow-md'
|
|
505
|
+
}
|
|
506
|
+
`}
|
|
507
|
+
title="Speech To Text"
|
|
508
|
+
aria-label={`${isSpeechToText ? 'Disable' : 'Enable'} speech to text`}
|
|
509
|
+
>
|
|
510
|
+
<div className="relative z-10 flex items-center space-x-2">
|
|
511
|
+
<Mic className={`w-4 h-4 transition-all duration-300 ${isSpeechToText ? 'animate-bounce' : ''
|
|
512
|
+
}`} />
|
|
513
|
+
</div>
|
|
514
|
+
</Button>
|
|
515
|
+
)}
|
|
516
|
+
|
|
517
|
+
<ModeToggle />
|
|
518
|
+
</div>
|
|
519
|
+
</div>
|
|
520
|
+
</nav>
|
|
521
|
+
);
|
|
522
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
4
|
+
import {$insertNodeToNearestRoot} from '@lexical/utils';
|
|
5
|
+
import {COMMAND_PRIORITY_EDITOR, createCommand, LexicalCommand} from 'lexical';
|
|
6
|
+
import {JSX, useEffect} from 'react';
|
|
7
|
+
|
|
8
|
+
import {$createTweetNode, TweetNode} from '../../nodes/TweetNode';
|
|
9
|
+
|
|
10
|
+
export const INSERT_TWEET_COMMAND: LexicalCommand<string> = createCommand(
|
|
11
|
+
'INSERT_TWEET_COMMAND',
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default function TwitterPlugin(): JSX.Element | null {
|
|
15
|
+
const [editor] = useLexicalComposerContext();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!editor.hasNodes([TweetNode])) {
|
|
19
|
+
throw new Error('TwitterPlugin: TweetNode not registered on editor');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return editor.registerCommand<string>(
|
|
23
|
+
INSERT_TWEET_COMMAND,
|
|
24
|
+
(payload) => {
|
|
25
|
+
const tweetNode = $createTweetNode(payload);
|
|
26
|
+
$insertNodeToNearestRoot(tweetNode);
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
COMMAND_PRIORITY_EDITOR,
|
|
31
|
+
);
|
|
32
|
+
}, [editor]);
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
}
|