@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,383 @@
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 {Position} from './InlineImageNode';
9
+ import type {BaseSelection, LexicalEditor, NodeKey} from 'lexical';
10
+ import type {JSX} from 'react';
11
+
12
+ import './InlineImageNode.css';
13
+
14
+ import {AutoFocusPlugin} from '@lexical/react/LexicalAutoFocusPlugin';
15
+ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
16
+ import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
17
+ import {LexicalNestedComposer} from '@lexical/react/LexicalNestedComposer';
18
+ import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin';
19
+ import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
20
+ import {useLexicalNodeSelection} from '@lexical/react/useLexicalNodeSelection';
21
+ import {mergeRegister} from '@lexical/utils';
22
+ import {
23
+ $getNodeByKey,
24
+ $getSelection,
25
+ $isNodeSelection,
26
+ $setSelection,
27
+ CLICK_COMMAND,
28
+ COMMAND_PRIORITY_LOW,
29
+ DRAGSTART_COMMAND,
30
+ KEY_ENTER_COMMAND,
31
+ KEY_ESCAPE_COMMAND,
32
+ SELECTION_CHANGE_COMMAND,
33
+ } from 'lexical';
34
+ import * as React from 'react';
35
+ import {Suspense, useCallback, useEffect, useRef, useState} from 'react';
36
+
37
+ // import useModal from '../../hooks/useModal';
38
+ import LinkPlugin from '../../plugins/LinkPlugin';
39
+ // import ContentEditable from '@/components/ui/ContentEditable';
40
+ import {InlineImageNode} from './InlineImageNode';
41
+ import { Button } from '@/components/ui/button';
42
+ import TextInput from '@/components/ui/TextInput';
43
+ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
44
+ import { DialogActions } from '@/components/ui/dialog/Dialog';
45
+ import Select from '@/components/ui/Select';
46
+ import useModal from '@/components/ui/models/use-model';
47
+
48
+ const imageCache = new Set();
49
+
50
+ function useSuspenseImage(src: string) {
51
+ if (!imageCache.has(src)) {
52
+ throw new Promise((resolve) => {
53
+ const img = new Image();
54
+ img.src = src;
55
+ img.onload = () => {
56
+ imageCache.add(src);
57
+ resolve(null);
58
+ };
59
+ });
60
+ }
61
+ }
62
+
63
+ function LazyImage({
64
+ altText,
65
+ className,
66
+ imageRef,
67
+ src,
68
+ width,
69
+ height,
70
+ position,
71
+ }: {
72
+ altText: string;
73
+ className: string | null;
74
+ height: 'inherit' | number;
75
+ imageRef: {current: null | HTMLImageElement};
76
+ src: string;
77
+ width: 'inherit' | number;
78
+ position: Position;
79
+ }): JSX.Element {
80
+ useSuspenseImage(src);
81
+ return (
82
+ <img
83
+ className={className || undefined}
84
+ src={src}
85
+ alt={altText}
86
+ ref={imageRef}
87
+ data-position={position}
88
+ style={{
89
+ display: 'block',
90
+ height,
91
+ width,
92
+ }}
93
+ draggable="false"
94
+ />
95
+ );
96
+ }
97
+
98
+ export function UpdateInlineImageDialog({
99
+ activeEditor,
100
+ nodeKey,
101
+ onClose,
102
+ }: {
103
+ activeEditor: LexicalEditor;
104
+ nodeKey: NodeKey;
105
+ onClose: () => void;
106
+ }): JSX.Element {
107
+ const editorState = activeEditor.getEditorState();
108
+ const node = editorState.read(
109
+ () => $getNodeByKey(nodeKey) as InlineImageNode,
110
+ );
111
+ const [altText, setAltText] = useState(node.getAltText());
112
+ const [showCaption, setShowCaption] = useState(node.getShowCaption());
113
+ const [position, setPosition] = useState<Position>(node.getPosition());
114
+
115
+ const handleShowCaptionChange = (e: React.ChangeEvent<HTMLInputElement>) => {
116
+ setShowCaption(e.target.checked);
117
+ };
118
+
119
+ const handlePositionChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
120
+ setPosition(e.target.value as Position);
121
+ };
122
+
123
+ const handleOnConfirm = () => {
124
+ const payload = {altText, position, showCaption};
125
+ if (node) {
126
+ activeEditor.update(() => {
127
+ node.update(payload);
128
+ });
129
+ }
130
+ onClose();
131
+ };
132
+
133
+ return (
134
+ <>
135
+ <div style={{marginBottom: '1em'}}>
136
+ <TextInput
137
+ label="Alt Text"
138
+ placeholder="Descriptive alternative text"
139
+ onChange={setAltText}
140
+ value={altText}
141
+ data-test-id="image-modal-alt-text-input"
142
+ />
143
+ </div>
144
+
145
+ <Select
146
+ style={{marginBottom: '1em', width: '208px'}}
147
+ value={position}
148
+ label="Position"
149
+ name="position"
150
+ id="position-select"
151
+ onChange={handlePositionChange}>
152
+ <option value="left">Left</option>
153
+ <option value="right">Right</option>
154
+ <option value="full">Full Width</option>
155
+ </Select>
156
+
157
+ <div className="Input__wrapper">
158
+ <input
159
+ id="caption"
160
+ type="checkbox"
161
+ checked={showCaption}
162
+ onChange={handleShowCaptionChange}
163
+ />
164
+ <label htmlFor="caption">Show Caption</label>
165
+ </div>
166
+
167
+ <DialogActions>
168
+ <Button
169
+ data-test-id="image-modal-file-upload-btn"
170
+ onClick={() => handleOnConfirm()}>
171
+ Confirm
172
+ </Button>
173
+ </DialogActions>
174
+ </>
175
+ );
176
+ }
177
+
178
+ export default function InlineImageComponent({
179
+ src,
180
+ altText,
181
+ nodeKey,
182
+ width,
183
+ height,
184
+ showCaption,
185
+ caption,
186
+ position,
187
+ }: {
188
+ altText: string;
189
+ caption: LexicalEditor;
190
+ height: 'inherit' | number;
191
+ nodeKey: NodeKey;
192
+ showCaption: boolean;
193
+ src: string;
194
+ width: 'inherit' | number;
195
+ position: Position;
196
+ }): JSX.Element {
197
+ const [modal, showModal] = useModal();
198
+ const imageRef = useRef<null | HTMLImageElement>(null);
199
+ const buttonRef = useRef<HTMLButtonElement | null>(null);
200
+ const [isSelected, setSelected, clearSelection] =
201
+ useLexicalNodeSelection(nodeKey);
202
+ const [editor] = useLexicalComposerContext();
203
+ const [selection, setSelection] = useState<BaseSelection | null>(null);
204
+ const activeEditorRef = useRef<LexicalEditor | null>(null);
205
+ const isEditable = useLexicalEditable();
206
+
207
+ const $onEnter = useCallback(
208
+ (event: KeyboardEvent) => {
209
+ const latestSelection = $getSelection();
210
+ const buttonElem = buttonRef.current;
211
+ if (
212
+ isSelected &&
213
+ $isNodeSelection(latestSelection) &&
214
+ latestSelection.getNodes().length === 1
215
+ ) {
216
+ if (showCaption) {
217
+ // Move focus into nested editor
218
+ $setSelection(null);
219
+ event.preventDefault();
220
+ caption.focus();
221
+ return true;
222
+ } else if (
223
+ buttonElem !== null &&
224
+ buttonElem !== document.activeElement
225
+ ) {
226
+ event.preventDefault();
227
+ buttonElem.focus();
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ },
233
+ [caption, isSelected, showCaption],
234
+ );
235
+
236
+ const $onEscape = useCallback(
237
+ (event: KeyboardEvent) => {
238
+ if (
239
+ activeEditorRef.current === caption ||
240
+ buttonRef.current === event.target
241
+ ) {
242
+ $setSelection(null);
243
+ editor.update(() => {
244
+ setSelected(true);
245
+ const parentRootElement = editor.getRootElement();
246
+ if (parentRootElement !== null) {
247
+ parentRootElement.focus();
248
+ }
249
+ });
250
+ return true;
251
+ }
252
+ return false;
253
+ },
254
+ [caption, editor, setSelected],
255
+ );
256
+
257
+ useEffect(() => {
258
+ let isMounted = true;
259
+ const unregister = mergeRegister(
260
+ editor.registerUpdateListener(({editorState}) => {
261
+ if (isMounted) {
262
+ setSelection(editorState.read(() => $getSelection()));
263
+ }
264
+ }),
265
+ editor.registerCommand(
266
+ SELECTION_CHANGE_COMMAND,
267
+ (_, activeEditor) => {
268
+ activeEditorRef.current = activeEditor;
269
+ return false;
270
+ },
271
+ COMMAND_PRIORITY_LOW,
272
+ ),
273
+ editor.registerCommand<MouseEvent>(
274
+ CLICK_COMMAND,
275
+ (payload) => {
276
+ const event = payload;
277
+ if (event.target === imageRef.current) {
278
+ if (event.shiftKey) {
279
+ setSelected(!isSelected);
280
+ } else {
281
+ clearSelection();
282
+ setSelected(true);
283
+ }
284
+ return true;
285
+ }
286
+
287
+ return false;
288
+ },
289
+ COMMAND_PRIORITY_LOW,
290
+ ),
291
+ editor.registerCommand(
292
+ DRAGSTART_COMMAND,
293
+ (event) => {
294
+ if (event.target === imageRef.current) {
295
+ // TODO This is just a temporary workaround for FF to behave like other browsers.
296
+ // Ideally, this handles drag & drop too (and all browsers).
297
+ event.preventDefault();
298
+ return true;
299
+ }
300
+ return false;
301
+ },
302
+ COMMAND_PRIORITY_LOW,
303
+ ),
304
+ editor.registerCommand(KEY_ENTER_COMMAND, $onEnter, COMMAND_PRIORITY_LOW),
305
+ editor.registerCommand(
306
+ KEY_ESCAPE_COMMAND,
307
+ $onEscape,
308
+ COMMAND_PRIORITY_LOW,
309
+ ),
310
+ );
311
+ return () => {
312
+ isMounted = false;
313
+ unregister();
314
+ };
315
+ }, [
316
+ clearSelection,
317
+ editor,
318
+ isSelected,
319
+ nodeKey,
320
+ $onEnter,
321
+ $onEscape,
322
+ setSelected,
323
+ ]);
324
+
325
+ const draggable = isSelected && $isNodeSelection(selection);
326
+ const isFocused = isSelected && isEditable;
327
+ return (
328
+ <Suspense fallback={null}>
329
+ <>
330
+ <span draggable={draggable}>
331
+ {isEditable && (
332
+ <button
333
+ className="image-edit-button"
334
+ ref={buttonRef}
335
+ onClick={() => {
336
+ showModal('Update Inline Image', (onClose) => (
337
+ <UpdateInlineImageDialog
338
+ activeEditor={editor}
339
+ nodeKey={nodeKey}
340
+ onClose={onClose}
341
+ />
342
+ ));
343
+ }}>
344
+ Edit
345
+ </button>
346
+ )}
347
+ <LazyImage
348
+ className={
349
+ isFocused
350
+ ? `focused ${$isNodeSelection(selection) ? 'draggable' : ''}`
351
+ : null
352
+ }
353
+ src={src}
354
+ altText={altText}
355
+ imageRef={imageRef}
356
+ width={width}
357
+ height={height}
358
+ position={position}
359
+ />
360
+ </span>
361
+ {showCaption && (
362
+ <span className="image-caption-container">
363
+ <LexicalNestedComposer initialEditor={caption}>
364
+ <AutoFocusPlugin />
365
+ <LinkPlugin />
366
+ <RichTextPlugin
367
+ contentEditable={
368
+ <ContentEditable
369
+ placeholder="Enter a caption..."
370
+ placeholderClassName="InlineImageNode__placeholder"
371
+ className="InlineImageNode__contentEditable"
372
+ />
373
+ }
374
+ ErrorBoundary={LexicalErrorBoundary}
375
+ />
376
+ </LexicalNestedComposer>
377
+ </span>
378
+ )}
379
+ </>
380
+ {modal}
381
+ </Suspense>
382
+ );
383
+ }
@@ -0,0 +1,94 @@
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
+
10
+ .InlineImageNode__contentEditable {
11
+ min-height: 20px;
12
+ border: 0px;
13
+ resize: none;
14
+ cursor: text;
15
+ caret-color: rgb(5, 5, 5);
16
+ display: block;
17
+ position: relative;
18
+ tab-size: 1;
19
+ outline: 0px;
20
+ padding: 10px;
21
+ user-select: text;
22
+ font-size: 14px;
23
+ line-height: 1.4em;
24
+ width: calc(100% - 20px);
25
+ white-space: pre-wrap;
26
+ word-break: break-word;
27
+ }
28
+
29
+ .InlineImageNode__placeholder {
30
+ font-size: 12px;
31
+ color: #888;
32
+ overflow: hidden;
33
+ position: absolute;
34
+ text-overflow: ellipsis;
35
+ bottom: 10px;
36
+ left: 10px;
37
+ user-select: none;
38
+ white-space: nowrap;
39
+ display: inline-block;
40
+ pointer-events: none;
41
+ }
42
+
43
+ .InlineImageNode_Checkbox:checked,
44
+ .InlineImageNode_Checkbox:not(:checked) {
45
+ position: absolute;
46
+ left: -9999px;
47
+ }
48
+
49
+ .InlineImageNode_Checkbox:checked + label,
50
+ .InlineImageNode_Checkbox:not(:checked) + label {
51
+ position: absolute;
52
+ padding-right: 55px;
53
+ cursor: pointer;
54
+ line-height: 20px;
55
+ display: inline-block;
56
+ color: #666;
57
+ }
58
+
59
+ .InlineImageNode_Checkbox:checked + label:before,
60
+ .InlineImageNode_Checkbox:not(:checked) + label:before {
61
+ content: '';
62
+ position: absolute;
63
+ right: 0;
64
+ top: 0;
65
+ width: 18px;
66
+ height: 18px;
67
+ border: 1px solid #666;
68
+ background: #fff;
69
+ }
70
+
71
+ .InlineImageNode_Checkbox:checked + label:after,
72
+ .InlineImageNode_Checkbox:not(:checked) + label:after {
73
+ content: '';
74
+ width: 8px;
75
+ height: 8px;
76
+ background: #222222;
77
+ position: absolute;
78
+ top: 6px;
79
+ right: 6px;
80
+ -webkit-transition: all 0.2s ease;
81
+ transition: all 0.2s ease;
82
+ }
83
+
84
+ .InlineImageNode_Checkbox:not(:checked) + label:after {
85
+ opacity: 0;
86
+ -webkit-transform: scale(0);
87
+ transform: scale(0);
88
+ }
89
+
90
+ .InlineImageNode_Checkbox:checked + label:after {
91
+ opacity: 1;
92
+ -webkit-transform: scale(1);
93
+ transform: scale(1);
94
+ }