eddyter 1.3.30

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 (223) hide show
  1. package/README.md +444 -0
  2. package/dist/App.d.ts +3 -0
  3. package/dist/Provider/EditorProvider.d.ts +27 -0
  4. package/dist/Provider/LexicalProvider.d.ts +6 -0
  5. package/dist/api/ai/index.d.ts +31 -0
  6. package/dist/api/auth.d.ts +108 -0
  7. package/dist/api/config/axios.d.ts +2 -0
  8. package/dist/api/config/endpoints.d.ts +21 -0
  9. package/dist/api/featureSuggestion.d.ts +23 -0
  10. package/dist/api/linkPreview.d.ts +15 -0
  11. package/dist/api/transcript/index.d.ts +1 -0
  12. package/dist/assets/style.css +7990 -0
  13. package/dist/babel-d3085146.js +7776 -0
  14. package/dist/babel-d3085146.js.map +1 -0
  15. package/dist/components/AiPlugin/index.d.ts +6 -0
  16. package/dist/components/AlignMenu/AlignMenu.d.ts +9 -0
  17. package/dist/components/AlignMenu/AlignMenuDrop.d.ts +3 -0
  18. package/dist/components/AlignMenu/index.d.ts +1 -0
  19. package/dist/components/AutoExpandingDemo.d.ts +6 -0
  20. package/dist/components/BlockFormatMenu/BlockFormatMenu.d.ts +4 -0
  21. package/dist/components/BlockFormatMenu/constants.d.ts +14 -0
  22. package/dist/components/BlockFormatMenu/index.d.ts +1 -0
  23. package/dist/components/ChartEditDialog.d.ts +9 -0
  24. package/dist/components/ChartInsertDialog.d.ts +8 -0
  25. package/dist/components/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
  26. package/dist/components/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +9 -0
  27. package/dist/components/CodeActionMenuPlugin/index.d.ts +4 -0
  28. package/dist/components/CodeActionMenuPlugin/utils.d.ts +1 -0
  29. package/dist/components/ColorPicker/ColorPicker.d.ts +4 -0
  30. package/dist/components/ColorPicker/index.d.ts +1 -0
  31. package/dist/components/CommentSidebar/CommentSidebar.d.ts +8 -0
  32. package/dist/components/CommentSidebar/index.d.ts +1 -0
  33. package/dist/components/CommentToggle/CommentToggle.d.ts +8 -0
  34. package/dist/components/CommentToggle/index.d.ts +1 -0
  35. package/dist/components/CommentView/CommentView.d.ts +9 -0
  36. package/dist/components/CommentView/index.d.ts +1 -0
  37. package/dist/components/ConfigurableEditorWithAuth.d.ts +24 -0
  38. package/dist/components/DatePicker/DatePickerWidget.d.ts +8 -0
  39. package/dist/components/EmojiPickerWidget/EmojiPickerWidget.d.ts +4 -0
  40. package/dist/components/EmojiPickerWidget/index.d.ts +1 -0
  41. package/dist/components/FeatureSuggestionDialog/index.d.ts +6 -0
  42. package/dist/components/FileUpload/InsertFileDialog.d.ts +7 -0
  43. package/dist/components/FileUpload/InsertFileUploadedDialogBody.d.ts +5 -0
  44. package/dist/components/FileView/index.d.ts +9 -0
  45. package/dist/components/FontFamilySelect/FontFamilyMenu.d.ts +8 -0
  46. package/dist/components/FontSizePicker/FontSizeControl.d.ts +3 -0
  47. package/dist/components/FormatTextMenu/FormatTextMenu.d.ts +4 -0
  48. package/dist/components/FormatTextMenu/FormatTextMenuDrop.d.ts +4 -0
  49. package/dist/components/FormatTextMenu/index.d.ts +1 -0
  50. package/dist/components/HighlightColorPicker/HighlightColorPicker.d.ts +7 -0
  51. package/dist/components/HtmlViewDisplay.d.ts +3 -0
  52. package/dist/components/ImageComparisonDialog/index.d.ts +11 -0
  53. package/dist/components/ImageGenerationDialog/ImageGenerationManager.d.ts +11 -0
  54. package/dist/components/ImageGenerationDialog/index.d.ts +11 -0
  55. package/dist/components/ImageInsertTest.d.ts +3 -0
  56. package/dist/components/ImageView/ImageDialog/ImageUploadDialogBody.d.ts +9 -0
  57. package/dist/components/ImageView/ImageDialog/index.d.ts +6 -0
  58. package/dist/components/ImageView/ImageResizer.d.ts +16 -0
  59. package/dist/components/ImageView/index.d.ts +18 -0
  60. package/dist/components/InsertMenu/InsertMenu.d.ts +9 -0
  61. package/dist/components/InsertMenu/InsertMenuDrop.d.ts +9 -0
  62. package/dist/components/InsertMenu/index.d.ts +1 -0
  63. package/dist/components/LanguageSelectorDialog/index.d.ts +8 -0
  64. package/dist/components/NotePanelMenu/NotePanelMenu.d.ts +6 -0
  65. package/dist/components/NotePanelMenu/index.d.ts +1 -0
  66. package/dist/components/NotePanelView/NotePanelView.d.ts +10 -0
  67. package/dist/components/NotePanelView/index.d.ts +1 -0
  68. package/dist/components/Placeholder/Placeholder.d.ts +4 -0
  69. package/dist/components/Placeholder/index.d.ts +1 -0
  70. package/dist/components/Placeholder/styles.d.ts +1 -0
  71. package/dist/components/ScopedEditor.d.ts +8 -0
  72. package/dist/components/SignatureCaption/index.d.ts +6 -0
  73. package/dist/components/TableColorPicker/index.d.ts +8 -0
  74. package/dist/components/TableModal/TableModal.d.ts +10 -0
  75. package/dist/components/TextEnhanceDialog/index.d.ts +10 -0
  76. package/dist/components/ToneAdjustDialog/index.d.ts +8 -0
  77. package/dist/components/Toolbar/Toolbar.d.ts +4 -0
  78. package/dist/components/Toolbar/index.d.ts +1 -0
  79. package/dist/components/Toolbar/styles.d.ts +6 -0
  80. package/dist/components/VoiceTranscriptIcon/VoiceTranscriptIcon.d.ts +2 -0
  81. package/dist/components/VoiceTranscriptIcon/index.d.ts +1 -0
  82. package/dist/components/ui/avatar.d.ts +6 -0
  83. package/dist/components/ui/badge.d.ts +9 -0
  84. package/dist/components/ui/button.d.ts +11 -0
  85. package/dist/components/ui/calendar.d.ts +8 -0
  86. package/dist/components/ui/card.d.ts +8 -0
  87. package/dist/components/ui/checkbox.d.ts +4 -0
  88. package/dist/components/ui/dialog.d.ts +19 -0
  89. package/dist/components/ui/dropdown-menu.d.ts +27 -0
  90. package/dist/components/ui/input.d.ts +3 -0
  91. package/dist/components/ui/label.d.ts +5 -0
  92. package/dist/components/ui/popover.d.ts +7 -0
  93. package/dist/components/ui/select.d.ts +13 -0
  94. package/dist/components/ui/separator.d.ts +4 -0
  95. package/dist/components/ui/sheet.d.ts +25 -0
  96. package/dist/components/ui/skeleton.d.ts +3 -0
  97. package/dist/components/ui/tabs.d.ts +7 -0
  98. package/dist/components/ui/textarea.d.ts +3 -0
  99. package/dist/components/ui/tooltip.d.ts +7 -0
  100. package/dist/constants.d.ts +40 -0
  101. package/dist/context/CommentContext.d.ts +43 -0
  102. package/dist/context/HtmlViewContext.d.ts +17 -0
  103. package/dist/context/ToolbarContext.d.ts +57 -0
  104. package/dist/editorConfig.d.ts +48 -0
  105. package/dist/estree-164983f6.js +4691 -0
  106. package/dist/estree-164983f6.js.map +1 -0
  107. package/dist/hooks/useAutoExpandingHeight.d.ts +15 -0
  108. package/dist/hooks/useBlockFormat.d.ts +20 -0
  109. package/dist/hooks/useColorPicker.d.ts +6 -0
  110. package/dist/hooks/useCustomCommands.d.ts +3 -0
  111. package/dist/hooks/useDebounce.d.ts +1 -0
  112. package/dist/hooks/useEditorToolbar.d.ts +10 -0
  113. package/dist/hooks/useInsertMenu.d.ts +9 -0
  114. package/dist/hooks/useModal.d.ts +5 -0
  115. package/dist/hooks/useReactNativeBridge.d.ts +54 -0
  116. package/dist/hooks/useS3Uploader.d.ts +11 -0
  117. package/dist/hooks/useVoiceToText.d.ts +15 -0
  118. package/dist/html-5586dbf6.js +2930 -0
  119. package/dist/html-5586dbf6.js.map +1 -0
  120. package/dist/html2pdf.bundle-8d3a50b2.js +46128 -0
  121. package/dist/html2pdf.bundle-8d3a50b2.js.map +1 -0
  122. package/dist/html2pdf.bundle.min-d80d5aa7.js +21987 -0
  123. package/dist/html2pdf.bundle.min-d80d5aa7.js.map +1 -0
  124. package/dist/index-68349a2f.js +1286 -0
  125. package/dist/index-68349a2f.js.map +1 -0
  126. package/dist/index-e6dfde84.js +41188 -0
  127. package/dist/index-e6dfde84.js.map +1 -0
  128. package/dist/index-e7705f79.js +190 -0
  129. package/dist/index-e7705f79.js.map +1 -0
  130. package/dist/index.d.ts +10 -0
  131. package/dist/index.js +50 -0
  132. package/dist/index.js.map +1 -0
  133. package/dist/lib/utils.d.ts +2 -0
  134. package/dist/main.d.ts +0 -0
  135. package/dist/markdown-d513479b.js +3806 -0
  136. package/dist/markdown-d513479b.js.map +1 -0
  137. package/dist/nodes/ChartNode.d.ts +41 -0
  138. package/dist/nodes/CommentNode.d.ts +34 -0
  139. package/dist/nodes/CommentedTextNode.d.ts +29 -0
  140. package/dist/nodes/EmbedNode.d.ts +32 -0
  141. package/dist/nodes/FileNode.d.ts +32 -0
  142. package/dist/nodes/ImageNode.d.ts +65 -0
  143. package/dist/nodes/MentionNode.d.ts +75 -0
  144. package/dist/nodes/NotePanelNode.d.ts +31 -0
  145. package/dist/pages/ConfigurableEditor/ConfigurableEditor.d.ts +26 -0
  146. package/dist/pages/ConfigurableEditor/index.d.ts +2 -0
  147. package/dist/pages/NotFound.d.ts +2 -0
  148. package/dist/pages/RichTextEditor.d.ts +6 -0
  149. package/dist/pages/TextareaEditor.d.ts +6 -0
  150. package/dist/pages/styles.d.ts +5 -0
  151. package/dist/pcm-processor.js +50 -0
  152. package/dist/plugins/AIChatPlugin.d.ts +11 -0
  153. package/dist/plugins/AndroidKeyboardFixPlugin.d.ts +16 -0
  154. package/dist/plugins/AutocompletePlugin.d.ts +22 -0
  155. package/dist/plugins/CodeBlockNormalizerPlugin.d.ts +8 -0
  156. package/dist/plugins/CodeBlockSelectAllPlugin.d.ts +8 -0
  157. package/dist/plugins/CodeHighlightPlugin.d.ts +3 -0
  158. package/dist/plugins/CombinedAutocompletGrammarPlugin.d.ts +20 -0
  159. package/dist/plugins/CommentBubblePlugin.d.ts +3 -0
  160. package/dist/plugins/CommentPlugin.d.ts +8 -0
  161. package/dist/plugins/CustomHorizontalRulePlugin/CustomHorizontalRuleNode.d.ts +30 -0
  162. package/dist/plugins/CustomHorizontalRulePlugin/CustomHorizontalRulePlugin.d.ts +3 -0
  163. package/dist/plugins/CustomHorizontalRulePlugin/HorizontalRuleCustomizationDialog.d.ts +8 -0
  164. package/dist/plugins/CustomHorizontalRulePlugin/index.d.ts +3 -0
  165. package/dist/plugins/DragDropPastePlugin/index.d.ts +8 -0
  166. package/dist/plugins/EmbedPreviewPlugin/FloatingEmbedMenuPlugin.d.ts +3 -0
  167. package/dist/plugins/EmbedPreviewPlugin/index.d.ts +6 -0
  168. package/dist/plugins/FilePlugin.d.ts +8 -0
  169. package/dist/plugins/FloatingEnhanceButton/index.d.ts +4 -0
  170. package/dist/plugins/FloatingLinkEditorPlugin/index.d.ts +6 -0
  171. package/dist/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +27 -0
  172. package/dist/plugins/GrammarCheckPlugin.d.ts +1 -0
  173. package/dist/plugins/HtmlCodeViewPlugin/index.d.ts +2 -0
  174. package/dist/plugins/HtmlImportPlugin.d.ts +5 -0
  175. package/dist/plugins/HtmlSyncPlugin.d.ts +3 -0
  176. package/dist/plugins/ImagePlugin.d.ts +9 -0
  177. package/dist/plugins/LinkPlugin/index.d.ts +6 -0
  178. package/dist/plugins/LinkPreviewPlugin/index.d.ts +4 -0
  179. package/dist/plugins/LocalStoragePlugin.d.ts +8 -0
  180. package/dist/plugins/MarkdownShortcutsPlugin/index.d.ts +20 -0
  181. package/dist/plugins/MentionsPlugin/index.d.ts +7 -0
  182. package/dist/plugins/NotePanelPlugin.d.ts +7 -0
  183. package/dist/plugins/PasteOptionsPlugin/index.d.ts +17 -0
  184. package/dist/plugins/RichTextPastePlugin/index.d.ts +6 -0
  185. package/dist/plugins/SignatureCanvasPlugin/SignatureCanvasDialog.d.ts +6 -0
  186. package/dist/plugins/SignatureCanvasPlugin/SignatureCanvasPlugin.d.ts +9 -0
  187. package/dist/plugins/SignatureCanvasPlugin/index.d.ts +2 -0
  188. package/dist/plugins/SlashCommandPlugin/index.d.ts +2 -0
  189. package/dist/plugins/TableActionMenuPlugin/index.d.ts +6 -0
  190. package/dist/plugins/TableCellResizer/index.d.ts +2 -0
  191. package/dist/plugins/TableHoverActionsPlugin/index.d.ts +4 -0
  192. package/dist/plugins/TablePlugin.d.ts +5 -0
  193. package/dist/plugins/Tableimageautoresizeplugin.d.ts +1 -0
  194. package/dist/plugins/TextEnhancePlugin.d.ts +6 -0
  195. package/dist/plugins/TreeViewPlugin.d.ts +3 -0
  196. package/dist/plugins/UsageTrackingPlugin.d.ts +15 -0
  197. package/dist/plugins/VoiceTranscriptPlugin.d.ts +21 -0
  198. package/dist/plugins/WordCountPlugin.d.ts +3 -0
  199. package/dist/postcss-f084f74d.js +5420 -0
  200. package/dist/postcss-f084f74d.js.map +1 -0
  201. package/dist/standalone-5a8c6b7e.js +2518 -0
  202. package/dist/standalone-5a8c6b7e.js.map +1 -0
  203. package/dist/styles/PlaygroundEditorTheme.d.ts +3 -0
  204. package/dist/types.d.ts +155 -0
  205. package/dist/typescript-b1005db4.js +13705 -0
  206. package/dist/typescript-b1005db4.js.map +1 -0
  207. package/dist/ui/ColorPicker.d.ts +14 -0
  208. package/dist/ui/Icons.d.ts +48 -0
  209. package/dist/ui/TextInput.d.ts +11 -0
  210. package/dist/utils/dateFormats.d.ts +33 -0
  211. package/dist/utils/debounce.d.ts +6 -0
  212. package/dist/utils/editorStyleConverter.d.ts +17 -0
  213. package/dist/utils/export.d.ts +2 -0
  214. package/dist/utils/getDOMRangeRect.d.ts +13 -0
  215. package/dist/utils/getSelectedNode.d.ts +3 -0
  216. package/dist/utils/helper.d.ts +3 -0
  217. package/dist/utils/index.d.ts +5 -0
  218. package/dist/utils/invarient.d.ts +1 -0
  219. package/dist/utils/setFloatingElemPosition.d.ts +8 -0
  220. package/dist/utils/setFloatingElemPositionForLinkEditor.d.ts +1 -0
  221. package/dist/utils/url.d.ts +9 -0
  222. package/dist/vite.svg +1 -0
  223. package/package.json +127 -0
