reactjs-tiptap-editor-pro 0.2.29 → 0.2.31

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 (333) hide show
  1. package/package.json +5 -58
  2. package/src/components/ActionButton.tsx +103 -0
  3. package/src/components/ActionMenuButton.tsx +76 -0
  4. package/src/components/BubbleMenu.tsx +93 -0
  5. package/src/components/CharactorCount.tsx +50 -0
  6. package/src/components/ColorPicker.tsx +272 -0
  7. package/src/components/RichTextEditor.tsx +212 -0
  8. package/src/components/SizeSetter/SizeSetter.tsx +102 -0
  9. package/src/components/Toolbar.tsx +108 -0
  10. package/src/components/icons/Activity.tsx +19 -0
  11. package/src/components/icons/Animas.tsx +24 -0
  12. package/src/components/icons/AspectRatio.tsx +13 -0
  13. package/src/components/icons/Blockquote.tsx +17 -0
  14. package/src/components/icons/ColumnAddLeft.tsx +7 -0
  15. package/src/components/icons/ColumnAddRight.tsx +7 -0
  16. package/src/components/icons/DeleteColumn.tsx +26 -0
  17. package/src/components/icons/DeleteRow.tsx +26 -0
  18. package/src/components/icons/Direction.tsx +7 -0
  19. package/src/components/icons/Excalidraw.tsx +7 -0
  20. package/src/components/icons/ExportPdf.tsx +8 -0
  21. package/src/components/icons/ExportWord.tsx +24 -0
  22. package/src/components/icons/FileWordOutline.tsx +13 -0
  23. package/src/components/icons/Flag.tsx +19 -0
  24. package/src/components/icons/Food.tsx +20 -0
  25. package/src/components/icons/GIfIcon.tsx +10 -0
  26. package/src/components/icons/Icon.tsx +30 -0
  27. package/src/components/icons/ImportWord.tsx +23 -0
  28. package/src/components/icons/LeftToRight.tsx +7 -0
  29. package/src/components/icons/LineHeight.tsx +13 -0
  30. package/src/components/icons/MenuDown.tsx +24 -0
  31. package/src/components/icons/Mermaid.tsx +13 -0
  32. package/src/components/icons/NoFill.tsx +7 -0
  33. package/src/components/icons/Object.tsx +24 -0
  34. package/src/components/icons/RightToLeft.tsx +7 -0
  35. package/src/components/icons/SizeL.tsx +9 -0
  36. package/src/components/icons/SizeM.tsx +13 -0
  37. package/src/components/icons/SizeS.tsx +13 -0
  38. package/src/components/icons/Symbol.tsx +19 -0
  39. package/src/components/icons/Travel.tsx +24 -0
  40. package/src/components/icons/Twitter.tsx +7 -0
  41. package/src/components/icons/icons.ts +212 -0
  42. package/src/components/icons/index.ts +12 -0
  43. package/src/components/index.ts +9 -0
  44. package/src/components/menus/bubble.ts +395 -0
  45. package/src/components/menus/components/BubbleMenuContent.tsx +15 -0
  46. package/src/components/menus/components/BubbleMenuDrawer.tsx +128 -0
  47. package/src/components/menus/components/BubbleMenuExcalidraw.tsx +91 -0
  48. package/src/components/menus/components/BubbleMenuIframe.tsx +143 -0
  49. package/src/components/menus/components/BubbleMenuKatex.tsx +136 -0
  50. package/src/components/menus/components/BubbleMenuLink.tsx +99 -0
  51. package/src/components/menus/components/BubbleMenuMedia.tsx +235 -0
  52. package/src/components/menus/components/BubbleMenuMermaid.tsx +128 -0
  53. package/src/components/menus/components/BubbleMenuText.tsx +102 -0
  54. package/src/components/menus/components/BubbleMenuTwitter.tsx +91 -0
  55. package/src/components/menus/components/ColumnsBubbleMenu.tsx +59 -0
  56. package/src/components/menus/components/ContentMenu.tsx +396 -0
  57. package/src/components/menus/components/TableBubbleMenu.tsx +362 -0
  58. package/src/components/menus/index.ts +7 -0
  59. package/src/components/ui/button.tsx +56 -0
  60. package/src/components/ui/checkbox.tsx +30 -0
  61. package/src/components/ui/dialog.tsx +128 -0
  62. package/src/components/ui/dropdown-menu.tsx +203 -0
  63. package/src/components/ui/emoji-picker.tsx +166 -0
  64. package/src/components/ui/index.ts +14 -0
  65. package/src/components/ui/input.tsx +25 -0
  66. package/src/components/ui/label.tsx +26 -0
  67. package/src/components/ui/popover.tsx +31 -0
  68. package/src/components/ui/select.tsx +162 -0
  69. package/src/components/ui/separator.tsx +31 -0
  70. package/src/components/ui/switch.tsx +29 -0
  71. package/src/components/ui/tabs.tsx +55 -0
  72. package/src/components/ui/textarea.tsx +24 -0
  73. package/src/components/ui/toast.tsx +129 -0
  74. package/src/components/ui/toaster.tsx +44 -0
  75. package/src/components/ui/toggle.tsx +45 -0
  76. package/src/components/ui/tooltip.tsx +30 -0
  77. package/src/components/ui/use-toast.ts +197 -0
  78. package/src/constants/index.ts +223 -0
  79. package/src/constants/resetCSS.ts +139 -0
  80. package/src/extension-bundle.ts +2 -0
  81. package/src/extensions/Attachment/Attachment.ts +144 -0
  82. package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +69 -0
  83. package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +28 -0
  84. package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +155 -0
  85. package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +23 -0
  86. package/src/extensions/Attachment/index.ts +1 -0
  87. package/src/extensions/BaseKit.ts +253 -0
  88. package/src/extensions/Blockquote/Blockquote.ts +31 -0
  89. package/src/extensions/Blockquote/index.ts +1 -0
  90. package/src/extensions/Bold/Bold.ts +26 -0
  91. package/src/extensions/Bold/index.ts +1 -0
  92. package/src/extensions/BulletList/BulletList.ts +28 -0
  93. package/src/extensions/BulletList/index.ts +1 -0
  94. package/src/extensions/Clear/Clear.ts +24 -0
  95. package/src/extensions/Clear/index.ts +1 -0
  96. package/src/extensions/Code/Code.ts +26 -0
  97. package/src/extensions/Code/index.ts +1 -0
  98. package/src/extensions/CodeBlock/CodeBlock.ts +54 -0
  99. package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +66 -0
  100. package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +89 -0
  101. package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +81 -0
  102. package/src/extensions/CodeBlock/highlighter.ts +132 -0
  103. package/src/extensions/CodeBlock/index.ts +1 -0
  104. package/src/extensions/CodeBlock/shiki-plugin.ts +213 -0
  105. package/src/extensions/Color/Color.ts +52 -0
  106. package/src/extensions/Color/components/ColorActionButton.tsx +104 -0
  107. package/src/extensions/Color/index.ts +1 -0
  108. package/src/extensions/Document/Document.ts +8 -0
  109. package/src/extensions/Document/index.ts +1 -0
  110. package/src/extensions/Drawer/Drawer.ts +177 -0
  111. package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +85 -0
  112. package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +598 -0
  113. package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +500 -0
  114. package/src/extensions/Drawer/components/DrawerActiveButton.tsx +239 -0
  115. package/src/extensions/Drawer/components/EditDrawerBlock.tsx +238 -0
  116. package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +260 -0
  117. package/src/extensions/Drawer/index.ts +1 -0
  118. package/src/extensions/Emoji/Emoji.ts +146 -0
  119. package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +103 -0
  120. package/src/extensions/Emoji/components/EmojiList/emojis.ts +1858 -0
  121. package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +61 -0
  122. package/src/extensions/Emoji/index.ts +1 -0
  123. package/src/extensions/Excalidraw/Excalidraw.ts +123 -0
  124. package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +138 -0
  125. package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +178 -0
  126. package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +43 -0
  127. package/src/extensions/Excalidraw/index.ts +1 -0
  128. package/src/extensions/ExportPdf/ExportPdf.ts +25 -0
  129. package/src/extensions/ExportPdf/index.ts +1 -0
  130. package/src/extensions/ExportWord/ExportWord.ts +87 -0
  131. package/src/extensions/ExportWord/index.ts +1 -0
  132. package/src/extensions/FontFamily/FontFamily.ts +64 -0
  133. package/src/extensions/FontFamily/components/FontFamilyButton.tsx +97 -0
  134. package/src/extensions/FontFamily/index.ts +1 -0
  135. package/src/extensions/FontSize/FontSize.ts +119 -0
  136. package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +84 -0
  137. package/src/extensions/FontSize/index.ts +1 -0
  138. package/src/extensions/FormatPainter/FormatPainter.ts +121 -0
  139. package/src/extensions/FormatPainter/index.ts +1 -0
  140. package/src/extensions/Heading/Heading.ts +57 -0
  141. package/src/extensions/Heading/components/HeadingButton.tsx +96 -0
  142. package/src/extensions/Heading/index.ts +1 -0
  143. package/src/extensions/Highlight/Highlight.ts +36 -0
  144. package/src/extensions/Highlight/components/HighlightActionButton.tsx +108 -0
  145. package/src/extensions/Highlight/index.ts +1 -0
  146. package/src/extensions/History/History.ts +39 -0
  147. package/src/extensions/History/components/HistoryActionButton.tsx +74 -0
  148. package/src/extensions/History/index.ts +1 -0
  149. package/src/extensions/HorizontalRule/HorizontalRule.ts +42 -0
  150. package/src/extensions/HorizontalRule/index.ts +1 -0
  151. package/src/extensions/Iframe/Iframe.ts +140 -0
  152. package/src/extensions/Iframe/components/IframeNodeView.tsx +92 -0
  153. package/src/extensions/Iframe/components/index.module.scss +40 -0
  154. package/src/extensions/Iframe/embed.ts +487 -0
  155. package/src/extensions/Iframe/index.ts +1 -0
  156. package/src/extensions/Image/Image.ts +303 -0
  157. package/src/extensions/Image/components/ActionImageButton.tsx +186 -0
  158. package/src/extensions/Image/components/ImageCropper.tsx +198 -0
  159. package/src/extensions/Image/components/ImageView.tsx +271 -0
  160. package/src/extensions/Image/index.ts +1 -0
  161. package/src/extensions/Image/store.ts +15 -0
  162. package/src/extensions/ImageGif/ImageGif.ts +176 -0
  163. package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +138 -0
  164. package/src/extensions/ImageGif/components/ImageGifView.tsx +260 -0
  165. package/src/extensions/ImageGif/index.ts +1 -0
  166. package/src/extensions/ImportWord/ImportWord.ts +52 -0
  167. package/src/extensions/ImportWord/components/ImportWordButton.tsx +151 -0
  168. package/src/extensions/ImportWord/index.ts +1 -0
  169. package/src/extensions/Indent/Indent.ts +110 -0
  170. package/src/extensions/Indent/index.ts +1 -0
  171. package/src/extensions/Italic/Italic.ts +29 -0
  172. package/src/extensions/Italic/index.ts +1 -0
  173. package/src/extensions/Katex/Katex.ts +109 -0
  174. package/src/extensions/Katex/components/KatexActiveButton.tsx +117 -0
  175. package/src/extensions/Katex/components/KatexWrapper.tsx +53 -0
  176. package/src/extensions/Katex/index.ts +1 -0
  177. package/src/extensions/LineHeight/LineHeight.ts +76 -0
  178. package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +93 -0
  179. package/src/extensions/LineHeight/index.ts +1 -0
  180. package/src/extensions/Link/Link.ts +92 -0
  181. package/src/extensions/Link/components/LinkEditBlock.tsx +110 -0
  182. package/src/extensions/Link/components/LinkEditPopover.tsx +46 -0
  183. package/src/extensions/Link/components/LinkViewBlock.tsx +54 -0
  184. package/src/extensions/Link/index.ts +1 -0
  185. package/src/extensions/ListItem/ListItem.ts +1 -0
  186. package/src/extensions/ListItem/index.ts +1 -0
  187. package/src/extensions/Mention/Mention.ts +100 -0
  188. package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +94 -0
  189. package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +38 -0
  190. package/src/extensions/Mention/index.ts +1 -0
  191. package/src/extensions/Mermaid/Mermaid.ts +177 -0
  192. package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +155 -0
  193. package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +151 -0
  194. package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +260 -0
  195. package/src/extensions/Mermaid/index.ts +1 -0
  196. package/src/extensions/MoreMark/MoreMark.ts +102 -0
  197. package/src/extensions/MoreMark/components/ActionMoreButton.tsx +97 -0
  198. package/src/extensions/MoreMark/index.ts +1 -0
  199. package/src/extensions/MultiColumn/Column.ts +36 -0
  200. package/src/extensions/MultiColumn/MultiColumn.ts +111 -0
  201. package/src/extensions/MultiColumn/components/ColumnActionButton.ts +22 -0
  202. package/src/extensions/MultiColumn/index.ts +3 -0
  203. package/src/extensions/OrderedList/OrderedList.ts +28 -0
  204. package/src/extensions/OrderedList/index.ts +1 -0
  205. package/src/extensions/SearchAndReplace/SearchAndReplace.ts +395 -0
  206. package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +190 -0
  207. package/src/extensions/SearchAndReplace/index.ts +1 -0
  208. package/src/extensions/Selection/Selection.ts +32 -0
  209. package/src/extensions/Selection/index.ts +1 -0
  210. package/src/extensions/SlashCommand/SlashCommand.ts +255 -0
  211. package/src/extensions/SlashCommand/components/CommandsList.tsx +180 -0
  212. package/src/extensions/SlashCommand/groups.ts +183 -0
  213. package/src/extensions/SlashCommand/index.ts +1 -0
  214. package/src/extensions/SlashCommand/types.ts +24 -0
  215. package/src/extensions/Strike/Strike.ts +26 -0
  216. package/src/extensions/Strike/index.ts +1 -0
  217. package/src/extensions/Subscript/Subscript.ts +88 -0
  218. package/src/extensions/Subscript/index.ts +1 -0
  219. package/src/extensions/Table/Cell.ts +131 -0
  220. package/src/extensions/Table/Header.ts +93 -0
  221. package/src/extensions/Table/Row.ts +8 -0
  222. package/src/extensions/Table/Table.ts +60 -0
  223. package/src/extensions/Table/cell-background.ts +112 -0
  224. package/src/extensions/Table/components/CreateTablePopover.tsx +132 -0
  225. package/src/extensions/Table/components/TableActionButton.tsx +42 -0
  226. package/src/extensions/Table/index.ts +6 -0
  227. package/src/extensions/Table/utils.ts +352 -0
  228. package/src/extensions/TableOfContent/TableOfContent.ts +124 -0
  229. package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +116 -0
  230. package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +27 -0
  231. package/src/extensions/TableOfContent/components/index.module.scss +40 -0
  232. package/src/extensions/TableOfContent/index.ts +1 -0
  233. package/src/extensions/TaskList/TaskList.ts +46 -0
  234. package/src/extensions/TaskList/index.ts +1 -0
  235. package/src/extensions/TextAlign/TextAlign.ts +68 -0
  236. package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +103 -0
  237. package/src/extensions/TextAlign/index.ts +1 -0
  238. package/src/extensions/TextBubble/TextBubble.ts +22 -0
  239. package/src/extensions/TextBubble/components/TextDropdown.tsx +146 -0
  240. package/src/extensions/TextBubble/index.ts +1 -0
  241. package/src/extensions/TextDirection/TextDirection.ts +97 -0
  242. package/src/extensions/TextDirection/components/TextDirectionButton.tsx +103 -0
  243. package/src/extensions/TextDirection/index.ts +1 -0
  244. package/src/extensions/TrailingNode/TrailingNode.ts +71 -0
  245. package/src/extensions/TrailingNode/index.ts +1 -0
  246. package/src/extensions/Twitter/Twitter.ts +161 -0
  247. package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +68 -0
  248. package/src/extensions/Twitter/components/NodeViewTweet.tsx +30 -0
  249. package/src/extensions/Twitter/components/TwitterActiveButton.tsx +41 -0
  250. package/src/extensions/Twitter/index.ts +1 -0
  251. package/src/extensions/UnderLine/Underline.ts +30 -0
  252. package/src/extensions/UnderLine/index.ts +1 -0
  253. package/src/extensions/Video/Video.ts +204 -0
  254. package/src/extensions/Video/components/ActiveVideoButton.tsx +191 -0
  255. package/src/extensions/Video/index.ts +1 -0
  256. package/src/extensions/Video/store.ts +15 -0
  257. package/src/extensions/index.ts +122 -0
  258. package/src/hooks/useActive.tsx +24 -0
  259. package/src/hooks/useAttributes.tsx +45 -0
  260. package/src/hooks/useCopy.tsx +20 -0
  261. package/src/hooks/useEditorState.tsx +23 -0
  262. package/src/hooks/useExtension.tsx +29 -0
  263. package/src/index.ts +8 -0
  264. package/src/lib/utils.ts +7 -0
  265. package/src/locale-bundle.ts +3 -0
  266. package/src/locales/en.ts +173 -0
  267. package/src/locales/hu.ts +173 -0
  268. package/src/locales/index.tsx +163 -0
  269. package/src/locales/pt-br.ts +173 -0
  270. package/src/locales/vi.ts +173 -0
  271. package/src/locales/zh-cn.ts +173 -0
  272. package/src/plugins/DragHandle/index.ts +375 -0
  273. package/src/plugins/DragHandle/range.ts +114 -0
  274. package/src/plugins/DragHandle/utils.ts +80 -0
  275. package/src/plugins/image-upload.ts +160 -0
  276. package/src/store/ProviderRichText.tsx +53 -0
  277. package/src/store/editableEditor.ts +15 -0
  278. package/src/store/fast-context.tsx +70 -0
  279. package/src/store/store.ts +35 -0
  280. package/src/styles/ProseMirror.scss +176 -0
  281. package/src/styles/columns.scss +23 -0
  282. package/src/styles/editor.scss +411 -0
  283. package/src/styles/global.scss +87 -0
  284. package/src/styles/index.scss +5 -0
  285. package/src/styles/mention.scss +6 -0
  286. package/src/theme/theme.ts +15 -0
  287. package/src/types.ts +271 -0
  288. package/src/utils/_event.ts +55 -0
  289. package/src/utils/color.ts +67 -0
  290. package/src/utils/columns.ts +142 -0
  291. package/src/utils/customEvents/customEvents.ts +18 -0
  292. package/src/utils/customEvents/events.constant.ts +11 -0
  293. package/src/utils/delete-node.ts +46 -0
  294. package/src/utils/dom-dataset.ts +121 -0
  295. package/src/utils/download.ts +17 -0
  296. package/src/utils/dynamicCSS.ts +192 -0
  297. package/src/utils/editor-container-size.ts +28 -0
  298. package/src/utils/file.ts +112 -0
  299. package/src/utils/getRenderContainer.ts +41 -0
  300. package/src/utils/indent.ts +99 -0
  301. package/src/utils/is-mobile.ts +57 -0
  302. package/src/utils/json.ts +18 -0
  303. package/src/utils/line-height.ts +109 -0
  304. package/src/utils/lru-cache.ts +145 -0
  305. package/src/utils/mitt.ts +114 -0
  306. package/src/utils/node.ts +92 -0
  307. package/src/utils/pdf.ts +72 -0
  308. package/src/utils/plateform.ts +49 -0
  309. package/src/utils/shortId.ts +5 -0
  310. package/src/utils/storage.ts +18 -0
  311. package/src/utils/utils.ts +71 -0
  312. package/src/vite-env.d.ts +3 -0
  313. package/lib/RichTextEditor-BwbqJLnA.cjs +0 -141
  314. package/lib/RichTextEditor-iGJ6-rbq.js +0 -8833
  315. package/lib/extension-bundle.cjs +0 -33
  316. package/lib/extension-bundle.d.cts +0 -947
  317. package/lib/extension-bundle.d.ts +0 -947
  318. package/lib/extension-bundle.js +0 -5755
  319. package/lib/index-DV-nXpU1.cjs +0 -1
  320. package/lib/index-M6H3FoBi.js +0 -1147
  321. package/lib/index.cjs +0 -1
  322. package/lib/index.d.cts +0 -513
  323. package/lib/index.d.ts +0 -513
  324. package/lib/index.js +0 -16
  325. package/lib/locale-bundle.cjs +0 -1
  326. package/lib/locale-bundle.d.cts +0 -1140
  327. package/lib/locale-bundle.d.ts +0 -1140
  328. package/lib/locale-bundle.js +0 -9
  329. package/lib/style.css +0 -1
  330. package/lib/tiptap-DkWHMWDt.js +0 -6061
  331. package/lib/tiptap-gBG-1T-V.cjs +0 -116
  332. package/lib/vendor-BJ0Yf78E.cjs +0 -8114
  333. package/lib/vendor-Cpa6z-M0.js +0 -67575
