@refactico/pages 0.1.0
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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/index.cjs +2249 -0
- package/dist/index.d.ts +376 -0
- package/dist/index.js +2210 -0
- package/dist/style.css +1908 -0
- package/package.json +105 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
const generateId = () => {
|
|
9
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
10
|
+
return `block_${crypto.randomUUID()}`;
|
|
11
|
+
}
|
|
12
|
+
const timestamp = Date.now().toString(36);
|
|
13
|
+
const randomPart = Math.random().toString(36).substring(2, 11);
|
|
14
|
+
const counter = generateId._counter ?? 0;
|
|
15
|
+
generateId._counter = counter + 1;
|
|
16
|
+
return `block_${timestamp}_${randomPart}_${counter.toString(36)}`;
|
|
17
|
+
};
|
|
18
|
+
const createEmptyEditorData = () => ({
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
21
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22
|
+
blocks: []
|
|
23
|
+
});
|
|
24
|
+
const createTextBlock = (content = "") => ({
|
|
25
|
+
type: "text",
|
|
26
|
+
id: generateId(),
|
|
27
|
+
content,
|
|
28
|
+
fontSize: "base",
|
|
29
|
+
alignment: "left"
|
|
30
|
+
});
|
|
31
|
+
const createHeadingBlock = (level = 2, content = "") => ({
|
|
32
|
+
type: "heading",
|
|
33
|
+
id: generateId(),
|
|
34
|
+
content,
|
|
35
|
+
level,
|
|
36
|
+
alignment: "left"
|
|
37
|
+
});
|
|
38
|
+
const createImageBlock = (src = "", alt = "") => ({
|
|
39
|
+
type: "image",
|
|
40
|
+
id: generateId(),
|
|
41
|
+
src,
|
|
42
|
+
alt,
|
|
43
|
+
caption: "",
|
|
44
|
+
alignment: "center"
|
|
45
|
+
});
|
|
46
|
+
const createCodeBlock = (code = "", language = "javascript") => ({
|
|
47
|
+
type: "code",
|
|
48
|
+
id: generateId(),
|
|
49
|
+
code,
|
|
50
|
+
language,
|
|
51
|
+
showLineNumbers: true
|
|
52
|
+
});
|
|
53
|
+
const createTableBlock = (rows = 3, cols = 3) => ({
|
|
54
|
+
type: "table",
|
|
55
|
+
id: generateId(),
|
|
56
|
+
rows: Array(rows).fill(null).map(
|
|
57
|
+
(_, rowIndex) => Array(cols).fill(null).map(() => ({
|
|
58
|
+
content: "",
|
|
59
|
+
header: rowIndex === 0
|
|
60
|
+
}))
|
|
61
|
+
),
|
|
62
|
+
hasHeader: true
|
|
63
|
+
});
|
|
64
|
+
const createDividerBlock = () => ({
|
|
65
|
+
type: "divider",
|
|
66
|
+
id: generateId(),
|
|
67
|
+
style: "solid"
|
|
68
|
+
});
|
|
69
|
+
const createQuoteBlock = (content = "") => ({
|
|
70
|
+
type: "quote",
|
|
71
|
+
id: generateId(),
|
|
72
|
+
content,
|
|
73
|
+
style: "default"
|
|
74
|
+
});
|
|
75
|
+
const createListBlock = (listType = "bullet") => ({
|
|
76
|
+
type: "list",
|
|
77
|
+
id: generateId(),
|
|
78
|
+
items: [""],
|
|
79
|
+
listType,
|
|
80
|
+
checkedItems: listType === "checklist" ? [false] : void 0
|
|
81
|
+
});
|
|
82
|
+
const createCalloutBlock = (variant = "info") => ({
|
|
83
|
+
type: "callout",
|
|
84
|
+
id: generateId(),
|
|
85
|
+
content: "",
|
|
86
|
+
variant
|
|
87
|
+
});
|
|
88
|
+
const fileToBase64 = (file) => {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const reader = new FileReader();
|
|
91
|
+
reader.readAsDataURL(file);
|
|
92
|
+
reader.onload = () => resolve(reader.result);
|
|
93
|
+
reader.onerror = (error) => reject(error);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const validateEditorData = (data) => {
|
|
97
|
+
if (!data || typeof data !== "object") return false;
|
|
98
|
+
const d = data;
|
|
99
|
+
return typeof d.version === "string" && typeof d.createdAt === "string" && typeof d.updatedAt === "string" && Array.isArray(d.blocks);
|
|
100
|
+
};
|
|
101
|
+
const cloneBlock = (block) => {
|
|
102
|
+
return {
|
|
103
|
+
...JSON.parse(JSON.stringify(block)),
|
|
104
|
+
id: generateId()
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const moveArrayItem = (arr, fromIndex, toIndex) => {
|
|
108
|
+
const newArr = [...arr];
|
|
109
|
+
const [item] = newArr.splice(fromIndex, 1);
|
|
110
|
+
if (item !== void 0) {
|
|
111
|
+
newArr.splice(toIndex, 0, item);
|
|
112
|
+
}
|
|
113
|
+
return newArr;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const PlusIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "5", x2: "12", y2: "19" }),
|
|
118
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" })
|
|
119
|
+
] });
|
|
120
|
+
const TextIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "4 7 4 4 20 4 20 7" }),
|
|
122
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "9", y1: "20", x2: "15", y2: "20" }),
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "4", x2: "12", y2: "20" })
|
|
124
|
+
] });
|
|
125
|
+
const HeadingIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 4v16" }),
|
|
127
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 4v16" }),
|
|
128
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 12h12" })
|
|
129
|
+
] });
|
|
130
|
+
const ImageIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }),
|
|
132
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "8.5", cy: "8.5", r: "1.5" }),
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "21 15 16 10 5 21" })
|
|
134
|
+
] });
|
|
135
|
+
const CodeIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
136
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "16 18 22 12 16 6" }),
|
|
137
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "8 6 2 12 8 18" })
|
|
138
|
+
] });
|
|
139
|
+
const TableIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "9", x2: "21", y2: "9" }),
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "15", x2: "21", y2: "15" }),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "9", y1: "3", x2: "9", y2: "21" }),
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "15", y1: "3", x2: "15", y2: "21" })
|
|
145
|
+
] });
|
|
146
|
+
const DividerIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsx("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "12", x2: "21", y2: "12" }) });
|
|
147
|
+
const QuoteIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V21c0 1 0 1 1 1z" }),
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z" })
|
|
150
|
+
] });
|
|
151
|
+
const ListIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "8", y1: "6", x2: "21", y2: "6" }),
|
|
153
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "8", y1: "12", x2: "21", y2: "12" }),
|
|
154
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "8", y1: "18", x2: "21", y2: "18" }),
|
|
155
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "6", x2: "3.01", y2: "6" }),
|
|
156
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "12", x2: "3.01", y2: "12" }),
|
|
157
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "18", x2: "3.01", y2: "18" })
|
|
158
|
+
] });
|
|
159
|
+
const CalloutIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
160
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12", y2: "12" }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })
|
|
163
|
+
] });
|
|
164
|
+
const TrashIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "3 6 5 6 21 6" }),
|
|
166
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" })
|
|
167
|
+
] });
|
|
168
|
+
const DragIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "9", cy: "5", r: "1" }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "9", cy: "12", r: "1" }),
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "9", cy: "19", r: "1" }),
|
|
172
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "15", cy: "5", r: "1" }),
|
|
173
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "15", cy: "12", r: "1" }),
|
|
174
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "15", cy: "19", r: "1" })
|
|
175
|
+
] });
|
|
176
|
+
const CopyIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
179
|
+
] });
|
|
180
|
+
const ChevronUpIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsx("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "18 15 12 9 6 15" }) });
|
|
181
|
+
const ChevronDownIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsx("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "6 9 12 15 18 9" }) });
|
|
182
|
+
const BoldIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
183
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
|
|
184
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
|
|
185
|
+
] });
|
|
186
|
+
const ItalicIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
|
|
188
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
|
|
190
|
+
] });
|
|
191
|
+
const UnderlineIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
192
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3" }),
|
|
193
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "21", x2: "20", y2: "21" })
|
|
194
|
+
] });
|
|
195
|
+
const AlignLeftIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "17", y1: "10", x2: "3", y2: "10" }),
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "6", x2: "3", y2: "6" }),
|
|
198
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "14", x2: "3", y2: "14" }),
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "17", y1: "18", x2: "3", y2: "18" })
|
|
200
|
+
] });
|
|
201
|
+
const AlignCenterIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
202
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "10", x2: "6", y2: "10" }),
|
|
203
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "6", x2: "3", y2: "6" }),
|
|
204
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "14", x2: "3", y2: "14" }),
|
|
205
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "18", x2: "6", y2: "18" })
|
|
206
|
+
] });
|
|
207
|
+
const AlignRightIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "10", x2: "7", y2: "10" }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "6", x2: "3", y2: "6" }),
|
|
210
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "14", x2: "3", y2: "14" }),
|
|
211
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "21", y1: "18", x2: "7", y2: "18" })
|
|
212
|
+
] });
|
|
213
|
+
const CheckIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsx("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20 6 9 17 4 12" }) });
|
|
214
|
+
const UploadIcon = ({ className = "", size = 20 }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
215
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
|
|
216
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "17 8 12 3 7 8" }),
|
|
217
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "3", x2: "12", y2: "15" })
|
|
218
|
+
] });
|
|
219
|
+
|
|
220
|
+
const blockOptions = [
|
|
221
|
+
{ type: "text", label: "Text", description: "Plain text paragraph", icon: TextIcon },
|
|
222
|
+
{ type: "heading", label: "Heading", description: "Section heading", icon: HeadingIcon },
|
|
223
|
+
{ type: "image", label: "Image", description: "Upload or embed image", icon: ImageIcon },
|
|
224
|
+
{ type: "code", label: "Code", description: "Code block with syntax highlighting", icon: CodeIcon },
|
|
225
|
+
{ type: "table", label: "Table", description: "Insert a table", icon: TableIcon },
|
|
226
|
+
{ type: "list", label: "List", description: "Bullet, numbered, or checklist", icon: ListIcon },
|
|
227
|
+
{ type: "quote", label: "Quote", description: "Blockquote", icon: QuoteIcon },
|
|
228
|
+
{ type: "callout", label: "Callout", description: "Info, warning, or tip box", icon: CalloutIcon },
|
|
229
|
+
{ type: "divider", label: "Divider", description: "Horizontal line separator", icon: DividerIcon }
|
|
230
|
+
];
|
|
231
|
+
const AddBlockMenu = ({ onAdd, onClose, theme = "light" }) => {
|
|
232
|
+
const menuRef = react.useRef(null);
|
|
233
|
+
const [focusedIndex, setFocusedIndex] = react.useState(0);
|
|
234
|
+
const isDark = theme === "dark";
|
|
235
|
+
const handleKeyDown = react.useCallback((e) => {
|
|
236
|
+
switch (e.key) {
|
|
237
|
+
case "ArrowDown":
|
|
238
|
+
e.preventDefault();
|
|
239
|
+
setFocusedIndex((prev) => (prev + 1) % blockOptions.length);
|
|
240
|
+
break;
|
|
241
|
+
case "ArrowUp":
|
|
242
|
+
e.preventDefault();
|
|
243
|
+
setFocusedIndex((prev) => (prev - 1 + blockOptions.length) % blockOptions.length);
|
|
244
|
+
break;
|
|
245
|
+
case "Enter":
|
|
246
|
+
case " ": {
|
|
247
|
+
e.preventDefault();
|
|
248
|
+
const option = blockOptions[focusedIndex];
|
|
249
|
+
if (option) {
|
|
250
|
+
onAdd(option.type);
|
|
251
|
+
onClose();
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case "Escape":
|
|
256
|
+
e.preventDefault();
|
|
257
|
+
onClose();
|
|
258
|
+
break;
|
|
259
|
+
case "Tab":
|
|
260
|
+
onClose();
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}, [focusedIndex, onAdd, onClose]);
|
|
264
|
+
react.useEffect(() => {
|
|
265
|
+
const handleClickOutside = (event) => {
|
|
266
|
+
if (menuRef.current && !menuRef.current.contains(event.target)) {
|
|
267
|
+
onClose();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const handleGlobalEscape = (event) => {
|
|
271
|
+
if (event.key === "Escape") {
|
|
272
|
+
onClose();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
276
|
+
document.addEventListener("keydown", handleGlobalEscape);
|
|
277
|
+
menuRef.current?.focus();
|
|
278
|
+
return () => {
|
|
279
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
280
|
+
document.removeEventListener("keydown", handleGlobalEscape);
|
|
281
|
+
};
|
|
282
|
+
}, [onClose]);
|
|
283
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
284
|
+
"div",
|
|
285
|
+
{
|
|
286
|
+
ref: menuRef,
|
|
287
|
+
role: "menu",
|
|
288
|
+
"aria-label": "Add block menu",
|
|
289
|
+
tabIndex: 0,
|
|
290
|
+
onKeyDown: handleKeyDown,
|
|
291
|
+
className: `absolute z-50 mt-2 w-72 max-h-80 overflow-y-auto rounded-xl shadow-xl border animate-in fade-in slide-in-from-top-2 duration-200 focus:outline-none ${isDark ? "bg-slate-800 border-slate-700" : "bg-white border-slate-200"}`,
|
|
292
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-2", children: [
|
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
294
|
+
"p",
|
|
295
|
+
{
|
|
296
|
+
className: `px-3 py-2 text-xs font-semibold uppercase tracking-wider ${isDark ? "text-slate-500" : "text-slate-400"}`,
|
|
297
|
+
id: "add-block-menu-label",
|
|
298
|
+
children: "Add Block"
|
|
299
|
+
}
|
|
300
|
+
),
|
|
301
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-1", role: "group", "aria-labelledby": "add-block-menu-label", children: blockOptions.map((option, index) => {
|
|
302
|
+
const Icon = option.icon;
|
|
303
|
+
const isFocused = index === focusedIndex;
|
|
304
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
305
|
+
"button",
|
|
306
|
+
{
|
|
307
|
+
role: "menuitem",
|
|
308
|
+
type: "button",
|
|
309
|
+
tabIndex: -1,
|
|
310
|
+
onClick: () => {
|
|
311
|
+
onAdd(option.type);
|
|
312
|
+
onClose();
|
|
313
|
+
},
|
|
314
|
+
onMouseEnter: () => setFocusedIndex(index),
|
|
315
|
+
"aria-label": `Add ${option.label} block: ${option.description}`,
|
|
316
|
+
className: `w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors text-left group ${isFocused ? isDark ? "bg-slate-700" : "bg-slate-100" : isDark ? "hover:bg-slate-700" : "hover:bg-slate-50"}`,
|
|
317
|
+
children: [
|
|
318
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `flex-shrink-0 w-10 h-10 flex items-center justify-center rounded-lg transition-colors ${isDark ? "bg-slate-700 group-hover:bg-slate-600" : "bg-slate-100 group-hover:bg-slate-200"}`, children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: isDark ? "text-slate-300" : "text-slate-600", size: 20, "aria-hidden": "true" }) }),
|
|
319
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
320
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-sm font-medium ${isDark ? "text-white" : "text-slate-900"}`, children: option.label }),
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-xs truncate ${isDark ? "text-slate-400" : "text-slate-500"}`, children: option.description })
|
|
322
|
+
] })
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
option.type
|
|
326
|
+
);
|
|
327
|
+
}) })
|
|
328
|
+
] })
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const fontSizeMap = {
|
|
334
|
+
sm: "text-sm leading-relaxed",
|
|
335
|
+
base: "text-base leading-relaxed",
|
|
336
|
+
lg: "text-lg leading-relaxed",
|
|
337
|
+
xl: "text-xl leading-relaxed"
|
|
338
|
+
};
|
|
339
|
+
const alignmentMap$2 = {
|
|
340
|
+
left: "text-left",
|
|
341
|
+
center: "text-center",
|
|
342
|
+
right: "text-right",
|
|
343
|
+
justify: "text-justify"
|
|
344
|
+
};
|
|
345
|
+
const TextBlockComponent = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
346
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
347
|
+
const textareaRef = react.useRef(null);
|
|
348
|
+
const isDark = theme === "dark";
|
|
349
|
+
react.useEffect(() => {
|
|
350
|
+
if (textareaRef.current) {
|
|
351
|
+
textareaRef.current.style.height = "auto";
|
|
352
|
+
textareaRef.current.style.height = textareaRef.current.scrollHeight + "px";
|
|
353
|
+
}
|
|
354
|
+
}, [block.content]);
|
|
355
|
+
const handleChange = react.useCallback((e) => {
|
|
356
|
+
onUpdate({ ...block, content: e.target.value });
|
|
357
|
+
}, [block, onUpdate]);
|
|
358
|
+
const toggleStyle = react.useCallback((style) => {
|
|
359
|
+
onUpdate({
|
|
360
|
+
...block,
|
|
361
|
+
style: {
|
|
362
|
+
...block.style,
|
|
363
|
+
[style]: !block.style?.[style]
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}, [block, onUpdate]);
|
|
367
|
+
const setAlignment = react.useCallback((alignment) => {
|
|
368
|
+
onUpdate({ ...block, alignment });
|
|
369
|
+
}, [block, onUpdate]);
|
|
370
|
+
const setFontSize = react.useCallback((fontSize) => {
|
|
371
|
+
onUpdate({ ...block, fontSize });
|
|
372
|
+
}, [block, onUpdate]);
|
|
373
|
+
const handleFocus = react.useCallback(() => setShowToolbar(true), []);
|
|
374
|
+
const handleBlur = react.useCallback((e) => {
|
|
375
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
376
|
+
setShowToolbar(false);
|
|
377
|
+
}
|
|
378
|
+
}, []);
|
|
379
|
+
const textStyle = {
|
|
380
|
+
fontWeight: block.style?.bold ? "bold" : "normal",
|
|
381
|
+
fontStyle: block.style?.italic ? "italic" : "normal",
|
|
382
|
+
textDecoration: block.style?.underline ? "underline" : block.style?.strikethrough ? "line-through" : "none",
|
|
383
|
+
color: block.style?.color || void 0,
|
|
384
|
+
backgroundColor: block.style?.backgroundColor || "transparent"
|
|
385
|
+
};
|
|
386
|
+
const toolbarBtnClass = (isActive) => `p-2 rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-600"}`;
|
|
387
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
388
|
+
"div",
|
|
389
|
+
{
|
|
390
|
+
className: "group relative",
|
|
391
|
+
onFocus: handleFocus,
|
|
392
|
+
onBlur: handleBlur,
|
|
393
|
+
children: [
|
|
394
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
395
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
396
|
+
"button",
|
|
397
|
+
{
|
|
398
|
+
onClick: () => toggleStyle("bold"),
|
|
399
|
+
className: toolbarBtnClass(block.style?.bold),
|
|
400
|
+
title: "Bold",
|
|
401
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(BoldIcon, { size: 16 })
|
|
402
|
+
}
|
|
403
|
+
),
|
|
404
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
405
|
+
"button",
|
|
406
|
+
{
|
|
407
|
+
onClick: () => toggleStyle("italic"),
|
|
408
|
+
className: toolbarBtnClass(block.style?.italic),
|
|
409
|
+
title: "Italic",
|
|
410
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ItalicIcon, { size: 16 })
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
414
|
+
"button",
|
|
415
|
+
{
|
|
416
|
+
onClick: () => toggleStyle("underline"),
|
|
417
|
+
className: toolbarBtnClass(block.style?.underline),
|
|
418
|
+
title: "Underline",
|
|
419
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(UnderlineIcon, { size: 16 })
|
|
420
|
+
}
|
|
421
|
+
),
|
|
422
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
423
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
424
|
+
"button",
|
|
425
|
+
{
|
|
426
|
+
onClick: () => setAlignment("left"),
|
|
427
|
+
className: toolbarBtnClass(block.alignment === "left"),
|
|
428
|
+
title: "Align Left",
|
|
429
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignLeftIcon, { size: 16 })
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
433
|
+
"button",
|
|
434
|
+
{
|
|
435
|
+
onClick: () => setAlignment("center"),
|
|
436
|
+
className: toolbarBtnClass(block.alignment === "center"),
|
|
437
|
+
title: "Align Center",
|
|
438
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignCenterIcon, { size: 16 })
|
|
439
|
+
}
|
|
440
|
+
),
|
|
441
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
442
|
+
"button",
|
|
443
|
+
{
|
|
444
|
+
onClick: () => setAlignment("right"),
|
|
445
|
+
className: toolbarBtnClass(block.alignment === "right"),
|
|
446
|
+
title: "Align Right",
|
|
447
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignRightIcon, { size: 16 })
|
|
448
|
+
}
|
|
449
|
+
),
|
|
450
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
451
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
452
|
+
"select",
|
|
453
|
+
{
|
|
454
|
+
value: block.fontSize || "base",
|
|
455
|
+
onChange: (e) => setFontSize(e.target.value),
|
|
456
|
+
className: `px-2 py-1.5 text-sm rounded-lg border ${isDark ? "bg-slate-700 border-slate-600 text-slate-200" : "bg-white border-slate-200 text-slate-700"}`,
|
|
457
|
+
children: [
|
|
458
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "sm", children: "Small" }),
|
|
459
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "base", children: "Normal" }),
|
|
460
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "lg", children: "Large" }),
|
|
461
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "xl", children: "X-Large" })
|
|
462
|
+
]
|
|
463
|
+
}
|
|
464
|
+
)
|
|
465
|
+
] }),
|
|
466
|
+
readOnly ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
467
|
+
"div",
|
|
468
|
+
{
|
|
469
|
+
style: textStyle,
|
|
470
|
+
className: `w-full whitespace-pre-wrap break-words ${fontSizeMap[block.fontSize || "base"]} ${alignmentMap$2[block.alignment || "left"]} ${isDark ? "text-slate-200" : "text-slate-800"}`,
|
|
471
|
+
children: block.content || /* @__PURE__ */ jsxRuntime.jsx("span", { className: isDark ? "text-slate-500" : "text-slate-400", children: "Empty text block" })
|
|
472
|
+
}
|
|
473
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
474
|
+
"textarea",
|
|
475
|
+
{
|
|
476
|
+
ref: textareaRef,
|
|
477
|
+
value: block.content,
|
|
478
|
+
onChange: handleChange,
|
|
479
|
+
placeholder: "Start typing...",
|
|
480
|
+
style: textStyle,
|
|
481
|
+
className: `w-full min-h-[2.5rem] p-2 resize-none outline-none bg-transparent ${fontSizeMap[block.fontSize || "base"]} ${alignmentMap$2[block.alignment || "left"]} ${isDark ? "text-slate-200 placeholder:text-slate-500" : "text-slate-800 placeholder:text-slate-400"}`,
|
|
482
|
+
rows: 1
|
|
483
|
+
}
|
|
484
|
+
)
|
|
485
|
+
]
|
|
486
|
+
}
|
|
487
|
+
);
|
|
488
|
+
};
|
|
489
|
+
const TextBlock = react.memo(TextBlockComponent);
|
|
490
|
+
|
|
491
|
+
const headingSizeMap = {
|
|
492
|
+
1: "text-4xl font-bold tracking-tight",
|
|
493
|
+
2: "text-3xl font-bold tracking-tight",
|
|
494
|
+
3: "text-2xl font-semibold",
|
|
495
|
+
4: "text-xl font-semibold",
|
|
496
|
+
5: "text-lg font-medium",
|
|
497
|
+
6: "text-base font-medium"
|
|
498
|
+
};
|
|
499
|
+
const alignmentMap$1 = {
|
|
500
|
+
left: "text-left",
|
|
501
|
+
center: "text-center",
|
|
502
|
+
right: "text-right"
|
|
503
|
+
};
|
|
504
|
+
const HeadingBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
505
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
506
|
+
const inputRef = react.useRef(null);
|
|
507
|
+
const isDark = theme === "dark";
|
|
508
|
+
const handleChange = (e) => {
|
|
509
|
+
onUpdate({ ...block, content: e.target.value });
|
|
510
|
+
};
|
|
511
|
+
const setLevel = (level) => {
|
|
512
|
+
onUpdate({ ...block, level });
|
|
513
|
+
};
|
|
514
|
+
const setAlignment = (alignment) => {
|
|
515
|
+
onUpdate({ ...block, alignment });
|
|
516
|
+
};
|
|
517
|
+
const toolbarBtnClass = (isActive) => `p-2 rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-600"}`;
|
|
518
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
519
|
+
"div",
|
|
520
|
+
{
|
|
521
|
+
className: "group relative",
|
|
522
|
+
onFocus: () => setShowToolbar(true),
|
|
523
|
+
onBlur: (e) => {
|
|
524
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
525
|
+
setShowToolbar(false);
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
children: [
|
|
529
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
530
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
531
|
+
"select",
|
|
532
|
+
{
|
|
533
|
+
value: block.level,
|
|
534
|
+
onChange: (e) => setLevel(parseInt(e.target.value)),
|
|
535
|
+
className: `px-2 py-1.5 text-sm rounded-lg border ${isDark ? "bg-slate-700 border-slate-600 text-slate-200" : "bg-white border-slate-200 text-slate-700"}`,
|
|
536
|
+
children: [
|
|
537
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 1, children: "Heading 1" }),
|
|
538
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 2, children: "Heading 2" }),
|
|
539
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 3, children: "Heading 3" }),
|
|
540
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 4, children: "Heading 4" }),
|
|
541
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 5, children: "Heading 5" }),
|
|
542
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: 6, children: "Heading 6" })
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
),
|
|
546
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
547
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
548
|
+
"button",
|
|
549
|
+
{
|
|
550
|
+
onClick: () => setAlignment("left"),
|
|
551
|
+
className: toolbarBtnClass(block.alignment === "left"),
|
|
552
|
+
title: "Align Left",
|
|
553
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignLeftIcon, { size: 16 })
|
|
554
|
+
}
|
|
555
|
+
),
|
|
556
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
557
|
+
"button",
|
|
558
|
+
{
|
|
559
|
+
onClick: () => setAlignment("center"),
|
|
560
|
+
className: toolbarBtnClass(block.alignment === "center"),
|
|
561
|
+
title: "Align Center",
|
|
562
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignCenterIcon, { size: 16 })
|
|
563
|
+
}
|
|
564
|
+
),
|
|
565
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
566
|
+
"button",
|
|
567
|
+
{
|
|
568
|
+
onClick: () => setAlignment("right"),
|
|
569
|
+
className: toolbarBtnClass(block.alignment === "right"),
|
|
570
|
+
title: "Align Right",
|
|
571
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignRightIcon, { size: 16 })
|
|
572
|
+
}
|
|
573
|
+
)
|
|
574
|
+
] }),
|
|
575
|
+
readOnly ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
576
|
+
"div",
|
|
577
|
+
{
|
|
578
|
+
className: `w-full p-2 ${headingSizeMap[block.level]} ${alignmentMap$1[block.alignment || "left"]} ${isDark ? "text-white" : "text-slate-900"}`,
|
|
579
|
+
children: block.content || /* @__PURE__ */ jsxRuntime.jsx("span", { className: isDark ? "text-slate-500" : "text-slate-400", children: "Empty heading" })
|
|
580
|
+
}
|
|
581
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
582
|
+
"input",
|
|
583
|
+
{
|
|
584
|
+
ref: inputRef,
|
|
585
|
+
type: "text",
|
|
586
|
+
value: block.content,
|
|
587
|
+
onChange: handleChange,
|
|
588
|
+
placeholder: `Heading ${block.level}`,
|
|
589
|
+
className: `w-full p-2 outline-none bg-transparent ${headingSizeMap[block.level]} ${alignmentMap$1[block.alignment || "left"]} ${isDark ? "text-white placeholder:text-slate-500" : "text-slate-900 placeholder:text-slate-400"}`
|
|
590
|
+
}
|
|
591
|
+
)
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
);
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
const alignmentMap = {
|
|
598
|
+
left: "mr-auto",
|
|
599
|
+
center: "mx-auto",
|
|
600
|
+
right: "ml-auto"
|
|
601
|
+
};
|
|
602
|
+
const ImageBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
603
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
604
|
+
const [isDragging, setIsDragging] = react.useState(false);
|
|
605
|
+
const fileInputRef = react.useRef(null);
|
|
606
|
+
const isDark = theme === "dark";
|
|
607
|
+
const handleFileChange = async (file) => {
|
|
608
|
+
if (file && file.type.startsWith("image/")) {
|
|
609
|
+
try {
|
|
610
|
+
const base64 = await fileToBase64(file);
|
|
611
|
+
onUpdate({ ...block, src: base64, alt: file.name });
|
|
612
|
+
} catch (error) {
|
|
613
|
+
console.error("Error converting image to base64:", error);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const handleInputChange = (e) => {
|
|
618
|
+
const file = e.target.files?.[0];
|
|
619
|
+
if (file) {
|
|
620
|
+
handleFileChange(file);
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
const handleDrop = (e) => {
|
|
624
|
+
e.preventDefault();
|
|
625
|
+
setIsDragging(false);
|
|
626
|
+
const file = e.dataTransfer.files[0];
|
|
627
|
+
if (file) {
|
|
628
|
+
handleFileChange(file);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
const handleDragOver = (e) => {
|
|
632
|
+
e.preventDefault();
|
|
633
|
+
setIsDragging(true);
|
|
634
|
+
};
|
|
635
|
+
const handleDragLeave = () => {
|
|
636
|
+
setIsDragging(false);
|
|
637
|
+
};
|
|
638
|
+
const setAlignment = (alignment) => {
|
|
639
|
+
onUpdate({ ...block, alignment });
|
|
640
|
+
};
|
|
641
|
+
const handleCaptionChange = (e) => {
|
|
642
|
+
onUpdate({ ...block, caption: e.target.value });
|
|
643
|
+
};
|
|
644
|
+
const handleAltChange = (e) => {
|
|
645
|
+
onUpdate({ ...block, alt: e.target.value });
|
|
646
|
+
};
|
|
647
|
+
const handleWidthChange = (e) => {
|
|
648
|
+
const width = parseInt(e.target.value) || void 0;
|
|
649
|
+
onUpdate({ ...block, width });
|
|
650
|
+
};
|
|
651
|
+
const clearImage = () => {
|
|
652
|
+
onUpdate({ ...block, src: "", alt: "", caption: "" });
|
|
653
|
+
};
|
|
654
|
+
const toolbarBtnClass = (isActive) => `p-2 rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-600"}`;
|
|
655
|
+
if (!block.src) {
|
|
656
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
657
|
+
"div",
|
|
658
|
+
{
|
|
659
|
+
className: `relative border-2 border-dashed rounded-xl p-8 transition-colors ${isDragging ? isDark ? "border-indigo-500 bg-indigo-950/30" : "border-indigo-500 bg-indigo-50" : isDark ? "border-slate-700 hover:border-slate-500" : "border-slate-300 hover:border-slate-400"}`,
|
|
660
|
+
onDrop: handleDrop,
|
|
661
|
+
onDragOver: handleDragOver,
|
|
662
|
+
onDragLeave: handleDragLeave,
|
|
663
|
+
children: [
|
|
664
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
665
|
+
"input",
|
|
666
|
+
{
|
|
667
|
+
ref: fileInputRef,
|
|
668
|
+
type: "file",
|
|
669
|
+
accept: "image/*",
|
|
670
|
+
onChange: handleInputChange,
|
|
671
|
+
className: "hidden"
|
|
672
|
+
}
|
|
673
|
+
),
|
|
674
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center text-center", children: [
|
|
675
|
+
/* @__PURE__ */ jsxRuntime.jsx(UploadIcon, { className: `w-12 h-12 mb-4 ${isDark ? "text-slate-500" : "text-slate-400"}` }),
|
|
676
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `mb-2 ${isDark ? "text-slate-400" : "text-slate-600"}`, children: "Drag and drop an image here, or" }),
|
|
677
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
678
|
+
"button",
|
|
679
|
+
{
|
|
680
|
+
onClick: () => fileInputRef.current?.click(),
|
|
681
|
+
className: "px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors font-medium",
|
|
682
|
+
disabled: readOnly,
|
|
683
|
+
children: "Browse Files"
|
|
684
|
+
}
|
|
685
|
+
),
|
|
686
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-xs mt-2 ${isDark ? "text-slate-500" : "text-slate-500"}`, children: "PNG, JPG, GIF up to 10MB" })
|
|
687
|
+
] })
|
|
688
|
+
]
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
693
|
+
"div",
|
|
694
|
+
{
|
|
695
|
+
className: "group relative",
|
|
696
|
+
onFocus: () => setShowToolbar(true),
|
|
697
|
+
onBlur: (e) => {
|
|
698
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
699
|
+
setShowToolbar(false);
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
children: [
|
|
703
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-1/2 -translate-x-1/2 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
704
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
705
|
+
"button",
|
|
706
|
+
{
|
|
707
|
+
onClick: () => setAlignment("left"),
|
|
708
|
+
className: toolbarBtnClass(block.alignment === "left"),
|
|
709
|
+
title: "Align Left",
|
|
710
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignLeftIcon, { size: 16 })
|
|
711
|
+
}
|
|
712
|
+
),
|
|
713
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
714
|
+
"button",
|
|
715
|
+
{
|
|
716
|
+
onClick: () => setAlignment("center"),
|
|
717
|
+
className: toolbarBtnClass(block.alignment === "center"),
|
|
718
|
+
title: "Align Center",
|
|
719
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignCenterIcon, { size: 16 })
|
|
720
|
+
}
|
|
721
|
+
),
|
|
722
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
723
|
+
"button",
|
|
724
|
+
{
|
|
725
|
+
onClick: () => setAlignment("right"),
|
|
726
|
+
className: toolbarBtnClass(block.alignment === "right"),
|
|
727
|
+
title: "Align Right",
|
|
728
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AlignRightIcon, { size: 16 })
|
|
729
|
+
}
|
|
730
|
+
),
|
|
731
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
732
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
733
|
+
"input",
|
|
734
|
+
{
|
|
735
|
+
type: "number",
|
|
736
|
+
value: block.width || "",
|
|
737
|
+
onChange: handleWidthChange,
|
|
738
|
+
placeholder: "Width",
|
|
739
|
+
className: `w-20 px-2 py-1.5 text-sm rounded-lg border ${isDark ? "bg-slate-700 border-slate-600 text-slate-200" : "bg-white border-slate-200 text-slate-700"}`
|
|
740
|
+
}
|
|
741
|
+
),
|
|
742
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
743
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
744
|
+
"button",
|
|
745
|
+
{
|
|
746
|
+
onClick: clearImage,
|
|
747
|
+
className: `p-2 rounded-lg hover:text-red-500 ${isDark ? "hover:bg-red-950/30 text-slate-400" : "hover:bg-red-50 text-slate-400"}`,
|
|
748
|
+
title: "Remove Image",
|
|
749
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, { size: 16 })
|
|
750
|
+
}
|
|
751
|
+
)
|
|
752
|
+
] }),
|
|
753
|
+
/* @__PURE__ */ jsxRuntime.jsxs("figure", { className: `${alignmentMap[block.alignment || "center"]}`, style: { maxWidth: block.width ? `${block.width}px` : "100%" }, children: [
|
|
754
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
755
|
+
"img",
|
|
756
|
+
{
|
|
757
|
+
src: block.src,
|
|
758
|
+
alt: block.alt || "",
|
|
759
|
+
className: "max-w-full h-auto rounded-xl shadow-sm"
|
|
760
|
+
}
|
|
761
|
+
),
|
|
762
|
+
!readOnly ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 space-y-2", children: [
|
|
763
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
764
|
+
"input",
|
|
765
|
+
{
|
|
766
|
+
type: "text",
|
|
767
|
+
value: block.caption || "",
|
|
768
|
+
onChange: handleCaptionChange,
|
|
769
|
+
placeholder: "Add a caption...",
|
|
770
|
+
className: `w-full text-center text-sm bg-transparent outline-none ${isDark ? "text-slate-400 placeholder:text-slate-500" : "text-slate-600 placeholder:text-slate-400"}`
|
|
771
|
+
}
|
|
772
|
+
),
|
|
773
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
774
|
+
"input",
|
|
775
|
+
{
|
|
776
|
+
type: "text",
|
|
777
|
+
value: block.alt || "",
|
|
778
|
+
onChange: handleAltChange,
|
|
779
|
+
placeholder: "Alt text for accessibility...",
|
|
780
|
+
className: `w-full text-center text-xs bg-transparent outline-none ${isDark ? "text-slate-500 placeholder:text-slate-600" : "text-slate-500 placeholder:text-slate-400"}`
|
|
781
|
+
}
|
|
782
|
+
)
|
|
783
|
+
] }) : block.caption ? /* @__PURE__ */ jsxRuntime.jsx("figcaption", { className: `mt-3 text-center text-sm ${isDark ? "text-slate-400" : "text-slate-600"}`, children: block.caption }) : null
|
|
784
|
+
] })
|
|
785
|
+
]
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
const SUPPORTED_LANGUAGES = [
|
|
791
|
+
"javascript",
|
|
792
|
+
"typescript",
|
|
793
|
+
"python",
|
|
794
|
+
"java",
|
|
795
|
+
"csharp",
|
|
796
|
+
"cpp",
|
|
797
|
+
"c",
|
|
798
|
+
"go",
|
|
799
|
+
"rust",
|
|
800
|
+
"ruby",
|
|
801
|
+
"php",
|
|
802
|
+
"swift",
|
|
803
|
+
"kotlin",
|
|
804
|
+
"scala",
|
|
805
|
+
"html",
|
|
806
|
+
"css",
|
|
807
|
+
"scss",
|
|
808
|
+
"json",
|
|
809
|
+
"yaml",
|
|
810
|
+
"xml",
|
|
811
|
+
"markdown",
|
|
812
|
+
"sql",
|
|
813
|
+
"bash",
|
|
814
|
+
"shell",
|
|
815
|
+
"powershell",
|
|
816
|
+
"dockerfile",
|
|
817
|
+
"plaintext"
|
|
818
|
+
];
|
|
819
|
+
|
|
820
|
+
const CodeBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
821
|
+
const [copied, setCopied] = react.useState(false);
|
|
822
|
+
const textareaRef = react.useRef(null);
|
|
823
|
+
const isDark = theme === "dark";
|
|
824
|
+
const handleCodeChange = (e) => {
|
|
825
|
+
onUpdate({ ...block, code: e.target.value });
|
|
826
|
+
if (textareaRef.current) {
|
|
827
|
+
textareaRef.current.style.height = "auto";
|
|
828
|
+
textareaRef.current.style.height = textareaRef.current.scrollHeight + "px";
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
const handleLanguageChange = (e) => {
|
|
832
|
+
onUpdate({ ...block, language: e.target.value });
|
|
833
|
+
};
|
|
834
|
+
const handleFilenameChange = (e) => {
|
|
835
|
+
onUpdate({ ...block, filename: e.target.value });
|
|
836
|
+
};
|
|
837
|
+
const toggleLineNumbers = () => {
|
|
838
|
+
onUpdate({ ...block, showLineNumbers: !block.showLineNumbers });
|
|
839
|
+
};
|
|
840
|
+
const copyToClipboard = async () => {
|
|
841
|
+
try {
|
|
842
|
+
await navigator.clipboard.writeText(block.code);
|
|
843
|
+
setCopied(true);
|
|
844
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
845
|
+
} catch (error) {
|
|
846
|
+
console.error("Failed to copy:", error);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
const lines = block.code.split("\n");
|
|
850
|
+
const lineNumbers = lines.map((_, i) => i + 1);
|
|
851
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
852
|
+
"div",
|
|
853
|
+
{
|
|
854
|
+
className: `group relative rounded-xl overflow-hidden ${isDark ? "bg-slate-950" : "bg-slate-900"}`,
|
|
855
|
+
children: [
|
|
856
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex items-center justify-between px-4 py-2.5 border-b ${isDark ? "bg-slate-900 border-slate-800" : "bg-slate-800 border-slate-700"}`, children: [
|
|
857
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
858
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-1.5", children: [
|
|
859
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-3 h-3 rounded-full bg-red-500/80" }),
|
|
860
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-3 h-3 rounded-full bg-yellow-500/80" }),
|
|
861
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-3 h-3 rounded-full bg-green-500/80" })
|
|
862
|
+
] }),
|
|
863
|
+
!readOnly ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
864
|
+
"input",
|
|
865
|
+
{
|
|
866
|
+
type: "text",
|
|
867
|
+
value: block.filename || "",
|
|
868
|
+
onChange: handleFilenameChange,
|
|
869
|
+
placeholder: "filename.js",
|
|
870
|
+
className: "text-sm text-slate-400 bg-transparent outline-none placeholder:text-slate-600 w-32"
|
|
871
|
+
}
|
|
872
|
+
) : block.filename ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-slate-400", children: block.filename }) : null
|
|
873
|
+
] }),
|
|
874
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
875
|
+
!readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
876
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
877
|
+
"select",
|
|
878
|
+
{
|
|
879
|
+
value: block.language,
|
|
880
|
+
onChange: handleLanguageChange,
|
|
881
|
+
className: "text-xs px-2 py-1.5 bg-slate-700 text-slate-300 rounded-lg border border-slate-600 outline-none",
|
|
882
|
+
children: SUPPORTED_LANGUAGES.map((lang) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: lang, children: lang }, lang))
|
|
883
|
+
}
|
|
884
|
+
),
|
|
885
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
886
|
+
"button",
|
|
887
|
+
{
|
|
888
|
+
onClick: toggleLineNumbers,
|
|
889
|
+
className: `text-xs px-2 py-1.5 rounded-lg transition-colors ${block.showLineNumbers ? "bg-indigo-600 text-white" : "bg-slate-700 text-slate-300 hover:bg-slate-600"}`,
|
|
890
|
+
children: "#"
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] }),
|
|
894
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
895
|
+
"button",
|
|
896
|
+
{
|
|
897
|
+
onClick: copyToClipboard,
|
|
898
|
+
className: "p-1.5 rounded-lg hover:bg-slate-700 text-slate-400 hover:text-white transition-colors",
|
|
899
|
+
title: "Copy code",
|
|
900
|
+
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, { size: 16 }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { size: 16 })
|
|
901
|
+
}
|
|
902
|
+
)
|
|
903
|
+
] })
|
|
904
|
+
] }),
|
|
905
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex overflow-x-auto", children: [
|
|
906
|
+
block.showLineNumbers && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-shrink-0 py-4 pl-4 pr-3 text-right select-none border-r border-slate-800", children: lineNumbers.map((num) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-slate-600 leading-6 font-mono", children: num }, num)) }),
|
|
907
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 p-4 overflow-x-auto", children: readOnly ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-sm text-slate-100 font-mono leading-6 whitespace-pre", children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: block.code }) }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
908
|
+
"textarea",
|
|
909
|
+
{
|
|
910
|
+
ref: textareaRef,
|
|
911
|
+
value: block.code,
|
|
912
|
+
onChange: handleCodeChange,
|
|
913
|
+
placeholder: "// Write your code here...",
|
|
914
|
+
spellCheck: false,
|
|
915
|
+
className: "w-full min-h-[100px] text-sm text-slate-100 font-mono leading-6 bg-transparent outline-none resize-none placeholder:text-slate-600",
|
|
916
|
+
style: { tabSize: 2 },
|
|
917
|
+
onKeyDown: (e) => {
|
|
918
|
+
if (e.key === "Tab") {
|
|
919
|
+
e.preventDefault();
|
|
920
|
+
const start = e.currentTarget.selectionStart;
|
|
921
|
+
const end = e.currentTarget.selectionEnd;
|
|
922
|
+
const newValue = block.code.substring(0, start) + " " + block.code.substring(end);
|
|
923
|
+
onUpdate({ ...block, code: newValue });
|
|
924
|
+
setTimeout(() => {
|
|
925
|
+
if (textareaRef.current) {
|
|
926
|
+
textareaRef.current.selectionStart = textareaRef.current.selectionEnd = start + 2;
|
|
927
|
+
}
|
|
928
|
+
}, 0);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
) })
|
|
933
|
+
] }),
|
|
934
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute bottom-2 right-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-slate-500 uppercase font-medium", children: block.language }) })
|
|
935
|
+
]
|
|
936
|
+
}
|
|
937
|
+
);
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
const TableBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
941
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
942
|
+
const [selectedCell, setSelectedCell] = react.useState(null);
|
|
943
|
+
const isDark = theme === "dark";
|
|
944
|
+
const updateCell = (rowIndex, colIndex, content) => {
|
|
945
|
+
const currentRow = block.rows[rowIndex];
|
|
946
|
+
if (!currentRow) return;
|
|
947
|
+
const currentCell = currentRow[colIndex];
|
|
948
|
+
if (!currentCell) return;
|
|
949
|
+
const newRows = [...block.rows];
|
|
950
|
+
newRows[rowIndex] = [...currentRow];
|
|
951
|
+
newRows[rowIndex][colIndex] = { ...currentCell, content };
|
|
952
|
+
onUpdate({ ...block, rows: newRows });
|
|
953
|
+
};
|
|
954
|
+
const addRow = () => {
|
|
955
|
+
const colCount = block.rows[0]?.length || 3;
|
|
956
|
+
const newRow = Array(colCount).fill(null).map(() => ({ content: "" }));
|
|
957
|
+
onUpdate({ ...block, rows: [...block.rows, newRow] });
|
|
958
|
+
};
|
|
959
|
+
const addColumn = () => {
|
|
960
|
+
const newRows = block.rows.map((row, rowIndex) => [
|
|
961
|
+
...row,
|
|
962
|
+
{ content: "", header: rowIndex === 0 && block.hasHeader }
|
|
963
|
+
]);
|
|
964
|
+
onUpdate({ ...block, rows: newRows });
|
|
965
|
+
};
|
|
966
|
+
const deleteRow = (rowIndex) => {
|
|
967
|
+
if (block.rows.length <= 1) return;
|
|
968
|
+
const newRows = block.rows.filter((_, i) => i !== rowIndex);
|
|
969
|
+
onUpdate({ ...block, rows: newRows });
|
|
970
|
+
};
|
|
971
|
+
const deleteColumn = (colIndex) => {
|
|
972
|
+
if ((block.rows[0]?.length ?? 0) <= 1) return;
|
|
973
|
+
const newRows = block.rows.map((row) => row.filter((_, i) => i !== colIndex));
|
|
974
|
+
onUpdate({ ...block, rows: newRows });
|
|
975
|
+
};
|
|
976
|
+
const toggleHeader = () => {
|
|
977
|
+
const newRows = block.rows.map(
|
|
978
|
+
(row, rowIndex) => row.map((cell) => ({
|
|
979
|
+
...cell,
|
|
980
|
+
header: rowIndex === 0 ? !block.hasHeader : false
|
|
981
|
+
}))
|
|
982
|
+
);
|
|
983
|
+
onUpdate({ ...block, rows: newRows, hasHeader: !block.hasHeader });
|
|
984
|
+
};
|
|
985
|
+
const setCellAlignment = (alignment) => {
|
|
986
|
+
if (!selectedCell) return;
|
|
987
|
+
const currentRow = block.rows[selectedCell.row];
|
|
988
|
+
if (!currentRow) return;
|
|
989
|
+
const currentCell = currentRow[selectedCell.col];
|
|
990
|
+
if (!currentCell) return;
|
|
991
|
+
const newRows = [...block.rows];
|
|
992
|
+
const newRow = [...currentRow];
|
|
993
|
+
newRow[selectedCell.col] = {
|
|
994
|
+
...currentCell,
|
|
995
|
+
alignment
|
|
996
|
+
};
|
|
997
|
+
newRows[selectedCell.row] = newRow;
|
|
998
|
+
onUpdate({ ...block, rows: newRows });
|
|
999
|
+
};
|
|
1000
|
+
const toolbarBtnClass = (isActive) => `px-2 py-1 text-sm rounded-lg transition-colors ${isActive ? isDark ? "bg-indigo-900/50 text-indigo-400" : "bg-indigo-100 text-indigo-600" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-700"}`;
|
|
1001
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1002
|
+
"div",
|
|
1003
|
+
{
|
|
1004
|
+
className: "group relative",
|
|
1005
|
+
onFocus: () => setShowToolbar(true),
|
|
1006
|
+
onBlur: (e) => {
|
|
1007
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
1008
|
+
setShowToolbar(false);
|
|
1009
|
+
}
|
|
1010
|
+
},
|
|
1011
|
+
children: [
|
|
1012
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
1013
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1014
|
+
"button",
|
|
1015
|
+
{
|
|
1016
|
+
onClick: addRow,
|
|
1017
|
+
className: `flex items-center gap-1 ${toolbarBtnClass()}`,
|
|
1018
|
+
title: "Add Row",
|
|
1019
|
+
children: [
|
|
1020
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 14 }),
|
|
1021
|
+
" Row"
|
|
1022
|
+
]
|
|
1023
|
+
}
|
|
1024
|
+
),
|
|
1025
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1026
|
+
"button",
|
|
1027
|
+
{
|
|
1028
|
+
onClick: addColumn,
|
|
1029
|
+
className: `flex items-center gap-1 ${toolbarBtnClass()}`,
|
|
1030
|
+
title: "Add Column",
|
|
1031
|
+
children: [
|
|
1032
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 14 }),
|
|
1033
|
+
" Col"
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
),
|
|
1037
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
1038
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1039
|
+
"button",
|
|
1040
|
+
{
|
|
1041
|
+
onClick: toggleHeader,
|
|
1042
|
+
className: toolbarBtnClass(block.hasHeader),
|
|
1043
|
+
children: "Header"
|
|
1044
|
+
}
|
|
1045
|
+
),
|
|
1046
|
+
selectedCell && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1047
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}` }),
|
|
1048
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1049
|
+
"button",
|
|
1050
|
+
{
|
|
1051
|
+
onClick: () => setCellAlignment("left"),
|
|
1052
|
+
className: toolbarBtnClass(),
|
|
1053
|
+
children: "Left"
|
|
1054
|
+
}
|
|
1055
|
+
),
|
|
1056
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1057
|
+
"button",
|
|
1058
|
+
{
|
|
1059
|
+
onClick: () => setCellAlignment("center"),
|
|
1060
|
+
className: toolbarBtnClass(),
|
|
1061
|
+
children: "Center"
|
|
1062
|
+
}
|
|
1063
|
+
),
|
|
1064
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1065
|
+
"button",
|
|
1066
|
+
{
|
|
1067
|
+
onClick: () => setCellAlignment("right"),
|
|
1068
|
+
className: toolbarBtnClass(),
|
|
1069
|
+
children: "Right"
|
|
1070
|
+
}
|
|
1071
|
+
)
|
|
1072
|
+
] })
|
|
1073
|
+
] }),
|
|
1074
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto rounded-xl", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: `w-full border-collapse border ${isDark ? "border-slate-600" : "border-slate-300"}`, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "group/row", children: [
|
|
1075
|
+
row.map((cell, colIndex) => {
|
|
1076
|
+
const isHeader = block.hasHeader && rowIndex === 0;
|
|
1077
|
+
const CellTag = isHeader ? "th" : "td";
|
|
1078
|
+
const alignClass = cell.alignment === "center" ? "text-center" : cell.alignment === "right" ? "text-right" : "text-left";
|
|
1079
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1080
|
+
CellTag,
|
|
1081
|
+
{
|
|
1082
|
+
className: `relative border p-0 ${isDark ? "border-slate-600" : "border-slate-300"} ${isHeader ? isDark ? "bg-slate-800 font-semibold" : "bg-slate-100 font-semibold" : isDark ? "bg-slate-900" : "bg-white"} ${alignClass}`,
|
|
1083
|
+
children: [
|
|
1084
|
+
readOnly ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: `px-3 py-2 min-h-[40px] ${isDark ? "text-slate-200" : "text-slate-700"}`, children: cell.content }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1085
|
+
"input",
|
|
1086
|
+
{
|
|
1087
|
+
type: "text",
|
|
1088
|
+
value: cell.content,
|
|
1089
|
+
onChange: (e) => updateCell(rowIndex, colIndex, e.target.value),
|
|
1090
|
+
onFocus: () => setSelectedCell({ row: rowIndex, col: colIndex }),
|
|
1091
|
+
onBlur: () => setSelectedCell(null),
|
|
1092
|
+
className: `w-full px-3 py-2 min-h-[40px] outline-none bg-transparent ${alignClass} ${isHeader ? "font-semibold" : ""} ${isDark ? "text-slate-200 placeholder:text-slate-500" : "text-slate-700 placeholder:text-slate-400"} focus:ring-2 focus:ring-indigo-500 focus:ring-inset`,
|
|
1093
|
+
placeholder: isHeader ? "Header" : ""
|
|
1094
|
+
}
|
|
1095
|
+
),
|
|
1096
|
+
!readOnly && rowIndex === 0 && showToolbar && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1097
|
+
"button",
|
|
1098
|
+
{
|
|
1099
|
+
onClick: () => deleteColumn(colIndex),
|
|
1100
|
+
className: "absolute -top-6 left-1/2 -translate-x-1/2 p-1 rounded-lg bg-red-500 text-white opacity-0 group-hover:opacity-100 transition-opacity",
|
|
1101
|
+
title: "Delete Column",
|
|
1102
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, { size: 12 })
|
|
1103
|
+
}
|
|
1104
|
+
)
|
|
1105
|
+
]
|
|
1106
|
+
},
|
|
1107
|
+
colIndex
|
|
1108
|
+
);
|
|
1109
|
+
}),
|
|
1110
|
+
!readOnly && showToolbar && /* @__PURE__ */ jsxRuntime.jsx("td", { className: "w-8 border-none bg-transparent p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1111
|
+
"button",
|
|
1112
|
+
{
|
|
1113
|
+
onClick: () => deleteRow(rowIndex),
|
|
1114
|
+
className: "p-1 rounded-lg bg-red-500 text-white opacity-0 group-hover/row:opacity-100 transition-opacity",
|
|
1115
|
+
title: "Delete Row",
|
|
1116
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, { size: 12 })
|
|
1117
|
+
}
|
|
1118
|
+
) })
|
|
1119
|
+
] }, rowIndex)) }) }) })
|
|
1120
|
+
]
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
const styleMap = {
|
|
1126
|
+
solid: "border-solid",
|
|
1127
|
+
dashed: "border-dashed",
|
|
1128
|
+
dotted: "border-dotted"
|
|
1129
|
+
};
|
|
1130
|
+
const DividerBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
1131
|
+
const isDark = theme === "dark";
|
|
1132
|
+
const cycleStyle = () => {
|
|
1133
|
+
if (readOnly) return;
|
|
1134
|
+
const styles = ["solid", "dashed", "dotted"];
|
|
1135
|
+
const currentIndex = styles.indexOf(block.style || "solid");
|
|
1136
|
+
const nextIndex = (currentIndex + 1) % styles.length;
|
|
1137
|
+
onUpdate({ ...block, style: styles[nextIndex] });
|
|
1138
|
+
};
|
|
1139
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-4 group", children: [
|
|
1140
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1141
|
+
"hr",
|
|
1142
|
+
{
|
|
1143
|
+
onClick: cycleStyle,
|
|
1144
|
+
className: `border-t-2 ${styleMap[block.style || "solid"]} ${isDark ? "border-slate-700" + (!readOnly ? " hover:border-slate-500" : "") : "border-slate-200" + (!readOnly ? " hover:border-slate-400" : "")} ${!readOnly ? "cursor-pointer" : ""}`
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
!readOnly && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: `text-xs text-center mt-1 opacity-0 group-hover:opacity-100 transition-opacity ${isDark ? "text-slate-500" : "text-slate-400"}`, children: [
|
|
1148
|
+
"Click to change style (",
|
|
1149
|
+
block.style || "solid",
|
|
1150
|
+
")"
|
|
1151
|
+
] })
|
|
1152
|
+
] });
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
const QuoteBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
1156
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
1157
|
+
const textareaRef = react.useRef(null);
|
|
1158
|
+
const isDark = theme === "dark";
|
|
1159
|
+
const styleClasses = {
|
|
1160
|
+
default: `border-l-4 pl-4 italic ${isDark ? "border-slate-600" : "border-slate-300"}`,
|
|
1161
|
+
bordered: `border-l-4 pl-4 py-3 rounded-r ${isDark ? "border-indigo-500 bg-indigo-950/30" : "border-indigo-500 bg-indigo-50"}`,
|
|
1162
|
+
modern: `relative pl-10 before:content-['"'] before:absolute before:left-0 before:top-0 before:text-5xl before:leading-none ${isDark ? "before:text-slate-600" : "before:text-slate-300"}`
|
|
1163
|
+
};
|
|
1164
|
+
react.useEffect(() => {
|
|
1165
|
+
if (textareaRef.current) {
|
|
1166
|
+
textareaRef.current.style.height = "auto";
|
|
1167
|
+
textareaRef.current.style.height = textareaRef.current.scrollHeight + "px";
|
|
1168
|
+
}
|
|
1169
|
+
}, [block.content]);
|
|
1170
|
+
const handleContentChange = (e) => {
|
|
1171
|
+
onUpdate({ ...block, content: e.target.value });
|
|
1172
|
+
};
|
|
1173
|
+
const handleAuthorChange = (e) => {
|
|
1174
|
+
onUpdate({ ...block, author: e.target.value });
|
|
1175
|
+
};
|
|
1176
|
+
const setStyle = (style) => {
|
|
1177
|
+
onUpdate({ ...block, style });
|
|
1178
|
+
};
|
|
1179
|
+
const toolbarBtnClass = (isActive) => `px-3 py-1.5 text-sm rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-600"}`;
|
|
1180
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1181
|
+
"div",
|
|
1182
|
+
{
|
|
1183
|
+
className: "group relative",
|
|
1184
|
+
onFocus: () => setShowToolbar(true),
|
|
1185
|
+
onBlur: (e) => {
|
|
1186
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
1187
|
+
setShowToolbar(false);
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
children: [
|
|
1191
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
1192
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1193
|
+
"button",
|
|
1194
|
+
{
|
|
1195
|
+
onClick: () => setStyle("default"),
|
|
1196
|
+
className: toolbarBtnClass(block.style === "default" || !block.style),
|
|
1197
|
+
children: "Simple"
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1201
|
+
"button",
|
|
1202
|
+
{
|
|
1203
|
+
onClick: () => setStyle("bordered"),
|
|
1204
|
+
className: toolbarBtnClass(block.style === "bordered"),
|
|
1205
|
+
children: "Bordered"
|
|
1206
|
+
}
|
|
1207
|
+
),
|
|
1208
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1209
|
+
"button",
|
|
1210
|
+
{
|
|
1211
|
+
onClick: () => setStyle("modern"),
|
|
1212
|
+
className: toolbarBtnClass(block.style === "modern"),
|
|
1213
|
+
children: "Modern"
|
|
1214
|
+
}
|
|
1215
|
+
)
|
|
1216
|
+
] }),
|
|
1217
|
+
/* @__PURE__ */ jsxRuntime.jsx("blockquote", { className: `${styleClasses[block.style || "default"]} ${isDark ? "text-slate-300" : "text-slate-700"}`, children: readOnly ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1218
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-lg leading-relaxed whitespace-pre-wrap", children: block.content }),
|
|
1219
|
+
block.author && /* @__PURE__ */ jsxRuntime.jsxs("cite", { className: `block mt-3 text-sm not-italic ${isDark ? "text-slate-400" : "text-slate-500"}`, children: [
|
|
1220
|
+
"— ",
|
|
1221
|
+
block.author
|
|
1222
|
+
] })
|
|
1223
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1224
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1225
|
+
"textarea",
|
|
1226
|
+
{
|
|
1227
|
+
ref: textareaRef,
|
|
1228
|
+
value: block.content,
|
|
1229
|
+
onChange: handleContentChange,
|
|
1230
|
+
placeholder: "Enter quote...",
|
|
1231
|
+
className: `w-full text-lg leading-relaxed bg-transparent outline-none resize-none ${isDark ? "placeholder:text-slate-500" : "placeholder:text-slate-400"}`,
|
|
1232
|
+
rows: 1
|
|
1233
|
+
}
|
|
1234
|
+
),
|
|
1235
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1236
|
+
"input",
|
|
1237
|
+
{
|
|
1238
|
+
type: "text",
|
|
1239
|
+
value: block.author || "",
|
|
1240
|
+
onChange: handleAuthorChange,
|
|
1241
|
+
placeholder: "— Author name",
|
|
1242
|
+
className: `w-full mt-2 text-sm bg-transparent outline-none ${isDark ? "text-slate-400 placeholder:text-slate-500" : "text-slate-500 placeholder:text-slate-400"}`
|
|
1243
|
+
}
|
|
1244
|
+
)
|
|
1245
|
+
] }) })
|
|
1246
|
+
]
|
|
1247
|
+
}
|
|
1248
|
+
);
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
const ListBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
1252
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
1253
|
+
const isDark = theme === "dark";
|
|
1254
|
+
const updateItem = (index, value) => {
|
|
1255
|
+
const newItems = [...block.items];
|
|
1256
|
+
newItems[index] = value;
|
|
1257
|
+
onUpdate({ ...block, items: newItems });
|
|
1258
|
+
};
|
|
1259
|
+
const addItem = (afterIndex) => {
|
|
1260
|
+
const newItems = [...block.items];
|
|
1261
|
+
const insertIndex = afterIndex !== void 0 ? afterIndex + 1 : newItems.length;
|
|
1262
|
+
newItems.splice(insertIndex, 0, "");
|
|
1263
|
+
const newCheckedItems = block.checkedItems ? [...block.checkedItems] : void 0;
|
|
1264
|
+
if (newCheckedItems) {
|
|
1265
|
+
newCheckedItems.splice(insertIndex, 0, false);
|
|
1266
|
+
}
|
|
1267
|
+
onUpdate({ ...block, items: newItems, checkedItems: newCheckedItems });
|
|
1268
|
+
};
|
|
1269
|
+
const removeItem = (index) => {
|
|
1270
|
+
if (block.items.length <= 1) return;
|
|
1271
|
+
const newItems = block.items.filter((_, i) => i !== index);
|
|
1272
|
+
const newCheckedItems = block.checkedItems?.filter((_, i) => i !== index);
|
|
1273
|
+
onUpdate({ ...block, items: newItems, checkedItems: newCheckedItems });
|
|
1274
|
+
};
|
|
1275
|
+
const toggleChecked = (index) => {
|
|
1276
|
+
if (!block.checkedItems) return;
|
|
1277
|
+
const newCheckedItems = [...block.checkedItems];
|
|
1278
|
+
newCheckedItems[index] = !newCheckedItems[index];
|
|
1279
|
+
onUpdate({ ...block, checkedItems: newCheckedItems });
|
|
1280
|
+
};
|
|
1281
|
+
const setListType = (listType) => {
|
|
1282
|
+
const newBlock = {
|
|
1283
|
+
...block,
|
|
1284
|
+
listType,
|
|
1285
|
+
checkedItems: listType === "checklist" ? block.items.map(() => false) : void 0
|
|
1286
|
+
};
|
|
1287
|
+
onUpdate(newBlock);
|
|
1288
|
+
};
|
|
1289
|
+
const handleKeyDown = (e, index) => {
|
|
1290
|
+
if (e.key === "Enter") {
|
|
1291
|
+
e.preventDefault();
|
|
1292
|
+
addItem(index);
|
|
1293
|
+
setTimeout(() => {
|
|
1294
|
+
const inputs = document.querySelectorAll(`[data-list-input="${block.id}"]`);
|
|
1295
|
+
inputs[index + 1]?.focus();
|
|
1296
|
+
}, 0);
|
|
1297
|
+
} else if (e.key === "Backspace" && block.items[index] === "" && block.items.length > 1) {
|
|
1298
|
+
e.preventDefault();
|
|
1299
|
+
removeItem(index);
|
|
1300
|
+
setTimeout(() => {
|
|
1301
|
+
const inputs = document.querySelectorAll(`[data-list-input="${block.id}"]`);
|
|
1302
|
+
inputs[Math.max(0, index - 1)]?.focus();
|
|
1303
|
+
}, 0);
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
const toolbarBtnClass = (isActive) => `px-2 py-1 text-sm rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-700"}`;
|
|
1307
|
+
const ListWrapper = block.listType === "numbered" ? "ol" : "ul";
|
|
1308
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1309
|
+
"div",
|
|
1310
|
+
{
|
|
1311
|
+
className: "group relative",
|
|
1312
|
+
onFocus: () => setShowToolbar(true),
|
|
1313
|
+
onBlur: (e) => {
|
|
1314
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
1315
|
+
setShowToolbar(false);
|
|
1316
|
+
}
|
|
1317
|
+
},
|
|
1318
|
+
children: [
|
|
1319
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: [
|
|
1320
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1321
|
+
"button",
|
|
1322
|
+
{
|
|
1323
|
+
onClick: () => setListType("bullet"),
|
|
1324
|
+
className: toolbarBtnClass(block.listType === "bullet"),
|
|
1325
|
+
children: "• Bullet"
|
|
1326
|
+
}
|
|
1327
|
+
),
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1329
|
+
"button",
|
|
1330
|
+
{
|
|
1331
|
+
onClick: () => setListType("numbered"),
|
|
1332
|
+
className: toolbarBtnClass(block.listType === "numbered"),
|
|
1333
|
+
children: "1. Numbered"
|
|
1334
|
+
}
|
|
1335
|
+
),
|
|
1336
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1337
|
+
"button",
|
|
1338
|
+
{
|
|
1339
|
+
onClick: () => setListType("checklist"),
|
|
1340
|
+
className: toolbarBtnClass(block.listType === "checklist"),
|
|
1341
|
+
children: "☑ Checklist"
|
|
1342
|
+
}
|
|
1343
|
+
)
|
|
1344
|
+
] }),
|
|
1345
|
+
/* @__PURE__ */ jsxRuntime.jsx(ListWrapper, { className: `space-y-1 ${block.listType === "numbered" ? "list-decimal" : block.listType === "bullet" ? "list-disc" : "list-none"} ${block.listType !== "checklist" ? "pl-6" : ""} ${isDark ? "text-slate-200" : "text-slate-700"}`, children: block.items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "group/item flex items-center gap-2", children: [
|
|
1346
|
+
block.listType === "checklist" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1347
|
+
"button",
|
|
1348
|
+
{
|
|
1349
|
+
onClick: () => toggleChecked(index),
|
|
1350
|
+
disabled: readOnly,
|
|
1351
|
+
className: `flex-shrink-0 w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${block.checkedItems?.[index] ? "bg-indigo-500 border-indigo-500 text-white" : isDark ? "border-slate-500 hover:border-indigo-400" : "border-slate-300 hover:border-indigo-400"}`,
|
|
1352
|
+
children: block.checkedItems?.[index] && /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, { size: 12 })
|
|
1353
|
+
}
|
|
1354
|
+
),
|
|
1355
|
+
readOnly ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: block.checkedItems?.[index] ? isDark ? "line-through text-slate-500" : "line-through text-slate-400" : "", children: item }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1356
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1357
|
+
"input",
|
|
1358
|
+
{
|
|
1359
|
+
type: "text",
|
|
1360
|
+
"data-list-input": block.id,
|
|
1361
|
+
value: item,
|
|
1362
|
+
onChange: (e) => updateItem(index, e.target.value),
|
|
1363
|
+
onKeyDown: (e) => handleKeyDown(e, index),
|
|
1364
|
+
placeholder: "List item...",
|
|
1365
|
+
className: `flex-1 outline-none bg-transparent ${block.checkedItems?.[index] ? isDark ? "line-through text-slate-500" : "line-through text-slate-400" : ""} ${isDark ? "placeholder:text-slate-500" : "placeholder:text-slate-400"}`
|
|
1366
|
+
}
|
|
1367
|
+
),
|
|
1368
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1369
|
+
"button",
|
|
1370
|
+
{
|
|
1371
|
+
onClick: () => removeItem(index),
|
|
1372
|
+
className: `opacity-0 group-hover/item:opacity-100 p-1 transition-all ${isDark ? "text-slate-500 hover:text-red-400" : "text-slate-400 hover:text-red-500"}`,
|
|
1373
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, { size: 14 })
|
|
1374
|
+
}
|
|
1375
|
+
)
|
|
1376
|
+
] })
|
|
1377
|
+
] }, index)) }),
|
|
1378
|
+
!readOnly && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1379
|
+
"button",
|
|
1380
|
+
{
|
|
1381
|
+
onClick: () => addItem(),
|
|
1382
|
+
className: `mt-2 flex items-center gap-1 text-sm transition-colors ${isDark ? "text-slate-500 hover:text-slate-300" : "text-slate-400 hover:text-slate-600"}`,
|
|
1383
|
+
children: [
|
|
1384
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 14 }),
|
|
1385
|
+
" Add item"
|
|
1386
|
+
]
|
|
1387
|
+
}
|
|
1388
|
+
)
|
|
1389
|
+
]
|
|
1390
|
+
}
|
|
1391
|
+
);
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
const getVariantStyles = (isDark) => ({
|
|
1395
|
+
info: {
|
|
1396
|
+
bg: isDark ? "bg-blue-950/40" : "bg-blue-50",
|
|
1397
|
+
border: isDark ? "border-blue-800" : "border-blue-200",
|
|
1398
|
+
icon: "text-blue-500",
|
|
1399
|
+
title: isDark ? "text-blue-300" : "text-blue-800",
|
|
1400
|
+
content: isDark ? "text-blue-200" : "text-blue-700"
|
|
1401
|
+
},
|
|
1402
|
+
warning: {
|
|
1403
|
+
bg: isDark ? "bg-amber-950/40" : "bg-amber-50",
|
|
1404
|
+
border: isDark ? "border-amber-800" : "border-amber-200",
|
|
1405
|
+
icon: "text-amber-500",
|
|
1406
|
+
title: isDark ? "text-amber-300" : "text-amber-800",
|
|
1407
|
+
content: isDark ? "text-amber-200" : "text-amber-700"
|
|
1408
|
+
},
|
|
1409
|
+
success: {
|
|
1410
|
+
bg: isDark ? "bg-emerald-950/40" : "bg-emerald-50",
|
|
1411
|
+
border: isDark ? "border-emerald-800" : "border-emerald-200",
|
|
1412
|
+
icon: "text-emerald-500",
|
|
1413
|
+
title: isDark ? "text-emerald-300" : "text-emerald-800",
|
|
1414
|
+
content: isDark ? "text-emerald-200" : "text-emerald-700"
|
|
1415
|
+
},
|
|
1416
|
+
error: {
|
|
1417
|
+
bg: isDark ? "bg-red-950/40" : "bg-red-50",
|
|
1418
|
+
border: isDark ? "border-red-800" : "border-red-200",
|
|
1419
|
+
icon: "text-red-500",
|
|
1420
|
+
title: isDark ? "text-red-300" : "text-red-800",
|
|
1421
|
+
content: isDark ? "text-red-200" : "text-red-700"
|
|
1422
|
+
},
|
|
1423
|
+
tip: {
|
|
1424
|
+
bg: isDark ? "bg-violet-950/40" : "bg-violet-50",
|
|
1425
|
+
border: isDark ? "border-violet-800" : "border-violet-200",
|
|
1426
|
+
icon: "text-violet-500",
|
|
1427
|
+
title: isDark ? "text-violet-300" : "text-violet-800",
|
|
1428
|
+
content: isDark ? "text-violet-200" : "text-violet-700"
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
const variantIcons = {
|
|
1432
|
+
info: "ℹ️",
|
|
1433
|
+
warning: "⚠️",
|
|
1434
|
+
success: "✅",
|
|
1435
|
+
error: "❌",
|
|
1436
|
+
tip: "💡"
|
|
1437
|
+
};
|
|
1438
|
+
const variantLabels = {
|
|
1439
|
+
info: "Info",
|
|
1440
|
+
warning: "Warning",
|
|
1441
|
+
success: "Success",
|
|
1442
|
+
error: "Error",
|
|
1443
|
+
tip: "Tip"
|
|
1444
|
+
};
|
|
1445
|
+
const CalloutBlock = ({ block, onUpdate, readOnly, theme = "light" }) => {
|
|
1446
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
1447
|
+
const textareaRef = react.useRef(null);
|
|
1448
|
+
const isDark = theme === "dark";
|
|
1449
|
+
const handleContentChange = (e) => {
|
|
1450
|
+
onUpdate({ ...block, content: e.target.value });
|
|
1451
|
+
if (textareaRef.current) {
|
|
1452
|
+
textareaRef.current.style.height = "auto";
|
|
1453
|
+
textareaRef.current.style.height = textareaRef.current.scrollHeight + "px";
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
const handleTitleChange = (e) => {
|
|
1457
|
+
onUpdate({ ...block, title: e.target.value });
|
|
1458
|
+
};
|
|
1459
|
+
const setVariant = (variant) => {
|
|
1460
|
+
onUpdate({ ...block, variant });
|
|
1461
|
+
};
|
|
1462
|
+
const variantStyles = getVariantStyles(isDark);
|
|
1463
|
+
const styles = variantStyles[block.variant];
|
|
1464
|
+
const toolbarBtnClass = (isActive) => `px-2 py-1 text-sm rounded-lg transition-colors ${isActive ? isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900" : isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-700"}`;
|
|
1465
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1466
|
+
"div",
|
|
1467
|
+
{
|
|
1468
|
+
className: "group relative",
|
|
1469
|
+
onFocus: () => setShowToolbar(true),
|
|
1470
|
+
onBlur: (e) => {
|
|
1471
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
1472
|
+
setShowToolbar(false);
|
|
1473
|
+
}
|
|
1474
|
+
},
|
|
1475
|
+
children: [
|
|
1476
|
+
showToolbar && !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`, children: Object.keys(variantStyles).map((variant) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1477
|
+
"button",
|
|
1478
|
+
{
|
|
1479
|
+
onClick: () => setVariant(variant),
|
|
1480
|
+
className: toolbarBtnClass(block.variant === variant),
|
|
1481
|
+
children: [
|
|
1482
|
+
variantIcons[variant],
|
|
1483
|
+
" ",
|
|
1484
|
+
variantLabels[variant]
|
|
1485
|
+
]
|
|
1486
|
+
},
|
|
1487
|
+
variant
|
|
1488
|
+
)) }),
|
|
1489
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `rounded-xl border ${styles.bg} ${styles.border} p-4`, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
|
|
1490
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-xl flex-shrink-0 ${styles.icon}`, children: variantIcons[block.variant] }),
|
|
1491
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 min-w-0", children: readOnly ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1492
|
+
block.title && /* @__PURE__ */ jsxRuntime.jsx("p", { className: `font-semibold mb-1 ${styles.title}`, children: block.title }),
|
|
1493
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `whitespace-pre-wrap break-words ${styles.content}`, children: block.content })
|
|
1494
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1495
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1496
|
+
"input",
|
|
1497
|
+
{
|
|
1498
|
+
type: "text",
|
|
1499
|
+
value: block.title || "",
|
|
1500
|
+
onChange: handleTitleChange,
|
|
1501
|
+
placeholder: `${variantLabels[block.variant]} title (optional)`,
|
|
1502
|
+
className: `w-full font-semibold mb-1 bg-transparent outline-none ${styles.title} ${isDark ? "placeholder:text-slate-500" : "placeholder:text-slate-400"}`
|
|
1503
|
+
}
|
|
1504
|
+
),
|
|
1505
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1506
|
+
"textarea",
|
|
1507
|
+
{
|
|
1508
|
+
ref: textareaRef,
|
|
1509
|
+
value: block.content,
|
|
1510
|
+
onChange: handleContentChange,
|
|
1511
|
+
placeholder: "Enter callout content...",
|
|
1512
|
+
className: `w-full bg-transparent outline-none resize-none ${styles.content} ${isDark ? "placeholder:text-slate-500" : "placeholder:text-slate-400"}`,
|
|
1513
|
+
rows: 1,
|
|
1514
|
+
onInput: (e) => {
|
|
1515
|
+
const target = e.target;
|
|
1516
|
+
target.style.height = "auto";
|
|
1517
|
+
target.style.height = target.scrollHeight + "px";
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
)
|
|
1521
|
+
] }) })
|
|
1522
|
+
] }) })
|
|
1523
|
+
]
|
|
1524
|
+
}
|
|
1525
|
+
);
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
const BlockWrapper = ({
|
|
1529
|
+
block,
|
|
1530
|
+
index,
|
|
1531
|
+
totalBlocks,
|
|
1532
|
+
onUpdate,
|
|
1533
|
+
onDelete,
|
|
1534
|
+
onDuplicate,
|
|
1535
|
+
onMoveUp,
|
|
1536
|
+
onMoveDown,
|
|
1537
|
+
onAddBlock,
|
|
1538
|
+
readOnly,
|
|
1539
|
+
isDragging,
|
|
1540
|
+
onDragStart,
|
|
1541
|
+
onDragEnd,
|
|
1542
|
+
onDragOver,
|
|
1543
|
+
onDrop,
|
|
1544
|
+
theme = "light"
|
|
1545
|
+
}) => {
|
|
1546
|
+
const [showAddMenu, setShowAddMenu] = react.useState(false);
|
|
1547
|
+
const [isSelected, setIsSelected] = react.useState(false);
|
|
1548
|
+
const wrapperRef = react.useRef(null);
|
|
1549
|
+
const isDark = theme === "dark";
|
|
1550
|
+
react.useEffect(() => {
|
|
1551
|
+
const handleClickOutside = (event) => {
|
|
1552
|
+
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
|
1553
|
+
setIsSelected(false);
|
|
1554
|
+
setShowAddMenu(false);
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
if (isSelected) {
|
|
1558
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
1559
|
+
}
|
|
1560
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
1561
|
+
}, [isSelected]);
|
|
1562
|
+
const handleBlockClick = react.useCallback((e) => {
|
|
1563
|
+
const target = e.target;
|
|
1564
|
+
const interactiveElements = ["INPUT", "TEXTAREA", "BUTTON", "SELECT"];
|
|
1565
|
+
if (interactiveElements.includes(target.tagName)) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
if (!readOnly) {
|
|
1569
|
+
setIsSelected(true);
|
|
1570
|
+
}
|
|
1571
|
+
}, [readOnly]);
|
|
1572
|
+
const renderBlock = react.useCallback(() => {
|
|
1573
|
+
const commonProps = { readOnly, theme };
|
|
1574
|
+
switch (block.type) {
|
|
1575
|
+
case "text":
|
|
1576
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TextBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1577
|
+
case "heading":
|
|
1578
|
+
return /* @__PURE__ */ jsxRuntime.jsx(HeadingBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1579
|
+
case "image":
|
|
1580
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ImageBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1581
|
+
case "code":
|
|
1582
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1583
|
+
case "table":
|
|
1584
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TableBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1585
|
+
case "divider":
|
|
1586
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DividerBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1587
|
+
case "quote":
|
|
1588
|
+
return /* @__PURE__ */ jsxRuntime.jsx(QuoteBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1589
|
+
case "list":
|
|
1590
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ListBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1591
|
+
case "callout":
|
|
1592
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CalloutBlock, { block, onUpdate: (b) => onUpdate(b), ...commonProps });
|
|
1593
|
+
default: {
|
|
1594
|
+
const _exhaustiveCheck = block;
|
|
1595
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1596
|
+
"Unknown block type: ",
|
|
1597
|
+
_exhaustiveCheck.type
|
|
1598
|
+
] });
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}, [block, onUpdate, readOnly, theme]);
|
|
1602
|
+
const buttonBaseClass = `p-1.5 rounded-lg transition-all ${isDark ? "text-slate-400 hover:text-slate-200 hover:bg-slate-700" : "text-slate-500 hover:text-slate-700 hover:bg-slate-100"}`;
|
|
1603
|
+
const showControls = !readOnly && isSelected;
|
|
1604
|
+
const handleKeyDown = react.useCallback((e) => {
|
|
1605
|
+
if (readOnly || !isSelected) return;
|
|
1606
|
+
switch (e.key) {
|
|
1607
|
+
case "Escape":
|
|
1608
|
+
setIsSelected(false);
|
|
1609
|
+
setShowAddMenu(false);
|
|
1610
|
+
break;
|
|
1611
|
+
case "Delete":
|
|
1612
|
+
case "Backspace":
|
|
1613
|
+
if (!e.target.matches("input, textarea, [contenteditable]")) {
|
|
1614
|
+
e.preventDefault();
|
|
1615
|
+
onDelete();
|
|
1616
|
+
}
|
|
1617
|
+
break;
|
|
1618
|
+
case "ArrowUp":
|
|
1619
|
+
if (e.altKey) {
|
|
1620
|
+
e.preventDefault();
|
|
1621
|
+
onMoveUp();
|
|
1622
|
+
}
|
|
1623
|
+
break;
|
|
1624
|
+
case "ArrowDown":
|
|
1625
|
+
if (e.altKey) {
|
|
1626
|
+
e.preventDefault();
|
|
1627
|
+
onMoveDown();
|
|
1628
|
+
}
|
|
1629
|
+
break;
|
|
1630
|
+
case "d":
|
|
1631
|
+
if (e.ctrlKey || e.metaKey) {
|
|
1632
|
+
e.preventDefault();
|
|
1633
|
+
onDuplicate();
|
|
1634
|
+
}
|
|
1635
|
+
break;
|
|
1636
|
+
}
|
|
1637
|
+
}, [readOnly, isSelected, onDelete, onMoveUp, onMoveDown, onDuplicate]);
|
|
1638
|
+
const editModeBorderClass = !readOnly ? isSelected ? isDark ? "ring-2 ring-indigo-500 rounded-lg bg-slate-800/30" : "ring-2 ring-indigo-500 rounded-lg bg-indigo-50/30" : isDark ? "border border-slate-700 rounded-lg hover:border-slate-500" : "border border-slate-200 rounded-lg hover:border-slate-400" : "";
|
|
1639
|
+
const blockTypeLabel = block.type.charAt(0).toUpperCase() + block.type.slice(1);
|
|
1640
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1641
|
+
"div",
|
|
1642
|
+
{
|
|
1643
|
+
ref: wrapperRef,
|
|
1644
|
+
role: "article",
|
|
1645
|
+
"aria-label": `${blockTypeLabel} block ${index + 1} of ${totalBlocks}`,
|
|
1646
|
+
"aria-selected": isSelected,
|
|
1647
|
+
tabIndex: readOnly ? -1 : 0,
|
|
1648
|
+
className: `group relative transition-all ${isDragging ? "opacity-50" : ""} ${editModeBorderClass} ${!readOnly ? "cursor-pointer" : ""} focus:outline-none`,
|
|
1649
|
+
onClick: handleBlockClick,
|
|
1650
|
+
onKeyDown: handleKeyDown,
|
|
1651
|
+
draggable: !readOnly && isSelected,
|
|
1652
|
+
onDragStart,
|
|
1653
|
+
onDragEnd,
|
|
1654
|
+
onDragOver,
|
|
1655
|
+
onDrop,
|
|
1656
|
+
"data-block-index": index,
|
|
1657
|
+
"data-block-type": block.type,
|
|
1658
|
+
children: [
|
|
1659
|
+
showControls && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1660
|
+
"div",
|
|
1661
|
+
{
|
|
1662
|
+
role: "toolbar",
|
|
1663
|
+
"aria-label": "Block controls",
|
|
1664
|
+
className: `flex items-center justify-between gap-1 px-2 py-1.5 mb-1 rounded-t-lg border-b ${isDark ? "bg-slate-800 border-slate-700" : "bg-slate-50 border-slate-200"}`,
|
|
1665
|
+
children: [
|
|
1666
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Reorder controls", children: [
|
|
1667
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1668
|
+
"button",
|
|
1669
|
+
{
|
|
1670
|
+
type: "button",
|
|
1671
|
+
className: `${buttonBaseClass} cursor-grab active:cursor-grabbing`,
|
|
1672
|
+
title: "Drag to reorder",
|
|
1673
|
+
"aria-label": "Drag to reorder block",
|
|
1674
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DragIcon, { size: 16 })
|
|
1675
|
+
}
|
|
1676
|
+
),
|
|
1677
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1678
|
+
"button",
|
|
1679
|
+
{
|
|
1680
|
+
type: "button",
|
|
1681
|
+
onClick: (e) => {
|
|
1682
|
+
e.stopPropagation();
|
|
1683
|
+
onMoveUp();
|
|
1684
|
+
},
|
|
1685
|
+
disabled: index === 0,
|
|
1686
|
+
className: `${buttonBaseClass} disabled:opacity-30 disabled:cursor-not-allowed`,
|
|
1687
|
+
title: "Move up (Alt+↑)",
|
|
1688
|
+
"aria-label": "Move block up",
|
|
1689
|
+
"aria-disabled": index === 0,
|
|
1690
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronUpIcon, { size: 16 })
|
|
1691
|
+
}
|
|
1692
|
+
),
|
|
1693
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1694
|
+
"button",
|
|
1695
|
+
{
|
|
1696
|
+
type: "button",
|
|
1697
|
+
onClick: (e) => {
|
|
1698
|
+
e.stopPropagation();
|
|
1699
|
+
onMoveDown();
|
|
1700
|
+
},
|
|
1701
|
+
disabled: index === totalBlocks - 1,
|
|
1702
|
+
className: `${buttonBaseClass} disabled:opacity-30 disabled:cursor-not-allowed`,
|
|
1703
|
+
title: "Move down (Alt+↓)",
|
|
1704
|
+
"aria-label": "Move block down",
|
|
1705
|
+
"aria-disabled": index === totalBlocks - 1,
|
|
1706
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronDownIcon, { size: 16 })
|
|
1707
|
+
}
|
|
1708
|
+
)
|
|
1709
|
+
] }),
|
|
1710
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", role: "group", "aria-label": "Block actions", children: [
|
|
1711
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1712
|
+
"button",
|
|
1713
|
+
{
|
|
1714
|
+
type: "button",
|
|
1715
|
+
onClick: (e) => {
|
|
1716
|
+
e.stopPropagation();
|
|
1717
|
+
setShowAddMenu(!showAddMenu);
|
|
1718
|
+
},
|
|
1719
|
+
className: `${buttonBaseClass} hover:!text-indigo-500`,
|
|
1720
|
+
title: "Add block below",
|
|
1721
|
+
"aria-label": "Add new block below",
|
|
1722
|
+
"aria-expanded": showAddMenu,
|
|
1723
|
+
"aria-haspopup": "menu",
|
|
1724
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 16 })
|
|
1725
|
+
}
|
|
1726
|
+
),
|
|
1727
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1728
|
+
"button",
|
|
1729
|
+
{
|
|
1730
|
+
type: "button",
|
|
1731
|
+
onClick: (e) => {
|
|
1732
|
+
e.stopPropagation();
|
|
1733
|
+
onDuplicate();
|
|
1734
|
+
},
|
|
1735
|
+
className: `${buttonBaseClass} hover:!text-indigo-500`,
|
|
1736
|
+
title: "Duplicate (Ctrl+D)",
|
|
1737
|
+
"aria-label": "Duplicate block",
|
|
1738
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { size: 16 })
|
|
1739
|
+
}
|
|
1740
|
+
),
|
|
1741
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1742
|
+
"button",
|
|
1743
|
+
{
|
|
1744
|
+
type: "button",
|
|
1745
|
+
onClick: (e) => {
|
|
1746
|
+
e.stopPropagation();
|
|
1747
|
+
onDelete();
|
|
1748
|
+
},
|
|
1749
|
+
className: `${buttonBaseClass} hover:!text-red-500`,
|
|
1750
|
+
title: "Delete",
|
|
1751
|
+
"aria-label": "Delete block",
|
|
1752
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, { size: 16 })
|
|
1753
|
+
}
|
|
1754
|
+
)
|
|
1755
|
+
] }),
|
|
1756
|
+
showAddMenu && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-1/2 -translate-x-1/2 top-full mt-1 z-50", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1757
|
+
AddBlockMenu,
|
|
1758
|
+
{
|
|
1759
|
+
onAdd: (type) => {
|
|
1760
|
+
onAddBlock(type, index);
|
|
1761
|
+
setShowAddMenu(false);
|
|
1762
|
+
},
|
|
1763
|
+
onClose: () => setShowAddMenu(false),
|
|
1764
|
+
theme
|
|
1765
|
+
}
|
|
1766
|
+
) })
|
|
1767
|
+
]
|
|
1768
|
+
}
|
|
1769
|
+
),
|
|
1770
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative px-2 py-2", children: renderBlock() })
|
|
1771
|
+
]
|
|
1772
|
+
}
|
|
1773
|
+
);
|
|
1774
|
+
};
|
|
1775
|
+
|
|
1776
|
+
const ThemeContext = react.createContext("light");
|
|
1777
|
+
const PagesEditor = ({
|
|
1778
|
+
initialData,
|
|
1779
|
+
onChange,
|
|
1780
|
+
debounceDelay = 300,
|
|
1781
|
+
readOnly = false,
|
|
1782
|
+
placeholder = "Start creating your content...",
|
|
1783
|
+
className = "",
|
|
1784
|
+
theme = "light"
|
|
1785
|
+
}) => {
|
|
1786
|
+
const [data, setData] = react.useState(() => {
|
|
1787
|
+
if (initialData && validateEditorData(initialData)) {
|
|
1788
|
+
return initialData;
|
|
1789
|
+
}
|
|
1790
|
+
return createEmptyEditorData();
|
|
1791
|
+
});
|
|
1792
|
+
const [showInitialAddMenu, setShowInitialAddMenu] = react.useState(false);
|
|
1793
|
+
const [draggedIndex, setDraggedIndex] = react.useState(null);
|
|
1794
|
+
const [dragOverIndex, setDragOverIndex] = react.useState(null);
|
|
1795
|
+
const debounceTimerRef = react.useRef(null);
|
|
1796
|
+
const isDark = theme === "dark";
|
|
1797
|
+
const createBlock = react.useCallback((type) => {
|
|
1798
|
+
switch (type) {
|
|
1799
|
+
case "text":
|
|
1800
|
+
return createTextBlock();
|
|
1801
|
+
case "heading":
|
|
1802
|
+
return createHeadingBlock();
|
|
1803
|
+
case "image":
|
|
1804
|
+
return createImageBlock();
|
|
1805
|
+
case "code":
|
|
1806
|
+
return createCodeBlock();
|
|
1807
|
+
case "table":
|
|
1808
|
+
return createTableBlock();
|
|
1809
|
+
case "divider":
|
|
1810
|
+
return createDividerBlock();
|
|
1811
|
+
case "quote":
|
|
1812
|
+
return createQuoteBlock();
|
|
1813
|
+
case "list":
|
|
1814
|
+
return createListBlock();
|
|
1815
|
+
case "callout":
|
|
1816
|
+
return createCalloutBlock();
|
|
1817
|
+
default:
|
|
1818
|
+
return createTextBlock();
|
|
1819
|
+
}
|
|
1820
|
+
}, []);
|
|
1821
|
+
react.useEffect(() => {
|
|
1822
|
+
if (initialData && validateEditorData(initialData)) {
|
|
1823
|
+
setData(initialData);
|
|
1824
|
+
}
|
|
1825
|
+
}, [initialData]);
|
|
1826
|
+
react.useEffect(() => {
|
|
1827
|
+
return () => {
|
|
1828
|
+
if (debounceTimerRef.current) {
|
|
1829
|
+
clearTimeout(debounceTimerRef.current);
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
}, []);
|
|
1833
|
+
const updateData = react.useCallback(
|
|
1834
|
+
(newBlocks) => {
|
|
1835
|
+
const newData = {
|
|
1836
|
+
...data,
|
|
1837
|
+
blocks: newBlocks,
|
|
1838
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1839
|
+
};
|
|
1840
|
+
setData(newData);
|
|
1841
|
+
if (onChange) {
|
|
1842
|
+
if (debounceTimerRef.current) {
|
|
1843
|
+
clearTimeout(debounceTimerRef.current);
|
|
1844
|
+
}
|
|
1845
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
1846
|
+
onChange(newData);
|
|
1847
|
+
}, debounceDelay);
|
|
1848
|
+
}
|
|
1849
|
+
},
|
|
1850
|
+
[data, onChange, debounceDelay]
|
|
1851
|
+
);
|
|
1852
|
+
const addBlock = react.useCallback(
|
|
1853
|
+
(type, afterIndex) => {
|
|
1854
|
+
const newBlock = createBlock(type);
|
|
1855
|
+
const newBlocks = [...data.blocks];
|
|
1856
|
+
if (afterIndex !== void 0 && afterIndex >= 0) {
|
|
1857
|
+
newBlocks.splice(afterIndex + 1, 0, newBlock);
|
|
1858
|
+
} else {
|
|
1859
|
+
newBlocks.push(newBlock);
|
|
1860
|
+
}
|
|
1861
|
+
updateData(newBlocks);
|
|
1862
|
+
setShowInitialAddMenu(false);
|
|
1863
|
+
},
|
|
1864
|
+
[data.blocks, updateData, createBlock]
|
|
1865
|
+
);
|
|
1866
|
+
const updateBlock = react.useCallback(
|
|
1867
|
+
(index, block) => {
|
|
1868
|
+
const newBlocks = [...data.blocks];
|
|
1869
|
+
newBlocks[index] = block;
|
|
1870
|
+
updateData(newBlocks);
|
|
1871
|
+
},
|
|
1872
|
+
[data.blocks, updateData]
|
|
1873
|
+
);
|
|
1874
|
+
const deleteBlock = react.useCallback(
|
|
1875
|
+
(index) => {
|
|
1876
|
+
const newBlocks = data.blocks.filter((_, i) => i !== index);
|
|
1877
|
+
updateData(newBlocks);
|
|
1878
|
+
},
|
|
1879
|
+
[data.blocks, updateData]
|
|
1880
|
+
);
|
|
1881
|
+
const duplicateBlock = react.useCallback(
|
|
1882
|
+
(index) => {
|
|
1883
|
+
const block = data.blocks[index];
|
|
1884
|
+
if (!block) return;
|
|
1885
|
+
const newBlock = cloneBlock(block);
|
|
1886
|
+
const newBlocks = [...data.blocks];
|
|
1887
|
+
newBlocks.splice(index + 1, 0, newBlock);
|
|
1888
|
+
updateData(newBlocks);
|
|
1889
|
+
},
|
|
1890
|
+
[data.blocks, updateData]
|
|
1891
|
+
);
|
|
1892
|
+
const moveBlockUp = react.useCallback(
|
|
1893
|
+
(index) => {
|
|
1894
|
+
if (index === 0) return;
|
|
1895
|
+
const newBlocks = moveArrayItem(data.blocks, index, index - 1);
|
|
1896
|
+
updateData(newBlocks);
|
|
1897
|
+
},
|
|
1898
|
+
[data.blocks, updateData]
|
|
1899
|
+
);
|
|
1900
|
+
const moveBlockDown = react.useCallback(
|
|
1901
|
+
(index) => {
|
|
1902
|
+
if (index === data.blocks.length - 1) return;
|
|
1903
|
+
const newBlocks = moveArrayItem(data.blocks, index, index + 1);
|
|
1904
|
+
updateData(newBlocks);
|
|
1905
|
+
},
|
|
1906
|
+
[data.blocks, updateData]
|
|
1907
|
+
);
|
|
1908
|
+
const handleDragStart = (e, index) => {
|
|
1909
|
+
setDraggedIndex(index);
|
|
1910
|
+
e.dataTransfer.effectAllowed = "move";
|
|
1911
|
+
e.dataTransfer.setData("text/plain", index.toString());
|
|
1912
|
+
};
|
|
1913
|
+
const handleDragEnd = () => {
|
|
1914
|
+
setDraggedIndex(null);
|
|
1915
|
+
setDragOverIndex(null);
|
|
1916
|
+
};
|
|
1917
|
+
const handleDragOver = (e, index) => {
|
|
1918
|
+
e.preventDefault();
|
|
1919
|
+
e.dataTransfer.dropEffect = "move";
|
|
1920
|
+
setDragOverIndex(index);
|
|
1921
|
+
};
|
|
1922
|
+
const handleDrop = (e, dropIndex) => {
|
|
1923
|
+
e.preventDefault();
|
|
1924
|
+
const dragIndex = parseInt(e.dataTransfer.getData("text/plain"), 10);
|
|
1925
|
+
if (dragIndex !== dropIndex && !isNaN(dragIndex)) {
|
|
1926
|
+
const newBlocks = moveArrayItem(data.blocks, dragIndex, dropIndex);
|
|
1927
|
+
updateData(newBlocks);
|
|
1928
|
+
}
|
|
1929
|
+
setDraggedIndex(null);
|
|
1930
|
+
setDragOverIndex(null);
|
|
1931
|
+
};
|
|
1932
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: theme, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: `pages-editor w-full ${isDark ? "pe-dark" : "pe-light"} ${className}`, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative py-4", children: [
|
|
1933
|
+
data.blocks.length === 0 ? (
|
|
1934
|
+
// Empty state
|
|
1935
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center py-16", children: [
|
|
1936
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: `mb-4 ${isDark ? "text-slate-500" : "text-slate-400"}`, children: placeholder }),
|
|
1937
|
+
!readOnly && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative inline-block", children: [
|
|
1938
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1939
|
+
"button",
|
|
1940
|
+
{
|
|
1941
|
+
onClick: () => setShowInitialAddMenu(true),
|
|
1942
|
+
className: "flex items-center gap-2 px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors mx-auto font-medium shadow-sm",
|
|
1943
|
+
children: [
|
|
1944
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 20 }),
|
|
1945
|
+
"Add First Block"
|
|
1946
|
+
]
|
|
1947
|
+
}
|
|
1948
|
+
),
|
|
1949
|
+
showInitialAddMenu && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-1/2 -translate-x-1/2 top-full mt-2 z-50", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1950
|
+
AddBlockMenu,
|
|
1951
|
+
{
|
|
1952
|
+
onAdd: (type) => addBlock(type),
|
|
1953
|
+
onClose: () => setShowInitialAddMenu(false),
|
|
1954
|
+
theme
|
|
1955
|
+
}
|
|
1956
|
+
) })
|
|
1957
|
+
] })
|
|
1958
|
+
] })
|
|
1959
|
+
) : (
|
|
1960
|
+
// Blocks list
|
|
1961
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: data.blocks.map((block, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1962
|
+
"div",
|
|
1963
|
+
{
|
|
1964
|
+
className: `transition-all duration-200 ${dragOverIndex === index && draggedIndex !== index ? "border-t-2 border-indigo-500 pt-2" : ""}`,
|
|
1965
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1966
|
+
BlockWrapper,
|
|
1967
|
+
{
|
|
1968
|
+
block,
|
|
1969
|
+
index,
|
|
1970
|
+
totalBlocks: data.blocks.length,
|
|
1971
|
+
onUpdate: (updatedBlock) => updateBlock(index, updatedBlock),
|
|
1972
|
+
onDelete: () => deleteBlock(index),
|
|
1973
|
+
onDuplicate: () => duplicateBlock(index),
|
|
1974
|
+
onMoveUp: () => moveBlockUp(index),
|
|
1975
|
+
onMoveDown: () => moveBlockDown(index),
|
|
1976
|
+
onAddBlock: (type, afterIdx) => addBlock(type, afterIdx),
|
|
1977
|
+
readOnly,
|
|
1978
|
+
isDragging: draggedIndex === index,
|
|
1979
|
+
onDragStart: (e) => handleDragStart(e, index),
|
|
1980
|
+
onDragEnd: handleDragEnd,
|
|
1981
|
+
onDragOver: (e) => handleDragOver(e, index),
|
|
1982
|
+
onDrop: (e) => handleDrop(e, index),
|
|
1983
|
+
theme
|
|
1984
|
+
}
|
|
1985
|
+
)
|
|
1986
|
+
},
|
|
1987
|
+
block.id
|
|
1988
|
+
)) })
|
|
1989
|
+
),
|
|
1990
|
+
!readOnly && data.blocks.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative mt-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
1991
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1992
|
+
"button",
|
|
1993
|
+
{
|
|
1994
|
+
onClick: () => setShowInitialAddMenu(true),
|
|
1995
|
+
className: `flex items-center gap-2 px-4 py-2 border-2 border-dashed rounded-lg transition-colors ${isDark ? "text-slate-500 hover:text-slate-300 border-slate-700 hover:border-slate-500" : "text-slate-400 hover:text-slate-600 border-slate-300 hover:border-slate-400"}`,
|
|
1996
|
+
children: [
|
|
1997
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlusIcon, { size: 16 }),
|
|
1998
|
+
"Add Block"
|
|
1999
|
+
]
|
|
2000
|
+
}
|
|
2001
|
+
),
|
|
2002
|
+
showInitialAddMenu && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-1/2 -translate-x-1/2 bottom-full mb-2 z-50", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2003
|
+
AddBlockMenu,
|
|
2004
|
+
{
|
|
2005
|
+
onAdd: (type) => addBlock(type),
|
|
2006
|
+
onClose: () => setShowInitialAddMenu(false),
|
|
2007
|
+
theme
|
|
2008
|
+
}
|
|
2009
|
+
) })
|
|
2010
|
+
] }) }) })
|
|
2011
|
+
] }) }) });
|
|
2012
|
+
};
|
|
2013
|
+
|
|
2014
|
+
function useBlockToolbar({ readOnly = false } = {}) {
|
|
2015
|
+
const [showToolbar, setShowToolbar] = react.useState(false);
|
|
2016
|
+
const handleFocus = react.useCallback(() => {
|
|
2017
|
+
if (!readOnly) {
|
|
2018
|
+
setShowToolbar(true);
|
|
2019
|
+
}
|
|
2020
|
+
}, [readOnly]);
|
|
2021
|
+
const handleBlur = react.useCallback((e) => {
|
|
2022
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
2023
|
+
setShowToolbar(false);
|
|
2024
|
+
}
|
|
2025
|
+
}, []);
|
|
2026
|
+
return {
|
|
2027
|
+
showToolbar: showToolbar && !readOnly,
|
|
2028
|
+
handleFocus,
|
|
2029
|
+
handleBlur,
|
|
2030
|
+
containerProps: {
|
|
2031
|
+
onFocus: handleFocus,
|
|
2032
|
+
onBlur: handleBlur
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
function useAutoResize(content) {
|
|
2038
|
+
const ref = react.useRef(null);
|
|
2039
|
+
react.useEffect(() => {
|
|
2040
|
+
const element = ref.current;
|
|
2041
|
+
if (element) {
|
|
2042
|
+
element.style.height = "auto";
|
|
2043
|
+
element.style.height = `${element.scrollHeight}px`;
|
|
2044
|
+
}
|
|
2045
|
+
}, [content]);
|
|
2046
|
+
return ref;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
function useClickOutside(ref, handler, enabled = true) {
|
|
2050
|
+
react.useEffect(() => {
|
|
2051
|
+
if (!enabled) return;
|
|
2052
|
+
const handleClickOutside = (event) => {
|
|
2053
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
2054
|
+
handler();
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2058
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
2059
|
+
}, [ref, handler, enabled]);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
const isDarkTheme = (theme) => theme === "dark";
|
|
2063
|
+
const getToolbarButtonClass = (isActive, isDark) => {
|
|
2064
|
+
const baseClass = "p-2 rounded-lg transition-colors";
|
|
2065
|
+
if (isActive) {
|
|
2066
|
+
return `${baseClass} ${isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900"}`;
|
|
2067
|
+
}
|
|
2068
|
+
return `${baseClass} ${isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-600"}`;
|
|
2069
|
+
};
|
|
2070
|
+
const getSmallToolbarButtonClass = (isActive, isDark) => {
|
|
2071
|
+
const baseClass = "px-2 py-1 text-sm rounded-lg transition-colors";
|
|
2072
|
+
if (isActive) {
|
|
2073
|
+
return `${baseClass} ${isDark ? "bg-slate-600 text-white" : "bg-slate-200 text-slate-900"}`;
|
|
2074
|
+
}
|
|
2075
|
+
return `${baseClass} ${isDark ? "hover:bg-slate-700 text-slate-300" : "hover:bg-slate-100 text-slate-700"}`;
|
|
2076
|
+
};
|
|
2077
|
+
const getToolbarContainerClass = (isDark) => {
|
|
2078
|
+
return `absolute -top-12 left-0 flex items-center gap-1 p-1.5 rounded-xl shadow-lg border z-10 ${isDark ? "bg-slate-800 border-slate-600" : "bg-white border-slate-200"}`;
|
|
2079
|
+
};
|
|
2080
|
+
const getToolbarDividerClass = (isDark) => {
|
|
2081
|
+
return `w-px h-6 mx-1 ${isDark ? "bg-slate-600" : "bg-slate-200"}`;
|
|
2082
|
+
};
|
|
2083
|
+
const getPlaceholderClass = (isDark) => {
|
|
2084
|
+
return isDark ? "placeholder:text-slate-500" : "placeholder:text-slate-400";
|
|
2085
|
+
};
|
|
2086
|
+
const getMutedTextClass = (isDark) => {
|
|
2087
|
+
return isDark ? "text-slate-500" : "text-slate-400";
|
|
2088
|
+
};
|
|
2089
|
+
const getPrimaryTextClass = (isDark) => {
|
|
2090
|
+
return isDark ? "text-slate-200" : "text-slate-800";
|
|
2091
|
+
};
|
|
2092
|
+
const getSecondaryTextClass = (isDark) => {
|
|
2093
|
+
return isDark ? "text-slate-300" : "text-slate-700";
|
|
2094
|
+
};
|
|
2095
|
+
const CALLOUT_VARIANT_STYLES = {
|
|
2096
|
+
info: {
|
|
2097
|
+
light: {
|
|
2098
|
+
bg: "bg-blue-50",
|
|
2099
|
+
border: "border-blue-200",
|
|
2100
|
+
icon: "text-blue-500",
|
|
2101
|
+
title: "text-blue-800",
|
|
2102
|
+
content: "text-blue-700"
|
|
2103
|
+
},
|
|
2104
|
+
dark: {
|
|
2105
|
+
bg: "bg-blue-950/40",
|
|
2106
|
+
border: "border-blue-800",
|
|
2107
|
+
icon: "text-blue-500",
|
|
2108
|
+
title: "text-blue-300",
|
|
2109
|
+
content: "text-blue-200"
|
|
2110
|
+
}
|
|
2111
|
+
},
|
|
2112
|
+
warning: {
|
|
2113
|
+
light: {
|
|
2114
|
+
bg: "bg-amber-50",
|
|
2115
|
+
border: "border-amber-200",
|
|
2116
|
+
icon: "text-amber-500",
|
|
2117
|
+
title: "text-amber-800",
|
|
2118
|
+
content: "text-amber-700"
|
|
2119
|
+
},
|
|
2120
|
+
dark: {
|
|
2121
|
+
bg: "bg-amber-950/40",
|
|
2122
|
+
border: "border-amber-800",
|
|
2123
|
+
icon: "text-amber-500",
|
|
2124
|
+
title: "text-amber-300",
|
|
2125
|
+
content: "text-amber-200"
|
|
2126
|
+
}
|
|
2127
|
+
},
|
|
2128
|
+
success: {
|
|
2129
|
+
light: {
|
|
2130
|
+
bg: "bg-emerald-50",
|
|
2131
|
+
border: "border-emerald-200",
|
|
2132
|
+
icon: "text-emerald-500",
|
|
2133
|
+
title: "text-emerald-800",
|
|
2134
|
+
content: "text-emerald-700"
|
|
2135
|
+
},
|
|
2136
|
+
dark: {
|
|
2137
|
+
bg: "bg-emerald-950/40",
|
|
2138
|
+
border: "border-emerald-800",
|
|
2139
|
+
icon: "text-emerald-500",
|
|
2140
|
+
title: "text-emerald-300",
|
|
2141
|
+
content: "text-emerald-200"
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
error: {
|
|
2145
|
+
light: {
|
|
2146
|
+
bg: "bg-red-50",
|
|
2147
|
+
border: "border-red-200",
|
|
2148
|
+
icon: "text-red-500",
|
|
2149
|
+
title: "text-red-800",
|
|
2150
|
+
content: "text-red-700"
|
|
2151
|
+
},
|
|
2152
|
+
dark: {
|
|
2153
|
+
bg: "bg-red-950/40",
|
|
2154
|
+
border: "border-red-800",
|
|
2155
|
+
icon: "text-red-500",
|
|
2156
|
+
title: "text-red-300",
|
|
2157
|
+
content: "text-red-200"
|
|
2158
|
+
}
|
|
2159
|
+
},
|
|
2160
|
+
tip: {
|
|
2161
|
+
light: {
|
|
2162
|
+
bg: "bg-violet-50",
|
|
2163
|
+
border: "border-violet-200",
|
|
2164
|
+
icon: "text-violet-500",
|
|
2165
|
+
title: "text-violet-800",
|
|
2166
|
+
content: "text-violet-700"
|
|
2167
|
+
},
|
|
2168
|
+
dark: {
|
|
2169
|
+
bg: "bg-violet-950/40",
|
|
2170
|
+
border: "border-violet-800",
|
|
2171
|
+
icon: "text-violet-500",
|
|
2172
|
+
title: "text-violet-300",
|
|
2173
|
+
content: "text-violet-200"
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
const CALLOUT_ICONS = {
|
|
2178
|
+
info: "ℹ️",
|
|
2179
|
+
warning: "⚠️",
|
|
2180
|
+
success: "✅",
|
|
2181
|
+
error: "❌",
|
|
2182
|
+
tip: "💡"
|
|
2183
|
+
};
|
|
2184
|
+
const CALLOUT_LABELS = {
|
|
2185
|
+
info: "Info",
|
|
2186
|
+
warning: "Warning",
|
|
2187
|
+
success: "Success",
|
|
2188
|
+
error: "Error",
|
|
2189
|
+
tip: "Tip"
|
|
2190
|
+
};
|
|
2191
|
+
const FONT_SIZE_CLASSES = {
|
|
2192
|
+
sm: "text-sm leading-relaxed",
|
|
2193
|
+
base: "text-base leading-relaxed",
|
|
2194
|
+
lg: "text-lg leading-relaxed",
|
|
2195
|
+
xl: "text-xl leading-relaxed"
|
|
2196
|
+
};
|
|
2197
|
+
const ALIGNMENT_CLASSES = {
|
|
2198
|
+
left: "text-left",
|
|
2199
|
+
center: "text-center",
|
|
2200
|
+
right: "text-right",
|
|
2201
|
+
justify: "text-justify"
|
|
2202
|
+
};
|
|
2203
|
+
const QUOTE_STYLE_CLASSES = {
|
|
2204
|
+
default: (isDark) => `border-l-4 pl-4 italic ${isDark ? "border-slate-600" : "border-slate-300"}`,
|
|
2205
|
+
bordered: (isDark) => `border-l-4 pl-4 py-3 rounded-r ${isDark ? "border-indigo-500 bg-indigo-950/30" : "border-indigo-500 bg-indigo-50"}`,
|
|
2206
|
+
modern: (isDark) => `relative pl-10 before:content-['"'] before:absolute before:left-0 before:top-0 before:text-5xl before:leading-none ${isDark ? "before:text-slate-600" : "before:text-slate-300"}`
|
|
2207
|
+
};
|
|
2208
|
+
const DIVIDER_STYLE_CLASSES = {
|
|
2209
|
+
solid: "border-solid",
|
|
2210
|
+
dashed: "border-dashed",
|
|
2211
|
+
dotted: "border-dotted"
|
|
2212
|
+
};
|
|
2213
|
+
|
|
2214
|
+
exports.ALIGNMENT_CLASSES = ALIGNMENT_CLASSES;
|
|
2215
|
+
exports.CALLOUT_ICONS = CALLOUT_ICONS;
|
|
2216
|
+
exports.CALLOUT_LABELS = CALLOUT_LABELS;
|
|
2217
|
+
exports.CALLOUT_VARIANT_STYLES = CALLOUT_VARIANT_STYLES;
|
|
2218
|
+
exports.DIVIDER_STYLE_CLASSES = DIVIDER_STYLE_CLASSES;
|
|
2219
|
+
exports.FONT_SIZE_CLASSES = FONT_SIZE_CLASSES;
|
|
2220
|
+
exports.PagesEditor = PagesEditor;
|
|
2221
|
+
exports.QUOTE_STYLE_CLASSES = QUOTE_STYLE_CLASSES;
|
|
2222
|
+
exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
|
|
2223
|
+
exports.cloneBlock = cloneBlock;
|
|
2224
|
+
exports.createCalloutBlock = createCalloutBlock;
|
|
2225
|
+
exports.createCodeBlock = createCodeBlock;
|
|
2226
|
+
exports.createDividerBlock = createDividerBlock;
|
|
2227
|
+
exports.createEmptyEditorData = createEmptyEditorData;
|
|
2228
|
+
exports.createHeadingBlock = createHeadingBlock;
|
|
2229
|
+
exports.createImageBlock = createImageBlock;
|
|
2230
|
+
exports.createListBlock = createListBlock;
|
|
2231
|
+
exports.createQuoteBlock = createQuoteBlock;
|
|
2232
|
+
exports.createTableBlock = createTableBlock;
|
|
2233
|
+
exports.createTextBlock = createTextBlock;
|
|
2234
|
+
exports.fileToBase64 = fileToBase64;
|
|
2235
|
+
exports.generateId = generateId;
|
|
2236
|
+
exports.getMutedTextClass = getMutedTextClass;
|
|
2237
|
+
exports.getPlaceholderClass = getPlaceholderClass;
|
|
2238
|
+
exports.getPrimaryTextClass = getPrimaryTextClass;
|
|
2239
|
+
exports.getSecondaryTextClass = getSecondaryTextClass;
|
|
2240
|
+
exports.getSmallToolbarButtonClass = getSmallToolbarButtonClass;
|
|
2241
|
+
exports.getToolbarButtonClass = getToolbarButtonClass;
|
|
2242
|
+
exports.getToolbarContainerClass = getToolbarContainerClass;
|
|
2243
|
+
exports.getToolbarDividerClass = getToolbarDividerClass;
|
|
2244
|
+
exports.isDarkTheme = isDarkTheme;
|
|
2245
|
+
exports.moveArrayItem = moveArrayItem;
|
|
2246
|
+
exports.useAutoResize = useAutoResize;
|
|
2247
|
+
exports.useBlockToolbar = useBlockToolbar;
|
|
2248
|
+
exports.useClickOutside = useClickOutside;
|
|
2249
|
+
exports.validateEditorData = validateEditorData;
|