tetrons 0.1.0 → 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 (80) hide show
  1. package/dist/.next/types/app/api/export/route.d.ts +12 -0
  2. package/dist/.next/types/app/api/export/route.js +52 -0
  3. package/dist/.next/types/app/api/save/route.d.ts +12 -0
  4. package/dist/.next/types/app/api/save/route.js +52 -0
  5. package/dist/.next/types/app/layout.d.ts +12 -0
  6. package/dist/.next/types/app/layout.js +22 -0
  7. package/dist/.next/types/app/page.d.ts +12 -0
  8. package/dist/.next/types/app/page.js +22 -0
  9. package/dist/next.config.d.ts +3 -0
  10. package/dist/next.config.js +4 -0
  11. package/dist/src/app/api/export/route.d.ts +1 -0
  12. package/dist/src/app/api/export/route.js +4 -0
  13. package/dist/src/app/api/save/route.d.ts +6 -0
  14. package/dist/src/app/api/save/route.js +15 -0
  15. package/dist/src/app/layout.d.ts +6 -0
  16. package/dist/src/app/layout.jsx +34 -0
  17. package/dist/src/app/page.d.ts +1 -0
  18. package/dist/src/app/page.jsx +10 -0
  19. package/dist/src/components/UI/Button.d.ts +0 -0
  20. package/dist/src/components/UI/Button.jsx +1 -0
  21. package/dist/src/components/UI/Dropdown.d.ts +0 -0
  22. package/dist/src/components/UI/Dropdown.jsx +1 -0
  23. package/dist/src/components/tetrons/EditorContent.d.ts +1 -0
  24. package/dist/src/components/tetrons/EditorContent.jsx +158 -0
  25. package/dist/src/components/tetrons/ResizableImage.d.ts +1 -0
  26. package/dist/src/components/tetrons/ResizableImage.js +40 -0
  27. package/dist/src/components/tetrons/ResizableImageComponent.d.ts +11 -0
  28. package/dist/src/components/tetrons/ResizableImageComponent.jsx +37 -0
  29. package/dist/src/components/tetrons/ResizableVideo.d.ts +12 -0
  30. package/dist/src/components/tetrons/ResizableVideo.js +61 -0
  31. package/dist/src/components/tetrons/ResizableVideoComponent.d.ts +4 -0
  32. package/dist/src/components/tetrons/ResizableVideoComponent.jsx +32 -0
  33. package/dist/src/components/tetrons/helpers.d.ts +0 -0
  34. package/dist/src/components/tetrons/helpers.js +1 -0
  35. package/dist/src/components/tetrons/toolbar/ActionGroup.d.ts +6 -0
  36. package/dist/src/components/tetrons/toolbar/ActionGroup.jsx +165 -0
  37. package/dist/src/components/tetrons/toolbar/ClipboardGroup.d.ts +4 -0
  38. package/dist/src/components/tetrons/toolbar/ClipboardGroup.jsx +35 -0
  39. package/dist/src/components/tetrons/toolbar/FileGroup.d.ts +6 -0
  40. package/dist/src/components/tetrons/toolbar/FileGroup.jsx +40 -0
  41. package/dist/src/components/tetrons/toolbar/FontStyleGroup.d.ts +6 -0
  42. package/dist/src/components/tetrons/toolbar/FontStyleGroup.jsx +104 -0
  43. package/dist/src/components/tetrons/toolbar/InsertGroup.d.ts +5 -0
  44. package/dist/src/components/tetrons/toolbar/InsertGroup.jsx +162 -0
  45. package/dist/src/components/tetrons/toolbar/ListAlignGroup.d.ts +4 -0
  46. package/dist/src/components/tetrons/toolbar/ListAlignGroup.jsx +15 -0
  47. package/dist/src/components/tetrons/toolbar/MiscGroup.d.ts +6 -0
  48. package/dist/src/components/tetrons/toolbar/MiscGroup.jsx +30 -0
  49. package/dist/src/components/tetrons/toolbar/TableContextMenu.d.ts +6 -0
  50. package/dist/src/components/tetrons/toolbar/TableContextMenu.jsx +52 -0
  51. package/dist/src/components/tetrons/toolbar/TetronsToolbar.d.ts +4 -0
  52. package/dist/src/components/tetrons/toolbar/TetronsToolbar.jsx +46 -0
  53. package/dist/src/components/tetrons/toolbar/ToolbarButton.d.ts +12 -0
  54. package/dist/src/components/tetrons/toolbar/ToolbarButton.jsx +8 -0
  55. package/dist/src/components/tetrons/toolbar/extensions/Comment.d.ts +17 -0
  56. package/dist/src/components/tetrons/toolbar/extensions/Comment.js +45 -0
  57. package/dist/src/components/tetrons/toolbar/extensions/Embed.d.ts +2 -0
  58. package/dist/src/components/tetrons/toolbar/extensions/Embed.js +90 -0
  59. package/dist/src/components/tetrons/toolbar/extensions/FontFamily.d.ts +9 -0
  60. package/dist/src/components/tetrons/toolbar/extensions/FontFamily.js +28 -0
  61. package/dist/src/components/tetrons/toolbar/extensions/FontSize.d.ts +9 -0
  62. package/dist/src/components/tetrons/toolbar/extensions/FontSize.js +28 -0
  63. package/dist/src/components/tetrons/toolbar/extensions/ResizableTable.d.ts +1 -0
  64. package/dist/src/components/tetrons/toolbar/extensions/ResizableTable.js +11 -0
  65. package/dist/src/components/tetrons/toolbar/marks/Subscript.d.ts +2 -0
  66. package/dist/src/components/tetrons/toolbar/marks/Subscript.js +35 -0
  67. package/dist/src/components/tetrons/toolbar/marks/Superscript.d.ts +2 -0
  68. package/dist/src/components/tetrons/toolbar/marks/Superscript.js +35 -0
  69. package/dist/src/index.d.ts +1 -0
  70. package/dist/src/index.js +2 -0
  71. package/dist/src/lib/export.d.ts +0 -0
  72. package/dist/src/lib/export.js +1 -0
  73. package/dist/src/lib/tiptap-extensions.d.ts +0 -0
  74. package/dist/src/lib/tiptap-extensions.js +1 -0
  75. package/dist/src/utils/loadEmojiPicker.d.ts +1 -0
  76. package/dist/src/utils/loadEmojiPicker.js +12 -0
  77. package/package.json +1 -1
  78. package/src/app/api/export/route.ts +4 -0
  79. package/src/types/global.d.ts +9 -2
  80. package/tsconfig.json +57 -41