@@ -0,0 +1,271 @@
1
+ /* eslint-disable no-unsafe-optional-chaining */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
4
+
5
+ import { NodeViewWrapper } from '@tiptap/react';
6
+ import { clamp, isNumber, throttle } from 'lodash-es';
7
+
8
+ import { IMAGE_MAX_SIZE, IMAGE_MIN_SIZE, IMAGE_THROTTLE_WAIT_TIME } from 'reactjs-tiptap-editor-pro/constants';
9
+
10
+ interface Size {
11
+ width: number
12
+ height: number
13
+ }
14
+
15
+ const ResizeDirection = {
16
+ TOP_LEFT: 'tl',
17
+ TOP_RIGHT: 'tr',
18
+ BOTTOM_LEFT: 'bl',
19
+ BOTTOM_RIGHT: 'br',
20
+ };
21
+
22
+ function ImageView(props: any) {
23
+ const [maxSize, setMaxSize] = useState<Size>({
24
+ width: IMAGE_MAX_SIZE,
25
+ height: IMAGE_MAX_SIZE,
26
+ });
27
+
28
+ const [originalSize, setOriginalSize] = useState({
29
+ width: 0,
30
+ height: 0,
31
+ });
32
+
33
+ const [resizeDirections] = useState<string[]>([
34
+ ResizeDirection.TOP_LEFT,
35
+ ResizeDirection.TOP_RIGHT,
36
+ ResizeDirection.BOTTOM_LEFT,
37
+ ResizeDirection.BOTTOM_RIGHT,
38
+ ]);
39
+
40
+ const [resizing, setResizing] = useState<boolean>(false);
41
+
42
+ const [resizerState, setResizerState] = useState({
43
+ x: 0,
44
+ y: 0,
45
+ w: 0,
46
+ h: 0,
47
+ dir: '',
48
+ });
49
+
50
+ const { align, inline } = props?.node?.attrs;
51
+
52
+ const imgAttrs = useMemo(() => {
53
+ const { src, alt, width: w, height: h, flipX, flipY } = props?.node?.attrs;
54
+
55
+ const width = isNumber(w) ? `${w}px` : w;
56
+ const height = isNumber(h) ? `${h}px` : h;
57
+ const transformStyles: any = [];
58
+
59
+ if (flipX)
60
+ transformStyles.push('rotateX(180deg)');
61
+ if (flipY)
62
+ transformStyles.push('rotateY(180deg)');
63
+ const transform = transformStyles.join(' ');
64
+
65
+ return {
66
+ src: src || undefined,
67
+ alt: alt || undefined,
68
+ style: {
69
+ width: width || undefined,
70
+ height: height || undefined,
71
+ transform: transform || 'none',
72
+ },
73
+ };
74
+ }, [props?.node?.attrs]);
75
+
76
+ const imageMaxStyle = useMemo(() => {
77
+ const {
78
+ style: { width },
79
+ } = imgAttrs;
80
+
81
+ return { width: width === '100%' ? width : undefined };
82
+ }, [imgAttrs]);
83
+
84
+ function onImageLoad(e: Record<string, any>) {
85
+ setOriginalSize({
86
+ width: e.target.width,
87
+ height: e.target.height,
88
+ });
89
+ }
90
+
91
+ // https://github.com/scrumpy/tiptap/issues/361#issuecomment-540299541
92
+ function selectImage() {
93
+ const { editor, getPos } = props;
94
+ editor.commands.setNodeSelection(getPos());
95
+ }
96
+
97
+ const getMaxSize = useCallback(
98
+ throttle(() => {
99
+ const { editor } = props;
100
+ const { width } = getComputedStyle(editor.view.dom);
101
+ setMaxSize((prev) => {
102
+ return {
103
+ ...prev,
104
+ width: Number.parseInt(width, 10),
105
+ };
106
+ });
107
+ }, IMAGE_THROTTLE_WAIT_TIME),
108
+ [props?.editor],
109
+ );
110
+
111
+ function onMouseDown(e: MouseEvent, dir: string) {
112
+ e.preventDefault();
113
+ e.stopPropagation();
114
+
115
+ const originalWidth = originalSize.width;
116
+ const originalHeight = originalSize.height;
117
+ const aspectRatio = originalWidth / originalHeight;
118
+
119
+ let width = Number(props.node.attrs.width);
120
+ let height = Number(props.node.attrs.height);
121
+ const maxWidth = maxSize.width;
122
+
123
+ if (width && !height) {
124
+ width = width > maxWidth ? maxWidth : width;
125
+ height = Math.round(width / aspectRatio);
126
+ } else if (height && !width) {
127
+ width = Math.round(height * aspectRatio);
128
+ width = width > maxWidth ? maxWidth : width;
129
+ } else if (!width && !height) {
130
+ width = originalWidth > maxWidth ? maxWidth : originalWidth;
131
+ height = Math.round(width / aspectRatio);
132
+ } else {
133
+ width = width > maxWidth ? maxWidth : width;
134
+ }
135
+
136
+ setResizing(true);
137
+
138
+ setResizerState({
139
+ x: e.clientX,
140
+ y: e.clientY,
141
+ w: width,
142
+ h: height,
143
+ dir,
144
+ });
145
+ }
146
+
147
+ const onMouseMove = useCallback(
148
+ throttle((e: MouseEvent) => {
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+
152
+ if (!resizing) {
153
+ return;
154
+ }
155
+
156
+ const { x, w, dir } = resizerState;
157
+
158
+ const dx = (e.clientX - x) * (/l/.test(dir) ? -1 : 1);
159
+ // const dy = (e.clientY - y) * (/t/.test(dir) ? -1 : 1)
160
+
161
+ const width = clamp(w + dx, IMAGE_MIN_SIZE, maxSize.width);
162
+ const height = null;
163
+
164
+ props.updateAttributes({
165
+ width,
166
+ height,
167
+ });
168
+ }, IMAGE_THROTTLE_WAIT_TIME),
169
+ [resizing, resizerState, maxSize, props.updateAttributes],
170
+ );
171
+
172
+ const onMouseUp = useCallback(
173
+ (e: MouseEvent) => {
174
+ e.preventDefault();
175
+ e.stopPropagation();
176
+ if (!resizing) {
177
+ return;
178
+ }
179
+
180
+ setResizerState({
181
+ x: 0,
182
+ y: 0,
183
+ w: 0,
184
+ h: 0,
185
+ dir: '',
186
+ });
187
+ setResizing(false);
188
+
189
+ selectImage();
190
+ },
191
+ [resizing, selectImage],
192
+ );
193
+
194
+ const onEvents = useCallback(() => {
195
+ document?.addEventListener('mousemove', onMouseMove, true);
196
+ document?.addEventListener('mouseup', onMouseUp, true);
197
+ }, [onMouseMove, onMouseUp]);
198
+
199
+ const offEvents = useCallback(() => {
200
+ document?.removeEventListener('mousemove', onMouseMove, true);
201
+ document?.removeEventListener('mouseup', onMouseUp, true);
202
+ }, [onMouseMove, onMouseUp]);
203
+
204
+ useEffect(() => {
205
+ if (resizing) {
206
+ onEvents();
207
+ } else {
208
+ offEvents();
209
+ }
210
+
211
+ return () => {
212
+ offEvents();
213
+ };
214
+ }, [resizing, onEvents, offEvents]);
215
+
216
+ const resizeOb: ResizeObserver = useMemo(() => {
217
+ return new ResizeObserver(() => getMaxSize());
218
+ }, [getMaxSize]);
219
+
220
+ useEffect(() => {
221
+ resizeOb.observe(props.editor.view.dom);
222
+
223
+ return () => {
224
+ resizeOb.disconnect();
225
+ };
226
+ }, [props.editor.view.dom, resizeOb]);
227
+
228
+ return (
229
+ <NodeViewWrapper
230
+ as={inline ? 'span' : 'div'}
231
+ className="image-view"
232
+ style={{ ...imageMaxStyle, textAlign: align, display: inline ? 'inline' : 'block' }}
233
+ >
234
+ <div
235
+ data-drag-handle
236
+ draggable="true"
237
+ style={imageMaxStyle}
238
+ className={`image-view__body ${props?.selected ? 'image-view__body--focused' : ''} ${
239
+ resizing ? 'image-view__body--resizing' : ''
240
+ }`}
241
+ >
242
+ <img
243
+ alt={imgAttrs.alt}
244
+ className="image-view__body__image block"
245
+ height="auto"
246
+ onClick={selectImage}
247
+ onLoad={onImageLoad}
248
+ src={imgAttrs.src}
249
+ style={imgAttrs.style}
250
+ />
251
+
252
+ {props?.editor.view.editable && (props?.selected || resizing) && (
253
+ <div className="image-resizer">
254
+ {resizeDirections?.map((direction) => {
255
+ return (
256
+ <span
257
+ className={`image-resizer__handler image-resizer__handler--${direction}`}
258
+ key={`image-dir-${direction}`}
259
+ onMouseDown={(e: any) => onMouseDown(e, direction)}
260
+ >
261
+ </span>
262
+ );
263
+ })}
264
+ </div>
265
+ )}
266
+ </div>
267
+ </NodeViewWrapper>
268
+ );
269
+ }
270
+
271
+ export default ImageView;
@@ -0,0 +1 @@
1
+ export * from './Image';
@@ -0,0 +1,15 @@
1
+ import { useStoreUploadImage } from 'reactjs-tiptap-editor-pro/store/store';
2
+ import { dispatchEvent } from 'reactjs-tiptap-editor-pro/utils/customEvents/customEvents';
3
+ import { EVENTS } from 'reactjs-tiptap-editor-pro/utils/customEvents/events.constant';
4
+
5
+ export function useDialogImage() {
6
+ const [v] = useStoreUploadImage(store => store.value);
7
+
8
+ return v;
9
+ }
10
+
11
+ export const actionDialogImage = {
12
+ setOpen: (id: any, value: boolean) => {
13
+ dispatchEvent(EVENTS.UPLOAD_IMAGE(id), value);
14
+ },
15
+ };
@@ -0,0 +1,176 @@
1
+ import { mergeAttributes } from '@tiptap/core';
2
+ import type { ImageOptions } from '@tiptap/extension-image';
3
+ import TiptapImage from '@tiptap/extension-image';
4
+ import { ReactNodeViewRenderer } from '@tiptap/react';
5
+
6
+ import ImageGifActionButton from 'reactjs-tiptap-editor-pro/extensions/ImageGif/components/ImageGifActionButton';
7
+ import ImageGifView from 'reactjs-tiptap-editor-pro/extensions/ImageGif/components/ImageGifView';
8
+
9
+ export interface SetImageAttrsOptions {
10
+ src?: string
11
+ /** The alternative text for the image. */
12
+ alt?: string
13
+ /** The title of the image. */
14
+ title?: string
15
+ /** The width of the image. */
16
+ width?: number | string | null
17
+ /** The alignment of the image. */
18
+ align?: 'left' | 'center' | 'right'
19
+ }
20
+
21
+ interface ImageGifOptions extends ImageOptions {
22
+ /**
23
+ * The key for the gif https://giphy.com/
24
+ */
25
+ GIPHY_API_KEY: string
26
+ }
27
+
28
+ declare module '@tiptap/core' {
29
+ interface Commands<ReturnType> {
30
+ imageGifUpload: {
31
+ /**
32
+ * Add an image gif
33
+ */
34
+ setImageGif: (options: Partial<SetImageAttrsOptions>) => ReturnType
35
+ /**
36
+ * Update an image gif
37
+ */
38
+ updateImageGif: (options: Partial<SetImageAttrsOptions>) => ReturnType
39
+ /**
40
+ * Set image alignment
41
+ */
42
+ setAlignImageGif: (align: 'left' | 'center' | 'right') => ReturnType
43
+ }
44
+ }
45
+ }
46
+
47
+ export const ImageGif = TiptapImage.extend<ImageGifOptions>({
48
+ name: 'imageGif',
49
+ addOptions() {
50
+ return {
51
+ ...this.parent?.(),
52
+ inline: false,
53
+ content: '',
54
+ marks: '',
55
+ group: 'block',
56
+ GIPHY_API_KEY: '',
57
+ draggable: false,
58
+ selectable: true,
59
+ atom: true,
60
+ button: ({ editor, extension, t }: any) => {
61
+ const giphyApiKey = extension?.options?.GIPHY_API_KEY || '';
62
+
63
+ return {
64
+ component: ImageGifActionButton,
65
+ componentProps: {
66
+ editor,
67
+ action: () => {
68
+ return;
69
+ },
70
+ isActive: () => false,
71
+ disabled: false,
72
+ icon: 'GifIcon',
73
+ tooltip: t('editor.imageGif.tooltip'),
74
+ giphyApiKey,
75
+ },
76
+ };
77
+ },
78
+ };
79
+ },
80
+ addAttributes() {
81
+ return {
82
+ ...this.parent?.(),
83
+ width: {
84
+ default: null,
85
+ parseHTML: (element) => {
86
+ const width = element.style.width || element.getAttribute('width') || '10';
87
+ return width === undefined ? null : Number.parseInt(`${width}`, 10);
88
+ },
89
+ renderHTML: (attributes) => {
90
+ return {
91
+ width: attributes.width,
92
+ };
93
+ },
94
+ },
95
+ align: {
96
+ default: 'center',
97
+ parseHTML: element => element.getAttribute('align'),
98
+ renderHTML: (attributes) => {
99
+ return {
100
+ align: attributes.align,
101
+ };
102
+ },
103
+ },
104
+ };
105
+ },
106
+
107
+ addNodeView() {
108
+ return ReactNodeViewRenderer(ImageGifView);
109
+ },
110
+ addCommands() {
111
+ return {
112
+ ...this.parent?.(),
113
+ setImageGif: (options: any) => ({ commands }: any) => {
114
+ return commands.insertContent({
115
+ type: this.name,
116
+ attrs: options,
117
+ });
118
+ },
119
+ updateImageGif:
120
+ (options: any) =>
121
+ ({ commands }: any) => {
122
+ return commands.updateAttributes(this.name, options);
123
+ },
124
+ setAlignImageGif:
125
+ (align: any) =>
126
+ ({ commands }: any) => {
127
+ return commands.updateAttributes(this.name, { align });
128
+ },
129
+ };
130
+ },
131
+ renderHTML({ HTMLAttributes }) {
132
+ const { align } = HTMLAttributes;
133
+
134
+ const style = align ? `text-align: ${align};` : '';
135
+ return [
136
+ 'div', // Parent element
137
+ {
138
+ style,
139
+ class: 'imageGIf',
140
+ },
141
+ [
142
+ 'img',
143
+ mergeAttributes(
144
+ // Always render the `height="auto"`
145
+ {
146
+ height: 'auto',
147
+ },
148
+ this.options.HTMLAttributes,
149
+ HTMLAttributes,
150
+ ),
151
+ ],
152
+ ];
153
+ },
154
+ parseHTML() {
155
+ return [
156
+ {
157
+ tag: 'div[class=imageGIf]',
158
+ getAttrs: (element) => {
159
+ const img = element.querySelector('img');
160
+
161
+ const width = img?.getAttribute('width');
162
+
163
+ return {
164
+ src: img?.getAttribute('src'),
165
+ alt: img?.getAttribute('alt'),
166
+ title: img?.getAttribute('title'),
167
+ width: width ? Number.parseInt(width, 10) : null,
168
+ align: img?.getAttribute('align') || element.style.textAlign || null,
169
+ };
170
+ },
171
+ },
172
+ ];
173
+ },
174
+ });
175
+
176
+ export default ImageGif;
@@ -0,0 +1,138 @@
1
+ import type React from 'react';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+
4
+ import { debounce } from 'lodash-es';
5
+
6
+ import { ActionButton, Input, Popover, PopoverContent, PopoverTrigger } from 'reactjs-tiptap-editor-pro/components';
7
+
8
+ interface IProps {
9
+ showClear?: boolean
10
+ selectImage: (arg: string) => void
11
+ children: React.ReactNode
12
+ giphyApiKey: string
13
+ }
14
+
15
+ function ImageGifWrap({ selectImage, giphyApiKey, children }: IProps) {
16
+ const [gifs, setGifs] = useState([]);
17
+ const [limit] = useState(15);
18
+
19
+ const inputRef = useRef(null);
20
+
21
+ const search = (term: any, kind: any = 'search') => {
22
+ if (!giphyApiKey) {
23
+ return;
24
+ }
25
+
26
+ const url
27
+ = kind === 'search'
28
+ ? `https://api.giphy.com/v1/gifs/search?q=${term}`
29
+ : `https://api.giphy.com/v1/gifs/trending?q=${term}`;
30
+ const link = `${url}&limit=${limit}&api_key=${giphyApiKey}`;
31
+
32
+ fetch(link).then(r => r.json()).then((response) => {
33
+ // handle success
34
+ setGifs(response.data);
35
+ })
36
+ .catch((error) => {
37
+ // handle error
38
+ console.log(error);
39
+ });
40
+ };
41
+
42
+ useEffect(() => {
43
+ search('', 'trend');
44
+ }, []);
45
+
46
+ const handleInputChange = useCallback(
47
+ debounce((event: React.ChangeEvent<HTMLInputElement>) => {
48
+ if (!event.target.value) {
49
+ search('', 'trend');
50
+ return;
51
+ }
52
+ // Add your logic here
53
+ search(event.target.value);
54
+ }, 350), // Adjust the debounce delay as needed
55
+ [],
56
+ );
57
+
58
+ return (
59
+ <Popover modal>
60
+ <PopoverTrigger asChild>
61
+ {children}
62
+ </PopoverTrigger>
63
+
64
+ <PopoverContent align="start"
65
+ className="size-full p-2"
66
+ hideWhenDetached
67
+ side="bottom"
68
+ >
69
+
70
+ {
71
+ giphyApiKey
72
+ ? (
73
+ <>
74
+ <div className="mb-[10px] w-full">
75
+ <Input
76
+ onChange={handleInputChange}
77
+ placeholder="Search GIF"
78
+ ref={inputRef}
79
+ type="text"
80
+ />
81
+ </div>
82
+
83
+ <div className="max-h-[280px] overflow-y-auto">
84
+ <div className="grid grid-cols-2 gap-1 ">
85
+
86
+ {gifs?.length
87
+ ? gifs?.map((o: any) => (
88
+ <img
89
+ alt="giphy"
90
+ className="cursor-pointer text-center"
91
+ height={o.images.fixed_width_downsampled.height}
92
+ key={`giphy-${o.id}`}
93
+ onClick={() => selectImage(o)}
94
+ src={o.images.fixed_width_downsampled.url}
95
+ width={o.images.fixed_width_downsampled.width}
96
+ />
97
+ ))
98
+ : <p>
99
+ No GIFs found
100
+ </p>}
101
+ </div>
102
+ </div>
103
+ </>
104
+ )
105
+ : (
106
+ <div>
107
+ <p>
108
+ Missing Giphy API Key
109
+ </p>
110
+ </div>
111
+ )
112
+ }
113
+ </PopoverContent>
114
+ </Popover>
115
+ );
116
+ }
117
+
118
+ export function ImageGifActionButton({ editor, icon, giphyApiKey, ...props }: any) {
119
+ const selectImage = (giphyblock: any) => {
120
+ const { url } = giphyblock.images.original;
121
+
122
+ editor.chain().focus().setImageGif({ src: url }).run();
123
+ };
124
+
125
+ return (
126
+ <ImageGifWrap
127
+ giphyApiKey={giphyApiKey}
128
+ selectImage={selectImage}
129
+ >
130
+ <ActionButton
131
+ icon={icon}
132
+ tooltip={props?.tooltip}
133
+ />
134
+ </ImageGifWrap>
135
+ );
136
+ }
137
+
138
+ export default ImageGifActionButton;