@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,346 @@
|
|
|
1
|
+
import { blockTypeToBlockName } from "@/components/providers/ToolbarContext";
|
|
2
|
+
import {
|
|
3
|
+
$getSelection,
|
|
4
|
+
COMMAND_PRIORITY_LOW,
|
|
5
|
+
FORMAT_TEXT_COMMAND,
|
|
6
|
+
getDOMSelection,
|
|
7
|
+
LexicalEditor,
|
|
8
|
+
SELECTION_CHANGE_COMMAND,
|
|
9
|
+
} from "lexical";
|
|
10
|
+
import { Dispatch, useCallback, useEffect, useRef } from "react";
|
|
11
|
+
import { TOGGLE_LINK_COMMAND } from "@lexical/link";
|
|
12
|
+
import { getDOMRangeRect } from "@/components/editor/utils/getDOMRangeRect";
|
|
13
|
+
import { setFloatingElemPosition } from "@/components/editor/utils/setFloatingElemPosition";
|
|
14
|
+
import { mergeRegister } from "@lexical/utils";
|
|
15
|
+
import { Separator } from "@/components/ui/separator";
|
|
16
|
+
import BlockFormatDropDown from "../drop-downs/block-format";
|
|
17
|
+
import { useIsMobile } from "@/components/editor/hooks/use-mobile";
|
|
18
|
+
import { Toggle } from "@/components/ui/toggle";
|
|
19
|
+
import { SHORTCUTS } from "@/components/editor/plugins/ShortcutsPlugin/shortcuts";
|
|
20
|
+
import { Bold, Code, Italic, Link, UnderlineIcon } from "lucide-react";
|
|
21
|
+
import Color from "../drop-downs/color";
|
|
22
|
+
import { sanitizeUrl } from "@/components/editor/utils/url";
|
|
23
|
+
import TextFormat from "../drop-downs/text-format";
|
|
24
|
+
import Font from "../drop-downs/font";
|
|
25
|
+
import FontSize from "../drop-downs/font-size";
|
|
26
|
+
import AiButton from "../ai/ai-button";
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export default function TextFormatFloatingToolbar({
|
|
34
|
+
editor,
|
|
35
|
+
anchorElem,
|
|
36
|
+
isLink,
|
|
37
|
+
isBold,
|
|
38
|
+
isItalic,
|
|
39
|
+
isUnderline,
|
|
40
|
+
isUppercase,
|
|
41
|
+
isLowercase,
|
|
42
|
+
isCapitalize,
|
|
43
|
+
isCode,
|
|
44
|
+
fontColor,
|
|
45
|
+
isStrikethrough,
|
|
46
|
+
isSubscript,
|
|
47
|
+
isSuperscript,
|
|
48
|
+
bgColor,
|
|
49
|
+
setIsLinkEditMode,
|
|
50
|
+
blockType,
|
|
51
|
+
fontFamily,
|
|
52
|
+
rootType,
|
|
53
|
+
textAlign,
|
|
54
|
+
fontSize,
|
|
55
|
+
}: {
|
|
56
|
+
editor: LexicalEditor;
|
|
57
|
+
anchorElem: HTMLElement;
|
|
58
|
+
isBold: boolean;
|
|
59
|
+
isCode: boolean;
|
|
60
|
+
bgColor: string;
|
|
61
|
+
fontColor: string;
|
|
62
|
+
isItalic: boolean;
|
|
63
|
+
isLink: boolean;
|
|
64
|
+
fontFamily: string;
|
|
65
|
+
isUppercase: boolean;
|
|
66
|
+
isLowercase: boolean;
|
|
67
|
+
fontSize: string;
|
|
68
|
+
isCapitalize: boolean;
|
|
69
|
+
isStrikethrough: boolean;
|
|
70
|
+
isSubscript: boolean;
|
|
71
|
+
isSuperscript: boolean;
|
|
72
|
+
isUnderline: boolean;
|
|
73
|
+
setIsLinkEditMode: Dispatch<boolean>;
|
|
74
|
+
blockType: keyof typeof blockTypeToBlockName;
|
|
75
|
+
rootType: "root" | "table";
|
|
76
|
+
textAlign: "left" | "center" | "right" | "justify" | null;
|
|
77
|
+
}): React.JSX.Element {
|
|
78
|
+
const popupCharStylesEditorRef = useRef<HTMLDivElement | null>(null);
|
|
79
|
+
const isSmall = useIsMobile();
|
|
80
|
+
|
|
81
|
+
const insertLink = useCallback(() => {
|
|
82
|
+
if (!isLink) {
|
|
83
|
+
setIsLinkEditMode(true);
|
|
84
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl("https://"));
|
|
85
|
+
} else {
|
|
86
|
+
setIsLinkEditMode(false);
|
|
87
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
88
|
+
}
|
|
89
|
+
}, [editor, setIsLinkEditMode, isLink]);
|
|
90
|
+
function mouseMoveListener(e: MouseEvent) {
|
|
91
|
+
if (
|
|
92
|
+
popupCharStylesEditorRef?.current &&
|
|
93
|
+
(e.buttons === 1 || e.buttons === 3)
|
|
94
|
+
) {
|
|
95
|
+
if (popupCharStylesEditorRef.current.style.pointerEvents !== "none") {
|
|
96
|
+
const x = e.clientX;
|
|
97
|
+
const y = e.clientY;
|
|
98
|
+
const elementUnderMouse = document.elementFromPoint(x, y);
|
|
99
|
+
|
|
100
|
+
if (!popupCharStylesEditorRef.current.contains(elementUnderMouse)) {
|
|
101
|
+
// Mouse is not over the target element => not a normal click, but probably a drag
|
|
102
|
+
popupCharStylesEditorRef.current.style.pointerEvents = "none";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function mouseUpListener(e: MouseEvent) {
|
|
108
|
+
if (popupCharStylesEditorRef?.current) {
|
|
109
|
+
if (popupCharStylesEditorRef.current.style.pointerEvents !== "auto") {
|
|
110
|
+
popupCharStylesEditorRef.current.style.pointerEvents = "auto";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (popupCharStylesEditorRef?.current) {
|
|
117
|
+
document.addEventListener("mousemove", mouseMoveListener);
|
|
118
|
+
document.addEventListener("mouseup", mouseUpListener);
|
|
119
|
+
|
|
120
|
+
return () => {
|
|
121
|
+
document.removeEventListener("mousemove", mouseMoveListener);
|
|
122
|
+
document.removeEventListener("mouseup", mouseUpListener);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, [popupCharStylesEditorRef]);
|
|
126
|
+
|
|
127
|
+
const $updateTextFormatFloatingToolbar = useCallback(() => {
|
|
128
|
+
const selection = $getSelection();
|
|
129
|
+
const popupCharStylesEditorElem = popupCharStylesEditorRef.current;
|
|
130
|
+
const nativeSelection = getDOMSelection(editor._window);
|
|
131
|
+
|
|
132
|
+
if (!popupCharStylesEditorElem) return;
|
|
133
|
+
|
|
134
|
+
const rootElement = editor.getRootElement();
|
|
135
|
+
if (
|
|
136
|
+
selection &&
|
|
137
|
+
nativeSelection &&
|
|
138
|
+
!nativeSelection.isCollapsed &&
|
|
139
|
+
rootElement &&
|
|
140
|
+
rootElement.contains(nativeSelection.anchorNode)
|
|
141
|
+
) {
|
|
142
|
+
const rangeRect = getDOMRangeRect(nativeSelection, rootElement);
|
|
143
|
+
|
|
144
|
+
setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);
|
|
145
|
+
}
|
|
146
|
+
}, [editor, anchorElem]);
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const scrollerElem = anchorElem.parentElement;
|
|
153
|
+
|
|
154
|
+
const update = () => {
|
|
155
|
+
editor.getEditorState().read(() => {
|
|
156
|
+
$updateTextFormatFloatingToolbar();
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
window.addEventListener("resize", update);
|
|
161
|
+
if (scrollerElem) {
|
|
162
|
+
scrollerElem.addEventListener("scroll", update);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return () => {
|
|
166
|
+
window.removeEventListener("resize", update);
|
|
167
|
+
if (scrollerElem) {
|
|
168
|
+
scrollerElem.removeEventListener("scroll", update);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}, [editor, $updateTextFormatFloatingToolbar, anchorElem]);
|
|
172
|
+
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
editor.getEditorState().read(() => {
|
|
175
|
+
$updateTextFormatFloatingToolbar();
|
|
176
|
+
});
|
|
177
|
+
return mergeRegister(
|
|
178
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
179
|
+
editorState.read(() => {
|
|
180
|
+
$updateTextFormatFloatingToolbar();
|
|
181
|
+
});
|
|
182
|
+
}),
|
|
183
|
+
|
|
184
|
+
editor.registerCommand(
|
|
185
|
+
SELECTION_CHANGE_COMMAND,
|
|
186
|
+
() => {
|
|
187
|
+
$updateTextFormatFloatingToolbar();
|
|
188
|
+
return false;
|
|
189
|
+
},
|
|
190
|
+
COMMAND_PRIORITY_LOW
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
}, [editor, $updateTextFormatFloatingToolbar]);
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div
|
|
198
|
+
id="toolbar"
|
|
199
|
+
ref={popupCharStylesEditorRef}
|
|
200
|
+
className={`
|
|
201
|
+
h-[30px] p-1 px-2 max-sm:p-2 max-sm:h-[295px] max-sm:w-[32px] max-sm:overflow-y-auto
|
|
202
|
+
border dark:border-zinc-800 dark:bg-zinc-900 text-zinc-950 dark:text-zinc-50 border-zinc-200 bg-white/90
|
|
203
|
+
inline-flex flex-row max-sm:flex-col items-center shadow-md absolute top-0 left-0 text-sm rounded-[6px]
|
|
204
|
+
`}
|
|
205
|
+
>
|
|
206
|
+
<AiButton editor={editor}/>
|
|
207
|
+
<Separator
|
|
208
|
+
orientation="vertical"
|
|
209
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
210
|
+
/>
|
|
211
|
+
<BlockFormatDropDown
|
|
212
|
+
editor={editor}
|
|
213
|
+
blockType={blockType}
|
|
214
|
+
style={{ height: "25px" }}
|
|
215
|
+
ShowChevronsUpDown={false}
|
|
216
|
+
side={isSmall ? "right" : "bottom"}
|
|
217
|
+
sideOffset={isSmall ? 10 : 5}
|
|
218
|
+
/>
|
|
219
|
+
<Separator
|
|
220
|
+
orientation="vertical"
|
|
221
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
222
|
+
/>
|
|
223
|
+
<FontSize
|
|
224
|
+
selectionFontSize={fontSize.slice(0, -2)}
|
|
225
|
+
editor={editor}
|
|
226
|
+
disabled={false}
|
|
227
|
+
className="h-[25px]"
|
|
228
|
+
classNameContent="max-sm:flex-col"
|
|
229
|
+
/>
|
|
230
|
+
<Separator
|
|
231
|
+
orientation="vertical"
|
|
232
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
233
|
+
/>
|
|
234
|
+
<Font
|
|
235
|
+
disabled={false}
|
|
236
|
+
style={{ fontFamily: fontFamily, height: "25px", padding: "0px 13px" }}
|
|
237
|
+
value={fontFamily}
|
|
238
|
+
editor={editor}
|
|
239
|
+
ShowChevronsUpDown={false}
|
|
240
|
+
side={isSmall ? "right" : "bottom"}
|
|
241
|
+
sideOffset={isSmall ? 10 : 5}
|
|
242
|
+
/>
|
|
243
|
+
<Separator
|
|
244
|
+
orientation="vertical"
|
|
245
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
246
|
+
/>
|
|
247
|
+
<div className="flex flex-row max-sm:flex-col gap-1 items-center justify-center">
|
|
248
|
+
<Toggle
|
|
249
|
+
variant={"outline"}
|
|
250
|
+
size={"floting"}
|
|
251
|
+
pressed={isBold}
|
|
252
|
+
onPressedChange={() => {
|
|
253
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
|
254
|
+
}}
|
|
255
|
+
tip={`Bold ${SHORTCUTS.BOLD}`}
|
|
256
|
+
aria-label={`Format text as bold. Shortcut: ${SHORTCUTS.BOLD}`}
|
|
257
|
+
>
|
|
258
|
+
<Bold />
|
|
259
|
+
</Toggle>
|
|
260
|
+
<Toggle
|
|
261
|
+
variant={"outline"}
|
|
262
|
+
size={"floting"}
|
|
263
|
+
pressed={isItalic}
|
|
264
|
+
onPressedChange={() => {
|
|
265
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
266
|
+
}}
|
|
267
|
+
tip={`Italic (${SHORTCUTS.ITALIC})`}
|
|
268
|
+
type="button"
|
|
269
|
+
aria-label={`Format text as italics. Shortcut: ${SHORTCUTS.ITALIC}`}
|
|
270
|
+
>
|
|
271
|
+
<Italic />
|
|
272
|
+
</Toggle>
|
|
273
|
+
<Toggle
|
|
274
|
+
variant={"outline"}
|
|
275
|
+
size={"floting"}
|
|
276
|
+
pressed={isUnderline}
|
|
277
|
+
onPressedChange={() => {
|
|
278
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
|
|
279
|
+
}}
|
|
280
|
+
tip={`Underline (${SHORTCUTS.UNDERLINE})`}
|
|
281
|
+
type="button"
|
|
282
|
+
aria-label={`Format text to underlined. Shortcut: ${SHORTCUTS.UNDERLINE}`}
|
|
283
|
+
>
|
|
284
|
+
<UnderlineIcon />
|
|
285
|
+
</Toggle>
|
|
286
|
+
<Toggle
|
|
287
|
+
variant={"outline"}
|
|
288
|
+
size={"floting"}
|
|
289
|
+
pressed={isCode}
|
|
290
|
+
onPressedChange={() => {
|
|
291
|
+
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "code");
|
|
292
|
+
}}
|
|
293
|
+
tip={`Insert code block (${SHORTCUTS.INSERT_CODE_BLOCK})`}
|
|
294
|
+
type="button"
|
|
295
|
+
aria-label="Insert code block"
|
|
296
|
+
>
|
|
297
|
+
<Code />
|
|
298
|
+
</Toggle>
|
|
299
|
+
<Toggle
|
|
300
|
+
variant={"outline"}
|
|
301
|
+
size={"floting"}
|
|
302
|
+
onPressedChange={insertLink}
|
|
303
|
+
pressed={isLink}
|
|
304
|
+
aria-label="Insert link"
|
|
305
|
+
tip={`Insert link (${SHORTCUTS.INSERT_LINK})`}
|
|
306
|
+
type="button"
|
|
307
|
+
>
|
|
308
|
+
<Link />
|
|
309
|
+
</Toggle>
|
|
310
|
+
</div>
|
|
311
|
+
<Separator
|
|
312
|
+
orientation="vertical"
|
|
313
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
314
|
+
/>
|
|
315
|
+
<Color
|
|
316
|
+
disabled={false}
|
|
317
|
+
side={isSmall ? "right" : "bottom"}
|
|
318
|
+
sideOffset={isSmall ? 10 : 5}
|
|
319
|
+
style={{ height: "25px" }}
|
|
320
|
+
color={fontColor}
|
|
321
|
+
bgColor={bgColor}
|
|
322
|
+
editor={editor}
|
|
323
|
+
/>
|
|
324
|
+
<Separator
|
|
325
|
+
orientation="vertical"
|
|
326
|
+
className="max-sm:h-[1px] max-sm:my-1 max-sm:w-5 h-5 mx-1"
|
|
327
|
+
/>
|
|
328
|
+
<TextFormat
|
|
329
|
+
disabled={false}
|
|
330
|
+
editor={editor}
|
|
331
|
+
ShowChevronsUpDown={false}
|
|
332
|
+
side={isSmall ? "right" : "bottom"}
|
|
333
|
+
sideOffset={isSmall ? 10 : 5}
|
|
334
|
+
style={{ height: "2px" }}
|
|
335
|
+
toolbarState={{
|
|
336
|
+
isLowercase,
|
|
337
|
+
isUppercase,
|
|
338
|
+
isCapitalize,
|
|
339
|
+
isStrikethrough,
|
|
340
|
+
isSubscript,
|
|
341
|
+
isSuperscript
|
|
342
|
+
}}
|
|
343
|
+
/>
|
|
344
|
+
</div>
|
|
345
|
+
);
|
|
346
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { EdgeStoreRouter } from '@/app/api/edgestore/[...edgestore]/route';
|
|
4
|
+
import { createEdgeStoreProvider } from '@edgestore/react';
|
|
5
|
+
|
|
6
|
+
const { EdgeStoreProvider, useEdgeStore } =
|
|
7
|
+
createEdgeStoreProvider<EdgeStoreRouter>();
|
|
8
|
+
|
|
9
|
+
export { EdgeStoreProvider, useEdgeStore };
|
|
File without changes
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {SerializedDocument} from '@lexical/file';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
async function* generateReader<T = any>(
|
|
13
|
+
reader: ReadableStreamDefaultReader<T>,
|
|
14
|
+
) {
|
|
15
|
+
let done = false;
|
|
16
|
+
while (!done) {
|
|
17
|
+
const res = await reader.read();
|
|
18
|
+
const {value} = res;
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
yield value;
|
|
21
|
+
}
|
|
22
|
+
done = res.done;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function readBytestoString(
|
|
27
|
+
reader: ReadableStreamDefaultReader,
|
|
28
|
+
): Promise<string> {
|
|
29
|
+
const output = [];
|
|
30
|
+
const chunkSize = 0x8000;
|
|
31
|
+
for await (const value of generateReader(reader)) {
|
|
32
|
+
for (let i = 0; i < value.length; i += chunkSize) {
|
|
33
|
+
output.push(String.fromCharCode(...value.subarray(i, i + chunkSize)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return output.join('');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function docToHash(doc: SerializedDocument): Promise<string> {
|
|
40
|
+
const cs = new CompressionStream('gzip');
|
|
41
|
+
const writer = cs.writable.getWriter();
|
|
42
|
+
const [, output] = await Promise.all([
|
|
43
|
+
writer
|
|
44
|
+
.write(new TextEncoder().encode(JSON.stringify(doc)))
|
|
45
|
+
.then(() => writer.close()),
|
|
46
|
+
readBytestoString(cs.readable.getReader()),
|
|
47
|
+
]);
|
|
48
|
+
return `#doc=${btoa(output)
|
|
49
|
+
.replace(/\//g, '_')
|
|
50
|
+
.replace(/\+/g, '-')
|
|
51
|
+
.replace(/=+$/, '')}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function docFromHash(
|
|
55
|
+
hash: string,
|
|
56
|
+
): Promise<SerializedDocument | null> {
|
|
57
|
+
const m = /^#doc=(.*)$/.exec(hash);
|
|
58
|
+
if (!m) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const ds = new DecompressionStream('gzip');
|
|
62
|
+
const writer = ds.writable.getWriter();
|
|
63
|
+
const b64 = atob(m[1].replace(/_/g, '/').replace(/-/g, '+'));
|
|
64
|
+
const array = new Uint8Array(b64.length);
|
|
65
|
+
for (let i = 0; i < b64.length; i++) {
|
|
66
|
+
array[i] = b64.charCodeAt(i);
|
|
67
|
+
}
|
|
68
|
+
const closed = writer.write(array).then(() => writer.close());
|
|
69
|
+
const output = [];
|
|
70
|
+
for await (const chunk of generateReader(
|
|
71
|
+
ds.readable.pipeThrough(new TextDecoderStream()).getReader(),
|
|
72
|
+
)) {
|
|
73
|
+
output.push(chunk);
|
|
74
|
+
}
|
|
75
|
+
await closed;
|
|
76
|
+
return JSON.parse(output.join(''));
|
|
77
|
+
}
|