@collabchron/notiq 0.2.0 → 1.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.
Files changed (282) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +230 -39
  3. package/dist/CodeActionMenuPlugin-EINOY4U4.mjs +15 -0
  4. package/dist/DynamicBlockComponent-NRQJ4WW4.mjs +161 -0
  5. package/dist/EquationComponent-CB6DFIHV.mjs +154 -0
  6. package/dist/ExcalidrawComponent-XW6646OH.mjs +528 -0
  7. package/dist/ExcalidrawPlugin-ZFHT62IF.mjs +14 -0
  8. package/dist/ExportPlugin-V2RLM63S.mjs +11 -0
  9. package/dist/FloatingLinkEditorPlugin-TRTCMSP4.mjs +12 -0
  10. package/dist/FloatingTextFormatToolbarPlugin-F2GY6LMI.mjs +30 -0
  11. package/dist/HintComponet-BRL6EAMS.mjs +217 -0
  12. package/dist/InlineImageComponent-UWIUWBHI.mjs +453 -0
  13. package/dist/MobileToolbar-BOOZAMQE.mjs +268 -0
  14. package/dist/SlashCommand-GMT5JI33.mjs +28 -0
  15. package/dist/StoryBuilderComponent-JGDBM5JU.mjs +562 -0
  16. package/{src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx → dist/TableCellActionMenuPlugin-PGK2K3VG.mjs} +667 -759
  17. package/{src/components/editor/plugins/TableHoverActionsPlugin/index.tsx → dist/TableHoverActionsPlugin-GJVE6VRW.mjs} +258 -314
  18. package/dist/TemplatePlugin-ZD3QEVTI.mjs +9 -0
  19. package/dist/ToolbarPlugin-7TOZRD2R.mjs +1547 -0
  20. package/dist/babel-JZ2EV6AX.mjs +7233 -0
  21. package/dist/background-color-XZTYLGO2.mjs +362 -0
  22. package/dist/block-format-YJCV2DIY.mjs +15 -0
  23. package/dist/chunk-2FNEAMSP.mjs +127 -0
  24. package/dist/chunk-3CPBODXA.mjs +84 -0
  25. package/dist/chunk-3G37YKTV.mjs +83 -0
  26. package/dist/chunk-3JVFG7ER.mjs +184 -0
  27. package/dist/chunk-456TN7IM.mjs +110 -0
  28. package/dist/chunk-4EXYCTGJ.mjs +27 -0
  29. package/{src/utils/getSelectedNode.ts → dist/chunk-4HBCVSE6.mjs} +26 -27
  30. package/dist/chunk-4MEDW3T6.mjs +125 -0
  31. package/dist/chunk-4VWFVWYP.mjs +36 -0
  32. package/dist/chunk-5BAKY5KN.mjs +84 -0
  33. package/dist/chunk-5QSNIVIG.mjs +333 -0
  34. package/dist/chunk-64Z3FI7T.mjs +37 -0
  35. package/{src/components/editor/nodes/Stepper/index.tsx → dist/chunk-6RNZQOH2.mjs} +214 -260
  36. package/dist/chunk-77KXU36M.mjs +64 -0
  37. package/dist/chunk-77UA6HYR.mjs +165 -0
  38. package/dist/chunk-7NZAPJ4G.mjs +102 -0
  39. package/dist/chunk-7VUMHWWL.mjs +152 -0
  40. package/dist/chunk-AMMKBSST.mjs +1256 -0
  41. package/dist/chunk-BIU7WTLX.mjs +95 -0
  42. package/dist/chunk-EGMI62PP.mjs +83 -0
  43. package/dist/chunk-EHNQD5KO.mjs +88 -0
  44. package/dist/chunk-FSM26655.mjs +37 -0
  45. package/{src/components/editor/nodes/Hint/index.tsx → dist/chunk-G53GLEAY.mjs} +158 -190
  46. package/dist/chunk-GK35L7UY.mjs +28 -0
  47. package/dist/chunk-GXYD4VZM.mjs +193 -0
  48. package/dist/chunk-GYIOYVCN.mjs +538 -0
  49. package/dist/chunk-GZPNVR7L.mjs +157 -0
  50. package/dist/chunk-JXDPPUJI.mjs +52 -0
  51. package/dist/chunk-K36V4SIW.mjs +141 -0
  52. package/dist/chunk-KJ6AJ44Q.mjs +128 -0
  53. package/dist/chunk-KJV3FAZ7.mjs +142 -0
  54. package/{src/components/editor/plugins/ImagesPlugin/index.tsx → dist/chunk-LGG4IUIA.mjs} +189 -222
  55. package/dist/chunk-LQN3CMKV.mjs +1906 -0
  56. package/dist/chunk-N3WN46VL.mjs +236 -0
  57. package/dist/chunk-PBD6LMLC.mjs +366 -0
  58. package/dist/chunk-POGRR73N.mjs +33 -0
  59. package/{src/components/editor/utils/editorFormatting.ts → dist/chunk-PZSUSXQG.mjs} +238 -282
  60. package/dist/chunk-QEIFVK5M.mjs +29 -0
  61. package/dist/chunk-QHIQKMVN.mjs +427 -0
  62. package/dist/chunk-TCYK7DM7.mjs +36 -0
  63. package/dist/chunk-TTHQCW5F.mjs +47 -0
  64. package/dist/chunk-U47ABU5Z.mjs +53 -0
  65. package/dist/chunk-WDG7J2DY.mjs +116 -0
  66. package/dist/chunk-WJRHXI2C.mjs +733 -0
  67. package/dist/chunk-XLER2DHM.mjs +357 -0
  68. package/dist/chunk-XWC4TK2N.mjs +315 -0
  69. package/dist/chunk-YHPNOWFH.mjs +15 -0
  70. package/dist/chunk-YKC3SO4Z.mjs +32 -0
  71. package/dist/chunk-YMBXLRW5.mjs +374 -0
  72. package/dist/chunk-YPHOEJ46.mjs +64 -0
  73. package/dist/chunk-YUDCJRJM.mjs +25 -0
  74. package/dist/chunk-Z4EWP7BI.mjs +65 -0
  75. package/dist/chunk-ZB5LZQKC.mjs +191 -0
  76. package/dist/chunk-ZJRKATOJ.mjs +65 -0
  77. package/dist/color-BPKOPQKN.mjs +12 -0
  78. package/dist/estree-XC56IUFX.mjs +4414 -0
  79. package/dist/font-FEZ3GKSF.mjs +13 -0
  80. package/dist/font-size-EK775WRH.mjs +15 -0
  81. package/dist/html-S3ACX7NI.mjs +2738 -0
  82. package/dist/image-2PJIAYAT.mjs +993 -0
  83. package/dist/index.d.mts +145 -0
  84. package/dist/index.d.ts +145 -0
  85. package/dist/index.js +57855 -0
  86. package/dist/index.mjs +1790 -0
  87. package/dist/insert-gif-SAIDYURE.mjs +100 -0
  88. package/dist/insert-image-U3RJN3OW.mjs +259 -0
  89. package/dist/insert-node-5P2CRJ7S.mjs +201 -0
  90. package/dist/insert-poll-HCPM7MO6.mjs +33 -0
  91. package/dist/insert-table-24XYUS2W.mjs +66 -0
  92. package/dist/markdown-SNVBOSRA.mjs +3487 -0
  93. package/dist/poll-component-2R4MDLHS.mjs +303 -0
  94. package/dist/postcss-ONF3VDIM.mjs +5051 -0
  95. package/dist/standalone-EOIALU3M.mjs +2373 -0
  96. package/dist/stepper-FSARL6X6.mjs +304 -0
  97. package/dist/styles/notiq.css +1149 -0
  98. package/dist/text-align-VLECWO4H.mjs +118 -0
  99. package/dist/text-format-BG5WOOPZ.mjs +16 -0
  100. package/dist/typescript-AMPI6OVS.mjs +13135 -0
  101. package/package.json +94 -10
  102. package/src/styles/notiq.css +1149 -0
  103. package/src/styles/tailwind-plugin.ts +134 -0
  104. package/components.json +0 -21
  105. package/eslint.config.mjs +0 -16
  106. package/next.config.ts +0 -12
  107. package/postcss.config.mjs +0 -5
  108. package/public/file.svg +0 -1
  109. package/public/globe.svg +0 -1
  110. package/public/images/icons/plus.svg +0 -10
  111. package/public/next.svg +0 -1
  112. package/public/vercel.svg +0 -1
  113. package/public/window.svg +0 -1
  114. package/src/app/actions.ts +0 -2
  115. package/src/app/api/ai/route.ts +0 -175
  116. package/src/app/api/edgestore/[...edgestore]/route.ts +0 -28
  117. package/src/app/favicon.ico +0 -0
  118. package/src/app/globals.css +0 -205
  119. package/src/app/layout.tsx +0 -38
  120. package/src/app/page.tsx +0 -12
  121. package/src/components/editor/Core.tsx +0 -220
  122. package/src/components/editor/hooks/instructions-messages.ts +0 -300
  123. package/src/components/editor/hooks/use-mobile.ts +0 -19
  124. package/src/components/editor/hooks/useReport.ts +0 -67
  125. package/src/components/editor/hooks/useResizeObservert.ts +0 -22
  126. package/src/components/editor/index.tsx +0 -39
  127. package/src/components/editor/lexical-on-change.tsx +0 -28
  128. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +0 -92
  129. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +0 -65
  130. package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +0 -105
  131. package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +0 -143
  132. package/src/components/editor/nodes/EquationNode/EquationNode.tsx +0 -170
  133. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +0 -228
  134. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +0 -137
  135. package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +0 -317
  136. package/src/components/editor/nodes/ExcalidrawNode/index.tsx +0 -204
  137. package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +0 -134
  138. package/src/components/editor/nodes/Hint/HintComponet.tsx +0 -221
  139. package/src/components/editor/nodes/ImageNode/index.tsx +0 -328
  140. package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +0 -383
  141. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +0 -94
  142. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +0 -309
  143. package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +0 -146
  144. package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +0 -79
  145. package/src/components/editor/nodes/PollNode/index.tsx +0 -204
  146. package/src/components/editor/nodes/TweetNode/index.tsx +0 -214
  147. package/src/components/editor/nodes/index.ts +0 -81
  148. package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +0 -350
  149. package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +0 -56
  150. package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +0 -70
  151. package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +0 -192
  152. package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +0 -217
  153. package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +0 -26
  154. package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +0 -21
  155. package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +0 -76
  156. package/src/components/editor/plugins/CollapsiblePlugin/index.ts +0 -228
  157. package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +0 -44
  158. package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +0 -52
  159. package/src/components/editor/plugins/EquationsPlugin/index.tsx +0 -85
  160. package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +0 -98
  161. package/src/components/editor/plugins/FigmaPlugin/index.tsx +0 -42
  162. package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +0 -445
  163. package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +0 -275
  164. package/src/components/editor/plugins/InlineImagePlugin/index.tsx +0 -351
  165. package/src/components/editor/plugins/LayoutPlugin/index.tsx +0 -238
  166. package/src/components/editor/plugins/LinkPlugin/index.tsx +0 -36
  167. package/src/components/editor/plugins/LinkWithMetaData/index.tsx +0 -271
  168. package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +0 -11
  169. package/src/components/editor/plugins/MarkdownTransformers/index.tsx +0 -304
  170. package/src/components/editor/plugins/PollPlugin/index.tsx +0 -49
  171. package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +0 -180
  172. package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +0 -253
  173. package/src/components/editor/plugins/SlashCommand/index.tsx +0 -621
  174. package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +0 -127
  175. package/src/components/editor/plugins/TabFocusPlugin/index.ts +0 -58
  176. package/src/components/editor/plugins/TableCellResizer/index.tsx +0 -438
  177. package/src/components/editor/plugins/TablePlugin/index.tsx +0 -99
  178. package/src/components/editor/plugins/ToolbarPlugin/index.tsx +0 -522
  179. package/src/components/editor/plugins/TwitterPlugin/index.ts +0 -35
  180. package/src/components/editor/plugins/YouTubeNode/index.tsx +0 -179
  181. package/src/components/editor/plugins/YouTubePlugin/index.ts +0 -41
  182. package/src/components/editor/themes/editor-theme.ts +0 -113
  183. package/src/components/editor/themes/theme.css +0 -377
  184. package/src/components/editor/utils/ai.ts +0 -291
  185. package/src/components/editor/utils/canUseDOM.ts +0 -12
  186. package/src/components/editor/utils/environment.ts +0 -50
  187. package/src/components/editor/utils/extract-data.ts +0 -166
  188. package/src/components/editor/utils/getAllLexicalChildren.ts +0 -13
  189. package/src/components/editor/utils/getDOMRangeRect.ts +0 -27
  190. package/src/components/editor/utils/getSelectedNode.ts +0 -27
  191. package/src/components/editor/utils/gif.ts +0 -29
  192. package/src/components/editor/utils/invariant.ts +0 -15
  193. package/src/components/editor/utils/setFloatingElemPosition.ts +0 -51
  194. package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +0 -40
  195. package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +0 -51
  196. package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +0 -15
  197. package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +0 -114
  198. package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +0 -6
  199. package/src/components/editor/utils/url.ts +0 -109
  200. package/src/components/editor/utils/useLayoutEffect.ts +0 -13
  201. package/src/components/providers/QueryProvider.tsx +0 -15
  202. package/src/components/providers/SharedHistoryContext.tsx +0 -28
  203. package/src/components/providers/ToolbarContext.tsx +0 -123
  204. package/src/components/providers/theme-provider.tsx +0 -11
  205. package/src/components/theme/ModeToggle.tsx +0 -40
  206. package/src/components/ui/FileInput.tsx +0 -40
  207. package/src/components/ui/Input.css +0 -32
  208. package/src/components/ui/Select.css +0 -42
  209. package/src/components/ui/Select.tsx +0 -36
  210. package/src/components/ui/TextInput.tsx +0 -48
  211. package/src/components/ui/ai/ai-button.tsx +0 -574
  212. package/src/components/ui/ai/border.tsx +0 -99
  213. package/src/components/ui/ai/placeholder-input-vanish.tsx +0 -282
  214. package/src/components/ui/button.tsx +0 -89
  215. package/src/components/ui/card.tsx +0 -76
  216. package/src/components/ui/checkbox.tsx +0 -30
  217. package/src/components/ui/command.tsx +0 -153
  218. package/src/components/ui/dialog/Dialog.css +0 -25
  219. package/src/components/ui/dialog/Dialog.tsx +0 -34
  220. package/src/components/ui/dialog.tsx +0 -122
  221. package/src/components/ui/drop-downs/background-color.tsx +0 -183
  222. package/src/components/ui/drop-downs/block-format.tsx +0 -159
  223. package/src/components/ui/drop-downs/code.tsx +0 -42
  224. package/src/components/ui/drop-downs/color.tsx +0 -177
  225. package/src/components/ui/drop-downs/font-size.tsx +0 -138
  226. package/src/components/ui/drop-downs/font.tsx +0 -155
  227. package/src/components/ui/drop-downs/index.tsx +0 -122
  228. package/src/components/ui/drop-downs/insert-node.tsx +0 -213
  229. package/src/components/ui/drop-downs/text-align.tsx +0 -123
  230. package/src/components/ui/drop-downs/text-format.tsx +0 -104
  231. package/src/components/ui/dropdown-menu.tsx +0 -201
  232. package/src/components/ui/equation/EquationEditor.css +0 -38
  233. package/src/components/ui/equation/EquationEditor.tsx +0 -56
  234. package/src/components/ui/equation/KatexEquationAlterer.css +0 -41
  235. package/src/components/ui/equation/KatexEquationAlterer.tsx +0 -83
  236. package/src/components/ui/equation/KatexRenderer.tsx +0 -66
  237. package/src/components/ui/excalidraw/ExcalidrawModal.css +0 -64
  238. package/src/components/ui/excalidraw/ExcalidrawModal.tsx +0 -234
  239. package/src/components/ui/excalidraw/Modal.css +0 -62
  240. package/src/components/ui/excalidraw/Modal.tsx +0 -110
  241. package/src/components/ui/hover-card.tsx +0 -29
  242. package/src/components/ui/image/error-image.tsx +0 -17
  243. package/src/components/ui/image/file-upload.tsx +0 -240
  244. package/src/components/ui/image/image-resizer.tsx +0 -297
  245. package/src/components/ui/image/image-toolbar.tsx +0 -264
  246. package/src/components/ui/image/index.tsx +0 -408
  247. package/src/components/ui/image/lazy-image.tsx +0 -68
  248. package/src/components/ui/image/lazy-video.tsx +0 -71
  249. package/src/components/ui/input.tsx +0 -22
  250. package/src/components/ui/models/custom-dialog.tsx +0 -320
  251. package/src/components/ui/models/insert-gif.tsx +0 -90
  252. package/src/components/ui/models/insert-image.tsx +0 -52
  253. package/src/components/ui/models/insert-poll.tsx +0 -29
  254. package/src/components/ui/models/insert-table.tsx +0 -62
  255. package/src/components/ui/models/use-model.tsx +0 -91
  256. package/src/components/ui/poll/poll-component.tsx +0 -304
  257. package/src/components/ui/popover.tsx +0 -33
  258. package/src/components/ui/progress.tsx +0 -28
  259. package/src/components/ui/scroll-area.tsx +0 -48
  260. package/src/components/ui/separator.tsx +0 -31
  261. package/src/components/ui/skeleton.tsx +0 -15
  262. package/src/components/ui/sonner.tsx +0 -31
  263. package/src/components/ui/stepper/step.tsx +0 -179
  264. package/src/components/ui/stepper/stepper.tsx +0 -89
  265. package/src/components/ui/textarea.tsx +0 -22
  266. package/src/components/ui/toggle.tsx +0 -71
  267. package/src/components/ui/tooltip.tsx +0 -32
  268. package/src/components/ui/write/text-format-floting-toolbar.tsx +0 -346
  269. package/src/lib/edgestore.ts +0 -9
  270. package/src/lib/pinecone-client.ts +0 -0
  271. package/src/lib/utils.ts +0 -6
  272. package/src/utils/docSerialization.ts +0 -77
  273. package/src/utils/emoji-list.ts +0 -16615
  274. package/src/utils/getDOMRangeRect.ts +0 -27
  275. package/src/utils/getThemeSelector.ts +0 -25
  276. package/src/utils/isMobileWidth.ts +0 -7
  277. package/src/utils/joinClasses.ts +0 -13
  278. package/src/utils/setFloatingElemPosition.ts +0 -74
  279. package/src/utils/setFloatingElemPositionForLinkEditor.ts +0 -46
  280. package/src/utils/swipe.ts +0 -127
  281. package/src/utils/url.ts +0 -38
  282. package/tsconfig.json +0 -27
