@cyberyozh/text-editor 0.1.1

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 (209) hide show
  1. package/README.md +102 -0
  2. package/dist/editor.css +2069 -0
  3. package/dist/editor.css.map +1 -0
  4. package/dist/editor.d.mts +45 -0
  5. package/dist/editor.d.ts +45 -0
  6. package/dist/editor.js +6155 -0
  7. package/dist/editor.js.map +1 -0
  8. package/dist/editor.mjs +6118 -0
  9. package/dist/editor.mjs.map +1 -0
  10. package/dist/render/client.d.mts +24 -0
  11. package/dist/render/client.d.ts +24 -0
  12. package/dist/render/client.js +98 -0
  13. package/dist/render/client.js.map +1 -0
  14. package/dist/render/client.mjs +74 -0
  15. package/dist/render/client.mjs.map +1 -0
  16. package/dist/render.d.mts +58 -0
  17. package/dist/render.d.ts +58 -0
  18. package/dist/render.js +2521 -0
  19. package/dist/render.js.map +1 -0
  20. package/dist/render.mjs +2484 -0
  21. package/dist/render.mjs.map +1 -0
  22. package/dist/styles/index.css +2068 -0
  23. package/package.json +92 -0
  24. package/src/editor/commands/items.ts +374 -0
  25. package/src/editor/commands/suggestion.tsx +146 -0
  26. package/src/editor/components/button/button.css +56 -0
  27. package/src/editor/components/button/button.tsx +35 -0
  28. package/src/editor/components/button/index.ts +1 -0
  29. package/src/editor/components/common-modal/common-modal.css +85 -0
  30. package/src/editor/components/common-modal/common-modal.tsx +58 -0
  31. package/src/editor/components/common-modal/index.ts +1 -0
  32. package/src/editor/components/index.ts +3 -0
  33. package/src/editor/components/input/index.ts +1 -0
  34. package/src/editor/components/input/input.css +43 -0
  35. package/src/editor/components/input/input.tsx +22 -0
  36. package/src/editor/context/dialog-command.tsx +47 -0
  37. package/src/editor/context/index.ts +2 -0
  38. package/src/editor/context/translations-context.tsx +28 -0
  39. package/src/editor/controls/bubble-menu-content.tsx +394 -0
  40. package/src/editor/controls/callout-menu.tsx +169 -0
  41. package/src/editor/controls/character-count.tsx +36 -0
  42. package/src/editor/controls/commands-list.tsx +117 -0
  43. package/src/editor/controls/drag-handle.tsx +98 -0
  44. package/src/editor/controls/emoji-picker.tsx +62 -0
  45. package/src/editor/controls/index.ts +5 -0
  46. package/src/editor/controls/table-menu.tsx +322 -0
  47. package/src/editor/dialogs/add-katex-dialog/add-katex-dialog.css +115 -0
  48. package/src/editor/dialogs/add-katex-dialog/add-katex-dialog.tsx +116 -0
  49. package/src/editor/dialogs/add-katex-dialog/index.ts +1 -0
  50. package/src/editor/dialogs/add-link-dialog/add-link-dialog.css +105 -0
  51. package/src/editor/dialogs/add-link-dialog/add-link-dialog.tsx +177 -0
  52. package/src/editor/dialogs/add-link-dialog/index.ts +1 -0
  53. package/src/editor/dialogs/add-video-dialog/add-video-dialog.css +146 -0
  54. package/src/editor/dialogs/add-video-dialog/add-video-dialog.tsx +157 -0
  55. package/src/editor/dialogs/add-video-dialog/index.ts +1 -0
  56. package/src/editor/dialogs/image-dialog/image-dialog.css +101 -0
  57. package/src/editor/dialogs/image-dialog/image-dialog.tsx +276 -0
  58. package/src/editor/dialogs/image-dialog/index.ts +1 -0
  59. package/src/editor/dialogs/index.ts +4 -0
  60. package/src/editor/editor.tsx +247 -0
  61. package/src/editor/handlers/create-image-upload-handler.ts +24 -0
  62. package/src/editor/handlers/dialog-handlers.ts +143 -0
  63. package/src/editor/handlers/index.ts +8 -0
  64. package/src/editor/index.ts +3 -0
  65. package/src/extensions/base/callout.ts +138 -0
  66. package/src/extensions/base/code-block.ts +24 -0
  67. package/src/extensions/base/compatibility.ts +493 -0
  68. package/src/extensions/base/copyable-text.ts +56 -0
  69. package/src/extensions/base/custom-quote.ts +174 -0
  70. package/src/extensions/base/figure.ts +141 -0
  71. package/src/extensions/base/index.ts +19 -0
  72. package/src/extensions/base/link.ts +18 -0
  73. package/src/extensions/base/myth-reality.ts +45 -0
  74. package/src/extensions/base/prompt.ts +109 -0
  75. package/src/extensions/base/video.ts +29 -0
  76. package/src/extensions/editor/callout.ts +43 -0
  77. package/src/extensions/editor/code-block.ts +9 -0
  78. package/src/extensions/editor/commands.ts +43 -0
  79. package/src/extensions/editor/copyable-text.ts +16 -0
  80. package/src/extensions/editor/custom-quote.ts +54 -0
  81. package/src/extensions/editor/figure.ts +20 -0
  82. package/src/extensions/editor/get-editor-extensions.ts +113 -0
  83. package/src/extensions/editor/index.ts +25 -0
  84. package/src/extensions/editor/prompt.ts +43 -0
  85. package/src/extensions/editor/video.ts +23 -0
  86. package/src/extensions/render/get-render-extensions.ts +74 -0
  87. package/src/extensions/render/index.ts +6 -0
  88. package/src/extensions/views/components/callout.tsx +70 -0
  89. package/src/extensions/views/components/code-block.tsx +73 -0
  90. package/src/extensions/views/components/copy-button.tsx +52 -0
  91. package/src/extensions/views/components/copyable-text.tsx +11 -0
  92. package/src/extensions/views/components/custom-quote.tsx +64 -0
  93. package/src/extensions/views/components/figure.tsx +63 -0
  94. package/src/extensions/views/components/index.ts +7 -0
  95. package/src/extensions/views/components/prompt.tsx +43 -0
  96. package/src/extensions/views/components/video.tsx +40 -0
  97. package/src/extensions/views/node-views/callout.tsx +51 -0
  98. package/src/extensions/views/node-views/code-block.tsx +30 -0
  99. package/src/extensions/views/node-views/copyable-text.tsx +10 -0
  100. package/src/extensions/views/node-views/custom-quote.tsx +66 -0
  101. package/src/extensions/views/node-views/figure.tsx +38 -0
  102. package/src/extensions/views/node-views/index.ts +7 -0
  103. package/src/extensions/views/node-views/prompt.tsx +35 -0
  104. package/src/extensions/views/node-views/video.tsx +19 -0
  105. package/src/icons/Check.tsx +12 -0
  106. package/src/icons/Copy.tsx +15 -0
  107. package/src/icons/DragIcon.tsx +10 -0
  108. package/src/icons/Edit.tsx +12 -0
  109. package/src/icons/Quote.tsx +10 -0
  110. package/src/icons/X.tsx +13 -0
  111. package/src/icons/color/TiptapCalloutError.tsx +25 -0
  112. package/src/icons/color/TiptapCalloutInfo.tsx +18 -0
  113. package/src/icons/color/TiptapCalloutSuccess.tsx +49 -0
  114. package/src/icons/color/TiptapCalloutWarning.tsx +28 -0
  115. package/src/icons/color/index.ts +4 -0
  116. package/src/icons/index.ts +60 -0
  117. package/src/icons/menu/AddImage.tsx +10 -0
  118. package/src/icons/menu/AlignCenter.tsx +10 -0
  119. package/src/icons/menu/AlignLeft.tsx +10 -0
  120. package/src/icons/menu/AlignRight.tsx +10 -0
  121. package/src/icons/menu/ArrowDown.tsx +13 -0
  122. package/src/icons/menu/ArrowLeft.tsx +13 -0
  123. package/src/icons/menu/ArrowRight.tsx +13 -0
  124. package/src/icons/menu/ArrowUp.tsx +13 -0
  125. package/src/icons/menu/Blockquote.tsx +7 -0
  126. package/src/icons/menu/Bold.tsx +10 -0
  127. package/src/icons/menu/BulletList.tsx +10 -0
  128. package/src/icons/menu/CalloutError.tsx +10 -0
  129. package/src/icons/menu/CalloutInfo.tsx +12 -0
  130. package/src/icons/menu/CalloutSuccess.tsx +10 -0
  131. package/src/icons/menu/CalloutWarning.tsx +12 -0
  132. package/src/icons/menu/ClearFormatting.tsx +10 -0
  133. package/src/icons/menu/Code.tsx +10 -0
  134. package/src/icons/menu/CodeBlock.tsx +10 -0
  135. package/src/icons/menu/Copyable.tsx +10 -0
  136. package/src/icons/menu/CustomQuote.tsx +17 -0
  137. package/src/icons/menu/DeleteColumn.tsx +17 -0
  138. package/src/icons/menu/DeleteRow.tsx +17 -0
  139. package/src/icons/menu/Details.tsx +10 -0
  140. package/src/icons/menu/H2.tsx +10 -0
  141. package/src/icons/menu/H3.tsx +10 -0
  142. package/src/icons/menu/H4.tsx +10 -0
  143. package/src/icons/menu/H5.tsx +10 -0
  144. package/src/icons/menu/H6.tsx +10 -0
  145. package/src/icons/menu/Highlight.tsx +13 -0
  146. package/src/icons/menu/HorizontalRule.tsx +7 -0
  147. package/src/icons/menu/Italic.tsx +10 -0
  148. package/src/icons/menu/Link.tsx +10 -0
  149. package/src/icons/menu/LinkOff.tsx +10 -0
  150. package/src/icons/menu/Math.tsx +10 -0
  151. package/src/icons/menu/MergeCells.tsx +10 -0
  152. package/src/icons/menu/MythReality.tsx +10 -0
  153. package/src/icons/menu/OrderedList.tsx +10 -0
  154. package/src/icons/menu/Prompt.tsx +18 -0
  155. package/src/icons/menu/Redo.tsx +14 -0
  156. package/src/icons/menu/SplitCells.tsx +7 -0
  157. package/src/icons/menu/Strikethrough.tsx +10 -0
  158. package/src/icons/menu/Subscript.tsx +10 -0
  159. package/src/icons/menu/Superscript.tsx +10 -0
  160. package/src/icons/menu/Table.tsx +14 -0
  161. package/src/icons/menu/TableColumnHeading.tsx +7 -0
  162. package/src/icons/menu/TableRowHeading.tsx +10 -0
  163. package/src/icons/menu/TextColor.tsx +13 -0
  164. package/src/icons/menu/Underline.tsx +10 -0
  165. package/src/icons/menu/Undo.tsx +14 -0
  166. package/src/icons/menu/Video.tsx +14 -0
  167. package/src/icons/menu/index.ts +49 -0
  168. package/src/render/index.ts +22 -0
  169. package/src/render/static-renderer-config.tsx +206 -0
  170. package/src/render/tiptap-interactivity-provider.tsx +78 -0
  171. package/src/render/tiptap-render.tsx +102 -0
  172. package/src/styles/components.css +10 -0
  173. package/src/styles/editor/base.css +39 -0
  174. package/src/styles/editor/callout-menu.css +81 -0
  175. package/src/styles/editor/controls.css +57 -0
  176. package/src/styles/editor/emoji-picker.css +113 -0
  177. package/src/styles/editor/index.css +9 -0
  178. package/src/styles/editor/menus.css +16 -0
  179. package/src/styles/editor/states.css +43 -0
  180. package/src/styles/editor/typography.css +165 -0
  181. package/src/styles/editor/utilities.css +71 -0
  182. package/src/styles/editor/variables.css +70 -0
  183. package/src/styles/extensions/callout.css +155 -0
  184. package/src/styles/extensions/code-block.css +109 -0
  185. package/src/styles/extensions/commands-list.css +83 -0
  186. package/src/styles/extensions/custom-quote.css +103 -0
  187. package/src/styles/extensions/details.css +87 -0
  188. package/src/styles/extensions/figure.css +66 -0
  189. package/src/styles/extensions/index.css +11 -0
  190. package/src/styles/extensions/math.css +32 -0
  191. package/src/styles/extensions/myth-reality.css +59 -0
  192. package/src/styles/extensions/prompt.css +75 -0
  193. package/src/styles/extensions/table.css +253 -0
  194. package/src/styles/extensions/video.css +53 -0
  195. package/src/styles/styles.css +3 -0
  196. package/src/translations/en.json +158 -0
  197. package/src/translations/ru.json +158 -0
  198. package/src/types/image-handler.ts +33 -0
  199. package/src/types/index.ts +1 -0
  200. package/src/utils/copy-to-clipboard.ts +23 -0
  201. package/src/utils/custom-emoji.ts +174 -0
  202. package/src/utils/detect-video-hosting.ts +106 -0
  203. package/src/utils/get-shared-extensions.ts +45 -0
  204. package/src/utils/get-translations.ts +25 -0
  205. package/src/utils/handle-exit-node.ts +61 -0
  206. package/src/utils/image-src-resolver.ts +74 -0
  207. package/src/utils/index.ts +2 -0
  208. package/src/utils/migrate-legacy-callouts.ts +59 -0
  209. package/src/utils/pluralize.ts +38 -0
