@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.
Files changed (188) hide show
  1. package/README.md +71 -0
  2. package/components.json +21 -0
  3. package/eslint.config.mjs +16 -0
  4. package/next.config.ts +12 -0
  5. package/package.json +108 -0
  6. package/postcss.config.mjs +5 -0
  7. package/public/file.svg +1 -0
  8. package/public/globe.svg +1 -0
  9. package/public/images/icons/plus.svg +10 -0
  10. package/public/next.svg +1 -0
  11. package/public/vercel.svg +1 -0
  12. package/public/window.svg +1 -0
  13. package/src/app/actions.ts +2 -0
  14. package/src/app/api/ai/route.ts +175 -0
  15. package/src/app/api/edgestore/[...edgestore]/route.ts +28 -0
  16. package/src/app/favicon.ico +0 -0
  17. package/src/app/globals.css +205 -0
  18. package/src/app/layout.tsx +38 -0
  19. package/src/app/page.tsx +12 -0
  20. package/src/components/editor/Core.tsx +220 -0
  21. package/src/components/editor/hooks/instructions-messages.ts +300 -0
  22. package/src/components/editor/hooks/use-mobile.ts +19 -0
  23. package/src/components/editor/hooks/useReport.ts +67 -0
  24. package/src/components/editor/hooks/useResizeObservert.ts +22 -0
  25. package/src/components/editor/index.tsx +39 -0
  26. package/src/components/editor/lexical-on-change.tsx +28 -0
  27. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +92 -0
  28. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +65 -0
  29. package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +105 -0
  30. package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +143 -0
  31. package/src/components/editor/nodes/EquationNode/EquationNode.tsx +170 -0
  32. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +228 -0
  33. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +137 -0
  34. package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +317 -0
  35. package/src/components/editor/nodes/ExcalidrawNode/index.tsx +204 -0
  36. package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +134 -0
  37. package/src/components/editor/nodes/Hint/HintComponet.tsx +221 -0
  38. package/src/components/editor/nodes/Hint/index.tsx +190 -0
  39. package/src/components/editor/nodes/ImageNode/index.tsx +328 -0
  40. package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +383 -0
  41. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +94 -0
  42. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +309 -0
  43. package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +146 -0
  44. package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +79 -0
  45. package/src/components/editor/nodes/PollNode/index.tsx +204 -0
  46. package/src/components/editor/nodes/Stepper/index.tsx +260 -0
  47. package/src/components/editor/nodes/TweetNode/index.tsx +214 -0
  48. package/src/components/editor/nodes/index.ts +81 -0
  49. package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +350 -0
  50. package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +56 -0
  51. package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +70 -0
  52. package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +192 -0
  53. package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +217 -0
  54. package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +26 -0
  55. package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +21 -0
  56. package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +76 -0
  57. package/src/components/editor/plugins/CollapsiblePlugin/index.ts +228 -0
  58. package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +44 -0
  59. package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +52 -0
  60. package/src/components/editor/plugins/EquationsPlugin/index.tsx +85 -0
  61. package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +98 -0
  62. package/src/components/editor/plugins/FigmaPlugin/index.tsx +42 -0
  63. package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +445 -0
  64. package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +275 -0
  65. package/src/components/editor/plugins/ImagesPlugin/index.tsx +222 -0
  66. package/src/components/editor/plugins/InlineImagePlugin/index.tsx +351 -0
  67. package/src/components/editor/plugins/LayoutPlugin/index.tsx +238 -0
  68. package/src/components/editor/plugins/LinkPlugin/index.tsx +36 -0
  69. package/src/components/editor/plugins/LinkWithMetaData/index.tsx +271 -0
  70. package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +11 -0
  71. package/src/components/editor/plugins/MarkdownTransformers/index.tsx +304 -0
  72. package/src/components/editor/plugins/PollPlugin/index.tsx +49 -0
  73. package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +180 -0
  74. package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +253 -0
  75. package/src/components/editor/plugins/SlashCommand/index.tsx +621 -0
  76. package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +127 -0
  77. package/src/components/editor/plugins/TabFocusPlugin/index.ts +58 -0
  78. package/src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx +759 -0
  79. package/src/components/editor/plugins/TableCellResizer/index.tsx +438 -0
  80. package/src/components/editor/plugins/TableHoverActionsPlugin/index.tsx +314 -0
  81. package/src/components/editor/plugins/TablePlugin/index.tsx +99 -0
  82. package/src/components/editor/plugins/ToolbarPlugin/index.tsx +522 -0
  83. package/src/components/editor/plugins/TwitterPlugin/index.ts +35 -0
  84. package/src/components/editor/plugins/YouTubeNode/index.tsx +179 -0
  85. package/src/components/editor/plugins/YouTubePlugin/index.ts +41 -0
  86. package/src/components/editor/themes/editor-theme.ts +113 -0
  87. package/src/components/editor/themes/theme.css +377 -0
  88. package/src/components/editor/utils/ai.ts +291 -0
  89. package/src/components/editor/utils/canUseDOM.ts +12 -0
  90. package/src/components/editor/utils/editorFormatting.ts +282 -0
  91. package/src/components/editor/utils/environment.ts +50 -0
  92. package/src/components/editor/utils/extract-data.ts +166 -0
  93. package/src/components/editor/utils/getAllLexicalChildren.ts +13 -0
  94. package/src/components/editor/utils/getDOMRangeRect.ts +27 -0
  95. package/src/components/editor/utils/getSelectedNode.ts +27 -0
  96. package/src/components/editor/utils/gif.ts +29 -0
  97. package/src/components/editor/utils/invariant.ts +15 -0
  98. package/src/components/editor/utils/setFloatingElemPosition.ts +51 -0
  99. package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +40 -0
  100. package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +51 -0
  101. package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +15 -0
  102. package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +114 -0
  103. package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +6 -0
  104. package/src/components/editor/utils/url.ts +109 -0
  105. package/src/components/editor/utils/useLayoutEffect.ts +13 -0
  106. package/src/components/providers/QueryProvider.tsx +15 -0
  107. package/src/components/providers/SharedHistoryContext.tsx +28 -0
  108. package/src/components/providers/ToolbarContext.tsx +123 -0
  109. package/src/components/providers/theme-provider.tsx +11 -0
  110. package/src/components/theme/ModeToggle.tsx +40 -0
  111. package/src/components/ui/FileInput.tsx +40 -0
  112. package/src/components/ui/Input.css +32 -0
  113. package/src/components/ui/Select.css +42 -0
  114. package/src/components/ui/Select.tsx +36 -0
  115. package/src/components/ui/TextInput.tsx +48 -0
  116. package/src/components/ui/ai/ai-button.tsx +574 -0
  117. package/src/components/ui/ai/border.tsx +99 -0
  118. package/src/components/ui/ai/placeholder-input-vanish.tsx +282 -0
  119. package/src/components/ui/button.tsx +89 -0
  120. package/src/components/ui/card.tsx +76 -0
  121. package/src/components/ui/checkbox.tsx +30 -0
  122. package/src/components/ui/command.tsx +153 -0
  123. package/src/components/ui/dialog/Dialog.css +25 -0
  124. package/src/components/ui/dialog/Dialog.tsx +34 -0
  125. package/src/components/ui/dialog.tsx +122 -0
  126. package/src/components/ui/drop-downs/background-color.tsx +183 -0
  127. package/src/components/ui/drop-downs/block-format.tsx +159 -0
  128. package/src/components/ui/drop-downs/code.tsx +42 -0
  129. package/src/components/ui/drop-downs/color.tsx +177 -0
  130. package/src/components/ui/drop-downs/font-size.tsx +138 -0
  131. package/src/components/ui/drop-downs/font.tsx +155 -0
  132. package/src/components/ui/drop-downs/index.tsx +122 -0
  133. package/src/components/ui/drop-downs/insert-node.tsx +213 -0
  134. package/src/components/ui/drop-downs/text-align.tsx +123 -0
  135. package/src/components/ui/drop-downs/text-format.tsx +104 -0
  136. package/src/components/ui/dropdown-menu.tsx +201 -0
  137. package/src/components/ui/equation/EquationEditor.css +38 -0
  138. package/src/components/ui/equation/EquationEditor.tsx +56 -0
  139. package/src/components/ui/equation/KatexEquationAlterer.css +41 -0
  140. package/src/components/ui/equation/KatexEquationAlterer.tsx +83 -0
  141. package/src/components/ui/equation/KatexRenderer.tsx +66 -0
  142. package/src/components/ui/excalidraw/ExcalidrawModal.css +64 -0
  143. package/src/components/ui/excalidraw/ExcalidrawModal.tsx +234 -0
  144. package/src/components/ui/excalidraw/Modal.css +62 -0
  145. package/src/components/ui/excalidraw/Modal.tsx +110 -0
  146. package/src/components/ui/hover-card.tsx +29 -0
  147. package/src/components/ui/image/error-image.tsx +17 -0
  148. package/src/components/ui/image/file-upload.tsx +240 -0
  149. package/src/components/ui/image/image-resizer.tsx +297 -0
  150. package/src/components/ui/image/image-toolbar.tsx +264 -0
  151. package/src/components/ui/image/index.tsx +408 -0
  152. package/src/components/ui/image/lazy-image.tsx +68 -0
  153. package/src/components/ui/image/lazy-video.tsx +71 -0
  154. package/src/components/ui/input.tsx +22 -0
  155. package/src/components/ui/models/custom-dialog.tsx +320 -0
  156. package/src/components/ui/models/insert-gif.tsx +90 -0
  157. package/src/components/ui/models/insert-image.tsx +52 -0
  158. package/src/components/ui/models/insert-poll.tsx +29 -0
  159. package/src/components/ui/models/insert-table.tsx +62 -0
  160. package/src/components/ui/models/use-model.tsx +91 -0
  161. package/src/components/ui/poll/poll-component.tsx +304 -0
  162. package/src/components/ui/popover.tsx +33 -0
  163. package/src/components/ui/progress.tsx +28 -0
  164. package/src/components/ui/scroll-area.tsx +48 -0
  165. package/src/components/ui/separator.tsx +31 -0
  166. package/src/components/ui/skeleton.tsx +15 -0
  167. package/src/components/ui/sonner.tsx +31 -0
  168. package/src/components/ui/stepper/step.tsx +179 -0
  169. package/src/components/ui/stepper/stepper.tsx +89 -0
  170. package/src/components/ui/textarea.tsx +22 -0
  171. package/src/components/ui/toggle.tsx +71 -0
  172. package/src/components/ui/tooltip.tsx +32 -0
  173. package/src/components/ui/write/text-format-floting-toolbar.tsx +346 -0
  174. package/src/lib/edgestore.ts +9 -0
  175. package/src/lib/pinecone-client.ts +0 -0
  176. package/src/lib/utils.ts +6 -0
  177. package/src/utils/docSerialization.ts +77 -0
  178. package/src/utils/emoji-list.ts +16615 -0
  179. package/src/utils/getDOMRangeRect.ts +27 -0
  180. package/src/utils/getSelectedNode.ts +27 -0
  181. package/src/utils/getThemeSelector.ts +25 -0
  182. package/src/utils/isMobileWidth.ts +7 -0
  183. package/src/utils/joinClasses.ts +13 -0
  184. package/src/utils/setFloatingElemPosition.ts +74 -0
  185. package/src/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
  186. package/src/utils/swipe.ts +127 -0
  187. package/src/utils/url.ts +38 -0
  188. package/tsconfig.json +27 -0