@@ -0,0 +1,1286 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { CodeNode } from "@lexical/code";
3
+ import { LinkNode } from "@lexical/link";
4
+ import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
5
+ import { useCollaborationContext } from "@lexical/react/LexicalCollaborationContext";
6
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
7
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
8
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
9
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
10
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
11
+ import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
12
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
13
+ import { useLexicalEditable } from "@lexical/react/useLexicalEditable";
14
+ import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection";
15
+ import { calculateZoomLevel, mergeRegister } from "@lexical/utils";
16
+ import { RootNode, TextNode, LineBreakNode, ParagraphNode, $getSelection, $isNodeSelection, $isParagraphNode, $setSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, createCommand, $getNodeByKey } from "lexical";
17
+ import { useRef, useState, useEffect, useCallback, Suspense } from "react";
18
+ import { a as createLucideIcon, b as Dialog, d as DialogContent, e as DialogHeader, f as DialogTitle, h as DialogDescription, i as DialogFooter, B as Button, L as LocalStoragePlugin, j as initialConfig, k as $isImageNode, A as AlignLeft, l as AlignCenter, m as AlignRight, n as Type, S as Sparkles, E as ExternalLink, T as Trash2, t as toast, o as AiJsonResponse } from "./index-e6dfde84.js";
19
+ import "axios";
20
+ import "@emotion/styled";
21
+ import "@lexical/html";
22
+ import "@lexical/react/LexicalCheckListPlugin";
23
+ import "@lexical/react/LexicalComposer";
24
+ import "@lexical/react/LexicalHorizontalRulePlugin";
25
+ import "@lexical/react/LexicalListPlugin";
26
+ import "@lexical/react/LexicalTablePlugin";
27
+ import "@lexical/table";
28
+ import "react-dom";
29
+ import "@lexical/list";
30
+ import "@lexical/rich-text";
31
+ import "@lexical/selection";
32
+ import "@lexical/react/LexicalHorizontalRuleNode";
33
+ import "@mui/icons-material/Description";
34
+ import "@mui/icons-material/FolderZip";
35
+ import "@mui/icons-material/InsertChart";
36
+ import "@mui/icons-material/InsertDriveFile";
37
+ import "@mui/icons-material/PictureAsPdf";
38
+ import "@lexical/react/LexicalDecoratorBlockNode";
39
+ import "emoji-picker-react";
40
+ import "@lexical/react/LexicalLinkPlugin";
41
+ import "@lexical/react/LexicalTypeaheadMenuPlugin";
42
+ /**
43
+ * @license lucide-react v0.344.0 - ISC
44
+ *
45
+ * This source code is licensed under the ISC license.
46
+ * See the LICENSE file in the root directory of this source tree.
47
+ */
48
+ const Link2 = createLucideIcon("Link2", [
49
+ ["path", { d: "M9 17H7A5 5 0 0 1 7 7h2", key: "8i5ue5" }],
50
+ ["path", { d: "M15 7h2a5 5 0 1 1 0 10h-2", key: "1b9ql8" }],
51
+ ["line", { x1: "8", x2: "16", y1: "12", y2: "12", key: "1jonct" }]
52
+ ]);
53
+ /**
54
+ * @license lucide-react v0.344.0 - ISC
55
+ *
56
+ * This source code is licensed under the ISC license.
57
+ * See the LICENSE file in the root directory of this source tree.
58
+ */
59
+ const WrapText = createLucideIcon("WrapText", [
60
+ ["line", { x1: "3", x2: "21", y1: "6", y2: "6", key: "4m8b97" }],
61
+ ["path", { d: "M3 12h15a3 3 0 1 1 0 6h-4", key: "1cl7v7" }],
62
+ ["polyline", { points: "16 16 14 18 16 20", key: "1jznyi" }],
63
+ ["line", { x1: "3", x2: "10", y1: "18", y2: "18", key: "1h33wv" }]
64
+ ]);
65
+ const imageCaptionStyles = "";
66
+ const ImageComparisonDialog = ({
67
+ open,
68
+ onOpenChange,
69
+ oldImageUrl,
70
+ newImageUrl,
71
+ onReplace,
72
+ onCancel
73
+ }) => {
74
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-[800px] max-h-[90vh] overflow-y-auto", children: [
75
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [
76
+ /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2 text-xl", children: [
77
+ /* @__PURE__ */ jsx("span", { className: "text-2xl", children: "🔄" }),
78
+ "Compare Images"
79
+ ] }),
80
+ /* @__PURE__ */ jsx(DialogDescription, { className: "text-sm pt-1", children: "Choose whether to replace the original image with the refined version." })
81
+ ] }),
82
+ /* @__PURE__ */ jsxs("div", { className: "space-y-4 py-4", children: [
83
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-4", children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
84
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
85
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold text-gray-700 dark:text-gray-300", children: "Refined Image" }),
86
+ /* @__PURE__ */ jsx("span", { className: "text-xs px-2 py-1 rounded-full bg-blue-100 dark:bg-blue-950/30 text-blue-600 dark:text-blue-400", children: "New" })
87
+ ] }),
88
+ /* @__PURE__ */ jsx("div", { className: "relative aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border-2 border-blue-500 dark:border-blue-600", children: /* @__PURE__ */ jsx(
89
+ "img",
90
+ {
91
+ src: newImageUrl,
92
+ alt: "Refined",
93
+ className: "w-full h-full object-contain"
94
+ }
95
+ ) })
96
+ ] }) }),
97
+ /* @__PURE__ */ jsx("div", { className: "p-3 rounded-lg bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800", children: /* @__PURE__ */ jsxs("p", { className: "text-sm text-blue-800 dark:text-blue-200", children: [
98
+ /* @__PURE__ */ jsx("span", { className: "font-semibold", children: "Note:" }),
99
+ ' Clicking "Replace" will update the image in your document. This action cannot be undone.'
100
+ ] }) })
101
+ ] }),
102
+ /* @__PURE__ */ jsxs(DialogFooter, { className: "gap-2", children: [
103
+ /* @__PURE__ */ jsx(
104
+ Button,
105
+ {
106
+ variant: "outline",
107
+ onClick: onCancel,
108
+ children: "Keep Original"
109
+ }
110
+ ),
111
+ /* @__PURE__ */ jsxs(
112
+ Button,
113
+ {
114
+ onClick: onReplace,
115
+ className: "bg-blue-500 hover:bg-blue-600 text-white",
116
+ children: [
117
+ /* @__PURE__ */ jsx("span", { className: "mr-2", children: "✓" }),
118
+ "Replace Image"
119
+ ]
120
+ }
121
+ )
122
+ ] })
123
+ ] }) });
124
+ };
125
+ const signatureCaption = "";
126
+ function SignatureCaption({
127
+ caption
128
+ }) {
129
+ return /* @__PURE__ */ jsx("div", { className: "signature-caption-container", children: /* @__PURE__ */ jsxs(
130
+ LexicalNestedComposer,
131
+ {
132
+ initialEditor: caption,
133
+ initialNodes: [
134
+ RootNode,
135
+ TextNode,
136
+ LineBreakNode,
137
+ ParagraphNode,
138
+ LinkNode,
139
+ CodeNode
140
+ ],
141
+ children: [
142
+ /* @__PURE__ */ jsx(
143
+ RichTextPlugin,
144
+ {
145
+ contentEditable: /* @__PURE__ */ jsx(
146
+ ContentEditable,
147
+ {
148
+ "aria-placeholder": "Enter signature name...",
149
+ placeholder: /* @__PURE__ */ jsx("div", { style: {
150
+ position: "absolute",
151
+ top: "4px",
152
+ left: "8px",
153
+ right: "8px",
154
+ textAlign: "center",
155
+ pointerEvents: "none",
156
+ color: "hsla(var(--cteditorf47ac10b-foreground) / 0.4)",
157
+ fontStyle: "italic"
158
+ }, children: "Enter signature name..." }),
159
+ className: "signature-caption-editable"
160
+ }
161
+ ),
162
+ ErrorBoundary: LexicalErrorBoundary
163
+ }
164
+ ),
165
+ /* @__PURE__ */ jsx(OnChangePlugin, { onChange: () => {
166
+ } }),
167
+ /* @__PURE__ */ jsx(HistoryPlugin, {}),
168
+ /* @__PURE__ */ jsx(LocalStoragePlugin, { namespace: initialConfig.namespace })
169
+ ]
170
+ }
171
+ ) });
172
+ }
173
+ function clamp(value, min, max) {
174
+ return Math.min(Math.max(value, min), max);
175
+ }
176
+ const Direction = {
177
+ east: 1 << 0,
178
+ north: 1 << 3,
179
+ south: 1 << 1,
180
+ west: 1 << 2
181
+ };
182
+ function ImageResizer({
183
+ onResizeStart,
184
+ onResizeEnd,
185
+ buttonRef,
186
+ imageRef,
187
+ maxWidth,
188
+ editor,
189
+ showCaption,
190
+ setShowCaption,
191
+ captionsEnabled
192
+ }) {
193
+ const controlWrapperRef = useRef(null);
194
+ const userSelect = useRef({
195
+ priority: "",
196
+ value: "default"
197
+ });
198
+ const positioningRef = useRef({
199
+ currentHeight: 0,
200
+ currentWidth: 0,
201
+ direction: 0,
202
+ isResizing: false,
203
+ ratio: 0,
204
+ startHeight: 0,
205
+ startWidth: 0,
206
+ startX: 0,
207
+ startY: 0
208
+ });
209
+ const editorRootElement = editor.getRootElement();
210
+ const maxWidthContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().width - 20 : 100;
211
+ const maxHeightContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;
212
+ const minWidth = 100;
213
+ const minHeight = 100;
214
+ const setStartCursor = (direction) => {
215
+ const ew = direction === Direction.east || direction === Direction.west;
216
+ const ns = direction === Direction.north || direction === Direction.south;
217
+ const nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
218
+ const cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
219
+ if (editorRootElement !== null) {
220
+ editorRootElement.style.setProperty(
221
+ "cursor",
222
+ `${cursorDir}-resize`,
223
+ "important"
224
+ );
225
+ }
226
+ if (document.body !== null) {
227
+ document.body.style.setProperty(
228
+ "cursor",
229
+ `${cursorDir}-resize`,
230
+ "important"
231
+ );
232
+ userSelect.current.value = document.body.style.getPropertyValue(
233
+ "-webkit-user-select"
234
+ );
235
+ userSelect.current.priority = document.body.style.getPropertyPriority(
236
+ "-webkit-user-select"
237
+ );
238
+ document.body.style.setProperty(
239
+ "-webkit-user-select",
240
+ `none`,
241
+ "important"
242
+ );
243
+ }
244
+ };
245
+ const setEndCursor = () => {
246
+ if (editorRootElement !== null) {
247
+ editorRootElement.style.setProperty("cursor", "text");
248
+ }
249
+ if (document.body !== null) {
250
+ document.body.style.setProperty("cursor", "default");
251
+ document.body.style.setProperty(
252
+ "-webkit-user-select",
253
+ userSelect.current.value,
254
+ userSelect.current.priority
255
+ );
256
+ }
257
+ };
258
+ const handlePointerDown = (event, direction) => {
259
+ if (!editor.isEditable()) {
260
+ return;
261
+ }
262
+ const image = imageRef.current;
263
+ const controlWrapper = controlWrapperRef.current;
264
+ if (image !== null && controlWrapper !== null) {
265
+ event.preventDefault();
266
+ const { width, height } = image.getBoundingClientRect();
267
+ const zoom = calculateZoomLevel(image);
268
+ const positioning = positioningRef.current;
269
+ positioning.startWidth = width;
270
+ positioning.startHeight = height;
271
+ positioning.ratio = width / height;
272
+ positioning.currentWidth = width;
273
+ positioning.currentHeight = height;
274
+ positioning.startX = event.clientX / zoom;
275
+ positioning.startY = event.clientY / zoom;
276
+ positioning.isResizing = true;
277
+ positioning.direction = direction;
278
+ setStartCursor(direction);
279
+ onResizeStart();
280
+ controlWrapper.classList.add("image-control-wrapper--resizing");
281
+ image.style.height = `${height}px`;
282
+ image.style.width = `${width}px`;
283
+ document.addEventListener("pointermove", handlePointerMove);
284
+ document.addEventListener("pointerup", handlePointerUp);
285
+ }
286
+ };
287
+ const handlePointerMove = (event) => {
288
+ const image = imageRef.current;
289
+ const positioning = positioningRef.current;
290
+ const isHorizontal = positioning.direction & (Direction.east | Direction.west);
291
+ const isVertical = positioning.direction & (Direction.south | Direction.north);
292
+ if (image !== null && positioning.isResizing) {
293
+ const zoom = calculateZoomLevel(image);
294
+ if (isHorizontal && isVertical) {
295
+ let diff = Math.floor(positioning.startX - event.clientX / zoom);
296
+ diff = positioning.direction & Direction.east ? -diff : diff;
297
+ const width = clamp(
298
+ positioning.startWidth + diff,
299
+ minWidth,
300
+ maxWidthContainer
301
+ );
302
+ const height = width / positioning.ratio;
303
+ image.style.width = `${width}px`;
304
+ image.style.height = `${height}px`;
305
+ positioning.currentHeight = height;
306
+ positioning.currentWidth = width;
307
+ } else if (isVertical) {
308
+ let diff = Math.floor(positioning.startY - event.clientY / zoom);
309
+ diff = positioning.direction & Direction.south ? -diff : diff;
310
+ const height = clamp(
311
+ positioning.startHeight + diff,
312
+ minHeight,
313
+ maxHeightContainer
314
+ );
315
+ image.style.height = `${height}px`;
316
+ positioning.currentHeight = height;
317
+ } else {
318
+ let diff = Math.floor(positioning.startX - event.clientX / zoom);
319
+ diff = positioning.direction & Direction.east ? -diff : diff;
320
+ const width = clamp(
321
+ positioning.startWidth + diff,
322
+ minWidth,
323
+ maxWidthContainer
324
+ );
325
+ image.style.width = `${width}px`;
326
+ positioning.currentWidth = width;
327
+ }
328
+ }
329
+ };
330
+ const handlePointerUp = () => {
331
+ const image = imageRef.current;
332
+ const positioning = positioningRef.current;
333
+ const controlWrapper = controlWrapperRef.current;
334
+ if (image !== null && controlWrapper !== null && positioning.isResizing) {
335
+ const width = positioning.currentWidth;
336
+ const height = positioning.currentHeight;
337
+ positioning.startWidth = 0;
338
+ positioning.startHeight = 0;
339
+ positioning.ratio = 0;
340
+ positioning.startX = 0;
341
+ positioning.startY = 0;
342
+ positioning.currentWidth = 0;
343
+ positioning.currentHeight = 0;
344
+ positioning.isResizing = false;
345
+ controlWrapper.classList.remove("image-control-wrapper--resizing");
346
+ setEndCursor();
347
+ onResizeEnd(width, height);
348
+ document.removeEventListener("pointermove", handlePointerMove);
349
+ document.removeEventListener("pointerup", handlePointerUp);
350
+ }
351
+ };
352
+ return /* @__PURE__ */ jsxs("div", { ref: controlWrapperRef, children: [
353
+ !showCaption && captionsEnabled && /* @__PURE__ */ jsx(
354
+ "button",
355
+ {
356
+ className: "image-caption-button",
357
+ ref: buttonRef,
358
+ onClick: () => {
359
+ setShowCaption(!showCaption);
360
+ },
361
+ children: "Add Caption"
362
+ }
363
+ ),
364
+ /* @__PURE__ */ jsx(
365
+ "div",
366
+ {
367
+ className: "image-resizer image-resizer-n",
368
+ onPointerDown: (event) => {
369
+ handlePointerDown(event, Direction.north);
370
+ }
371
+ }
372
+ ),
373
+ /* @__PURE__ */ jsx(
374
+ "div",
375
+ {
376
+ className: "image-resizer image-resizer-ne",
377
+ onPointerDown: (event) => {
378
+ handlePointerDown(event, Direction.north | Direction.east);
379
+ }
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsx(
383
+ "div",
384
+ {
385
+ className: "image-resizer image-resizer-e",
386
+ onPointerDown: (event) => {
387
+ handlePointerDown(event, Direction.east);
388
+ }
389
+ }
390
+ ),
391
+ /* @__PURE__ */ jsx(
392
+ "div",
393
+ {
394
+ className: "image-resizer image-resizer-se",
395
+ onPointerDown: (event) => {
396
+ handlePointerDown(event, Direction.south | Direction.east);
397
+ }
398
+ }
399
+ ),
400
+ /* @__PURE__ */ jsx(
401
+ "div",
402
+ {
403
+ className: "image-resizer image-resizer-s",
404
+ onPointerDown: (event) => {
405
+ handlePointerDown(event, Direction.south);
406
+ }
407
+ }
408
+ ),
409
+ /* @__PURE__ */ jsx(
410
+ "div",
411
+ {
412
+ className: "image-resizer image-resizer-sw",
413
+ onPointerDown: (event) => {
414
+ handlePointerDown(event, Direction.south | Direction.west);
415
+ }
416
+ }
417
+ ),
418
+ /* @__PURE__ */ jsx(
419
+ "div",
420
+ {
421
+ className: "image-resizer image-resizer-w",
422
+ onPointerDown: (event) => {
423
+ handlePointerDown(event, Direction.west);
424
+ }
425
+ }
426
+ ),
427
+ /* @__PURE__ */ jsx(
428
+ "div",
429
+ {
430
+ className: "image-resizer image-resizer-nw",
431
+ onPointerDown: (event) => {
432
+ handlePointerDown(event, Direction.north | Direction.west);
433
+ }
434
+ }
435
+ )
436
+ ] });
437
+ }
438
+ const imageCache = /* @__PURE__ */ new Set();
439
+ const RIGHT_CLICK_IMAGE_COMMAND = createCommand("RIGHT_CLICK_IMAGE_COMMAND");
440
+ function useSuspenseImage(src) {
441
+ if (!imageCache.has(src)) {
442
+ throw new Promise((resolve) => {
443
+ const img = new Image();
444
+ img.src = src;
445
+ img.onload = () => {
446
+ imageCache.add(src);
447
+ resolve(null);
448
+ };
449
+ img.onerror = () => {
450
+ imageCache.add(src);
451
+ };
452
+ });
453
+ }
454
+ }
455
+ function LazyImage({
456
+ altText,
457
+ className,
458
+ imageRef,
459
+ src,
460
+ width,
461
+ height,
462
+ maxWidth,
463
+ onError
464
+ }) {
465
+ useSuspenseImage(src);
466
+ const hasExplicitSize = typeof width === "number" && typeof height === "number";
467
+ const computedWidth = typeof width === "number" ? width : "auto";
468
+ const computedHeight = typeof height === "number" ? height : "auto";
469
+ return /* @__PURE__ */ jsx(
470
+ "img",
471
+ {
472
+ className: className || void 0,
473
+ src,
474
+ alt: altText,
475
+ ref: imageRef,
476
+ style: hasExplicitSize ? {
477
+ // User has set a numeric size or original dimensions are provided
478
+ width: computedWidth,
479
+ height: computedHeight,
480
+ maxWidth: "100%"
481
+ } : {
482
+ // No dimensions specified - use original image size
483
+ maxWidth: "100%",
484
+ height: "auto"
485
+ },
486
+ onError,
487
+ draggable: "false"
488
+ }
489
+ );
490
+ }
491
+ function BrokenImage() {
492
+ return /* @__PURE__ */ jsx(
493
+ "img",
494
+ {
495
+ src: "",
496
+ style: {
497
+ height: 200,
498
+ opacity: 0.2,
499
+ width: 200
500
+ },
501
+ draggable: "false"
502
+ }
503
+ );
504
+ }
505
+ function ImageComponent({
506
+ src,
507
+ altText,
508
+ nodeKey,
509
+ width,
510
+ height,
511
+ maxWidth,
512
+ resizable,
513
+ showCaption,
514
+ caption,
515
+ captionsEnabled,
516
+ originalPrompt,
517
+ position = "none",
518
+ linkUrl
519
+ }) {
520
+ const imageRef = useRef(null);
521
+ const buttonRef = useRef(null);
522
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
523
+ const [isResizing, setIsResizing] = useState(false);
524
+ useCollaborationContext();
525
+ const [editor] = useLexicalComposerContext();
526
+ const [selection, setSelection] = useState(null);
527
+ const activeEditorRef = useRef(null);
528
+ const [isLoadError, setIsLoadError] = useState(false);
529
+ const isEditable = useLexicalEditable();
530
+ const [showRefineInput, setShowRefineInput] = useState(false);
531
+ const [refinementPrompt, setRefinementPrompt] = useState("");
532
+ const [isRefining, setIsRefining] = useState(false);
533
+ const [showComparisonDialog, setShowComparisonDialog] = useState(false);
534
+ const [newImageUrl, setNewImageUrl] = useState("");
535
+ const [newCombinedPrompt, setNewCombinedPrompt] = useState("");
536
+ const [showLinkPreview, setShowLinkPreview] = useState(false);
537
+ const linkPreviewTimeoutRef = useRef(null);
538
+ const [imageWidth, setImageWidth] = useState(0);
539
+ const shouldPositionBelow = imageWidth > 0 && imageWidth < 350;
540
+ useEffect(() => {
541
+ if (imageRef.current) {
542
+ const updateWidth = () => {
543
+ if (imageRef.current) {
544
+ setImageWidth(imageRef.current.offsetWidth);
545
+ }
546
+ };
547
+ updateWidth();
548
+ const resizeObserver = new ResizeObserver(updateWidth);
549
+ resizeObserver.observe(imageRef.current);
550
+ return () => resizeObserver.disconnect();
551
+ }
552
+ }, [width, height, isSelected]);
553
+ const $onDelete = useCallback(
554
+ (payload) => {
555
+ const deleteSelection = $getSelection();
556
+ if (isSelected && $isNodeSelection(deleteSelection)) {
557
+ const event = payload;
558
+ event.preventDefault();
559
+ editor.update(() => {
560
+ deleteSelection.getNodes().forEach((node) => {
561
+ if ($isImageNode(node)) {
562
+ const parent = node.getParent();
563
+ node.remove();
564
+ if (parent && $isParagraphNode(parent) && parent.getChildrenSize() === 0) {
565
+ parent.setFormat("left");
566
+ }
567
+ }
568
+ });
569
+ });
570
+ }
571
+ return false;
572
+ },
573
+ [editor, isSelected]
574
+ );
575
+ const $onEnter = useCallback(
576
+ (event) => {
577
+ const latestSelection = $getSelection();
578
+ const buttonElem = buttonRef.current;
579
+ if (isSelected && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
580
+ if (showCaption) {
581
+ $setSelection(null);
582
+ event.preventDefault();
583
+ caption.focus();
584
+ return true;
585
+ } else if (buttonElem !== null && buttonElem !== document.activeElement) {
586
+ event.preventDefault();
587
+ buttonElem.focus();
588
+ return true;
589
+ }
590
+ }
591
+ return false;
592
+ },
593
+ [caption, isSelected, showCaption]
594
+ );
595
+ const $onEscape = useCallback(
596
+ (event) => {
597
+ if (activeEditorRef.current === caption || buttonRef.current === event.target) {
598
+ $setSelection(null);
599
+ editor.update(() => {
600
+ setSelected(true);
601
+ const parentRootElement = editor.getRootElement();
602
+ if (parentRootElement !== null) {
603
+ parentRootElement.focus();
604
+ }
605
+ });
606
+ return true;
607
+ }
608
+ return false;
609
+ },
610
+ [caption, editor, setSelected]
611
+ );
612
+ const onClick = useCallback(
613
+ (payload) => {
614
+ const event = payload;
615
+ if (isResizing) {
616
+ return true;
617
+ }
618
+ const target = event.target;
619
+ const isClickOnImage = target === imageRef.current;
620
+ let isClickWithinImageBounds = false;
621
+ if (!isClickOnImage && imageRef.current) {
622
+ const imageRect = imageRef.current.getBoundingClientRect();
623
+ isClickWithinImageBounds = event.clientX >= imageRect.left && event.clientX <= imageRect.right && event.clientY >= imageRect.top && event.clientY <= imageRect.bottom;
624
+ }
625
+ if (isClickOnImage || isClickWithinImageBounds) {
626
+ if (event.shiftKey) {
627
+ setSelected(!isSelected);
628
+ } else {
629
+ clearSelection();
630
+ setSelected(true);
631
+ }
632
+ return true;
633
+ }
634
+ return false;
635
+ },
636
+ [isResizing, isSelected, setSelected, clearSelection]
637
+ );
638
+ const onRightClick = useCallback(
639
+ (event) => {
640
+ editor.getEditorState().read(() => {
641
+ const latestSelection = $getSelection();
642
+ const domElement = event.target;
643
+ if (domElement.tagName === "IMG" && $isRangeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
644
+ editor.dispatchCommand(
645
+ RIGHT_CLICK_IMAGE_COMMAND,
646
+ event
647
+ );
648
+ }
649
+ });
650
+ },
651
+ [editor]
652
+ );
653
+ useEffect(() => {
654
+ let isMounted = true;
655
+ const rootElement = editor.getRootElement();
656
+ const unregister = mergeRegister(
657
+ editor.registerUpdateListener(({ editorState }) => {
658
+ if (isMounted) {
659
+ setSelection(editorState.read(() => $getSelection()));
660
+ }
661
+ }),
662
+ editor.registerCommand(
663
+ SELECTION_CHANGE_COMMAND,
664
+ (_, activeEditor) => {
665
+ activeEditorRef.current = activeEditor;
666
+ return false;
667
+ },
668
+ COMMAND_PRIORITY_LOW
669
+ ),
670
+ editor.registerCommand(
671
+ CLICK_COMMAND,
672
+ onClick,
673
+ COMMAND_PRIORITY_LOW
674
+ ),
675
+ editor.registerCommand(
676
+ RIGHT_CLICK_IMAGE_COMMAND,
677
+ onClick,
678
+ COMMAND_PRIORITY_LOW
679
+ ),
680
+ editor.registerCommand(
681
+ DRAGSTART_COMMAND,
682
+ (event) => {
683
+ if (event.target === imageRef.current) {
684
+ event.preventDefault();
685
+ return true;
686
+ }
687
+ return false;
688
+ },
689
+ COMMAND_PRIORITY_LOW
690
+ ),
691
+ editor.registerCommand(
692
+ KEY_DELETE_COMMAND,
693
+ $onDelete,
694
+ COMMAND_PRIORITY_LOW
695
+ ),
696
+ editor.registerCommand(
697
+ KEY_BACKSPACE_COMMAND,
698
+ $onDelete,
699
+ COMMAND_PRIORITY_LOW
700
+ ),
701
+ editor.registerCommand(KEY_ENTER_COMMAND, $onEnter, COMMAND_PRIORITY_LOW),
702
+ editor.registerCommand(
703
+ KEY_ESCAPE_COMMAND,
704
+ $onEscape,
705
+ COMMAND_PRIORITY_LOW
706
+ )
707
+ );
708
+ rootElement == null ? void 0 : rootElement.addEventListener("contextmenu", onRightClick);
709
+ return () => {
710
+ isMounted = false;
711
+ unregister();
712
+ rootElement == null ? void 0 : rootElement.removeEventListener("contextmenu", onRightClick);
713
+ };
714
+ }, [
715
+ clearSelection,
716
+ editor,
717
+ isResizing,
718
+ isSelected,
719
+ nodeKey,
720
+ $onDelete,
721
+ $onEnter,
722
+ $onEscape,
723
+ onClick,
724
+ onRightClick,
725
+ setSelected
726
+ ]);
727
+ const setShowCaption = () => {
728
+ editor.update(() => {
729
+ const node = $getNodeByKey(nodeKey);
730
+ if ($isImageNode(node)) {
731
+ node.setShowCaption(true);
732
+ }
733
+ });
734
+ };
735
+ const onResizeEnd = (nextWidth, nextHeight) => {
736
+ setTimeout(() => {
737
+ setIsResizing(false);
738
+ }, 200);
739
+ editor.update(() => {
740
+ const node = $getNodeByKey(nodeKey);
741
+ if ($isImageNode(node)) {
742
+ node.setWidthAndHeight(nextWidth, nextHeight);
743
+ }
744
+ });
745
+ };
746
+ const onResizeStart = () => {
747
+ setIsResizing(true);
748
+ };
749
+ const handleOpenInNewTab = (e) => {
750
+ e.preventDefault();
751
+ e.stopPropagation();
752
+ if (src.startsWith("data:")) {
753
+ const newWindow = window.open("", "_blank");
754
+ if (newWindow) {
755
+ newWindow.document.write(`
756
+ <!DOCTYPE html>
757
+ <html>
758
+ <head>
759
+ <title>${altText || "Image"}</title>
760
+ <style>
761
+ body {
762
+ margin: 0;
763
+ display: flex;
764
+ justify-content: center;
765
+ align-items: center;
766
+ min-height: 100vh;
767
+ background-color: #1a1a1a;
768
+ }
769
+ img {
770
+ max-width: 100%;
771
+ max-height: 100vh;
772
+ object-fit: contain;
773
+ }
774
+ </style>
775
+ </head>
776
+ <body>
777
+ <img src="${src}" alt="${altText || "Image"}" />
778
+ </body>
779
+ </html>
780
+ `);
781
+ newWindow.document.close();
782
+ }
783
+ } else {
784
+ window.open(src, "_blank");
785
+ }
786
+ };
787
+ const handleDeleteImage = (e) => {
788
+ e.preventDefault();
789
+ e.stopPropagation();
790
+ editor.update(() => {
791
+ const node = $getNodeByKey(nodeKey);
792
+ if ($isImageNode(node)) {
793
+ const parent = node.getParent();
794
+ node.remove();
795
+ if (parent && $isParagraphNode(parent) && parent.getChildrenSize() === 0) {
796
+ parent.setFormat("left");
797
+ }
798
+ }
799
+ });
800
+ };
801
+ const handlePositionChange = (e, newPosition) => {
802
+ e.preventDefault();
803
+ e.stopPropagation();
804
+ editor.update(() => {
805
+ const node = $getNodeByKey(nodeKey);
806
+ if ($isImageNode(node)) {
807
+ node.setPosition(newPosition);
808
+ }
809
+ });
810
+ };
811
+ const handleRefineClick = (e) => {
812
+ e.preventDefault();
813
+ e.stopPropagation();
814
+ setShowRefineInput(!showRefineInput);
815
+ };
816
+ const handleImageMouseEnter = useCallback(() => {
817
+ if (linkUrl && !isSelected) {
818
+ linkPreviewTimeoutRef.current = setTimeout(() => {
819
+ setShowLinkPreview(true);
820
+ }, 300);
821
+ }
822
+ }, [linkUrl, isSelected]);
823
+ const handleImageMouseLeave = useCallback(() => {
824
+ if (linkPreviewTimeoutRef.current) {
825
+ clearTimeout(linkPreviewTimeoutRef.current);
826
+ linkPreviewTimeoutRef.current = null;
827
+ }
828
+ setShowLinkPreview(false);
829
+ }, []);
830
+ const handleLinkClick = useCallback((e) => {
831
+ e.preventDefault();
832
+ e.stopPropagation();
833
+ if (linkUrl) {
834
+ window.open(linkUrl, "_blank", "noopener,noreferrer");
835
+ }
836
+ }, [linkUrl]);
837
+ useEffect(() => {
838
+ return () => {
839
+ if (linkPreviewTimeoutRef.current) {
840
+ clearTimeout(linkPreviewTimeoutRef.current);
841
+ }
842
+ };
843
+ }, []);
844
+ const handleRefineImage = async () => {
845
+ if (!refinementPrompt.trim() || isRefining)
846
+ return;
847
+ setIsRefining(true);
848
+ const loadingToast = toast.loading("Refining image...", {
849
+ description: "This may take 10-30 seconds. Please wait."
850
+ });
851
+ try {
852
+ let combinedPrompt = refinementPrompt.trim();
853
+ if (originalPrompt && originalPrompt.trim()) {
854
+ const original = originalPrompt.trim();
855
+ const refinement = refinementPrompt.trim();
856
+ const cleanedRefinement = refinement.replace(/^(add|also add|include|with|and)\s+(some|a|an)\s+/gi, "").replace(/^(add|also add|include|with|and)\s+/gi, "").trim();
857
+ combinedPrompt = `${original} with ${cleanedRefinement}`;
858
+ } else {
859
+ if (altText && altText !== "Generated image" && altText.trim()) {
860
+ const cleanedRefinement = refinementPrompt.trim().replace(/^(add|also add|include|with|and)\s+(some|a|an)\s+/gi, "").replace(/^(add|also add|include|with|and)\s+/gi, "").trim();
861
+ combinedPrompt = `${altText} with ${cleanedRefinement}`;
862
+ }
863
+ }
864
+ const response = await AiJsonResponse({
865
+ content: `Generate Image: ${combinedPrompt}`
866
+ });
867
+ const htmlString = response == null ? void 0 : response.data;
868
+ if (!htmlString) {
869
+ throw new Error("Failed to generate image - empty response");
870
+ }
871
+ const parser = new DOMParser();
872
+ const dom = parser.parseFromString(htmlString, "text/html");
873
+ const imgElement = dom.querySelector("img");
874
+ if (!imgElement || !imgElement.src) {
875
+ throw new Error(`No image found in response`);
876
+ }
877
+ const generatedImageUrl = imgElement.src;
878
+ toast.dismiss(loadingToast);
879
+ toast.success("Image refined successfully!", {
880
+ description: "Compare the images and choose which to keep."
881
+ });
882
+ setNewImageUrl(generatedImageUrl);
883
+ setNewCombinedPrompt(combinedPrompt);
884
+ setShowComparisonDialog(true);
885
+ setRefinementPrompt("");
886
+ setShowRefineInput(false);
887
+ } catch (error) {
888
+ toast.dismiss(loadingToast);
889
+ toast.error("Failed to refine image", {
890
+ description: error instanceof Error ? error.message : "Unknown error. Please try again."
891
+ });
892
+ } finally {
893
+ setIsRefining(false);
894
+ }
895
+ };
896
+ const handleReplaceImage = () => {
897
+ editor.update(() => {
898
+ const node = $getNodeByKey(nodeKey);
899
+ if ($isImageNode(node)) {
900
+ node.setSrc(newImageUrl);
901
+ node.setOriginalPrompt(newCombinedPrompt);
902
+ const currentSelection = $getSelection();
903
+ if (currentSelection) {
904
+ $setSelection(currentSelection.clone());
905
+ }
906
+ }
907
+ });
908
+ setShowComparisonDialog(false);
909
+ setNewImageUrl("");
910
+ setNewCombinedPrompt("");
911
+ toast.success("Image replaced successfully!", {
912
+ description: "The image has been updated with the refined version."
913
+ });
914
+ };
915
+ const handleCancelReplace = () => {
916
+ setShowComparisonDialog(false);
917
+ setNewImageUrl("");
918
+ setNewCombinedPrompt("");
919
+ };
920
+ const draggable = isSelected && $isNodeSelection(selection) && !isResizing;
921
+ const isFocused = (isSelected || isResizing) && isEditable;
922
+ const getPositionStyles = () => {
923
+ if (position === "left" || position === "right") {
924
+ return {
925
+ position: "relative",
926
+ display: "block",
927
+ width: "100%"
928
+ // Fill the floated container
929
+ };
930
+ }
931
+ if (position === "full") {
932
+ return {
933
+ position: "relative",
934
+ display: "inline-block"
935
+ // Use inline-block to respect text-align: center from parent
936
+ };
937
+ }
938
+ if (position === "inline-left" || position === "inline-center" || position === "inline-right") {
939
+ return {
940
+ position: "relative",
941
+ display: "inline-block"
942
+ // Use inline-block to respect text-align from parent
943
+ };
944
+ }
945
+ return {
946
+ position: "relative",
947
+ display: "inline-block"
948
+ };
949
+ };
950
+ const handleDirectClick = useCallback(
951
+ (e) => {
952
+ if (isResizing) {
953
+ return;
954
+ }
955
+ if (e.target.closest("button")) {
956
+ return;
957
+ }
958
+ const target = e.target;
959
+ const isClickOnImage = target === imageRef.current;
960
+ let isClickWithinImageBounds = false;
961
+ if (!isClickOnImage && imageRef.current) {
962
+ const imageRect = imageRef.current.getBoundingClientRect();
963
+ isClickWithinImageBounds = e.clientX >= imageRect.left && e.clientX <= imageRect.right && e.clientY >= imageRect.top && e.clientY <= imageRect.bottom;
964
+ }
965
+ if (!isClickOnImage && !isClickWithinImageBounds) {
966
+ return;
967
+ }
968
+ e.stopPropagation();
969
+ if (e.shiftKey) {
970
+ setSelected(!isSelected);
971
+ } else {
972
+ clearSelection();
973
+ setSelected(true);
974
+ }
975
+ },
976
+ [isResizing, isSelected, setSelected, clearSelection]
977
+ );
978
+ return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsxs(Fragment, { children: [
979
+ /* @__PURE__ */ jsxs(
980
+ "div",
981
+ {
982
+ draggable,
983
+ style: getPositionStyles(),
984
+ onClick: handleDirectClick,
985
+ onMouseEnter: handleImageMouseEnter,
986
+ onMouseLeave: handleImageMouseLeave,
987
+ children: [
988
+ isLoadError ? /* @__PURE__ */ jsx(BrokenImage, {}) : /* @__PURE__ */ jsx(
989
+ LazyImage,
990
+ {
991
+ className: isFocused ? `focused ${$isNodeSelection(selection) ? "draggable" : ""}` : linkUrl ? "cteditor-cursor-pointer" : null,
992
+ src,
993
+ altText,
994
+ imageRef,
995
+ width,
996
+ height,
997
+ maxWidth,
998
+ onError: () => setIsLoadError(true)
999
+ }
1000
+ ),
1001
+ showLinkPreview && linkUrl && !isSelected && /* @__PURE__ */ jsxs(
1002
+ "div",
1003
+ {
1004
+ className: "cteditor-absolute cteditor-bottom-2 cteditor-left-2 cteditor-right-2 cteditor-bg-background cteditor-rounded-lg cteditor-shadow-lg cteditor-border cteditor-border-border cteditor-p-2 cteditor-flex cteditor-items-center cteditor-gap-2",
1005
+ style: { zIndex: 10 },
1006
+ children: [
1007
+ /* @__PURE__ */ jsx(Link2, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-muted-foreground cteditor-flex-shrink-0" }),
1008
+ /* @__PURE__ */ jsx("span", { className: "cteditor-text-sm cteditor-text-foreground cteditor-truncate cteditor-flex-1", children: linkUrl }),
1009
+ /* @__PURE__ */ jsx(
1010
+ "button",
1011
+ {
1012
+ onClick: handleLinkClick,
1013
+ className: "cteditor-px-2 cteditor-py-1 cteditor-text-xs cteditor-rounded cteditor-bg-primary cteditor-text-primary-foreground hover:cteditor-bg-primary/90 cteditor-transition-colors cteditor-flex-shrink-0",
1014
+ children: "Open"
1015
+ }
1016
+ )
1017
+ ]
1018
+ }
1019
+ ),
1020
+ isSelected && $isNodeSelection(selection) && !isLoadError && /* @__PURE__ */ jsxs(
1021
+ "div",
1022
+ {
1023
+ className: `cteditor-absolute cteditor-flex cteditor-gap-1 z-10 ${shouldPositionBelow ? "cteditor-left-1/2 cteditor--translate-x-1/2 cteditor-bottom-0 cteditor-translate-y-full cteditor-mt-1" : "cteditor-top-2 cteditor-right-2"}`,
1024
+ children: [
1025
+ /* @__PURE__ */ jsxs("div", { className: "cteditor-flex cteditor-items-center cteditor-gap-0.5 cteditor-bg-background/80 cteditor-rounded-md cteditor-shadow-md cteditor-border cteditor-border-border cteditor-p-0.5", children: [
1026
+ /* @__PURE__ */ jsx(
1027
+ "button",
1028
+ {
1029
+ onClick: (e) => handlePositionChange(e, "left"),
1030
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "left" ? "cteditor-bg-accent" : ""}`,
1031
+ "aria-label": "Wrap text left",
1032
+ title: "Wrap text left",
1033
+ children: /* @__PURE__ */ jsx(WrapText, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground", style: { transform: "scaleX(-1)" } })
1034
+ }
1035
+ ),
1036
+ /* @__PURE__ */ jsx(
1037
+ "button",
1038
+ {
1039
+ onClick: (e) => handlePositionChange(e, "right"),
1040
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "right" ? "cteditor-bg-accent" : ""}`,
1041
+ "aria-label": "Wrap text right",
1042
+ title: "Wrap text right",
1043
+ children: /* @__PURE__ */ jsx(WrapText, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1044
+ }
1045
+ ),
1046
+ /* @__PURE__ */ jsx("div", { className: "cteditor-w-px cteditor-h-5 cteditor-bg-border cteditor-mx-0.5" }),
1047
+ /* @__PURE__ */ jsx(
1048
+ "button",
1049
+ {
1050
+ onClick: (e) => handlePositionChange(e, "inline-left"),
1051
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "inline-left" ? "cteditor-bg-accent" : ""}`,
1052
+ "aria-label": "Align left",
1053
+ title: "Align left (no text wrap)",
1054
+ children: /* @__PURE__ */ jsx(AlignLeft, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1055
+ }
1056
+ ),
1057
+ /* @__PURE__ */ jsx(
1058
+ "button",
1059
+ {
1060
+ onClick: (e) => handlePositionChange(e, "inline-center"),
1061
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "inline-center" || position === "full" ? "cteditor-bg-accent" : ""}`,
1062
+ "aria-label": "Align center",
1063
+ title: "Align center (no text wrap)",
1064
+ children: /* @__PURE__ */ jsx(AlignCenter, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1065
+ }
1066
+ ),
1067
+ /* @__PURE__ */ jsx(
1068
+ "button",
1069
+ {
1070
+ onClick: (e) => handlePositionChange(e, "inline-right"),
1071
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "inline-right" ? "cteditor-bg-accent" : ""}`,
1072
+ "aria-label": "Align right",
1073
+ title: "Align right (no text wrap)",
1074
+ children: /* @__PURE__ */ jsx(AlignRight, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1075
+ }
1076
+ ),
1077
+ /* @__PURE__ */ jsx("div", { className: "cteditor-w-px cteditor-h-5 cteditor-bg-border cteditor-mx-0.5" }),
1078
+ /* @__PURE__ */ jsx(
1079
+ "button",
1080
+ {
1081
+ onClick: (e) => handlePositionChange(e, "none"),
1082
+ className: `cteditor-p-1.5 cteditor-rounded hover:cteditor-bg-accent cteditor-transition-colors ${position === "none" ? "cteditor-bg-accent" : ""}`,
1083
+ "aria-label": "Inline",
1084
+ title: "Inline with text",
1085
+ children: /* @__PURE__ */ jsx(Type, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1086
+ }
1087
+ )
1088
+ ] }),
1089
+ linkUrl && /* @__PURE__ */ jsx(
1090
+ "button",
1091
+ {
1092
+ onClick: handleLinkClick,
1093
+ className: "cteditor-p-2 cteditor-rounded-md cteditor-bg-background/80 hover:cteditor-bg-accent cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-border",
1094
+ "aria-label": "Visit link",
1095
+ title: `Visit: ${linkUrl}`,
1096
+ children: /* @__PURE__ */ jsx(Link2, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1097
+ }
1098
+ ),
1099
+ originalPrompt && /* @__PURE__ */ jsx(
1100
+ "button",
1101
+ {
1102
+ onClick: (e) => {
1103
+ e.stopPropagation();
1104
+ handleRefineClick(e);
1105
+ },
1106
+ className: "cteditor-p-2 cteditor-rounded-md cteditor-bg-background/80 hover:cteditor-bg-accent cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-border",
1107
+ "aria-label": "Refine image",
1108
+ title: "Refine image",
1109
+ children: /* @__PURE__ */ jsx(Sparkles, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1110
+ }
1111
+ ),
1112
+ /* @__PURE__ */ jsx(
1113
+ "button",
1114
+ {
1115
+ onClick: (e) => {
1116
+ e.stopPropagation();
1117
+ handleOpenInNewTab(e);
1118
+ },
1119
+ className: "cteditor-p-2 cteditor-rounded-md cteditor-bg-background/80 hover:cteditor-bg-accent cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-border",
1120
+ "aria-label": "Open image in new tab",
1121
+ title: "Open in new tab",
1122
+ children: /* @__PURE__ */ jsx(ExternalLink, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1123
+ }
1124
+ ),
1125
+ /* @__PURE__ */ jsx(
1126
+ "button",
1127
+ {
1128
+ onClick: (e) => {
1129
+ e.stopPropagation();
1130
+ handleDeleteImage(e);
1131
+ },
1132
+ className: "cteditor-p-2 cteditor-rounded-md cteditor-bg-background/80 hover:cteditor-bg-destructive hover:cteditor-text-destructive-foreground cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-border",
1133
+ "aria-label": "Delete image",
1134
+ title: "Delete image",
1135
+ children: /* @__PURE__ */ jsx(Trash2, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1136
+ }
1137
+ )
1138
+ ]
1139
+ }
1140
+ ),
1141
+ showRefineInput && isSelected && !isLoadError && originalPrompt && /* @__PURE__ */ jsx(
1142
+ "div",
1143
+ {
1144
+ className: "cteditor-absolute cteditor-bottom-2 cteditor-left-2 cteditor-right-2 cteditor-bg-background cteditor-rounded-lg cteditor-shadow-xl cteditor-border cteditor-border-border cteditor-p-3",
1145
+ style: { zIndex: 10 },
1146
+ onClick: (e) => e.stopPropagation(),
1147
+ onKeyDown: (e) => e.stopPropagation(),
1148
+ onKeyUp: (e) => e.stopPropagation(),
1149
+ children: /* @__PURE__ */ jsxs("div", { className: "cteditor-flex cteditor-flex-col cteditor-gap-2", children: [
1150
+ /* @__PURE__ */ jsx("label", { className: "cteditor-text-xs cteditor-font-medium cteditor-text-foreground", children: "What else do you want in this scene?" }),
1151
+ /* @__PURE__ */ jsx(
1152
+ "input",
1153
+ {
1154
+ type: "text",
1155
+ value: refinementPrompt,
1156
+ onChange: (e) => setRefinementPrompt(e.target.value),
1157
+ onKeyDown: (e) => {
1158
+ e.stopPropagation();
1159
+ if (e.key === "Enter" && refinementPrompt.trim() && !isRefining) {
1160
+ handleRefineImage();
1161
+ }
1162
+ if (e.key === "Escape") {
1163
+ setShowRefineInput(false);
1164
+ setRefinementPrompt("");
1165
+ }
1166
+ },
1167
+ onKeyUp: (e) => {
1168
+ e.stopPropagation();
1169
+ },
1170
+ onClick: (e) => {
1171
+ e.stopPropagation();
1172
+ },
1173
+ placeholder: "e.g., flying birds, golden sunset, stormy clouds...",
1174
+ className: "cteditor-w-full cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-border cteditor-border-border cteditor-rounded-md cteditor-bg-background cteditor-text-foreground focus:cteditor-outline-none focus:cteditor-ring-2 focus:cteditor-ring-blue-500",
1175
+ disabled: isRefining,
1176
+ autoFocus: true
1177
+ }
1178
+ ),
1179
+ /* @__PURE__ */ jsxs("div", { className: "cteditor-flex cteditor-gap-2", children: [
1180
+ /* @__PURE__ */ jsx(
1181
+ "button",
1182
+ {
1183
+ onClick: (e) => {
1184
+ e.stopPropagation();
1185
+ handleRefineImage();
1186
+ },
1187
+ disabled: isRefining || !refinementPrompt.trim(),
1188
+ className: "cteditor-flex-1 cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-blue-500 cteditor-text-white hover:cteditor-bg-blue-600 disabled:cteditor-opacity-50 disabled:cteditor-cursor-not-allowed cteditor-transition-colors",
1189
+ children: isRefining ? /* @__PURE__ */ jsxs("span", { className: "cteditor-flex cteditor-items-center cteditor-justify-center cteditor-gap-2", children: [
1190
+ /* @__PURE__ */ jsx("span", { className: "cteditor-inline-block cteditor-w-4 cteditor-h-4 cteditor-border-2 cteditor-border-white cteditor-border-t-transparent cteditor-rounded-full cteditor-animate-spin" }),
1191
+ "Refining..."
1192
+ ] }) : "Refine Image"
1193
+ }
1194
+ ),
1195
+ /* @__PURE__ */ jsx(
1196
+ "button",
1197
+ {
1198
+ onClick: (e) => {
1199
+ e.stopPropagation();
1200
+ setShowRefineInput(false);
1201
+ setRefinementPrompt("");
1202
+ },
1203
+ disabled: isRefining,
1204
+ className: "cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-background cteditor-border cteditor-border-border cteditor-text-foreground hover:cteditor-bg-accent disabled:cteditor-opacity-50 disabled:cteditor-cursor-not-allowed cteditor-transition-colors",
1205
+ children: "Cancel"
1206
+ }
1207
+ )
1208
+ ] })
1209
+ ] })
1210
+ }
1211
+ ),
1212
+ resizable && $isNodeSelection(selection) && isFocused && /* @__PURE__ */ jsx(
1213
+ ImageResizer,
1214
+ {
1215
+ showCaption,
1216
+ setShowCaption,
1217
+ editor,
1218
+ buttonRef,
1219
+ imageRef,
1220
+ maxWidth,
1221
+ onResizeStart,
1222
+ onResizeEnd,
1223
+ captionsEnabled: !isLoadError && captionsEnabled
1224
+ }
1225
+ )
1226
+ ]
1227
+ }
1228
+ ),
1229
+ showCaption && (altText.startsWith("Signature by") ? /* @__PURE__ */ jsx(SignatureCaption, { caption }) : /* @__PURE__ */ jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ jsxs(
1230
+ LexicalNestedComposer,
1231
+ {
1232
+ initialEditor: caption,
1233
+ initialNodes: [
1234
+ RootNode,
1235
+ TextNode,
1236
+ LineBreakNode,
1237
+ ParagraphNode,
1238
+ LinkNode,
1239
+ CodeNode
1240
+ ],
1241
+ children: [
1242
+ /* @__PURE__ */ jsx(AutoFocusPlugin, {}),
1243
+ /* @__PURE__ */ jsx(
1244
+ RichTextPlugin,
1245
+ {
1246
+ contentEditable: /* @__PURE__ */ jsx(
1247
+ ContentEditable,
1248
+ {
1249
+ "aria-placeholder": "Enter a caption...",
1250
+ placeholder: () => /* @__PURE__ */ jsx("span", { className: "cteditor-text-xs", children: "Enter a caption..." }),
1251
+ className: "ImageNode__contentEditable"
1252
+ }
1253
+ ),
1254
+ ErrorBoundary: LexicalErrorBoundary
1255
+ }
1256
+ ),
1257
+ /* @__PURE__ */ jsx(
1258
+ OnChangePlugin,
1259
+ {
1260
+ onChange: () => {
1261
+ }
1262
+ }
1263
+ ),
1264
+ /* @__PURE__ */ jsx(HistoryPlugin, {}),
1265
+ /* @__PURE__ */ jsx(LocalStoragePlugin, { namespace: initialConfig.namespace })
1266
+ ]
1267
+ }
1268
+ ) })),
1269
+ /* @__PURE__ */ jsx(
1270
+ ImageComparisonDialog,
1271
+ {
1272
+ open: showComparisonDialog,
1273
+ onOpenChange: setShowComparisonDialog,
1274
+ oldImageUrl: src,
1275
+ newImageUrl,
1276
+ onReplace: handleReplaceImage,
1277
+ onCancel: handleCancelReplace
1278
+ }
1279
+ )
1280
+ ] }) });
1281
+ }
1282
+ export {
1283
+ RIGHT_CLICK_IMAGE_COMMAND,
1284
+ ImageComponent as default
1285
+ };
1286
+ //# sourceMappingURL=index-68349a2f.js.map