@@ -0,0 +1,85 @@
1
+ .modal-overlay {
2
+ display: flex;
3
+ z-index: 10000;
4
+ position: fixed;
5
+ top: 0;
6
+ right: 0;
7
+ bottom: 0;
8
+ left: 0;
9
+ align-items: center;
10
+ justify-content: center;
11
+ margin: 0 !important;
12
+ background-color: rgba(0, 0, 0, 0.5);
13
+ animation: modal-fadeIn 0.2s ease-out;
14
+ }
15
+
16
+ @keyframes modal-fadeIn {
17
+ from {
18
+ opacity: 0;
19
+ }
20
+ to {
21
+ opacity: 1;
22
+ }
23
+ }
24
+
25
+ .modal-content {
26
+ position: relative;
27
+ width: 100%;
28
+ max-width: 500px;
29
+ max-height: 90vh;
30
+ overflow: auto;
31
+ border-radius: 8px;
32
+ background-color: var(--ui-text-white);
33
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
34
+ animation: modal-slideIn 0.2s ease-out;
35
+ }
36
+
37
+ @keyframes modal-slideIn {
38
+ from {
39
+ transform: scale(0.95);
40
+ opacity: 0;
41
+ }
42
+ to {
43
+ transform: scale(1);
44
+ opacity: 1;
45
+ }
46
+ }
47
+
48
+ .modal-close-button {
49
+ display: flex;
50
+ z-index: 1001;
51
+ position: absolute;
52
+ top: 16px;
53
+ right: 16px;
54
+ align-items: center;
55
+ justify-content: center;
56
+ width: 32px;
57
+ height: 32px;
58
+ padding: 0;
59
+ border: none;
60
+ border-radius: 8px;
61
+ background-color: transparent;
62
+ color: var(--ui-text-secondary);
63
+ font-size: 24px;
64
+ line-height: 1;
65
+ cursor: pointer;
66
+ transition: all 0.2s ease-out;
67
+ }
68
+
69
+ .modal-close-button svg {
70
+ width: 20px;
71
+ height: 20px;
72
+ }
73
+
74
+ .modal-close-button:hover {
75
+ background-color: var(--ui-secondary-bg);
76
+ color: var(--ui-text-primary);
77
+ }
78
+
79
+ .modal-close-button:active {
80
+ background-color: var(--ui-secondary-bg-hover);
81
+ }
82
+
83
+ .modal-inner-content {
84
+ padding: 24px;
85
+ }
@@ -0,0 +1,58 @@
1
+ "use client";
2
+
3
+ import { useEffect, ReactNode } from "react";
4
+
5
+ import { TiptapX } from "../../../icons";
6
+
7
+ interface CommonModalProps {
8
+ open: boolean;
9
+ handleClose: () => void;
10
+ children: ReactNode;
11
+ }
12
+
13
+ export const CommonModal = ({ open, handleClose, children }: CommonModalProps) => {
14
+ useEffect(() => {
15
+ if (!open) return;
16
+
17
+ const handleEscapeKey = (event: KeyboardEvent) => {
18
+ if (event.key === "Escape") {
19
+ handleClose();
20
+ }
21
+ };
22
+
23
+ document.addEventListener("keydown", handleEscapeKey);
24
+ document.body.style.overflow = "hidden";
25
+
26
+ return () => {
27
+ document.removeEventListener("keydown", handleEscapeKey);
28
+ document.body.style.overflow = "unset";
29
+ };
30
+ }, [open, handleClose]);
31
+
32
+ if (!open) return null;
33
+
34
+ const handleOverlayClick = (e: React.MouseEvent) => {
35
+ if (e.target === e.currentTarget) {
36
+ handleClose();
37
+ }
38
+ };
39
+
40
+ return (
41
+ <div
42
+ className="modal-overlay"
43
+ onClick={handleOverlayClick}
44
+ >
45
+ <div className="modal-content">
46
+ <button
47
+ type="button"
48
+ className="modal-close-button"
49
+ onClick={handleClose}
50
+ aria-label="Close modal"
51
+ >
52
+ <TiptapX />
53
+ </button>
54
+ <div className="modal-inner-content">{children}</div>
55
+ </div>
56
+ </div>
57
+ );
58
+ };
@@ -0,0 +1 @@
1
+ export { CommonModal } from './common-modal';
@@ -0,0 +1,3 @@
1
+ export { Button } from './button';
2
+ export { Input } from './input';
3
+ export { CommonModal } from './common-modal';
@@ -0,0 +1 @@
1
+ export { Input } from './input';
@@ -0,0 +1,43 @@
1
+ /* ═══════════════════════════════════════════════════════════ */
2
+ /* INPUT COMPONENT */
3
+ /* ═══════════════════════════════════════════════════════════ */
4
+
5
+ .input-wrapper {
6
+ display: flex;
7
+ flex-direction: column;
8
+ margin-bottom: 12px;
9
+ gap: 4px;
10
+ }
11
+
12
+ .input-label {
13
+ color: var(--ui-text-primary);
14
+ font-weight: 500;
15
+ font-size: 14px;
16
+ }
17
+
18
+ .input-field {
19
+ padding: 8px 12px;
20
+ border: 1px solid var(--ui-secondary-bg-hover);
21
+ border-radius: 4px;
22
+ font-size: 14px;
23
+ font-family: inherit;
24
+ transition: all 0.2s ease-out;
25
+ }
26
+
27
+ .input-field:focus {
28
+ border-color: var(--ui-color-primary);
29
+ outline: none;
30
+ box-shadow: var(--ui-shadow-primary);
31
+ }
32
+
33
+ .input-field:disabled {
34
+ background-color: var(--ui-secondary-bg);
35
+ color: var(--ui-text-disabled);
36
+ cursor: not-allowed;
37
+ }
38
+
39
+ .input-error {
40
+ margin-top: 4px;
41
+ color: var(--ui-error-text-simple);
42
+ font-size: 12px;
43
+ }
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+
3
+ import { InputHTMLAttributes, forwardRef } from 'react';
4
+
5
+ interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
6
+ label?: string;
7
+ error?: string;
8
+ }
9
+
10
+ export const Input = forwardRef<HTMLInputElement, InputProps>(
11
+ ({ label, error, className, ...props }, ref) => {
12
+ return (
13
+ <div className="input-wrapper">
14
+ {label && <label className="input-label">{label}</label>}
15
+ <input ref={ref} className={`input-field ${className || ''}`} {...props} />
16
+ {error && <span className="input-error">{error}</span>}
17
+ </div>
18
+ );
19
+ }
20
+ );
21
+
22
+ Input.displayName = 'Input';
@@ -0,0 +1,47 @@
1
+ "use client";
2
+
3
+ import { createContext, useContext, useState, ReactNode } from "react";
4
+
5
+ import type { Editor } from "@tiptap/react";
6
+
7
+ export type DialogCommandType = "image" | "video" | "link" | "katex";
8
+
9
+ interface DialogCommandContextType {
10
+ activeDialog: DialogCommandType | null;
11
+ openDialogCommand: (command: DialogCommandType) => void;
12
+ closeDialogCommand: () => void;
13
+ }
14
+
15
+ const DialogCommandContext = createContext<DialogCommandContextType | undefined>(undefined);
16
+
17
+ export function DialogCommandProvider({ children }: { children: ReactNode }) {
18
+ const [activeDialog, setActiveDialog] = useState<DialogCommandType | null>(null);
19
+
20
+ const openDialogCommand = (command: DialogCommandType) => {
21
+ setActiveDialog(command);
22
+ };
23
+
24
+ const closeDialogCommand = () => {
25
+ setActiveDialog(null);
26
+ };
27
+
28
+ return (
29
+ <DialogCommandContext.Provider
30
+ value={{
31
+ activeDialog,
32
+ openDialogCommand,
33
+ closeDialogCommand,
34
+ }}
35
+ >
36
+ {children}
37
+ </DialogCommandContext.Provider>
38
+ );
39
+ }
40
+
41
+ export function useDialogCommand() {
42
+ const context = useContext(DialogCommandContext);
43
+ if (!context) {
44
+ throw new Error("useDialogCommand must be used within DialogCommandProvider");
45
+ }
46
+ return context;
47
+ }
@@ -0,0 +1,2 @@
1
+ export { DialogCommandProvider, useDialogCommand } from './dialog-command';
2
+ export { TiptapTranslationsProvider, useTiptapTranslations } from './translations-context';
@@ -0,0 +1,28 @@
1
+ import React, { createContext, useContext } from "react";
2
+ import type { TiptapTranslations } from "@/utils/get-translations";
3
+
4
+ const TiptapTranslationsContext = createContext<TiptapTranslations | undefined>(undefined);
5
+
6
+ interface TiptapTranslationsProviderProps {
7
+ translations: TiptapTranslations;
8
+ children: React.ReactNode;
9
+ }
10
+
11
+ export const TiptapTranslationsProvider = ({
12
+ translations,
13
+ children,
14
+ }: TiptapTranslationsProviderProps) => {
15
+ return (
16
+ <TiptapTranslationsContext.Provider value={translations}>
17
+ {children}
18
+ </TiptapTranslationsContext.Provider>
19
+ );
20
+ };
21
+
22
+ export const useTiptapTranslations = () => {
23
+ const context = useContext(TiptapTranslationsContext);
24
+ if (!context) {
25
+ throw new Error("useTiptapTranslations must be used within TiptapTranslationsProvider");
26
+ }
27
+ return context;
28
+ };
@@ -0,0 +1,394 @@
1
+ import { useRef } from "react";
2
+
3
+ import { useEditorState, type Editor } from "@tiptap/react";
4
+
5
+ import {
6
+ TiptapMenuLink,
7
+ TiptapMenuLinkOff,
8
+ TiptapMenuAlignCenter,
9
+ TiptapMenuAlignLeft,
10
+ TiptapMenuAlignRight,
11
+ TiptapMenuBold,
12
+ TiptapMenuClearFormatting,
13
+ TiptapMenuCopyable,
14
+ TiptapMenuH2,
15
+ TiptapMenuH3,
16
+ TiptapMenuH4,
17
+ TiptapMenuH5,
18
+ TiptapMenuH6,
19
+ TiptapMenuHighlight,
20
+ TiptapMenuItalic,
21
+ TiptapMenuRedo,
22
+ TiptapMenuStrikethrough,
23
+ TiptapMenuSubscript,
24
+ TiptapMenuSuperscript,
25
+ TiptapMenuTextColor,
26
+ TiptapMenuUnderline,
27
+ TiptapMenuUndo,
28
+ TiptapMenuMergeCells,
29
+ TiptapMenuSplitCells,
30
+ } from "../../icons";
31
+
32
+ import { useDialogCommand } from "../context/dialog-command";
33
+ import { useTiptapTranslations } from "../context";
34
+
35
+ interface Props {
36
+ editor: Editor;
37
+ onLinkClick?: (selectedText: string, url?: string) => void;
38
+ }
39
+
40
+ export const BubbleMenuContent = ({ editor, onLinkClick }: Props) => {
41
+ const translations = useTiptapTranslations();
42
+ const textColorInputRef = useRef<HTMLInputElement>(null);
43
+ const highlightColorInputRef = useRef<HTMLInputElement>(null);
44
+ const { openDialogCommand } = useDialogCommand();
45
+ const {
46
+ canUndo,
47
+ canRedo,
48
+ isHeading2,
49
+ isHeading3,
50
+ isHeading4,
51
+ isHeading5,
52
+ isHeading6,
53
+ isBold,
54
+ isItalic,
55
+ isStrikethrough,
56
+ isUnderline,
57
+ isTextAlignLeft,
58
+ isTextAlignCenter,
59
+ isTextAlignRight,
60
+ isSuperscript,
61
+ isSubscript,
62
+ canClearMarks,
63
+ isLink,
64
+ isCopyable,
65
+ textColor,
66
+ highlightColor,
67
+ isTable,
68
+ } = useEditorState({
69
+ editor,
70
+ selector: (ctx) => {
71
+ if (!editor) return {};
72
+ return {
73
+ canUndo: ctx.editor.can().undo(),
74
+ canRedo: ctx.editor.can().redo(),
75
+ canClearMarks: ctx.editor.can().unsetAllMarks(),
76
+ isHeading2: ctx.editor.isActive("heading", { level: 2 }),
77
+ isHeading3: ctx.editor.isActive("heading", { level: 3 }),
78
+ isHeading4: ctx.editor.isActive("heading", { level: 4 }),
79
+ isHeading5: ctx.editor.isActive("heading", { level: 5 }),
80
+ isHeading6: ctx.editor.isActive("heading", { level: 6 }),
81
+ isBold: ctx.editor.isActive("bold"),
82
+ isItalic: ctx.editor.isActive("italic"),
83
+ isStrikethrough: ctx.editor.isActive("strike"),
84
+ isUnderline: ctx.editor.isActive("underline"),
85
+ isTextAlignLeft: ctx.editor.isActive({ textAlign: "left" }),
86
+ isTextAlignCenter: ctx.editor.isActive({ textAlign: "center" }),
87
+ isTextAlignRight: ctx.editor.isActive({ textAlign: "right" }),
88
+ isSuperscript: ctx.editor.isActive("superscript"),
89
+ isSubscript: ctx.editor.isActive("subscript"),
90
+ isLink: ctx.editor.isActive("link"),
91
+ isCopyable: ctx.editor.isActive("copyable-text"),
92
+ textColor: ctx.editor.getAttributes("textStyle").color || "",
93
+ highlightColor: ctx.editor.getAttributes("highlight").color || "",
94
+ isTable: ctx.editor.isActive("table"),
95
+ };
96
+ },
97
+ });
98
+
99
+ const handleLinkClick = () => {
100
+ const selectedText = editor.state.doc.textBetween(
101
+ editor.state.selection.$from.pos,
102
+ editor.state.selection.$to.pos
103
+ );
104
+
105
+ let linkUrl: string | undefined;
106
+ if (isLink) {
107
+ const link = editor.getAttributes("link");
108
+ linkUrl = link.href;
109
+ }
110
+
111
+ onLinkClick?.(selectedText, linkUrl);
112
+ openDialogCommand("link");
113
+ };
114
+
115
+ return (
116
+ <div className={`bubble-menu ${textColor || highlightColor ? "hide-text-selection" : ""}`}>
117
+ <div className="tiptap-controls-group">
118
+ <button
119
+ className="tiptap-control-button"
120
+ onClick={() => editor.chain().focus().undo().run()}
121
+ disabled={!canUndo}
122
+ title={translations.history.undo}
123
+ type="button"
124
+ >
125
+ <TiptapMenuUndo />
126
+ </button>
127
+ <button
128
+ className="tiptap-control-button"
129
+ onClick={() => editor.chain().focus().redo().run()}
130
+ disabled={!canRedo}
131
+ type="button"
132
+ title={translations.history.redo}
133
+ >
134
+ <TiptapMenuRedo />
135
+ </button>
136
+ </div>
137
+
138
+ <div className="tiptap-controls-group">
139
+ <button
140
+ type="button"
141
+ title={translations.headings.h2}
142
+ onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
143
+ className={`tiptap-control-button ${isHeading2 ? "is-active" : ""}`}
144
+ >
145
+ <TiptapMenuH2 />
146
+ </button>
147
+ <button
148
+ type="button"
149
+ title={translations.headings.h3}
150
+ onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
151
+ className={`tiptap-control-button ${isHeading3 ? "is-active" : ""}`}
152
+ >
153
+ <TiptapMenuH3 />
154
+ </button>
155
+ <button
156
+ type="button"
157
+ title={translations.headings.h4}
158
+ onClick={() => editor.chain().focus().toggleHeading({ level: 4 }).run()}
159
+ className={`tiptap-control-button ${isHeading4 ? "is-active" : ""}`}
160
+ >
161
+ <TiptapMenuH4 />
162
+ </button>
163
+ <button
164
+ type="button"
165
+ title={translations.headings.h5}
166
+ onClick={() => editor.chain().focus().toggleHeading({ level: 5 }).run()}
167
+ className={`tiptap-control-button ${isHeading5 ? "is-active" : ""}`}
168
+ >
169
+ <TiptapMenuH5 />
170
+ </button>
171
+ <button
172
+ type="button"
173
+ title={translations.headings.h6}
174
+ onClick={() => editor.chain().focus().toggleHeading({ level: 6 }).run()}
175
+ className={`tiptap-control-button ${isHeading6 ? "is-active" : ""}`}
176
+ >
177
+ <TiptapMenuH6 />
178
+ </button>
179
+ </div>
180
+
181
+ <div className="tiptap-controls-group">
182
+ <button
183
+ onClick={() => editor.chain().focus().toggleBold().run()}
184
+ className={`${isBold ? "is-active" : ""} tiptap-control-button`}
185
+ title={translations.textFormatting.bold}
186
+ type="button"
187
+ >
188
+ <TiptapMenuBold />
189
+ </button>
190
+ <button
191
+ onClick={() => editor.chain().focus().toggleItalic().run()}
192
+ className={`${isItalic ? "is-active" : ""} tiptap-control-button`}
193
+ title={translations.textFormatting.italic}
194
+ type="button"
195
+ >
196
+ <TiptapMenuItalic />
197
+ </button>
198
+ <button
199
+ onClick={() => editor.chain().focus().toggleUnderline().run()}
200
+ className={`${isUnderline ? "is-active" : ""} tiptap-control-button`}
201
+ title={translations.textFormatting.underline}
202
+ type="button"
203
+ >
204
+ <TiptapMenuUnderline />
205
+ </button>
206
+ <button
207
+ onClick={() => editor.chain().focus().toggleStrike().run()}
208
+ className={`${isStrikethrough ? "is-active" : ""} tiptap-control-button`}
209
+ title={translations.textFormatting.strikethrough}
210
+ type="button"
211
+ >
212
+ <TiptapMenuStrikethrough />
213
+ </button>
214
+ </div>
215
+
216
+ {isTable && (
217
+ <div className="tiptap-controls-group">
218
+ <button
219
+ className="tiptap-control-button"
220
+ type="button"
221
+ title={translations.table.mergeCells}
222
+ onClick={() => editor.chain().focus().mergeCells().run()}
223
+ >
224
+ <TiptapMenuMergeCells />
225
+ </button>
226
+ <button
227
+ className="tiptap-control-button"
228
+ type="button"
229
+ title={translations.table.splitCell}
230
+ onClick={() => editor.chain().focus().splitCell().run()}
231
+ >
232
+ <TiptapMenuSplitCells />
233
+ </button>
234
+ </div>
235
+ )}
236
+
237
+ <div className="tiptap-controls-group">
238
+ <div style={{ position: "relative" }}>
239
+ <button
240
+ onClick={() => {
241
+ textColorInputRef.current?.click();
242
+ }}
243
+ className="tiptap-control-button"
244
+ type="button"
245
+ title={translations.textFormatting.textColor}
246
+ style={{ color: textColor }}
247
+ >
248
+ <TiptapMenuTextColor />
249
+ </button>
250
+ <input
251
+ ref={textColorInputRef}
252
+ type="color"
253
+ value={textColor}
254
+ onChange={(e) => {
255
+ editor.chain().focus().setColor(e.target.value).run();
256
+ }}
257
+ style={{
258
+ position: "absolute",
259
+ top: 0,
260
+ left: 0,
261
+ width: "100%",
262
+ height: "100%",
263
+ opacity: 0,
264
+ pointerEvents: "none",
265
+ }}
266
+ />
267
+ </div>
268
+ <div style={{ position: "relative" }}>
269
+ <button
270
+ onClick={() => {
271
+ highlightColorInputRef.current?.click();
272
+ }}
273
+ className="tiptap-control-button"
274
+ type="button"
275
+ title={translations.textFormatting.highlightColor}
276
+ style={{ color: highlightColor }}
277
+ >
278
+ <TiptapMenuHighlight />
279
+ </button>
280
+ <input
281
+ ref={highlightColorInputRef}
282
+ type="color"
283
+ value={highlightColor}
284
+ onChange={(e) => {
285
+ editor.chain().focus().setHighlight({ color: e.target.value }).run();
286
+ }}
287
+ style={{
288
+ position: "absolute",
289
+ top: 0,
290
+ left: 0,
291
+ width: "100%",
292
+ height: "100%",
293
+ opacity: 0,
294
+ pointerEvents: "none",
295
+ }}
296
+ />
297
+ </div>
298
+ </div>
299
+
300
+ <div className="tiptap-controls-group">
301
+ <button
302
+ type="button"
303
+ onClick={() => editor.chain().focus().toggleCopyable().run()}
304
+ className={`${isCopyable ? "is-active" : ""} tiptap-control-button`}
305
+ title={translations.textFormatting.copyableText}
306
+ >
307
+ <TiptapMenuCopyable />
308
+ </button>
309
+ </div>
310
+
311
+ <div className="tiptap-controls-group">
312
+ <button
313
+ title={isLink ? translations.link.editLink : translations.link.addLinkTitle}
314
+ onClick={handleLinkClick}
315
+ className={`${isLink ? "is-active" : ""} tiptap-control-button`}
316
+ type="button"
317
+ >
318
+ <TiptapMenuLink />
319
+ </button>
320
+ {isLink && (
321
+ <button
322
+ onClick={() => editor.chain().focus().unsetLink().run()}
323
+ className="tiptap-control-button tiptap-control-button--delete"
324
+ type="button"
325
+ title={translations.link.removeLinkTitle}
326
+ >
327
+ <TiptapMenuLinkOff />
328
+ </button>
329
+ )}
330
+ </div>
331
+
332
+ <div className="tiptap-controls-group">
333
+ <button
334
+ onClick={() => editor.chain().focus().setTextAlign("left").run()}
335
+ className={`${isTextAlignLeft ? "is-active" : ""} tiptap-control-button`}
336
+ title={translations.alignment.alignLeft}
337
+ type="button"
338
+ >
339
+ <TiptapMenuAlignLeft />
340
+ </button>
341
+ <button
342
+ onClick={() => editor.chain().focus().setTextAlign("center").run()}
343
+ className={`${isTextAlignCenter ? "is-active" : ""} tiptap-control-button`}
344
+ title={translations.alignment.alignCenter}
345
+ type="button"
346
+ >
347
+ <TiptapMenuAlignCenter />
348
+ </button>
349
+ <button
350
+ onClick={() => editor.chain().focus().setTextAlign("right").run()}
351
+ className={`${isTextAlignRight ? "is-active" : ""} tiptap-control-button`}
352
+ title={translations.alignment.alignRight}
353
+ type="button"
354
+ >
355
+ <TiptapMenuAlignRight />
356
+ </button>
357
+ </div>
358
+
359
+ <div className="tiptap-controls-group">
360
+ <button
361
+ type="button"
362
+ onClick={() => editor.chain().focus().toggleSuperscript().run()}
363
+ className={`${isSuperscript ? "is-active" : ""} tiptap-control-button`}
364
+ title={translations.textFormatting.superscript}
365
+ >
366
+ <TiptapMenuSuperscript />
367
+ </button>
368
+ <button
369
+ type="button"
370
+ onClick={() => editor.chain().focus().toggleSubscript().run()}
371
+ className={`${isSubscript ? "is-active" : ""} tiptap-control-button`}
372
+ title={translations.textFormatting.subscript}
373
+ >
374
+ <TiptapMenuSubscript />
375
+ </button>
376
+ </div>
377
+
378
+ <div className="tiptap-controls-group">
379
+ <button
380
+ type="button"
381
+ onClick={() => {
382
+ editor.chain().focus().clearNodes().run();
383
+ editor.chain().focus().unsetAllMarks().run();
384
+ }}
385
+ disabled={!canClearMarks}
386
+ className="tiptap-control-button"
387
+ title={translations.textFormatting.clearFormatting}
388
+ >
389
+ <TiptapMenuClearFormatting />
390
+ </button>
391
+ </div>
392
+ </div>
393
+ );
394
+ };