@@ -0,0 +1,621 @@
1
+ import { $createCodeNode } from "@lexical/code";
2
+ import {
3
+ INSERT_CHECK_LIST_COMMAND,
4
+ INSERT_ORDERED_LIST_COMMAND,
5
+ INSERT_UNORDERED_LIST_COMMAND,
6
+ } from "@lexical/list";
7
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
8
+ import { INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/react/LexicalHorizontalRuleNode";
9
+ import {
10
+ LexicalTypeaheadMenuPlugin,
11
+ MenuOption,
12
+ useBasicTypeaheadTriggerMatch,
13
+ } from "@lexical/react/LexicalTypeaheadMenuPlugin";
14
+ import { $createHeadingNode, $createQuoteNode } from "@lexical/rich-text";
15
+ import { $setBlocksType } from "@lexical/selection";
16
+ import { INSERT_TABLE_COMMAND } from "@lexical/table";
17
+ import {
18
+ $createParagraphNode,
19
+ $getSelection,
20
+ $isRangeSelection,
21
+ createEditor,
22
+ LexicalEditor,
23
+ TextNode,
24
+ } from "lexical";
25
+ import { useCallback, useMemo, useState } from "react";
26
+ import * as React from "react";
27
+ import * as ReactDOM from "react-dom";
28
+ import {
29
+ Code2,
30
+ Columns2,
31
+ Columns3,
32
+ Columns4,
33
+ ImageIcon,
34
+ ImagePlayIcon,
35
+ ListCheck,
36
+ OctagonX,
37
+ Pilcrow,
38
+ QuoteIcon,
39
+ SquarePenIcon,
40
+ StepForward,
41
+ Twitter,
42
+ Youtube,
43
+ Figma,
44
+ Heading1,
45
+ Heading2,
46
+ Heading3,
47
+ Minus,
48
+ List,
49
+ ListOrdered,
50
+ Table,
51
+ SigmaIcon,
52
+ } from "lucide-react";
53
+
54
+ import { INSERT_COLLAPSIBLE_COMMAND } from "../CollapsiblePlugin";
55
+ import { cn } from "@/lib/utils";
56
+ import { INSERT_LAYOUT_COMMAND } from "../LayoutPlugin";
57
+ import { INSERT_POLL_COMMAND } from "../PollPlugin";
58
+ import { INSERT_HINT_COMMAND } from "../../nodes/Hint";
59
+ import useModal from "@/components/ui/models/use-model";
60
+ import {
61
+ Command,
62
+ CommandItem,
63
+ CommandList,
64
+ CommandInput,
65
+ CommandEmpty,
66
+ CommandShortcut,
67
+ } from "@/components/ui/command";
68
+ import { SHORTCUTS } from "../ShortcutsPlugin/shortcuts";
69
+ import { Skeleton } from "@/components/ui/skeleton";
70
+ import { ImagePayload } from "../../nodes/ImageNode";
71
+ import { INSERT_IMAGE_COMMAND } from "../ImagesPlugin";
72
+ import { AutoEmbedDialog, FigmaEmbedConfig, TwitterEmbedConfig, YoutubeEmbedConfig } from "../AutoEmbedPlugin";
73
+ import { initialEditorState, INSERT_STEPPER_COMMAND } from "../../nodes/Stepper";
74
+ import { InsertInlineImageDialog } from "../InlineImagePlugin";
75
+ import { InsertEquationDialog } from "../EquationsPlugin";
76
+ const InsertGif = React.lazy(() => import("@/components/ui/models/insert-gif"));
77
+ const InsertImageDialog = React.lazy(() =>
78
+ import("@/components/ui/models/insert-image").then((module) => ({
79
+ default: module.InsertImageDialog,
80
+ }))
81
+ );
82
+ class ComponentPickerOption extends MenuOption {
83
+ // What shows up in the editor
84
+ title: string;
85
+ // Icon for display
86
+ icon?: React.JSX.Element;
87
+ // For extra searching.
88
+ keywords: Array<string>;
89
+ // TBD
90
+ keyboardShortcut?: string;
91
+ // What happens when you select this option?
92
+ onSelect: (queryString: string) => void;
93
+ desc?: string;
94
+ constructor(
95
+ title: string,
96
+ options: {
97
+ icon?: React.JSX.Element;
98
+ keywords?: Array<string>;
99
+ keyboardShortcut?: string;
100
+ onSelect: (queryString: string) => void;
101
+ desc?: string;
102
+ }
103
+ ) {
104
+ super(title);
105
+ this.title = title;
106
+ this.keywords = options.keywords || [];
107
+ this.icon = options.icon;
108
+ this.keyboardShortcut = options.keyboardShortcut;
109
+ this.onSelect = options.onSelect.bind(this);
110
+ this.desc = options.desc; // Add this line
111
+ }
112
+ }
113
+
114
+ function getDynamicOptions(editor: LexicalEditor, queryString: string) {
115
+ const options: Array<ComponentPickerOption> = [];
116
+
117
+ if (queryString == null) {
118
+ return options;
119
+ }
120
+
121
+ const tableMatch = queryString.match(/^([1-9]\d?)(?:x([1-9]\d?)?)?$/);
122
+
123
+ if (tableMatch !== null) {
124
+ const rows = tableMatch[1];
125
+ const colOptions = tableMatch[2]
126
+ ? [tableMatch[2]]
127
+ : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(String);
128
+
129
+ options.push(
130
+ ...colOptions.map(
131
+ (columns) =>
132
+ new ComponentPickerOption(`${rows}x${columns} Table`, {
133
+ icon: <i className="icon table" />,
134
+ keywords: ["table"],
135
+ onSelect: () =>
136
+ editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns, rows }),
137
+ })
138
+ )
139
+ );
140
+ }
141
+
142
+ return options;
143
+ }
144
+
145
+ function getBaseOptions(
146
+ editor: LexicalEditor,
147
+ showModal: (
148
+ title?: string | null,
149
+ description?: string | null,
150
+ getContent?: (onClose: () => void) => React.JSX.Element,
151
+ isDilog?: boolean
152
+ ) => void
153
+ ) {
154
+ return [
155
+ new ComponentPickerOption("Paragraph", {
156
+ icon: <Pilcrow className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
157
+ keywords: ["normal", "paragraph", "p", "text"],
158
+ onSelect: () =>
159
+ editor.update(() => {
160
+ const selection = $getSelection();
161
+ if ($isRangeSelection(selection)) {
162
+ $setBlocksType(selection, () => $createParagraphNode());
163
+ }
164
+ }),
165
+ desc: "Just start writing with plain text",
166
+ }),
167
+ ...([1, 2, 3] as const).map(
168
+ (n) =>
169
+ new ComponentPickerOption(`Heading ${n}`, {
170
+ icon:
171
+ n === 1 ? (
172
+ <Heading1 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />
173
+ ) : n === 2 ? (
174
+ <Heading2 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />
175
+ ) : (
176
+ <Heading3 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />
177
+ ),
178
+ keywords: ["heading", "header", `h${n}`],
179
+ keyboardShortcut:
180
+ n === 1
181
+ ? SHORTCUTS.HEADING1
182
+ : n === 2
183
+ ? SHORTCUTS.HEADING2
184
+ : SHORTCUTS.HEADING3,
185
+ onSelect: () =>
186
+ editor.update(() => {
187
+ const selection = $getSelection();
188
+ if ($isRangeSelection(selection)) {
189
+ $setBlocksType(selection, () => $createHeadingNode(`h${n}`));
190
+ }
191
+ }),
192
+ desc: `${n == 1
193
+ ? "Big section heading"
194
+ : n == 2
195
+ ? "Meduim section heading."
196
+ : "Small section heading"
197
+ }`,
198
+ })
199
+ ),
200
+ new ComponentPickerOption("Table", {
201
+ icon: <Table className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
202
+ keywords: ["table", "grid", "spreadsheet", "rows", "columns"],
203
+ desc: "Add simple table content to your blog.",
204
+ onSelect: () =>
205
+ editor.dispatchCommand(INSERT_TABLE_COMMAND, {
206
+ rows: "4",
207
+ columns: "4",
208
+ }),
209
+ }),
210
+ new ComponentPickerOption("Hint", {
211
+ icon: <OctagonX className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
212
+ keywords: [
213
+ "Hint",
214
+ "note",
215
+ "info",
216
+ "alert",
217
+ "alert",
218
+ "success",
219
+ "warning",
220
+ "error",
221
+ ],
222
+ desc: "Add a hint to your content.",
223
+ onSelect: () => editor.dispatchCommand(INSERT_HINT_COMMAND, "hint"),
224
+ }),
225
+ new ComponentPickerOption("Numbered List", {
226
+ icon: <ListOrdered className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
227
+ keywords: ["numbered list", "ordered list", "ol"],
228
+ desc: "Create list with number",
229
+ keyboardShortcut: SHORTCUTS.NUMBERED_LIST,
230
+
231
+ onSelect: () =>
232
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined),
233
+ }),
234
+ new ComponentPickerOption("Bulleted List", {
235
+ icon: <List className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
236
+ keywords: ["bulleted list", "unordered list", "ul"],
237
+ desc: "Create list with Bulleted",
238
+ keyboardShortcut: SHORTCUTS.BULLET_LIST,
239
+
240
+ onSelect: () =>
241
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined),
242
+ }),
243
+ new ComponentPickerOption("Check List", {
244
+ icon: <ListCheck className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
245
+ keywords: ["check list", "todo list"],
246
+ desc: "Track tasks with to-do list.",
247
+ keyboardShortcut: SHORTCUTS.CHECK_LIST,
248
+
249
+ onSelect: () =>
250
+ editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined),
251
+ }),
252
+ new ComponentPickerOption("Quote", {
253
+ icon: <QuoteIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
254
+ keywords: ["block quote"],
255
+ desc: "Capture Quote",
256
+ keyboardShortcut: SHORTCUTS.QUOTE,
257
+
258
+ onSelect: () =>
259
+ editor.update(() => {
260
+ const selection = $getSelection();
261
+ if ($isRangeSelection(selection)) {
262
+ $setBlocksType(selection, () => $createQuoteNode());
263
+ }
264
+ }),
265
+ }),
266
+ new ComponentPickerOption("Pool", {
267
+ icon: <SquarePenIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
268
+ keywords: ["pool", "vote", "survey"],
269
+ desc: "Add pool to take people votes.",
270
+ onSelect: () =>
271
+ editor.dispatchCommand(INSERT_POLL_COMMAND, "type the Question"),
272
+ }),
273
+ new ComponentPickerOption("Code", {
274
+ icon: <Code2 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
275
+ keywords: ["javascript", "python", "js", "codeblock"],
276
+ desc: "Add block of code.",
277
+ keyboardShortcut: SHORTCUTS.CODE_BLOCK,
278
+
279
+ onSelect: () =>
280
+ editor.update(() => {
281
+ const selection = $getSelection();
282
+ if ($isRangeSelection(selection)) {
283
+ if (selection.isCollapsed()) {
284
+ $setBlocksType(selection, () => $createCodeNode());
285
+ } else {
286
+ const textContent = selection.getTextContent();
287
+ const codeNode = $createCodeNode();
288
+ selection.insertNodes([codeNode]);
289
+ selection.insertRawText(textContent);
290
+ }
291
+ }
292
+ }),
293
+ }),
294
+ new ComponentPickerOption("Divider", {
295
+ icon: <Minus className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
296
+ keywords: ["horizontal rule", "divider", "hr"],
297
+ desc: "Visually divide blocks",
298
+
299
+ onSelect: () =>
300
+ editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined),
301
+ }),
302
+ new ComponentPickerOption("Youtube", {
303
+ icon: <Youtube className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
304
+ keywords: ["Youtube", "youtube", "video"],
305
+ desc: "Embedded YouTube videos ",
306
+
307
+ onSelect: () => {
308
+ showModal(
309
+ "Youtube",
310
+ "Insert a URL to embed a live preview. Works with YouTube",
311
+ (onClose) => (
312
+ <AutoEmbedDialog
313
+ embedConfig={YoutubeEmbedConfig}
314
+ onClose={onClose}
315
+ />
316
+ ),
317
+ true
318
+ );
319
+ },
320
+ }),
321
+ new ComponentPickerOption("Figma", {
322
+ icon: <Figma className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
323
+ keywords: ["figma", "figma.com", "ui"],
324
+ desc: "Embedded Figma File ",
325
+
326
+ onSelect: () => {
327
+ showModal(
328
+ "Figma",
329
+ "Insert a URL to embed a live preview. Works with Figma",
330
+ (onClose) => (
331
+ <AutoEmbedDialog
332
+ embedConfig={FigmaEmbedConfig}
333
+ onClose={onClose}
334
+ />
335
+ ),
336
+ true
337
+ );
338
+ },
339
+ }),
340
+ new ComponentPickerOption("Twitter", {
341
+ icon: <Twitter className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
342
+ keywords: ["Twitter", "tweet", "x", "twitter"],
343
+ desc: "Embedded Tweets ",
344
+
345
+ onSelect: () => {
346
+ showModal(
347
+ "Twitter tweet",
348
+ "Insert a URL to embed a live preview. Works with Twitter",
349
+ (onClose) => (
350
+ <AutoEmbedDialog
351
+ embedConfig={TwitterEmbedConfig}
352
+ onClose={onClose}
353
+ />
354
+ ),
355
+ true
356
+ );
357
+ },
358
+ }),
359
+ new ComponentPickerOption("Image", {
360
+ icon: <ImageIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
361
+ keywords: ["image", "photo", "picture", "file", "img"],
362
+ desc: "Upload or embed with a link",
363
+
364
+ onSelect: () =>
365
+ showModal(
366
+ "Insert Image",
367
+ "Please select an image to upload.",
368
+ (onClose) => (
369
+ <React.Suspense
370
+ fallback={<Skeleton className="mx-2 w-[350px] h-[350px]" />}
371
+ >
372
+ <InsertImageDialog activeEditor={editor} onClose={onClose} />
373
+ </React.Suspense>
374
+ ),
375
+ true
376
+ ),
377
+ }),
378
+
379
+ new ComponentPickerOption("Inline Image", {
380
+ icon: <ImageIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
381
+ keywords: ["image", "photo", "picture", "file", "img"],
382
+ desc: "Upload or embed with a link",
383
+
384
+ onSelect: () =>
385
+ showModal(
386
+ "Insert Image",
387
+ "Please select an image to upload.",
388
+ (onClose) => (
389
+ <React.Suspense
390
+ fallback={<Skeleton className="mx-2 w-[350px] h-[350px]" />}
391
+ >
392
+ <InsertInlineImageDialog
393
+ activeEditor={editor}
394
+ onClose={onClose}
395
+ />
396
+ </React.Suspense>
397
+ ),
398
+ true
399
+ ),
400
+ }),
401
+
402
+ new ComponentPickerOption('Equation', {
403
+ icon: <SigmaIcon className="w-4 h-4" />,
404
+ keywords: ['equation', 'latex', 'math'],
405
+ onSelect: () =>
406
+ showModal(
407
+ 'Insert Equation',
408
+ 'Insert mathematical equations using LaTeX syntax.',
409
+ (onClose) => (
410
+ <React.Suspense
411
+ fallback={<Skeleton className="mx-2 w-[350px] h-[350px]" />}
412
+ >
413
+
414
+ <InsertEquationDialog
415
+ activeEditor={editor}
416
+ onClose={onClose}
417
+ />
418
+ </React.Suspense>
419
+ ),
420
+ true
421
+ ),
422
+ }),
423
+
424
+ new ComponentPickerOption("Poll", {
425
+ icon: <SquarePenIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
426
+ keywords: ["collapse", "collapsible", "toggle"],
427
+ desc: "make poll to take people votes.",
428
+ onSelect: () =>
429
+ editor.dispatchCommand(INSERT_POLL_COMMAND, "type the Question"),
430
+ }),
431
+ new ComponentPickerOption("Collapsible", {
432
+ icon: <StepForward className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
433
+ keywords: ["collapse", "collapsible", "toggle"],
434
+ desc: "Toggles can hide and show content inside.",
435
+ onSelect: () =>
436
+ editor.dispatchCommand(INSERT_COLLAPSIBLE_COMMAND, undefined),
437
+ }),
438
+ new ComponentPickerOption("2 columns", {
439
+ icon: <Columns2 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
440
+ keywords: ["columns", "flex", "row", "layout", "grid"],
441
+ desc: "Dvide your content into 2 container.",
442
+ onSelect: () => editor.dispatchCommand(INSERT_LAYOUT_COMMAND, "1fr 1fr"),
443
+ }),
444
+ new ComponentPickerOption("3 columns", {
445
+ icon: <Columns3 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
446
+ keywords: ["3columns", "3", "flex", "row", "layout", "grid"],
447
+ desc: "Dvide your content into 3 container.",
448
+ onSelect: () =>
449
+ editor.dispatchCommand(INSERT_LAYOUT_COMMAND, "1fr 1fr 1fr"),
450
+ }),
451
+ new ComponentPickerOption("Stepper", {
452
+ icon: <svg className="w-9 h-9 max-sm:h-5 max-sm:w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="none" fillRule="evenodd"><path d="m12.594 23.258l-.012.002l-.071.035l-.02.004l-.014-.004l-.071-.036q-.016-.004-.024.006l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.016-.018m.264-.113l-.014.002l-.184.093l-.01.01l-.003.011l.018.43l.005.012l.008.008l.201.092q.019.005.029-.008l.004-.014l-.034-.614q-.005-.019-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.003-.011l.018-.43l-.003-.012l-.01-.01z"></path><path fill="currentColor" d="M5 6a3 3 0 0 1 6 0v2a3 3 0 0 1-6 0zm3-1a1 1 0 0 0-1 1v2a1 1 0 0 0 2 0V6a1 1 0 0 0-1-1m9.707-.707a1 1 0 0 0-1.414 0L13.465 7.12a1 1 0 0 0 1.414 1.415L16 7.414V20a1 1 0 1 0 2 0V7.414l1.121 1.122a1 1 0 1 0 1.415-1.415zM5 15a3 3 0 0 1 5.995-.176l.005.186c0 .408-.039.799-.107 1.171c-.264 1.433-.964 2.58-1.57 3.352c-.307.39-.598.694-.815.904c-.124.12-.25.238-.385.345a1 1 0 0 1-1.34-1.479L7.118 19l.224-.228A7 7 0 0 0 7.971 18A3 3 0 0 1 5 15m3-1a1 1 0 1 0 0 2a1 1 0 0 0 0-2"></path></g></svg>,
453
+ keywords: ["stpper", "step", "lines", "routes", "docs", "number"],
454
+ desc: "Stepper with descriptions for each step.",
455
+ onSelect: () => {
456
+
457
+ const newEditor = createEditor();
458
+ const parsedEditorState = newEditor.parseEditorState(
459
+ JSON.stringify(initialEditorState)
460
+ );
461
+ newEditor.setEditorState(parsedEditorState);
462
+ const newStep = {
463
+ id: 0,
464
+ title: `New step 0`,
465
+ content: newEditor,
466
+ };
467
+ editor.dispatchCommand(INSERT_STEPPER_COMMAND, [newStep])
468
+
469
+ }
470
+ }),
471
+ new ComponentPickerOption("Gifs", {
472
+ icon: <ImagePlayIcon className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
473
+ keywords: ["gif", "gifs", "videos", "short video"],
474
+ desc: "Insert a GIF video",
475
+ onSelect: () => {
476
+ showModal(
477
+ "Insert GIF",
478
+ "Please select a GIF to upload.",
479
+ (onClose) => (
480
+ <React.Suspense
481
+ fallback={<Skeleton className="mx-2 w-[400px] h-[400px]" />}
482
+ >
483
+ <InsertGif
484
+ insertGifOnClick={(payload: ImagePayload) => {
485
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, payload);
486
+ }}
487
+ onClose={onClose}
488
+ />
489
+ </React.Suspense>
490
+ ),
491
+ true
492
+ );
493
+ },
494
+ }),
495
+
496
+ new ComponentPickerOption("4 columns", {
497
+ icon: <Columns4 className="w-9 h-9 max-sm:h-5 max-sm:w-5" />,
498
+ keywords: ["4columns", "4", "flex", "row", "layout", "grid"],
499
+ desc: "Dvide your content into 4 container.",
500
+ onSelect: () =>
501
+ editor.dispatchCommand(INSERT_LAYOUT_COMMAND, "1fr 1fr 1fr 1fr"),
502
+ }),
503
+ ];
504
+ }
505
+
506
+ export default function SlashCommand(): React.JSX.Element {
507
+ const [editor] = useLexicalComposerContext();
508
+ const [Modal, showModal] = useModal();
509
+ const [queryString, setQueryString] = useState<string | null>(null);
510
+
511
+ const checkForTriggerMatch = useBasicTypeaheadTriggerMatch("/", {
512
+ minLength: 0,
513
+ });
514
+
515
+ const options = useMemo(() => {
516
+ const baseOptions = getBaseOptions(editor, showModal);
517
+
518
+ if (!queryString) {
519
+ return baseOptions;
520
+ }
521
+
522
+ const regex = new RegExp(queryString, "i");
523
+
524
+ return [
525
+ ...getDynamicOptions(editor, queryString),
526
+ ...baseOptions.filter(
527
+ (option) =>
528
+ regex.test(option.title) ||
529
+ option.keywords.some((keyword) => regex.test(keyword))
530
+ ),
531
+ ];
532
+ }, [editor, queryString]);
533
+
534
+ const onSelectOption = useCallback(
535
+ (
536
+ selectedOption: ComponentPickerOption,
537
+ nodeToRemove: TextNode | null,
538
+ closeMenu: () => void,
539
+ matchingString: string
540
+ ) => {
541
+ editor.update(() => {
542
+ nodeToRemove?.remove();
543
+ selectedOption.onSelect(matchingString);
544
+ closeMenu();
545
+ });
546
+ },
547
+ [editor, showModal]
548
+ );
549
+
550
+ return (
551
+ <>
552
+ <LexicalTypeaheadMenuPlugin<ComponentPickerOption>
553
+ onQueryChange={setQueryString}
554
+ onSelectOption={onSelectOption}
555
+ triggerFn={checkForTriggerMatch}
556
+ options={options}
557
+ menuRenderFn={(
558
+ anchorElementRef,
559
+ { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }
560
+ ) =>
561
+ anchorElementRef.current && options.length
562
+ ? ReactDOM.createPortal(
563
+ <div
564
+ id={"toolbar"}
565
+ className={`
566
+ overflow-x-hidden z-[100] relative max-w-[300px] max-sm:w-[200px] w-[300px] max-h-[300px] h-fit border rounded-sm bg-background shadow-sm shadow-muted-foreground/20
567
+
568
+ `}
569
+ >
570
+ <Command>
571
+ <CommandInput placeholder="Type a command" />
572
+ <CommandList>
573
+ <CommandEmpty>No results found.</CommandEmpty>
574
+
575
+ {options.map((option, i: number) => (
576
+ <CommandItem
577
+ ref={option.ref as React.Ref<HTMLDivElement>}
578
+ className={cn(
579
+ selectedIndex == i &&
580
+ "dark:bg-gray-300/10 bg-gray-400/60",
581
+ "gap-x-2 h-full items-start hover:bg-transparent border-0 bg-transparent transition-colors cursor-pointer rounded-sm relative"
582
+ )}
583
+ onSelect={() => {
584
+ setHighlightedIndex(i);
585
+ selectOptionAndCleanUp(option);
586
+ }}
587
+ onMouseEnter={() => {
588
+ setHighlightedIndex(i);
589
+ }}
590
+ key={option.key}
591
+ >
592
+ <div className="p-4 h-full bg-gray-400/60 dark:bg-gray-300/10 rounded-sm">
593
+ {option.icon}
594
+ </div>
595
+ <div className="flex flex-row justify-between items-center">
596
+ <div className="flex justify-center items-start flex-col">
597
+ <div>{option.title}</div>
598
+ <span className="text-sm text-muted-foreground break-words">
599
+ {option.desc}
600
+ </span>
601
+ </div>
602
+ {option.keyboardShortcut && (
603
+ <CommandShortcut className=" absolute top-1 right-2">
604
+ {option.keyboardShortcut}
605
+ </CommandShortcut>
606
+ )}
607
+ </div>
608
+ </CommandItem>
609
+ ))}
610
+ </CommandList>
611
+ </Command>
612
+ </div>,
613
+ anchorElementRef.current
614
+ )
615
+ : null
616
+ }
617
+ />
618
+ {Modal}
619
+ </>
620
+ );
621
+ }