@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,177 @@
1
+ "use client";
2
+
3
+ import { ChangeEvent, useEffect, useRef, useState } from "react";
4
+
5
+ import { CommonModal } from "../../components";
6
+ import { useTiptapTranslations } from "../../context";
7
+
8
+ interface AddLinkDialogProps {
9
+ open: boolean;
10
+ onClose: () => void;
11
+ onLinkAdd: (title: string, url: string) => void;
12
+ initialTitle?: string;
13
+ initialUrl?: string;
14
+ }
15
+
16
+ export const AddLinkDialog = ({
17
+ open,
18
+ onClose,
19
+ onLinkAdd,
20
+ initialTitle = "",
21
+ initialUrl = "",
22
+ }: AddLinkDialogProps) => {
23
+ const translations = useTiptapTranslations();
24
+ const [title, setTitle] = useState(initialTitle);
25
+ const [url, setUrl] = useState(initialUrl);
26
+ const [error, setError] = useState<string>("");
27
+ const titleInputRef = useRef<HTMLInputElement>(null);
28
+
29
+ useEffect(() => {
30
+ if (open) {
31
+ setTitle(initialTitle);
32
+ setUrl(initialUrl);
33
+ setError("");
34
+ // Focus the first input after modal opens
35
+ setTimeout(() => {
36
+ titleInputRef.current?.focus();
37
+ }, 0);
38
+ }
39
+ }, [open, initialTitle, initialUrl]);
40
+
41
+ const validateUrl = (urlStr: string): boolean => {
42
+ if (!urlStr.trim()) {
43
+ setError(translations.link.emptyUrl);
44
+ return false;
45
+ }
46
+
47
+ // Check if URL has a protocol (mailto:, tel:, http:, https:, etc)
48
+ const hasProtocol =
49
+ urlStr.includes("://") || urlStr.startsWith("mailto:") || urlStr.startsWith("tel:");
50
+
51
+ // Only validate hostname for web URLs (http/https)
52
+ if (!hasProtocol || urlStr.startsWith("http")) {
53
+ try {
54
+ const urlWithProtocol = urlStr.startsWith("http") ? urlStr : `https://${urlStr}`;
55
+ const url = new URL(urlWithProtocol);
56
+
57
+ // Validate hostname has proper structure (contains . or is localhost)
58
+ const hostname = url.hostname;
59
+ if (!hostname.includes(".") && hostname !== "localhost") {
60
+ setError(translations.link.invalidUrl);
61
+ return false;
62
+ }
63
+
64
+ return true;
65
+ } catch {
66
+ setError(translations.link.invalidUrl);
67
+ return false;
68
+ }
69
+ }
70
+
71
+ // For non-web protocols (mailto, tel, etc), just validate basic format
72
+ return true;
73
+ };
74
+
75
+ const handleSubmit = () => {
76
+ setError("");
77
+
78
+ if (!title.trim()) {
79
+ setError(translations.link.titleError);
80
+ return;
81
+ }
82
+
83
+ if (!validateUrl(url)) {
84
+ return;
85
+ }
86
+
87
+ // Preserve protocols like mailto:, tel:, etc; only add https for plain URLs
88
+ const hasProtocol = url.includes("://") || url.startsWith("mailto:") || url.startsWith("tel:");
89
+ const finalUrl = hasProtocol ? url : `https://${url}`;
90
+ onLinkAdd(title, finalUrl);
91
+ handleClose();
92
+ };
93
+
94
+ const handleClose = () => {
95
+ setTitle(initialTitle);
96
+ setUrl(initialUrl);
97
+ setError("");
98
+ onClose();
99
+ };
100
+
101
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
102
+ if (e.key === "Enter") {
103
+ e.preventDefault();
104
+ handleSubmit();
105
+ }
106
+ };
107
+
108
+ return (
109
+ <CommonModal
110
+ open={open}
111
+ handleClose={handleClose}
112
+ >
113
+ <p className="link-dialog-title">
114
+ {initialUrl ? translations.link.editLink : translations.link.addLink}
115
+ </p>
116
+ <hr className="link-dialog-divider" />
117
+
118
+ <div className="link-dialog-content">
119
+ <div className="link-dialog-form-group">
120
+ <label
121
+ htmlFor="link-title"
122
+ className="link-dialog-label"
123
+ >
124
+ {translations.link.title}
125
+ </label>
126
+ <input
127
+ ref={titleInputRef}
128
+ id="link-title"
129
+ type="text"
130
+ className="link-dialog-input"
131
+ placeholder={translations.link.titlePlaceholder}
132
+ value={title}
133
+ onChange={(e: ChangeEvent<HTMLInputElement>) => setTitle(e.target.value)}
134
+ onKeyDown={handleKeyDown}
135
+ />
136
+ </div>
137
+
138
+ <div className="link-dialog-form-group">
139
+ <label
140
+ htmlFor="link-url"
141
+ className="link-dialog-label"
142
+ >
143
+ {translations.link.url}
144
+ </label>
145
+ <input
146
+ id="link-url"
147
+ type="text"
148
+ className="link-dialog-input"
149
+ placeholder={translations.link.urlPlaceholder}
150
+ value={url}
151
+ onChange={(e: ChangeEvent<HTMLInputElement>) => setUrl(e.target.value)}
152
+ onKeyDown={handleKeyDown}
153
+ />
154
+ </div>
155
+
156
+ {error && <div className="link-dialog-error">{error}</div>}
157
+ </div>
158
+
159
+ <div className="link-dialog-actions">
160
+ <button
161
+ className="link-dialog-button-cancel"
162
+ onClick={handleClose}
163
+ type="button"
164
+ >
165
+ {translations.common.cancel}
166
+ </button>
167
+ <button
168
+ className="link-dialog-button-submit"
169
+ onClick={handleSubmit}
170
+ type="button"
171
+ >
172
+ {initialUrl ? translations.link.editLink : translations.link.addLink}
173
+ </button>
174
+ </div>
175
+ </CommonModal>
176
+ );
177
+ };
@@ -0,0 +1 @@
1
+ export { AddLinkDialog } from './add-link-dialog';
@@ -0,0 +1,146 @@
1
+ /* ═══════════════════════════════════════════════════════════ */
2
+ /* ADD VIDEO DIALOG */
3
+ /* ═══════════════════════════════════════════════════════════ */
4
+
5
+ .video-dialog-title {
6
+ margin: 0 0 16px 0;
7
+ font-weight: 600;
8
+ font-size: 16px;
9
+ }
10
+
11
+ .video-dialog-divider {
12
+ margin-bottom: 16px;
13
+ border: none;
14
+ border-top: 1px solid var(--tiptap-color-border);
15
+ }
16
+
17
+ .video-dialog-content {
18
+ display: flex;
19
+ flex-direction: column;
20
+ margin-bottom: 16px;
21
+ gap: 16px;
22
+ }
23
+
24
+ .video-dialog-form-group {
25
+ display: flex;
26
+ flex-direction: column;
27
+ gap: 6px;
28
+ }
29
+
30
+ .video-dialog-label {
31
+ color: var(--ui-text-primary);
32
+ font-weight: 500;
33
+ font-size: 14px;
34
+ }
35
+
36
+ .video-dialog-input {
37
+ padding: 8px 12px;
38
+ border: 1px solid var(--tiptap-color-border);
39
+ border-radius: 4px;
40
+ font-size: 14px;
41
+ font-family: inherit;
42
+ transition: border-color 150ms ease-in-out;
43
+ }
44
+
45
+ .video-dialog-input:focus {
46
+ border-color: var(--ui-color-primary);
47
+ outline: none;
48
+ box-shadow: 0 0 0 3px var(--tiptap-color-primary-subtle);
49
+ }
50
+
51
+ .video-dialog-input::placeholder {
52
+ color: var(--tiptap-color-text-placeholder);
53
+ }
54
+
55
+ .video-dialog-input:disabled {
56
+ background-color: var(--ui-secondary-bg);
57
+ color: var(--tiptap-color-text-disabled);
58
+ cursor: not-allowed;
59
+ }
60
+
61
+ .video-dialog-help-text {
62
+ padding: 12px;
63
+ border: 1px solid var(--ui-info-border);
64
+ border-radius: 4px;
65
+ background-color: var(--ui-info-bg);
66
+ font-size: 13px;
67
+ }
68
+
69
+ .video-dialog-help-title {
70
+ margin: 0 0 8px 0;
71
+ color: var(--ui-text-primary);
72
+ font-weight: 500;
73
+ }
74
+
75
+ .video-dialog-platform-list {
76
+ margin: 0;
77
+ padding-left: 20px;
78
+ color: var(--ui-text-secondary);
79
+ list-style-type: disc;
80
+ }
81
+
82
+ .video-dialog-platform-list li {
83
+ margin: 4px 0;
84
+ }
85
+
86
+ .video-dialog-error {
87
+ padding: 8px 12px;
88
+ border: 1px solid var(--ui-error-border);
89
+ border-radius: 4px;
90
+ background-color: var(--ui-error-bg);
91
+ color: var(--ui-error-text);
92
+ font-size: 13px;
93
+ }
94
+
95
+ .video-dialog-actions {
96
+ display: flex;
97
+ justify-content: flex-end;
98
+ gap: 8px;
99
+ }
100
+
101
+ .video-dialog-button-cancel {
102
+ padding: 8px 16px;
103
+ border: 1px solid var(--tiptap-color-border);
104
+ border-radius: 4px;
105
+ background-color: var(--ui-text-white);
106
+ color: var(--ui-text-primary);
107
+ font-weight: 500;
108
+ font-size: 14px;
109
+ cursor: pointer;
110
+ transition: all 150ms ease-in-out;
111
+ }
112
+
113
+ .video-dialog-button-cancel:hover {
114
+ border-color: var(--ui-secondary-bg-active);
115
+ background-color: var(--ui-secondary-bg);
116
+ }
117
+
118
+ .video-dialog-button-cancel:disabled {
119
+ cursor: not-allowed;
120
+ opacity: 0.6;
121
+ }
122
+
123
+ .video-dialog-button-submit {
124
+ padding: 8px 16px;
125
+ border: none;
126
+ border-radius: 4px;
127
+ background-color: var(--ui-color-primary);
128
+ color: var(--ui-text-white);
129
+ font-weight: 500;
130
+ font-size: 14px;
131
+ cursor: pointer;
132
+ transition: all 150ms ease-in-out;
133
+ }
134
+
135
+ .video-dialog-button-submit:hover {
136
+ background-color: var(--ui-color-primary-dark);
137
+ }
138
+
139
+ .video-dialog-button-submit:active {
140
+ transform: scale(0.98);
141
+ }
142
+
143
+ .video-dialog-button-submit:disabled {
144
+ cursor: not-allowed;
145
+ opacity: 0.6;
146
+ }
@@ -0,0 +1,157 @@
1
+ "use client";
2
+
3
+ import { ChangeEvent, useEffect, useRef, useState } from "react";
4
+
5
+ import { CommonModal } from "../../components";
6
+ import { detectVideoHosting, VideoHosting } from "../../../utils/detect-video-hosting";
7
+ import { useTiptapTranslations } from "../../context";
8
+
9
+ interface AddVideoDialogProps {
10
+ open: boolean;
11
+ onClose: () => void;
12
+ onVideoAdd: (url: string) => void;
13
+ }
14
+
15
+ const SUPPORTED_PLATFORMS = {
16
+ [VideoHosting.Youtube]: "YouTube",
17
+ [VideoHosting.Vimeo]: "Vimeo",
18
+ [VideoHosting.Rutube]: "Rutube",
19
+ [VideoHosting.VK]: "VK",
20
+ };
21
+
22
+ export const AddVideoDialog = ({
23
+ open,
24
+ onClose,
25
+ onVideoAdd,
26
+ }: AddVideoDialogProps) => {
27
+ const translations = useTiptapTranslations();
28
+ const [url, setUrl] = useState("");
29
+ const [error, setError] = useState<string>("");
30
+ const [isValidating, setIsValidating] = useState(false);
31
+ const urlInputRef = useRef<HTMLInputElement>(null);
32
+
33
+ useEffect(() => {
34
+ if (open) {
35
+ setUrl("");
36
+ setError("");
37
+ setIsValidating(false);
38
+ // Focus the input after modal opens
39
+ setTimeout(() => {
40
+ urlInputRef.current?.focus();
41
+ }, 0);
42
+ }
43
+ }, [open]);
44
+
45
+ const validateVideo = async (videoUrl: string): Promise<boolean> => {
46
+ if (!videoUrl.trim()) {
47
+ setError(translations.videoUpload.emptyUrl);
48
+ return false;
49
+ }
50
+
51
+ setIsValidating(true);
52
+ try {
53
+ const videoInfo = await detectVideoHosting(videoUrl);
54
+ if (!videoInfo) {
55
+ setError(translations.videoUpload.unsupportedUrl);
56
+ return false;
57
+ }
58
+ return true;
59
+ } catch {
60
+ setError(translations.videoUpload.validationError);
61
+ return false;
62
+ } finally {
63
+ setIsValidating(false);
64
+ }
65
+ };
66
+
67
+ const handleSubmit = async () => {
68
+ setError("");
69
+
70
+ if (!url.trim()) {
71
+ setError(translations.videoUpload.emptyUrl);
72
+ return;
73
+ }
74
+
75
+ const isValid = await validateVideo(url);
76
+ if (isValid) {
77
+ onVideoAdd(url);
78
+ handleClose();
79
+ }
80
+ };
81
+
82
+ const handleClose = () => {
83
+ setUrl("");
84
+ setError("");
85
+ setIsValidating(false);
86
+ onClose();
87
+ };
88
+
89
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
90
+ if (e.key === "Enter" && !isValidating) {
91
+ e.preventDefault();
92
+ handleSubmit();
93
+ }
94
+ };
95
+
96
+ return (
97
+ <CommonModal
98
+ open={open}
99
+ handleClose={handleClose}
100
+ >
101
+ <p className="video-dialog-title">{translations.videoUpload.title}</p>
102
+ <hr className="video-dialog-divider" />
103
+
104
+ <div className="video-dialog-content">
105
+ <div className="video-dialog-form-group">
106
+ <label
107
+ htmlFor="video-url"
108
+ className="video-dialog-label"
109
+ >
110
+ {translations.videoUpload.urlLabel}
111
+ </label>
112
+ <input
113
+ ref={urlInputRef}
114
+ id="video-url"
115
+ type="text"
116
+ className="video-dialog-input"
117
+ placeholder={translations.videoUpload.urlPlaceholder}
118
+ value={url}
119
+ onChange={(e: ChangeEvent<HTMLInputElement>) => setUrl(e.target.value)}
120
+ onKeyDown={handleKeyDown}
121
+ disabled={isValidating}
122
+ />
123
+ </div>
124
+
125
+ <div className="video-dialog-help-text">
126
+ <p className="video-dialog-help-title">{translations.videoUpload.supportedPlatforms}</p>
127
+ <ul className="video-dialog-platform-list">
128
+ {Object.entries(SUPPORTED_PLATFORMS).map(([key, name]) => (
129
+ <li key={key}>{name}</li>
130
+ ))}
131
+ </ul>
132
+ </div>
133
+
134
+ {error && <div className="video-dialog-error">{error}</div>}
135
+ </div>
136
+
137
+ <div className="video-dialog-actions">
138
+ <button
139
+ className="video-dialog-button-cancel"
140
+ onClick={handleClose}
141
+ type="button"
142
+ disabled={isValidating}
143
+ >
144
+ {translations.videoUpload.cancel}
145
+ </button>
146
+ <button
147
+ className="video-dialog-button-submit"
148
+ onClick={handleSubmit}
149
+ type="button"
150
+ disabled={isValidating}
151
+ >
152
+ {isValidating ? translations.videoUpload.validating : translations.videoUpload.add}
153
+ </button>
154
+ </div>
155
+ </CommonModal>
156
+ );
157
+ };
@@ -0,0 +1 @@
1
+ export { AddVideoDialog } from './add-video-dialog';
@@ -0,0 +1,101 @@
1
+ /* ═══════════════════════════════════════════════════════════ */
2
+ /* IMAGE DIALOG */
3
+ /* ═══════════════════════════════════════════════════════════ */
4
+
5
+ .image-dialog-title {
6
+ margin: 0;
7
+ font-weight: 600;
8
+ font-size: 16px;
9
+ }
10
+
11
+ .image-dialog-divider {
12
+ margin-bottom: 16px;
13
+ border: none;
14
+ border-top: 1px solid var(--tiptap-color-border);
15
+ }
16
+
17
+ .image-dialog-form-container {
18
+ margin-bottom: 16px;
19
+ }
20
+
21
+ .image-dialog-form {
22
+ display: flex;
23
+ flex-direction: column;
24
+ gap: 12px;
25
+ }
26
+
27
+ .image-dialog-preview {
28
+ max-width: 100%;
29
+ height: auto;
30
+ margin-bottom: 12px;
31
+ border-radius: 12px;
32
+ }
33
+
34
+ .image-dialog-preview-wrapper {
35
+ display: flex;
36
+ position: relative;
37
+ justify-content: center;
38
+ }
39
+
40
+ .image-dialog-preview-wrapper:hover .image-dialog-delete-button {
41
+ display: flex;
42
+ }
43
+
44
+ .image-dialog-delete-button {
45
+ display: none;
46
+ position: absolute;
47
+ top: 12px;
48
+ right: 12px;
49
+ align-items: center;
50
+ justify-content: center;
51
+ width: 30px;
52
+ height: 30px;
53
+ padding: 0;
54
+ border: none;
55
+ border-radius: 50%;
56
+ background-color: var(--ui-text-white);
57
+ color: var(--ui-text-primary);
58
+ font-size: 20px;
59
+ cursor: pointer;
60
+ opacity: 0.8;
61
+ transition: all 0.2s ease-out;
62
+ }
63
+
64
+ .image-dialog-delete-button svg {
65
+ width: 16px;
66
+ height: 16px;
67
+ }
68
+
69
+ .image-dialog-delete-button:hover {
70
+ background-color: var(--ui-secondary-bg);
71
+ opacity: 1;
72
+ }
73
+
74
+ .image-dialog-drag-area {
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ width: 100%;
79
+ height: 150px;
80
+ border: 2px dashed #cccccc;
81
+ border-radius: 10px;
82
+ background-color: transparent;
83
+ cursor: pointer;
84
+ transition: all 0.2s ease-out;
85
+ }
86
+
87
+ .image-dialog-drag-area-active {
88
+ border-color: var(--ui-color-primary);
89
+ background-color: var(--ui-info-bg);
90
+ }
91
+
92
+ .image-dialog-actions {
93
+ display: flex;
94
+ justify-content: flex-end;
95
+ gap: 8px;
96
+ }
97
+
98
+ .image-dialog-cancel-button {
99
+ background: var(--ui-secondary-bg);
100
+ color: var(--ui-text-primary);
101
+ }