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,64 @@
1
+ import type { Extension } from '@tiptap/core';
2
+ import type { FontFamilyOptions as TiptapFontFamilyOptions } from '@tiptap/extension-font-family';
3
+ import FontFamilyTiptap from '@tiptap/extension-font-family';
4
+
5
+ import type { BaseKitOptions } from '../BaseKit';
6
+ import { ensureNameValueOptions } from 'reactjs-tiptap-editor-pro/utils/utils';
7
+ import { DEFAULT_FONT_FAMILY_LIST } from 'reactjs-tiptap-editor-pro/constants';
8
+ import FontFamilyButton from 'reactjs-tiptap-editor-pro/extensions/FontFamily/components/FontFamilyButton';
9
+ import type { GeneralOptions, NameValueOption } from 'reactjs-tiptap-editor-pro/types';
10
+
11
+ export interface FontFamilyOptions extends TiptapFontFamilyOptions, GeneralOptions<FontFamilyOptions> {
12
+ /**
13
+ * Font family list.
14
+ */
15
+ fontFamilyList: (string | NameValueOption)[]
16
+ }
17
+
18
+ export const FontFamily = FontFamilyTiptap.extend<FontFamilyOptions>({
19
+ addOptions() {
20
+ return {
21
+ ...this.parent?.(),
22
+ fontFamilyList: DEFAULT_FONT_FAMILY_LIST,
23
+ button({ editor, extension, t }: any) {
24
+ const { extensions = [] } = editor.extensionManager ?? [];
25
+ const fontFamilyList = ensureNameValueOptions(extension?.options?.fontFamilyList || []);
26
+ const baseKitExt = extensions.find(
27
+ (k: any) => k.name === 'base-kit',
28
+ ) as Extension<BaseKitOptions>;
29
+
30
+ const items = fontFamilyList.map(font => ({
31
+ action: () => {
32
+ editor.chain().focus().setFontFamily(font.value).run();
33
+ },
34
+ isActive: () => editor.isActive('textStyle', { fontFamily: font.value }) || false,
35
+ disabled: !editor.can().setFontFamily(font.value),
36
+ title: font.name,
37
+ font: font.value,
38
+ }));
39
+
40
+ if (baseKitExt && baseKitExt.options.textStyle !== false) {
41
+ items.unshift({
42
+ action: () => editor.chain().focus().unsetFontFamily().run(),
43
+ isActive: () => false,
44
+ disabled: false,
45
+ font: t('editor.fontFamily.default.tooltip'),
46
+ title: t('editor.fontFamily.tooltip'),
47
+ });
48
+ }
49
+
50
+ const disabled = items.filter((k: any) => k.disabled).length === items.length;
51
+
52
+ return {
53
+ component: FontFamilyButton,
54
+ componentProps: {
55
+ tooltip: t('editor.fontFamily.tooltip'),
56
+ disabled,
57
+ items,
58
+ editor,
59
+ },
60
+ };
61
+ },
62
+ };
63
+ },
64
+ });
@@ -0,0 +1,97 @@
1
+ import React, { Fragment, useMemo } from 'react';
2
+
3
+ import {
4
+ ActionMenuButton,
5
+ DropdownMenu,
6
+ DropdownMenuCheckboxItem,
7
+ DropdownMenuContent,
8
+ DropdownMenuSeparator,
9
+ DropdownMenuTrigger,
10
+ } from 'reactjs-tiptap-editor-pro/components';
11
+ import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
12
+ import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
13
+
14
+ export interface Item {
15
+ title: string
16
+ icon?: any
17
+ font?: string
18
+ isActive: NonNullable<ButtonViewReturnComponentProps['isActive']>
19
+ action?: ButtonViewReturnComponentProps['action']
20
+ style?: React.CSSProperties
21
+ shortcutKeys?: string[]
22
+ disabled?: boolean
23
+ divider?: boolean
24
+ default?: boolean
25
+ }
26
+
27
+ interface Props {
28
+ editor: any
29
+ disabled?: boolean
30
+ color?: string
31
+ shortcutKeys?: string[]
32
+ maxHeight?: string | number
33
+ tooltip?: string
34
+ items?: Item[]
35
+ }
36
+
37
+ function FontFamilyButton(props: Props) {
38
+ const { t, lang } = useLocale();
39
+
40
+ const active = useMemo(() => {
41
+ const find: any = props?.items?.find((k: any) => k.isActive());
42
+
43
+ if (find && !find.default) {
44
+ return {
45
+ ...find,
46
+ };
47
+ }
48
+ const item: Item = {
49
+ title: props.tooltip as any,
50
+ font: t('editor.fontFamily.default.tooltip'),
51
+ isActive: () => false,
52
+ disabled: false,
53
+ action: () => props.editor.chain().focus().unsetFontFamily().run(),
54
+ };
55
+ return item;
56
+ }, [t, lang, props]);
57
+
58
+ return (
59
+ <DropdownMenu>
60
+ <DropdownMenuTrigger asChild
61
+ disabled={props?.disabled}
62
+ >
63
+ <ActionMenuButton
64
+ disabled={props?.disabled}
65
+ icon="MenuDown"
66
+ title={active?.font?.length > 7 ? `${active?.font?.slice(0, 6)}...` : active?.font}
67
+ tooltip={props?.tooltip}
68
+ />
69
+ </DropdownMenuTrigger>
70
+
71
+ <DropdownMenuContent className="w-full">
72
+ {props?.items?.map((item: any, index) => {
73
+ const style
74
+ = item.font === t('editor.fontFamily.default.tooltip') ? {} : { fontFamily: item.font };
75
+
76
+ return (
77
+ <Fragment key={`font-family-${index}`}>
78
+ <DropdownMenuCheckboxItem checked={active?.font === item.font}
79
+ onClick={item.action}
80
+ >
81
+ <div className="ml-1 h-full"
82
+ style={style}
83
+ >
84
+ {item.font}
85
+ </div>
86
+ </DropdownMenuCheckboxItem>
87
+
88
+ {item.font === t('editor.fontFamily.default.tooltip') && <DropdownMenuSeparator />}
89
+ </Fragment>
90
+ );
91
+ })}
92
+ </DropdownMenuContent>
93
+ </DropdownMenu>
94
+ );
95
+ }
96
+
97
+ export default FontFamilyButton;
@@ -0,0 +1 @@
1
+ export * from './FontFamily';
@@ -0,0 +1,119 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ import FontSizeMenuButton from './components/FontSizeMenuButton';
4
+ import { ensureNameValueOptions } from 'reactjs-tiptap-editor-pro/utils/utils';
5
+ import { DEFAULT_FONT_SIZE_LIST, DEFAULT_FONT_SIZE_VALUE } from 'reactjs-tiptap-editor-pro/constants';
6
+ import type { GeneralOptions, NameValueOption } from 'reactjs-tiptap-editor-pro/types';
7
+
8
+ /**
9
+ * Represents the interface for font size options, extending GeneralOptions.
10
+ */
11
+ export interface FontSizeOptions extends GeneralOptions<FontSizeOptions> {
12
+ types: string[]
13
+ /**
14
+ * List of available font size values
15
+ *
16
+ * @default DEFAULT_FONT_SIZE_LIST
17
+ */
18
+ fontSizes: (string | NameValueOption)[]
19
+ }
20
+
21
+ declare module '@tiptap/core' {
22
+ interface Commands<ReturnType> {
23
+ fontSize: {
24
+ /**
25
+ * Set the text font size. ex: "12px", "2em", or "small". Must be a valid
26
+ * CSS font-size
27
+ * (https://developer.mozilla.org/en-US/docs/Web/CSS/font-size).
28
+ */
29
+ setFontSize: (fontSize: string) => ReturnType
30
+ /**
31
+ * Unset the font size
32
+ */
33
+ unsetFontSize: () => ReturnType
34
+ }
35
+ }
36
+ }
37
+
38
+ export const FontSize = Extension.create<FontSizeOptions>({
39
+ name: 'fontSize',
40
+ addOptions() {
41
+ return {
42
+ ...this.parent?.(),
43
+ types: ['textStyle'],
44
+ fontSizes: [...DEFAULT_FONT_SIZE_LIST],
45
+ button({ editor, extension, t }) {
46
+ const fontSizes = ensureNameValueOptions(extension.options?.fontSizes || DEFAULT_FONT_SIZE_VALUE);
47
+ const defaultFontSize = ensureNameValueOptions([DEFAULT_FONT_SIZE_VALUE])[0];
48
+ const items = fontSizes.map(k => ({
49
+ title: k.value === defaultFontSize.value ? t('editor.fontSize.default.tooltip') : String(k.name),
50
+ isActive: () => {
51
+ const { fontSize } = editor.getAttributes('textStyle');
52
+ const isDefault = k.value === defaultFontSize.value;
53
+ const notFontSize = fontSize === undefined;
54
+ if (isDefault && notFontSize) {
55
+ return true;
56
+ }
57
+ return editor.isActive({ fontSize: String(k.value) }) || false;
58
+ },
59
+ action: () => {
60
+ if (k.value === defaultFontSize.value) {
61
+ editor.commands.unsetFontSize();
62
+ return;
63
+ }
64
+ editor.commands.setFontSize(String(k.value));
65
+ },
66
+ disabled: !editor.can().setFontSize(String(k.value)),
67
+ divider: k.value === defaultFontSize.value || false,
68
+ default: k.value === defaultFontSize.value || false,
69
+ }));
70
+ const disabled = items.filter(k => k.disabled).length === items.length;
71
+ return {
72
+ component: FontSizeMenuButton,
73
+ componentProps: {
74
+ editor,
75
+ tooltip: t('editor.fontSize.tooltip'),
76
+ disabled,
77
+ items,
78
+ maxHeight: 280,
79
+ },
80
+ };
81
+ },
82
+ };
83
+ },
84
+ addGlobalAttributes() {
85
+ return [
86
+ {
87
+ types: this.options.types,
88
+ attributes: {
89
+ fontSize: {
90
+ default: null,
91
+ parseHTML: element => element.style.fontSize.replaceAll(/["']+/g, ''),
92
+ renderHTML: (attributes) => {
93
+ if (!attributes.fontSize) {
94
+ return {};
95
+ }
96
+ return {
97
+ style: `font-size: ${attributes.fontSize}`,
98
+ };
99
+ },
100
+ },
101
+ },
102
+ },
103
+ ];
104
+ },
105
+ addCommands() {
106
+ return {
107
+ setFontSize:
108
+ fontSize =>
109
+ ({ chain }) => {
110
+ return chain().setMark('textStyle', { fontSize }).run();
111
+ },
112
+ unsetFontSize:
113
+ () =>
114
+ ({ chain }) => {
115
+ return chain().setMark('textStyle', { fontSize: null }).removeEmptyTextStyle().run();
116
+ },
117
+ };
118
+ },
119
+ });
@@ -0,0 +1,84 @@
1
+ import React, { useMemo, useRef } from 'react';
2
+
3
+ import {
4
+ ActionMenuButton,
5
+ DropdownMenu,
6
+ DropdownMenuCheckboxItem,
7
+ DropdownMenuContent,
8
+ DropdownMenuTrigger,
9
+ } from 'reactjs-tiptap-editor-pro/components';
10
+ import { useLocale } from 'reactjs-tiptap-editor-pro/locales';
11
+ import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
12
+
13
+ export interface Item {
14
+ title: string
15
+ isActive: NonNullable<ButtonViewReturnComponentProps['isActive']>
16
+ action?: ButtonViewReturnComponentProps['action']
17
+ style?: React.CSSProperties
18
+ disabled?: boolean
19
+ divider?: boolean
20
+ default?: boolean
21
+ }
22
+
23
+ interface IPropsFontSizeMenuButton {
24
+ editor: any
25
+ disabled?: boolean
26
+ color?: string
27
+ shortcutKeys?: string[]
28
+ maxHeight?: string | number
29
+ tooltip?: string
30
+ items?: Item[]
31
+ }
32
+
33
+ function FontSizeMenuButton(props: IPropsFontSizeMenuButton) {
34
+ const { t } = useLocale();
35
+ const divRef = useRef<HTMLDivElement>(null);
36
+
37
+ const active = useMemo(() => {
38
+ const find: any = (props.items || []).find((k: any) => k.isActive());
39
+ if (find) {
40
+ return find;
41
+ }
42
+ const item: Item = {
43
+ title: t('editor.fontSize.default.tooltip'),
44
+ isActive: () => false,
45
+ };
46
+ return item;
47
+ }, [props]);
48
+
49
+ return (
50
+ <DropdownMenu>
51
+ <DropdownMenuTrigger asChild disabled={props?.disabled}>
52
+ <div ref={divRef}>
53
+ <ActionMenuButton
54
+ disabled={props?.disabled}
55
+ icon="MenuDown"
56
+ title={active?.title}
57
+ tooltip={`${props?.tooltip}`}
58
+ />
59
+ </div>
60
+ </DropdownMenuTrigger>
61
+
62
+ <DropdownMenuContent
63
+ container={divRef.current as any}
64
+ className="max-h-[40vh] w-32 overflow-y-auto"
65
+ >
66
+ {props?.items?.map((item: any, index) => {
67
+ return (
68
+ <DropdownMenuCheckboxItem
69
+ checked={active.title === item.title}
70
+ key={`font-size-${index}`}
71
+ onClick={item.action}
72
+ >
73
+ <div className="ml-1 h-full">
74
+ {item.title}
75
+ </div>
76
+ </DropdownMenuCheckboxItem>
77
+ );
78
+ })}
79
+ </DropdownMenuContent>
80
+ </DropdownMenu>
81
+ );
82
+ }
83
+
84
+ export default FontSizeMenuButton;
@@ -0,0 +1 @@
1
+ export * from './FontSize';
@@ -0,0 +1,121 @@
1
+ /* eslint-disable prefer-const */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ import { Extension } from '@tiptap/core';
4
+ import type { Mark } from '@tiptap/pm/model';
5
+ import { Plugin, PluginKey } from '@tiptap/pm/state';
6
+
7
+ import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
8
+ import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
9
+
10
+ /**
11
+ * Represents the interface for font size options, extending GeneralOptions.
12
+ */
13
+ export interface FormatPainterOptions extends GeneralOptions<FormatPainterOptions> {}
14
+
15
+ declare module '@tiptap/core' {
16
+ interface Commands<ReturnType> {
17
+ painter: {
18
+ setPainter: (marks: Mark[]) => ReturnType
19
+ }
20
+ }
21
+ }
22
+
23
+ export interface PainterAction {
24
+ type: 'start' | 'end'
25
+ marks: Mark[]
26
+ }
27
+ /**
28
+ * 格式刷
29
+ */
30
+ export const FormatPainter = Extension.create<FormatPainterOptions>({
31
+ name: 'painter',
32
+ addOptions() {
33
+ return {
34
+ ...this.parent?.(),
35
+ button: ({ editor, t }) => ({
36
+ component: ActionButton,
37
+ componentProps: {
38
+ action: () => {
39
+ editor.commands.setPainter(editor?.state.selection.$head.marks() as Mark[]);
40
+ },
41
+ icon: 'PaintRoller',
42
+ tooltip: t('editor.format'),
43
+ },
44
+ }),
45
+ };
46
+ },
47
+ addCommands() {
48
+ return {
49
+ setPainter:
50
+ (marks: Mark[]) =>
51
+ ({
52
+ view: {
53
+ dispatch,
54
+ state: { tr },
55
+ dom,
56
+ },
57
+ }) => {
58
+ const svgCursor
59
+ = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#000" d="M9 22v-6H4V7q0-1.65 1.175-2.825T8 3h12v13h-5v6zM6 10h12V5h-1v4h-2V5h-1v2h-2V5H8q-.825 0-1.412.588T6 7zm0 4h12v-2H6zm0 0v-2z"/></svg>';
60
+ const encodedSvg = encodeURIComponent(svgCursor);
61
+ const cursorUrl = `url("data:image/svg+xml;utf8,${encodedSvg}"), auto`;
62
+
63
+ dom.style.cursor = cursorUrl;
64
+ dispatch(tr.setMeta('painterAction', { type: 'start', marks }));
65
+ return true;
66
+ },
67
+ };
68
+ },
69
+
70
+ addProseMirrorPlugins() {
71
+ return [
72
+ new Plugin({
73
+ key: new PluginKey('format-painter'),
74
+ state: {
75
+ init: () => [] as Mark[],
76
+ apply: (tr, set) => {
77
+ const action = tr.getMeta('painterAction') as PainterAction;
78
+ if (action && action.type === 'start') {
79
+ set = action.marks;
80
+ } else if (action && action.type === 'end') {
81
+ set = [];
82
+ }
83
+ return set;
84
+ },
85
+ },
86
+ props: {
87
+ handleDOMEvents: {
88
+ mousedown(view) {
89
+ const marks = this.getState(view.state) as Mark[];
90
+ if (!marks || marks.length === 0) {
91
+ view.dom.style.cursor = '';
92
+ return false; // 如果没有标记,则不执行任何操作
93
+ }
94
+ const mouseup = () => {
95
+ document.removeEventListener('mouseup', mouseup);
96
+
97
+ let {
98
+ dispatch,
99
+ state: { tr, selection },
100
+ dom,
101
+ } = view as any;
102
+ dom.style.cursor = '';
103
+
104
+ tr = tr.removeMark(selection.from, selection.to);
105
+ for (const mark of marks) {
106
+ if (mark.type.name !== 'link') {
107
+ tr = tr.addMark(selection.from, selection.to, mark);
108
+ }
109
+ }
110
+
111
+ dispatch(tr.setMeta('painterAction', { type: 'end' }));
112
+ };
113
+ document.addEventListener('mouseup', mouseup);
114
+ return true;
115
+ },
116
+ },
117
+ },
118
+ }),
119
+ ];
120
+ },
121
+ });
@@ -0,0 +1 @@
1
+ export * from './FormatPainter';
@@ -0,0 +1,57 @@
1
+ import type { Extension } from '@tiptap/core';
2
+ import type { HeadingOptions as TiptapHeadingOptions } from '@tiptap/extension-heading';
3
+ import { Heading as TiptapHeading } from '@tiptap/extension-heading';
4
+
5
+ import type { BaseKitOptions } from '../BaseKit';
6
+ import HeadingButton from 'reactjs-tiptap-editor-pro/extensions/Heading/components/HeadingButton';
7
+ import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
8
+
9
+ export interface HeadingOptions extends TiptapHeadingOptions, GeneralOptions<HeadingOptions> {}
10
+
11
+ export const Heading = TiptapHeading.extend<HeadingOptions>({
12
+ addOptions() {
13
+ return {
14
+ ...this.parent?.(),
15
+ levels: [1, 2, 3, 4, 5, 6],
16
+ button({ editor, extension, t }) {
17
+ const { extensions = [] } = editor.extensionManager ?? [];
18
+ const levels = extension.options?.levels || [];
19
+ const baseKitExt = extensions.find(
20
+ k => k.name === 'base-kit',
21
+ ) as Extension<BaseKitOptions>;
22
+
23
+ const items: any[] = levels.map(level => ({
24
+ action: () => editor.commands.toggleHeading({ level }),
25
+ isActive: () => editor.isActive('heading', { level }) || false,
26
+ disabled: !editor.can().toggleHeading({ level }),
27
+ title: t(`editor.heading.h${level}.tooltip`),
28
+ level,
29
+ shortcutKeys: ['alt', 'mod', `${level}`],
30
+ }));
31
+
32
+ if (baseKitExt && baseKitExt.options.paragraph !== false) {
33
+ items.unshift({
34
+ action: () => editor.commands.setParagraph(),
35
+ isActive: () => editor.isActive('paragraph') || false,
36
+ disabled: !editor.can().setParagraph(),
37
+ level: 0,
38
+ title: t('editor.paragraph.tooltip'),
39
+ shortcutKeys: ['alt', 'mod', '0'],
40
+ });
41
+ }
42
+
43
+ const disabled = items.filter((k: any) => k.disabled).length === items.length;
44
+
45
+ return {
46
+ component: HeadingButton,
47
+ componentProps: {
48
+ tooltip: t('editor.heading.tooltip'),
49
+ disabled,
50
+ items,
51
+ editor,
52
+ },
53
+ };
54
+ },
55
+ };
56
+ },
57
+ });
@@ -0,0 +1,96 @@
1
+ import React, { Fragment, useMemo } from 'react';
2
+
3
+ import {
4
+ ActionMenuButton,
5
+ DropdownMenu,
6
+ DropdownMenuCheckboxItem,
7
+ DropdownMenuContent,
8
+ DropdownMenuSeparator,
9
+ DropdownMenuShortcut,
10
+ DropdownMenuTrigger,
11
+ } from 'reactjs-tiptap-editor-pro/components';
12
+ import type { ButtonViewReturnComponentProps } from 'reactjs-tiptap-editor-pro/types';
13
+ import { getShortcutKey } from 'reactjs-tiptap-editor-pro/utils/plateform';
14
+
15
+ export interface Item {
16
+ title: string
17
+ icon?: any
18
+ level?: number
19
+ isActive: NonNullable<ButtonViewReturnComponentProps['isActive']>
20
+ action?: ButtonViewReturnComponentProps['action']
21
+ style?: React.CSSProperties
22
+ shortcutKeys?: string[]
23
+ disabled?: boolean
24
+ divider?: boolean
25
+ default?: boolean
26
+ }
27
+
28
+ interface Props {
29
+ editor: any
30
+ disabled?: boolean
31
+ color?: string
32
+ shortcutKeys?: string[]
33
+ maxHeight?: string | number
34
+ tooltip?: string
35
+ items?: Item[]
36
+ }
37
+
38
+ function HeadingButton(props: Props) {
39
+ const active = useMemo(() => {
40
+ const find: any = props?.items?.find((k: any) => k.isActive());
41
+
42
+ if (find && !find.default) {
43
+ return {
44
+ ...find,
45
+ };
46
+ }
47
+ const item: Item = {
48
+ title: props.tooltip as any,
49
+ level: 0,
50
+ isActive: () => false,
51
+ };
52
+ return item;
53
+ }, [props]);
54
+
55
+ return (
56
+ <DropdownMenu>
57
+ <DropdownMenuTrigger asChild
58
+ disabled={props?.disabled}
59
+ >
60
+ <ActionMenuButton
61
+ disabled={props?.disabled}
62
+ icon="MenuDown"
63
+ title={active?.title}
64
+ tooltip={props?.tooltip}
65
+ />
66
+ </DropdownMenuTrigger>
67
+
68
+ <DropdownMenuContent className="w-full">
69
+ {props?.items?.map((item: any, index) => {
70
+ return (
71
+ <Fragment key={`heading-k-${index}`}>
72
+ <DropdownMenuCheckboxItem
73
+ checked={active?.title === item.title}
74
+ onClick={item.action}
75
+ >
76
+ <div className={`heading- ml-1 h-full${item.level}`}>
77
+ {item.title}
78
+ </div>
79
+
80
+ {!!item?.shortcutKeys?.length && (
81
+ <DropdownMenuShortcut className="pl-4">
82
+ {item?.shortcutKeys?.map((item: any) => getShortcutKey(item)).join(' ')}
83
+ </DropdownMenuShortcut>
84
+ )}
85
+ </DropdownMenuCheckboxItem>
86
+
87
+ {item.level === 0 && <DropdownMenuSeparator />}
88
+ </Fragment>
89
+ );
90
+ })}
91
+ </DropdownMenuContent>
92
+ </DropdownMenu>
93
+ );
94
+ }
95
+
96
+ export default HeadingButton;
@@ -0,0 +1 @@
1
+ export * from './Heading';
@@ -0,0 +1,36 @@
1
+ import type { HighlightOptions as TiptapHighlightOptions } from '@tiptap/extension-highlight';
2
+ import { Highlight as TiptapHighlight } from '@tiptap/extension-highlight';
3
+
4
+ import HighlightActionButton from './components/HighlightActionButton';
5
+ import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
6
+
7
+ export interface HighlightOptions
8
+ extends TiptapHighlightOptions,
9
+ GeneralOptions<HighlightOptions> {}
10
+
11
+ export const Highlight = TiptapHighlight.extend<HighlightOptions>({
12
+ addOptions() {
13
+ return {
14
+ ...this.parent?.(),
15
+ multicolor: true,
16
+ button: ({ editor, t }) => ({
17
+ component: HighlightActionButton,
18
+ componentProps: {
19
+ action: (color?: unknown) => {
20
+ if (typeof color === 'string') {
21
+ editor.chain().focus().setHighlight({ color }).run();
22
+ }
23
+ if (color === undefined) {
24
+ editor.chain().focus().unsetHighlight().run();
25
+ }
26
+ },
27
+ editor,
28
+ isActive: () => editor.isActive('highlight') || false,
29
+ disabled: !editor.can().setHighlight(),
30
+ shortcutKeys: ['⇧', 'mod', 'H'],
31
+ tooltip: t('editor.highlight.tooltip'),
32
+ },
33
+ }),
34
+ };
35
+ },
36
+ });