@collabchron/notiq 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +230 -39
  3. package/dist/CodeActionMenuPlugin-EINOY4U4.mjs +15 -0
  4. package/dist/DynamicBlockComponent-NRQJ4WW4.mjs +161 -0
  5. package/dist/EquationComponent-CB6DFIHV.mjs +154 -0
  6. package/dist/ExcalidrawComponent-XW6646OH.mjs +528 -0
  7. package/dist/ExcalidrawPlugin-ZFHT62IF.mjs +14 -0
  8. package/dist/ExportPlugin-V2RLM63S.mjs +11 -0
  9. package/dist/FloatingLinkEditorPlugin-TRTCMSP4.mjs +12 -0
  10. package/dist/FloatingTextFormatToolbarPlugin-F2GY6LMI.mjs +30 -0
  11. package/dist/HintComponet-BRL6EAMS.mjs +217 -0
  12. package/dist/InlineImageComponent-UWIUWBHI.mjs +453 -0
  13. package/dist/MobileToolbar-BOOZAMQE.mjs +268 -0
  14. package/dist/SlashCommand-GMT5JI33.mjs +28 -0
  15. package/dist/StoryBuilderComponent-JGDBM5JU.mjs +562 -0
  16. package/{src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx → dist/TableCellActionMenuPlugin-PGK2K3VG.mjs} +667 -759
  17. package/{src/components/editor/plugins/TableHoverActionsPlugin/index.tsx → dist/TableHoverActionsPlugin-GJVE6VRW.mjs} +258 -314
  18. package/dist/TemplatePlugin-ZD3QEVTI.mjs +9 -0
  19. package/dist/ToolbarPlugin-7TOZRD2R.mjs +1547 -0
  20. package/dist/babel-JZ2EV6AX.mjs +7233 -0
  21. package/dist/background-color-XZTYLGO2.mjs +362 -0
  22. package/dist/block-format-YJCV2DIY.mjs +15 -0
  23. package/dist/chunk-2FNEAMSP.mjs +127 -0
  24. package/dist/chunk-3CPBODXA.mjs +84 -0
  25. package/dist/chunk-3G37YKTV.mjs +83 -0
  26. package/dist/chunk-3JVFG7ER.mjs +184 -0
  27. package/dist/chunk-456TN7IM.mjs +110 -0
  28. package/dist/chunk-4EXYCTGJ.mjs +27 -0
  29. package/{src/utils/getSelectedNode.ts → dist/chunk-4HBCVSE6.mjs} +26 -27
  30. package/dist/chunk-4MEDW3T6.mjs +125 -0
  31. package/dist/chunk-4VWFVWYP.mjs +36 -0
  32. package/dist/chunk-5BAKY5KN.mjs +84 -0
  33. package/dist/chunk-5QSNIVIG.mjs +333 -0
  34. package/dist/chunk-64Z3FI7T.mjs +37 -0
  35. package/{src/components/editor/nodes/Stepper/index.tsx → dist/chunk-6RNZQOH2.mjs} +214 -260
  36. package/dist/chunk-77KXU36M.mjs +64 -0
  37. package/dist/chunk-77UA6HYR.mjs +165 -0
  38. package/dist/chunk-7NZAPJ4G.mjs +102 -0
  39. package/dist/chunk-7VUMHWWL.mjs +152 -0
  40. package/dist/chunk-AMMKBSST.mjs +1256 -0
  41. package/dist/chunk-BIU7WTLX.mjs +95 -0
  42. package/dist/chunk-EGMI62PP.mjs +83 -0
  43. package/dist/chunk-EHNQD5KO.mjs +88 -0
  44. package/dist/chunk-FSM26655.mjs +37 -0
  45. package/{src/components/editor/nodes/Hint/index.tsx → dist/chunk-G53GLEAY.mjs} +158 -190
  46. package/dist/chunk-GK35L7UY.mjs +28 -0
  47. package/dist/chunk-GXYD4VZM.mjs +193 -0
  48. package/dist/chunk-GYIOYVCN.mjs +538 -0
  49. package/dist/chunk-GZPNVR7L.mjs +157 -0
  50. package/dist/chunk-JXDPPUJI.mjs +52 -0
  51. package/dist/chunk-K36V4SIW.mjs +141 -0
  52. package/dist/chunk-KJ6AJ44Q.mjs +128 -0
  53. package/dist/chunk-KJV3FAZ7.mjs +142 -0
  54. package/{src/components/editor/plugins/ImagesPlugin/index.tsx → dist/chunk-LGG4IUIA.mjs} +189 -222
  55. package/dist/chunk-LQN3CMKV.mjs +1906 -0
  56. package/dist/chunk-N3WN46VL.mjs +236 -0
  57. package/dist/chunk-PBD6LMLC.mjs +366 -0
  58. package/dist/chunk-POGRR73N.mjs +33 -0
  59. package/{src/components/editor/utils/editorFormatting.ts → dist/chunk-PZSUSXQG.mjs} +238 -282
  60. package/dist/chunk-QEIFVK5M.mjs +29 -0
  61. package/dist/chunk-QHIQKMVN.mjs +427 -0
  62. package/dist/chunk-TCYK7DM7.mjs +36 -0
  63. package/dist/chunk-TTHQCW5F.mjs +47 -0
  64. package/dist/chunk-U47ABU5Z.mjs +53 -0
  65. package/dist/chunk-WDG7J2DY.mjs +116 -0
  66. package/dist/chunk-WJRHXI2C.mjs +733 -0
  67. package/dist/chunk-XLER2DHM.mjs +357 -0
  68. package/dist/chunk-XWC4TK2N.mjs +315 -0
  69. package/dist/chunk-YHPNOWFH.mjs +15 -0
  70. package/dist/chunk-YKC3SO4Z.mjs +32 -0
  71. package/dist/chunk-YMBXLRW5.mjs +374 -0
  72. package/dist/chunk-YPHOEJ46.mjs +64 -0
  73. package/dist/chunk-YUDCJRJM.mjs +25 -0
  74. package/dist/chunk-Z4EWP7BI.mjs +65 -0
  75. package/dist/chunk-ZB5LZQKC.mjs +191 -0
  76. package/dist/chunk-ZJRKATOJ.mjs +65 -0
  77. package/dist/color-BPKOPQKN.mjs +12 -0
  78. package/dist/estree-XC56IUFX.mjs +4414 -0
  79. package/dist/font-FEZ3GKSF.mjs +13 -0
  80. package/dist/font-size-EK775WRH.mjs +15 -0
  81. package/dist/html-S3ACX7NI.mjs +2738 -0
  82. package/dist/image-2PJIAYAT.mjs +993 -0
  83. package/dist/index.d.mts +145 -0
  84. package/dist/index.d.ts +145 -0
  85. package/dist/index.js +57855 -0
  86. package/dist/index.mjs +1790 -0
  87. package/dist/insert-gif-SAIDYURE.mjs +100 -0
  88. package/dist/insert-image-U3RJN3OW.mjs +259 -0
  89. package/dist/insert-node-5P2CRJ7S.mjs +201 -0
  90. package/dist/insert-poll-HCPM7MO6.mjs +33 -0
  91. package/dist/insert-table-24XYUS2W.mjs +66 -0
  92. package/dist/markdown-SNVBOSRA.mjs +3487 -0
  93. package/dist/poll-component-2R4MDLHS.mjs +303 -0
  94. package/dist/postcss-ONF3VDIM.mjs +5051 -0
  95. package/dist/standalone-EOIALU3M.mjs +2373 -0
  96. package/dist/stepper-FSARL6X6.mjs +304 -0
  97. package/dist/styles/notiq.css +1149 -0
  98. package/dist/text-align-VLECWO4H.mjs +118 -0
  99. package/dist/text-format-BG5WOOPZ.mjs +16 -0
  100. package/dist/typescript-AMPI6OVS.mjs +13135 -0
  101. package/package.json +94 -10
  102. package/src/styles/notiq.css +1149 -0
  103. package/src/styles/tailwind-plugin.ts +134 -0
  104. package/components.json +0 -21
  105. package/eslint.config.mjs +0 -16
  106. package/next.config.ts +0 -12
  107. package/postcss.config.mjs +0 -5
  108. package/public/file.svg +0 -1
  109. package/public/globe.svg +0 -1
  110. package/public/images/icons/plus.svg +0 -10
  111. package/public/next.svg +0 -1
  112. package/public/vercel.svg +0 -1
  113. package/public/window.svg +0 -1
  114. package/src/app/actions.ts +0 -2
  115. package/src/app/api/ai/route.ts +0 -175
  116. package/src/app/api/edgestore/[...edgestore]/route.ts +0 -28
  117. package/src/app/favicon.ico +0 -0
  118. package/src/app/globals.css +0 -205
  119. package/src/app/layout.tsx +0 -38
  120. package/src/app/page.tsx +0 -12
  121. package/src/components/editor/Core.tsx +0 -220
  122. package/src/components/editor/hooks/instructions-messages.ts +0 -300
  123. package/src/components/editor/hooks/use-mobile.ts +0 -19
  124. package/src/components/editor/hooks/useReport.ts +0 -67
  125. package/src/components/editor/hooks/useResizeObservert.ts +0 -22
  126. package/src/components/editor/index.tsx +0 -39
  127. package/src/components/editor/lexical-on-change.tsx +0 -28
  128. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +0 -92
  129. package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +0 -65
  130. package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +0 -105
  131. package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +0 -143
  132. package/src/components/editor/nodes/EquationNode/EquationNode.tsx +0 -170
  133. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +0 -228
  134. package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +0 -137
  135. package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +0 -317
  136. package/src/components/editor/nodes/ExcalidrawNode/index.tsx +0 -204
  137. package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +0 -134
  138. package/src/components/editor/nodes/Hint/HintComponet.tsx +0 -221
  139. package/src/components/editor/nodes/ImageNode/index.tsx +0 -328
  140. package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +0 -383
  141. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +0 -94
  142. package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +0 -309
  143. package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +0 -146
  144. package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +0 -79
  145. package/src/components/editor/nodes/PollNode/index.tsx +0 -204
  146. package/src/components/editor/nodes/TweetNode/index.tsx +0 -214
  147. package/src/components/editor/nodes/index.ts +0 -81
  148. package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +0 -350
  149. package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +0 -56
  150. package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +0 -70
  151. package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +0 -192
  152. package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +0 -217
  153. package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +0 -26
  154. package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +0 -21
  155. package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +0 -76
  156. package/src/components/editor/plugins/CollapsiblePlugin/index.ts +0 -228
  157. package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +0 -44
  158. package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +0 -52
  159. package/src/components/editor/plugins/EquationsPlugin/index.tsx +0 -85
  160. package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +0 -98
  161. package/src/components/editor/plugins/FigmaPlugin/index.tsx +0 -42
  162. package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +0 -445
  163. package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +0 -275
  164. package/src/components/editor/plugins/InlineImagePlugin/index.tsx +0 -351
  165. package/src/components/editor/plugins/LayoutPlugin/index.tsx +0 -238
  166. package/src/components/editor/plugins/LinkPlugin/index.tsx +0 -36
  167. package/src/components/editor/plugins/LinkWithMetaData/index.tsx +0 -271
  168. package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +0 -11
  169. package/src/components/editor/plugins/MarkdownTransformers/index.tsx +0 -304
  170. package/src/components/editor/plugins/PollPlugin/index.tsx +0 -49
  171. package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +0 -180
  172. package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +0 -253
  173. package/src/components/editor/plugins/SlashCommand/index.tsx +0 -621
  174. package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +0 -127
  175. package/src/components/editor/plugins/TabFocusPlugin/index.ts +0 -58
  176. package/src/components/editor/plugins/TableCellResizer/index.tsx +0 -438
  177. package/src/components/editor/plugins/TablePlugin/index.tsx +0 -99
  178. package/src/components/editor/plugins/ToolbarPlugin/index.tsx +0 -522
  179. package/src/components/editor/plugins/TwitterPlugin/index.ts +0 -35
  180. package/src/components/editor/plugins/YouTubeNode/index.tsx +0 -179
  181. package/src/components/editor/plugins/YouTubePlugin/index.ts +0 -41
  182. package/src/components/editor/themes/editor-theme.ts +0 -113
  183. package/src/components/editor/themes/theme.css +0 -377
  184. package/src/components/editor/utils/ai.ts +0 -291
  185. package/src/components/editor/utils/canUseDOM.ts +0 -12
  186. package/src/components/editor/utils/environment.ts +0 -50
  187. package/src/components/editor/utils/extract-data.ts +0 -166
  188. package/src/components/editor/utils/getAllLexicalChildren.ts +0 -13
  189. package/src/components/editor/utils/getDOMRangeRect.ts +0 -27
  190. package/src/components/editor/utils/getSelectedNode.ts +0 -27
  191. package/src/components/editor/utils/gif.ts +0 -29
  192. package/src/components/editor/utils/invariant.ts +0 -15
  193. package/src/components/editor/utils/setFloatingElemPosition.ts +0 -51
  194. package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +0 -40
  195. package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +0 -51
  196. package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +0 -15
  197. package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +0 -114
  198. package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +0 -6
  199. package/src/components/editor/utils/url.ts +0 -109
  200. package/src/components/editor/utils/useLayoutEffect.ts +0 -13
  201. package/src/components/providers/QueryProvider.tsx +0 -15
  202. package/src/components/providers/SharedHistoryContext.tsx +0 -28
  203. package/src/components/providers/ToolbarContext.tsx +0 -123
  204. package/src/components/providers/theme-provider.tsx +0 -11
  205. package/src/components/theme/ModeToggle.tsx +0 -40
  206. package/src/components/ui/FileInput.tsx +0 -40
  207. package/src/components/ui/Input.css +0 -32
  208. package/src/components/ui/Select.css +0 -42
  209. package/src/components/ui/Select.tsx +0 -36
  210. package/src/components/ui/TextInput.tsx +0 -48
  211. package/src/components/ui/ai/ai-button.tsx +0 -574
  212. package/src/components/ui/ai/border.tsx +0 -99
  213. package/src/components/ui/ai/placeholder-input-vanish.tsx +0 -282
  214. package/src/components/ui/button.tsx +0 -89
  215. package/src/components/ui/card.tsx +0 -76
  216. package/src/components/ui/checkbox.tsx +0 -30
  217. package/src/components/ui/command.tsx +0 -153
  218. package/src/components/ui/dialog/Dialog.css +0 -25
  219. package/src/components/ui/dialog/Dialog.tsx +0 -34
  220. package/src/components/ui/dialog.tsx +0 -122
  221. package/src/components/ui/drop-downs/background-color.tsx +0 -183
  222. package/src/components/ui/drop-downs/block-format.tsx +0 -159
  223. package/src/components/ui/drop-downs/code.tsx +0 -42
  224. package/src/components/ui/drop-downs/color.tsx +0 -177
  225. package/src/components/ui/drop-downs/font-size.tsx +0 -138
  226. package/src/components/ui/drop-downs/font.tsx +0 -155
  227. package/src/components/ui/drop-downs/index.tsx +0 -122
  228. package/src/components/ui/drop-downs/insert-node.tsx +0 -213
  229. package/src/components/ui/drop-downs/text-align.tsx +0 -123
  230. package/src/components/ui/drop-downs/text-format.tsx +0 -104
  231. package/src/components/ui/dropdown-menu.tsx +0 -201
  232. package/src/components/ui/equation/EquationEditor.css +0 -38
  233. package/src/components/ui/equation/EquationEditor.tsx +0 -56
  234. package/src/components/ui/equation/KatexEquationAlterer.css +0 -41
  235. package/src/components/ui/equation/KatexEquationAlterer.tsx +0 -83
  236. package/src/components/ui/equation/KatexRenderer.tsx +0 -66
  237. package/src/components/ui/excalidraw/ExcalidrawModal.css +0 -64
  238. package/src/components/ui/excalidraw/ExcalidrawModal.tsx +0 -234
  239. package/src/components/ui/excalidraw/Modal.css +0 -62
  240. package/src/components/ui/excalidraw/Modal.tsx +0 -110
  241. package/src/components/ui/hover-card.tsx +0 -29
  242. package/src/components/ui/image/error-image.tsx +0 -17
  243. package/src/components/ui/image/file-upload.tsx +0 -240
  244. package/src/components/ui/image/image-resizer.tsx +0 -297
  245. package/src/components/ui/image/image-toolbar.tsx +0 -264
  246. package/src/components/ui/image/index.tsx +0 -408
  247. package/src/components/ui/image/lazy-image.tsx +0 -68
  248. package/src/components/ui/image/lazy-video.tsx +0 -71
  249. package/src/components/ui/input.tsx +0 -22
  250. package/src/components/ui/models/custom-dialog.tsx +0 -320
  251. package/src/components/ui/models/insert-gif.tsx +0 -90
  252. package/src/components/ui/models/insert-image.tsx +0 -52
  253. package/src/components/ui/models/insert-poll.tsx +0 -29
  254. package/src/components/ui/models/insert-table.tsx +0 -62
  255. package/src/components/ui/models/use-model.tsx +0 -91
  256. package/src/components/ui/poll/poll-component.tsx +0 -304
  257. package/src/components/ui/popover.tsx +0 -33
  258. package/src/components/ui/progress.tsx +0 -28
  259. package/src/components/ui/scroll-area.tsx +0 -48
  260. package/src/components/ui/separator.tsx +0 -31
  261. package/src/components/ui/skeleton.tsx +0 -15
  262. package/src/components/ui/sonner.tsx +0 -31
  263. package/src/components/ui/stepper/step.tsx +0 -179
  264. package/src/components/ui/stepper/stepper.tsx +0 -89
  265. package/src/components/ui/textarea.tsx +0 -22
  266. package/src/components/ui/toggle.tsx +0 -71
  267. package/src/components/ui/tooltip.tsx +0 -32
  268. package/src/components/ui/write/text-format-floting-toolbar.tsx +0 -346
  269. package/src/lib/edgestore.ts +0 -9
  270. package/src/lib/pinecone-client.ts +0 -0
  271. package/src/lib/utils.ts +0 -6
  272. package/src/utils/docSerialization.ts +0 -77
  273. package/src/utils/emoji-list.ts +0 -16615
  274. package/src/utils/getDOMRangeRect.ts +0 -27
  275. package/src/utils/getThemeSelector.ts +0 -25
  276. package/src/utils/isMobileWidth.ts +0 -7
  277. package/src/utils/joinClasses.ts +0 -13
  278. package/src/utils/setFloatingElemPosition.ts +0 -74
  279. package/src/utils/setFloatingElemPositionForLinkEditor.ts +0 -46
  280. package/src/utils/swipe.ts +0 -127
  281. package/src/utils/url.ts +0 -38
  282. package/tsconfig.json +0 -27
