magic-editor-x 1.0.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 +890 -0
- package/dist/_chunks/App-B1FgOsWa.mjs +2143 -0
- package/dist/_chunks/App-mtrlABtd.js +2146 -0
- package/dist/_chunks/LicensePage-BnyWSrWs.js +375 -0
- package/dist/_chunks/LicensePage-CWH-AFR-.mjs +373 -0
- package/dist/_chunks/LiveCollaborationPanel-DbDHwr2C.js +222 -0
- package/dist/_chunks/LiveCollaborationPanel-ryjcDAA7.mjs +220 -0
- package/dist/_chunks/Settings-Bk9bxJTy.js +440 -0
- package/dist/_chunks/Settings-D-V2MLVm.mjs +438 -0
- package/dist/_chunks/de-CSrHZWEb.mjs +295 -0
- package/dist/_chunks/de-CzSo1oD2.js +295 -0
- package/dist/_chunks/en-DuQun2v4.mjs +295 -0
- package/dist/_chunks/en-DxIkVPUh.js +295 -0
- package/dist/_chunks/es-DAQ_97zx.js +273 -0
- package/dist/_chunks/es-DEB0CA8S.mjs +273 -0
- package/dist/_chunks/fr-Bqkhvdx2.mjs +273 -0
- package/dist/_chunks/fr-ChPabvNP.js +273 -0
- package/dist/_chunks/getTranslation-C4uWR0DB.mjs +50985 -0
- package/dist/_chunks/getTranslation-D35vbDap.js +51001 -0
- package/dist/_chunks/index-B5MzUyo0.mjs +2541 -0
- package/dist/_chunks/index-BRVqbnOb.mjs +4450 -0
- package/dist/_chunks/index-BiLy_f7C.js +2540 -0
- package/dist/_chunks/index-CQx7-dFP.js +4472 -0
- package/dist/_chunks/pt-BMoYltav.mjs +273 -0
- package/dist/_chunks/pt-Cm74LpyZ.js +273 -0
- package/dist/_chunks/tools-CjnQJ9w2.mjs +2155 -0
- package/dist/_chunks/tools-DNt2tioN.js +2186 -0
- package/dist/admin/index.js +3 -0
- package/dist/admin/index.mjs +4 -0
- package/dist/server/index.js +2554 -0
- package/dist/server/index.mjs +2544 -0
- package/dist/style.css +164 -0
- package/package.json +122 -0
- package/pics/collab-magiceditorX.png +0 -0
- package/pics/editorX.png +0 -0
- package/pics/liveCollabwidget1.png +0 -0
|
@@ -0,0 +1,4472 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const getTranslation = require("./getTranslation-D35vbDap.js");
|
|
6
|
+
const styled = require("styled-components");
|
|
7
|
+
const outline = require("@heroicons/react/24/outline");
|
|
8
|
+
const EditorJS = require("@editorjs/editorjs");
|
|
9
|
+
const tools = require("./tools-DNt2tioN.js");
|
|
10
|
+
const admin = require("@strapi/strapi/admin");
|
|
11
|
+
const index = require("./index-BiLy_f7C.js");
|
|
12
|
+
const socket_ioClient = require("socket.io-client");
|
|
13
|
+
const Y = require("yjs");
|
|
14
|
+
const yIndexeddb = require("y-indexeddb");
|
|
15
|
+
const reactRouterDom = require("react-router-dom");
|
|
16
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
20
|
+
if (e) {
|
|
21
|
+
for (const k in e) {
|
|
22
|
+
if (k !== "default") {
|
|
23
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: () => e[k]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
35
|
+
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
36
|
+
const EditorJS__default = /* @__PURE__ */ _interopDefault(EditorJS);
|
|
37
|
+
const Y__namespace = /* @__PURE__ */ _interopNamespace(Y);
|
|
38
|
+
const getBackendUrl = () => {
|
|
39
|
+
return window.location.origin;
|
|
40
|
+
};
|
|
41
|
+
const prefixFileUrl = (url) => {
|
|
42
|
+
if (!url) return url;
|
|
43
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
44
|
+
return url;
|
|
45
|
+
}
|
|
46
|
+
return `${getBackendUrl()}${url}`;
|
|
47
|
+
};
|
|
48
|
+
const MediaLibComponent = ({
|
|
49
|
+
isOpen = false,
|
|
50
|
+
onChange = () => {
|
|
51
|
+
},
|
|
52
|
+
onToggle = () => {
|
|
53
|
+
},
|
|
54
|
+
allowedTypes = ["images", "files", "videos", "audios"],
|
|
55
|
+
multiple = true
|
|
56
|
+
}) => {
|
|
57
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
58
|
+
const [retryCount, setRetryCount] = React.useState(0);
|
|
59
|
+
const components = admin.useStrapiApp("MediaLibComponent", (state) => state.components);
|
|
60
|
+
const MediaLibraryDialog = components?.["media-library"];
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (isOpen && !MediaLibraryDialog && retryCount < 5) {
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
setRetryCount((prev) => prev + 1);
|
|
65
|
+
}, 200);
|
|
66
|
+
return () => clearTimeout(timer);
|
|
67
|
+
}
|
|
68
|
+
setIsLoading(false);
|
|
69
|
+
}, [isOpen, MediaLibraryDialog, retryCount]);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (!isOpen) {
|
|
72
|
+
setRetryCount(0);
|
|
73
|
+
setIsLoading(true);
|
|
74
|
+
}
|
|
75
|
+
}, [isOpen]);
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
if (isOpen) {
|
|
78
|
+
console.log("[Magic Editor X] MediaLib opened");
|
|
79
|
+
console.log("[Magic Editor X] Available components:", Object.keys(components || {}));
|
|
80
|
+
console.log("[Magic Editor X] MediaLibraryDialog:", MediaLibraryDialog ? "✅ Found" : "❌ Not found");
|
|
81
|
+
console.log("[Magic Editor X] Retry count:", retryCount);
|
|
82
|
+
}
|
|
83
|
+
}, [isOpen, components, MediaLibraryDialog, retryCount]);
|
|
84
|
+
const handleSelectAssets = React.useCallback((files) => {
|
|
85
|
+
console.log("[Magic Editor X] Selected assets:", files);
|
|
86
|
+
if (!files || files.length === 0) {
|
|
87
|
+
onToggle();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const formattedFiles = files.map((file) => ({
|
|
91
|
+
alt: file.alternativeText || file.name || "",
|
|
92
|
+
url: prefixFileUrl(file.url),
|
|
93
|
+
width: file.width,
|
|
94
|
+
height: file.height,
|
|
95
|
+
size: file.size,
|
|
96
|
+
mime: file.mime,
|
|
97
|
+
formats: file.formats,
|
|
98
|
+
name: file.name,
|
|
99
|
+
caption: file.caption || "",
|
|
100
|
+
id: file.id,
|
|
101
|
+
documentId: file.documentId
|
|
102
|
+
}));
|
|
103
|
+
console.log("[Magic Editor X] Formatted files:", formattedFiles);
|
|
104
|
+
onChange(formattedFiles);
|
|
105
|
+
}, [onChange, onToggle]);
|
|
106
|
+
const handleClose = React.useCallback(() => {
|
|
107
|
+
console.log("[Magic Editor X] MediaLib closing");
|
|
108
|
+
onToggle();
|
|
109
|
+
}, [onToggle]);
|
|
110
|
+
if (!isOpen) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
if (isLoading && !MediaLibraryDialog && retryCount < 5) {
|
|
114
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
style: {
|
|
118
|
+
position: "fixed",
|
|
119
|
+
top: 0,
|
|
120
|
+
left: 0,
|
|
121
|
+
right: 0,
|
|
122
|
+
bottom: 0,
|
|
123
|
+
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
124
|
+
display: "flex",
|
|
125
|
+
alignItems: "center",
|
|
126
|
+
justifyContent: "center",
|
|
127
|
+
zIndex: 1e5
|
|
128
|
+
// Higher than fullscreen (9999)
|
|
129
|
+
},
|
|
130
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
131
|
+
"div",
|
|
132
|
+
{
|
|
133
|
+
style: {
|
|
134
|
+
backgroundColor: "white",
|
|
135
|
+
padding: "40px",
|
|
136
|
+
borderRadius: "16px",
|
|
137
|
+
textAlign: "center",
|
|
138
|
+
maxWidth: "400px",
|
|
139
|
+
boxShadow: "0 20px 40px rgba(0, 0, 0, 0.2)"
|
|
140
|
+
},
|
|
141
|
+
children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
143
|
+
width: "48px",
|
|
144
|
+
height: "48px",
|
|
145
|
+
margin: "0 auto 20px",
|
|
146
|
+
border: "4px solid #e2e8f0",
|
|
147
|
+
borderTop: "4px solid #7C3AED",
|
|
148
|
+
borderRadius: "50%",
|
|
149
|
+
animation: "spin 1s linear infinite"
|
|
150
|
+
} }),
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
152
|
+
@keyframes spin {
|
|
153
|
+
0% { transform: rotate(0deg); }
|
|
154
|
+
100% { transform: rotate(360deg); }
|
|
155
|
+
}
|
|
156
|
+
` }),
|
|
157
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: "14px", color: "#64748b" }, children: "Media Library wird geladen..." })
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (!MediaLibraryDialog) {
|
|
165
|
+
console.warn("[Magic Editor X] Media Library component not available after retries");
|
|
166
|
+
console.log("[Magic Editor X] Registered components:", Object.keys(components || {}));
|
|
167
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
style: {
|
|
171
|
+
position: "fixed",
|
|
172
|
+
top: 0,
|
|
173
|
+
left: 0,
|
|
174
|
+
right: 0,
|
|
175
|
+
bottom: 0,
|
|
176
|
+
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
177
|
+
display: "flex",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
justifyContent: "center",
|
|
180
|
+
zIndex: 1e5
|
|
181
|
+
// Higher than fullscreen (9999)
|
|
182
|
+
},
|
|
183
|
+
onClick: handleClose,
|
|
184
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
185
|
+
"div",
|
|
186
|
+
{
|
|
187
|
+
style: {
|
|
188
|
+
backgroundColor: "white",
|
|
189
|
+
padding: "40px",
|
|
190
|
+
borderRadius: "16px",
|
|
191
|
+
textAlign: "center",
|
|
192
|
+
maxWidth: "400px",
|
|
193
|
+
boxShadow: "0 20px 40px rgba(0, 0, 0, 0.2)"
|
|
194
|
+
},
|
|
195
|
+
onClick: (e) => e.stopPropagation(),
|
|
196
|
+
children: [
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
198
|
+
width: "64px",
|
|
199
|
+
height: "64px",
|
|
200
|
+
margin: "0 auto 20px",
|
|
201
|
+
background: "linear-gradient(135deg, #fee2e2 0%, #fecaca 100%)",
|
|
202
|
+
borderRadius: "50%",
|
|
203
|
+
display: "flex",
|
|
204
|
+
alignItems: "center",
|
|
205
|
+
justifyContent: "center"
|
|
206
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "#ef4444", strokeWidth: "2", children: [
|
|
207
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
210
|
+
] }) }),
|
|
211
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: {
|
|
212
|
+
fontSize: "18px",
|
|
213
|
+
fontWeight: "600",
|
|
214
|
+
color: "#1e293b",
|
|
215
|
+
marginBottom: "12px"
|
|
216
|
+
}, children: "Media Library nicht verfügbar" }),
|
|
217
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: {
|
|
218
|
+
fontSize: "14px",
|
|
219
|
+
color: "#64748b",
|
|
220
|
+
marginBottom: "16px",
|
|
221
|
+
lineHeight: "1.5"
|
|
222
|
+
}, children: "Die Strapi Media Library konnte nicht geladen werden." }),
|
|
223
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
224
|
+
fontSize: "12px",
|
|
225
|
+
color: "#94a3b8",
|
|
226
|
+
marginBottom: "24px",
|
|
227
|
+
background: "#f1f5f9",
|
|
228
|
+
padding: "8px 12px",
|
|
229
|
+
borderRadius: "6px",
|
|
230
|
+
fontFamily: "monospace"
|
|
231
|
+
}, children: [
|
|
232
|
+
"Verfügbare Komponenten: ",
|
|
233
|
+
Object.keys(components || {}).join(", ") || "Keine"
|
|
234
|
+
] }),
|
|
235
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
"button",
|
|
237
|
+
{
|
|
238
|
+
onClick: handleClose,
|
|
239
|
+
style: {
|
|
240
|
+
padding: "12px 24px",
|
|
241
|
+
background: "linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%)",
|
|
242
|
+
color: "white",
|
|
243
|
+
border: "none",
|
|
244
|
+
borderRadius: "8px",
|
|
245
|
+
fontSize: "14px",
|
|
246
|
+
fontWeight: "600",
|
|
247
|
+
cursor: "pointer",
|
|
248
|
+
transition: "all 0.2s ease"
|
|
249
|
+
},
|
|
250
|
+
onMouseOver: (e) => e.target.style.transform = "translateY(-1px)",
|
|
251
|
+
onMouseOut: (e) => e.target.style.transform = "translateY(0)",
|
|
252
|
+
children: "Schließen"
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MediaLibErrorBoundary, { onClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
262
|
+
MediaLibraryDialog,
|
|
263
|
+
{
|
|
264
|
+
allowedTypes,
|
|
265
|
+
onClose: handleClose,
|
|
266
|
+
onSelectAssets: handleSelectAssets,
|
|
267
|
+
multiple
|
|
268
|
+
}
|
|
269
|
+
) });
|
|
270
|
+
};
|
|
271
|
+
class MediaLibErrorBoundary extends React__default.default.Component {
|
|
272
|
+
constructor(props) {
|
|
273
|
+
super(props);
|
|
274
|
+
this.state = { hasError: false, error: null };
|
|
275
|
+
}
|
|
276
|
+
static getDerivedStateFromError(error) {
|
|
277
|
+
return { hasError: true, error };
|
|
278
|
+
}
|
|
279
|
+
componentDidCatch(error, errorInfo) {
|
|
280
|
+
console.error("[Magic Editor X] Media Library error:", error, errorInfo);
|
|
281
|
+
}
|
|
282
|
+
render() {
|
|
283
|
+
if (this.state.hasError) {
|
|
284
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
285
|
+
"div",
|
|
286
|
+
{
|
|
287
|
+
style: {
|
|
288
|
+
position: "fixed",
|
|
289
|
+
top: 0,
|
|
290
|
+
left: 0,
|
|
291
|
+
right: 0,
|
|
292
|
+
bottom: 0,
|
|
293
|
+
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
294
|
+
display: "flex",
|
|
295
|
+
alignItems: "center",
|
|
296
|
+
justifyContent: "center",
|
|
297
|
+
zIndex: 1e5
|
|
298
|
+
},
|
|
299
|
+
onClick: this.props.onClose,
|
|
300
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
301
|
+
"div",
|
|
302
|
+
{
|
|
303
|
+
style: {
|
|
304
|
+
backgroundColor: "white",
|
|
305
|
+
padding: "40px",
|
|
306
|
+
borderRadius: "16px",
|
|
307
|
+
textAlign: "center",
|
|
308
|
+
maxWidth: "450px",
|
|
309
|
+
boxShadow: "0 20px 40px rgba(0, 0, 0, 0.2)"
|
|
310
|
+
},
|
|
311
|
+
onClick: (e) => e.stopPropagation(),
|
|
312
|
+
children: [
|
|
313
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
314
|
+
width: "64px",
|
|
315
|
+
height: "64px",
|
|
316
|
+
margin: "0 auto 20px",
|
|
317
|
+
background: "linear-gradient(135deg, #fef3c7 0%, #fde68a 100%)",
|
|
318
|
+
borderRadius: "50%",
|
|
319
|
+
display: "flex",
|
|
320
|
+
alignItems: "center",
|
|
321
|
+
justifyContent: "center"
|
|
322
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "#d97706", strokeWidth: "2", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }) }),
|
|
323
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: {
|
|
324
|
+
fontSize: "18px",
|
|
325
|
+
fontWeight: "600",
|
|
326
|
+
color: "#1e293b",
|
|
327
|
+
marginBottom: "12px"
|
|
328
|
+
}, children: "Keine Upload-Berechtigung" }),
|
|
329
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { style: {
|
|
330
|
+
fontSize: "14px",
|
|
331
|
+
color: "#64748b",
|
|
332
|
+
marginBottom: "20px",
|
|
333
|
+
lineHeight: "1.6"
|
|
334
|
+
}, children: [
|
|
335
|
+
"Du benötigst Upload-Berechtigungen um die Media Library zu nutzen.",
|
|
336
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
337
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
338
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Lösung:" }),
|
|
339
|
+
" Bitte einen Super Admin, dir die Upload-Rechte unter ",
|
|
340
|
+
/* @__PURE__ */ jsxRuntime.jsx("em", { children: "Settings → Administration panel → Roles" }),
|
|
341
|
+
" zu geben."
|
|
342
|
+
] }),
|
|
343
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
344
|
+
"button",
|
|
345
|
+
{
|
|
346
|
+
onClick: this.props.onClose,
|
|
347
|
+
style: {
|
|
348
|
+
padding: "12px 24px",
|
|
349
|
+
background: "linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%)",
|
|
350
|
+
color: "white",
|
|
351
|
+
border: "none",
|
|
352
|
+
borderRadius: "8px",
|
|
353
|
+
fontSize: "14px",
|
|
354
|
+
fontWeight: "600",
|
|
355
|
+
cursor: "pointer"
|
|
356
|
+
},
|
|
357
|
+
children: "Schließen"
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return this.props.children;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const getToggleFunc = ({ openStateSetter, indexStateSetter }) => {
|
|
370
|
+
return (idx) => {
|
|
371
|
+
if (idx !== void 0 && idx !== null) {
|
|
372
|
+
indexStateSetter(idx);
|
|
373
|
+
}
|
|
374
|
+
openStateSetter((prev) => !prev);
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
const changeFunc = ({ indexStateSetter, editor, data, index: index2 }) => {
|
|
378
|
+
if (!editor || !data || data.length === 0) {
|
|
379
|
+
indexStateSetter(-1);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
let insertedBlocksCount = 0;
|
|
383
|
+
data.forEach((entry) => {
|
|
384
|
+
if (!entry.mime || !entry.mime.includes("image")) {
|
|
385
|
+
console.warn("[Magic Editor X] Skipping non-image file:", entry.name);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const newBlockType = "image";
|
|
389
|
+
const newBlockData = {
|
|
390
|
+
file: {
|
|
391
|
+
url: entry.url.replace(window.location.origin, ""),
|
|
392
|
+
mime: entry.mime,
|
|
393
|
+
height: entry.height,
|
|
394
|
+
width: entry.width,
|
|
395
|
+
size: entry.size,
|
|
396
|
+
alt: entry.alt || entry.name || "",
|
|
397
|
+
formats: entry.formats
|
|
398
|
+
},
|
|
399
|
+
caption: entry.caption || "",
|
|
400
|
+
withBorder: false,
|
|
401
|
+
withBackground: false,
|
|
402
|
+
stretched: false
|
|
403
|
+
};
|
|
404
|
+
try {
|
|
405
|
+
editor.blocks.insert(
|
|
406
|
+
newBlockType,
|
|
407
|
+
newBlockData,
|
|
408
|
+
{},
|
|
409
|
+
index2 + insertedBlocksCount,
|
|
410
|
+
true
|
|
411
|
+
);
|
|
412
|
+
insertedBlocksCount++;
|
|
413
|
+
} catch (error) {
|
|
414
|
+
console.error("[Magic Editor X] Error inserting image block:", error);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
if (insertedBlocksCount > 0) {
|
|
418
|
+
try {
|
|
419
|
+
editor.blocks.delete(index2 + insertedBlocksCount);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
console.warn("[Magic Editor X] Could not delete placeholder block:", error);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
indexStateSetter(-1);
|
|
425
|
+
};
|
|
426
|
+
const pluginId = "magic-editor-x";
|
|
427
|
+
const SOCKET_FALLBACK_PATH = "/magic-editor-x/realtime";
|
|
428
|
+
const CURSOR_COLORS = [
|
|
429
|
+
{ bg: "#EF4444", text: "#FFFFFF", name: "Red" },
|
|
430
|
+
// Red
|
|
431
|
+
{ bg: "#3B82F6", text: "#FFFFFF", name: "Blue" },
|
|
432
|
+
// Blue
|
|
433
|
+
{ bg: "#10B981", text: "#FFFFFF", name: "Green" },
|
|
434
|
+
// Green
|
|
435
|
+
{ bg: "#F59E0B", text: "#000000", name: "Amber" },
|
|
436
|
+
// Amber
|
|
437
|
+
{ bg: "#8B5CF6", text: "#FFFFFF", name: "Purple" },
|
|
438
|
+
// Purple
|
|
439
|
+
{ bg: "#EC4899", text: "#FFFFFF", name: "Pink" },
|
|
440
|
+
// Pink
|
|
441
|
+
{ bg: "#06B6D4", text: "#FFFFFF", name: "Cyan" },
|
|
442
|
+
// Cyan
|
|
443
|
+
{ bg: "#F97316", text: "#FFFFFF", name: "Orange" }
|
|
444
|
+
// Orange
|
|
445
|
+
];
|
|
446
|
+
const getUserColor = (userId) => {
|
|
447
|
+
if (!userId) return CURSOR_COLORS[0];
|
|
448
|
+
const hash = String(userId).split("").reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
|
449
|
+
return CURSOR_COLORS[hash % CURSOR_COLORS.length];
|
|
450
|
+
};
|
|
451
|
+
const useMagicCollaboration = ({
|
|
452
|
+
enabled,
|
|
453
|
+
roomId,
|
|
454
|
+
fieldName,
|
|
455
|
+
initialValue,
|
|
456
|
+
onRemoteUpdate
|
|
457
|
+
// Callback when remote update is received
|
|
458
|
+
}) => {
|
|
459
|
+
const { get, post } = admin.useFetchClient();
|
|
460
|
+
const authContext = admin.useAuth("useMagicCollaboration", (state) => state);
|
|
461
|
+
const user = authContext?.user || null;
|
|
462
|
+
const [status, setStatus] = React.useState(enabled ? "idle" : "disabled");
|
|
463
|
+
const [error, setError] = React.useState(null);
|
|
464
|
+
const [peers, setPeers] = React.useState([]);
|
|
465
|
+
const [awareness, setAwareness] = React.useState({});
|
|
466
|
+
const [collabRole, setCollabRole] = React.useState(null);
|
|
467
|
+
const [canEdit, setCanEdit] = React.useState(null);
|
|
468
|
+
const socketRef = React.useRef(null);
|
|
469
|
+
const persistenceRef = React.useRef(null);
|
|
470
|
+
const bootstrappedRef = React.useRef(false);
|
|
471
|
+
const onRemoteUpdateRef = React.useRef(onRemoteUpdate);
|
|
472
|
+
React.useEffect(() => {
|
|
473
|
+
onRemoteUpdateRef.current = onRemoteUpdate;
|
|
474
|
+
}, [onRemoteUpdate]);
|
|
475
|
+
const { doc, blocksMap, metaMap } = React.useMemo(() => {
|
|
476
|
+
const yDoc = new Y__namespace.Doc();
|
|
477
|
+
return {
|
|
478
|
+
doc: yDoc,
|
|
479
|
+
blocksMap: yDoc.getMap("blocks"),
|
|
480
|
+
// Each block stored by ID
|
|
481
|
+
metaMap: yDoc.getMap("meta")
|
|
482
|
+
// Metadata (time, blockOrder, etc.)
|
|
483
|
+
};
|
|
484
|
+
}, [roomId]);
|
|
485
|
+
React.useEffect(() => {
|
|
486
|
+
return () => {
|
|
487
|
+
doc.destroy();
|
|
488
|
+
};
|
|
489
|
+
}, [doc]);
|
|
490
|
+
React.useEffect(() => {
|
|
491
|
+
bootstrappedRef.current = false;
|
|
492
|
+
setPeers([]);
|
|
493
|
+
setAwareness({});
|
|
494
|
+
if (socketRef.current) {
|
|
495
|
+
socketRef.current.disconnect();
|
|
496
|
+
socketRef.current = null;
|
|
497
|
+
}
|
|
498
|
+
return () => {
|
|
499
|
+
if (socketRef.current) {
|
|
500
|
+
socketRef.current.disconnect();
|
|
501
|
+
socketRef.current = null;
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}, [roomId]);
|
|
505
|
+
React.useEffect(() => {
|
|
506
|
+
if (!enabled) return void 0;
|
|
507
|
+
const cleanupInterval = setInterval(() => {
|
|
508
|
+
const now = Date.now();
|
|
509
|
+
const staleThreshold = 3e4;
|
|
510
|
+
setAwareness((prev) => {
|
|
511
|
+
const next = { ...prev };
|
|
512
|
+
let changed = false;
|
|
513
|
+
Object.keys(next).forEach((key) => {
|
|
514
|
+
if (now - next[key].lastUpdate > staleThreshold) {
|
|
515
|
+
delete next[key];
|
|
516
|
+
changed = true;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
return changed ? next : prev;
|
|
520
|
+
});
|
|
521
|
+
}, 1e4);
|
|
522
|
+
return () => clearInterval(cleanupInterval);
|
|
523
|
+
}, [enabled]);
|
|
524
|
+
React.useEffect(() => {
|
|
525
|
+
if (!enabled) {
|
|
526
|
+
setStatus("disabled");
|
|
527
|
+
} else if (status === "disabled") {
|
|
528
|
+
setStatus("idle");
|
|
529
|
+
}
|
|
530
|
+
}, [enabled, status]);
|
|
531
|
+
React.useEffect(() => {
|
|
532
|
+
if (!enabled || !roomId) {
|
|
533
|
+
return void 0;
|
|
534
|
+
}
|
|
535
|
+
bootstrappedRef.current = true;
|
|
536
|
+
console.log("[Magic Collab] [READY] Client ready, waiting for server sync...");
|
|
537
|
+
return void 0;
|
|
538
|
+
}, [enabled, roomId]);
|
|
539
|
+
React.useEffect(() => {
|
|
540
|
+
if (!enabled || !roomId || !doc) {
|
|
541
|
+
return void 0;
|
|
542
|
+
}
|
|
543
|
+
const persistenceKey = `magic-editor-x::${roomId}`;
|
|
544
|
+
try {
|
|
545
|
+
const persistence = new yIndexeddb.IndexeddbPersistence(persistenceKey, doc);
|
|
546
|
+
persistenceRef.current = persistence;
|
|
547
|
+
persistence.on("synced", () => {
|
|
548
|
+
console.log("[Magic Collab] [CACHE] IndexedDB synced for room:", roomId);
|
|
549
|
+
const blockOrder = metaMap.get("blockOrder");
|
|
550
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "useMagicCollaboration:indexeddb:synced", message: "IndexedDB synced - loaded local state", data: { blocksMapSize: blocksMap.size, blocksMapKeys: Array.from(blocksMap.keys()), blockOrder, roomId, persistenceKey }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "H" }) }).catch(() => {
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
console.log("[Magic Collab] [CACHE] IndexedDB persistence initialized:", persistenceKey);
|
|
554
|
+
} catch (e) {
|
|
555
|
+
console.warn("[Magic Collab] IndexedDB persistence failed:", e.message);
|
|
556
|
+
}
|
|
557
|
+
return () => {
|
|
558
|
+
if (persistenceRef.current) {
|
|
559
|
+
try {
|
|
560
|
+
persistenceRef.current.destroy();
|
|
561
|
+
persistenceRef.current = null;
|
|
562
|
+
console.log("[Magic Collab] [CACHE] IndexedDB persistence destroyed");
|
|
563
|
+
} catch (e) {
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}, [enabled, roomId, doc]);
|
|
568
|
+
const initialValueRef = React.useRef(initialValue);
|
|
569
|
+
React.useEffect(() => {
|
|
570
|
+
initialValueRef.current = initialValue;
|
|
571
|
+
}, [initialValue]);
|
|
572
|
+
React.useEffect(() => {
|
|
573
|
+
if (!enabled || !roomId || !user) {
|
|
574
|
+
return void 0;
|
|
575
|
+
}
|
|
576
|
+
if (socketRef.current?.connected) {
|
|
577
|
+
return void 0;
|
|
578
|
+
}
|
|
579
|
+
let cancelled = false;
|
|
580
|
+
setError(null);
|
|
581
|
+
setStatus("requesting");
|
|
582
|
+
const startSession = async () => {
|
|
583
|
+
try {
|
|
584
|
+
console.log("[Magic Collab] [SESSION] Requesting session for room:", roomId);
|
|
585
|
+
const { data } = await post(`/${pluginId}/collab/session`, {
|
|
586
|
+
roomId,
|
|
587
|
+
fieldName,
|
|
588
|
+
initialValue: initialValueRef.current || "",
|
|
589
|
+
meta: { roomId, fieldName }
|
|
590
|
+
});
|
|
591
|
+
console.log("[Magic Collab] [SUCCESS] Session response:", data);
|
|
592
|
+
if (cancelled) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (!data || !data.token) {
|
|
596
|
+
throw new Error("Invalid session response: missing token");
|
|
597
|
+
}
|
|
598
|
+
const userRole = data.role || "viewer";
|
|
599
|
+
const userCanEdit = data.canEdit !== void 0 ? data.canEdit : ["editor", "owner"].includes(userRole);
|
|
600
|
+
setCollabRole(userRole);
|
|
601
|
+
setCanEdit(userCanEdit);
|
|
602
|
+
console.log("[Magic Collab] [ROLE] User role:", userRole, "| Can edit:", userCanEdit);
|
|
603
|
+
setStatus("connecting");
|
|
604
|
+
const wsUrl = data.wsUrl || window.location.origin;
|
|
605
|
+
const wsPath = data.wsPath || SOCKET_FALLBACK_PATH;
|
|
606
|
+
console.log("[Magic Collab] [SOCKET] Connecting to Socket.io:", { wsUrl, wsPath });
|
|
607
|
+
const socket = socket_ioClient.io(wsUrl, {
|
|
608
|
+
path: wsPath,
|
|
609
|
+
auth: { token: data.token },
|
|
610
|
+
transports: ["websocket", "polling"],
|
|
611
|
+
// Add polling as fallback
|
|
612
|
+
reconnection: true,
|
|
613
|
+
reconnectionDelay: 1e3,
|
|
614
|
+
reconnectionAttempts: 5
|
|
615
|
+
});
|
|
616
|
+
socketRef.current = socket;
|
|
617
|
+
socket.on("connect", () => {
|
|
618
|
+
setStatus("connected");
|
|
619
|
+
console.log("[Magic Collab] [SUCCESS] Connected to room:", roomId);
|
|
620
|
+
});
|
|
621
|
+
socket.on("disconnect", (reason) => {
|
|
622
|
+
setStatus("disconnected");
|
|
623
|
+
console.log("[Magic Collab] [WARNING] Disconnected:", reason);
|
|
624
|
+
});
|
|
625
|
+
socket.on("connect_error", (error2) => {
|
|
626
|
+
console.error("[Magic Collab] [ERROR] Connection error:", error2);
|
|
627
|
+
setStatus("error");
|
|
628
|
+
setError(`Connection failed: ${error2.message}`);
|
|
629
|
+
});
|
|
630
|
+
socket.on("collab:error", (payload) => {
|
|
631
|
+
console.error("[Magic Collab] [ERROR] Collaboration error:", payload);
|
|
632
|
+
setError(payload?.message || "Realtime collaboration error");
|
|
633
|
+
});
|
|
634
|
+
socket.on("collab:sync", (update) => {
|
|
635
|
+
if (update) {
|
|
636
|
+
console.log("[Magic Collab] [SYNC] Syncing initial state, update size:", update.length, "bytes");
|
|
637
|
+
try {
|
|
638
|
+
const blockOrderBefore = metaMap.get("blockOrder");
|
|
639
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "useMagicCollaboration:collab:sync:before", message: "BEFORE applying server sync", data: { blocksMapSize: blocksMap.size, blocksMapKeys: Array.from(blocksMap.keys()), blockOrder: blockOrderBefore, roomId }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "F" }) }).catch(() => {
|
|
640
|
+
});
|
|
641
|
+
const beforeBlockCount = blocksMap.size;
|
|
642
|
+
console.log("[Magic Collab] [DATA] Y.Map BEFORE sync - block count:", beforeBlockCount);
|
|
643
|
+
Y__namespace.applyUpdate(doc, new Uint8Array(update), "remote");
|
|
644
|
+
const afterBlockCount = blocksMap.size;
|
|
645
|
+
console.log("[Magic Collab] [DATA] Y.Map AFTER sync - block count:", afterBlockCount);
|
|
646
|
+
const blockOrderAfter = metaMap.get("blockOrder");
|
|
647
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "useMagicCollaboration:collab:sync:after", message: "AFTER applying server sync", data: { blocksMapSize: blocksMap.size, blocksMapKeys: Array.from(blocksMap.keys()), blockOrder: blockOrderAfter, roomId }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "F" }) }).catch(() => {
|
|
648
|
+
});
|
|
649
|
+
if (onRemoteUpdateRef.current) {
|
|
650
|
+
console.log("[Magic Collab] [CALLBACK] Calling onRemoteUpdate callback after sync");
|
|
651
|
+
setTimeout(() => {
|
|
652
|
+
onRemoteUpdateRef.current();
|
|
653
|
+
}, 0);
|
|
654
|
+
}
|
|
655
|
+
} catch (err) {
|
|
656
|
+
console.error("[Magic Collab] Failed to apply initial sync:", err);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
socket.on("collab:update", (update) => {
|
|
661
|
+
if (update) {
|
|
662
|
+
console.log("[Magic Collab] [UPDATE] Received remote update:", update.length, "bytes");
|
|
663
|
+
try {
|
|
664
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "useMagicCollaboration:collab:update:before", message: "BEFORE applying remote update", data: { blocksMapSize: blocksMap.size, blocksMapKeys: Array.from(blocksMap.keys()), blockOrder: metaMap.get("blockOrder"), updateSize: update.length, roomId }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "G" }) }).catch(() => {
|
|
665
|
+
});
|
|
666
|
+
const beforeBlockCount = blocksMap.size;
|
|
667
|
+
console.log("[Magic Collab] [DATA] Y.Map BEFORE update - blocks:", beforeBlockCount);
|
|
668
|
+
Y__namespace.applyUpdate(doc, new Uint8Array(update), "remote");
|
|
669
|
+
const afterBlockCount = blocksMap.size;
|
|
670
|
+
console.log("[Magic Collab] [DATA] Y.Map AFTER update - blocks:", afterBlockCount);
|
|
671
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "useMagicCollaboration:collab:update:after", message: "AFTER applying remote update", data: { blocksMapSize: blocksMap.size, blocksMapKeys: Array.from(blocksMap.keys()), blockOrder: metaMap.get("blockOrder"), roomId }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "G" }) }).catch(() => {
|
|
672
|
+
});
|
|
673
|
+
if (onRemoteUpdateRef.current) {
|
|
674
|
+
console.log("[Magic Collab] [CALLBACK] Calling onRemoteUpdate callback");
|
|
675
|
+
setTimeout(() => {
|
|
676
|
+
onRemoteUpdateRef.current();
|
|
677
|
+
}, 0);
|
|
678
|
+
}
|
|
679
|
+
} catch (err) {
|
|
680
|
+
console.error("[Magic Collab] Failed to apply update:", err);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
socket.on("collab:presence", ({ type, user: peerUser }) => {
|
|
685
|
+
if (!peerUser?.id) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
console.log("[Magic Collab] [PEERS] Peer presence:", type, peerUser.email);
|
|
689
|
+
setPeers((current) => {
|
|
690
|
+
if (type === "leave") {
|
|
691
|
+
setAwareness((prev) => {
|
|
692
|
+
const next = { ...prev };
|
|
693
|
+
delete next[peerUser.id];
|
|
694
|
+
return next;
|
|
695
|
+
});
|
|
696
|
+
return current.filter((peer) => peer.id !== peerUser.id);
|
|
697
|
+
}
|
|
698
|
+
const exists = current.some((peer) => peer.id === peerUser.id);
|
|
699
|
+
if (exists) {
|
|
700
|
+
return current;
|
|
701
|
+
}
|
|
702
|
+
return [...current, peerUser];
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
socket.on("collab:awareness", ({ user: peerUser, payload }) => {
|
|
706
|
+
if (!peerUser?.id) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (user && peerUser.id === user.id) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
if (payload?.blockIndex === -1 || payload?.blockIndex === null) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
setAwareness((prev) => ({
|
|
716
|
+
...prev,
|
|
717
|
+
[peerUser.id]: {
|
|
718
|
+
user: peerUser,
|
|
719
|
+
cursor: payload?.cursor || null,
|
|
720
|
+
blockId: payload?.blockId || null,
|
|
721
|
+
blockIndex: payload?.blockIndex ?? null,
|
|
722
|
+
selection: payload?.selection || null,
|
|
723
|
+
color: getUserColor(peerUser.id),
|
|
724
|
+
lastUpdate: Date.now()
|
|
725
|
+
}
|
|
726
|
+
}));
|
|
727
|
+
});
|
|
728
|
+
} catch (err) {
|
|
729
|
+
if (!cancelled) {
|
|
730
|
+
console.error("[Magic Collab] [ERROR] Session error:", err);
|
|
731
|
+
const errorMessage = err?.response?.data?.error?.message || err?.message;
|
|
732
|
+
const errorStatus = err?.response?.status;
|
|
733
|
+
setStatus("denied");
|
|
734
|
+
if (errorStatus === 403 || errorMessage?.includes("Freigabe") || errorMessage?.includes("forbidden")) {
|
|
735
|
+
setError("[DENIED] Keine Freigabe: Kontaktiere einen Super Admin fuer Zugriff");
|
|
736
|
+
} else if (errorStatus === 401 || errorMessage?.includes("unauthorized")) {
|
|
737
|
+
setError("[AUTH] Authentifizierung fehlgeschlagen");
|
|
738
|
+
} else if (errorMessage?.includes("disabled")) {
|
|
739
|
+
setError("[DISABLED] Echtzeit-Bearbeitung ist deaktiviert");
|
|
740
|
+
} else if (errorStatus === 400) {
|
|
741
|
+
setError(`[ERROR] Ungueltige Anfrage: ${errorMessage}`);
|
|
742
|
+
} else {
|
|
743
|
+
setError(errorMessage || "[ERROR] Keine Berechtigung fuer Live Editing");
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
startSession();
|
|
749
|
+
return () => {
|
|
750
|
+
cancelled = true;
|
|
751
|
+
if (socketRef.current) {
|
|
752
|
+
console.log("[Magic Collab] [SOCKET] Disconnecting socket");
|
|
753
|
+
socketRef.current.disconnect();
|
|
754
|
+
socketRef.current = null;
|
|
755
|
+
}
|
|
756
|
+
setPeers([]);
|
|
757
|
+
};
|
|
758
|
+
}, [enabled, post, fieldName, roomId, user]);
|
|
759
|
+
React.useEffect(() => {
|
|
760
|
+
if (!enabled) {
|
|
761
|
+
console.log("[Magic Collab] [SKIP] Update handler not registered (disabled)");
|
|
762
|
+
return void 0;
|
|
763
|
+
}
|
|
764
|
+
console.log("[Magic Collab] [HANDLER] Registering update handler on doc");
|
|
765
|
+
const handler = (update, origin) => {
|
|
766
|
+
const updateSize = update?.length || 0;
|
|
767
|
+
if (updateSize > 10) {
|
|
768
|
+
console.log("[Magic Collab] [DOC] Doc update - origin:", origin, "size:", updateSize, "bytes");
|
|
769
|
+
}
|
|
770
|
+
if (origin === "remote" || origin === "bootstrap") {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (!socketRef.current?.connected) {
|
|
774
|
+
console.log("[Magic Collab] [WARNING] Socket not connected, update queued");
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const updateArray = Array.from(update);
|
|
778
|
+
socketRef.current.emit("collab:update", updateArray);
|
|
779
|
+
console.log("[Magic Collab] [SENT] Sent update:", updateArray.length, "bytes to server");
|
|
780
|
+
};
|
|
781
|
+
doc.on("update", handler);
|
|
782
|
+
return () => {
|
|
783
|
+
console.log("[Magic Collab] [CLEANUP] Removing update handler");
|
|
784
|
+
doc.off("update", handler);
|
|
785
|
+
};
|
|
786
|
+
}, [doc, enabled]);
|
|
787
|
+
const emitAwareness = React.useCallback((payload) => {
|
|
788
|
+
if (socketRef.current?.connected) {
|
|
789
|
+
socketRef.current.emit("collab:awareness", payload);
|
|
790
|
+
}
|
|
791
|
+
}, []);
|
|
792
|
+
const localUserColor = React.useMemo(() => {
|
|
793
|
+
return user ? getUserColor(user.id) : CURSOR_COLORS[0];
|
|
794
|
+
}, [user]);
|
|
795
|
+
return {
|
|
796
|
+
doc,
|
|
797
|
+
blocksMap,
|
|
798
|
+
// Y.Map for block-level sync (replaces Y.Text)
|
|
799
|
+
metaMap,
|
|
800
|
+
// Y.Map for metadata (includes blockOrder as JSON string)
|
|
801
|
+
status,
|
|
802
|
+
error,
|
|
803
|
+
peers,
|
|
804
|
+
awareness,
|
|
805
|
+
emitAwareness,
|
|
806
|
+
localUserColor,
|
|
807
|
+
getUserColor,
|
|
808
|
+
// Role-based access control
|
|
809
|
+
collabRole,
|
|
810
|
+
// 'viewer' | 'editor' | 'owner' | null
|
|
811
|
+
canEdit
|
|
812
|
+
// true if user can edit (editor/owner), false for viewer
|
|
813
|
+
};
|
|
814
|
+
};
|
|
815
|
+
const useLicense = () => {
|
|
816
|
+
const { get } = admin.useFetchClient();
|
|
817
|
+
const [isPremium, setIsPremium] = React.useState(false);
|
|
818
|
+
const [isAdvanced, setIsAdvanced] = React.useState(false);
|
|
819
|
+
const [isEnterprise, setIsEnterprise] = React.useState(false);
|
|
820
|
+
const [tier, setTier] = React.useState("free");
|
|
821
|
+
const [loading, setLoading] = React.useState(true);
|
|
822
|
+
const [error, setError] = React.useState(null);
|
|
823
|
+
const [licenseData, setLicenseData] = React.useState(null);
|
|
824
|
+
const [limits, setLimits] = React.useState(null);
|
|
825
|
+
React.useEffect(() => {
|
|
826
|
+
let mounted = true;
|
|
827
|
+
const fetchLicense = async () => {
|
|
828
|
+
if (mounted) {
|
|
829
|
+
await checkLicense();
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
fetchLicense();
|
|
833
|
+
const interval = setInterval(() => {
|
|
834
|
+
if (mounted) {
|
|
835
|
+
checkLicense(true);
|
|
836
|
+
}
|
|
837
|
+
}, 60 * 60 * 1e3);
|
|
838
|
+
return () => {
|
|
839
|
+
mounted = false;
|
|
840
|
+
clearInterval(interval);
|
|
841
|
+
};
|
|
842
|
+
}, []);
|
|
843
|
+
const checkLicense = async (silent = false) => {
|
|
844
|
+
if (!silent) {
|
|
845
|
+
setLoading(true);
|
|
846
|
+
}
|
|
847
|
+
try {
|
|
848
|
+
const response = await get("/magic-editor-x/license/status");
|
|
849
|
+
const isValid = response.data?.valid || false;
|
|
850
|
+
const tierName = response.data?.tier || "free";
|
|
851
|
+
const hasPremiumFeature = response.data?.data?.features?.premium || tierName === "premium";
|
|
852
|
+
const hasAdvancedFeature = response.data?.data?.features?.advanced || tierName === "advanced";
|
|
853
|
+
const hasEnterpriseFeature = response.data?.data?.features?.enterprise || tierName === "enterprise";
|
|
854
|
+
setTier(tierName);
|
|
855
|
+
setIsPremium(isValid && (hasPremiumFeature || hasAdvancedFeature || hasEnterpriseFeature));
|
|
856
|
+
setIsAdvanced(isValid && (hasAdvancedFeature || hasEnterpriseFeature));
|
|
857
|
+
setIsEnterprise(isValid && hasEnterpriseFeature);
|
|
858
|
+
setLicenseData(response.data?.data || null);
|
|
859
|
+
setError(null);
|
|
860
|
+
await fetchLimits();
|
|
861
|
+
} catch (err) {
|
|
862
|
+
if (err.name === "AbortError") {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
if (!silent) {
|
|
866
|
+
console.error("[Magic Editor X] License check error:", err);
|
|
867
|
+
}
|
|
868
|
+
setTier("free");
|
|
869
|
+
setIsPremium(false);
|
|
870
|
+
setIsAdvanced(false);
|
|
871
|
+
setIsEnterprise(false);
|
|
872
|
+
setLicenseData(null);
|
|
873
|
+
setError(err);
|
|
874
|
+
} finally {
|
|
875
|
+
if (!silent) {
|
|
876
|
+
setLoading(false);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
const fetchLimits = async () => {
|
|
881
|
+
try {
|
|
882
|
+
const response = await get("/magic-editor-x/license/limits");
|
|
883
|
+
setLimits(response.data?.limits || null);
|
|
884
|
+
} catch (err) {
|
|
885
|
+
console.error("[Magic Editor X] Error fetching limits:", err);
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
const hasFeature = (featureName) => {
|
|
889
|
+
if (!featureName) return false;
|
|
890
|
+
const freeFeatures = [
|
|
891
|
+
"editor",
|
|
892
|
+
"allTools",
|
|
893
|
+
"collaboration-basic"
|
|
894
|
+
// 2 collaborators
|
|
895
|
+
];
|
|
896
|
+
if (freeFeatures.includes(featureName)) return true;
|
|
897
|
+
const premiumFeatures = [
|
|
898
|
+
"collaboration-extended",
|
|
899
|
+
// 10 collaborators
|
|
900
|
+
"ai-basic"
|
|
901
|
+
];
|
|
902
|
+
if (premiumFeatures.includes(featureName) && isPremium) return true;
|
|
903
|
+
const advancedFeatures = [
|
|
904
|
+
"collaboration-unlimited",
|
|
905
|
+
"ai-full"
|
|
906
|
+
];
|
|
907
|
+
if (advancedFeatures.includes(featureName) && isAdvanced) return true;
|
|
908
|
+
const enterpriseFeatures = [
|
|
909
|
+
"priority-support",
|
|
910
|
+
"custom-branding"
|
|
911
|
+
];
|
|
912
|
+
if (enterpriseFeatures.includes(featureName) && isEnterprise) return true;
|
|
913
|
+
return false;
|
|
914
|
+
};
|
|
915
|
+
const canAddCollaborator = () => {
|
|
916
|
+
if (!limits?.collaborators) return true;
|
|
917
|
+
return limits.collaborators.canAdd;
|
|
918
|
+
};
|
|
919
|
+
const getCollaboratorInfo = () => {
|
|
920
|
+
if (!limits?.collaborators) {
|
|
921
|
+
return { current: 0, max: 2, unlimited: false, canAdd: true };
|
|
922
|
+
}
|
|
923
|
+
return limits.collaborators;
|
|
924
|
+
};
|
|
925
|
+
return {
|
|
926
|
+
tier,
|
|
927
|
+
isPremium,
|
|
928
|
+
isAdvanced,
|
|
929
|
+
isEnterprise,
|
|
930
|
+
loading,
|
|
931
|
+
error,
|
|
932
|
+
licenseData,
|
|
933
|
+
limits,
|
|
934
|
+
features: {
|
|
935
|
+
premium: isPremium,
|
|
936
|
+
advanced: isAdvanced,
|
|
937
|
+
enterprise: isEnterprise
|
|
938
|
+
},
|
|
939
|
+
hasFeature,
|
|
940
|
+
canAddCollaborator,
|
|
941
|
+
getCollaboratorInfo,
|
|
942
|
+
refetch: checkLicense
|
|
943
|
+
};
|
|
944
|
+
};
|
|
945
|
+
const useAIActions = ({ licenseKey, editorInstanceRef, isReady, onNoCredits }) => {
|
|
946
|
+
const apiClientRef = React__default.default.useRef(null);
|
|
947
|
+
React__default.default.useEffect(() => {
|
|
948
|
+
if (licenseKey && !apiClientRef.current) {
|
|
949
|
+
apiClientRef.current = new tools.MagicEditorAPI(licenseKey);
|
|
950
|
+
}
|
|
951
|
+
}, [licenseKey]);
|
|
952
|
+
const replaceText = React.useCallback((range, newText) => {
|
|
953
|
+
if (!range) return false;
|
|
954
|
+
try {
|
|
955
|
+
const selection = window.getSelection();
|
|
956
|
+
selection.removeAllRanges();
|
|
957
|
+
selection.addRange(range);
|
|
958
|
+
const success = document.execCommand("insertText", false, newText);
|
|
959
|
+
if (editorInstanceRef.current && isReady) {
|
|
960
|
+
const currentBlock = editorInstanceRef.current.blocks.getBlockByIndex(
|
|
961
|
+
editorInstanceRef.current.blocks.getCurrentBlockIndex()
|
|
962
|
+
);
|
|
963
|
+
currentBlock?.dispatchChange?.();
|
|
964
|
+
}
|
|
965
|
+
return success;
|
|
966
|
+
} catch (err) {
|
|
967
|
+
console.error("[AI Actions] Failed to replace text:", err);
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
}, [editorInstanceRef, isReady]);
|
|
971
|
+
const appendText = React.useCallback((range, additionalText) => {
|
|
972
|
+
if (!range) return false;
|
|
973
|
+
try {
|
|
974
|
+
const selection = window.getSelection();
|
|
975
|
+
const newRange = range.cloneRange();
|
|
976
|
+
newRange.collapse(false);
|
|
977
|
+
selection.removeAllRanges();
|
|
978
|
+
selection.addRange(newRange);
|
|
979
|
+
const success = document.execCommand("insertText", false, additionalText);
|
|
980
|
+
if (editorInstanceRef.current && isReady) {
|
|
981
|
+
const currentBlock = editorInstanceRef.current.blocks.getBlockByIndex(
|
|
982
|
+
editorInstanceRef.current.blocks.getCurrentBlockIndex()
|
|
983
|
+
);
|
|
984
|
+
currentBlock?.dispatchChange?.();
|
|
985
|
+
}
|
|
986
|
+
return success;
|
|
987
|
+
} catch (err) {
|
|
988
|
+
console.error("[AI Actions] Failed to append text:", err);
|
|
989
|
+
return false;
|
|
990
|
+
}
|
|
991
|
+
}, [editorInstanceRef, isReady]);
|
|
992
|
+
const handleAIAction = React.useCallback(async (action, options, { text, range }) => {
|
|
993
|
+
if (!apiClientRef.current || !text) return;
|
|
994
|
+
const originalText = text;
|
|
995
|
+
const langNames = { en: "Englisch", de: "Deutsch", fr: "Französisch", es: "Spanisch" };
|
|
996
|
+
try {
|
|
997
|
+
let result;
|
|
998
|
+
let type;
|
|
999
|
+
let apiOptions = {};
|
|
1000
|
+
switch (action) {
|
|
1001
|
+
case "fix":
|
|
1002
|
+
type = "grammar";
|
|
1003
|
+
break;
|
|
1004
|
+
case "rewrite":
|
|
1005
|
+
type = "rewrite";
|
|
1006
|
+
apiOptions = { tone: options.tone };
|
|
1007
|
+
break;
|
|
1008
|
+
case "expand":
|
|
1009
|
+
type = "expand";
|
|
1010
|
+
break;
|
|
1011
|
+
case "summarize":
|
|
1012
|
+
type = "summarize";
|
|
1013
|
+
break;
|
|
1014
|
+
case "continue":
|
|
1015
|
+
type = "continue";
|
|
1016
|
+
break;
|
|
1017
|
+
case "translate":
|
|
1018
|
+
type = "translate";
|
|
1019
|
+
apiOptions = { language: options.language };
|
|
1020
|
+
break;
|
|
1021
|
+
default:
|
|
1022
|
+
console.warn("Unknown AI action:", action);
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
result = await apiClientRef.current.correct(text, type, apiOptions);
|
|
1026
|
+
if (result.data.hasChanges && result.data.corrected) {
|
|
1027
|
+
if (action === "continue") {
|
|
1028
|
+
appendText(range, " " + result.data.corrected);
|
|
1029
|
+
} else {
|
|
1030
|
+
replaceText(range, result.data.corrected);
|
|
1031
|
+
}
|
|
1032
|
+
const messages = {
|
|
1033
|
+
fix: `✓ ${result.data.changes?.length || 1} Korrekturen angewendet`,
|
|
1034
|
+
rewrite: `✨ Text umgeschrieben (${options.tone || "standard"})`,
|
|
1035
|
+
expand: "📈 Text erweitert",
|
|
1036
|
+
summarize: "📉 Text zusammengefasst",
|
|
1037
|
+
continue: "✍️ Text fortgesetzt",
|
|
1038
|
+
translate: `🌍 Übersetzt zu ${langNames[options.language] || options.language}`
|
|
1039
|
+
};
|
|
1040
|
+
tools.toastManager.success(messages[action], {
|
|
1041
|
+
description: `${result.credits?.remaining ?? 0} Credits übrig`,
|
|
1042
|
+
onUndo: () => replaceText(range, originalText),
|
|
1043
|
+
duration: 5e3
|
|
1044
|
+
});
|
|
1045
|
+
} else {
|
|
1046
|
+
tools.toastManager.info("Text ist bereits korrekt");
|
|
1047
|
+
}
|
|
1048
|
+
return true;
|
|
1049
|
+
} catch (err) {
|
|
1050
|
+
console.error("[AI Actions] Action failed:", err);
|
|
1051
|
+
switch (err.code) {
|
|
1052
|
+
case "NO_CREDITS":
|
|
1053
|
+
if (onNoCredits) {
|
|
1054
|
+
onNoCredits(err.upgrade);
|
|
1055
|
+
} else {
|
|
1056
|
+
tools.toastManager.warning("Keine Credits", {
|
|
1057
|
+
description: err.message || "Bitte Credits kaufen",
|
|
1058
|
+
duration: 5e3
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
break;
|
|
1062
|
+
case "TYPE_NOT_ALLOWED":
|
|
1063
|
+
tools.toastManager.warning("Funktion nicht verfügbar", {
|
|
1064
|
+
description: "Diese Funktion ist in deinem Tier nicht enthalten",
|
|
1065
|
+
duration: 5e3
|
|
1066
|
+
});
|
|
1067
|
+
break;
|
|
1068
|
+
case "LICENSE_NOT_FOUND":
|
|
1069
|
+
case "LICENSE_INACTIVE":
|
|
1070
|
+
case "WRONG_PLUGIN":
|
|
1071
|
+
tools.toastManager.error("Lizenz ungültig", {
|
|
1072
|
+
description: err.message || "Bitte prüfe deine Lizenz",
|
|
1073
|
+
duration: 5e3
|
|
1074
|
+
});
|
|
1075
|
+
break;
|
|
1076
|
+
case "DAILY_LIMIT_EXCEEDED":
|
|
1077
|
+
case "MONTHLY_LIMIT_EXCEEDED":
|
|
1078
|
+
tools.toastManager.warning("Limit erreicht", {
|
|
1079
|
+
description: err.message,
|
|
1080
|
+
duration: 5e3
|
|
1081
|
+
});
|
|
1082
|
+
break;
|
|
1083
|
+
case "CORRECTION_FAILED":
|
|
1084
|
+
tools.toastManager.error("AI Fehler", {
|
|
1085
|
+
description: "Die KI konnte die Anfrage nicht verarbeiten",
|
|
1086
|
+
duration: 4e3
|
|
1087
|
+
});
|
|
1088
|
+
break;
|
|
1089
|
+
default:
|
|
1090
|
+
tools.toastManager.error("Fehler", {
|
|
1091
|
+
description: err.message || "Aktion fehlgeschlagen",
|
|
1092
|
+
duration: 4e3
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
return false;
|
|
1096
|
+
}
|
|
1097
|
+
}, [replaceText, appendText, onNoCredits]);
|
|
1098
|
+
return { handleAIAction };
|
|
1099
|
+
};
|
|
1100
|
+
const Overlay$1 = styled__default.default.div`
|
|
1101
|
+
position: fixed;
|
|
1102
|
+
top: 0;
|
|
1103
|
+
left: 0;
|
|
1104
|
+
right: 0;
|
|
1105
|
+
bottom: 0;
|
|
1106
|
+
background: rgba(0, 0, 0, 0.5);
|
|
1107
|
+
display: flex;
|
|
1108
|
+
align-items: center;
|
|
1109
|
+
justify-content: center;
|
|
1110
|
+
z-index: 999999;
|
|
1111
|
+
`;
|
|
1112
|
+
const PopupContainer = styled__default.default.div`
|
|
1113
|
+
background: ${(props) => props.theme.colors.neutral0};
|
|
1114
|
+
border-radius: 16px;
|
|
1115
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
|
|
1116
|
+
width: 100%;
|
|
1117
|
+
max-width: 500px;
|
|
1118
|
+
max-height: 80vh;
|
|
1119
|
+
overflow: hidden;
|
|
1120
|
+
display: flex;
|
|
1121
|
+
flex-direction: column;
|
|
1122
|
+
`;
|
|
1123
|
+
const Header$1 = styled__default.default.div`
|
|
1124
|
+
background: linear-gradient(135deg, #7C3AED 0%, #a855f7 100%);
|
|
1125
|
+
padding: 20px 24px;
|
|
1126
|
+
color: white;
|
|
1127
|
+
display: flex;
|
|
1128
|
+
justify-content: space-between;
|
|
1129
|
+
align-items: center;
|
|
1130
|
+
`;
|
|
1131
|
+
const HeaderTitle = styled__default.default.div`
|
|
1132
|
+
display: flex;
|
|
1133
|
+
align-items: center;
|
|
1134
|
+
gap: 12px;
|
|
1135
|
+
font-size: 16px;
|
|
1136
|
+
font-weight: 600;
|
|
1137
|
+
`;
|
|
1138
|
+
const CreditsBadge = styled__default.default.div`
|
|
1139
|
+
background: rgba(255, 255, 255, 0.2);
|
|
1140
|
+
padding: 6px 14px;
|
|
1141
|
+
border-radius: 20px;
|
|
1142
|
+
font-size: 13px;
|
|
1143
|
+
font-weight: 500;
|
|
1144
|
+
`;
|
|
1145
|
+
const Content$1 = styled__default.default.div`
|
|
1146
|
+
padding: 24px;
|
|
1147
|
+
overflow-y: auto;
|
|
1148
|
+
flex: 1;
|
|
1149
|
+
`;
|
|
1150
|
+
const TextPreview = styled__default.default.div`
|
|
1151
|
+
background: ${(props) => props.theme.colors.neutral100};
|
|
1152
|
+
border: 1px solid ${(props) => props.theme.colors.neutral200};
|
|
1153
|
+
border-radius: 10px;
|
|
1154
|
+
padding: 14px;
|
|
1155
|
+
margin-bottom: 20px;
|
|
1156
|
+
max-height: 100px;
|
|
1157
|
+
overflow-y: auto;
|
|
1158
|
+
font-size: 14px;
|
|
1159
|
+
color: ${(props) => props.theme.colors.neutral600};
|
|
1160
|
+
line-height: 1.6;
|
|
1161
|
+
`;
|
|
1162
|
+
const TypeButtons = styled__default.default.div`
|
|
1163
|
+
display: flex;
|
|
1164
|
+
gap: 10px;
|
|
1165
|
+
margin-bottom: 20px;
|
|
1166
|
+
`;
|
|
1167
|
+
const TypeButton = styled__default.default.button`
|
|
1168
|
+
flex: 1;
|
|
1169
|
+
padding: 14px 16px;
|
|
1170
|
+
border: 2px solid ${(props) => props.$active ? "#7C3AED" : props.theme.colors.neutral200};
|
|
1171
|
+
border-radius: 10px;
|
|
1172
|
+
background: ${(props) => props.$active ? "#f5f3ff" : props.theme.colors.neutral0};
|
|
1173
|
+
color: ${(props) => props.$active ? "#7C3AED" : props.theme.colors.neutral700};
|
|
1174
|
+
font-size: 13px;
|
|
1175
|
+
font-weight: 600;
|
|
1176
|
+
cursor: pointer;
|
|
1177
|
+
transition: all 0.15s ease;
|
|
1178
|
+
display: flex;
|
|
1179
|
+
align-items: center;
|
|
1180
|
+
justify-content: center;
|
|
1181
|
+
gap: 8px;
|
|
1182
|
+
|
|
1183
|
+
&:hover:not(:disabled) {
|
|
1184
|
+
border-color: #7C3AED;
|
|
1185
|
+
background: #faf8ff;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
&:disabled {
|
|
1189
|
+
opacity: 0.5;
|
|
1190
|
+
cursor: not-allowed;
|
|
1191
|
+
}
|
|
1192
|
+
`;
|
|
1193
|
+
const ResultArea = styled__default.default.div`
|
|
1194
|
+
min-height: 80px;
|
|
1195
|
+
`;
|
|
1196
|
+
const LoadingSpinner = styled__default.default.div`
|
|
1197
|
+
text-align: center;
|
|
1198
|
+
padding: 40px;
|
|
1199
|
+
|
|
1200
|
+
.spinner {
|
|
1201
|
+
width: 40px;
|
|
1202
|
+
height: 40px;
|
|
1203
|
+
border: 4px solid ${(props) => props.theme.colors.neutral200};
|
|
1204
|
+
border-top-color: #7C3AED;
|
|
1205
|
+
border-radius: 50%;
|
|
1206
|
+
margin: 0 auto 16px;
|
|
1207
|
+
animation: spin 0.8s linear infinite;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
@keyframes spin {
|
|
1211
|
+
to { transform: rotate(360deg); }
|
|
1212
|
+
}
|
|
1213
|
+
`;
|
|
1214
|
+
const ResultBox = styled__default.default.div`
|
|
1215
|
+
margin-bottom: 16px;
|
|
1216
|
+
`;
|
|
1217
|
+
const ResultLabel = styled__default.default.div`
|
|
1218
|
+
font-size: 11px;
|
|
1219
|
+
font-weight: 700;
|
|
1220
|
+
color: ${(props) => props.theme.colors.neutral500};
|
|
1221
|
+
text-transform: uppercase;
|
|
1222
|
+
margin-bottom: 8px;
|
|
1223
|
+
letter-spacing: 0.5px;
|
|
1224
|
+
`;
|
|
1225
|
+
const OriginalText = styled__default.default.div`
|
|
1226
|
+
background: #fef2f2;
|
|
1227
|
+
border: 1px solid #fecaca;
|
|
1228
|
+
border-radius: 8px;
|
|
1229
|
+
padding: 14px;
|
|
1230
|
+
font-size: 14px;
|
|
1231
|
+
color: #991b1b;
|
|
1232
|
+
text-decoration: line-through;
|
|
1233
|
+
line-height: 1.6;
|
|
1234
|
+
`;
|
|
1235
|
+
const CorrectedText = styled__default.default.div`
|
|
1236
|
+
background: #f0fdf4;
|
|
1237
|
+
border: 1px solid #bbf7d0;
|
|
1238
|
+
border-radius: 8px;
|
|
1239
|
+
padding: 14px;
|
|
1240
|
+
font-size: 14px;
|
|
1241
|
+
color: #166534;
|
|
1242
|
+
line-height: 1.6;
|
|
1243
|
+
`;
|
|
1244
|
+
const SuccessMessage = styled__default.default.div`
|
|
1245
|
+
text-align: center;
|
|
1246
|
+
padding: 30px;
|
|
1247
|
+
color: #10b981;
|
|
1248
|
+
|
|
1249
|
+
.icon {
|
|
1250
|
+
font-size: 48px;
|
|
1251
|
+
margin-bottom: 12px;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
.title {
|
|
1255
|
+
font-size: 16px;
|
|
1256
|
+
font-weight: 600;
|
|
1257
|
+
margin-bottom: 4px;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
.subtitle {
|
|
1261
|
+
font-size: 13px;
|
|
1262
|
+
color: ${(props) => props.theme.colors.neutral500};
|
|
1263
|
+
}
|
|
1264
|
+
`;
|
|
1265
|
+
const ErrorMessage = styled__default.default.div`
|
|
1266
|
+
text-align: center;
|
|
1267
|
+
padding: 30px;
|
|
1268
|
+
color: #dc2626;
|
|
1269
|
+
|
|
1270
|
+
.icon {
|
|
1271
|
+
font-size: 48px;
|
|
1272
|
+
margin-bottom: 12px;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
.title {
|
|
1276
|
+
font-size: 16px;
|
|
1277
|
+
font-weight: 600;
|
|
1278
|
+
margin-bottom: 4px;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
.subtitle {
|
|
1282
|
+
font-size: 13px;
|
|
1283
|
+
color: ${(props) => props.theme.colors.neutral500};
|
|
1284
|
+
}
|
|
1285
|
+
`;
|
|
1286
|
+
const Footer$1 = styled__default.default.div`
|
|
1287
|
+
padding: 16px 24px;
|
|
1288
|
+
border-top: 1px solid ${(props) => props.theme.colors.neutral200};
|
|
1289
|
+
display: flex;
|
|
1290
|
+
justify-content: flex-end;
|
|
1291
|
+
gap: 12px;
|
|
1292
|
+
background: ${(props) => props.theme.colors.neutral100};
|
|
1293
|
+
`;
|
|
1294
|
+
const Button$1 = styled__default.default.button`
|
|
1295
|
+
padding: 10px 20px;
|
|
1296
|
+
border-radius: 8px;
|
|
1297
|
+
font-size: 14px;
|
|
1298
|
+
font-weight: 500;
|
|
1299
|
+
cursor: pointer;
|
|
1300
|
+
transition: all 0.15s ease;
|
|
1301
|
+
`;
|
|
1302
|
+
const CancelButton = styled__default.default(Button$1)`
|
|
1303
|
+
background: ${(props) => props.theme.colors.neutral0};
|
|
1304
|
+
border: 1px solid ${(props) => props.theme.colors.neutral300};
|
|
1305
|
+
color: ${(props) => props.theme.colors.neutral700};
|
|
1306
|
+
|
|
1307
|
+
&:hover {
|
|
1308
|
+
background: ${(props) => props.theme.colors.neutral100};
|
|
1309
|
+
}
|
|
1310
|
+
`;
|
|
1311
|
+
const ApplyButton = styled__default.default(Button$1)`
|
|
1312
|
+
background: linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%);
|
|
1313
|
+
border: none;
|
|
1314
|
+
color: white;
|
|
1315
|
+
|
|
1316
|
+
&:hover {
|
|
1317
|
+
transform: translateY(-1px);
|
|
1318
|
+
box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
&:disabled {
|
|
1322
|
+
opacity: 0.5;
|
|
1323
|
+
cursor: not-allowed;
|
|
1324
|
+
transform: none;
|
|
1325
|
+
}
|
|
1326
|
+
`;
|
|
1327
|
+
const PlaceholderText = styled__default.default.div`
|
|
1328
|
+
text-align: center;
|
|
1329
|
+
padding: 40px;
|
|
1330
|
+
color: ${(props) => props.theme.colors.neutral400};
|
|
1331
|
+
font-size: 14px;
|
|
1332
|
+
`;
|
|
1333
|
+
const SparklesIcon = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1334
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 3l1.912 5.813a2 2 0 001.275 1.275L21 12l-5.813 1.912a2 2 0 00-1.275 1.275L12 21l-1.912-5.813a2 2 0 00-1.275-1.275L3 12l5.813-1.912a2 2 0 001.275-1.275L12 3z" }),
|
|
1335
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 3v4" }),
|
|
1336
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 5h4" }),
|
|
1337
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 17v4" }),
|
|
1338
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17 19h4" })
|
|
1339
|
+
] });
|
|
1340
|
+
const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
1341
|
+
const [activeType, setActiveType] = React.useState(null);
|
|
1342
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
1343
|
+
const [result, setResult] = React.useState(null);
|
|
1344
|
+
const [error, setError] = React.useState(null);
|
|
1345
|
+
const [credits, setCredits] = React.useState(0);
|
|
1346
|
+
const [usage, setUsage] = React.useState(null);
|
|
1347
|
+
const [apiClient, setApiClient] = React.useState(null);
|
|
1348
|
+
React.useEffect(() => {
|
|
1349
|
+
if (licenseKey) {
|
|
1350
|
+
const client = new tools.MagicEditorAPI(licenseKey);
|
|
1351
|
+
setApiClient(client);
|
|
1352
|
+
client.getUsage().then((res) => {
|
|
1353
|
+
setUsage(res.data);
|
|
1354
|
+
setCredits(res.data?.credits?.balance || 0);
|
|
1355
|
+
}).catch((err) => {
|
|
1356
|
+
console.error("[AI Popup] Failed to fetch usage:", err);
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
}, [licenseKey]);
|
|
1360
|
+
const handleCorrection = React.useCallback(async (type) => {
|
|
1361
|
+
if (!apiClient || !selectedText) return;
|
|
1362
|
+
setActiveType(type);
|
|
1363
|
+
setIsLoading(true);
|
|
1364
|
+
setResult(null);
|
|
1365
|
+
setError(null);
|
|
1366
|
+
try {
|
|
1367
|
+
const response = await apiClient.correct(selectedText, type);
|
|
1368
|
+
setResult(response.data);
|
|
1369
|
+
if (response.credits?.remaining !== void 0) {
|
|
1370
|
+
setCredits(response.credits.remaining);
|
|
1371
|
+
}
|
|
1372
|
+
if (response.usage) {
|
|
1373
|
+
setUsage((prev) => ({
|
|
1374
|
+
...prev,
|
|
1375
|
+
daily: {
|
|
1376
|
+
...prev?.daily,
|
|
1377
|
+
used: response.usage.used,
|
|
1378
|
+
remaining: response.usage.remaining,
|
|
1379
|
+
limit: response.usage.limit
|
|
1380
|
+
}
|
|
1381
|
+
}));
|
|
1382
|
+
}
|
|
1383
|
+
} catch (err) {
|
|
1384
|
+
console.error("[AI Popup] Correction failed:", err);
|
|
1385
|
+
setError(err.message || "Korrektur fehlgeschlagen");
|
|
1386
|
+
} finally {
|
|
1387
|
+
setIsLoading(false);
|
|
1388
|
+
}
|
|
1389
|
+
}, [apiClient, selectedText]);
|
|
1390
|
+
const handleApply = React.useCallback(() => {
|
|
1391
|
+
if (result?.corrected) {
|
|
1392
|
+
onApply(result.corrected);
|
|
1393
|
+
}
|
|
1394
|
+
}, [result, onApply]);
|
|
1395
|
+
const handleOverlayClick = (e) => {
|
|
1396
|
+
if (e.target === e.currentTarget) {
|
|
1397
|
+
onClose();
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
React.useEffect(() => {
|
|
1401
|
+
const handleKeyDown = (e) => {
|
|
1402
|
+
if (e.key === "Escape") {
|
|
1403
|
+
onClose();
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
1407
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1408
|
+
}, [onClose]);
|
|
1409
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Overlay$1, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxRuntime.jsxs(PopupContainer, { onClick: (e) => e.stopPropagation(), children: [
|
|
1410
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Header$1, { children: [
|
|
1411
|
+
/* @__PURE__ */ jsxRuntime.jsxs(HeaderTitle, { children: [
|
|
1412
|
+
/* @__PURE__ */ jsxRuntime.jsx(SparklesIcon, {}),
|
|
1413
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "KI-Assistent" })
|
|
1414
|
+
] }),
|
|
1415
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CreditsBadge, { children: [
|
|
1416
|
+
usage?.tier === "free" && `Free • ${usage?.daily?.remaining ?? 0}/${usage?.daily?.limit ?? 3} heute`,
|
|
1417
|
+
usage?.tier === "basic" && `Basic • ${usage?.daily?.remaining ?? 0}/${usage?.daily?.limit ?? 10} heute`,
|
|
1418
|
+
usage?.tier === "pro" && `Pro • ${usage?.daily?.remaining ?? 0}/${usage?.daily?.limit ?? 50} heute`,
|
|
1419
|
+
!usage?.tier && "Wird geladen..."
|
|
1420
|
+
] })
|
|
1421
|
+
] }),
|
|
1422
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Content$1, { children: [
|
|
1423
|
+
/* @__PURE__ */ jsxRuntime.jsx(TextPreview, { children: selectedText.length > 300 ? selectedText.substring(0, 300) + "..." : selectedText }),
|
|
1424
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TypeButtons, { children: [
|
|
1425
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1426
|
+
TypeButton,
|
|
1427
|
+
{
|
|
1428
|
+
type: "button",
|
|
1429
|
+
$active: activeType === "grammar",
|
|
1430
|
+
onClick: () => handleCorrection("grammar"),
|
|
1431
|
+
disabled: isLoading || (usage?.daily?.remaining ?? 0) <= 0 && credits <= 0,
|
|
1432
|
+
children: [
|
|
1433
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "✓" }),
|
|
1434
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Grammatik" })
|
|
1435
|
+
]
|
|
1436
|
+
}
|
|
1437
|
+
),
|
|
1438
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1439
|
+
TypeButton,
|
|
1440
|
+
{
|
|
1441
|
+
type: "button",
|
|
1442
|
+
$active: activeType === "style",
|
|
1443
|
+
onClick: () => handleCorrection("style"),
|
|
1444
|
+
disabled: isLoading || !usage?.allowedTypes?.includes("style") || (usage?.daily?.remaining ?? 0) <= 0 && credits <= 0,
|
|
1445
|
+
title: !usage?.allowedTypes?.includes("style") ? "Basic oder höher erforderlich" : void 0,
|
|
1446
|
+
children: [
|
|
1447
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: usage?.allowedTypes?.includes("style") ? "✨" : "🔒" }),
|
|
1448
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Stil" })
|
|
1449
|
+
]
|
|
1450
|
+
}
|
|
1451
|
+
),
|
|
1452
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1453
|
+
TypeButton,
|
|
1454
|
+
{
|
|
1455
|
+
type: "button",
|
|
1456
|
+
$active: activeType === "rewrite",
|
|
1457
|
+
onClick: () => handleCorrection("rewrite"),
|
|
1458
|
+
disabled: isLoading || !usage?.allowedTypes?.includes("rewrite") || (usage?.daily?.remaining ?? 0) <= 0 && credits <= 0,
|
|
1459
|
+
title: !usage?.allowedTypes?.includes("rewrite") ? "Pro erforderlich" : void 0,
|
|
1460
|
+
children: [
|
|
1461
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: usage?.allowedTypes?.includes("rewrite") ? "↻" : "🔒" }),
|
|
1462
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Umschreiben" })
|
|
1463
|
+
]
|
|
1464
|
+
}
|
|
1465
|
+
)
|
|
1466
|
+
] }),
|
|
1467
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ResultArea, { children: [
|
|
1468
|
+
isLoading && /* @__PURE__ */ jsxRuntime.jsxs(LoadingSpinner, { children: [
|
|
1469
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "spinner" }),
|
|
1470
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: "Korrigiere..." })
|
|
1471
|
+
] }),
|
|
1472
|
+
!isLoading && !result && !error && /* @__PURE__ */ jsxRuntime.jsx(PlaceholderText, { children: "Wähle einen Korrektur-Typ, um den Text zu verbessern" }),
|
|
1473
|
+
!isLoading && result && !result.hasChanges && /* @__PURE__ */ jsxRuntime.jsxs(SuccessMessage, { children: [
|
|
1474
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "icon", children: "✓" }),
|
|
1475
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "title", children: "Keine Änderungen nötig" }),
|
|
1476
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "subtitle", children: "Der Text ist bereits korrekt" })
|
|
1477
|
+
] }),
|
|
1478
|
+
!isLoading && result && result.hasChanges && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ResultBox, { children: [
|
|
1480
|
+
/* @__PURE__ */ jsxRuntime.jsx(ResultLabel, { children: "Original" }),
|
|
1481
|
+
/* @__PURE__ */ jsxRuntime.jsx(OriginalText, { children: result.original })
|
|
1482
|
+
] }),
|
|
1483
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ResultBox, { children: [
|
|
1484
|
+
/* @__PURE__ */ jsxRuntime.jsx(ResultLabel, { children: "Korrigiert" }),
|
|
1485
|
+
/* @__PURE__ */ jsxRuntime.jsx(CorrectedText, { children: result.corrected })
|
|
1486
|
+
] })
|
|
1487
|
+
] }),
|
|
1488
|
+
!isLoading && error && /* @__PURE__ */ jsxRuntime.jsxs(ErrorMessage, { children: [
|
|
1489
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "icon", children: "✕" }),
|
|
1490
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "title", children: "Fehler" }),
|
|
1491
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "subtitle", children: error })
|
|
1492
|
+
] })
|
|
1493
|
+
] })
|
|
1494
|
+
] }),
|
|
1495
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Footer$1, { children: [
|
|
1496
|
+
/* @__PURE__ */ jsxRuntime.jsx(CancelButton, { type: "button", onClick: onClose, children: "Abbrechen" }),
|
|
1497
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1498
|
+
ApplyButton,
|
|
1499
|
+
{
|
|
1500
|
+
type: "button",
|
|
1501
|
+
onClick: handleApply,
|
|
1502
|
+
disabled: !result?.hasChanges,
|
|
1503
|
+
children: "Übernehmen"
|
|
1504
|
+
}
|
|
1505
|
+
)
|
|
1506
|
+
] })
|
|
1507
|
+
] }) });
|
|
1508
|
+
};
|
|
1509
|
+
const Overlay = styled__default.default.div`
|
|
1510
|
+
position: fixed;
|
|
1511
|
+
top: 0;
|
|
1512
|
+
left: 0;
|
|
1513
|
+
right: 0;
|
|
1514
|
+
bottom: 0;
|
|
1515
|
+
background: rgba(0, 0, 0, 0.5);
|
|
1516
|
+
backdrop-filter: blur(4px);
|
|
1517
|
+
display: flex;
|
|
1518
|
+
align-items: center;
|
|
1519
|
+
justify-content: center;
|
|
1520
|
+
z-index: 100000;
|
|
1521
|
+
animation: fadeIn 0.2s ease-out;
|
|
1522
|
+
|
|
1523
|
+
@keyframes fadeIn {
|
|
1524
|
+
from { opacity: 0; }
|
|
1525
|
+
to { opacity: 1; }
|
|
1526
|
+
}
|
|
1527
|
+
`;
|
|
1528
|
+
const Modal = styled__default.default.div`
|
|
1529
|
+
background: white;
|
|
1530
|
+
border-radius: 16px;
|
|
1531
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
|
|
1532
|
+
max-width: 600px;
|
|
1533
|
+
width: 90%;
|
|
1534
|
+
overflow: hidden;
|
|
1535
|
+
animation: slideUp 0.3s ease-out;
|
|
1536
|
+
|
|
1537
|
+
@keyframes slideUp {
|
|
1538
|
+
from {
|
|
1539
|
+
opacity: 0;
|
|
1540
|
+
transform: translateY(20px);
|
|
1541
|
+
}
|
|
1542
|
+
to {
|
|
1543
|
+
opacity: 1;
|
|
1544
|
+
transform: translateY(0);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
`;
|
|
1548
|
+
const Header = styled__default.default.div`
|
|
1549
|
+
background: linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%);
|
|
1550
|
+
padding: 24px;
|
|
1551
|
+
text-align: center;
|
|
1552
|
+
color: white;
|
|
1553
|
+
`;
|
|
1554
|
+
const Icon = styled__default.default.div`
|
|
1555
|
+
width: 64px;
|
|
1556
|
+
height: 64px;
|
|
1557
|
+
background: rgba(255, 255, 255, 0.2);
|
|
1558
|
+
border-radius: 50%;
|
|
1559
|
+
display: flex;
|
|
1560
|
+
align-items: center;
|
|
1561
|
+
justify-content: center;
|
|
1562
|
+
margin: 0 auto 16px;
|
|
1563
|
+
font-size: 28px;
|
|
1564
|
+
`;
|
|
1565
|
+
const Title = styled__default.default.h2`
|
|
1566
|
+
margin: 0 0 8px;
|
|
1567
|
+
font-size: 22px;
|
|
1568
|
+
font-weight: 700;
|
|
1569
|
+
`;
|
|
1570
|
+
const Subtitle = styled__default.default.p`
|
|
1571
|
+
margin: 0;
|
|
1572
|
+
font-size: 14px;
|
|
1573
|
+
opacity: 0.9;
|
|
1574
|
+
`;
|
|
1575
|
+
const Content = styled__default.default.div`
|
|
1576
|
+
padding: 24px;
|
|
1577
|
+
`;
|
|
1578
|
+
const PackagesGrid = styled__default.default.div`
|
|
1579
|
+
display: grid;
|
|
1580
|
+
grid-template-columns: repeat(3, 1fr);
|
|
1581
|
+
gap: 16px;
|
|
1582
|
+
margin-bottom: 24px;
|
|
1583
|
+
|
|
1584
|
+
@media (max-width: 540px) {
|
|
1585
|
+
grid-template-columns: 1fr;
|
|
1586
|
+
}
|
|
1587
|
+
`;
|
|
1588
|
+
const Package = styled__default.default.div`
|
|
1589
|
+
background: ${(props) => props.$best ? "linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%)" : "#f8fafc"};
|
|
1590
|
+
border: 2px solid ${(props) => props.$best ? "#7C3AED" : "#e2e8f0"};
|
|
1591
|
+
border-radius: 12px;
|
|
1592
|
+
padding: 20px;
|
|
1593
|
+
text-align: center;
|
|
1594
|
+
position: relative;
|
|
1595
|
+
transition: all 0.2s ease;
|
|
1596
|
+
|
|
1597
|
+
&:hover {
|
|
1598
|
+
transform: translateY(-4px);
|
|
1599
|
+
box-shadow: 0 8px 24px rgba(124, 58, 237, 0.15);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
${(props) => props.$best && `
|
|
1603
|
+
transform: scale(1.05);
|
|
1604
|
+
|
|
1605
|
+
&:hover {
|
|
1606
|
+
transform: scale(1.05) translateY(-4px);
|
|
1607
|
+
}
|
|
1608
|
+
`}
|
|
1609
|
+
`;
|
|
1610
|
+
const BestBadge = styled__default.default.div`
|
|
1611
|
+
position: absolute;
|
|
1612
|
+
top: -10px;
|
|
1613
|
+
left: 50%;
|
|
1614
|
+
transform: translateX(-50%);
|
|
1615
|
+
background: linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%);
|
|
1616
|
+
color: white;
|
|
1617
|
+
font-size: 10px;
|
|
1618
|
+
font-weight: 700;
|
|
1619
|
+
padding: 4px 12px;
|
|
1620
|
+
border-radius: 20px;
|
|
1621
|
+
text-transform: uppercase;
|
|
1622
|
+
letter-spacing: 0.5px;
|
|
1623
|
+
`;
|
|
1624
|
+
const Credits = styled__default.default.div`
|
|
1625
|
+
font-size: 32px;
|
|
1626
|
+
font-weight: 800;
|
|
1627
|
+
color: #1e293b;
|
|
1628
|
+
margin-bottom: 4px;
|
|
1629
|
+
`;
|
|
1630
|
+
const CreditsLabel = styled__default.default.div`
|
|
1631
|
+
font-size: 12px;
|
|
1632
|
+
color: #64748b;
|
|
1633
|
+
margin-bottom: 12px;
|
|
1634
|
+
`;
|
|
1635
|
+
const Price = styled__default.default.div`
|
|
1636
|
+
font-size: 24px;
|
|
1637
|
+
font-weight: 700;
|
|
1638
|
+
color: ${(props) => props.$best ? "#7C3AED" : "#334155"};
|
|
1639
|
+
|
|
1640
|
+
span {
|
|
1641
|
+
font-size: 14px;
|
|
1642
|
+
font-weight: 400;
|
|
1643
|
+
color: #64748b;
|
|
1644
|
+
}
|
|
1645
|
+
`;
|
|
1646
|
+
const PerCredit = styled__default.default.div`
|
|
1647
|
+
font-size: 11px;
|
|
1648
|
+
color: #94a3b8;
|
|
1649
|
+
margin-top: 4px;
|
|
1650
|
+
`;
|
|
1651
|
+
const Actions = styled__default.default.div`
|
|
1652
|
+
display: flex;
|
|
1653
|
+
gap: 12px;
|
|
1654
|
+
justify-content: center;
|
|
1655
|
+
`;
|
|
1656
|
+
const Button = styled__default.default.button`
|
|
1657
|
+
padding: 12px 32px;
|
|
1658
|
+
border-radius: 8px;
|
|
1659
|
+
font-size: 14px;
|
|
1660
|
+
font-weight: 600;
|
|
1661
|
+
cursor: pointer;
|
|
1662
|
+
transition: all 0.15s ease;
|
|
1663
|
+
|
|
1664
|
+
${(props) => props.$primary ? `
|
|
1665
|
+
background: linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%);
|
|
1666
|
+
border: none;
|
|
1667
|
+
color: white;
|
|
1668
|
+
|
|
1669
|
+
&:hover {
|
|
1670
|
+
transform: translateY(-2px);
|
|
1671
|
+
box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
|
|
1672
|
+
}
|
|
1673
|
+
` : `
|
|
1674
|
+
background: white;
|
|
1675
|
+
border: 1px solid #e2e8f0;
|
|
1676
|
+
color: #64748b;
|
|
1677
|
+
|
|
1678
|
+
&:hover {
|
|
1679
|
+
background: #f8fafc;
|
|
1680
|
+
border-color: #cbd5e1;
|
|
1681
|
+
}
|
|
1682
|
+
`}
|
|
1683
|
+
|
|
1684
|
+
&:active {
|
|
1685
|
+
transform: scale(0.98);
|
|
1686
|
+
}
|
|
1687
|
+
`;
|
|
1688
|
+
const Footer = styled__default.default.div`
|
|
1689
|
+
padding: 16px 24px;
|
|
1690
|
+
background: #f8fafc;
|
|
1691
|
+
border-top: 1px solid #e2e8f0;
|
|
1692
|
+
text-align: center;
|
|
1693
|
+
font-size: 12px;
|
|
1694
|
+
color: #64748b;
|
|
1695
|
+
|
|
1696
|
+
a {
|
|
1697
|
+
color: #7C3AED;
|
|
1698
|
+
text-decoration: none;
|
|
1699
|
+
font-weight: 500;
|
|
1700
|
+
|
|
1701
|
+
&:hover {
|
|
1702
|
+
text-decoration: underline;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
`;
|
|
1706
|
+
const CreditsModal = ({
|
|
1707
|
+
isOpen,
|
|
1708
|
+
onClose,
|
|
1709
|
+
upgradeInfo
|
|
1710
|
+
}) => {
|
|
1711
|
+
const navigate = reactRouterDom.useNavigate();
|
|
1712
|
+
if (!isOpen) return null;
|
|
1713
|
+
const packages = upgradeInfo?.packages || [
|
|
1714
|
+
{ credits: 50, price: 4.99, currency: "EUR" },
|
|
1715
|
+
{ credits: 200, price: 14.99, currency: "EUR", bestValue: true },
|
|
1716
|
+
{ credits: 500, price: 29.99, currency: "EUR" }
|
|
1717
|
+
];
|
|
1718
|
+
const handleUpgrade = () => {
|
|
1719
|
+
onClose();
|
|
1720
|
+
navigate("/settings/magic-editor-x/upgrade");
|
|
1721
|
+
};
|
|
1722
|
+
const formatPrice = (price, currency) => {
|
|
1723
|
+
return new Intl.NumberFormat("de-DE", {
|
|
1724
|
+
style: "currency",
|
|
1725
|
+
currency: currency || "EUR"
|
|
1726
|
+
}).format(price);
|
|
1727
|
+
};
|
|
1728
|
+
const getPerCredit = (price, credits) => {
|
|
1729
|
+
return (price / credits).toFixed(3).replace(".", ",");
|
|
1730
|
+
};
|
|
1731
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Overlay, { onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(Modal, { onClick: (e) => e.stopPropagation(), children: [
|
|
1732
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Header, { children: [
|
|
1733
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon, { children: "✨" }),
|
|
1734
|
+
/* @__PURE__ */ jsxRuntime.jsx(Title, { children: "Keine Credits verfügbar" }),
|
|
1735
|
+
/* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: upgradeInfo?.message || "Kaufe Credits um Magic Editor AI zu nutzen" })
|
|
1736
|
+
] }),
|
|
1737
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Content, { children: [
|
|
1738
|
+
/* @__PURE__ */ jsxRuntime.jsx(PackagesGrid, { children: packages.map((pkg, index2) => /* @__PURE__ */ jsxRuntime.jsxs(Package, { $best: pkg.bestValue, children: [
|
|
1739
|
+
pkg.bestValue && /* @__PURE__ */ jsxRuntime.jsx(BestBadge, { children: "Best Value" }),
|
|
1740
|
+
/* @__PURE__ */ jsxRuntime.jsx(Credits, { children: pkg.credits }),
|
|
1741
|
+
/* @__PURE__ */ jsxRuntime.jsx(CreditsLabel, { children: "Credits" }),
|
|
1742
|
+
/* @__PURE__ */ jsxRuntime.jsx(Price, { $best: pkg.bestValue, children: formatPrice(pkg.price, pkg.currency) }),
|
|
1743
|
+
/* @__PURE__ */ jsxRuntime.jsxs(PerCredit, { children: [
|
|
1744
|
+
getPerCredit(pkg.price, pkg.credits),
|
|
1745
|
+
" € / Credit"
|
|
1746
|
+
] })
|
|
1747
|
+
] }, index2)) }),
|
|
1748
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Actions, { children: [
|
|
1749
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: onClose, children: "Später" }),
|
|
1750
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { $primary: true, onClick: handleUpgrade, children: "Credits kaufen" })
|
|
1751
|
+
] })
|
|
1752
|
+
] }),
|
|
1753
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Footer, { children: [
|
|
1754
|
+
"Credits werden nie ablaufen • ",
|
|
1755
|
+
/* @__PURE__ */ jsxRuntime.jsx("a", { href: "#", onClick: handleUpgrade, children: "Alle Pakete ansehen" })
|
|
1756
|
+
] })
|
|
1757
|
+
] }) });
|
|
1758
|
+
};
|
|
1759
|
+
const FullscreenGlobalStyle = styled.createGlobalStyle`
|
|
1760
|
+
body.editor-fullscreen {
|
|
1761
|
+
overflow: hidden !important;
|
|
1762
|
+
}
|
|
1763
|
+
`;
|
|
1764
|
+
const EditorJSGlobalStyles = styled.createGlobalStyle`
|
|
1765
|
+
/* Popover rendered at document body */
|
|
1766
|
+
body > .ce-popover,
|
|
1767
|
+
body > .ce-popover--opened,
|
|
1768
|
+
body > .ce-popover__container,
|
|
1769
|
+
body > .ce-settings,
|
|
1770
|
+
body > .ce-conversion-toolbar,
|
|
1771
|
+
body > .ce-inline-toolbar {
|
|
1772
|
+
z-index: 99999 !important;
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
/* Ensure popovers are visible above Strapi modals */
|
|
1776
|
+
.ce-popover,
|
|
1777
|
+
.ce-popover--opened {
|
|
1778
|
+
z-index: 99999 !important;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
/* ============================================
|
|
1782
|
+
READONLY MODE - Block all editing interactions
|
|
1783
|
+
============================================ */
|
|
1784
|
+
.editor-readonly {
|
|
1785
|
+
/* Block all pointer events on editing elements */
|
|
1786
|
+
.ce-block__content,
|
|
1787
|
+
.ce-paragraph,
|
|
1788
|
+
.cdx-block,
|
|
1789
|
+
.ce-header,
|
|
1790
|
+
[contenteditable] {
|
|
1791
|
+
pointer-events: none !important;
|
|
1792
|
+
cursor: not-allowed !important;
|
|
1793
|
+
user-select: text !important; /* Allow text selection for copying */
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
/* Hide editing UI elements */
|
|
1797
|
+
.ce-toolbar,
|
|
1798
|
+
.ce-toolbar__plus,
|
|
1799
|
+
.ce-toolbar__actions,
|
|
1800
|
+
.ce-settings,
|
|
1801
|
+
.ce-block--selected::after,
|
|
1802
|
+
.ce-inline-toolbar,
|
|
1803
|
+
.ce-conversion-toolbar {
|
|
1804
|
+
display: none !important;
|
|
1805
|
+
visibility: hidden !important;
|
|
1806
|
+
pointer-events: none !important;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/* Visual indicator that editor is readonly */
|
|
1810
|
+
.codex-editor {
|
|
1811
|
+
opacity: 0.9;
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
/* Disable contenteditable */
|
|
1815
|
+
[contenteditable="true"] {
|
|
1816
|
+
pointer-events: none !important;
|
|
1817
|
+
-webkit-user-modify: read-only !important;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
/* ============================================
|
|
1822
|
+
STRAPI MEDIA LIBRARY - Higher z-index for fullscreen
|
|
1823
|
+
============================================ */
|
|
1824
|
+
[data-react-portal],
|
|
1825
|
+
.ReactModalPortal,
|
|
1826
|
+
[role="dialog"],
|
|
1827
|
+
[data-strapi-modal="true"],
|
|
1828
|
+
.upload-dialog,
|
|
1829
|
+
[class*="Modal"],
|
|
1830
|
+
[class*="modal"],
|
|
1831
|
+
[class*="Dialog"],
|
|
1832
|
+
[class*="dialog"] {
|
|
1833
|
+
z-index: 100001 !important;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/* Strapi overlay */
|
|
1837
|
+
[data-strapi-modal-overlay="true"],
|
|
1838
|
+
[class*="Overlay"] {
|
|
1839
|
+
z-index: 100000 !important;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
.ce-popover__container {
|
|
1843
|
+
z-index: 99999 !important;
|
|
1844
|
+
background: white;
|
|
1845
|
+
border-radius: 8px;
|
|
1846
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
/* Settings popover */
|
|
1850
|
+
.ce-settings {
|
|
1851
|
+
z-index: 99999 !important;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
/* Inline toolbar */
|
|
1855
|
+
.ce-inline-toolbar {
|
|
1856
|
+
z-index: 99998 !important;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
/* Conversion toolbar */
|
|
1860
|
+
.ce-conversion-toolbar {
|
|
1861
|
+
z-index: 99999 !important;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
/* Block tune popovers */
|
|
1865
|
+
.ce-block-tunes,
|
|
1866
|
+
.ce-block-tunes__buttons {
|
|
1867
|
+
z-index: 99999 !important;
|
|
1868
|
+
}
|
|
1869
|
+
`;
|
|
1870
|
+
const EditorContainer = styled__default.default.div`
|
|
1871
|
+
position: ${(props) => props.$isFullscreen ? "fixed" : "relative"};
|
|
1872
|
+
top: ${(props) => props.$isFullscreen ? "0" : "auto"};
|
|
1873
|
+
left: ${(props) => props.$isFullscreen ? "0" : "auto"};
|
|
1874
|
+
right: ${(props) => props.$isFullscreen ? "0" : "auto"};
|
|
1875
|
+
bottom: ${(props) => props.$isFullscreen ? "0" : "auto"};
|
|
1876
|
+
z-index: ${(props) => props.$isFullscreen ? "9999" : "1"};
|
|
1877
|
+
background: ${(props) => props.$isFullscreen ? props.theme.colors.neutral100 : "transparent"};
|
|
1878
|
+
display: flex;
|
|
1879
|
+
flex-direction: column;
|
|
1880
|
+
min-height: ${(props) => props.$isFullscreen ? "100vh" : `${props.$minHeight}px`};
|
|
1881
|
+
height: ${(props) => props.$isFullscreen ? "100vh" : "auto"};
|
|
1882
|
+
margin-top: ${(props) => props.$isFullscreen ? "0" : "4px"};
|
|
1883
|
+
|
|
1884
|
+
${(props) => props.$isFullscreen && styled.css`
|
|
1885
|
+
padding: 20px;
|
|
1886
|
+
|
|
1887
|
+
@media (min-width: 1200px) {
|
|
1888
|
+
padding: 40px 80px;
|
|
1889
|
+
}
|
|
1890
|
+
`}
|
|
1891
|
+
`;
|
|
1892
|
+
const EditorCard = styled__default.default.div`
|
|
1893
|
+
background: ${(props) => props.theme.colors.neutral0};
|
|
1894
|
+
border: 1px solid ${(props) => props.$hasError ? "#dc2626" : props.$isFocused ? "#7C3AED" : props.theme.colors.neutral200};
|
|
1895
|
+
border-radius: 16px;
|
|
1896
|
+
display: flex;
|
|
1897
|
+
flex-direction: column;
|
|
1898
|
+
flex: 1;
|
|
1899
|
+
box-shadow: ${(props) => props.$isFocused ? "0 0 0 3px rgba(124, 58, 237, 0.1), 0 4px 16px rgba(0, 0, 0, 0.08)" : "0 1px 3px rgba(0, 0, 0, 0.04)"};
|
|
1900
|
+
transition: all 0.2s ease;
|
|
1901
|
+
resize: ${(props) => props.$isFullscreen ? "none" : "vertical"};
|
|
1902
|
+
min-height: ${(props) => props.$minHeight}px;
|
|
1903
|
+
overflow: visible; /* Allow dropdowns to escape container bounds */
|
|
1904
|
+
|
|
1905
|
+
&:hover {
|
|
1906
|
+
border-color: ${(props) => props.$hasError ? "#dc2626" : props.theme.colors.primary200};
|
|
1907
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
${(props) => props.$disabled && styled.css`
|
|
1911
|
+
opacity: 0.6;
|
|
1912
|
+
pointer-events: none;
|
|
1913
|
+
background: ${(props2) => props2.theme.colors.neutral100};
|
|
1914
|
+
`}
|
|
1915
|
+
`;
|
|
1916
|
+
const EditorHeader = styled__default.default.div`
|
|
1917
|
+
display: flex;
|
|
1918
|
+
align-items: center;
|
|
1919
|
+
justify-content: space-between;
|
|
1920
|
+
padding: 12px 16px;
|
|
1921
|
+
background: ${(props) => props.theme.colors.neutral100};
|
|
1922
|
+
border-bottom: 1px solid ${(props) => props.theme.colors.neutral200};
|
|
1923
|
+
flex-shrink: 0;
|
|
1924
|
+
border-radius: 16px 16px 0 0;
|
|
1925
|
+
gap: 8px;
|
|
1926
|
+
flex-wrap: wrap;
|
|
1927
|
+
|
|
1928
|
+
@media (max-width: 640px) {
|
|
1929
|
+
padding: 10px 12px;
|
|
1930
|
+
gap: 6px;
|
|
1931
|
+
}
|
|
1932
|
+
`;
|
|
1933
|
+
const HeaderLeft = styled__default.default.div`
|
|
1934
|
+
display: flex;
|
|
1935
|
+
align-items: center;
|
|
1936
|
+
gap: 12px;
|
|
1937
|
+
flex-shrink: 0;
|
|
1938
|
+
|
|
1939
|
+
@media (max-width: 640px) {
|
|
1940
|
+
gap: 8px;
|
|
1941
|
+
}
|
|
1942
|
+
`;
|
|
1943
|
+
const Logo = styled__default.default.div`
|
|
1944
|
+
display: flex;
|
|
1945
|
+
align-items: center;
|
|
1946
|
+
gap: 8px;
|
|
1947
|
+
|
|
1948
|
+
svg {
|
|
1949
|
+
width: 20px;
|
|
1950
|
+
height: 20px;
|
|
1951
|
+
color: #7C3AED;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
@media (max-width: 480px) {
|
|
1955
|
+
gap: 4px;
|
|
1956
|
+
|
|
1957
|
+
svg {
|
|
1958
|
+
width: 18px;
|
|
1959
|
+
height: 18px;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
`;
|
|
1963
|
+
const LogoText = styled__default.default.span`
|
|
1964
|
+
font-size: 13px;
|
|
1965
|
+
font-weight: 600;
|
|
1966
|
+
color: #6366f1;
|
|
1967
|
+
text-transform: uppercase;
|
|
1968
|
+
letter-spacing: 0.5px;
|
|
1969
|
+
|
|
1970
|
+
@media (max-width: 768px) {
|
|
1971
|
+
font-size: 11px;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
@media (max-width: 480px) {
|
|
1975
|
+
display: none;
|
|
1976
|
+
}
|
|
1977
|
+
`;
|
|
1978
|
+
const STATUS_TOKENS = {
|
|
1979
|
+
idle: { bg: "#e2e8f0", color: "#475569", dot: "#94a3b8" },
|
|
1980
|
+
requesting: { bg: "#fef3c7", color: "#92400e", dot: "#f59e0b" },
|
|
1981
|
+
connecting: { bg: "#ede9fe", color: "#5b21b6", dot: "#7C3AED" },
|
|
1982
|
+
connected: { bg: "#dcfce7", color: "#166534", dot: "#22c55e" },
|
|
1983
|
+
disconnected: { bg: "#fee2e2", color: "#991b1b", dot: "#ef4444" },
|
|
1984
|
+
denied: { bg: "#fee2e2", color: "#b91c1c", dot: "#dc2626" },
|
|
1985
|
+
disabled: { bg: "#e2e8f0", color: "#475569", dot: "#94a3b8" }
|
|
1986
|
+
};
|
|
1987
|
+
const getStatusToken = (status) => STATUS_TOKENS[status] || STATUS_TOKENS.idle;
|
|
1988
|
+
const BlockCount = styled__default.default.span`
|
|
1989
|
+
font-size: 11px;
|
|
1990
|
+
font-weight: 600;
|
|
1991
|
+
color: #7C3AED;
|
|
1992
|
+
background: #ede9fe;
|
|
1993
|
+
padding: 4px 10px;
|
|
1994
|
+
border-radius: 20px;
|
|
1995
|
+
white-space: nowrap;
|
|
1996
|
+
|
|
1997
|
+
@media (max-width: 480px) {
|
|
1998
|
+
font-size: 10px;
|
|
1999
|
+
padding: 3px 8px;
|
|
2000
|
+
}
|
|
2001
|
+
`;
|
|
2002
|
+
styled__default.default.span`
|
|
2003
|
+
display: inline-flex;
|
|
2004
|
+
align-items: center;
|
|
2005
|
+
gap: 6px;
|
|
2006
|
+
font-size: 11px;
|
|
2007
|
+
font-weight: 600;
|
|
2008
|
+
padding: 4px 10px;
|
|
2009
|
+
border-radius: 999px;
|
|
2010
|
+
background: ${({ $status }) => getStatusToken($status).bg};
|
|
2011
|
+
color: ${({ $status }) => getStatusToken($status).color};
|
|
2012
|
+
border: 1px solid rgba(148, 163, 184, 0.25);
|
|
2013
|
+
`;
|
|
2014
|
+
styled__default.default.span`
|
|
2015
|
+
width: 8px;
|
|
2016
|
+
height: 8px;
|
|
2017
|
+
border-radius: 50%;
|
|
2018
|
+
background: ${({ $status }) => getStatusToken($status).dot};
|
|
2019
|
+
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
|
|
2020
|
+
`;
|
|
2021
|
+
styled__default.default.div`
|
|
2022
|
+
display: inline-flex;
|
|
2023
|
+
align-items: center;
|
|
2024
|
+
margin-left: 8px;
|
|
2025
|
+
`;
|
|
2026
|
+
styled__default.default.span`
|
|
2027
|
+
width: 22px;
|
|
2028
|
+
height: 22px;
|
|
2029
|
+
border-radius: 50%;
|
|
2030
|
+
background: rgba(124, 58, 237, 0.08);
|
|
2031
|
+
border: 1px solid rgba(124, 58, 237, 0.25);
|
|
2032
|
+
color: #5b21b6;
|
|
2033
|
+
font-size: 10px;
|
|
2034
|
+
font-weight: 700;
|
|
2035
|
+
display: inline-flex;
|
|
2036
|
+
align-items: center;
|
|
2037
|
+
justify-content: center;
|
|
2038
|
+
margin-left: -6px;
|
|
2039
|
+
|
|
2040
|
+
&:first-child {
|
|
2041
|
+
margin-left: 0;
|
|
2042
|
+
}
|
|
2043
|
+
`;
|
|
2044
|
+
const CollabNotice = styled__default.default.div`
|
|
2045
|
+
padding: 10px 16px;
|
|
2046
|
+
font-size: 12px;
|
|
2047
|
+
color: #b45309;
|
|
2048
|
+
background: #fffbeb;
|
|
2049
|
+
border-top: 1px solid #fde68a;
|
|
2050
|
+
`;
|
|
2051
|
+
const ViewerBanner = styled__default.default.div`
|
|
2052
|
+
display: flex;
|
|
2053
|
+
align-items: center;
|
|
2054
|
+
justify-content: center;
|
|
2055
|
+
gap: 10px;
|
|
2056
|
+
padding: 12px 20px;
|
|
2057
|
+
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
|
|
2058
|
+
color: white;
|
|
2059
|
+
font-size: 14px;
|
|
2060
|
+
font-weight: 600;
|
|
2061
|
+
text-align: center;
|
|
2062
|
+
|
|
2063
|
+
svg {
|
|
2064
|
+
width: 20px;
|
|
2065
|
+
height: 20px;
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
span {
|
|
2069
|
+
opacity: 0.9;
|
|
2070
|
+
font-weight: 400;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
@media (max-width: 640px) {
|
|
2074
|
+
padding: 10px 16px;
|
|
2075
|
+
font-size: 13px;
|
|
2076
|
+
gap: 8px;
|
|
2077
|
+
}
|
|
2078
|
+
`;
|
|
2079
|
+
styled__default.default.div`
|
|
2080
|
+
display: inline-flex;
|
|
2081
|
+
align-items: center;
|
|
2082
|
+
gap: 6px;
|
|
2083
|
+
padding: 4px 12px;
|
|
2084
|
+
border-radius: 20px;
|
|
2085
|
+
font-size: 12px;
|
|
2086
|
+
font-weight: 600;
|
|
2087
|
+
background: ${(props) => props.$role === "viewer" ? "rgba(59, 130, 246, 0.15)" : props.$role === "owner" ? "rgba(245, 158, 11, 0.15)" : "rgba(16, 185, 129, 0.15)"};
|
|
2088
|
+
color: ${(props) => props.$role === "viewer" ? "#1d4ed8" : props.$role === "owner" ? "#b45309" : "#047857"};
|
|
2089
|
+
border: 1px solid ${(props) => props.$role === "viewer" ? "rgba(59, 130, 246, 0.3)" : props.$role === "owner" ? "rgba(245, 158, 11, 0.3)" : "rgba(16, 185, 129, 0.3)"};
|
|
2090
|
+
`;
|
|
2091
|
+
styled__default.default.div`
|
|
2092
|
+
position: absolute;
|
|
2093
|
+
top: 60px;
|
|
2094
|
+
right: 16px;
|
|
2095
|
+
z-index: 50;
|
|
2096
|
+
display: flex;
|
|
2097
|
+
flex-direction: column;
|
|
2098
|
+
align-items: flex-end;
|
|
2099
|
+
gap: 8px;
|
|
2100
|
+
|
|
2101
|
+
@media (max-width: 768px) {
|
|
2102
|
+
top: 50px;
|
|
2103
|
+
right: 12px;
|
|
2104
|
+
gap: 6px;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
@media (max-width: 480px) {
|
|
2108
|
+
top: auto;
|
|
2109
|
+
bottom: 60px;
|
|
2110
|
+
right: 8px;
|
|
2111
|
+
gap: 4px;
|
|
2112
|
+
}
|
|
2113
|
+
`;
|
|
2114
|
+
styled__default.default.div`
|
|
2115
|
+
background: white;
|
|
2116
|
+
border: 1px solid ${({ $status }) => $status === "connected" ? "rgba(34, 197, 94, 0.3)" : $status === "denied" ? "rgba(239, 68, 68, 0.3)" : "rgba(124, 58, 237, 0.2)"};
|
|
2117
|
+
border-radius: 12px;
|
|
2118
|
+
padding: 10px 14px;
|
|
2119
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
|
|
2120
|
+
display: flex;
|
|
2121
|
+
align-items: center;
|
|
2122
|
+
gap: 10px;
|
|
2123
|
+
backdrop-filter: blur(8px);
|
|
2124
|
+
transition: all 0.3s ease;
|
|
2125
|
+
|
|
2126
|
+
&:hover {
|
|
2127
|
+
transform: translateX(-4px);
|
|
2128
|
+
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
@media (max-width: 640px) {
|
|
2132
|
+
padding: 8px 12px;
|
|
2133
|
+
gap: 8px;
|
|
2134
|
+
border-radius: 10px;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
@media (max-width: 480px) {
|
|
2138
|
+
padding: 6px 10px;
|
|
2139
|
+
gap: 6px;
|
|
2140
|
+
border-radius: 8px;
|
|
2141
|
+
|
|
2142
|
+
&:hover {
|
|
2143
|
+
transform: none;
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
`;
|
|
2147
|
+
styled__default.default.div`
|
|
2148
|
+
width: 10px;
|
|
2149
|
+
height: 10px;
|
|
2150
|
+
border-radius: 50%;
|
|
2151
|
+
flex-shrink: 0;
|
|
2152
|
+
background: ${({ $status }) => getStatusToken($status).dot};
|
|
2153
|
+
box-shadow: ${({ $status }) => $status === "connected" ? "0 0 0 3px rgba(34, 197, 94, 0.2)" : $status === "denied" ? "0 0 0 3px rgba(239, 68, 68, 0.2)" : "0 0 0 3px rgba(124, 58, 237, 0.15)"};
|
|
2154
|
+
|
|
2155
|
+
${({ $status }) => $status === "connected" && styled.css`
|
|
2156
|
+
animation: pulse 2s ease-in-out infinite;
|
|
2157
|
+
|
|
2158
|
+
@keyframes pulse {
|
|
2159
|
+
0%, 100% {
|
|
2160
|
+
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
|
|
2161
|
+
transform: scale(1);
|
|
2162
|
+
}
|
|
2163
|
+
50% {
|
|
2164
|
+
box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.1);
|
|
2165
|
+
transform: scale(1.1);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
`}
|
|
2169
|
+
|
|
2170
|
+
@media (max-width: 480px) {
|
|
2171
|
+
width: 8px;
|
|
2172
|
+
height: 8px;
|
|
2173
|
+
}
|
|
2174
|
+
`;
|
|
2175
|
+
styled__default.default.div`
|
|
2176
|
+
display: flex;
|
|
2177
|
+
flex-direction: column;
|
|
2178
|
+
gap: 2px;
|
|
2179
|
+
`;
|
|
2180
|
+
styled__default.default.span`
|
|
2181
|
+
font-size: 12px;
|
|
2182
|
+
font-weight: 600;
|
|
2183
|
+
color: ${({ $status }) => getStatusToken($status).color};
|
|
2184
|
+
|
|
2185
|
+
@media (max-width: 640px) {
|
|
2186
|
+
font-size: 11px;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
@media (max-width: 480px) {
|
|
2190
|
+
font-size: 10px;
|
|
2191
|
+
}
|
|
2192
|
+
`;
|
|
2193
|
+
styled__default.default.span`
|
|
2194
|
+
font-size: 10px;
|
|
2195
|
+
color: #94a3b8;
|
|
2196
|
+
|
|
2197
|
+
@media (max-width: 480px) {
|
|
2198
|
+
display: none;
|
|
2199
|
+
}
|
|
2200
|
+
`;
|
|
2201
|
+
styled__default.default.div`
|
|
2202
|
+
background: white;
|
|
2203
|
+
border: 1px solid rgba(124, 58, 237, 0.15);
|
|
2204
|
+
border-radius: 12px;
|
|
2205
|
+
padding: 8px 12px;
|
|
2206
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
|
|
2207
|
+
display: flex;
|
|
2208
|
+
align-items: center;
|
|
2209
|
+
gap: 8px;
|
|
2210
|
+
transition: all 0.3s ease;
|
|
2211
|
+
|
|
2212
|
+
&:hover {
|
|
2213
|
+
transform: translateX(-4px);
|
|
2214
|
+
border-color: rgba(124, 58, 237, 0.3);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
@media (max-width: 640px) {
|
|
2218
|
+
padding: 6px 10px;
|
|
2219
|
+
gap: 6px;
|
|
2220
|
+
border-radius: 10px;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
@media (max-width: 480px) {
|
|
2224
|
+
padding: 4px 8px;
|
|
2225
|
+
border-radius: 8px;
|
|
2226
|
+
|
|
2227
|
+
&:hover {
|
|
2228
|
+
transform: none;
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
`;
|
|
2232
|
+
styled__default.default.div`
|
|
2233
|
+
display: flex;
|
|
2234
|
+
align-items: center;
|
|
2235
|
+
`;
|
|
2236
|
+
styled__default.default.div`
|
|
2237
|
+
width: 28px;
|
|
2238
|
+
height: 28px;
|
|
2239
|
+
border-radius: 50%;
|
|
2240
|
+
background: ${({ $color }) => $color || "linear-gradient(135deg, #7C3AED 0%, #a855f7 100%)"};
|
|
2241
|
+
border: 2px solid white;
|
|
2242
|
+
color: white;
|
|
2243
|
+
font-size: 10px;
|
|
2244
|
+
font-weight: 700;
|
|
2245
|
+
display: flex;
|
|
2246
|
+
align-items: center;
|
|
2247
|
+
justify-content: center;
|
|
2248
|
+
margin-left: -8px;
|
|
2249
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
2250
|
+
transition: all 0.2s ease;
|
|
2251
|
+
cursor: default;
|
|
2252
|
+
position: relative;
|
|
2253
|
+
|
|
2254
|
+
&:first-child {
|
|
2255
|
+
margin-left: 0;
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
&:hover {
|
|
2259
|
+
transform: translateY(-2px) scale(1.1);
|
|
2260
|
+
z-index: 10;
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
@media (max-width: 640px) {
|
|
2264
|
+
width: 24px;
|
|
2265
|
+
height: 24px;
|
|
2266
|
+
font-size: 9px;
|
|
2267
|
+
margin-left: -6px;
|
|
2268
|
+
|
|
2269
|
+
&:first-child {
|
|
2270
|
+
margin-left: 0;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
@media (max-width: 480px) {
|
|
2275
|
+
width: 22px;
|
|
2276
|
+
height: 22px;
|
|
2277
|
+
font-size: 8px;
|
|
2278
|
+
border-width: 1.5px;
|
|
2279
|
+
margin-left: -5px;
|
|
2280
|
+
|
|
2281
|
+
&:first-child {
|
|
2282
|
+
margin-left: 0;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
&:hover {
|
|
2286
|
+
transform: none;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
/* Hide tooltip on mobile */
|
|
2290
|
+
&::after {
|
|
2291
|
+
display: none;
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
&::after {
|
|
2296
|
+
content: attr(data-name);
|
|
2297
|
+
position: absolute;
|
|
2298
|
+
bottom: calc(100% + 6px);
|
|
2299
|
+
left: 50%;
|
|
2300
|
+
transform: translateX(-50%);
|
|
2301
|
+
background: #1e293b;
|
|
2302
|
+
color: white;
|
|
2303
|
+
font-size: 10px;
|
|
2304
|
+
font-weight: 500;
|
|
2305
|
+
padding: 4px 8px;
|
|
2306
|
+
border-radius: 6px;
|
|
2307
|
+
white-space: nowrap;
|
|
2308
|
+
opacity: 0;
|
|
2309
|
+
visibility: hidden;
|
|
2310
|
+
transition: all 0.15s ease;
|
|
2311
|
+
pointer-events: none;
|
|
2312
|
+
z-index: 100;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
&:hover::after {
|
|
2316
|
+
opacity: 1;
|
|
2317
|
+
visibility: visible;
|
|
2318
|
+
}
|
|
2319
|
+
`;
|
|
2320
|
+
styled__default.default.span`
|
|
2321
|
+
font-size: 11px;
|
|
2322
|
+
color: #64748b;
|
|
2323
|
+
font-weight: 500;
|
|
2324
|
+
white-space: nowrap;
|
|
2325
|
+
|
|
2326
|
+
@media (max-width: 640px) {
|
|
2327
|
+
font-size: 10px;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
@media (max-width: 480px) {
|
|
2331
|
+
display: none;
|
|
2332
|
+
}
|
|
2333
|
+
`;
|
|
2334
|
+
const Toolbar = styled__default.default.div`
|
|
2335
|
+
display: flex;
|
|
2336
|
+
align-items: center;
|
|
2337
|
+
gap: 4px;
|
|
2338
|
+
flex-wrap: wrap;
|
|
2339
|
+
|
|
2340
|
+
@media (max-width: 640px) {
|
|
2341
|
+
gap: 2px;
|
|
2342
|
+
}
|
|
2343
|
+
`;
|
|
2344
|
+
const ToolbarDivider = styled__default.default.div`
|
|
2345
|
+
width: 1px;
|
|
2346
|
+
height: 24px;
|
|
2347
|
+
background: ${(props) => props.theme.colors.neutral200};
|
|
2348
|
+
margin: 0 8px;
|
|
2349
|
+
|
|
2350
|
+
@media (max-width: 768px) {
|
|
2351
|
+
margin: 0 4px;
|
|
2352
|
+
height: 20px;
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
@media (max-width: 480px) {
|
|
2356
|
+
display: none;
|
|
2357
|
+
}
|
|
2358
|
+
`;
|
|
2359
|
+
const ToolButton = styled__default.default.button`
|
|
2360
|
+
display: flex;
|
|
2361
|
+
align-items: center;
|
|
2362
|
+
justify-content: center;
|
|
2363
|
+
width: 34px;
|
|
2364
|
+
height: 34px;
|
|
2365
|
+
border: none;
|
|
2366
|
+
background: ${(props) => props.$active ? "#7C3AED" : "transparent"};
|
|
2367
|
+
color: ${(props) => props.$active ? "white" : props.theme.colors.neutral600};
|
|
2368
|
+
border-radius: 8px;
|
|
2369
|
+
cursor: pointer;
|
|
2370
|
+
transition: all 0.15s ease;
|
|
2371
|
+
position: relative;
|
|
2372
|
+
flex-shrink: 0;
|
|
2373
|
+
|
|
2374
|
+
svg {
|
|
2375
|
+
width: 18px;
|
|
2376
|
+
height: 18px;
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
&:hover {
|
|
2380
|
+
background: ${(props) => props.$active ? "#6d28d9" : props.theme.colors.neutral150};
|
|
2381
|
+
color: ${(props) => props.$active ? "white" : "#7C3AED"};
|
|
2382
|
+
transform: translateY(-1px);
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
&:active {
|
|
2386
|
+
transform: translateY(0);
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
&::after {
|
|
2390
|
+
content: attr(data-tooltip);
|
|
2391
|
+
position: absolute;
|
|
2392
|
+
bottom: calc(100% + 8px);
|
|
2393
|
+
left: 50%;
|
|
2394
|
+
transform: translateX(-50%);
|
|
2395
|
+
background: #1e293b;
|
|
2396
|
+
color: white;
|
|
2397
|
+
font-size: 11px;
|
|
2398
|
+
font-weight: 500;
|
|
2399
|
+
padding: 6px 10px;
|
|
2400
|
+
border-radius: 6px;
|
|
2401
|
+
white-space: nowrap;
|
|
2402
|
+
opacity: 0;
|
|
2403
|
+
visibility: hidden;
|
|
2404
|
+
transition: all 0.15s ease;
|
|
2405
|
+
pointer-events: none;
|
|
2406
|
+
z-index: 100;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
&:hover::after {
|
|
2410
|
+
opacity: 1;
|
|
2411
|
+
visibility: visible;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
@media (max-width: 768px) {
|
|
2415
|
+
width: 32px;
|
|
2416
|
+
height: 32px;
|
|
2417
|
+
|
|
2418
|
+
svg {
|
|
2419
|
+
width: 16px;
|
|
2420
|
+
height: 16px;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
@media (max-width: 480px) {
|
|
2425
|
+
width: 28px;
|
|
2426
|
+
height: 28px;
|
|
2427
|
+
border-radius: 6px;
|
|
2428
|
+
|
|
2429
|
+
svg {
|
|
2430
|
+
width: 14px;
|
|
2431
|
+
height: 14px;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
/* Hide tooltips on mobile - use touch */
|
|
2435
|
+
&::after {
|
|
2436
|
+
display: none;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
`;
|
|
2440
|
+
const QuickActions = styled__default.default.div`
|
|
2441
|
+
display: flex;
|
|
2442
|
+
align-items: center;
|
|
2443
|
+
gap: 2px;
|
|
2444
|
+
padding: 4px;
|
|
2445
|
+
background: ${(props) => props.theme.colors.neutral0};
|
|
2446
|
+
border-radius: 10px;
|
|
2447
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
2448
|
+
flex-wrap: wrap;
|
|
2449
|
+
|
|
2450
|
+
@media (max-width: 768px) {
|
|
2451
|
+
padding: 3px;
|
|
2452
|
+
gap: 1px;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
@media (max-width: 480px) {
|
|
2456
|
+
padding: 2px;
|
|
2457
|
+
border-radius: 8px;
|
|
2458
|
+
|
|
2459
|
+
/* Hide less essential buttons on mobile */
|
|
2460
|
+
& > button:nth-child(n+6) {
|
|
2461
|
+
display: none;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
@media (max-width: 360px) {
|
|
2466
|
+
/* Show only first 4 buttons on very small screens */
|
|
2467
|
+
& > button:nth-child(n+5) {
|
|
2468
|
+
display: none;
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
`;
|
|
2472
|
+
const EditorContent = styled__default.default.div`
|
|
2473
|
+
flex: 1;
|
|
2474
|
+
overflow: visible; /* Allow toolbars/popovers to escape */
|
|
2475
|
+
position: relative;
|
|
2476
|
+
padding: 24px 24px 24px 16px; /* Less left padding since toolbar has its own space */
|
|
2477
|
+
min-height: 200px;
|
|
2478
|
+
|
|
2479
|
+
${(props) => props.$isFullscreen && styled.css`
|
|
2480
|
+
padding: clamp(32px, 4vw, 60px);
|
|
2481
|
+
width: 100%;
|
|
2482
|
+
max-width: 100%;
|
|
2483
|
+
margin: 0;
|
|
2484
|
+
align-self: stretch;
|
|
2485
|
+
`}
|
|
2486
|
+
`;
|
|
2487
|
+
const EditorWrapper = styled__default.default.div`
|
|
2488
|
+
min-height: ${(props) => props.$minHeight - 120}px;
|
|
2489
|
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
2490
|
+
font-size: 15px;
|
|
2491
|
+
line-height: 1.7;
|
|
2492
|
+
color: ${(props) => props.theme.colors.neutral800};
|
|
2493
|
+
position: relative;
|
|
2494
|
+
|
|
2495
|
+
/* ============================================
|
|
2496
|
+
Z-INDEX FIXES FOR DROPDOWNS/POPOVERS
|
|
2497
|
+
============================================ */
|
|
2498
|
+
|
|
2499
|
+
/* Main Editor.js container - ensure proper stacking context */
|
|
2500
|
+
.codex-editor {
|
|
2501
|
+
position: relative;
|
|
2502
|
+
z-index: 1;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
/* Toolbar - needs to be above content */
|
|
2506
|
+
.ce-toolbar {
|
|
2507
|
+
z-index: 100 !important;
|
|
2508
|
+
position: absolute;
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
/* Toolbox (+ button dropdown) - keep position relative to toolbar */
|
|
2512
|
+
.ce-toolbox {
|
|
2513
|
+
z-index: 1000 !important;
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
/* Popover/Dropdown menus - high z-index but keep natural positioning */
|
|
2517
|
+
.ce-popover {
|
|
2518
|
+
z-index: 10000 !important;
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
.ce-popover--opened {
|
|
2522
|
+
z-index: 10000 !important;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
.ce-popover__container {
|
|
2526
|
+
z-index: 10000 !important;
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
/* Block settings popover */
|
|
2530
|
+
.ce-settings {
|
|
2531
|
+
z-index: 10000 !important;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
/* Inline toolbar (bold, italic, etc.) */
|
|
2535
|
+
.ce-inline-toolbar {
|
|
2536
|
+
z-index: 9000 !important;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
/* Inline toolbar actions dropdown */
|
|
2540
|
+
.ce-inline-toolbar__dropdown {
|
|
2541
|
+
z-index: 9500 !important;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
/* Conversion toolbar */
|
|
2545
|
+
.ce-conversion-toolbar {
|
|
2546
|
+
z-index: 10000 !important;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
/* Search field in popovers */
|
|
2550
|
+
.cdx-search-field,
|
|
2551
|
+
.cdx-search-field__input {
|
|
2552
|
+
z-index: 10001 !important;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
/* ============================================
|
|
2556
|
+
TOOLBAR INSIDE EDITOR - Position Fix
|
|
2557
|
+
============================================ */
|
|
2558
|
+
|
|
2559
|
+
/* Make the redactor (content area) have left padding for toolbar */
|
|
2560
|
+
.codex-editor__redactor {
|
|
2561
|
+
padding-bottom: 100px !important;
|
|
2562
|
+
padding-left: 50px !important; /* Space for toolbar */
|
|
2563
|
+
margin-left: 0 !important;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
/* Content blocks - full width within padded area */
|
|
2567
|
+
.ce-block__content {
|
|
2568
|
+
max-width: 100%;
|
|
2569
|
+
margin-left: 0;
|
|
2570
|
+
margin-right: 0;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/* ============================================
|
|
2574
|
+
BLOCK HOVER EFFECT - Visual feedback
|
|
2575
|
+
============================================ */
|
|
2576
|
+
.ce-block {
|
|
2577
|
+
position: relative;
|
|
2578
|
+
border-radius: 8px;
|
|
2579
|
+
transition: all 0.15s ease;
|
|
2580
|
+
margin: 2px 0;
|
|
2581
|
+
|
|
2582
|
+
&::before {
|
|
2583
|
+
content: '';
|
|
2584
|
+
position: absolute;
|
|
2585
|
+
top: -2px;
|
|
2586
|
+
left: -8px;
|
|
2587
|
+
right: -8px;
|
|
2588
|
+
bottom: -2px;
|
|
2589
|
+
border: 2px solid transparent;
|
|
2590
|
+
border-radius: 8px;
|
|
2591
|
+
pointer-events: none;
|
|
2592
|
+
transition: all 0.15s ease;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
&:hover::before {
|
|
2596
|
+
border-color: #e2e8f0;
|
|
2597
|
+
background: rgba(241, 245, 249, 0.3);
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
/* Selected block - stronger highlight */
|
|
2601
|
+
&--selected::before {
|
|
2602
|
+
border-color: #cbd5e1 !important;
|
|
2603
|
+
background: rgba(203, 213, 225, 0.15) !important;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
/* Focused block */
|
|
2607
|
+
&--focused::before {
|
|
2608
|
+
border-color: #7C3AED !important;
|
|
2609
|
+
background: rgba(124, 58, 237, 0.05) !important;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
/* Block content hover - subtle background */
|
|
2614
|
+
.ce-block__content:hover {
|
|
2615
|
+
background: rgba(248, 250, 252, 0.5);
|
|
2616
|
+
border-radius: 6px;
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
/* Toolbar positioning - inside the editor */
|
|
2620
|
+
.ce-toolbar__content {
|
|
2621
|
+
max-width: 100%;
|
|
2622
|
+
margin-left: 0;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
.ce-toolbar {
|
|
2626
|
+
left: 0 !important;
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
.ce-toolbar__plus {
|
|
2630
|
+
left: 0 !important;
|
|
2631
|
+
position: relative !important;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
.ce-toolbar__actions {
|
|
2635
|
+
right: 0 !important;
|
|
2636
|
+
position: absolute !important;
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
/* Settings button (⋮⋮) */
|
|
2640
|
+
.ce-toolbar__settings-btn {
|
|
2641
|
+
margin-left: 4px;
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
/* ============================================
|
|
2645
|
+
POPOVER/DROPDOWN STYLING
|
|
2646
|
+
============================================ */
|
|
2647
|
+
|
|
2648
|
+
.ce-popover {
|
|
2649
|
+
border-radius: 12px !important;
|
|
2650
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08) !important;
|
|
2651
|
+
border: 1px solid #e2e8f0 !important;
|
|
2652
|
+
overflow: hidden;
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
.ce-popover__container {
|
|
2656
|
+
background: white !important;
|
|
2657
|
+
border-radius: 12px !important;
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
.ce-popover__items {
|
|
2661
|
+
padding: 8px !important;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
.ce-popover-item {
|
|
2665
|
+
border-radius: 8px !important;
|
|
2666
|
+
padding: 8px 12px !important;
|
|
2667
|
+
margin: 2px 0 !important;
|
|
2668
|
+
transition: all 0.15s ease !important;
|
|
2669
|
+
|
|
2670
|
+
&:hover {
|
|
2671
|
+
background: #f1f5f9 !important;
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
.ce-popover-item__icon {
|
|
2676
|
+
color: #64748b !important;
|
|
2677
|
+
width: 20px !important;
|
|
2678
|
+
height: 20px !important;
|
|
2679
|
+
margin-right: 10px !important;
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
.ce-popover-item__title {
|
|
2683
|
+
font-weight: 500 !important;
|
|
2684
|
+
color: #334155 !important;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
.ce-popover-item--focused {
|
|
2688
|
+
background: #ede9fe !important;
|
|
2689
|
+
|
|
2690
|
+
.ce-popover-item__icon {
|
|
2691
|
+
color: #7C3AED !important;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
.ce-popover-item__title {
|
|
2695
|
+
color: #7C3AED !important;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/* Search field in popover */
|
|
2700
|
+
.cdx-search-field {
|
|
2701
|
+
margin: 8px !important;
|
|
2702
|
+
border-radius: 8px !important;
|
|
2703
|
+
border: 1px solid #e2e8f0 !important;
|
|
2704
|
+
background: #f8fafc !important;
|
|
2705
|
+
|
|
2706
|
+
&:focus-within {
|
|
2707
|
+
border-color: #7C3AED !important;
|
|
2708
|
+
box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1) !important;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
.cdx-search-field__input {
|
|
2713
|
+
font-size: 14px !important;
|
|
2714
|
+
color: #334155 !important;
|
|
2715
|
+
|
|
2716
|
+
&::placeholder {
|
|
2717
|
+
color: #94a3b8 !important;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
/* Separator in popover */
|
|
2722
|
+
.ce-popover__item-separator {
|
|
2723
|
+
margin: 8px !important;
|
|
2724
|
+
background: #e2e8f0 !important;
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
/* ============================================
|
|
2728
|
+
INDENT TUNE FIX
|
|
2729
|
+
============================================ */
|
|
2730
|
+
|
|
2731
|
+
/* Indent tune container */
|
|
2732
|
+
.ce-popover-item[data-item-name="indentTune"],
|
|
2733
|
+
.ce-popover-item[data-item-name="indent"] {
|
|
2734
|
+
display: flex !important;
|
|
2735
|
+
align-items: center !important;
|
|
2736
|
+
gap: 8px !important;
|
|
2737
|
+
padding: 4px 8px !important;
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
/* Indent tune wrapper - force horizontal layout */
|
|
2741
|
+
.indent-tune,
|
|
2742
|
+
[class*="indent-tune"],
|
|
2743
|
+
.ce-popover-item__custom-html {
|
|
2744
|
+
display: flex !important;
|
|
2745
|
+
align-items: center !important;
|
|
2746
|
+
gap: 4px !important;
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
/* Indent buttons */
|
|
2750
|
+
.indent-tune__button,
|
|
2751
|
+
.indent-tune button,
|
|
2752
|
+
[class*="indent"] button {
|
|
2753
|
+
width: 32px !important;
|
|
2754
|
+
height: 32px !important;
|
|
2755
|
+
min-width: 32px !important;
|
|
2756
|
+
border: 1px solid #e2e8f0 !important;
|
|
2757
|
+
border-radius: 6px !important;
|
|
2758
|
+
background: white !important;
|
|
2759
|
+
cursor: pointer !important;
|
|
2760
|
+
display: flex !important;
|
|
2761
|
+
align-items: center !important;
|
|
2762
|
+
justify-content: center !important;
|
|
2763
|
+
transition: all 0.15s ease !important;
|
|
2764
|
+
pointer-events: auto !important;
|
|
2765
|
+
position: relative !important;
|
|
2766
|
+
z-index: 10 !important;
|
|
2767
|
+
|
|
2768
|
+
&:hover {
|
|
2769
|
+
background: #f1f5f9 !important;
|
|
2770
|
+
border-color: #7C3AED !important;
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
&:active {
|
|
2774
|
+
background: #ede9fe !important;
|
|
2775
|
+
transform: scale(0.95) !important;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/* Indent button icons */
|
|
2780
|
+
.indent-tune__button svg,
|
|
2781
|
+
.indent-tune button svg,
|
|
2782
|
+
[class*="indent"] button svg {
|
|
2783
|
+
width: 16px !important;
|
|
2784
|
+
height: 16px !important;
|
|
2785
|
+
color: #64748b !important;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
/* Indent label */
|
|
2789
|
+
.indent-tune__label,
|
|
2790
|
+
.indent-tune span:not(:empty) {
|
|
2791
|
+
font-size: 13px !important;
|
|
2792
|
+
font-weight: 500 !important;
|
|
2793
|
+
color: #334155 !important;
|
|
2794
|
+
margin: 0 4px !important;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
/* ============================================
|
|
2798
|
+
ALIGNMENT TUNE FIX
|
|
2799
|
+
============================================ */
|
|
2800
|
+
|
|
2801
|
+
.ce-popover-item[data-item-name="alignmentTune"],
|
|
2802
|
+
.ce-popover-item[data-item-name="alignment"] {
|
|
2803
|
+
display: flex !important;
|
|
2804
|
+
align-items: center !important;
|
|
2805
|
+
gap: 4px !important;
|
|
2806
|
+
padding: 4px 8px !important;
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
.alignment-tune,
|
|
2810
|
+
[class*="alignment-tune"],
|
|
2811
|
+
[class*="text-alignment"] {
|
|
2812
|
+
display: flex !important;
|
|
2813
|
+
align-items: center !important;
|
|
2814
|
+
gap: 2px !important;
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
.alignment-tune button,
|
|
2818
|
+
[class*="alignment"] button,
|
|
2819
|
+
[class*="text-alignment"] button {
|
|
2820
|
+
width: 28px !important;
|
|
2821
|
+
height: 28px !important;
|
|
2822
|
+
min-width: 28px !important;
|
|
2823
|
+
border: 1px solid transparent !important;
|
|
2824
|
+
border-radius: 4px !important;
|
|
2825
|
+
background: transparent !important;
|
|
2826
|
+
cursor: pointer !important;
|
|
2827
|
+
display: flex !important;
|
|
2828
|
+
align-items: center !important;
|
|
2829
|
+
justify-content: center !important;
|
|
2830
|
+
transition: all 0.15s ease !important;
|
|
2831
|
+
pointer-events: auto !important;
|
|
2832
|
+
|
|
2833
|
+
&:hover {
|
|
2834
|
+
background: #f1f5f9 !important;
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
&.active,
|
|
2838
|
+
&[class*="active"] {
|
|
2839
|
+
background: #ede9fe !important;
|
|
2840
|
+
border-color: #7C3AED !important;
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
.alignment-tune button svg,
|
|
2845
|
+
[class*="alignment"] button svg {
|
|
2846
|
+
width: 16px !important;
|
|
2847
|
+
height: 16px !important;
|
|
2848
|
+
color: #64748b !important;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
/* Remote user editing highlight - subtle background only, cursor shown separately */
|
|
2852
|
+
.ce-block--remote-editing {
|
|
2853
|
+
position: relative;
|
|
2854
|
+
background: rgba(59, 130, 246, 0.04);
|
|
2855
|
+
border-radius: 4px;
|
|
2856
|
+
transition: background 0.2s ease;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
/* Typing indicator animation */
|
|
2860
|
+
.typing-indicator .dot {
|
|
2861
|
+
display: inline-block;
|
|
2862
|
+
width: 4px;
|
|
2863
|
+
height: 4px;
|
|
2864
|
+
border-radius: 50%;
|
|
2865
|
+
background: currentColor;
|
|
2866
|
+
opacity: 0.7;
|
|
2867
|
+
animation: typingBounce 1.4s ease-in-out infinite;
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
.typing-indicator .dot:nth-child(1) {
|
|
2871
|
+
animation-delay: 0s;
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
.typing-indicator .dot:nth-child(2) {
|
|
2875
|
+
animation-delay: 0.2s;
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
.typing-indicator .dot:nth-child(3) {
|
|
2879
|
+
animation-delay: 0.4s;
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
@keyframes typingBounce {
|
|
2883
|
+
0%, 60%, 100% {
|
|
2884
|
+
transform: translateY(0);
|
|
2885
|
+
opacity: 0.4;
|
|
2886
|
+
}
|
|
2887
|
+
30% {
|
|
2888
|
+
transform: translateY(-3px);
|
|
2889
|
+
opacity: 1;
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
/* Remote cursor pulse animation */
|
|
2894
|
+
.remote-cursor-indicator {
|
|
2895
|
+
animation: cursorPulse 1.5s ease-in-out infinite;
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
@keyframes cursorPulse {
|
|
2899
|
+
0%, 100% {
|
|
2900
|
+
opacity: 1;
|
|
2901
|
+
box-shadow: 0 0 8px currentColor;
|
|
2902
|
+
}
|
|
2903
|
+
50% {
|
|
2904
|
+
opacity: 0.7;
|
|
2905
|
+
box-shadow: 0 0 12px currentColor;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
`;
|
|
2909
|
+
const EmptyState = styled__default.default.div`
|
|
2910
|
+
position: absolute;
|
|
2911
|
+
top: 50%;
|
|
2912
|
+
left: 50%;
|
|
2913
|
+
transform: translate(-50%, -50%);
|
|
2914
|
+
text-align: center;
|
|
2915
|
+
pointer-events: none;
|
|
2916
|
+
`;
|
|
2917
|
+
const EmptyIcon = styled__default.default.div`
|
|
2918
|
+
width: 100px;
|
|
2919
|
+
height: 100px;
|
|
2920
|
+
margin: 0 auto 20px;
|
|
2921
|
+
background: linear-gradient(135deg, #f0f4ff 0%, #e8ecff 100%);
|
|
2922
|
+
border-radius: 50%;
|
|
2923
|
+
display: flex;
|
|
2924
|
+
align-items: center;
|
|
2925
|
+
justify-content: center;
|
|
2926
|
+
animation: float 4s ease-in-out infinite;
|
|
2927
|
+
|
|
2928
|
+
svg {
|
|
2929
|
+
width: 48px;
|
|
2930
|
+
height: 48px;
|
|
2931
|
+
color: #a5b4fc;
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2934
|
+
@keyframes float {
|
|
2935
|
+
0%, 100% { transform: translateY(0); }
|
|
2936
|
+
50% { transform: translateY(-10px); }
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
@media (max-width: 480px) {
|
|
2940
|
+
width: 72px;
|
|
2941
|
+
height: 72px;
|
|
2942
|
+
margin: 0 auto 16px;
|
|
2943
|
+
|
|
2944
|
+
svg {
|
|
2945
|
+
width: 32px;
|
|
2946
|
+
height: 32px;
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
`;
|
|
2950
|
+
const EmptyTitle = styled__default.default.h3`
|
|
2951
|
+
font-size: 18px;
|
|
2952
|
+
font-weight: 600;
|
|
2953
|
+
color: #64748b;
|
|
2954
|
+
margin: 0 0 8px 0;
|
|
2955
|
+
|
|
2956
|
+
@media (max-width: 480px) {
|
|
2957
|
+
font-size: 16px;
|
|
2958
|
+
}
|
|
2959
|
+
`;
|
|
2960
|
+
const EmptySubtitle = styled__default.default.p`
|
|
2961
|
+
font-size: 14px;
|
|
2962
|
+
color: #94a3b8;
|
|
2963
|
+
margin: 0 0 20px 0;
|
|
2964
|
+
|
|
2965
|
+
@media (max-width: 480px) {
|
|
2966
|
+
font-size: 12px;
|
|
2967
|
+
margin: 0 0 16px 0;
|
|
2968
|
+
padding: 0 16px;
|
|
2969
|
+
}
|
|
2970
|
+
`;
|
|
2971
|
+
const KeyboardHints = styled__default.default.div`
|
|
2972
|
+
display: flex;
|
|
2973
|
+
gap: 16px;
|
|
2974
|
+
justify-content: center;
|
|
2975
|
+
flex-wrap: wrap;
|
|
2976
|
+
|
|
2977
|
+
@media (max-width: 640px) {
|
|
2978
|
+
gap: 10px;
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
@media (max-width: 480px) {
|
|
2982
|
+
display: none; /* Hide keyboard hints on mobile - not useful for touch */
|
|
2983
|
+
}
|
|
2984
|
+
`;
|
|
2985
|
+
const KeyHint = styled__default.default.span`
|
|
2986
|
+
font-size: 12px;
|
|
2987
|
+
color: #94a3b8;
|
|
2988
|
+
|
|
2989
|
+
kbd {
|
|
2990
|
+
display: inline-block;
|
|
2991
|
+
padding: 2px 8px;
|
|
2992
|
+
background: #f1f5f9;
|
|
2993
|
+
border: 1px solid #e2e8f0;
|
|
2994
|
+
border-radius: 6px;
|
|
2995
|
+
font-family: 'SF Mono', Monaco, monospace;
|
|
2996
|
+
font-size: 11px;
|
|
2997
|
+
color: #475569;
|
|
2998
|
+
margin-right: 4px;
|
|
2999
|
+
box-shadow: 0 1px 0 rgba(0,0,0,0.05);
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
@media (max-width: 640px) {
|
|
3003
|
+
font-size: 10px;
|
|
3004
|
+
|
|
3005
|
+
kbd {
|
|
3006
|
+
padding: 2px 6px;
|
|
3007
|
+
font-size: 9px;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
`;
|
|
3011
|
+
const EditorFooter = styled__default.default.div`
|
|
3012
|
+
display: flex;
|
|
3013
|
+
align-items: center;
|
|
3014
|
+
justify-content: space-between;
|
|
3015
|
+
padding: 10px 16px;
|
|
3016
|
+
background: ${(props) => props.theme.colors.neutral100};
|
|
3017
|
+
border-top: 1px solid ${(props) => props.theme.colors.neutral150};
|
|
3018
|
+
flex-shrink: 0;
|
|
3019
|
+
border-radius: 0 0 16px 16px;
|
|
3020
|
+
gap: 8px;
|
|
3021
|
+
flex-wrap: wrap;
|
|
3022
|
+
|
|
3023
|
+
@media (max-width: 640px) {
|
|
3024
|
+
padding: 8px 12px;
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
@media (max-width: 480px) {
|
|
3028
|
+
padding: 8px 10px;
|
|
3029
|
+
gap: 6px;
|
|
3030
|
+
}
|
|
3031
|
+
`;
|
|
3032
|
+
const FooterLeft = styled__default.default.div`
|
|
3033
|
+
display: flex;
|
|
3034
|
+
align-items: center;
|
|
3035
|
+
gap: 16px;
|
|
3036
|
+
|
|
3037
|
+
@media (max-width: 640px) {
|
|
3038
|
+
gap: 12px;
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
@media (max-width: 480px) {
|
|
3042
|
+
gap: 8px;
|
|
3043
|
+
}
|
|
3044
|
+
`;
|
|
3045
|
+
const FooterStat = styled__default.default.span`
|
|
3046
|
+
font-size: 12px;
|
|
3047
|
+
color: ${(props) => props.theme.colors.neutral500};
|
|
3048
|
+
white-space: nowrap;
|
|
3049
|
+
|
|
3050
|
+
strong {
|
|
3051
|
+
color: ${(props) => props.theme.colors.neutral700};
|
|
3052
|
+
font-weight: 600;
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
@media (max-width: 640px) {
|
|
3056
|
+
font-size: 11px;
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
@media (max-width: 480px) {
|
|
3060
|
+
font-size: 10px;
|
|
3061
|
+
}
|
|
3062
|
+
`;
|
|
3063
|
+
const FooterRight = styled__default.default.div`
|
|
3064
|
+
display: flex;
|
|
3065
|
+
align-items: center;
|
|
3066
|
+
gap: 8px;
|
|
3067
|
+
|
|
3068
|
+
@media (max-width: 640px) {
|
|
3069
|
+
gap: 6px;
|
|
3070
|
+
}
|
|
3071
|
+
`;
|
|
3072
|
+
const FooterButton = styled__default.default.button`
|
|
3073
|
+
display: inline-flex;
|
|
3074
|
+
align-items: center;
|
|
3075
|
+
gap: 6px;
|
|
3076
|
+
padding: 6px 14px;
|
|
3077
|
+
background: ${(props) => props.$primary ? "linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%)" : props.theme.colors.neutral0};
|
|
3078
|
+
border: 1px solid ${(props) => props.$primary ? "transparent" : props.theme.colors.neutral200};
|
|
3079
|
+
border-radius: 8px;
|
|
3080
|
+
font-size: 12px;
|
|
3081
|
+
font-weight: 500;
|
|
3082
|
+
color: ${(props) => props.$primary ? "white" : props.theme.colors.neutral600};
|
|
3083
|
+
cursor: pointer;
|
|
3084
|
+
transition: all 0.15s ease;
|
|
3085
|
+
white-space: nowrap;
|
|
3086
|
+
|
|
3087
|
+
svg {
|
|
3088
|
+
width: 14px;
|
|
3089
|
+
height: 14px;
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
&:hover {
|
|
3093
|
+
background: ${(props) => props.$primary ? "linear-gradient(135deg, #6d28d9 0%, #5b21b6 100%)" : "#f8fafc"};
|
|
3094
|
+
border-color: ${(props) => props.$primary ? "transparent" : "#7C3AED"};
|
|
3095
|
+
color: ${(props) => props.$primary ? "white" : "#7C3AED"};
|
|
3096
|
+
transform: translateY(-1px);
|
|
3097
|
+
box-shadow: ${(props) => props.$primary ? "0 4px 12px rgba(124, 58, 237, 0.3)" : "none"};
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
@media (max-width: 640px) {
|
|
3101
|
+
padding: 5px 10px;
|
|
3102
|
+
font-size: 11px;
|
|
3103
|
+
gap: 4px;
|
|
3104
|
+
|
|
3105
|
+
svg {
|
|
3106
|
+
width: 12px;
|
|
3107
|
+
height: 12px;
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
@media (max-width: 480px) {
|
|
3112
|
+
padding: 4px 8px;
|
|
3113
|
+
font-size: 10px;
|
|
3114
|
+
border-radius: 6px;
|
|
3115
|
+
|
|
3116
|
+
/* Hide text on very small screens, show only icon */
|
|
3117
|
+
& > span {
|
|
3118
|
+
display: none;
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
`;
|
|
3122
|
+
const LoadingOverlay = styled__default.default.div`
|
|
3123
|
+
position: absolute;
|
|
3124
|
+
top: 0;
|
|
3125
|
+
left: 0;
|
|
3126
|
+
right: 0;
|
|
3127
|
+
bottom: 0;
|
|
3128
|
+
background: rgba(255, 255, 255, 0.9);
|
|
3129
|
+
display: flex;
|
|
3130
|
+
flex-direction: column;
|
|
3131
|
+
align-items: center;
|
|
3132
|
+
justify-content: center;
|
|
3133
|
+
gap: 12px;
|
|
3134
|
+
z-index: 10;
|
|
3135
|
+
`;
|
|
3136
|
+
const LoadingText = styled__default.default.span`
|
|
3137
|
+
font-size: 13px;
|
|
3138
|
+
color: #64748b;
|
|
3139
|
+
`;
|
|
3140
|
+
const ResizeHandle = styled__default.default.div`
|
|
3141
|
+
position: absolute;
|
|
3142
|
+
bottom: 0;
|
|
3143
|
+
left: 50%;
|
|
3144
|
+
transform: translateX(-50%);
|
|
3145
|
+
width: 60px;
|
|
3146
|
+
height: 16px;
|
|
3147
|
+
cursor: ns-resize;
|
|
3148
|
+
display: flex;
|
|
3149
|
+
align-items: center;
|
|
3150
|
+
justify-content: center;
|
|
3151
|
+
|
|
3152
|
+
&::before {
|
|
3153
|
+
content: '';
|
|
3154
|
+
width: 40px;
|
|
3155
|
+
height: 4px;
|
|
3156
|
+
background: #e2e8f0;
|
|
3157
|
+
border-radius: 2px;
|
|
3158
|
+
transition: background 0.15s ease;
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
&:hover::before {
|
|
3162
|
+
background: #7C3AED;
|
|
3163
|
+
}
|
|
3164
|
+
`;
|
|
3165
|
+
styled__default.default.div`
|
|
3166
|
+
position: absolute;
|
|
3167
|
+
top: 0;
|
|
3168
|
+
left: 0;
|
|
3169
|
+
right: 0;
|
|
3170
|
+
bottom: 0;
|
|
3171
|
+
pointer-events: none;
|
|
3172
|
+
z-index: 100;
|
|
3173
|
+
overflow: hidden;
|
|
3174
|
+
`;
|
|
3175
|
+
styled__default.default.div`
|
|
3176
|
+
position: absolute;
|
|
3177
|
+
pointer-events: none;
|
|
3178
|
+
transition: all 0.15s ease-out;
|
|
3179
|
+
z-index: 100;
|
|
3180
|
+
`;
|
|
3181
|
+
styled__default.default.div`
|
|
3182
|
+
width: 2px;
|
|
3183
|
+
height: 20px;
|
|
3184
|
+
background: ${(props) => props.$color || "#3B82F6"};
|
|
3185
|
+
border-radius: 1px;
|
|
3186
|
+
box-shadow: 0 0 4px ${(props) => props.$color || "#3B82F6"}40;
|
|
3187
|
+
animation: cursorBlink 1s ease-in-out infinite;
|
|
3188
|
+
|
|
3189
|
+
@keyframes cursorBlink {
|
|
3190
|
+
0%, 100% { opacity: 1; }
|
|
3191
|
+
50% { opacity: 0.6; }
|
|
3192
|
+
}
|
|
3193
|
+
`;
|
|
3194
|
+
styled__default.default.div`
|
|
3195
|
+
position: absolute;
|
|
3196
|
+
top: -22px;
|
|
3197
|
+
left: 0;
|
|
3198
|
+
background: ${(props) => props.$bgColor || "#3B82F6"};
|
|
3199
|
+
color: ${(props) => props.$textColor || "#FFFFFF"};
|
|
3200
|
+
font-size: 10px;
|
|
3201
|
+
font-weight: 600;
|
|
3202
|
+
padding: 2px 6px;
|
|
3203
|
+
border-radius: 4px 4px 4px 0;
|
|
3204
|
+
white-space: nowrap;
|
|
3205
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
|
|
3206
|
+
transform-origin: bottom left;
|
|
3207
|
+
animation: cursorLabelFadeIn 0.2s ease-out;
|
|
3208
|
+
|
|
3209
|
+
@keyframes cursorLabelFadeIn {
|
|
3210
|
+
from {
|
|
3211
|
+
opacity: 0;
|
|
3212
|
+
transform: scale(0.8);
|
|
3213
|
+
}
|
|
3214
|
+
to {
|
|
3215
|
+
opacity: 1;
|
|
3216
|
+
transform: scale(1);
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
`;
|
|
3220
|
+
styled__default.default.div`
|
|
3221
|
+
position: absolute;
|
|
3222
|
+
background: ${(props) => props.$color || "#3B82F6"}20;
|
|
3223
|
+
border: 1px solid ${(props) => props.$color || "#3B82F6"}40;
|
|
3224
|
+
border-radius: 2px;
|
|
3225
|
+
pointer-events: none;
|
|
3226
|
+
`;
|
|
3227
|
+
const ActiveEditorsBar = styled__default.default.div`
|
|
3228
|
+
display: flex;
|
|
3229
|
+
align-items: center;
|
|
3230
|
+
gap: 8px;
|
|
3231
|
+
padding: 8px 16px;
|
|
3232
|
+
background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 100%);
|
|
3233
|
+
border-bottom: 1px solid #e2e8f0;
|
|
3234
|
+
flex-shrink: 0;
|
|
3235
|
+
flex-wrap: wrap;
|
|
3236
|
+
|
|
3237
|
+
@media (max-width: 640px) {
|
|
3238
|
+
padding: 6px 12px;
|
|
3239
|
+
gap: 6px;
|
|
3240
|
+
}
|
|
3241
|
+
|
|
3242
|
+
@media (max-width: 480px) {
|
|
3243
|
+
padding: 6px 10px;
|
|
3244
|
+
gap: 4px;
|
|
3245
|
+
}
|
|
3246
|
+
`;
|
|
3247
|
+
const ActiveEditorBadge = styled__default.default.div`
|
|
3248
|
+
display: inline-flex;
|
|
3249
|
+
align-items: center;
|
|
3250
|
+
gap: 6px;
|
|
3251
|
+
padding: 4px 10px;
|
|
3252
|
+
background: white;
|
|
3253
|
+
border: 1px solid ${(props) => props.$color || "#e2e8f0"};
|
|
3254
|
+
border-radius: 20px;
|
|
3255
|
+
font-size: 11px;
|
|
3256
|
+
font-weight: 500;
|
|
3257
|
+
color: #374151;
|
|
3258
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
3259
|
+
transition: all 0.2s ease;
|
|
3260
|
+
white-space: nowrap;
|
|
3261
|
+
|
|
3262
|
+
&:hover {
|
|
3263
|
+
transform: translateY(-1px);
|
|
3264
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
@media (max-width: 640px) {
|
|
3268
|
+
padding: 3px 8px;
|
|
3269
|
+
font-size: 10px;
|
|
3270
|
+
gap: 4px;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
@media (max-width: 480px) {
|
|
3274
|
+
/* Hide "Block X" info on mobile */
|
|
3275
|
+
& > span:last-child {
|
|
3276
|
+
display: none;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
`;
|
|
3280
|
+
const ActiveEditorDot = styled__default.default.span`
|
|
3281
|
+
width: 8px;
|
|
3282
|
+
height: 8px;
|
|
3283
|
+
border-radius: 50%;
|
|
3284
|
+
background: ${(props) => props.$color || "#3B82F6"};
|
|
3285
|
+
box-shadow: 0 0 0 2px ${(props) => props.$color || "#3B82F6"}30;
|
|
3286
|
+
animation: pulse 2s ease-in-out infinite;
|
|
3287
|
+
flex-shrink: 0;
|
|
3288
|
+
|
|
3289
|
+
@keyframes pulse {
|
|
3290
|
+
0%, 100% { box-shadow: 0 0 0 2px ${(props) => props.$color || "#3B82F6"}30; }
|
|
3291
|
+
50% { box-shadow: 0 0 0 4px ${(props) => props.$color || "#3B82F6"}20; }
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
@media (max-width: 480px) {
|
|
3295
|
+
width: 6px;
|
|
3296
|
+
height: 6px;
|
|
3297
|
+
}
|
|
3298
|
+
`;
|
|
3299
|
+
const ActiveEditorsLabel = styled__default.default.span`
|
|
3300
|
+
font-size: 11px;
|
|
3301
|
+
color: #64748b;
|
|
3302
|
+
font-weight: 500;
|
|
3303
|
+
white-space: nowrap;
|
|
3304
|
+
|
|
3305
|
+
@media (max-width: 640px) {
|
|
3306
|
+
font-size: 10px;
|
|
3307
|
+
}
|
|
3308
|
+
|
|
3309
|
+
@media (max-width: 480px) {
|
|
3310
|
+
display: none;
|
|
3311
|
+
}
|
|
3312
|
+
`;
|
|
3313
|
+
const buildRoomId = (fieldName, documentId = null) => {
|
|
3314
|
+
if (typeof window === "undefined") {
|
|
3315
|
+
return `ssr|${fieldName}`;
|
|
3316
|
+
}
|
|
3317
|
+
const path = window.location.pathname;
|
|
3318
|
+
const matches = path.match(/content-manager\/(collection-types|single-types)\/([^/]+)(?:\/([^/?]+))?/);
|
|
3319
|
+
const contentType = matches?.[2] ? decodeURIComponent(matches[2]) : "unknown";
|
|
3320
|
+
const urlDocumentId = matches?.[3] || null;
|
|
3321
|
+
let docId = documentId || urlDocumentId;
|
|
3322
|
+
if (!docId) {
|
|
3323
|
+
docId = matches?.[1] === "single-types" ? "single" : "new";
|
|
3324
|
+
}
|
|
3325
|
+
const roomId = `${contentType}|${docId}|${fieldName}`;
|
|
3326
|
+
console.log("[Magic Editor X] buildRoomId:", { contentType, documentId: docId, fieldName, roomId });
|
|
3327
|
+
return roomId;
|
|
3328
|
+
};
|
|
3329
|
+
const getPeerName = (user = {}) => {
|
|
3330
|
+
if (user.firstname || user.lastname) {
|
|
3331
|
+
return `${user.firstname || ""} ${user.lastname || ""}`.trim();
|
|
3332
|
+
}
|
|
3333
|
+
return user.email?.split("@")[0] || "Anonymous";
|
|
3334
|
+
};
|
|
3335
|
+
const Editor = React.forwardRef(({
|
|
3336
|
+
name,
|
|
3337
|
+
value,
|
|
3338
|
+
onChange,
|
|
3339
|
+
attribute,
|
|
3340
|
+
disabled,
|
|
3341
|
+
error,
|
|
3342
|
+
required,
|
|
3343
|
+
hint,
|
|
3344
|
+
label,
|
|
3345
|
+
labelAction,
|
|
3346
|
+
placeholder,
|
|
3347
|
+
...props
|
|
3348
|
+
}, ref) => {
|
|
3349
|
+
const { formatMessage } = getTranslation.useIntl();
|
|
3350
|
+
const t = (id, defaultMessage) => formatMessage({ id: getTranslation.getTranslation(id), defaultMessage });
|
|
3351
|
+
const { licenseData } = useLicense();
|
|
3352
|
+
const editorRef = React.useRef(null);
|
|
3353
|
+
const editorInstanceRef = React.useRef(null);
|
|
3354
|
+
const containerRef = React.useRef(null);
|
|
3355
|
+
const isReadyRef = React.useRef(false);
|
|
3356
|
+
const [isReady, setIsReady] = React.useState(false);
|
|
3357
|
+
const [showCreditsModal, setShowCreditsModal] = React.useState(false);
|
|
3358
|
+
const [creditsUpgradeInfo, setCreditsUpgradeInfo] = React.useState(null);
|
|
3359
|
+
const { handleAIAction } = useAIActions({
|
|
3360
|
+
licenseKey: licenseData?.licenseKey,
|
|
3361
|
+
editorInstanceRef,
|
|
3362
|
+
isReady,
|
|
3363
|
+
onNoCredits: (upgradeInfo) => {
|
|
3364
|
+
setCreditsUpgradeInfo(upgradeInfo);
|
|
3365
|
+
setShowCreditsModal(true);
|
|
3366
|
+
}
|
|
3367
|
+
});
|
|
3368
|
+
React.useEffect(() => {
|
|
3369
|
+
if (licenseData?.licenseKey) {
|
|
3370
|
+
window.__MAGIC_EDITOR_LICENSE_KEY__ = licenseData.licenseKey;
|
|
3371
|
+
}
|
|
3372
|
+
return () => {
|
|
3373
|
+
delete window.__MAGIC_EDITOR_LICENSE_KEY__;
|
|
3374
|
+
};
|
|
3375
|
+
}, [licenseData?.licenseKey]);
|
|
3376
|
+
const [blocksCount, setBlocksCount] = React.useState(0);
|
|
3377
|
+
const [wordCount, setWordCount] = React.useState(0);
|
|
3378
|
+
const [charCount, setCharCount] = React.useState(0);
|
|
3379
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
3380
|
+
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
3381
|
+
const [editorHeight, setEditorHeight] = React.useState(400);
|
|
3382
|
+
const [mediaLibBlockIndex, setMediaLibBlockIndex] = React.useState(-1);
|
|
3383
|
+
const [isMediaLibOpen, setIsMediaLibOpen] = React.useState(false);
|
|
3384
|
+
const [showAIPopup, setShowAIPopup] = React.useState(false);
|
|
3385
|
+
const [showAIToolbar, setShowAIToolbar] = React.useState(false);
|
|
3386
|
+
const [aiToolbarPosition, setAIToolbarPosition] = React.useState({ top: 0, left: 0 });
|
|
3387
|
+
const [aiSelectedText, setAISelectedText] = React.useState("");
|
|
3388
|
+
const aiSelectionRangeRef = React.useRef(null);
|
|
3389
|
+
const [aiLoading, setAILoading] = React.useState(false);
|
|
3390
|
+
const serializedInitialValue = React.useMemo(() => {
|
|
3391
|
+
if (!value) {
|
|
3392
|
+
return "";
|
|
3393
|
+
}
|
|
3394
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
3395
|
+
}, [value]);
|
|
3396
|
+
const serializeForCompare = React.useCallback((payload) => {
|
|
3397
|
+
if (!payload) return "";
|
|
3398
|
+
try {
|
|
3399
|
+
const dataObj = typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
3400
|
+
if (!dataObj || typeof dataObj !== "object") return "";
|
|
3401
|
+
const clone = { ...dataObj };
|
|
3402
|
+
if ("time" in clone) {
|
|
3403
|
+
clone.time = 0;
|
|
3404
|
+
}
|
|
3405
|
+
return JSON.stringify(clone);
|
|
3406
|
+
} catch (err) {
|
|
3407
|
+
console.warn("[Magic Editor X] [COMPARE] Failed to normalize payload", err?.message);
|
|
3408
|
+
return "";
|
|
3409
|
+
}
|
|
3410
|
+
}, []);
|
|
3411
|
+
const collabRoomId = React.useMemo(() => buildRoomId(name), [name]);
|
|
3412
|
+
const collabEnabled = (attribute?.options?.collaboration?.enabled ?? true) && !disabled;
|
|
3413
|
+
const renderFromYDocRef = React.useRef(null);
|
|
3414
|
+
const {
|
|
3415
|
+
doc: yDoc,
|
|
3416
|
+
blocksMap: yBlocksMap,
|
|
3417
|
+
metaMap: yMetaMap,
|
|
3418
|
+
status: collabStatus,
|
|
3419
|
+
error: collabError,
|
|
3420
|
+
peers: collabPeers,
|
|
3421
|
+
awareness: collabAwareness,
|
|
3422
|
+
emitAwareness,
|
|
3423
|
+
collabRole,
|
|
3424
|
+
canEdit: collabCanEdit
|
|
3425
|
+
} = useMagicCollaboration({
|
|
3426
|
+
enabled: collabEnabled,
|
|
3427
|
+
roomId: collabRoomId,
|
|
3428
|
+
fieldName: name,
|
|
3429
|
+
initialValue: serializedInitialValue || "",
|
|
3430
|
+
onRemoteUpdate: () => {
|
|
3431
|
+
console.log("[Magic Editor X] [CALLBACK] onRemoteUpdate callback received");
|
|
3432
|
+
if (renderFromYDocRef.current) {
|
|
3433
|
+
renderFromYDocRef.current();
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
React.useMemo(() => {
|
|
3438
|
+
switch (collabRole) {
|
|
3439
|
+
case "viewer":
|
|
3440
|
+
return { icon: "V", text: "Viewer", color: "#3b82f6" };
|
|
3441
|
+
case "editor":
|
|
3442
|
+
return { icon: "E", text: "Editor", color: "#10b981" };
|
|
3443
|
+
case "owner":
|
|
3444
|
+
return { icon: "O", text: "Owner", color: "#f59e0b" };
|
|
3445
|
+
default:
|
|
3446
|
+
return null;
|
|
3447
|
+
}
|
|
3448
|
+
}, [collabRole]);
|
|
3449
|
+
React.useMemo(() => {
|
|
3450
|
+
switch (collabStatus) {
|
|
3451
|
+
case "connected":
|
|
3452
|
+
if (collabRole === "viewer") {
|
|
3453
|
+
return "Nur Lesen";
|
|
3454
|
+
}
|
|
3455
|
+
if (collabRole === "owner") {
|
|
3456
|
+
return "Live Sync";
|
|
3457
|
+
}
|
|
3458
|
+
return "Live Sync";
|
|
3459
|
+
case "connecting":
|
|
3460
|
+
return "Verbinde...";
|
|
3461
|
+
case "requesting":
|
|
3462
|
+
return "Freigabe pruefen";
|
|
3463
|
+
case "denied":
|
|
3464
|
+
return "Freigabe gesperrt";
|
|
3465
|
+
case "disconnected":
|
|
3466
|
+
return "Neu verbinden";
|
|
3467
|
+
case "disabled":
|
|
3468
|
+
return "Sync aus";
|
|
3469
|
+
default:
|
|
3470
|
+
return "Bereit";
|
|
3471
|
+
}
|
|
3472
|
+
}, [collabStatus, collabRole]);
|
|
3473
|
+
React.useMemo(() => collabPeers.slice(0, 3), [collabPeers]);
|
|
3474
|
+
const activeEditors = React.useMemo(() => {
|
|
3475
|
+
return Object.values(collabAwareness || {}).filter(
|
|
3476
|
+
(entry) => entry?.user && Date.now() - entry.lastUpdate < 3e4
|
|
3477
|
+
);
|
|
3478
|
+
}, [collabAwareness]);
|
|
3479
|
+
const lastCursorUpdateRef = React.useRef(0);
|
|
3480
|
+
const lastEmittedPositionRef = React.useRef(null);
|
|
3481
|
+
const getAbsoluteOffset = React.useCallback((container, node, offset) => {
|
|
3482
|
+
if (!container || !node) return 0;
|
|
3483
|
+
let absoluteOffset = 0;
|
|
3484
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null, false);
|
|
3485
|
+
let currentNode = walker.nextNode();
|
|
3486
|
+
while (currentNode) {
|
|
3487
|
+
if (currentNode === node) {
|
|
3488
|
+
return absoluteOffset + offset;
|
|
3489
|
+
}
|
|
3490
|
+
absoluteOffset += currentNode.textContent?.length || 0;
|
|
3491
|
+
currentNode = walker.nextNode();
|
|
3492
|
+
}
|
|
3493
|
+
return absoluteOffset + offset;
|
|
3494
|
+
}, []);
|
|
3495
|
+
const emitCursorPosition = React.useCallback(() => {
|
|
3496
|
+
if (!collabEnabled || !emitAwareness || collabStatus !== "connected") {
|
|
3497
|
+
return;
|
|
3498
|
+
}
|
|
3499
|
+
const now = Date.now();
|
|
3500
|
+
if (now - lastCursorUpdateRef.current < 200) {
|
|
3501
|
+
return;
|
|
3502
|
+
}
|
|
3503
|
+
if (!editorInstanceRef.current) {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
try {
|
|
3507
|
+
const currentBlockIndex = editorInstanceRef.current.blocks.getCurrentBlockIndex();
|
|
3508
|
+
if (currentBlockIndex < 0) {
|
|
3509
|
+
return;
|
|
3510
|
+
}
|
|
3511
|
+
const currentBlock = editorInstanceRef.current.blocks.getBlockByIndex(currentBlockIndex);
|
|
3512
|
+
const blockId = currentBlock?.id || null;
|
|
3513
|
+
const selection = window.getSelection();
|
|
3514
|
+
let selectionInfo = null;
|
|
3515
|
+
if (selection && selection.rangeCount > 0) {
|
|
3516
|
+
const range = selection.getRangeAt(0);
|
|
3517
|
+
const blocks = editorRef.current?.querySelectorAll(".ce-block");
|
|
3518
|
+
const targetBlock = blocks?.[currentBlockIndex];
|
|
3519
|
+
const contentContainer = targetBlock?.querySelector(
|
|
3520
|
+
'.ce-paragraph, .ce-header, [contenteditable="true"], .cdx-block'
|
|
3521
|
+
);
|
|
3522
|
+
const absoluteStart = contentContainer ? getAbsoluteOffset(contentContainer, range.startContainer, range.startOffset) : range.startOffset;
|
|
3523
|
+
const absoluteEnd = contentContainer ? getAbsoluteOffset(contentContainer, range.endContainer, range.endOffset) : range.endOffset;
|
|
3524
|
+
selectionInfo = {
|
|
3525
|
+
collapsed: selection.isCollapsed,
|
|
3526
|
+
startOffset: absoluteStart,
|
|
3527
|
+
endOffset: absoluteEnd
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
const newPosition = JSON.stringify({ blockIndex: currentBlockIndex, blockId, selection: selectionInfo });
|
|
3531
|
+
if (newPosition === lastEmittedPositionRef.current) {
|
|
3532
|
+
return;
|
|
3533
|
+
}
|
|
3534
|
+
lastCursorUpdateRef.current = now;
|
|
3535
|
+
lastEmittedPositionRef.current = newPosition;
|
|
3536
|
+
emitAwareness({
|
|
3537
|
+
blockIndex: currentBlockIndex,
|
|
3538
|
+
blockId,
|
|
3539
|
+
selection: selectionInfo,
|
|
3540
|
+
timestamp: now
|
|
3541
|
+
});
|
|
3542
|
+
} catch (err) {
|
|
3543
|
+
}
|
|
3544
|
+
}, [collabEnabled, emitAwareness, collabStatus, getAbsoluteOffset]);
|
|
3545
|
+
React.useEffect(() => {
|
|
3546
|
+
if (!collabEnabled || !editorRef.current) {
|
|
3547
|
+
return void 0;
|
|
3548
|
+
}
|
|
3549
|
+
const editorElement = editorRef.current;
|
|
3550
|
+
const handleInteraction = () => {
|
|
3551
|
+
emitCursorPosition();
|
|
3552
|
+
};
|
|
3553
|
+
editorElement.addEventListener("click", handleInteraction);
|
|
3554
|
+
editorElement.addEventListener("keyup", handleInteraction);
|
|
3555
|
+
editorElement.addEventListener("keydown", handleInteraction);
|
|
3556
|
+
editorElement.addEventListener("input", handleInteraction);
|
|
3557
|
+
editorElement.addEventListener("mouseup", handleInteraction);
|
|
3558
|
+
editorElement.addEventListener("selectionchange", handleInteraction);
|
|
3559
|
+
let intervalId = null;
|
|
3560
|
+
const handleFocus = () => {
|
|
3561
|
+
intervalId = setInterval(emitCursorPosition, 1e3);
|
|
3562
|
+
};
|
|
3563
|
+
const handleBlur = () => {
|
|
3564
|
+
if (intervalId) {
|
|
3565
|
+
clearInterval(intervalId);
|
|
3566
|
+
intervalId = null;
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
editorElement.addEventListener("focusin", handleFocus);
|
|
3570
|
+
editorElement.addEventListener("focusout", handleBlur);
|
|
3571
|
+
return () => {
|
|
3572
|
+
editorElement.removeEventListener("click", handleInteraction);
|
|
3573
|
+
editorElement.removeEventListener("keyup", handleInteraction);
|
|
3574
|
+
editorElement.removeEventListener("keydown", handleInteraction);
|
|
3575
|
+
editorElement.removeEventListener("input", handleInteraction);
|
|
3576
|
+
editorElement.removeEventListener("mouseup", handleInteraction);
|
|
3577
|
+
editorElement.removeEventListener("selectionchange", handleInteraction);
|
|
3578
|
+
editorElement.removeEventListener("focusin", handleFocus);
|
|
3579
|
+
editorElement.removeEventListener("focusout", handleBlur);
|
|
3580
|
+
if (intervalId) {
|
|
3581
|
+
clearInterval(intervalId);
|
|
3582
|
+
}
|
|
3583
|
+
};
|
|
3584
|
+
}, [collabEnabled, emitCursorPosition]);
|
|
3585
|
+
const findTextPosition = React.useCallback((container, targetOffset) => {
|
|
3586
|
+
if (!container || targetOffset === null || targetOffset === void 0) {
|
|
3587
|
+
return null;
|
|
3588
|
+
}
|
|
3589
|
+
let currentOffset = 0;
|
|
3590
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null, false);
|
|
3591
|
+
let node = walker.nextNode();
|
|
3592
|
+
while (node) {
|
|
3593
|
+
const nodeLength = node.textContent?.length || 0;
|
|
3594
|
+
if (currentOffset + nodeLength >= targetOffset) {
|
|
3595
|
+
return {
|
|
3596
|
+
node,
|
|
3597
|
+
offset: targetOffset - currentOffset,
|
|
3598
|
+
rect: (() => {
|
|
3599
|
+
try {
|
|
3600
|
+
const range = document.createRange();
|
|
3601
|
+
range.setStart(node, Math.min(targetOffset - currentOffset, nodeLength));
|
|
3602
|
+
range.setEnd(node, Math.min(targetOffset - currentOffset, nodeLength));
|
|
3603
|
+
return range.getBoundingClientRect();
|
|
3604
|
+
} catch {
|
|
3605
|
+
return null;
|
|
3606
|
+
}
|
|
3607
|
+
})()
|
|
3608
|
+
};
|
|
3609
|
+
}
|
|
3610
|
+
currentOffset += nodeLength;
|
|
3611
|
+
node = walker.nextNode();
|
|
3612
|
+
}
|
|
3613
|
+
return null;
|
|
3614
|
+
}, []);
|
|
3615
|
+
React.useRef(null);
|
|
3616
|
+
React.useEffect(() => {
|
|
3617
|
+
if (!collabEnabled || !editorRef.current || !isReady) {
|
|
3618
|
+
return void 0;
|
|
3619
|
+
}
|
|
3620
|
+
const editorElement = editorRef.current;
|
|
3621
|
+
const previousHighlights = editorElement.querySelectorAll(".ce-block--remote-editing");
|
|
3622
|
+
previousHighlights.forEach((el) => {
|
|
3623
|
+
el.classList.remove("ce-block--remote-editing");
|
|
3624
|
+
el.removeAttribute("data-remote-user");
|
|
3625
|
+
el.style.removeProperty("--remote-color");
|
|
3626
|
+
});
|
|
3627
|
+
const previousCursors = editorElement.querySelectorAll(".remote-cursor-indicator");
|
|
3628
|
+
previousCursors.forEach((el) => el.remove());
|
|
3629
|
+
activeEditors.forEach((editor) => {
|
|
3630
|
+
if (editor.blockIndex === null || editor.blockIndex === void 0) {
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
const blocks = editorElement.querySelectorAll(".ce-block");
|
|
3634
|
+
const targetBlock = blocks[editor.blockIndex];
|
|
3635
|
+
if (!targetBlock) {
|
|
3636
|
+
return;
|
|
3637
|
+
}
|
|
3638
|
+
targetBlock.classList.add("ce-block--remote-editing");
|
|
3639
|
+
targetBlock.setAttribute("data-remote-user", getPeerName(editor.user));
|
|
3640
|
+
targetBlock.style.setProperty("--remote-color", editor.color?.bg || "#3B82F6");
|
|
3641
|
+
const contentElement = targetBlock.querySelector(
|
|
3642
|
+
'.ce-paragraph, .ce-header, [contenteditable="true"], .cdx-block'
|
|
3643
|
+
);
|
|
3644
|
+
if (!contentElement) {
|
|
3645
|
+
return;
|
|
3646
|
+
}
|
|
3647
|
+
let position = null;
|
|
3648
|
+
if (editor.selection?.startOffset !== void 0 && editor.selection.startOffset >= 0) {
|
|
3649
|
+
position = findTextPosition(contentElement, editor.selection.startOffset);
|
|
3650
|
+
}
|
|
3651
|
+
const editorRect = editorElement.getBoundingClientRect();
|
|
3652
|
+
const contentRect = contentElement.getBoundingClientRect();
|
|
3653
|
+
let cursorLeft, cursorTop;
|
|
3654
|
+
if (position?.rect && position.rect.width !== void 0) {
|
|
3655
|
+
cursorLeft = position.rect.left - editorRect.left;
|
|
3656
|
+
cursorTop = position.rect.top - editorRect.top;
|
|
3657
|
+
} else {
|
|
3658
|
+
cursorLeft = contentRect.left - editorRect.left;
|
|
3659
|
+
cursorTop = contentRect.top - editorRect.top;
|
|
3660
|
+
}
|
|
3661
|
+
if (isNaN(cursorLeft) || isNaN(cursorTop) || cursorLeft < 0) {
|
|
3662
|
+
cursorLeft = contentRect.left - editorRect.left;
|
|
3663
|
+
cursorTop = contentRect.top - editorRect.top;
|
|
3664
|
+
}
|
|
3665
|
+
const cursorIndicator = document.createElement("div");
|
|
3666
|
+
cursorIndicator.className = "remote-cursor-indicator";
|
|
3667
|
+
cursorIndicator.dataset.userId = editor.user.id;
|
|
3668
|
+
cursorIndicator.style.cssText = `
|
|
3669
|
+
position: absolute;
|
|
3670
|
+
left: ${cursorLeft}px;
|
|
3671
|
+
top: ${cursorTop}px;
|
|
3672
|
+
width: 2px;
|
|
3673
|
+
height: 18px;
|
|
3674
|
+
background: ${editor.color?.bg || "#3B82F6"};
|
|
3675
|
+
border-radius: 1px;
|
|
3676
|
+
pointer-events: none;
|
|
3677
|
+
z-index: 1000;
|
|
3678
|
+
transition: left 0.05s linear, top 0.08s ease-out;
|
|
3679
|
+
box-shadow: 0 0 8px ${editor.color?.bg || "#3B82F6"}60;
|
|
3680
|
+
`;
|
|
3681
|
+
const cursorLabel = document.createElement("div");
|
|
3682
|
+
cursorLabel.className = "remote-cursor-label";
|
|
3683
|
+
cursorLabel.style.cssText = `
|
|
3684
|
+
position: absolute;
|
|
3685
|
+
top: -20px;
|
|
3686
|
+
left: 0;
|
|
3687
|
+
background: ${editor.color?.bg || "#3B82F6"};
|
|
3688
|
+
color: ${editor.color?.text || "#FFFFFF"};
|
|
3689
|
+
font-size: 9px;
|
|
3690
|
+
font-weight: 600;
|
|
3691
|
+
padding: 3px 8px;
|
|
3692
|
+
border-radius: 4px 4px 4px 0;
|
|
3693
|
+
white-space: nowrap;
|
|
3694
|
+
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
|
3695
|
+
display: flex;
|
|
3696
|
+
align-items: center;
|
|
3697
|
+
gap: 4px;
|
|
3698
|
+
`;
|
|
3699
|
+
const nameSpan = document.createElement("span");
|
|
3700
|
+
nameSpan.textContent = getPeerName(editor.user);
|
|
3701
|
+
cursorLabel.appendChild(nameSpan);
|
|
3702
|
+
const typingDots = document.createElement("span");
|
|
3703
|
+
typingDots.className = "typing-indicator";
|
|
3704
|
+
typingDots.innerHTML = `
|
|
3705
|
+
<span class="dot"></span>
|
|
3706
|
+
<span class="dot"></span>
|
|
3707
|
+
<span class="dot"></span>
|
|
3708
|
+
`;
|
|
3709
|
+
typingDots.style.cssText = `
|
|
3710
|
+
display: inline-flex;
|
|
3711
|
+
align-items: center;
|
|
3712
|
+
gap: 2px;
|
|
3713
|
+
margin-left: 2px;
|
|
3714
|
+
`;
|
|
3715
|
+
cursorLabel.appendChild(typingDots);
|
|
3716
|
+
cursorIndicator.appendChild(cursorLabel);
|
|
3717
|
+
requestAnimationFrame(() => {
|
|
3718
|
+
editorElement.appendChild(cursorIndicator);
|
|
3719
|
+
});
|
|
3720
|
+
});
|
|
3721
|
+
return () => {
|
|
3722
|
+
const cursors = editorElement?.querySelectorAll(".remote-cursor-indicator");
|
|
3723
|
+
cursors?.forEach((el) => el.remove());
|
|
3724
|
+
};
|
|
3725
|
+
}, [collabEnabled, activeEditors, isReady, findTextPosition]);
|
|
3726
|
+
React.useEffect(() => {
|
|
3727
|
+
const state = {
|
|
3728
|
+
status: collabStatus,
|
|
3729
|
+
peers: collabPeers,
|
|
3730
|
+
error: collabError
|
|
3731
|
+
};
|
|
3732
|
+
window.__MAGIC_EDITOR_COLLAB_STATE__ = state;
|
|
3733
|
+
window.dispatchEvent(new CustomEvent("magic-editor-collab-update", {
|
|
3734
|
+
detail: state
|
|
3735
|
+
}));
|
|
3736
|
+
return () => {
|
|
3737
|
+
window.__MAGIC_EDITOR_COLLAB_STATE__ = { status: "disabled", peers: [], error: null };
|
|
3738
|
+
window.dispatchEvent(new CustomEvent("magic-editor-collab-update", {
|
|
3739
|
+
detail: { status: "disabled", peers: [], error: null }
|
|
3740
|
+
}));
|
|
3741
|
+
};
|
|
3742
|
+
}, [collabStatus, collabPeers, collabError]);
|
|
3743
|
+
const isApplyingRemoteRef = React.useRef(false);
|
|
3744
|
+
const pendingRenderRef = React.useRef(null);
|
|
3745
|
+
const lastSerializedValueRef = React.useRef(serializeForCompare(serializedInitialValue || null));
|
|
3746
|
+
React.useEffect(() => {
|
|
3747
|
+
lastSerializedValueRef.current = serializeForCompare(serializedInitialValue || null);
|
|
3748
|
+
}, [serializedInitialValue, serializeForCompare]);
|
|
3749
|
+
const calculateStats = React.useCallback((data) => {
|
|
3750
|
+
if (!data?.blocks) {
|
|
3751
|
+
setWordCount(0);
|
|
3752
|
+
setCharCount(0);
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
let text = "";
|
|
3756
|
+
data.blocks.forEach((block) => {
|
|
3757
|
+
if (block.data?.text) text += block.data.text + " ";
|
|
3758
|
+
if (block.data?.items) {
|
|
3759
|
+
block.data.items.forEach((item) => {
|
|
3760
|
+
if (typeof item === "string") text += item + " ";
|
|
3761
|
+
else if (item.content) text += item.content + " ";
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
});
|
|
3765
|
+
const plainText = text.replace(/<[^>]*>/g, "").trim();
|
|
3766
|
+
setCharCount(plainText.length);
|
|
3767
|
+
setWordCount(plainText.split(/\s+/).filter((w) => w.length > 0).length);
|
|
3768
|
+
}, []);
|
|
3769
|
+
const renderFromYDoc = React.useCallback(async () => {
|
|
3770
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:entry", message: "renderFromYDoc called", data: { collabEnabled, hasYBlocksMap: !!yBlocksMap, hasYDoc: !!yDoc, hasYMetaMap: !!yMetaMap }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "A" }) }).catch(() => {
|
|
3771
|
+
});
|
|
3772
|
+
if (!collabEnabled || !yBlocksMap || !yDoc) {
|
|
3773
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:guard1", message: "EARLY EXIT: missing collab deps", data: { collabEnabled, hasYBlocksMap: !!yBlocksMap, hasYDoc: !!yDoc }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "A" }) }).catch(() => {
|
|
3774
|
+
});
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
const editor = editorInstanceRef.current;
|
|
3778
|
+
if (!editor || !isReadyRef.current) {
|
|
3779
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:guard2", message: "EARLY EXIT: editor not ready", data: { hasEditor: !!editor, isReady: isReadyRef.current }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "D" }) }).catch(() => {
|
|
3780
|
+
});
|
|
3781
|
+
pendingRenderRef.current = pendingRenderRef.current || true;
|
|
3782
|
+
return;
|
|
3783
|
+
}
|
|
3784
|
+
if (isApplyingRemoteRef.current) {
|
|
3785
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:guard3", message: "EARLY EXIT: isApplyingRemote is true (race condition)", data: { isApplyingRemote: true }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "B" }) }).catch(() => {
|
|
3786
|
+
});
|
|
3787
|
+
return;
|
|
3788
|
+
}
|
|
3789
|
+
isApplyingRemoteRef.current = true;
|
|
3790
|
+
try {
|
|
3791
|
+
let yOrder = [];
|
|
3792
|
+
const blockOrderJson = yMetaMap?.get("blockOrder");
|
|
3793
|
+
if (blockOrderJson) {
|
|
3794
|
+
try {
|
|
3795
|
+
yOrder = JSON.parse(blockOrderJson);
|
|
3796
|
+
} catch (e) {
|
|
3797
|
+
console.warn("[Magic Editor X] Invalid blockOrder JSON, falling back to Map keys");
|
|
3798
|
+
yOrder = Array.from(yBlocksMap.keys());
|
|
3799
|
+
}
|
|
3800
|
+
} else {
|
|
3801
|
+
yOrder = Array.from(yBlocksMap.keys());
|
|
3802
|
+
}
|
|
3803
|
+
const yBlocks = [];
|
|
3804
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:yState", message: "Y.js state before parsing", data: { blockOrderFromMeta: !!blockOrderJson, yBlocksMapSize: yBlocksMap?.size, yOrder, yBlocksMapKeys: Array.from(yBlocksMap?.keys() || []) }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "C" }) }).catch(() => {
|
|
3805
|
+
});
|
|
3806
|
+
yOrder.forEach((id) => {
|
|
3807
|
+
const json = yBlocksMap.get(id);
|
|
3808
|
+
if (json) {
|
|
3809
|
+
try {
|
|
3810
|
+
const block = JSON.parse(json);
|
|
3811
|
+
yBlocks.push(block);
|
|
3812
|
+
} catch (e) {
|
|
3813
|
+
console.warn("[Magic Editor X] Invalid block JSON:", id);
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
});
|
|
3817
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:parsed", message: "Parsed yBlocks from Y.Map", data: { yBlocksCount: yBlocks.length, yBlockIds: yBlocks.map((b) => b.id), yBlockTypes: yBlocks.map((b) => b.type) }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "A" }) }).catch(() => {
|
|
3818
|
+
});
|
|
3819
|
+
const parsed = { blocks: yBlocks };
|
|
3820
|
+
const normalizedParsed = serializeForCompare(parsed);
|
|
3821
|
+
const renderFull = async () => {
|
|
3822
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFull:start", message: "FULL RENDER triggered", data: { blocksToRender: yBlocks.length, blockIds: yBlocks.map((b) => b.id) }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "E" }) }).catch(() => {
|
|
3823
|
+
});
|
|
3824
|
+
await editor.render(parsed);
|
|
3825
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFull:done", message: "FULL RENDER completed", data: { newBlockCount: editor.blocks.getBlocksCount() }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "E" }) }).catch(() => {
|
|
3826
|
+
});
|
|
3827
|
+
lastSerializedValueRef.current = normalizedParsed;
|
|
3828
|
+
setBlocksCount(yBlocks.length);
|
|
3829
|
+
calculateStats(parsed);
|
|
3830
|
+
};
|
|
3831
|
+
const blockCount = editor.blocks.getBlocksCount();
|
|
3832
|
+
const currentBlocks = [];
|
|
3833
|
+
for (let i = 0; i < blockCount; i++) {
|
|
3834
|
+
const block = editor.blocks.getBlockByIndex(i);
|
|
3835
|
+
if (block) {
|
|
3836
|
+
currentBlocks.push({ id: block.id, index: i });
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
fetch("http://127.0.0.1:7242/ingest/12c1170b-f275-4a73-9ee7-3006bf7f0881", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ location: "EditorJS/index.jsx:renderFromYDoc:comparison", message: "Comparing editor vs Y.js state", data: { editorBlockCount: blockCount, yBlocksCount: yBlocks.length, editorBlockIds: currentBlocks.map((b) => b.id), yBlockIds: yBlocks.map((b) => b.id) }, timestamp: Date.now(), sessionId: "debug-session", hypothesisId: "E" }) }).catch(() => {
|
|
3840
|
+
});
|
|
3841
|
+
if (blockCount !== yBlocks.length) {
|
|
3842
|
+
console.log("[Magic Editor X] [SYNC] Structural change detected (count mismatch). Falling back to full render.");
|
|
3843
|
+
await renderFull();
|
|
3844
|
+
return;
|
|
3845
|
+
}
|
|
3846
|
+
const targetIds = yBlocks.map((b) => b.id);
|
|
3847
|
+
const orderMatches = targetIds.every((id, idx) => currentBlocks[idx]?.id === id);
|
|
3848
|
+
const allIdsPresent = targetIds.every((id) => yBlocksMap.has(id));
|
|
3849
|
+
if (!orderMatches || !allIdsPresent) {
|
|
3850
|
+
console.log("[Magic Editor X] [SYNC] Order mismatch detected. Falling back to full render.");
|
|
3851
|
+
await renderFull();
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
const activeBlockIndex = editor.blocks.getCurrentBlockIndex();
|
|
3855
|
+
for (let i = 0; i < yBlocks.length; i++) {
|
|
3856
|
+
const targetBlock = yBlocks[i];
|
|
3857
|
+
const currentBlock = editor.blocks.getBlockByIndex(i);
|
|
3858
|
+
if (!currentBlock || currentBlock.id !== targetBlock.id) {
|
|
3859
|
+
console.log("[Magic Editor X] [SYNC] Unexpected block mismatch during update, rerendering.");
|
|
3860
|
+
await renderFull();
|
|
3861
|
+
return;
|
|
3862
|
+
}
|
|
3863
|
+
if (activeBlockIndex === i) {
|
|
3864
|
+
continue;
|
|
3865
|
+
}
|
|
3866
|
+
try {
|
|
3867
|
+
editor.blocks.update(targetBlock.id, targetBlock.data);
|
|
3868
|
+
} catch (e) {
|
|
3869
|
+
console.warn("[Magic Editor X] [SYNC] Block update failed, rerendering:", targetBlock.id, e);
|
|
3870
|
+
await renderFull();
|
|
3871
|
+
return;
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
lastSerializedValueRef.current = normalizedParsed;
|
|
3875
|
+
setBlocksCount(yBlocks.length);
|
|
3876
|
+
calculateStats(parsed);
|
|
3877
|
+
} catch (error2) {
|
|
3878
|
+
console.error("[Magic Editor X] [SYNC] Error in smart sync:", error2);
|
|
3879
|
+
} finally {
|
|
3880
|
+
isApplyingRemoteRef.current = false;
|
|
3881
|
+
}
|
|
3882
|
+
}, [collabEnabled, yBlocksMap, yDoc, yMetaMap]);
|
|
3883
|
+
React.useEffect(() => {
|
|
3884
|
+
renderFromYDocRef.current = renderFromYDoc;
|
|
3885
|
+
}, [renderFromYDoc]);
|
|
3886
|
+
const pushLocalToCollab = React.useCallback((payload) => {
|
|
3887
|
+
console.log("[Magic Editor X] [PUSH] pushLocalToCollab called, enabled:", collabEnabled, "yDoc:", !!yDoc, "yBlocksMap:", !!yBlocksMap);
|
|
3888
|
+
if (!collabEnabled || !yDoc || !yBlocksMap) {
|
|
3889
|
+
console.log("[Magic Editor X] [SKIP] Skipping push - not enabled or missing yDoc/yBlocksMap");
|
|
3890
|
+
return;
|
|
3891
|
+
}
|
|
3892
|
+
try {
|
|
3893
|
+
const data = JSON.parse(payload);
|
|
3894
|
+
const blocks = data?.blocks || [];
|
|
3895
|
+
const time = data?.time || Date.now();
|
|
3896
|
+
console.log("[Magic Editor X] [DOC] Pushing", blocks.length, "blocks to Y.Map");
|
|
3897
|
+
yDoc.transact(() => {
|
|
3898
|
+
const uniqueBlocks = [];
|
|
3899
|
+
const currentBlockIds = /* @__PURE__ */ new Set();
|
|
3900
|
+
for (const block of blocks) {
|
|
3901
|
+
if (!block?.id) {
|
|
3902
|
+
console.warn("[Magic Editor X] [WARNING] Block without ID, skipping");
|
|
3903
|
+
continue;
|
|
3904
|
+
}
|
|
3905
|
+
if (currentBlockIds.has(block.id)) {
|
|
3906
|
+
console.warn("[Magic Editor X] [WARNING] Duplicate block ID detected, keeping first occurrence:", block.id);
|
|
3907
|
+
continue;
|
|
3908
|
+
}
|
|
3909
|
+
currentBlockIds.add(block.id);
|
|
3910
|
+
uniqueBlocks.push(block);
|
|
3911
|
+
}
|
|
3912
|
+
for (const block of uniqueBlocks) {
|
|
3913
|
+
const blockJson = JSON.stringify(block);
|
|
3914
|
+
const existing = yBlocksMap.get(block.id);
|
|
3915
|
+
if (existing !== blockJson) {
|
|
3916
|
+
yBlocksMap.set(block.id, blockJson);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
if (yMetaMap) {
|
|
3920
|
+
yMetaMap.set("time", time);
|
|
3921
|
+
const newOrder = uniqueBlocks.map((b) => b.id);
|
|
3922
|
+
yMetaMap.set("blockOrder", JSON.stringify(newOrder));
|
|
3923
|
+
console.log("[Magic Editor X] [ORDER] Updated block order in Y.Map:", newOrder.length, "blocks");
|
|
3924
|
+
}
|
|
3925
|
+
}, "local");
|
|
3926
|
+
console.log("[Magic Editor X] [SUCCESS] Successfully pushed", blocks.length, "blocks to Y.Map");
|
|
3927
|
+
} catch (error2) {
|
|
3928
|
+
console.error("[Magic Editor X] Failed to push local update", error2);
|
|
3929
|
+
}
|
|
3930
|
+
}, [collabEnabled, yDoc, yBlocksMap, yMetaMap]);
|
|
3931
|
+
const pushLocalToCollabRef = React.useRef(pushLocalToCollab);
|
|
3932
|
+
React.useEffect(() => {
|
|
3933
|
+
pushLocalToCollabRef.current = pushLocalToCollab;
|
|
3934
|
+
}, [pushLocalToCollab]);
|
|
3935
|
+
const customPlaceholder = attribute?.options?.placeholder || placeholder || "Start writing your amazing content...";
|
|
3936
|
+
attribute?.options?.minHeight || 400;
|
|
3937
|
+
const mediaLibToggleFunc = React.useCallback(
|
|
3938
|
+
getToggleFunc({
|
|
3939
|
+
openStateSetter: setIsMediaLibOpen,
|
|
3940
|
+
indexStateSetter: setMediaLibBlockIndex
|
|
3941
|
+
}),
|
|
3942
|
+
[]
|
|
3943
|
+
);
|
|
3944
|
+
const handleMediaLibChange = React.useCallback(
|
|
3945
|
+
(data) => {
|
|
3946
|
+
changeFunc({
|
|
3947
|
+
indexStateSetter: setMediaLibBlockIndex,
|
|
3948
|
+
data,
|
|
3949
|
+
index: mediaLibBlockIndex,
|
|
3950
|
+
editor: editorInstanceRef.current
|
|
3951
|
+
});
|
|
3952
|
+
mediaLibToggleFunc();
|
|
3953
|
+
},
|
|
3954
|
+
[mediaLibBlockIndex, mediaLibToggleFunc]
|
|
3955
|
+
);
|
|
3956
|
+
const toggleFullscreen = React.useCallback(() => {
|
|
3957
|
+
setIsFullscreen((prev) => {
|
|
3958
|
+
if (!prev) {
|
|
3959
|
+
document.body.classList.add("editor-fullscreen");
|
|
3960
|
+
} else {
|
|
3961
|
+
document.body.classList.remove("editor-fullscreen");
|
|
3962
|
+
}
|
|
3963
|
+
return !prev;
|
|
3964
|
+
});
|
|
3965
|
+
}, []);
|
|
3966
|
+
React.useEffect(() => {
|
|
3967
|
+
const handleKeyDown = (e) => {
|
|
3968
|
+
if (e.key === "Escape" && isFullscreen) {
|
|
3969
|
+
toggleFullscreen();
|
|
3970
|
+
}
|
|
3971
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
3972
|
+
toggleFullscreen();
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
3976
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3977
|
+
}, [isFullscreen, toggleFullscreen]);
|
|
3978
|
+
const handleAIAssistant = React.useCallback(() => {
|
|
3979
|
+
const selection = window.getSelection();
|
|
3980
|
+
let text = selection?.toString().trim();
|
|
3981
|
+
if (!text && editorInstanceRef.current && isReady) {
|
|
3982
|
+
const currentBlockIndex = editorInstanceRef.current.blocks.getCurrentBlockIndex();
|
|
3983
|
+
const currentBlock = editorInstanceRef.current.blocks.getBlockByIndex(currentBlockIndex);
|
|
3984
|
+
if (currentBlock) {
|
|
3985
|
+
const blockElement = currentBlock.holder?.querySelector("[contenteditable]") || currentBlock.holder?.querySelector(".ce-paragraph") || currentBlock.holder?.querySelector(".ce-header");
|
|
3986
|
+
if (blockElement) {
|
|
3987
|
+
text = blockElement.textContent?.trim() || "";
|
|
3988
|
+
if (text) {
|
|
3989
|
+
const range = document.createRange();
|
|
3990
|
+
range.selectNodeContents(blockElement);
|
|
3991
|
+
selection.removeAllRanges();
|
|
3992
|
+
selection.addRange(range);
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
if (!text) {
|
|
3998
|
+
tools.toastManager.warning("Bitte Text markieren");
|
|
3999
|
+
return;
|
|
4000
|
+
}
|
|
4001
|
+
if (selection.rangeCount > 0) {
|
|
4002
|
+
aiSelectionRangeRef.current = selection.getRangeAt(0).cloneRange();
|
|
4003
|
+
const rect = selection.getRangeAt(0).getBoundingClientRect();
|
|
4004
|
+
const toolbarWidth = 450;
|
|
4005
|
+
let left = rect.left + rect.width / 2 - toolbarWidth / 2;
|
|
4006
|
+
let top = rect.bottom + 10;
|
|
4007
|
+
if (left < 10) left = 10;
|
|
4008
|
+
if (left + toolbarWidth > window.innerWidth - 10) {
|
|
4009
|
+
left = window.innerWidth - toolbarWidth - 10;
|
|
4010
|
+
}
|
|
4011
|
+
if (top + 60 > window.innerHeight) {
|
|
4012
|
+
top = rect.top - 60;
|
|
4013
|
+
}
|
|
4014
|
+
setAIToolbarPosition({ left, top });
|
|
4015
|
+
}
|
|
4016
|
+
setAISelectedText(text);
|
|
4017
|
+
setShowAIToolbar(true);
|
|
4018
|
+
}, [isReady]);
|
|
4019
|
+
const handleInsertBlock = React.useCallback((blockType) => {
|
|
4020
|
+
if (!editorInstanceRef.current || !isReady) return;
|
|
4021
|
+
if (blockType === "mediaLib") {
|
|
4022
|
+
if (collabEnabled && collabCanEdit === false) {
|
|
4023
|
+
console.log("[Magic Editor X] Viewer cannot open Media Library");
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
setIsMediaLibOpen(true);
|
|
4027
|
+
return;
|
|
4028
|
+
}
|
|
4029
|
+
if (collabEnabled && collabCanEdit === false) {
|
|
4030
|
+
console.log("[Magic Editor X] Viewer cannot insert blocks");
|
|
4031
|
+
return;
|
|
4032
|
+
}
|
|
4033
|
+
const editor = editorInstanceRef.current;
|
|
4034
|
+
const lastIndex = editor.blocks.getBlocksCount();
|
|
4035
|
+
editor.blocks.insert(blockType, {}, {}, lastIndex, true);
|
|
4036
|
+
editor.caret.setToBlock(lastIndex);
|
|
4037
|
+
}, [isReady, collabEnabled, collabCanEdit]);
|
|
4038
|
+
const handleClear = React.useCallback(async () => {
|
|
4039
|
+
if (!editorInstanceRef.current || !isReady) return;
|
|
4040
|
+
if (window.confirm("Clear all content? This cannot be undone.")) {
|
|
4041
|
+
await editorInstanceRef.current.clear();
|
|
4042
|
+
const emptyPayload = JSON.stringify({ blocks: [] });
|
|
4043
|
+
lastSerializedValueRef.current = emptyPayload;
|
|
4044
|
+
pushLocalToCollab(emptyPayload);
|
|
4045
|
+
onChange({ target: { name, value: null, type: "text" } });
|
|
4046
|
+
setBlocksCount(0);
|
|
4047
|
+
setWordCount(0);
|
|
4048
|
+
setCharCount(0);
|
|
4049
|
+
}
|
|
4050
|
+
}, [isReady, name, onChange, pushLocalToCollab]);
|
|
4051
|
+
const handleCopy = React.useCallback(async () => {
|
|
4052
|
+
if (!editorInstanceRef.current || !isReady) return;
|
|
4053
|
+
const data = await editorInstanceRef.current.save();
|
|
4054
|
+
await navigator.clipboard.writeText(JSON.stringify(data, null, 2));
|
|
4055
|
+
}, [isReady]);
|
|
4056
|
+
React.useEffect(() => {
|
|
4057
|
+
if (editorRef.current && !editorInstanceRef.current) {
|
|
4058
|
+
const tools$1 = tools.getTools({ mediaLibToggleFunc, pluginId: index.PLUGIN_ID });
|
|
4059
|
+
let initialData = void 0;
|
|
4060
|
+
if (value) {
|
|
4061
|
+
try {
|
|
4062
|
+
initialData = typeof value === "string" ? JSON.parse(value) : value;
|
|
4063
|
+
setBlocksCount(initialData?.blocks?.length || 0);
|
|
4064
|
+
calculateStats(initialData);
|
|
4065
|
+
} catch (e) {
|
|
4066
|
+
console.warn("[Magic Editor X] Could not parse initial value:", e);
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
const isReadOnly = disabled || collabEnabled && collabCanEdit === false;
|
|
4070
|
+
console.log("[Magic Editor X] [INIT] Initial readOnly:", isReadOnly, "| collabCanEdit:", collabCanEdit);
|
|
4071
|
+
if (isReadOnly && collabEnabled && !disabled) {
|
|
4072
|
+
console.log("[Magic Editor X] [VIEWER] Viewer mode - editor is read-only");
|
|
4073
|
+
if (editorRef.current) {
|
|
4074
|
+
editorRef.current.classList.add("editor-readonly");
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
const editor = new EditorJS__default.default({
|
|
4078
|
+
holder: editorRef.current,
|
|
4079
|
+
tools: tools$1,
|
|
4080
|
+
data: initialData,
|
|
4081
|
+
readOnly: isReadOnly,
|
|
4082
|
+
placeholder: customPlaceholder,
|
|
4083
|
+
minHeight: 200,
|
|
4084
|
+
autofocus: false,
|
|
4085
|
+
onReady: async () => {
|
|
4086
|
+
isReadyRef.current = true;
|
|
4087
|
+
setIsReady(true);
|
|
4088
|
+
console.log("[Magic Editor X] [READY] Editor onReady fired");
|
|
4089
|
+
console.log("[Magic Editor X] [READY] Editor holder:", editorRef.current?.id);
|
|
4090
|
+
try {
|
|
4091
|
+
tools.initUndoRedo(editor);
|
|
4092
|
+
console.log("[Magic Editor X] [SUCCESS] Undo/Redo initialized");
|
|
4093
|
+
} catch (e) {
|
|
4094
|
+
console.warn("[Magic Editor X] Could not initialize Undo/Redo:", e);
|
|
4095
|
+
}
|
|
4096
|
+
try {
|
|
4097
|
+
tools.initDragDrop(editor);
|
|
4098
|
+
console.log("[Magic Editor X] [SUCCESS] Drag & Drop initialized");
|
|
4099
|
+
} catch (e) {
|
|
4100
|
+
console.warn("[Magic Editor X] Could not initialize Drag & Drop:", e);
|
|
4101
|
+
}
|
|
4102
|
+
if (pendingRenderRef.current) {
|
|
4103
|
+
try {
|
|
4104
|
+
if (typeof pendingRenderRef.current === "object" && pendingRenderRef.current.blocks) {
|
|
4105
|
+
console.log("[Magic Editor X] [PENDING] Rendering pending data with", pendingRenderRef.current?.blocks?.length, "blocks");
|
|
4106
|
+
isApplyingRemoteRef.current = true;
|
|
4107
|
+
try {
|
|
4108
|
+
await editor.render(pendingRenderRef.current);
|
|
4109
|
+
lastSerializedValueRef.current = serializeForCompare(pendingRenderRef.current);
|
|
4110
|
+
console.log("[Magic Editor X] [SUCCESS] Rendered pending blocks on ready");
|
|
4111
|
+
} finally {
|
|
4112
|
+
isApplyingRemoteRef.current = false;
|
|
4113
|
+
}
|
|
4114
|
+
} else {
|
|
4115
|
+
console.log("[Magic Editor X] [PENDING] Triggering queued sync after onReady");
|
|
4116
|
+
await renderFromYDocRef.current?.();
|
|
4117
|
+
}
|
|
4118
|
+
} catch (err) {
|
|
4119
|
+
console.error("[Magic Editor X] Error applying pending sync:", err);
|
|
4120
|
+
isApplyingRemoteRef.current = false;
|
|
4121
|
+
}
|
|
4122
|
+
pendingRenderRef.current = null;
|
|
4123
|
+
}
|
|
4124
|
+
},
|
|
4125
|
+
onChange: async (api) => {
|
|
4126
|
+
try {
|
|
4127
|
+
if (isApplyingRemoteRef.current) {
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
const outputData = await api.saver.save();
|
|
4131
|
+
const count = outputData.blocks?.length || 0;
|
|
4132
|
+
const serialized = JSON.stringify(outputData);
|
|
4133
|
+
const normalized = serializeForCompare(outputData);
|
|
4134
|
+
if (normalized === lastSerializedValueRef.current) {
|
|
4135
|
+
return;
|
|
4136
|
+
}
|
|
4137
|
+
setBlocksCount(count);
|
|
4138
|
+
calculateStats(outputData);
|
|
4139
|
+
const docPayload = count === 0 ? JSON.stringify({ blocks: [] }) : serialized;
|
|
4140
|
+
pushLocalToCollabRef.current?.(docPayload);
|
|
4141
|
+
lastSerializedValueRef.current = normalized;
|
|
4142
|
+
if (count === 0) {
|
|
4143
|
+
onChange({ target: { name, value: null, type: "text" } });
|
|
4144
|
+
} else {
|
|
4145
|
+
onChange({ target: { name, value: serialized, type: "text" } });
|
|
4146
|
+
}
|
|
4147
|
+
} catch (error2) {
|
|
4148
|
+
console.error("[Magic Editor X] Error in onChange:", error2);
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
});
|
|
4152
|
+
editorInstanceRef.current = editor;
|
|
4153
|
+
}
|
|
4154
|
+
return () => {
|
|
4155
|
+
console.log("[Magic Editor X] [CLEANUP] Editor component unmounting, destroying editor");
|
|
4156
|
+
isReadyRef.current = false;
|
|
4157
|
+
setIsReady(false);
|
|
4158
|
+
if (editorInstanceRef.current && editorInstanceRef.current.destroy) {
|
|
4159
|
+
try {
|
|
4160
|
+
editorInstanceRef.current.destroy();
|
|
4161
|
+
} catch (e) {
|
|
4162
|
+
console.warn("[Magic Editor X] Error destroying editor:", e);
|
|
4163
|
+
}
|
|
4164
|
+
editorInstanceRef.current = null;
|
|
4165
|
+
}
|
|
4166
|
+
document.body.classList.remove("editor-fullscreen");
|
|
4167
|
+
};
|
|
4168
|
+
}, []);
|
|
4169
|
+
React.useEffect(() => {
|
|
4170
|
+
const editor = editorInstanceRef.current;
|
|
4171
|
+
if (!editor || !isReady) return;
|
|
4172
|
+
const shouldBeReadOnly = disabled || collabEnabled && collabCanEdit === false;
|
|
4173
|
+
console.log("[Magic Editor X] [READONLY] ReadOnly check:", {
|
|
4174
|
+
disabled,
|
|
4175
|
+
collabEnabled,
|
|
4176
|
+
collabCanEdit,
|
|
4177
|
+
collabRole,
|
|
4178
|
+
shouldBeReadOnly
|
|
4179
|
+
});
|
|
4180
|
+
if (typeof editor.readOnly?.toggle === "function") {
|
|
4181
|
+
const currentReadOnly = editor.readOnly?.isEnabled;
|
|
4182
|
+
if (currentReadOnly !== shouldBeReadOnly) {
|
|
4183
|
+
console.log("[Magic Editor X] [TOGGLE] Toggling readOnly:", shouldBeReadOnly, "| Role:", collabRole);
|
|
4184
|
+
editor.readOnly.toggle(shouldBeReadOnly);
|
|
4185
|
+
if (editorRef.current) {
|
|
4186
|
+
if (shouldBeReadOnly) {
|
|
4187
|
+
editorRef.current.classList.add("editor-readonly");
|
|
4188
|
+
} else {
|
|
4189
|
+
editorRef.current.classList.remove("editor-readonly");
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
}, [disabled, collabEnabled, collabCanEdit, collabRole, isReady]);
|
|
4195
|
+
const quickActions = [
|
|
4196
|
+
{ icon: outline.Bars3BottomLeftIcon, label: "Heading", block: "header" },
|
|
4197
|
+
{ icon: outline.ListBulletIcon, label: "List", block: "list" },
|
|
4198
|
+
{ icon: outline.CheckCircleIcon, label: "Checklist", block: "checklist" },
|
|
4199
|
+
{ icon: outline.PhotoIcon, label: "Image", block: "image" },
|
|
4200
|
+
{ icon: outline.LinkIcon, label: "Link", block: "linkTool" },
|
|
4201
|
+
{ icon: outline.CodeBracketIcon, label: "Code", block: "code" },
|
|
4202
|
+
{ icon: outline.TableCellsIcon, label: "Table", block: "table" },
|
|
4203
|
+
{ icon: outline.ChatBubbleBottomCenterTextIcon, label: "Quote", block: "quote" },
|
|
4204
|
+
{ icon: outline.ExclamationTriangleIcon, label: "Warning", block: "warning" },
|
|
4205
|
+
{ icon: outline.MinusIcon, label: "Divider", block: "delimiter" }
|
|
4206
|
+
];
|
|
4207
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(getTranslation.Field.Root, { name, id: name, error, required, hint, children: [
|
|
4208
|
+
/* @__PURE__ */ jsxRuntime.jsx(FullscreenGlobalStyle, {}),
|
|
4209
|
+
/* @__PURE__ */ jsxRuntime.jsx(EditorJSGlobalStyles, {}),
|
|
4210
|
+
/* @__PURE__ */ jsxRuntime.jsx(tools.AIToast, {}),
|
|
4211
|
+
label && !isFullscreen && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.Field.Label, { action: labelAction, children: label }),
|
|
4212
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4213
|
+
EditorContainer,
|
|
4214
|
+
{
|
|
4215
|
+
ref: containerRef,
|
|
4216
|
+
$isFullscreen: isFullscreen,
|
|
4217
|
+
$minHeight: editorHeight,
|
|
4218
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4219
|
+
EditorCard,
|
|
4220
|
+
{
|
|
4221
|
+
$isFocused: isFocused,
|
|
4222
|
+
$hasError: !!error,
|
|
4223
|
+
$disabled: disabled,
|
|
4224
|
+
$isFullscreen: isFullscreen,
|
|
4225
|
+
$minHeight: editorHeight,
|
|
4226
|
+
children: [
|
|
4227
|
+
/* @__PURE__ */ jsxRuntime.jsxs(EditorHeader, { children: [
|
|
4228
|
+
/* @__PURE__ */ jsxRuntime.jsxs(HeaderLeft, { children: [
|
|
4229
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Logo, { children: [
|
|
4230
|
+
/* @__PURE__ */ jsxRuntime.jsx(outline.SparklesIcon, {}),
|
|
4231
|
+
/* @__PURE__ */ jsxRuntime.jsx(LogoText, { children: "Magic Editor" })
|
|
4232
|
+
] }),
|
|
4233
|
+
isReady && blocksCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs(BlockCount, { children: [
|
|
4234
|
+
blocksCount,
|
|
4235
|
+
" ",
|
|
4236
|
+
blocksCount === 1 ? "Block" : "Blocks"
|
|
4237
|
+
] })
|
|
4238
|
+
] }),
|
|
4239
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Toolbar, { children: [
|
|
4240
|
+
/* @__PURE__ */ jsxRuntime.jsx(QuickActions, { children: quickActions.map(({ icon: Icon2, label: label2, block }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4241
|
+
ToolButton,
|
|
4242
|
+
{
|
|
4243
|
+
type: "button",
|
|
4244
|
+
"data-tooltip": label2,
|
|
4245
|
+
onClick: () => handleInsertBlock(block),
|
|
4246
|
+
disabled: collabEnabled && collabCanEdit === false,
|
|
4247
|
+
style: collabEnabled && collabCanEdit === false ? { opacity: 0.4, cursor: "not-allowed" } : {},
|
|
4248
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon2, {})
|
|
4249
|
+
},
|
|
4250
|
+
block
|
|
4251
|
+
)) }),
|
|
4252
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToolbarDivider, {}),
|
|
4253
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4254
|
+
ToolButton,
|
|
4255
|
+
{
|
|
4256
|
+
type: "button",
|
|
4257
|
+
"data-tooltip": "KI-Assistent (Text markieren)",
|
|
4258
|
+
onClick: handleAIAssistant,
|
|
4259
|
+
disabled: collabEnabled && collabCanEdit === false,
|
|
4260
|
+
style: {
|
|
4261
|
+
background: "linear-gradient(135deg, #7C3AED 0%, #6d28d9 100%)",
|
|
4262
|
+
color: "white",
|
|
4263
|
+
...collabEnabled && collabCanEdit === false ? { opacity: 0.4, cursor: "not-allowed" } : {}
|
|
4264
|
+
},
|
|
4265
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(outline.SparklesIcon, {})
|
|
4266
|
+
}
|
|
4267
|
+
),
|
|
4268
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToolbarDivider, {}),
|
|
4269
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4270
|
+
ToolButton,
|
|
4271
|
+
{
|
|
4272
|
+
type: "button",
|
|
4273
|
+
"data-tooltip": "Copy JSON",
|
|
4274
|
+
onClick: handleCopy,
|
|
4275
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(outline.DocumentDuplicateIcon, {})
|
|
4276
|
+
}
|
|
4277
|
+
),
|
|
4278
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4279
|
+
ToolButton,
|
|
4280
|
+
{
|
|
4281
|
+
type: "button",
|
|
4282
|
+
"data-tooltip": "Clear All",
|
|
4283
|
+
onClick: handleClear,
|
|
4284
|
+
disabled: collabEnabled && collabCanEdit === false,
|
|
4285
|
+
style: collabEnabled && collabCanEdit === false ? { opacity: 0.4, cursor: "not-allowed" } : {},
|
|
4286
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(outline.TrashIcon, {})
|
|
4287
|
+
}
|
|
4288
|
+
),
|
|
4289
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToolbarDivider, {}),
|
|
4290
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4291
|
+
ToolButton,
|
|
4292
|
+
{
|
|
4293
|
+
type: "button",
|
|
4294
|
+
$active: isFullscreen,
|
|
4295
|
+
"data-tooltip": isFullscreen ? "Exit Fullscreen (Esc)" : "Fullscreen (⌘+Enter)",
|
|
4296
|
+
onClick: toggleFullscreen,
|
|
4297
|
+
children: isFullscreen ? /* @__PURE__ */ jsxRuntime.jsx(outline.ArrowsPointingInIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(outline.ArrowsPointingOutIcon, {})
|
|
4298
|
+
}
|
|
4299
|
+
)
|
|
4300
|
+
] })
|
|
4301
|
+
] }),
|
|
4302
|
+
collabError && collabEnabled && /* @__PURE__ */ jsxRuntime.jsx(CollabNotice, { children: collabError }),
|
|
4303
|
+
collabEnabled && collabStatus === "connected" && collabRole === "viewer" && /* @__PURE__ */ jsxRuntime.jsxs(ViewerBanner, { children: [
|
|
4304
|
+
/* @__PURE__ */ jsxRuntime.jsx(outline.EyeIcon, {}),
|
|
4305
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Nur-Lesen Modus" }),
|
|
4306
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "• Du kannst den Inhalt sehen, aber nicht bearbeiten" })
|
|
4307
|
+
] }),
|
|
4308
|
+
collabEnabled && collabStatus === "connected" && activeEditors.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(ActiveEditorsBar, { children: [
|
|
4309
|
+
/* @__PURE__ */ jsxRuntime.jsx(ActiveEditorsLabel, { children: "Aktive Bearbeiter:" }),
|
|
4310
|
+
activeEditors.map((editor) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4311
|
+
ActiveEditorBadge,
|
|
4312
|
+
{
|
|
4313
|
+
$color: editor.color?.bg,
|
|
4314
|
+
title: `${getPeerName(editor.user)} bearbeitet Block ${editor.blockIndex !== null ? editor.blockIndex + 1 : "?"}`,
|
|
4315
|
+
children: [
|
|
4316
|
+
/* @__PURE__ */ jsxRuntime.jsx(ActiveEditorDot, { $color: editor.color?.bg }),
|
|
4317
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: getPeerName(editor.user) }),
|
|
4318
|
+
editor.blockIndex !== null && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { opacity: 0.6, fontSize: "10px" }, children: [
|
|
4319
|
+
"Block ",
|
|
4320
|
+
editor.blockIndex + 1
|
|
4321
|
+
] })
|
|
4322
|
+
]
|
|
4323
|
+
},
|
|
4324
|
+
editor.user.id
|
|
4325
|
+
))
|
|
4326
|
+
] }),
|
|
4327
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4328
|
+
EditorContent,
|
|
4329
|
+
{
|
|
4330
|
+
$isFullscreen: isFullscreen,
|
|
4331
|
+
onFocus: () => setIsFocused(true),
|
|
4332
|
+
onBlur: () => setIsFocused(false),
|
|
4333
|
+
children: [
|
|
4334
|
+
!isReady && /* @__PURE__ */ jsxRuntime.jsxs(LoadingOverlay, { children: [
|
|
4335
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Loader, { small: true }),
|
|
4336
|
+
/* @__PURE__ */ jsxRuntime.jsx(LoadingText, { children: "Initializing editor..." })
|
|
4337
|
+
] }),
|
|
4338
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4339
|
+
EditorWrapper,
|
|
4340
|
+
{
|
|
4341
|
+
ref: editorRef,
|
|
4342
|
+
id: `editor-${name}`,
|
|
4343
|
+
$minHeight: editorHeight
|
|
4344
|
+
}
|
|
4345
|
+
),
|
|
4346
|
+
isReady && blocksCount === 0 && !collabEnabled && /* @__PURE__ */ jsxRuntime.jsxs(EmptyState, { children: [
|
|
4347
|
+
/* @__PURE__ */ jsxRuntime.jsx(EmptyIcon, { children: /* @__PURE__ */ jsxRuntime.jsx(outline.PencilSquareIcon, {}) }),
|
|
4348
|
+
/* @__PURE__ */ jsxRuntime.jsx(EmptyTitle, { children: "Start Writing" }),
|
|
4349
|
+
/* @__PURE__ */ jsxRuntime.jsx(EmptySubtitle, { children: "Click anywhere or use the toolbar to add content" }),
|
|
4350
|
+
/* @__PURE__ */ jsxRuntime.jsxs(KeyboardHints, { children: [
|
|
4351
|
+
/* @__PURE__ */ jsxRuntime.jsxs(KeyHint, { children: [
|
|
4352
|
+
/* @__PURE__ */ jsxRuntime.jsx("kbd", { children: "/" }),
|
|
4353
|
+
" Commands"
|
|
4354
|
+
] }),
|
|
4355
|
+
/* @__PURE__ */ jsxRuntime.jsxs(KeyHint, { children: [
|
|
4356
|
+
/* @__PURE__ */ jsxRuntime.jsx("kbd", { children: "⌘B" }),
|
|
4357
|
+
" Bold"
|
|
4358
|
+
] }),
|
|
4359
|
+
/* @__PURE__ */ jsxRuntime.jsxs(KeyHint, { children: [
|
|
4360
|
+
/* @__PURE__ */ jsxRuntime.jsx("kbd", { children: "⌘I" }),
|
|
4361
|
+
" Italic"
|
|
4362
|
+
] }),
|
|
4363
|
+
/* @__PURE__ */ jsxRuntime.jsxs(KeyHint, { children: [
|
|
4364
|
+
/* @__PURE__ */ jsxRuntime.jsx("kbd", { children: "Tab" }),
|
|
4365
|
+
" Add Block"
|
|
4366
|
+
] })
|
|
4367
|
+
] })
|
|
4368
|
+
] })
|
|
4369
|
+
]
|
|
4370
|
+
}
|
|
4371
|
+
),
|
|
4372
|
+
/* @__PURE__ */ jsxRuntime.jsxs(EditorFooter, { children: [
|
|
4373
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FooterLeft, { children: [
|
|
4374
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FooterStat, { children: [
|
|
4375
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: wordCount }),
|
|
4376
|
+
" ",
|
|
4377
|
+
t("editor.words", "Wörter")
|
|
4378
|
+
] }),
|
|
4379
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FooterStat, { children: [
|
|
4380
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: charCount }),
|
|
4381
|
+
" ",
|
|
4382
|
+
t("editor.characters", "Zeichen")
|
|
4383
|
+
] })
|
|
4384
|
+
] }),
|
|
4385
|
+
/* @__PURE__ */ jsxRuntime.jsxs(FooterRight, { children: [
|
|
4386
|
+
!(collabEnabled && collabCanEdit === false) && /* @__PURE__ */ jsxRuntime.jsxs(FooterButton, { type: "button", onClick: () => handleInsertBlock("mediaLib"), children: [
|
|
4387
|
+
/* @__PURE__ */ jsxRuntime.jsx(outline.PhotoIcon, {}),
|
|
4388
|
+
t("editor.mediaLibrary", "Media Library")
|
|
4389
|
+
] }),
|
|
4390
|
+
isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(FooterButton, { type: "button", $primary: true, onClick: toggleFullscreen, children: [
|
|
4391
|
+
/* @__PURE__ */ jsxRuntime.jsx(outline.ArrowsPointingInIcon, {}),
|
|
4392
|
+
"Exit Fullscreen"
|
|
4393
|
+
] })
|
|
4394
|
+
] })
|
|
4395
|
+
] }),
|
|
4396
|
+
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsx(ResizeHandle, {})
|
|
4397
|
+
]
|
|
4398
|
+
}
|
|
4399
|
+
)
|
|
4400
|
+
}
|
|
4401
|
+
),
|
|
4402
|
+
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4403
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Field.Hint, {}),
|
|
4404
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Field.Error, {})
|
|
4405
|
+
] }),
|
|
4406
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4407
|
+
MediaLibComponent,
|
|
4408
|
+
{
|
|
4409
|
+
isOpen: isMediaLibOpen,
|
|
4410
|
+
onChange: handleMediaLibChange,
|
|
4411
|
+
onToggle: mediaLibToggleFunc
|
|
4412
|
+
}
|
|
4413
|
+
),
|
|
4414
|
+
showAIToolbar && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4415
|
+
tools.AIInlineToolbar,
|
|
4416
|
+
{
|
|
4417
|
+
position: aiToolbarPosition,
|
|
4418
|
+
onAction: async (action, options) => {
|
|
4419
|
+
setAILoading(true);
|
|
4420
|
+
const success = await handleAIAction(action, options, {
|
|
4421
|
+
text: aiSelectedText,
|
|
4422
|
+
range: aiSelectionRangeRef.current
|
|
4423
|
+
});
|
|
4424
|
+
setAILoading(false);
|
|
4425
|
+
if (success) {
|
|
4426
|
+
setShowAIToolbar(false);
|
|
4427
|
+
aiSelectionRangeRef.current = null;
|
|
4428
|
+
}
|
|
4429
|
+
},
|
|
4430
|
+
loading: aiLoading,
|
|
4431
|
+
onClose: () => {
|
|
4432
|
+
setShowAIToolbar(false);
|
|
4433
|
+
aiSelectionRangeRef.current = null;
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
),
|
|
4437
|
+
showAIPopup && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4438
|
+
AIAssistantPopup,
|
|
4439
|
+
{
|
|
4440
|
+
selectedText: aiSelectedText,
|
|
4441
|
+
licenseKey: licenseData?.licenseKey,
|
|
4442
|
+
onClose: () => {
|
|
4443
|
+
setShowAIPopup(false);
|
|
4444
|
+
aiSelectionRangeRef.current = null;
|
|
4445
|
+
},
|
|
4446
|
+
onApply: (correctedText) => {
|
|
4447
|
+
if (aiSelectionRangeRef.current) {
|
|
4448
|
+
const selection = window.getSelection();
|
|
4449
|
+
selection.removeAllRanges();
|
|
4450
|
+
selection.addRange(aiSelectionRangeRef.current);
|
|
4451
|
+
document.execCommand("insertText", false, correctedText);
|
|
4452
|
+
aiSelectionRangeRef.current = null;
|
|
4453
|
+
}
|
|
4454
|
+
setShowAIPopup(false);
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
),
|
|
4458
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4459
|
+
CreditsModal,
|
|
4460
|
+
{
|
|
4461
|
+
isOpen: showCreditsModal,
|
|
4462
|
+
onClose: () => {
|
|
4463
|
+
setShowCreditsModal(false);
|
|
4464
|
+
setCreditsUpgradeInfo(null);
|
|
4465
|
+
},
|
|
4466
|
+
upgradeInfo: creditsUpgradeInfo
|
|
4467
|
+
}
|
|
4468
|
+
)
|
|
4469
|
+
] });
|
|
4470
|
+
});
|
|
4471
|
+
Editor.displayName = "MagicEditorXInput";
|
|
4472
|
+
exports.default = Editor;
|