@@ -0,0 +1,32 @@
1
+ import React, { useRef, useEffect } from "react";
2
+ import { NodeViewWrapper } from "@tiptap/react";
3
+ const ResizableVideoComponent = ({ node, updateAttributes, selected, }) => {
4
+ const { src, controls, width, height } = node.attrs;
5
+ const wrapperRef = useRef(null);
6
+ const videoRef = useRef(null);
7
+ useEffect(() => {
8
+ const video = videoRef.current;
9
+ if (!video)
10
+ return;
11
+ const observer = new ResizeObserver(() => {
12
+ const w = Math.round(video.offsetWidth);
13
+ const h = Math.round(video.offsetHeight);
14
+ updateAttributes({ width: w, height: h });
15
+ });
16
+ observer.observe(video);
17
+ return () => observer.disconnect();
18
+ }, [updateAttributes]);
19
+ return (<NodeViewWrapper ref={wrapperRef} contentEditable={false} className={`resizable-video-wrapper ${selected ? "ProseMirror-selectednode" : ""}`} style={{
20
+ resize: "both",
21
+ overflow: "auto",
22
+ border: "1px solid #ccc",
23
+ padding: "2px",
24
+ display: "inline-block",
25
+ }}>
26
+ <video ref={videoRef} src={src} controls={controls} style={{
27
+ width: width ? `${width}px` : "auto",
28
+ height: height ? `${height}px` : "auto",
29
+ }}/>
30
+ </NodeViewWrapper>);
31
+ };
32
+ export default ResizableVideoComponent;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,6 @@
1
+ import { Editor } from "@tiptap/react";
2
+ type ActionGroupProps = {
3
+ editor: Editor;
4
+ };
5
+ export default function ActionGroup({ editor }: ActionGroupProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,165 @@
1
+ "use client";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { MdZoomIn, MdZoomOut, MdPrint, MdSave, MdDownload, } from "react-icons/md";
4
+ import ToolbarButton from "./ToolbarButton";
5
+ export default function ActionGroup({ editor }) {
6
+ const [dropdownOpen, setDropdownOpen] = useState(false);
7
+ const dropdownRef = useRef(null);
8
+ useEffect(() => {
9
+ const handleClickOutside = (event) => {
10
+ if (dropdownRef.current &&
11
+ !dropdownRef.current.contains(event.target)) {
12
+ setDropdownOpen(false);
13
+ }
14
+ };
15
+ if (dropdownOpen) {
16
+ document.addEventListener("mousedown", handleClickOutside);
17
+ }
18
+ else {
19
+ document.removeEventListener("mousedown", handleClickOutside);
20
+ }
21
+ return () => {
22
+ document.removeEventListener("mousedown", handleClickOutside);
23
+ };
24
+ }, [dropdownOpen]);
25
+ const zoomIn = () => {
26
+ const element = document.querySelector(".ProseMirror");
27
+ if (element) {
28
+ const currentZoom = parseFloat(element.style.zoom || "1");
29
+ const next = Math.min(currentZoom + 0.1, 2);
30
+ element.style.zoom = next.toString();
31
+ }
32
+ };
33
+ const zoomOut = () => {
34
+ const element = document.querySelector(".ProseMirror");
35
+ if (element) {
36
+ const currentZoom = parseFloat(element.style.zoom || "1");
37
+ const next = Math.max(currentZoom - 0.1, 0.5);
38
+ element.style.zoom = next.toString();
39
+ }
40
+ };
41
+ const handlePrint = () => {
42
+ const html = editor.getHTML();
43
+ const printWindow = window.open("", "_blank");
44
+ if (printWindow) {
45
+ printWindow.document.write(`
46
+ <html>
47
+ <head>
48
+ <title>Print</title>
49
+ </head>
50
+ <body>${html}</body>
51
+ </html>
52
+ `);
53
+ printWindow.document.close();
54
+ printWindow.focus();
55
+ printWindow.print();
56
+ }
57
+ };
58
+ const handleSave = async () => {
59
+ const content = editor.getJSON();
60
+ try {
61
+ const response = await fetch("/api/save", {
62
+ method: "POST",
63
+ headers: { "Content-Type": "application/json" },
64
+ body: JSON.stringify(content),
65
+ });
66
+ if (!response.ok)
67
+ throw new Error("Failed to save file");
68
+ const result = await response.json();
69
+ console.log(result.message);
70
+ alert("Content saved successfully!");
71
+ }
72
+ catch (error) {
73
+ console.error("Error saving content:", error);
74
+ alert("Failed to save content.");
75
+ }
76
+ };
77
+ const handleDownloadPDF = async () => {
78
+ const html = editor.getHTML();
79
+ const container = document.createElement("div");
80
+ container.innerHTML = html;
81
+ container.classList.add("p-4", "prose");
82
+ document.body.appendChild(container);
83
+ try {
84
+ const domToPdf = (await import("dom-to-pdf")).default;
85
+ const options = {
86
+ filename: "document.pdf",
87
+ overrideWidth: 800,
88
+ overrideHeight: 1120,
89
+ };
90
+ domToPdf(container, options, () => {
91
+ console.log("PDF downloaded!");
92
+ });
93
+ }
94
+ catch (error) {
95
+ console.error("PDF download failed", error);
96
+ alert("Failed to download PDF.");
97
+ }
98
+ finally {
99
+ document.body.removeChild(container);
100
+ }
101
+ };
102
+ const handleDownloadHTML = () => {
103
+ const html = editor.getHTML();
104
+ const blob = new Blob([html], { type: "text/html" });
105
+ const link = document.createElement("a");
106
+ link.href = URL.createObjectURL(blob);
107
+ link.download = "document.html";
108
+ document.body.appendChild(link);
109
+ link.click();
110
+ document.body.removeChild(link);
111
+ };
112
+ const handleDownloadDOCX = async () => {
113
+ const { Document, Packer, Paragraph } = await import("docx");
114
+ const text = editor.getText();
115
+ const doc = new Document({
116
+ sections: [
117
+ {
118
+ properties: {},
119
+ children: [new Paragraph(text)],
120
+ },
121
+ ],
122
+ });
123
+ const blob = await Packer.toBlob(doc);
124
+ const link = document.createElement("a");
125
+ link.href = URL.createObjectURL(blob);
126
+ link.download = "document.docx";
127
+ document.body.appendChild(link);
128
+ link.click();
129
+ document.body.removeChild(link);
130
+ };
131
+ return (<div className="relative flex items-center gap-1" role="group" aria-label="Editor actions">
132
+ <ToolbarButton icon={MdZoomIn} onClick={zoomIn} title="Zoom In"/>
133
+ <ToolbarButton icon={MdZoomOut} onClick={zoomOut} title="Zoom Out"/>
134
+ <ToolbarButton icon={MdPrint} onClick={handlePrint} title="Print"/>
135
+ <ToolbarButton icon={MdSave} onClick={handleSave} title="Save"/>
136
+
137
+ <div className="relative" ref={dropdownRef}>
138
+ <button type="button" onClick={() => setDropdownOpen((open) => !open)} aria-haspopup="menu" aria-expanded={dropdownOpen ? "true" : "false"} className="flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100 focus:outline-none" title="Export">
139
+ <MdDownload />
140
+ <span className="text-sm"></span>
141
+ </button>
142
+
143
+ {dropdownOpen && (<div className="absolute z-10 mt-2 w-40 bg-white border rounded shadow-md">
144
+ <button type="button" onClick={() => {
145
+ setDropdownOpen(false);
146
+ handleDownloadPDF();
147
+ }} className="w-full text-left px-4 py-2 hover:bg-gray-100">
148
+ Export as PDF
149
+ </button>
150
+ <button type="button" onClick={() => {
151
+ setDropdownOpen(false);
152
+ handleDownloadHTML();
153
+ }} className="w-full text-left px-4 py-2 hover:bg-gray-100">
154
+ Export as HTML
155
+ </button>
156
+ <button type="button" onClick={() => {
157
+ setDropdownOpen(false);
158
+ handleDownloadDOCX();
159
+ }} className="w-full text-left px-4 py-2 hover:bg-gray-100">
160
+ Export as DOCX
161
+ </button>
162
+ </div>)}
163
+ </div>
164
+ </div>);
165
+ }
@@ -0,0 +1,4 @@
1
+ import { Editor } from "@tiptap/react";
2
+ export default function ClipboardGroup({ editor }: {
3
+ editor: Editor;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import { MdContentPaste, MdContentCut, MdContentCopy, MdFormatPaint, } from "react-icons/md";
2
+ import ToolbarButton from "./ToolbarButton";
3
+ export default function ClipboardGroup({ editor }) {
4
+ return (<div className="flex gap-1 border-r pr-3">
5
+ <ToolbarButton icon={MdContentPaste} title="Paste" onClick={async () => {
6
+ try {
7
+ const text = await navigator.clipboard.readText();
8
+ editor.chain().focus().insertContent(text).run();
9
+ }
10
+ catch (error) {
11
+ console.error("Failed to read clipboard contents:", error);
12
+ }
13
+ }}/>
14
+ <ToolbarButton icon={MdContentCut} title="Cut" onClick={() => {
15
+ const { from, to } = editor.state.selection;
16
+ if (from === to)
17
+ return;
18
+ const selectedText = editor.state.doc.textBetween(from, to);
19
+ navigator.clipboard.writeText(selectedText).then(() => {
20
+ editor.chain().focus().deleteRange({ from, to }).run();
21
+ });
22
+ }}/>
23
+ <ToolbarButton icon={MdContentCopy} title="Copy" onClick={() => {
24
+ const { from, to } = editor.state.selection;
25
+ if (from === to)
26
+ return;
27
+ const selectedText = editor.state.doc.textBetween(from, to);
28
+ navigator.clipboard.writeText(selectedText);
29
+ }}/>
30
+ <ToolbarButton icon={MdFormatPaint} title="Format Painter" onClick={() => {
31
+ const currentMarks = editor.getAttributes("textStyle");
32
+ localStorage.setItem("formatPainter", JSON.stringify(currentMarks));
33
+ }}/>
34
+ </div>);
35
+ }
@@ -0,0 +1,6 @@
1
+ import { Editor } from "@tiptap/react";
2
+ type FileGroupProps = {
3
+ editor: Editor;
4
+ };
5
+ export default function FileGroup({ editor }: FileGroupProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { FaRegFolderOpen } from "react-icons/fa";
3
+ import { VscNewFile } from "react-icons/vsc";
4
+ import ToolbarButton from "./ToolbarButton";
5
+ import { useRef } from "react";
6
+ export default function FileGroup({ editor }) {
7
+ const fileInputRef = useRef(null);
8
+ const handleNew = () => {
9
+ if (confirm("Are you sure you want to create a new document? Unsaved changes will be lost.")) {
10
+ editor.commands.clearContent();
11
+ }
12
+ };
13
+ const handleOpen = () => {
14
+ var _a;
15
+ (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
16
+ };
17
+ const handleFileChange = async (e) => {
18
+ var _a;
19
+ const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
20
+ if (!file)
21
+ return;
22
+ try {
23
+ const text = await file.text();
24
+ const json = JSON.parse(text);
25
+ editor.commands.setContent(json);
26
+ }
27
+ catch (error) {
28
+ console.error("Error reading file:", error);
29
+ alert("Failed to open or parse the file. Make sure it's a valid JSON file.");
30
+ }
31
+ finally {
32
+ e.target.value = "";
33
+ }
34
+ };
35
+ return (<div className="flex items-center gap-1 border-r pr-3" role="group" aria-label="File actions">
36
+ <input type="file" accept=".json" ref={fileInputRef} onChange={handleFileChange} className="hidden" aria-label="Open JSON file"/>
37
+ <ToolbarButton icon={VscNewFile} onClick={handleNew} title="New"/>
38
+ <ToolbarButton icon={FaRegFolderOpen} onClick={handleOpen} title="Open File"/>
39
+ </div>);
40
+ }
@@ -0,0 +1,6 @@
1
+ import { Editor } from "@tiptap/react";
2
+ interface FontStyleGroupProps {
3
+ editor: Editor;
4
+ }
5
+ export default function FontStyleGroup({ editor }: FontStyleGroupProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ import { MdFormatBold, MdFormatItalic, MdFormatUnderlined, MdStrikethroughS, MdSubscript, MdSuperscript, MdFormatClear, MdFormatPaint, } from "react-icons/md";
3
+ import { ImTextColor } from "react-icons/im";
4
+ import { BiSolidColorFill } from "react-icons/bi";
5
+ import ToolbarButton from "./ToolbarButton";
6
+ import { useEffect, useState } from "react";
7
+ export default function FontStyleGroup({ editor }) {
8
+ const [textColor, setTextColor] = useState("#000000");
9
+ const [highlightColor, setHighlightColor] = useState("#ffff00");
10
+ const [fontFamily, setFontFamily] = useState("Arial");
11
+ const [fontSize, setFontSize] = useState("16px");
12
+ useEffect(() => {
13
+ if (!editor)
14
+ return;
15
+ const updateStates = () => {
16
+ var _a, _b, _c;
17
+ const highlight = editor.getAttributes("highlight");
18
+ setHighlightColor((highlight === null || highlight === void 0 ? void 0 : highlight.color) || "#ffff00");
19
+ const color = (_a = editor.getAttributes("textStyle")) === null || _a === void 0 ? void 0 : _a.color;
20
+ setTextColor(color || "#000000");
21
+ const fontAttr = ((_b = editor.getAttributes("fontFamily")) === null || _b === void 0 ? void 0 : _b.font) || "Arial";
22
+ setFontFamily(fontAttr);
23
+ const sizeAttr = ((_c = editor.getAttributes("fontSize")) === null || _c === void 0 ? void 0 : _c.size) || "16px";
24
+ setFontSize(sizeAttr);
25
+ };
26
+ updateStates();
27
+ editor.on("selectionUpdate", updateStates);
28
+ editor.on("transaction", updateStates);
29
+ return () => {
30
+ editor.off("selectionUpdate", updateStates);
31
+ editor.off("transaction", updateStates);
32
+ };
33
+ }, [editor]);
34
+ return (<div className="flex gap-1 border-r pr-3 items-center">
35
+ <select title="Font Family" className="text-sm border rounded px-1 py-0.5 mr-2" value={fontFamily} onChange={(e) => {
36
+ const value = e.target.value;
37
+ setFontFamily(value);
38
+ editor.chain().focus().setFontFamily(value).run();
39
+ }}>
40
+ <option value="Arial">Arial</option>
41
+ <option value="Georgia">Georgia</option>
42
+ <option value="Times New Roman">Times New Roman</option>
43
+ <option value="Courier New">Courier New</option>
44
+ <option value="Verdana">Verdana</option>
45
+ </select>
46
+
47
+ <select title="Font Size" className="text-sm border rounded px-1 py-0.5 mr-2" value={fontSize} onChange={(e) => {
48
+ const value = e.target.value;
49
+ setFontSize(value);
50
+ editor.chain().focus().setFontSize(value).run();
51
+ }}>
52
+ <option value="12px">12</option>
53
+ <option value="14px">14</option>
54
+ <option value="16px">16</option>
55
+ <option value="18px">18</option>
56
+ <option value="24px">24</option>
57
+ <option value="36px">36</option>
58
+ <option value="48px">48</option>
59
+ <option value="64px">64</option>
60
+ <option value="72px">72</option>
61
+ </select>
62
+
63
+ <ToolbarButton icon={MdFormatBold} label="Bold" onClick={() => editor.chain().focus().toggleBold().run()} isActive={editor.isActive("bold")}/>
64
+ <ToolbarButton icon={MdFormatItalic} label="Italic" onClick={() => editor.chain().focus().toggleItalic().run()} isActive={editor.isActive("italic")}/>
65
+ <ToolbarButton icon={MdFormatUnderlined} label="Underline" onClick={() => editor.chain().focus().toggleUnderline().run()} isActive={editor.isActive("underline")}/>
66
+ <ToolbarButton icon={MdStrikethroughS} label="Strikethrough" onClick={() => editor.chain().focus().toggleStrike().run()} isActive={editor.isActive("strike")}/>
67
+ <ToolbarButton icon={MdSubscript} label="Subscript" onClick={() => editor.chain().focus().toggleSubscript().run()} isActive={editor.isActive("subscript")}/>
68
+ <ToolbarButton icon={MdSuperscript} label="Superscript" onClick={() => editor.chain().focus().toggleSuperscript().run()} isActive={editor.isActive("superscript")}/>
69
+
70
+ <label title="Font Color" aria-label="Font Color" className="relative w-8 h-8 flex items-center justify-center cursor-pointer color-label" style={{ "--indicator-color": textColor }}>
71
+ <ImTextColor size={20} className="text-gray-700"/>
72
+ <div className="color-indicator"/>
73
+ <input type="color" value={textColor} onChange={(e) => {
74
+ const color = e.target.value;
75
+ setTextColor(color);
76
+ editor.chain().focus().setColor(color).run();
77
+ }} className="absolute inset-0 opacity-0 cursor-pointer"/>
78
+ </label>
79
+
80
+ <label title="Highlight Color" aria-label="Highlight Color" className="relative w-8 h-8 flex items-center justify-center cursor-pointer color-label" style={{ "--indicator-color": highlightColor }}>
81
+ <BiSolidColorFill size={20} className="text-gray-700"/>
82
+ <div className="color-indicator"/>
83
+ <input type="color" value={highlightColor} onChange={(e) => {
84
+ const color = e.target.value;
85
+ setHighlightColor(color);
86
+ editor.chain().focus().setHighlight({ color }).run();
87
+ }} className="absolute inset-0 opacity-0 cursor-pointer"/>
88
+ </label>
89
+
90
+ <ToolbarButton icon={MdFormatClear} label="Clear Formatting" onClick={() => editor.chain().focus().unsetAllMarks().run()}/>
91
+ <ToolbarButton icon={MdFormatPaint} label="Apply Painter Format" onClick={() => {
92
+ const format = JSON.parse(localStorage.getItem("formatPainter") || "{}");
93
+ if (format.color)
94
+ editor.chain().focus().setColor(format.color).run();
95
+ if (format.backgroundColor) {
96
+ editor
97
+ .chain()
98
+ .focus()
99
+ .setHighlight({ color: format.backgroundColor })
100
+ .run();
101
+ }
102
+ }}/>
103
+ </div>);
104
+ }
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import { Editor } from "@tiptap/react";
3
+ export default function InsertGroup({ editor }: {
4
+ editor: Editor;
5
+ }): React.JSX.Element;
@@ -0,0 +1,162 @@
1
+ "use client";
2
+ import React, { useRef, useState } from "react";
3
+ import { MdTableChart, MdInsertPhoto, MdInsertLink, MdInsertComment, MdInsertEmoticon, MdHorizontalRule, MdVideoLibrary, MdOutlineOndemandVideo, } from "react-icons/md";
4
+ import ToolbarButton from "./ToolbarButton";
5
+ import Picker from "@emoji-mart/react";
6
+ export default function InsertGroup({ editor }) {
7
+ const [showTableGrid, setShowTableGrid] = useState(false);
8
+ const [selectedRows, setSelectedRows] = useState(1);
9
+ const [selectedCols, setSelectedCols] = useState(1);
10
+ const imageInputRef = useRef(null);
11
+ const videoInputRef = useRef(null);
12
+ const [showPicker, setShowPicker] = useState(false);
13
+ const addEmoji = (emoji) => {
14
+ editor.chain().focus().insertContent(emoji.native).run();
15
+ setShowPicker(false);
16
+ };
17
+ const handleTableCellHover = (row, col) => {
18
+ setSelectedRows(row);
19
+ setSelectedCols(col);
20
+ };
21
+ const handleTableInsert = (rows, cols) => {
22
+ editor
23
+ .chain()
24
+ .focus()
25
+ .insertTable({
26
+ rows: rows || 1,
27
+ cols: cols || 1,
28
+ withHeaderRow: true,
29
+ })
30
+ .run();
31
+ setShowTableGrid(false);
32
+ setSelectedRows(1);
33
+ setSelectedCols(1);
34
+ };
35
+ const handleImageUpload = (e) => {
36
+ var _a;
37
+ const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
38
+ if (file) {
39
+ const reader = new FileReader();
40
+ reader.onload = () => {
41
+ editor
42
+ .chain()
43
+ .focus()
44
+ .setImage({ src: reader.result })
45
+ .run();
46
+ };
47
+ reader.readAsDataURL(file);
48
+ }
49
+ };
50
+ const handleVideoUpload = (e) => {
51
+ var _a;
52
+ const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
53
+ if (file) {
54
+ const reader = new FileReader();
55
+ reader.onload = () => {
56
+ editor
57
+ .chain()
58
+ .focus()
59
+ .setVideo({ src: reader.result, controls: true })
60
+ .run();
61
+ };
62
+ reader.readAsDataURL(file);
63
+ }
64
+ };
65
+ function normalizeEmbedUrl(url) {
66
+ try {
67
+ const u = new URL(url);
68
+ const hostname = u.hostname.replace("www.", "").toLowerCase();
69
+ if (hostname === "youtube.com" || hostname === "youtu.be") {
70
+ let videoId = u.searchParams.get("v");
71
+ if (!videoId && hostname === "youtu.be") {
72
+ videoId = u.pathname.slice(1);
73
+ }
74
+ if (videoId) {
75
+ return `https://www.youtube.com/embed/${videoId}`;
76
+ }
77
+ }
78
+ if (hostname === "vimeo.com") {
79
+ const videoId = u.pathname.split("/")[1];
80
+ if (videoId) {
81
+ return `https://player.vimeo.com/video/${videoId}`;
82
+ }
83
+ }
84
+ if (hostname === "google.com" ||
85
+ hostname === "maps.google.com" ||
86
+ hostname === "goo.gl") {
87
+ if (url.includes("/maps/embed")) {
88
+ return url;
89
+ }
90
+ return url.replace("/maps/", "/maps/embed/");
91
+ }
92
+ return url;
93
+ }
94
+ catch (_a) {
95
+ return url;
96
+ }
97
+ }
98
+ return (<div className="flex gap-1 border-r pr-3 relative">
99
+ <input type="file" accept="image/*" ref={imageInputRef} className="hidden" onChange={handleImageUpload} aria-label="Upload Image" title="Upload Image"/>
100
+ <input type="file" accept="video/*" ref={videoInputRef} className="hidden" onChange={handleVideoUpload} aria-label="Upload Video" title="Upload Video"/>
101
+
102
+ <ToolbarButton icon={MdTableChart} label="Insert Table" onClick={() => setShowTableGrid(!showTableGrid)}/>
103
+ {showTableGrid && (<div className="absolute top-10 left-0 bg-white border rounded shadow p-2 z-20" onMouseLeave={() => setShowTableGrid(false)}>
104
+ <div className="grid grid-cols-10 gap-[1px]">
105
+ {[...Array(10)].map((_, row) => [...Array(10)].map((_, col) => {
106
+ const isSelected = row < selectedRows && col < selectedCols;
107
+ return (<div key={`${row}-${col}`} className={`w-5 h-5 border cursor-pointer ${isSelected ? "bg-blue-500" : "bg-gray-100"}`} onMouseEnter={() => handleTableCellHover(row + 1, col + 1)} onClick={() => handleTableInsert(row + 1, col + 1)}/>);
108
+ }))}
109
+ </div>
110
+ <div className="text-sm mt-2 text-center text-gray-600">
111
+ {selectedRows} x {selectedCols}
112
+ </div>
113
+ </div>)}
114
+
115
+ <ToolbarButton icon={MdInsertPhoto} label="Insert Image" onClick={() => { var _a; return (_a = imageInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }}/>
116
+ <ToolbarButton icon={MdVideoLibrary} label="Insert Video" onClick={() => { var _a; return (_a = videoInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }}/>
117
+ <ToolbarButton icon={MdInsertLink} label="Insert Link" onClick={() => {
118
+ const url = prompt("Enter URL");
119
+ if (url)
120
+ editor
121
+ .chain()
122
+ .focus()
123
+ .extendMarkRange("link")
124
+ .setLink({ href: url })
125
+ .run();
126
+ }}/>
127
+ <ToolbarButton icon={MdInsertComment} label="Insert Comment" onClick={() => {
128
+ const comment = prompt("Enter your comment");
129
+ if (comment &&
130
+ editor.can().chain().focus().setComment(comment).run()) {
131
+ editor.chain().focus().setComment(comment).run();
132
+ }
133
+ else {
134
+ console.warn("Cannot apply comment — maybe no selection?");
135
+ }
136
+ }}/>
137
+ <div className="relative">
138
+ <ToolbarButton icon={MdInsertEmoticon} label="Emoji" onClick={() => setShowPicker(!showPicker)}/>
139
+ {showPicker && (<div className="absolute z-50 top-10 left-0">
140
+ <Picker onEmojiSelect={addEmoji} theme="auto" emoji="point_up" showPreview={false} showSkinTones={true} emojiTooltip={true}/>
141
+ </div>)}
142
+ </div>
143
+ <ToolbarButton icon={MdHorizontalRule} label="Horizontal Line" onClick={() => editor.chain().focus().setHorizontalRule().run()}/>
144
+ <ToolbarButton icon={MdOutlineOndemandVideo} label="Embed" onClick={() => {
145
+ const url = prompt("Enter embed URL (YouTube, Vimeo, Google Maps, etc.)");
146
+ if (!url)
147
+ return;
148
+ const embedUrl = normalizeEmbedUrl(url);
149
+ const width = prompt("Enter width in pixels", "560");
150
+ const height = prompt("Enter height in pixels", "315");
151
+ editor
152
+ .chain()
153
+ .focus()
154
+ .setEmbed({
155
+ src: embedUrl,
156
+ width: width ? parseInt(width) : 560,
157
+ height: height ? parseInt(height) : 315,
158
+ })
159
+ .run();
160
+ }}/>
161
+ </div>);
162
+ }
@@ -0,0 +1,4 @@
1
+ import { Editor } from "@tiptap/react";
2
+ export default function ListAlignGroup({ editor }: {
3
+ editor: Editor;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { MdFormatListBulleted, MdFormatListNumbered, MdFormatIndentDecrease, MdFormatIndentIncrease, MdFormatAlignLeft, MdFormatAlignCenter, MdFormatAlignRight, MdFormatAlignJustify, } from "react-icons/md";
3
+ import ToolbarButton from "./ToolbarButton";
4
+ export default function ListAlignGroup({ editor }) {
5
+ return (<div className="flex gap-1 border-r pr-3">
6
+ <ToolbarButton icon={MdFormatListBulleted} title="Bulleted List" onClick={() => editor.chain().focus().toggleBulletList().run()} disabled={!editor.can().toggleBulletList()}/>
7
+ <ToolbarButton icon={MdFormatListNumbered} title="Numbered List" onClick={() => editor.chain().focus().toggleOrderedList().run()} disabled={!editor.can().toggleOrderedList()}/>
8
+ <ToolbarButton icon={MdFormatIndentIncrease} title="Increase Indent" onClick={() => editor.chain().focus().sinkListItem("listItem").run()} disabled={!editor.can().sinkListItem("listItem")}/>
9
+ <ToolbarButton icon={MdFormatIndentDecrease} title="Decrease Indent" onClick={() => editor.chain().focus().liftListItem("listItem").run()} disabled={!editor.can().liftListItem("listItem")}/>
10
+ <ToolbarButton icon={MdFormatAlignLeft} title="Align Left" onClick={() => editor.chain().focus().setTextAlign("left").run()} disabled={!editor.can().setTextAlign("left")}/>
11
+ <ToolbarButton icon={MdFormatAlignCenter} title="Align Center" onClick={() => editor.chain().focus().setTextAlign("center").run()} disabled={!editor.can().setTextAlign("center")}/>
12
+ <ToolbarButton icon={MdFormatAlignRight} title="Align Right" onClick={() => editor.chain().focus().setTextAlign("right").run()} disabled={!editor.can().setTextAlign("right")}/>
13
+ <ToolbarButton icon={MdFormatAlignJustify} title="Justify" onClick={() => editor.chain().focus().setTextAlign("justify").run()} disabled={!editor.can().setTextAlign("justify")}/>
14
+ </div>);
15
+ }
@@ -0,0 +1,6 @@
1
+ import { Editor } from "@tiptap/react";
2
+ interface MiscGroupProps {
3
+ editor: Editor;
4
+ }
5
+ export default function MiscGroup({ editor }: MiscGroupProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,30 @@
1
+ import { MdUndo, MdRedo, MdRefresh, MdVisibility, MdCode, } from "react-icons/md";
2
+ import ToolbarButton from "./ToolbarButton";
3
+ export default function MiscGroup({ editor }) {
4
+ const handlePreview = () => {
5
+ const html = editor.getHTML();
6
+ const previewWindow = window.open("", "_blank");
7
+ if (previewWindow) {
8
+ previewWindow.document.open();
9
+ previewWindow.document.write(`
10
+ <html>
11
+ <head>
12
+ <title>Preview</title>
13
+ <style>
14
+ body { font-family: sans-serif; padding: 2rem; line-height: 1.6; }
15
+ </style>
16
+ </head>
17
+ <body>${html}</body>
18
+ </html>
19
+ `);
20
+ previewWindow.document.close();
21
+ }
22
+ };
23
+ return (<div className="flex gap-1 items-center border-r pr-3">
24
+ <ToolbarButton icon={MdUndo} label="Undo" onClick={() => editor.chain().focus().undo().run()} disabled={!editor.can().undo()}/>
25
+ <ToolbarButton icon={MdRedo} label="Redo" onClick={() => editor.chain().focus().redo().run()} disabled={!editor.can().redo()}/>
26
+ <ToolbarButton icon={MdRefresh} label="Reset Formatting" onClick={() => editor.chain().focus().unsetAllMarks().clearNodes().run()}/>
27
+ <ToolbarButton icon={MdCode} label="Toggle Code Block" onClick={() => editor.chain().focus().toggleCodeBlock().run()} isActive={editor.isActive("codeBlock")}/>
28
+ <ToolbarButton icon={MdVisibility} label="Preview" onClick={handlePreview}/>
29
+ </div>);
30
+ }
@@ -0,0 +1,6 @@
1
+ import { Editor } from "@tiptap/react";
2
+ interface ContextMenuProps {
3
+ editor: Editor;
4
+ }
5
+ export default function TableContextMenu({ editor }: ContextMenuProps): import("react").JSX.Element | null;
6
+ export {};