@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.
- package/README.md +102 -0
- package/dist/editor.css +2069 -0
- package/dist/editor.css.map +1 -0
- package/dist/editor.d.mts +45 -0
- package/dist/editor.d.ts +45 -0
- package/dist/editor.js +6155 -0
- package/dist/editor.js.map +1 -0
- package/dist/editor.mjs +6118 -0
- package/dist/editor.mjs.map +1 -0
- package/dist/render/client.d.mts +24 -0
- package/dist/render/client.d.ts +24 -0
- package/dist/render/client.js +98 -0
- package/dist/render/client.js.map +1 -0
- package/dist/render/client.mjs +74 -0
- package/dist/render/client.mjs.map +1 -0
- package/dist/render.d.mts +58 -0
- package/dist/render.d.ts +58 -0
- package/dist/render.js +2521 -0
- package/dist/render.js.map +1 -0
- package/dist/render.mjs +2484 -0
- package/dist/render.mjs.map +1 -0
- package/dist/styles/index.css +2068 -0
- package/package.json +92 -0
- package/src/editor/commands/items.ts +374 -0
- package/src/editor/commands/suggestion.tsx +146 -0
- package/src/editor/components/button/button.css +56 -0
- package/src/editor/components/button/button.tsx +35 -0
- package/src/editor/components/button/index.ts +1 -0
- package/src/editor/components/common-modal/common-modal.css +85 -0
- package/src/editor/components/common-modal/common-modal.tsx +58 -0
- package/src/editor/components/common-modal/index.ts +1 -0
- package/src/editor/components/index.ts +3 -0
- package/src/editor/components/input/index.ts +1 -0
- package/src/editor/components/input/input.css +43 -0
- package/src/editor/components/input/input.tsx +22 -0
- package/src/editor/context/dialog-command.tsx +47 -0
- package/src/editor/context/index.ts +2 -0
- package/src/editor/context/translations-context.tsx +28 -0
- package/src/editor/controls/bubble-menu-content.tsx +394 -0
- package/src/editor/controls/callout-menu.tsx +169 -0
- package/src/editor/controls/character-count.tsx +36 -0
- package/src/editor/controls/commands-list.tsx +117 -0
- package/src/editor/controls/drag-handle.tsx +98 -0
- package/src/editor/controls/emoji-picker.tsx +62 -0
- package/src/editor/controls/index.ts +5 -0
- package/src/editor/controls/table-menu.tsx +322 -0
- package/src/editor/dialogs/add-katex-dialog/add-katex-dialog.css +115 -0
- package/src/editor/dialogs/add-katex-dialog/add-katex-dialog.tsx +116 -0
- package/src/editor/dialogs/add-katex-dialog/index.ts +1 -0
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.css +105 -0
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.tsx +177 -0
- package/src/editor/dialogs/add-link-dialog/index.ts +1 -0
- package/src/editor/dialogs/add-video-dialog/add-video-dialog.css +146 -0
- package/src/editor/dialogs/add-video-dialog/add-video-dialog.tsx +157 -0
- package/src/editor/dialogs/add-video-dialog/index.ts +1 -0
- package/src/editor/dialogs/image-dialog/image-dialog.css +101 -0
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +276 -0
- package/src/editor/dialogs/image-dialog/index.ts +1 -0
- package/src/editor/dialogs/index.ts +4 -0
- package/src/editor/editor.tsx +247 -0
- package/src/editor/handlers/create-image-upload-handler.ts +24 -0
- package/src/editor/handlers/dialog-handlers.ts +143 -0
- package/src/editor/handlers/index.ts +8 -0
- package/src/editor/index.ts +3 -0
- package/src/extensions/base/callout.ts +138 -0
- package/src/extensions/base/code-block.ts +24 -0
- package/src/extensions/base/compatibility.ts +493 -0
- package/src/extensions/base/copyable-text.ts +56 -0
- package/src/extensions/base/custom-quote.ts +174 -0
- package/src/extensions/base/figure.ts +141 -0
- package/src/extensions/base/index.ts +19 -0
- package/src/extensions/base/link.ts +18 -0
- package/src/extensions/base/myth-reality.ts +45 -0
- package/src/extensions/base/prompt.ts +109 -0
- package/src/extensions/base/video.ts +29 -0
- package/src/extensions/editor/callout.ts +43 -0
- package/src/extensions/editor/code-block.ts +9 -0
- package/src/extensions/editor/commands.ts +43 -0
- package/src/extensions/editor/copyable-text.ts +16 -0
- package/src/extensions/editor/custom-quote.ts +54 -0
- package/src/extensions/editor/figure.ts +20 -0
- package/src/extensions/editor/get-editor-extensions.ts +113 -0
- package/src/extensions/editor/index.ts +25 -0
- package/src/extensions/editor/prompt.ts +43 -0
- package/src/extensions/editor/video.ts +23 -0
- package/src/extensions/render/get-render-extensions.ts +74 -0
- package/src/extensions/render/index.ts +6 -0
- package/src/extensions/views/components/callout.tsx +70 -0
- package/src/extensions/views/components/code-block.tsx +73 -0
- package/src/extensions/views/components/copy-button.tsx +52 -0
- package/src/extensions/views/components/copyable-text.tsx +11 -0
- package/src/extensions/views/components/custom-quote.tsx +64 -0
- package/src/extensions/views/components/figure.tsx +63 -0
- package/src/extensions/views/components/index.ts +7 -0
- package/src/extensions/views/components/prompt.tsx +43 -0
- package/src/extensions/views/components/video.tsx +40 -0
- package/src/extensions/views/node-views/callout.tsx +51 -0
- package/src/extensions/views/node-views/code-block.tsx +30 -0
- package/src/extensions/views/node-views/copyable-text.tsx +10 -0
- package/src/extensions/views/node-views/custom-quote.tsx +66 -0
- package/src/extensions/views/node-views/figure.tsx +38 -0
- package/src/extensions/views/node-views/index.ts +7 -0
- package/src/extensions/views/node-views/prompt.tsx +35 -0
- package/src/extensions/views/node-views/video.tsx +19 -0
- package/src/icons/Check.tsx +12 -0
- package/src/icons/Copy.tsx +15 -0
- package/src/icons/DragIcon.tsx +10 -0
- package/src/icons/Edit.tsx +12 -0
- package/src/icons/Quote.tsx +10 -0
- package/src/icons/X.tsx +13 -0
- package/src/icons/color/TiptapCalloutError.tsx +25 -0
- package/src/icons/color/TiptapCalloutInfo.tsx +18 -0
- package/src/icons/color/TiptapCalloutSuccess.tsx +49 -0
- package/src/icons/color/TiptapCalloutWarning.tsx +28 -0
- package/src/icons/color/index.ts +4 -0
- package/src/icons/index.ts +60 -0
- package/src/icons/menu/AddImage.tsx +10 -0
- package/src/icons/menu/AlignCenter.tsx +10 -0
- package/src/icons/menu/AlignLeft.tsx +10 -0
- package/src/icons/menu/AlignRight.tsx +10 -0
- package/src/icons/menu/ArrowDown.tsx +13 -0
- package/src/icons/menu/ArrowLeft.tsx +13 -0
- package/src/icons/menu/ArrowRight.tsx +13 -0
- package/src/icons/menu/ArrowUp.tsx +13 -0
- package/src/icons/menu/Blockquote.tsx +7 -0
- package/src/icons/menu/Bold.tsx +10 -0
- package/src/icons/menu/BulletList.tsx +10 -0
- package/src/icons/menu/CalloutError.tsx +10 -0
- package/src/icons/menu/CalloutInfo.tsx +12 -0
- package/src/icons/menu/CalloutSuccess.tsx +10 -0
- package/src/icons/menu/CalloutWarning.tsx +12 -0
- package/src/icons/menu/ClearFormatting.tsx +10 -0
- package/src/icons/menu/Code.tsx +10 -0
- package/src/icons/menu/CodeBlock.tsx +10 -0
- package/src/icons/menu/Copyable.tsx +10 -0
- package/src/icons/menu/CustomQuote.tsx +17 -0
- package/src/icons/menu/DeleteColumn.tsx +17 -0
- package/src/icons/menu/DeleteRow.tsx +17 -0
- package/src/icons/menu/Details.tsx +10 -0
- package/src/icons/menu/H2.tsx +10 -0
- package/src/icons/menu/H3.tsx +10 -0
- package/src/icons/menu/H4.tsx +10 -0
- package/src/icons/menu/H5.tsx +10 -0
- package/src/icons/menu/H6.tsx +10 -0
- package/src/icons/menu/Highlight.tsx +13 -0
- package/src/icons/menu/HorizontalRule.tsx +7 -0
- package/src/icons/menu/Italic.tsx +10 -0
- package/src/icons/menu/Link.tsx +10 -0
- package/src/icons/menu/LinkOff.tsx +10 -0
- package/src/icons/menu/Math.tsx +10 -0
- package/src/icons/menu/MergeCells.tsx +10 -0
- package/src/icons/menu/MythReality.tsx +10 -0
- package/src/icons/menu/OrderedList.tsx +10 -0
- package/src/icons/menu/Prompt.tsx +18 -0
- package/src/icons/menu/Redo.tsx +14 -0
- package/src/icons/menu/SplitCells.tsx +7 -0
- package/src/icons/menu/Strikethrough.tsx +10 -0
- package/src/icons/menu/Subscript.tsx +10 -0
- package/src/icons/menu/Superscript.tsx +10 -0
- package/src/icons/menu/Table.tsx +14 -0
- package/src/icons/menu/TableColumnHeading.tsx +7 -0
- package/src/icons/menu/TableRowHeading.tsx +10 -0
- package/src/icons/menu/TextColor.tsx +13 -0
- package/src/icons/menu/Underline.tsx +10 -0
- package/src/icons/menu/Undo.tsx +14 -0
- package/src/icons/menu/Video.tsx +14 -0
- package/src/icons/menu/index.ts +49 -0
- package/src/render/index.ts +22 -0
- package/src/render/static-renderer-config.tsx +206 -0
- package/src/render/tiptap-interactivity-provider.tsx +78 -0
- package/src/render/tiptap-render.tsx +102 -0
- package/src/styles/components.css +10 -0
- package/src/styles/editor/base.css +39 -0
- package/src/styles/editor/callout-menu.css +81 -0
- package/src/styles/editor/controls.css +57 -0
- package/src/styles/editor/emoji-picker.css +113 -0
- package/src/styles/editor/index.css +9 -0
- package/src/styles/editor/menus.css +16 -0
- package/src/styles/editor/states.css +43 -0
- package/src/styles/editor/typography.css +165 -0
- package/src/styles/editor/utilities.css +71 -0
- package/src/styles/editor/variables.css +70 -0
- package/src/styles/extensions/callout.css +155 -0
- package/src/styles/extensions/code-block.css +109 -0
- package/src/styles/extensions/commands-list.css +83 -0
- package/src/styles/extensions/custom-quote.css +103 -0
- package/src/styles/extensions/details.css +87 -0
- package/src/styles/extensions/figure.css +66 -0
- package/src/styles/extensions/index.css +11 -0
- package/src/styles/extensions/math.css +32 -0
- package/src/styles/extensions/myth-reality.css +59 -0
- package/src/styles/extensions/prompt.css +75 -0
- package/src/styles/extensions/table.css +253 -0
- package/src/styles/extensions/video.css +53 -0
- package/src/styles/styles.css +3 -0
- package/src/translations/en.json +158 -0
- package/src/translations/ru.json +158 -0
- package/src/types/image-handler.ts +33 -0
- package/src/types/index.ts +1 -0
- package/src/utils/copy-to-clipboard.ts +23 -0
- package/src/utils/custom-emoji.ts +174 -0
- package/src/utils/detect-video-hosting.ts +106 -0
- package/src/utils/get-shared-extensions.ts +45 -0
- package/src/utils/get-translations.ts +25 -0
- package/src/utils/handle-exit-node.ts +61 -0
- package/src/utils/image-src-resolver.ts +74 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/migrate-legacy-callouts.ts +59 -0
- package/src/utils/pluralize.ts +38 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { useEditorState, type Editor } from "@tiptap/react";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
TiptapMenuArrowDown,
|
|
9
|
+
TiptapMenuArrowLeft,
|
|
10
|
+
TiptapMenuArrowRight,
|
|
11
|
+
TiptapMenuArrowUp,
|
|
12
|
+
TiptapMenuDeleteColumn,
|
|
13
|
+
TiptapMenuDeleteRow,
|
|
14
|
+
TiptapMenuTableColumnHeading,
|
|
15
|
+
TiptapMenuTableRowHeading,
|
|
16
|
+
} from "../../icons";
|
|
17
|
+
|
|
18
|
+
import { useTiptapTranslations } from "../context";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
editor: Editor;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type MenuType = "row" | "column" | "row-menu" | "column-menu" | null;
|
|
25
|
+
|
|
26
|
+
interface ButtonPositions {
|
|
27
|
+
row: { top: number; left: number } | null;
|
|
28
|
+
column: { top: number; left: number } | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const TableMenu = ({ editor }: Props) => {
|
|
32
|
+
const translations = useTiptapTranslations();
|
|
33
|
+
const [activeMenuType, setActiveMenuType] = useState<MenuType>(null);
|
|
34
|
+
const [buttonPositions, setButtonPositions] = useState<ButtonPositions>({
|
|
35
|
+
row: null,
|
|
36
|
+
column: null,
|
|
37
|
+
});
|
|
38
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
39
|
+
const [isScrolling, setIsScrolling] = useState(false);
|
|
40
|
+
const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
41
|
+
|
|
42
|
+
const { isTable } = useEditorState({
|
|
43
|
+
editor,
|
|
44
|
+
selector: (ctx) => ({
|
|
45
|
+
isTable: ctx.editor.isActive("table"),
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const updateButtonPositions = useCallback(() => {
|
|
50
|
+
if (!isTable) {
|
|
51
|
+
setButtonPositions({ row: null, column: null });
|
|
52
|
+
setActiveMenuType(null);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { $from } = editor.state.selection;
|
|
57
|
+
|
|
58
|
+
let pos: number;
|
|
59
|
+
try {
|
|
60
|
+
pos = $from.before();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
pos = $from.pos;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const domNode = editor.view.domAtPos(pos);
|
|
66
|
+
const activeDomCell = (domNode.node as HTMLElement).closest(
|
|
67
|
+
"td, th"
|
|
68
|
+
) as HTMLTableCellElement | null;
|
|
69
|
+
|
|
70
|
+
if (!activeDomCell) {
|
|
71
|
+
setButtonPositions({ row: null, column: null });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const row = activeDomCell.parentElement as HTMLTableRowElement;
|
|
76
|
+
const table = activeDomCell.closest("table") as HTMLTableElement;
|
|
77
|
+
if (!row || !table) {
|
|
78
|
+
setButtonPositions({ row: null, column: null });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const firstRow = table.querySelector("tr") as HTMLTableRowElement;
|
|
83
|
+
if (!firstRow) {
|
|
84
|
+
setButtonPositions({ row: null, column: null });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rowRect = row.getBoundingClientRect();
|
|
89
|
+
const cellRect = activeDomCell.getBoundingClientRect();
|
|
90
|
+
const firstRowRect = firstRow.getBoundingClientRect();
|
|
91
|
+
|
|
92
|
+
const rowButtonPos = {
|
|
93
|
+
top: rowRect.top + rowRect.height / 2 - 16,
|
|
94
|
+
left: rowRect.left - 8,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const columnButtonTop = Math.max(0, firstRowRect.top - 8);
|
|
98
|
+
const columnButtonPos = {
|
|
99
|
+
top: columnButtonTop,
|
|
100
|
+
left: cellRect.left + cellRect.width / 2 - 16,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
setButtonPositions({
|
|
104
|
+
row: rowButtonPos,
|
|
105
|
+
column: columnButtonPos,
|
|
106
|
+
});
|
|
107
|
+
}, [editor, isTable]);
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!isTable) return;
|
|
111
|
+
|
|
112
|
+
const updateHandler = () => updateButtonPositions();
|
|
113
|
+
editor.on("selectionUpdate", updateHandler);
|
|
114
|
+
editor.on("update", updateHandler);
|
|
115
|
+
|
|
116
|
+
updateButtonPositions();
|
|
117
|
+
|
|
118
|
+
return () => {
|
|
119
|
+
editor.off("selectionUpdate", updateHandler);
|
|
120
|
+
editor.off("update", updateHandler);
|
|
121
|
+
};
|
|
122
|
+
}, [editor, editor.isEditable, isTable, updateButtonPositions]);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const handleScroll = () => {
|
|
126
|
+
setIsScrolling(true);
|
|
127
|
+
setActiveMenuType(null);
|
|
128
|
+
|
|
129
|
+
if (scrollTimeoutRef.current) {
|
|
130
|
+
clearTimeout(scrollTimeoutRef.current);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
scrollTimeoutRef.current = setTimeout(() => {
|
|
134
|
+
setIsScrolling(false);
|
|
135
|
+
updateButtonPositions();
|
|
136
|
+
}, 150);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
window.removeEventListener("scroll", handleScroll, true);
|
|
143
|
+
if (scrollTimeoutRef.current) {
|
|
144
|
+
clearTimeout(scrollTimeoutRef.current);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}, [updateButtonPositions]);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (activeMenuType === null) return;
|
|
151
|
+
|
|
152
|
+
const handleClickOutside = (e: MouseEvent) => {
|
|
153
|
+
const target = e.target as HTMLElement;
|
|
154
|
+
|
|
155
|
+
if (menuRef.current && !menuRef.current.contains(target)) {
|
|
156
|
+
const isClickOnButton = target.closest('[class*="table-indicator__button"]');
|
|
157
|
+
if (!isClickOnButton) {
|
|
158
|
+
setActiveMenuType(null);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
164
|
+
|
|
165
|
+
return () => {
|
|
166
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
167
|
+
};
|
|
168
|
+
}, [activeMenuType]);
|
|
169
|
+
|
|
170
|
+
const executeTableCommand = (command: () => boolean | void) => {
|
|
171
|
+
command();
|
|
172
|
+
setActiveMenuType(null);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (activeMenuType === "row-menu" || activeMenuType === "column-menu") {
|
|
176
|
+
const pos = activeMenuType === "row-menu" ? buttonPositions.row : buttonPositions.column;
|
|
177
|
+
if (!pos) return null;
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<div
|
|
181
|
+
ref={menuRef}
|
|
182
|
+
className="table-context-menu"
|
|
183
|
+
style={{
|
|
184
|
+
top: `${pos.top + (activeMenuType === "row-menu" ? 32 : 0)}px`,
|
|
185
|
+
left: `${pos.left}px`,
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<div className="table-context-menu__content">
|
|
189
|
+
{activeMenuType === "row-menu" && (
|
|
190
|
+
<>
|
|
191
|
+
<button
|
|
192
|
+
className="table-context-menu__button"
|
|
193
|
+
onClick={() => executeTableCommand(editor.commands.addRowBefore)}
|
|
194
|
+
title={translations.table.insertRowBefore}
|
|
195
|
+
type="button"
|
|
196
|
+
>
|
|
197
|
+
<TiptapMenuArrowUp />
|
|
198
|
+
<span>{translations.table.insertRowBefore}</span>
|
|
199
|
+
</button>
|
|
200
|
+
<button
|
|
201
|
+
className="table-context-menu__button"
|
|
202
|
+
onClick={() => executeTableCommand(editor.commands.addRowAfter)}
|
|
203
|
+
title={translations.table.insertRowAfter}
|
|
204
|
+
type="button"
|
|
205
|
+
>
|
|
206
|
+
<TiptapMenuArrowDown />
|
|
207
|
+
<span>{translations.table.insertRowAfter}</span>
|
|
208
|
+
</button>
|
|
209
|
+
<button
|
|
210
|
+
className="table-context-menu__button"
|
|
211
|
+
onClick={() => executeTableCommand(editor.commands.toggleHeaderRow)}
|
|
212
|
+
title={translations.table.toggleHeaderRow}
|
|
213
|
+
type="button"
|
|
214
|
+
>
|
|
215
|
+
<TiptapMenuTableRowHeading />
|
|
216
|
+
<span>{translations.table.toggleHeaderRow}</span>
|
|
217
|
+
</button>
|
|
218
|
+
<div className="table-context-menu__divider" />
|
|
219
|
+
<button
|
|
220
|
+
className="table-context-menu__button table-context-menu__button--danger"
|
|
221
|
+
onClick={() => executeTableCommand(editor.commands.deleteRow)}
|
|
222
|
+
title={translations.table.deleteRow}
|
|
223
|
+
type="button"
|
|
224
|
+
>
|
|
225
|
+
<TiptapMenuDeleteRow />
|
|
226
|
+
<span>{translations.table.deleteRow}</span>
|
|
227
|
+
</button>
|
|
228
|
+
</>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
{activeMenuType === "column-menu" && (
|
|
232
|
+
<>
|
|
233
|
+
<button
|
|
234
|
+
className="table-context-menu__button"
|
|
235
|
+
onClick={() => executeTableCommand(editor.commands.addColumnBefore)}
|
|
236
|
+
title={translations.table.insertColumnBefore}
|
|
237
|
+
type="button"
|
|
238
|
+
>
|
|
239
|
+
<TiptapMenuArrowLeft />
|
|
240
|
+
<span>{translations.table.insertColumnBefore}</span>
|
|
241
|
+
</button>
|
|
242
|
+
<button
|
|
243
|
+
className="table-context-menu__button"
|
|
244
|
+
onClick={() => executeTableCommand(editor.commands.addColumnAfter)}
|
|
245
|
+
title={translations.table.insertColumnAfter}
|
|
246
|
+
type="button"
|
|
247
|
+
>
|
|
248
|
+
<TiptapMenuArrowRight />
|
|
249
|
+
<span>{translations.table.insertColumnAfter}</span>
|
|
250
|
+
</button>
|
|
251
|
+
<button
|
|
252
|
+
className="table-context-menu__button"
|
|
253
|
+
onClick={() => executeTableCommand(editor.commands.toggleHeaderColumn)}
|
|
254
|
+
title={translations.table.toggleHeaderColumn}
|
|
255
|
+
type="button"
|
|
256
|
+
>
|
|
257
|
+
<TiptapMenuTableColumnHeading />
|
|
258
|
+
<span>{translations.table.toggleHeaderColumn}</span>
|
|
259
|
+
</button>
|
|
260
|
+
<div className="table-context-menu__divider" />
|
|
261
|
+
<button
|
|
262
|
+
className="table-context-menu__button table-context-menu__button--danger"
|
|
263
|
+
onClick={() => executeTableCommand(editor.commands.deleteColumn)}
|
|
264
|
+
title={translations.table.deleteColumn}
|
|
265
|
+
type="button"
|
|
266
|
+
>
|
|
267
|
+
<TiptapMenuDeleteColumn />
|
|
268
|
+
<span>{translations.table.deleteColumn}</span>
|
|
269
|
+
</button>
|
|
270
|
+
</>
|
|
271
|
+
)}
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (isScrolling) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<>
|
|
283
|
+
{buttonPositions.row && (
|
|
284
|
+
<div
|
|
285
|
+
className="table-indicator"
|
|
286
|
+
style={{
|
|
287
|
+
top: `${buttonPositions.row.top}px`,
|
|
288
|
+
left: `${buttonPositions.row.left}px`,
|
|
289
|
+
}}
|
|
290
|
+
>
|
|
291
|
+
<button
|
|
292
|
+
className="table-indicator__button table-indicator__button--row"
|
|
293
|
+
onClick={() => setActiveMenuType("row-menu")}
|
|
294
|
+
title={translations.table.insertRowBefore}
|
|
295
|
+
type="button"
|
|
296
|
+
>
|
|
297
|
+
⋮
|
|
298
|
+
</button>
|
|
299
|
+
</div>
|
|
300
|
+
)}
|
|
301
|
+
|
|
302
|
+
{buttonPositions.column && (
|
|
303
|
+
<div
|
|
304
|
+
className="table-indicator"
|
|
305
|
+
style={{
|
|
306
|
+
top: `${buttonPositions.column.top}px`,
|
|
307
|
+
left: `${buttonPositions.column.left}px`,
|
|
308
|
+
}}
|
|
309
|
+
>
|
|
310
|
+
<button
|
|
311
|
+
className="table-indicator__button table-indicator__button--column"
|
|
312
|
+
onClick={() => setActiveMenuType("column-menu")}
|
|
313
|
+
title={translations.table.insertColumnBefore}
|
|
314
|
+
type="button"
|
|
315
|
+
>
|
|
316
|
+
⋯
|
|
317
|
+
</button>
|
|
318
|
+
</div>
|
|
319
|
+
)}
|
|
320
|
+
</>
|
|
321
|
+
);
|
|
322
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* ═══════════════════════════════════════════════════════════ */
|
|
2
|
+
/* ADD KATEX DIALOG */
|
|
3
|
+
/* ═══════════════════════════════════════════════════════════ */
|
|
4
|
+
|
|
5
|
+
.katex-dialog-title {
|
|
6
|
+
margin: 0 0 16px 0;
|
|
7
|
+
font-weight: 600;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.katex-dialog-divider {
|
|
12
|
+
margin-bottom: 16px;
|
|
13
|
+
border: none;
|
|
14
|
+
border-top: 1px soliv var(--tiptap-color-border);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.katex-dialog-content {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
margin-bottom: 16px;
|
|
21
|
+
gap: 16px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.katex-dialog-description {
|
|
25
|
+
margin: 0;
|
|
26
|
+
color: var(--ui-text-secondary);
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
line-height: 1.5;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.katex-dialog-description a {
|
|
32
|
+
color: var(--ui-color-primary);
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
transition: color 150ms ease-in-out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.katex-dialog-description a:hover {
|
|
38
|
+
color: var(--ui-color-primary-dark);
|
|
39
|
+
text-decoration: underline;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.katex-dialog-form-group {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: 6px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.katex-dialog-label {
|
|
49
|
+
color: var(--ui-text-primary);
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
font-size: 14px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.katex-dialog-textarea {
|
|
55
|
+
padding: 8px 12px;
|
|
56
|
+
border: 1px solid var(--tiptap-color-border);
|
|
57
|
+
border-radius: 4px;
|
|
58
|
+
font-size: 14px;
|
|
59
|
+
font-family: monospace;
|
|
60
|
+
resize: vertical;
|
|
61
|
+
transition: border-color 150ms ease-in-out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.katex-dialog-textarea:focus {
|
|
65
|
+
border-color: var(--ui-color-primary);
|
|
66
|
+
outline: none;
|
|
67
|
+
box-shadow: 0 0 0 3px var(--tiptap-color-primary-subtle);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.katex-dialog-textarea::placeholder {
|
|
71
|
+
color: var(--tiptap-color-text-placeholder);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.katex-dialog-actions {
|
|
75
|
+
display: flex;
|
|
76
|
+
justify-content: flex-end;
|
|
77
|
+
gap: 8px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.katex-dialog-button-cancel {
|
|
81
|
+
padding: 8px 16px;
|
|
82
|
+
border: 1px solid var(--tiptap-color-border);
|
|
83
|
+
border-radius: 4px;
|
|
84
|
+
background-color: var(--ui-text-white);
|
|
85
|
+
color: var(--ui-text-primary);
|
|
86
|
+
font-weight: 500;
|
|
87
|
+
font-size: 14px;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
transition: all 150ms ease-in-out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.katex-dialog-button-cancel:hover {
|
|
93
|
+
border-color: var(--ui-secondary-bg-active);
|
|
94
|
+
background-color: var(--ui-secondary-bg);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.katex-dialog-button-submit {
|
|
98
|
+
padding: 8px 16px;
|
|
99
|
+
border: none;
|
|
100
|
+
border-radius: 4px;
|
|
101
|
+
background-color: var(--ui-color-primary);
|
|
102
|
+
color: var(--ui-text-white);
|
|
103
|
+
font-weight: 500;
|
|
104
|
+
font-size: 14px;
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
transition: all 150ms ease-in-out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.katex-dialog-button-submit:hover {
|
|
110
|
+
background-color: var(--ui-color-primary-dark);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.katex-dialog-button-submit:active {
|
|
114
|
+
transform: scale(0.98);
|
|
115
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 AddKatexDialogProps {
|
|
9
|
+
open: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onKatexAdd: (content: string) => void;
|
|
12
|
+
initialContent?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const AddKatexDialog = ({
|
|
16
|
+
open,
|
|
17
|
+
onClose,
|
|
18
|
+
onKatexAdd,
|
|
19
|
+
initialContent = "",
|
|
20
|
+
}: AddKatexDialogProps) => {
|
|
21
|
+
const translations = useTiptapTranslations();
|
|
22
|
+
const [content, setContent] = useState(initialContent);
|
|
23
|
+
const contentInputRef = useRef<HTMLTextAreaElement>(null);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (open) {
|
|
27
|
+
setContent(initialContent);
|
|
28
|
+
// Focus the textarea after modal opens
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
contentInputRef.current?.focus();
|
|
31
|
+
}, 0);
|
|
32
|
+
}
|
|
33
|
+
}, [open, initialContent]);
|
|
34
|
+
|
|
35
|
+
const handleSubmit = () => {
|
|
36
|
+
if (content.trim()) {
|
|
37
|
+
onKatexAdd(content);
|
|
38
|
+
setContent("");
|
|
39
|
+
}
|
|
40
|
+
handleClose();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleClose = () => {
|
|
44
|
+
setContent(initialContent);
|
|
45
|
+
onClose();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
49
|
+
if (e.key === "Enter" && e.ctrlKey) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
handleSubmit();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<CommonModal
|
|
57
|
+
open={open}
|
|
58
|
+
handleClose={handleClose}
|
|
59
|
+
>
|
|
60
|
+
<p className="katex-dialog-title">
|
|
61
|
+
{initialContent ? translations.katex.editTitle : translations.katex.addTitle}
|
|
62
|
+
</p>
|
|
63
|
+
<hr className="katex-dialog-divider" />
|
|
64
|
+
|
|
65
|
+
<div className="katex-dialog-content">
|
|
66
|
+
<p className="katex-dialog-description">
|
|
67
|
+
{translations.katex.description}{" "}
|
|
68
|
+
<a
|
|
69
|
+
href="https://katex.org/docs/supported.html"
|
|
70
|
+
target="_blank"
|
|
71
|
+
rel="noreferrer"
|
|
72
|
+
>
|
|
73
|
+
{translations.katex.documentationLink}
|
|
74
|
+
</a>{" "}
|
|
75
|
+
{translations.katex.documentationLinkSuffix}
|
|
76
|
+
</p>
|
|
77
|
+
|
|
78
|
+
<div className="katex-dialog-form-group">
|
|
79
|
+
<label
|
|
80
|
+
htmlFor="katex-content"
|
|
81
|
+
className="katex-dialog-label"
|
|
82
|
+
>
|
|
83
|
+
{translations.katex.label}
|
|
84
|
+
</label>
|
|
85
|
+
<textarea
|
|
86
|
+
ref={contentInputRef}
|
|
87
|
+
id="katex-content"
|
|
88
|
+
className="katex-dialog-textarea"
|
|
89
|
+
placeholder={translations.katex.placeholder}
|
|
90
|
+
value={content}
|
|
91
|
+
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => setContent(e.target.value)}
|
|
92
|
+
onKeyDown={handleKeyDown}
|
|
93
|
+
rows={5}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div className="katex-dialog-actions">
|
|
99
|
+
<button
|
|
100
|
+
className="katex-dialog-button-cancel"
|
|
101
|
+
onClick={handleClose}
|
|
102
|
+
type="button"
|
|
103
|
+
>
|
|
104
|
+
{translations.common.cancel}
|
|
105
|
+
</button>
|
|
106
|
+
<button
|
|
107
|
+
className="katex-dialog-button-submit"
|
|
108
|
+
onClick={handleSubmit}
|
|
109
|
+
type="button"
|
|
110
|
+
>
|
|
111
|
+
{initialContent ? translations.katex.update : translations.katex.add}
|
|
112
|
+
</button>
|
|
113
|
+
</div>
|
|
114
|
+
</CommonModal>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AddKatexDialog } from './add-katex-dialog';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* ═══════════════════════════════════════════════════════════ */
|
|
2
|
+
/* ADD LINK DIALOG */
|
|
3
|
+
/* ═══════════════════════════════════════════════════════════ */
|
|
4
|
+
|
|
5
|
+
.link-dialog-title {
|
|
6
|
+
margin: 0 0 16px 0;
|
|
7
|
+
font-weight: 600;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.link-dialog-divider {
|
|
12
|
+
margin-bottom: 16px;
|
|
13
|
+
border: none;
|
|
14
|
+
border-top: 1px soliv var(--tiptap-color-border);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.link-dialog-content {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
margin-bottom: 16px;
|
|
21
|
+
gap: 16px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.link-dialog-form-group {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: 6px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.link-dialog-label {
|
|
31
|
+
color: var(--ui-text-primary);
|
|
32
|
+
font-weight: 500;
|
|
33
|
+
font-size: 14px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.link-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
|
+
.link-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
|
+
.link-dialog-input::placeholder {
|
|
52
|
+
color: var(--tiptap-color-text-placeholder);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.link-dialog-error {
|
|
56
|
+
padding: 8px 12px;
|
|
57
|
+
border: 1px solid var(--ui-error-border);
|
|
58
|
+
border-radius: 4px;
|
|
59
|
+
background-color: var(--ui-error-bg);
|
|
60
|
+
color: var(--ui-error-text);
|
|
61
|
+
font-size: 13px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.link-dialog-actions {
|
|
65
|
+
display: flex;
|
|
66
|
+
justify-content: flex-end;
|
|
67
|
+
gap: 8px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.link-dialog-button-cancel {
|
|
71
|
+
padding: 8px 16px;
|
|
72
|
+
border: 1px solid var(--tiptap-color-border);
|
|
73
|
+
border-radius: 4px;
|
|
74
|
+
background-color: var(--ui-text-white);
|
|
75
|
+
color: var(--ui-text-primary);
|
|
76
|
+
font-weight: 500;
|
|
77
|
+
font-size: 14px;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
transition: all 150ms ease-in-out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.link-dialog-button-cancel:hover {
|
|
83
|
+
border-color: var(--ui-secondary-bg-active);
|
|
84
|
+
background-color: var(--ui-secondary-bg);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.link-dialog-button-submit {
|
|
88
|
+
padding: 8px 16px;
|
|
89
|
+
border: none;
|
|
90
|
+
border-radius: 4px;
|
|
91
|
+
background-color: var(--ui-color-primary);
|
|
92
|
+
color: var(--ui-text-white);
|
|
93
|
+
font-weight: 500;
|
|
94
|
+
font-size: 14px;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
transition: all 150ms ease-in-out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.link-dialog-button-submit:hover {
|
|
100
|
+
background-color: var(--ui-color-primary-dark);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.link-dialog-button-submit:active {
|
|
104
|
+
transform: scale(0.98);
|
|
105
|
+
}
|