@@ -0,0 +1,993 @@
1
+ import {
2
+ Separator
3
+ } from "./chunk-TCYK7DM7.mjs";
4
+ import {
5
+ useSharedHistoryContext
6
+ } from "./chunk-4EXYCTGJ.mjs";
7
+ import {
8
+ $isImageNode
9
+ } from "./chunk-N3WN46VL.mjs";
10
+ import {
11
+ Skeleton
12
+ } from "./chunk-QEIFVK5M.mjs";
13
+ import {
14
+ Input
15
+ } from "./chunk-POGRR73N.mjs";
16
+ import {
17
+ Button
18
+ } from "./chunk-BIU7WTLX.mjs";
19
+ import {
20
+ cn
21
+ } from "./chunk-YHPNOWFH.mjs";
22
+ import {
23
+ React,
24
+ init_react_shim
25
+ } from "./chunk-77KXU36M.mjs";
26
+
27
+ // src/components/ui/image/index.tsx
28
+ init_react_shim();
29
+ import { LinkNode } from "@lexical/link";
30
+ import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
31
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
32
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
33
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
34
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
35
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
36
+ import { useLexicalEditable } from "@lexical/react/useLexicalEditable";
37
+ import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection";
38
+ import { mergeRegister } from "@lexical/utils";
39
+ import {
40
+ $getNodeByKey as $getNodeByKey2,
41
+ $getSelection,
42
+ $isNodeSelection,
43
+ $isRangeSelection,
44
+ $setSelection,
45
+ CLICK_COMMAND,
46
+ COMMAND_PRIORITY_LOW,
47
+ createCommand,
48
+ DRAGSTART_COMMAND,
49
+ KEY_BACKSPACE_COMMAND,
50
+ KEY_DELETE_COMMAND,
51
+ KEY_ENTER_COMMAND,
52
+ KEY_ESCAPE_COMMAND,
53
+ LineBreakNode,
54
+ ParagraphNode,
55
+ RootNode,
56
+ SELECTION_CHANGE_COMMAND,
57
+ TextNode
58
+ } from "lexical";
59
+ import * as React5 from "react";
60
+ import { Suspense, useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
61
+
62
+ // src/components/ui/image/error-image.tsx
63
+ init_react_shim();
64
+ import React2 from "react";
65
+ function ErrorImage() {
66
+ return /* @__PURE__ */ React2.createElement(
67
+ "img",
68
+ {
69
+ src: "https://cdn.mos.cms.futurecdn.net/Wh46bS2Gw8vUC6iQh2wEd6-1020-80.png",
70
+ style: {
71
+ height: 300,
72
+ width: 300
73
+ },
74
+ draggable: "false"
75
+ }
76
+ );
77
+ }
78
+
79
+ // src/components/ui/image/index.tsx
80
+ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
81
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
82
+
83
+ // src/components/ui/image/image-resizer.tsx
84
+ init_react_shim();
85
+ import * as React3 from "react";
86
+ import { useRef } from "react";
87
+ import { calculateZoomLevel } from "@lexical/utils";
88
+ function clamp(value, min, max) {
89
+ return Math.min(Math.max(value, min), max);
90
+ }
91
+ var Direction = {
92
+ east: 1 << 0,
93
+ north: 1 << 3,
94
+ south: 1 << 1,
95
+ west: 1 << 2
96
+ };
97
+ function ImageResizer({
98
+ onResizeStart,
99
+ onResizeEnd,
100
+ MediaRef,
101
+ editor
102
+ }) {
103
+ var _a, _b;
104
+ const controlWrapperRef = useRef(null);
105
+ const userSelect = useRef({
106
+ priority: "",
107
+ value: "default"
108
+ });
109
+ const positioningRef = useRef({
110
+ currentHeight: 0,
111
+ currentWidth: 0,
112
+ direction: 0,
113
+ isResizing: false,
114
+ ratio: 0,
115
+ startHeight: 0,
116
+ startWidth: 0,
117
+ startX: 0,
118
+ startY: 0
119
+ });
120
+ const editorRootElement = editor.getRootElement();
121
+ const maxWidthContainer = 950;
122
+ const maxHeightContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;
123
+ const minWidth = 100;
124
+ const minHeight = 100;
125
+ const setStartCursor = (direction) => {
126
+ const ew = direction === Direction.east || direction === Direction.west;
127
+ const ns = direction === Direction.north || direction === Direction.south;
128
+ const nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
129
+ const cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
130
+ if (editorRootElement !== null) {
131
+ editorRootElement.style.setProperty(
132
+ "cursor",
133
+ `${cursorDir}-resize`,
134
+ "important"
135
+ );
136
+ }
137
+ if (document.body !== null) {
138
+ document.body.style.setProperty(
139
+ "cursor",
140
+ `${cursorDir}-resize`,
141
+ "important"
142
+ );
143
+ userSelect.current.value = document.body.style.getPropertyValue(
144
+ "-webkit-user-select"
145
+ );
146
+ userSelect.current.priority = document.body.style.getPropertyPriority(
147
+ "-webkit-user-select"
148
+ );
149
+ document.body.style.setProperty(
150
+ "-webkit-user-select",
151
+ `none`,
152
+ "important"
153
+ );
154
+ }
155
+ };
156
+ const setEndCursor = () => {
157
+ if (editorRootElement !== null) {
158
+ editorRootElement.style.setProperty("cursor", "text");
159
+ }
160
+ if (document.body !== null) {
161
+ document.body.style.setProperty("cursor", "default");
162
+ document.body.style.setProperty(
163
+ "-webkit-user-select",
164
+ userSelect.current.value,
165
+ userSelect.current.priority
166
+ );
167
+ }
168
+ };
169
+ const handlePointerDown = (event, direction) => {
170
+ if (!editor.isEditable()) {
171
+ return;
172
+ }
173
+ const image = MediaRef.current;
174
+ const controlWrapper = controlWrapperRef.current;
175
+ if (image !== null && controlWrapper !== null) {
176
+ event.preventDefault();
177
+ const { width, height } = image.getBoundingClientRect();
178
+ const zoom = calculateZoomLevel(image);
179
+ const positioning = positioningRef.current;
180
+ positioning.startWidth = width;
181
+ positioning.startHeight = height;
182
+ positioning.ratio = width / height;
183
+ positioning.currentWidth = width;
184
+ positioning.currentHeight = height;
185
+ positioning.startX = event.clientX / zoom;
186
+ positioning.startY = event.clientY / zoom;
187
+ positioning.isResizing = true;
188
+ positioning.direction = direction;
189
+ setStartCursor(direction);
190
+ onResizeStart();
191
+ controlWrapper.classList.add("resizing");
192
+ image.classList.add("resizing");
193
+ document.addEventListener("pointermove", handlePointerMove);
194
+ document.addEventListener("pointerup", handlePointerUp);
195
+ }
196
+ };
197
+ const handlePointerMove = (event) => {
198
+ const image = MediaRef.current;
199
+ const positioning = positioningRef.current;
200
+ const isHorizontal = positioning.direction & (Direction.east | Direction.west);
201
+ const isVertical = positioning.direction & (Direction.south | Direction.north);
202
+ if (image !== null && positioning.isResizing) {
203
+ const zoom = calculateZoomLevel(image);
204
+ if (isHorizontal && isVertical) {
205
+ let diff = Math.floor(positioning.startX - event.clientX / zoom);
206
+ diff = positioning.direction & Direction.east ? -diff : diff;
207
+ const width = clamp(
208
+ positioning.startWidth + diff,
209
+ minWidth,
210
+ maxWidthContainer
211
+ );
212
+ const height = width / positioning.ratio;
213
+ image.style.width = `${width}px`;
214
+ image.style.height = `${height}px`;
215
+ positioning.currentHeight = height;
216
+ positioning.currentWidth = width;
217
+ } else if (isVertical) {
218
+ let diff = Math.floor(positioning.startY - event.clientY / zoom);
219
+ diff = positioning.direction & Direction.south ? -diff : diff;
220
+ const height = clamp(
221
+ positioning.startHeight + diff,
222
+ minHeight,
223
+ maxHeightContainer
224
+ );
225
+ image.style.height = `${height}px`;
226
+ positioning.currentHeight = height;
227
+ } else {
228
+ let diff = Math.floor(positioning.startX - event.clientX / zoom);
229
+ diff = positioning.direction & Direction.east ? -diff : diff;
230
+ const width = clamp(
231
+ positioning.startWidth + diff,
232
+ minWidth,
233
+ maxWidthContainer
234
+ );
235
+ image.style.width = `${width}px`;
236
+ positioning.currentWidth = width;
237
+ }
238
+ }
239
+ };
240
+ const handlePointerUp = () => {
241
+ const image = MediaRef.current;
242
+ const positioning = positioningRef.current;
243
+ const controlWrapper = controlWrapperRef.current;
244
+ if (image !== null && controlWrapper !== null && positioning.isResizing) {
245
+ const width = positioning.currentWidth;
246
+ const height = positioning.currentHeight;
247
+ positioning.startWidth = 0;
248
+ positioning.startHeight = 0;
249
+ positioning.ratio = 0;
250
+ positioning.startX = 0;
251
+ positioning.startY = 0;
252
+ positioning.currentWidth = 0;
253
+ positioning.currentHeight = 0;
254
+ positioning.isResizing = false;
255
+ controlWrapper.classList.remove("resizing");
256
+ image.classList.remove("resizing");
257
+ setEndCursor();
258
+ onResizeEnd(width, height);
259
+ document.removeEventListener("pointermove", handlePointerMove);
260
+ document.removeEventListener("pointerup", handlePointerUp);
261
+ }
262
+ };
263
+ return /* @__PURE__ */ React3.createElement(
264
+ "div",
265
+ {
266
+ ref: controlWrapperRef,
267
+ className: "absolute inset-0 z-10",
268
+ style: {
269
+ width: (_a = MediaRef.current) == null ? void 0 : _a.style.width,
270
+ height: (_b = MediaRef.current) == null ? void 0 : _b.style.height
271
+ }
272
+ },
273
+ /* @__PURE__ */ React3.createElement(
274
+ "div",
275
+ {
276
+ className: "absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-n-resize",
277
+ onPointerDown: (event) => {
278
+ handlePointerDown(event, Direction.north);
279
+ }
280
+ }
281
+ ),
282
+ /* @__PURE__ */ React3.createElement(
283
+ "div",
284
+ {
285
+ className: "absolute top-0 right-0 transform -translate-y-1/2 translate-x-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-ne-resize",
286
+ onPointerDown: (event) => {
287
+ handlePointerDown(event, Direction.north | Direction.east);
288
+ }
289
+ }
290
+ ),
291
+ /* @__PURE__ */ React3.createElement(
292
+ "div",
293
+ {
294
+ className: "absolute top-1/2 right-0 transform translate-x-1/2 -translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-e-resize",
295
+ onPointerDown: (event) => {
296
+ handlePointerDown(event, Direction.east);
297
+ }
298
+ }
299
+ ),
300
+ /* @__PURE__ */ React3.createElement(
301
+ "div",
302
+ {
303
+ className: "absolute bottom-0 right-0 transform translate-x-1/2 translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-se-resize",
304
+ onPointerDown: (event) => {
305
+ handlePointerDown(event, Direction.south | Direction.east);
306
+ }
307
+ }
308
+ ),
309
+ /* @__PURE__ */ React3.createElement(
310
+ "div",
311
+ {
312
+ className: "absolute bottom-0 left-1/2 transform -translate-x-1/2 translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-s-resize",
313
+ onPointerDown: (event) => {
314
+ handlePointerDown(event, Direction.south);
315
+ }
316
+ }
317
+ ),
318
+ /* @__PURE__ */ React3.createElement(
319
+ "div",
320
+ {
321
+ className: "absolute bottom-0 left-0 transform -translate-x-1/2 translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-sw-resize",
322
+ onPointerDown: (event) => {
323
+ handlePointerDown(event, Direction.south | Direction.west);
324
+ }
325
+ }
326
+ ),
327
+ /* @__PURE__ */ React3.createElement(
328
+ "div",
329
+ {
330
+ className: "absolute top-1/2 left-0 transform -translate-x-1/2 -translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-w-resize",
331
+ onPointerDown: (event) => {
332
+ handlePointerDown(event, Direction.west);
333
+ }
334
+ }
335
+ ),
336
+ /* @__PURE__ */ React3.createElement(
337
+ "div",
338
+ {
339
+ className: "absolute top-0 left-0 transform -translate-x-1/2 -translate-y-1/2 w-2 h-2 bg-blue-500 rounded-full cursor-nw-resize",
340
+ onPointerDown: (event) => {
341
+ handlePointerDown(event, Direction.north | Direction.west);
342
+ }
343
+ }
344
+ )
345
+ );
346
+ }
347
+
348
+ // src/components/ui/image/lazy-image.tsx
349
+ init_react_shim();
350
+ import { useEffect, useState } from "react";
351
+ var imageCache = /* @__PURE__ */ new Set();
352
+ function LazyImage({
353
+ altText,
354
+ style,
355
+ imageRef,
356
+ src,
357
+ onError
358
+ }) {
359
+ const [isLoading, setIsLoading] = useState(true);
360
+ useEffect(() => {
361
+ if (imageCache.has(src)) {
362
+ setIsLoading(false);
363
+ return;
364
+ }
365
+ const img = new Image();
366
+ img.src = src;
367
+ img.onload = () => {
368
+ imageCache.add(src);
369
+ setIsLoading(false);
370
+ };
371
+ img.onerror = () => {
372
+ imageCache.add(src);
373
+ setIsLoading(false);
374
+ onError();
375
+ };
376
+ return () => {
377
+ img.onload = null;
378
+ img.onerror = null;
379
+ };
380
+ }, [src, onError]);
381
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, isLoading && /* @__PURE__ */ React.createElement(
382
+ Skeleton,
383
+ {
384
+ style
385
+ }
386
+ ), /* @__PURE__ */ React.createElement(
387
+ "img",
388
+ {
389
+ className: cn("max-w-full transition-opacity border-amber-500 border-2", isLoading ? "opacity-0" : "opacity-100"),
390
+ src,
391
+ alt: altText,
392
+ ref: imageRef,
393
+ style,
394
+ onError,
395
+ draggable: "false"
396
+ }
397
+ ));
398
+ }
399
+
400
+ // src/components/ui/image/lazy-video.tsx
401
+ init_react_shim();
402
+ import { useEffect as useEffect2, useState as useState2 } from "react";
403
+ var videoCache = /* @__PURE__ */ new Set();
404
+ function LazyVideo({
405
+ videoRef,
406
+ src,
407
+ style,
408
+ onError,
409
+ rounded,
410
+ controls = true
411
+ }) {
412
+ const [isLoading, setIsLoading] = useState2(true);
413
+ useEffect2(() => {
414
+ if (videoCache.has(src)) {
415
+ setIsLoading(false);
416
+ return;
417
+ }
418
+ const video = document.createElement("video");
419
+ video.src = src;
420
+ video.onloadeddata = () => {
421
+ videoCache.add(src);
422
+ setIsLoading(false);
423
+ };
424
+ video.onerror = () => {
425
+ videoCache.add(src);
426
+ setIsLoading(false);
427
+ onError();
428
+ };
429
+ return () => {
430
+ video.onloadeddata = null;
431
+ video.onerror = null;
432
+ };
433
+ }, [src, onError]);
434
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, isLoading && /* @__PURE__ */ React.createElement(
435
+ Skeleton,
436
+ {
437
+ style
438
+ }
439
+ ), /* @__PURE__ */ React.createElement(
440
+ "video",
441
+ {
442
+ className: cn(" transition-opacity", isLoading ? "opacity-0" : "opacity-100"),
443
+ src,
444
+ ref: videoRef,
445
+ style,
446
+ onError,
447
+ controls,
448
+ draggable: "false"
449
+ }
450
+ ));
451
+ }
452
+
453
+ // src/components/ui/image/image-toolbar.tsx
454
+ init_react_shim();
455
+ import { $getNodeByKey } from "lexical";
456
+ import React4, { useCallback, useEffect as useEffect3, useState as useState3 } from "react";
457
+ import {
458
+ AlignCenterVertical,
459
+ CaptionsIcon,
460
+ Fullscreen,
461
+ PanelLeftClose,
462
+ Radius
463
+ } from "lucide-react";
464
+ function ImageToolBar({
465
+ editor,
466
+ nodeKey,
467
+ height,
468
+ width
469
+ }) {
470
+ const [showResizeInput, setShowResizeInput] = useState3(false);
471
+ const [widthInput, setWidthInput] = useState3(String(width));
472
+ const [heightInput, setHeightInput] = useState3(String(height));
473
+ const [showInput, setShowInput] = useState3(false);
474
+ const toggleResizeInput = useCallback(() => {
475
+ setShowResizeInput((prev) => !prev);
476
+ }, []);
477
+ const setShowCaption = () => {
478
+ editor.update(() => {
479
+ const node = $getNodeByKey(nodeKey);
480
+ if ($isImageNode(node)) {
481
+ const currentState = node.__showCaption;
482
+ node.setShowCaption(!currentState);
483
+ }
484
+ });
485
+ };
486
+ const updateWidthAndHeight = useCallback(() => {
487
+ const newWidth = Number(widthInput);
488
+ const newHeight = Number(heightInput);
489
+ console.log("update", newWidth, newHeight);
490
+ if (isNaN(newWidth) || isNaN(newHeight)) return;
491
+ if (newWidth > 990 || newHeight > 1800) return;
492
+ if (newWidth < 140 || newHeight < 90) return;
493
+ editor.update(() => {
494
+ const node = $getNodeByKey(nodeKey);
495
+ if ($isImageNode(node)) {
496
+ node.setWidthAndHeight(newWidth, newHeight);
497
+ }
498
+ });
499
+ }, [editor, nodeKey, widthInput, heightInput]);
500
+ useEffect3(() => {
501
+ const debounceTimeout = setTimeout(() => {
502
+ updateWidthAndHeight();
503
+ }, 500);
504
+ return () => clearTimeout(debounceTimeout);
505
+ }, [widthInput, heightInput, updateWidthAndHeight]);
506
+ const handleKeyDown = useCallback(
507
+ (e) => {
508
+ if (e.key === "Enter") {
509
+ updateWidthAndHeight();
510
+ }
511
+ },
512
+ [updateWidthAndHeight]
513
+ );
514
+ const handleWidthChange = useCallback(
515
+ (e) => {
516
+ setWidthInput(e.target.value);
517
+ },
518
+ []
519
+ );
520
+ const handleHeightChange = useCallback(
521
+ (e) => {
522
+ setHeightInput(e.target.value);
523
+ },
524
+ []
525
+ );
526
+ useEffect3(() => {
527
+ setWidthInput(String(width));
528
+ setHeightInput(String(height));
529
+ }, [height, width]);
530
+ const ChangeSideToLeft = useCallback(() => {
531
+ editor.update(() => {
532
+ const node = $getNodeByKey(nodeKey);
533
+ if ($isImageNode(node)) {
534
+ node.setAlignment("start");
535
+ }
536
+ });
537
+ }, [editor, nodeKey]);
538
+ const ChangeSideToCenter = useCallback(() => {
539
+ editor.update(() => {
540
+ const node = $getNodeByKey(nodeKey);
541
+ if ($isImageNode(node)) {
542
+ node.setAlignment("center");
543
+ }
544
+ });
545
+ }, [editor, nodeKey]);
546
+ const ChangeSideToRight = useCallback(() => {
547
+ editor.update(() => {
548
+ const node = $getNodeByKey(nodeKey);
549
+ if ($isImageNode(node)) {
550
+ node.setAlignment("end");
551
+ }
552
+ });
553
+ }, [editor, nodeKey]);
554
+ const ChangeRounded = useCallback(
555
+ (event) => {
556
+ editor.update(() => {
557
+ const node = $getNodeByKey(nodeKey);
558
+ if ($isImageNode(node)) {
559
+ const roundedValue = parseInt(event.target.value);
560
+ node.setRounded(roundedValue);
561
+ }
562
+ });
563
+ },
564
+ [editor, nodeKey]
565
+ );
566
+ return /* @__PURE__ */ React4.createElement("div", { className: "flex flex-row items-center z-50 gap-x-2 absolute top-1 left-1 group-hover:opacity-100 duration-500 opacity-0 transition-all" }, /* @__PURE__ */ React4.createElement("div", { className: "p-1 rounded-sm bg-background/40 flex flex-row items-center justify-between" }, /* @__PURE__ */ React4.createElement("div", { className: "flex flex-row items-center" }, /* @__PURE__ */ React4.createElement(
567
+ Button,
568
+ {
569
+ onClick: toggleResizeInput,
570
+ tip: "Resize image",
571
+ variant: "ghost",
572
+ size: "sm",
573
+ className: "p-1 w-6 h-6 "
574
+ },
575
+ /* @__PURE__ */ React4.createElement(Fullscreen, { className: "size-2" })
576
+ ), /* @__PURE__ */ React4.createElement(
577
+ "div",
578
+ {
579
+ className: cn(
580
+ "transition-all duration-500 ease-in-out",
581
+ showResizeInput ? "w-[30px] mx-1" : "w-0"
582
+ )
583
+ },
584
+ /* @__PURE__ */ React4.createElement(
585
+ Input,
586
+ {
587
+ type: "number",
588
+ placeholder: "0px",
589
+ max: 990,
590
+ min: 120,
591
+ value: widthInput,
592
+ onChange: handleWidthChange,
593
+ onKeyDown: handleKeyDown,
594
+ className: cn(
595
+ "h-5 px-0.5 w-full rounded-sm text-xs outline-none transition-opacity duration-300 ease-in-out",
596
+ showResizeInput ? "opacity-100" : "opacity-0"
597
+ )
598
+ }
599
+ )
600
+ ), /* @__PURE__ */ React4.createElement(
601
+ "div",
602
+ {
603
+ className: cn(
604
+ "transition-all duration-500 ease-in-out",
605
+ showResizeInput ? "w-[30px]" : "w-0"
606
+ )
607
+ },
608
+ /* @__PURE__ */ React4.createElement(
609
+ Input,
610
+ {
611
+ type: "number",
612
+ placeholder: "0px",
613
+ max: 1800,
614
+ min: 120,
615
+ value: heightInput,
616
+ onChange: handleHeightChange,
617
+ onKeyDown: handleKeyDown,
618
+ className: cn(
619
+ "h-5 px-0.5 w-full text-xs rounded-sm outline-none transition-opacity duration-300 ease-in-out",
620
+ showResizeInput ? "opacity-100" : "opacity-0"
621
+ )
622
+ }
623
+ )
624
+ )), /* @__PURE__ */ React4.createElement(Separator, { orientation: "vertical", className: "mx-1 h-5" }), /* @__PURE__ */ React4.createElement("div", { className: "flex flex-row items-center gap-x-1" }, /* @__PURE__ */ React4.createElement(
625
+ Button,
626
+ {
627
+ onClick: ChangeSideToLeft,
628
+ variant: "ghost",
629
+ size: "sm",
630
+ tip: "move left",
631
+ className: "w-6 h-6 p-1 "
632
+ },
633
+ /* @__PURE__ */ React4.createElement(PanelLeftClose, null)
634
+ ), /* @__PURE__ */ React4.createElement(
635
+ Button,
636
+ {
637
+ size: "sm",
638
+ variant: "ghost",
639
+ onClick: ChangeSideToCenter,
640
+ className: " mx-1 w-6 h-6 p-1 opacity-[0.70] hover:opacity-100 transition-opacity",
641
+ tip: "move center"
642
+ },
643
+ /* @__PURE__ */ React4.createElement(AlignCenterVertical, null)
644
+ ), /* @__PURE__ */ React4.createElement(
645
+ Button,
646
+ {
647
+ size: "sm",
648
+ variant: "ghost",
649
+ onClick: ChangeSideToRight,
650
+ className: " w-6 h-6 p-1 opacity-[0.70] hover:opacity-100 transition-opacity",
651
+ tip: "move right"
652
+ },
653
+ /* @__PURE__ */ React4.createElement(PanelLeftClose, null)
654
+ )), /* @__PURE__ */ React4.createElement(Separator, { orientation: "vertical", className: "mx-1 h-5" }), /* @__PURE__ */ React4.createElement(
655
+ Button,
656
+ {
657
+ size: "sm",
658
+ variant: "ghost",
659
+ onClick: () => {
660
+ setShowInput(!showInput);
661
+ },
662
+ className: " w-6 h-6 p-1 opacity-[0.70] hover:opacity-100 transition-opacity",
663
+ tip: "border radius"
664
+ },
665
+ /* @__PURE__ */ React4.createElement(Radius, null)
666
+ ), /* @__PURE__ */ React4.createElement(
667
+ "div",
668
+ {
669
+ className: cn(
670
+ "overflow-hidden transition-all duration-500 ease-in-out ",
671
+ showInput ? "w-[60px]" : "w-0"
672
+ )
673
+ },
674
+ /* @__PURE__ */ React4.createElement(
675
+ Input,
676
+ {
677
+ type: "range",
678
+ min: "0",
679
+ max: "120",
680
+ defaultValue: "0",
681
+ onChange: ChangeRounded,
682
+ className: cn(
683
+ "h-5 px-1 py-0 transition-opacity duration-300 ease-in-out",
684
+ showInput ? "opacity-100" : "opacity-0"
685
+ )
686
+ }
687
+ )
688
+ ), /* @__PURE__ */ React4.createElement(Separator, { orientation: "vertical", className: "mx-1 h-5" }), /* @__PURE__ */ React4.createElement(
689
+ Button,
690
+ {
691
+ size: "sm",
692
+ variant: "ghost",
693
+ onClick: setShowCaption,
694
+ className: " w-6 h-6 p-1 opacity-[0.70] hover:opacity-100 transition-opacity",
695
+ tip: "add caption"
696
+ },
697
+ /* @__PURE__ */ React4.createElement(CaptionsIcon, null)
698
+ )));
699
+ }
700
+
701
+ // src/components/ui/image/index.tsx
702
+ var RIGHT_CLICK_IMAGE_COMMAND = createCommand("RIGHT_CLICK_IMAGE_COMMAND");
703
+ function ImageComponent({
704
+ src,
705
+ altText,
706
+ nodeKey,
707
+ width,
708
+ height,
709
+ maxWidth,
710
+ resizable,
711
+ showCaption,
712
+ caption,
713
+ rounded
714
+ }) {
715
+ const MediaRef = useRef2(null);
716
+ const buttonRef = useRef2(null);
717
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
718
+ const [isResizing, setIsResizing] = useState4(false);
719
+ const [editor] = useLexicalComposerContext();
720
+ const [selection, setSelection] = useState4(null);
721
+ const activeEditorRef = useRef2(null);
722
+ const [isLoadError, setIsLoadError] = useState4(false);
723
+ const isEditable = useLexicalEditable();
724
+ const [MediaType, setMediaType] = useState4("IMAGE");
725
+ const $onDelete = useCallback2(
726
+ (payload) => {
727
+ const deleteSelection = $getSelection();
728
+ if (isSelected && $isNodeSelection(deleteSelection)) {
729
+ const event = payload;
730
+ event.preventDefault();
731
+ deleteSelection.getNodes().forEach((node) => {
732
+ if ($isImageNode(node)) {
733
+ node.remove();
734
+ }
735
+ });
736
+ }
737
+ return false;
738
+ },
739
+ [isSelected]
740
+ );
741
+ const $onEnter = useCallback2(
742
+ (event) => {
743
+ const latestSelection = $getSelection();
744
+ const buttonElem = buttonRef.current;
745
+ if (isSelected && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
746
+ if (showCaption) {
747
+ $setSelection(null);
748
+ event.preventDefault();
749
+ caption.focus();
750
+ return true;
751
+ } else if (buttonElem !== null && buttonElem !== document.activeElement) {
752
+ event.preventDefault();
753
+ buttonElem.focus();
754
+ return true;
755
+ }
756
+ }
757
+ return false;
758
+ },
759
+ [caption, isSelected, showCaption]
760
+ );
761
+ const $onEscape = useCallback2(
762
+ (event) => {
763
+ if (activeEditorRef.current === caption || buttonRef.current === event.target) {
764
+ $setSelection(null);
765
+ editor.update(() => {
766
+ setSelected(true);
767
+ const parentRootElement = editor.getRootElement();
768
+ if (parentRootElement !== null) {
769
+ parentRootElement.focus();
770
+ }
771
+ });
772
+ return true;
773
+ }
774
+ return false;
775
+ },
776
+ [caption, editor, setSelected]
777
+ );
778
+ const onClick = useCallback2(
779
+ (payload) => {
780
+ const event = payload;
781
+ if (isResizing) {
782
+ return true;
783
+ }
784
+ if (event.target === MediaRef.current) {
785
+ if (event.shiftKey) {
786
+ setSelected(!isSelected);
787
+ } else {
788
+ clearSelection();
789
+ setSelected(true);
790
+ }
791
+ return true;
792
+ }
793
+ return false;
794
+ },
795
+ [isResizing, isSelected, setSelected, clearSelection]
796
+ );
797
+ const onRightClick = useCallback2(
798
+ (event) => {
799
+ editor.getEditorState().read(() => {
800
+ const latestSelection = $getSelection();
801
+ const domElement = event.target;
802
+ if ((domElement.tagName === "IMG" || domElement.tagName === "VIDEO") && $isRangeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
803
+ editor.dispatchCommand(
804
+ RIGHT_CLICK_IMAGE_COMMAND,
805
+ event
806
+ );
807
+ }
808
+ });
809
+ },
810
+ [editor]
811
+ );
812
+ useEffect4(() => {
813
+ let isMounted = true;
814
+ const rootElement = editor.getRootElement();
815
+ const unregister = mergeRegister(
816
+ editor.registerUpdateListener(({ editorState }) => {
817
+ if (isMounted) {
818
+ setSelection(editorState.read(() => $getSelection()));
819
+ }
820
+ }),
821
+ editor.registerCommand(
822
+ SELECTION_CHANGE_COMMAND,
823
+ (_, activeEditor) => {
824
+ activeEditorRef.current = activeEditor;
825
+ return false;
826
+ },
827
+ COMMAND_PRIORITY_LOW
828
+ ),
829
+ editor.registerCommand(
830
+ CLICK_COMMAND,
831
+ onClick,
832
+ COMMAND_PRIORITY_LOW
833
+ ),
834
+ editor.registerCommand(
835
+ RIGHT_CLICK_IMAGE_COMMAND,
836
+ onClick,
837
+ COMMAND_PRIORITY_LOW
838
+ ),
839
+ editor.registerCommand(
840
+ DRAGSTART_COMMAND,
841
+ (event) => {
842
+ if (event.target === MediaRef.current) {
843
+ event.preventDefault();
844
+ return true;
845
+ }
846
+ return false;
847
+ },
848
+ COMMAND_PRIORITY_LOW
849
+ ),
850
+ editor.registerCommand(
851
+ KEY_DELETE_COMMAND,
852
+ $onDelete,
853
+ COMMAND_PRIORITY_LOW
854
+ ),
855
+ editor.registerCommand(
856
+ KEY_BACKSPACE_COMMAND,
857
+ $onDelete,
858
+ COMMAND_PRIORITY_LOW
859
+ ),
860
+ editor.registerCommand(KEY_ENTER_COMMAND, $onEnter, COMMAND_PRIORITY_LOW),
861
+ editor.registerCommand(
862
+ KEY_ESCAPE_COMMAND,
863
+ $onEscape,
864
+ COMMAND_PRIORITY_LOW
865
+ )
866
+ );
867
+ rootElement == null ? void 0 : rootElement.addEventListener("contextmenu", onRightClick);
868
+ return () => {
869
+ isMounted = false;
870
+ unregister();
871
+ rootElement == null ? void 0 : rootElement.removeEventListener("contextmenu", onRightClick);
872
+ };
873
+ }, [
874
+ clearSelection,
875
+ editor,
876
+ isResizing,
877
+ isSelected,
878
+ nodeKey,
879
+ $onDelete,
880
+ $onEnter,
881
+ $onEscape,
882
+ onClick,
883
+ onRightClick,
884
+ setSelected
885
+ ]);
886
+ useEffect4(() => {
887
+ if (src.endsWith(".mp4")) {
888
+ setMediaType("VIDEO");
889
+ } else if (src.endsWith(".jpg") || src.endsWith(".jpeg") || src.endsWith(".png")) {
890
+ setMediaType("IMAGE");
891
+ }
892
+ }, [src]);
893
+ const onResizeEnd = (nextWidth, nextHeight) => {
894
+ setTimeout(() => {
895
+ setIsResizing(false);
896
+ }, 200);
897
+ editor.update(() => {
898
+ const node = $getNodeByKey2(nodeKey);
899
+ if ($isImageNode(node)) {
900
+ node.setWidthAndHeight(nextWidth, nextHeight);
901
+ }
902
+ });
903
+ };
904
+ const onResizeStart = () => {
905
+ setIsResizing(true);
906
+ };
907
+ const { historyState } = useSharedHistoryContext();
908
+ const draggable = isSelected && $isNodeSelection(selection) && !isResizing;
909
+ const isFocused = (isSelected || isResizing) && isEditable;
910
+ return /* @__PURE__ */ React5.createElement(Suspense, { fallback: null }, /* @__PURE__ */ React5.createElement("div", { className: "relative inline-block group" }, /* @__PURE__ */ React5.createElement("div", { draggable }, isLoadError ? /* @__PURE__ */ React5.createElement(ErrorImage, null) : /* @__PURE__ */ React5.createElement(React5.Fragment, null, MediaType === "IMAGE" ? /* @__PURE__ */ React5.createElement(
911
+ LazyImage,
912
+ {
913
+ style: {
914
+ width: width === "inherit" ? "400px" : `${width}px`,
915
+ height: height === "inherit" ? "400px" : `${height}px`,
916
+ borderRadius: `${rounded}px`
917
+ },
918
+ src,
919
+ altText,
920
+ imageRef: MediaRef,
921
+ onError: () => setIsLoadError(true)
922
+ }
923
+ ) : /* @__PURE__ */ React5.createElement(
924
+ LazyVideo,
925
+ {
926
+ src,
927
+ style: {
928
+ width: width === "inherit" ? "800px" : `${width}px`,
929
+ height: height === "inherit" ? "450px" : `${height}px`,
930
+ borderRadius: `${rounded}px`
931
+ },
932
+ videoRef: MediaRef,
933
+ onError: () => setIsLoadError(true),
934
+ rounded,
935
+ controls: true
936
+ }
937
+ ))), showCaption && /* @__PURE__ */ React5.createElement("div", null, /* @__PURE__ */ React5.createElement(
938
+ LexicalNestedComposer,
939
+ {
940
+ initialEditor: caption,
941
+ initialNodes: [
942
+ RootNode,
943
+ TextNode,
944
+ LineBreakNode,
945
+ ParagraphNode,
946
+ LinkNode
947
+ ]
948
+ },
949
+ /* @__PURE__ */ React5.createElement(AutoFocusPlugin, null),
950
+ /* @__PURE__ */ React5.createElement(LinkPlugin, null),
951
+ /* @__PURE__ */ React5.createElement(HistoryPlugin, { externalHistoryState: historyState }),
952
+ /* @__PURE__ */ React5.createElement(
953
+ RichTextPlugin,
954
+ {
955
+ contentEditable: /* @__PURE__ */ React5.createElement(
956
+ ContentEditable,
957
+ {
958
+ "aria-placeholder": "Enter a caption...",
959
+ placeholder: () => /* @__PURE__ */ React5.createElement(
960
+ "span",
961
+ {
962
+ className: "\r\n color-[#999] text-xs overflow-hidden absolute text-ellipsis\r\n select-none text-nowrap inline-block pointer-events-none\r\n transform -translate-x-1/2 -translate-y-1/2 bottom-[-8px]\r\n "
963
+ },
964
+ "Enter a caption..."
965
+ ),
966
+ className: "text-center relative text-xs text-muted-foreground outline-none"
967
+ }
968
+ ),
969
+ ErrorBoundary: LexicalErrorBoundary
970
+ }
971
+ )
972
+ )), isEditable && !isResizing && /* @__PURE__ */ React5.createElement(
973
+ ImageToolBar,
974
+ {
975
+ width,
976
+ height,
977
+ editor,
978
+ nodeKey
979
+ }
980
+ ), resizable && $isNodeSelection(selection) && isFocused && /* @__PURE__ */ React5.createElement(
981
+ ImageResizer,
982
+ {
983
+ editor,
984
+ MediaRef,
985
+ onResizeStart,
986
+ onResizeEnd
987
+ }
988
+ )));
989
+ }
990
+ export {
991
+ RIGHT_CLICK_IMAGE_COMMAND,
992
+ ImageComponent as default
993
+ };