@@ -1,85 +0,0 @@
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 type {JSX} from 'react';
10
-
11
- import 'katex/dist/katex.css';
12
-
13
- import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
14
- import {$wrapNodeInElement} from '@lexical/utils';
15
- import {
16
- $createParagraphNode,
17
- $insertNodes,
18
- $isRootOrShadowRoot,
19
- COMMAND_PRIORITY_EDITOR,
20
- createCommand,
21
- LexicalCommand,
22
- LexicalEditor,
23
- } from 'lexical';
24
- import {useCallback, useEffect} from 'react';
25
- import * as React from 'react';
26
-
27
- import {$createEquationNode, EquationNode} from '../../nodes/EquationNode/EquationNode';
28
- import KatexEquationAlterer from '@/components/ui/equation/KatexEquationAlterer';
29
-
30
-
31
- type CommandPayload = {
32
- equation: string;
33
- inline: boolean;
34
- };
35
-
36
- export const INSERT_EQUATION_COMMAND: LexicalCommand<CommandPayload> =
37
- createCommand('INSERT_EQUATION_COMMAND');
38
-
39
- export function InsertEquationDialog({
40
- activeEditor,
41
- onClose,
42
- }: {
43
- activeEditor: LexicalEditor;
44
- onClose: () => void;
45
- }): JSX.Element {
46
- const onEquationConfirm = useCallback(
47
- (equation: string, inline: boolean) => {
48
- activeEditor.dispatchCommand(INSERT_EQUATION_COMMAND, {equation, inline});
49
- onClose();
50
- },
51
- [activeEditor, onClose],
52
- );
53
-
54
- return <KatexEquationAlterer onConfirm={onEquationConfirm} />;
55
- }
56
-
57
- export default function EquationsPlugin(): JSX.Element | null {
58
- const [editor] = useLexicalComposerContext();
59
-
60
- useEffect(() => {
61
- if (!editor.hasNodes([EquationNode])) {
62
- throw new Error(
63
- 'EquationsPlugins: EquationsNode not registered on editor',
64
- );
65
- }
66
-
67
- return editor.registerCommand<CommandPayload>(
68
- INSERT_EQUATION_COMMAND,
69
- (payload) => {
70
- const {equation, inline} = payload;
71
- const equationNode = $createEquationNode(equation, inline);
72
-
73
- $insertNodes([equationNode]);
74
- if ($isRootOrShadowRoot(equationNode.getParentOrThrow())) {
75
- $wrapNodeInElement(equationNode, $createParagraphNode).selectEnd();
76
- }
77
-
78
- return true;
79
- },
80
- COMMAND_PRIORITY_EDITOR,
81
- );
82
- }, [editor]);
83
-
84
- return null;
85
- }
@@ -1,98 +0,0 @@
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
- import type {AppState, BinaryFiles} from '@excalidraw/excalidraw/types';
9
- import type {JSX} from 'react';
10
-
11
- import '@excalidraw/excalidraw/index.css';
12
-
13
- import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
14
- import {$wrapNodeInElement} from '@lexical/utils';
15
- import {
16
- $createParagraphNode,
17
- $insertNodes,
18
- $isRootOrShadowRoot,
19
- COMMAND_PRIORITY_EDITOR,
20
- createCommand,
21
- LexicalCommand,
22
- } from 'lexical';
23
- import {useEffect, useState} from 'react';
24
-
25
- import {
26
- $createExcalidrawNode,
27
- ExcalidrawNode,
28
- } from '../../nodes/ExcalidrawNode';
29
- import ExcalidrawModal, { ExcalidrawInitialElements } from '@/components/ui/excalidraw/ExcalidrawModal';
30
-
31
- export const INSERT_EXCALIDRAW_COMMAND: LexicalCommand<void> = createCommand(
32
- 'INSERT_EXCALIDRAW_COMMAND',
33
- );
34
-
35
- export default function ExcalidrawPlugin(): JSX.Element | null {
36
- const [editor] = useLexicalComposerContext();
37
- const [isModalOpen, setModalOpen] = useState<boolean>(false);
38
-
39
- useEffect(() => {
40
- if (!editor.hasNodes([ExcalidrawNode])) {
41
- throw new Error(
42
- 'ExcalidrawPlugin: ExcalidrawNode not registered on editor',
43
- );
44
- }
45
-
46
- return editor.registerCommand(
47
- INSERT_EXCALIDRAW_COMMAND,
48
- () => {
49
- setModalOpen(true);
50
- return true;
51
- },
52
- COMMAND_PRIORITY_EDITOR,
53
- );
54
- }, [editor]);
55
-
56
- const onClose = () => {
57
- setModalOpen(false);
58
- };
59
-
60
- const onDelete = () => {
61
- setModalOpen(false);
62
- };
63
-
64
- const onSave = (
65
- elements: ExcalidrawInitialElements,
66
- appState: Partial<AppState>,
67
- files: BinaryFiles,
68
- ) => {
69
- editor.update(() => {
70
- const excalidrawNode = $createExcalidrawNode();
71
- excalidrawNode.setData(
72
- JSON.stringify({
73
- appState,
74
- elements,
75
- files,
76
- }),
77
- );
78
- $insertNodes([excalidrawNode]);
79
- if ($isRootOrShadowRoot(excalidrawNode.getParentOrThrow())) {
80
- $wrapNodeInElement(excalidrawNode, $createParagraphNode).selectEnd();
81
- }
82
- });
83
- setModalOpen(false);
84
- };
85
-
86
- return isModalOpen ? (
87
- <ExcalidrawModal
88
- initialElements={[]}
89
- initialAppState={{} as AppState}
90
- initialFiles={{}}
91
- isShown={isModalOpen}
92
- onDelete={onDelete}
93
- onClose={onClose}
94
- onSave={onSave}
95
- closeOnClickOutside={false}
96
- />
97
- ) : null;
98
- }
@@ -1,42 +0,0 @@
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 type {JSX} from 'react';
10
-
11
- import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
12
- import {$insertNodeToNearestRoot} from '@lexical/utils';
13
- import {COMMAND_PRIORITY_EDITOR, createCommand, LexicalCommand} from 'lexical';
14
- import {useEffect} from 'react';
15
-
16
- import {$createFigmaNode, FigmaNode} from '../../nodes/FigmaNode/FigmaNode';
17
-
18
- export const INSERT_FIGMA_COMMAND: LexicalCommand<string> = createCommand(
19
- 'INSERT_FIGMA_COMMAND',
20
- );
21
-
22
- export default function FigmaPlugin(): JSX.Element | null {
23
- const [editor] = useLexicalComposerContext();
24
-
25
- useEffect(() => {
26
- if (!editor.hasNodes([FigmaNode])) {
27
- throw new Error('FigmaPlugin: FigmaNode not registered on editor');
28
- }
29
-
30
- return editor.registerCommand<string>(
31
- INSERT_FIGMA_COMMAND,
32
- (payload) => {
33
- const figmaNode = $createFigmaNode(payload);
34
- $insertNodeToNearestRoot(figmaNode);
35
- return true;
36
- },
37
- COMMAND_PRIORITY_EDITOR,
38
- );
39
- }, [editor]);
40
-
41
- return null;
42
- }
@@ -1,445 +0,0 @@
1
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
- import { Dispatch, JSX, useCallback, useEffect, useRef, useState } from "react";
3
- import { createPortal } from "react-dom";
4
- import { getSelectedNode } from "../../utils/getSelectedNode";
5
- import {
6
- $createLinkNode,
7
- $isAutoLinkNode,
8
- $isLinkNode,
9
- TOGGLE_LINK_COMMAND,
10
- } from "@lexical/link";
11
- import { $findMatchingParent, mergeRegister } from "@lexical/utils";
12
- import {
13
- $getSelection,
14
- $isLineBreakNode,
15
- $isRangeSelection,
16
- BaseSelection,
17
- CLICK_COMMAND,
18
- COMMAND_PRIORITY_CRITICAL,
19
- COMMAND_PRIORITY_HIGH,
20
- COMMAND_PRIORITY_LOW,
21
- getDOMSelection,
22
- KEY_ESCAPE_COMMAND,
23
- LexicalEditor,
24
- SELECTION_CHANGE_COMMAND,
25
- } from "lexical";
26
- import { sanitizeUrl } from "../../utils/url";
27
- import { setFloatingElemPositionForLinkEditor } from "../../utils/setFloatingElemPositionForLinkEditor";
28
- import { Input } from "@/components/ui/input";
29
- import { Check, Edit2Icon, Link, X } from "lucide-react";
30
- import { cn } from "@/lib/utils";
31
- import { Button } from "@/components/ui/button";
32
-
33
- function preventDefault(
34
- event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLElement>
35
- ): void {
36
- event.preventDefault();
37
- }
38
-
39
- function FloatingLinkEditor({
40
- editor,
41
- isLink,
42
- setIsLink,
43
- anchorElem,
44
- isLinkEditMode,
45
- setIsLinkEditMode,
46
- }: {
47
- editor: LexicalEditor;
48
- isLink: boolean;
49
- setIsLink: Dispatch<boolean>;
50
- anchorElem: HTMLElement;
51
- isLinkEditMode: boolean;
52
- setIsLinkEditMode: Dispatch<boolean>;
53
- }): JSX.Element {
54
- const editorRef = useRef<HTMLDivElement | null>(null);
55
- const inputRef = useRef<HTMLInputElement>(null);
56
- const [linkUrl, setLinkUrl] = useState("");
57
- const [editedLinkUrl, setEditedLinkUrl] = useState("https://");
58
- const [lastSelection, setLastSelection] = useState<BaseSelection | null>(
59
- null
60
- );
61
-
62
- const [urlLogo, setUrlLogo] = useState<string | null>(null);
63
-
64
- const $updateLinkEditor = useCallback(() => {
65
- const selection = $getSelection();
66
- if ($isRangeSelection(selection)) {
67
- const node = getSelectedNode(selection);
68
- const linkParent = $findMatchingParent(node, $isLinkNode);
69
-
70
- if (linkParent) {
71
- setLinkUrl(linkParent.getURL());
72
- } else if ($isLinkNode(node)) {
73
- setLinkUrl(node.getURL());
74
- } else {
75
- setLinkUrl("");
76
- }
77
- if (isLinkEditMode) {
78
- setEditedLinkUrl(linkUrl);
79
- }
80
- }
81
- const editorElem = editorRef.current;
82
- const nativeSelection = getDOMSelection(editor._window);
83
- const activeElement = document.activeElement;
84
-
85
- if (editorElem === null) {
86
- return;
87
- }
88
-
89
- const rootElement = editor.getRootElement();
90
-
91
- if (
92
- selection !== null &&
93
- nativeSelection !== null &&
94
- rootElement !== null &&
95
- rootElement.contains(nativeSelection.anchorNode) &&
96
- editor.isEditable()
97
- ) {
98
- const domRect: DOMRect | undefined =
99
- nativeSelection.focusNode?.parentElement?.getBoundingClientRect();
100
- if (domRect) {
101
- domRect.y += 40;
102
- setFloatingElemPositionForLinkEditor(domRect, editorElem, anchorElem);
103
- }
104
- setLastSelection(selection);
105
- } else if (!activeElement || activeElement.className !== "link-input") {
106
- if (rootElement !== null) {
107
- setFloatingElemPositionForLinkEditor(null, editorElem, anchorElem);
108
- }
109
- setLastSelection(null);
110
- setIsLinkEditMode(false);
111
- setLinkUrl("");
112
- }
113
-
114
- return true;
115
- }, [anchorElem, editor, setIsLinkEditMode, isLinkEditMode, linkUrl]);
116
-
117
- useEffect(() => {
118
- const scrollerElem = anchorElem.parentElement;
119
-
120
- const update = () => {
121
- editor.getEditorState().read(() => {
122
- $updateLinkEditor();
123
- });
124
- };
125
-
126
- window.addEventListener("resize", update);
127
-
128
- if (scrollerElem) {
129
- scrollerElem.addEventListener("scroll", update);
130
- }
131
-
132
- return () => {
133
- window.removeEventListener("resize", update);
134
-
135
- if (scrollerElem) {
136
- scrollerElem.removeEventListener("scroll", update);
137
- }
138
- };
139
- }, [anchorElem.parentElement, editor, $updateLinkEditor]);
140
-
141
- useEffect(() => {
142
- return mergeRegister(
143
- editor.registerUpdateListener(({ editorState }) => {
144
- editorState.read(() => {
145
- $updateLinkEditor();
146
- });
147
- }),
148
-
149
- editor.registerCommand(
150
- SELECTION_CHANGE_COMMAND,
151
- () => {
152
- $updateLinkEditor();
153
- return true;
154
- },
155
- COMMAND_PRIORITY_LOW
156
- ),
157
- editor.registerCommand(
158
- KEY_ESCAPE_COMMAND,
159
- () => {
160
- if (isLink) {
161
- setIsLink(false);
162
- return true;
163
- }
164
- return false;
165
- },
166
- COMMAND_PRIORITY_HIGH
167
- )
168
- );
169
- }, [editor, $updateLinkEditor, setIsLink, isLink]);
170
-
171
- useEffect(() => {
172
- editor.getEditorState().read(() => {
173
- $updateLinkEditor();
174
- });
175
- }, [editor, $updateLinkEditor]);
176
-
177
- useEffect(() => {
178
- if (isLinkEditMode && inputRef.current) {
179
- inputRef.current.focus();
180
- }
181
- }, [isLinkEditMode, isLink]);
182
-
183
- const monitorInputInteraction = (
184
- event: React.KeyboardEvent<HTMLInputElement>
185
- ) => {
186
- if (event.key === "Enter") {
187
- handleLinkSubmission(event);
188
- } else if (event.key === "Escape") {
189
- event.preventDefault();
190
- setIsLinkEditMode(false);
191
- }
192
- };
193
-
194
- const handleLinkSubmission = (
195
- event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLElement>
196
- ) => {
197
- event.preventDefault();
198
-
199
- if (lastSelection !== null) {
200
- if (linkUrl !== "") {
201
- editor.update( () => {
202
- editor.dispatchCommand(
203
- TOGGLE_LINK_COMMAND,
204
- sanitizeUrl(editedLinkUrl)
205
- );
206
-
207
- const selection = $getSelection();
208
- if ($isRangeSelection(selection)) {
209
- const parent = getSelectedNode(selection).getParent();
210
- if ($isAutoLinkNode(parent)) {
211
- const linkNode = $createLinkNode(parent.getURL(), {
212
- rel: parent.__rel,
213
- target: parent.__target,
214
- title: parent.__title,
215
- });
216
- parent.replace(linkNode, true);
217
- }
218
- }
219
- });
220
- }
221
- // Fetch metadata asynchronously AFTER editor update
222
- setEditedLinkUrl("https://");
223
-
224
- setIsLinkEditMode(false);
225
- }
226
- };
227
-
228
- return (
229
- <div
230
- ref={editorRef}
231
- className=" absolute max-w-96 bg-background max-sm:mx-1 w-full border-0 top-0 left-0"
232
- >
233
- {isLinkEditMode ? (
234
- <div className=" relative w-full">
235
- <Link
236
- className={cn(
237
- "size-[14px] text-muted-foreground absolute transition-colors duration-500 transform -translate-x-1/2 -translate-y-1/2 left-4 top-1/2",
238
- !!editedLinkUrl && "text-black dark:text-white"
239
- )}
240
- />
241
- <Input
242
- placeholder="https://"
243
- value={editedLinkUrl}
244
- onChange={(event) => {
245
- setEditedLinkUrl(event.target.value);
246
- }}
247
- onKeyDown={(event) => {
248
- monitorInputInteraction(event);
249
- }}
250
- ref={inputRef}
251
- className="text-gray-900 pl-7 dark:text-gray-100 rounded-xl placeholder-gray-400 dark:placeholder-gray-500"
252
- />
253
- <div className=" absolute bg-background rounded-xl flex flex-row gap-x-1 items-center transition-colors duration-500 transform -translate-y-1/2 right-2 top-1/2">
254
- <Button
255
- className=" rounded-xl h-6 w-6 flex items-center"
256
- role="button"
257
- variant={"destructive"}
258
- size={"Toolbar"}
259
- tip="delete link"
260
- tabIndex={0}
261
- onMouseDown={preventDefault}
262
- onClick={() => {
263
- setIsLinkEditMode(false);
264
- }}
265
- >
266
- <X />
267
- </Button>
268
- <Button
269
- className=" rounded-xl h-6 w-6 flex items-center"
270
- role="button"
271
- tabIndex={0}
272
- tip="confirm link"
273
- onMouseDown={preventDefault}
274
- onClick={handleLinkSubmission}
275
- size={"Toolbar"}
276
- >
277
- <Check />
278
- </Button>
279
- </div>
280
- </div>
281
- ) : (
282
- <div className="w-full border-input border rounded-xl h-9 flex items-center justify-between px-3 py-1 text-base shadow-sm ">
283
- <Link
284
- className={cn(
285
- "size-[14px] text-muted-foreground absolute transition-colors duration-500 transform -translate-x-1/2 -translate-y-1/2 left-4 top-1/2",
286
- !!editedLinkUrl && "text-black dark:text-white"
287
- )}
288
- />
289
- <a
290
- href={sanitizeUrl(linkUrl)}
291
- target="_blank"
292
- rel="noopener noreferrer"
293
- className="pl-4 mb-[1px]"
294
- >
295
- {linkUrl}
296
- </a>
297
- <div className=" absolute bg-background rounded-xl flex flex-row gap-x-1 items-center transition-colors duration-500 transform -translate-y-1/2 right-2 top-1/2">
298
- <Button
299
- className=" rounded-xl z-50 h-6 w-6 flex items-center"
300
- role="button"
301
- size={"Toolbar"}
302
- tip="edit link"
303
- tabIndex={0}
304
- onMouseDown={preventDefault}
305
- onClick={(event) => {
306
- event.preventDefault();
307
- setEditedLinkUrl(linkUrl);
308
- setIsLinkEditMode(true);
309
- }}
310
- >
311
- <Edit2Icon className="size-4" />
312
- </Button>
313
- <Button
314
- className=" rounded-xl h-6 w-6 flex items-center"
315
- role="button"
316
- tabIndex={0}
317
- variant={"secondary"}
318
- tip="delet link"
319
- size={"Toolbar"}
320
- onMouseDown={preventDefault}
321
- onClick={() => {
322
- editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
323
- }}
324
- >
325
- <X />
326
- </Button>
327
- </div>
328
- </div>
329
- )}
330
- </div>
331
- );
332
- }
333
- function useFloatingLinkEditorToolbar(
334
- editor: LexicalEditor,
335
- anchorElem: HTMLElement,
336
- isLinkEditMode: boolean,
337
- setIsLinkEditMode: Dispatch<boolean>
338
- ): JSX.Element | null {
339
- const [activeEditor, setActiveEditor] = useState(editor);
340
- const [isLink, setIsLink] = useState(false);
341
-
342
- useEffect(() => {
343
- function $updateToolbar() {
344
- const selection = $getSelection();
345
- if ($isRangeSelection(selection)) {
346
- const focusNode = getSelectedNode(selection);
347
- const focusLinkNode = $findMatchingParent(focusNode, $isLinkNode);
348
- const focusAutoLinkNode = $findMatchingParent(
349
- focusNode,
350
- $isAutoLinkNode
351
- );
352
- if (!(focusLinkNode || focusAutoLinkNode)) {
353
- setIsLink(false);
354
- return;
355
- }
356
- const badNode = selection
357
- .getNodes()
358
- .filter((node) => !$isLineBreakNode(node))
359
- .find((node) => {
360
- const linkNode = $findMatchingParent(node, $isLinkNode);
361
- const autoLinkNode = $findMatchingParent(node, $isAutoLinkNode);
362
- return (
363
- (focusLinkNode && !focusLinkNode.is(linkNode)) ||
364
- (linkNode && !linkNode.is(focusLinkNode)) ||
365
- (focusAutoLinkNode && !focusAutoLinkNode.is(autoLinkNode)) ||
366
- (autoLinkNode &&
367
- (!autoLinkNode.is(focusAutoLinkNode) ||
368
- autoLinkNode.getIsUnlinked()))
369
- );
370
- });
371
- if (!badNode) {
372
- setIsLink(true);
373
- } else {
374
- setIsLink(false);
375
- }
376
- }
377
- }
378
- return mergeRegister(
379
- editor.registerUpdateListener(({ editorState }) => {
380
- editorState.read(() => {
381
- $updateToolbar();
382
- });
383
- }),
384
- editor.registerCommand(
385
- SELECTION_CHANGE_COMMAND,
386
- (_payload, newEditor) => {
387
- $updateToolbar();
388
- setActiveEditor(newEditor);
389
- return false;
390
- },
391
- COMMAND_PRIORITY_CRITICAL
392
- ),
393
- editor.registerCommand(
394
- CLICK_COMMAND,
395
- (payload) => {
396
- const selection = $getSelection();
397
- if ($isRangeSelection(selection)) {
398
- const node = getSelectedNode(selection);
399
- const linkNode = $findMatchingParent(node, $isLinkNode);
400
- if ($isLinkNode(linkNode) && (payload.metaKey || payload.ctrlKey)) {
401
- window.open(linkNode.getURL(), "_blank");
402
- return true;
403
- }
404
- }
405
- return false;
406
- },
407
- COMMAND_PRIORITY_LOW
408
- )
409
- );
410
- }, [editor]);
411
-
412
- if (!isLink) return null;
413
-
414
- return createPortal(
415
- <FloatingLinkEditor
416
- editor={activeEditor}
417
- isLink={isLink}
418
- anchorElem={anchorElem}
419
- setIsLink={setIsLink}
420
- isLinkEditMode={isLinkEditMode}
421
- setIsLinkEditMode={setIsLinkEditMode}
422
- />,
423
- anchorElem
424
- );
425
- }
426
-
427
- export default function FloatingLinkEditorPlugin({
428
- anchorElem = document.body,
429
- isLinkEditMode,
430
- setIsLinkEditMode,
431
- }: {
432
- anchorElem?: HTMLElement;
433
- isLinkEditMode: boolean;
434
- setIsLinkEditMode: Dispatch<boolean>;
435
- }): JSX.Element | null {
436
- const [editor] = useLexicalComposerContext();
437
-
438
-
439
- return useFloatingLinkEditorToolbar(
440
- editor,
441
- anchorElem,
442
- isLinkEditMode,
443
- setIsLinkEditMode
444
- );
445
- }