magic-editor-x 1.5.1 → 1.6.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/README.md +6 -110
- package/dist/{_chunks/App-iNfbV7cz.mjs → admin/App-BwMEZnS-.mjs} +35 -34
- package/dist/{_chunks/App-DImBvISP.js → admin/App-HNr2tizR.js} +65 -64
- package/dist/{_chunks/CustomBlocksPage-Cj-0TTUs.js → admin/CustomBlocksPage-BjcA7MGz.js} +13 -13
- package/dist/{_chunks/LicensePage-gLRoo8WJ.mjs → admin/LicensePage-D0DMTF41.mjs} +39 -38
- package/dist/{_chunks/LicensePage-CmvILX9m.js → admin/LicensePage-D0_9yPkw.js} +45 -44
- package/dist/{_chunks/LiveCollaborationPanel-BFybu8h0.js → admin/LiveCollaborationPanel-CZAbgAVr.js} +9 -8
- package/dist/{_chunks/LiveCollaborationPanel-CVgl4IyR.mjs → admin/LiveCollaborationPanel-D8z72afw.mjs} +4 -3
- package/dist/{_chunks/Settings-BzGqgrxD.js → admin/Settings-DRenvRcG.js} +90 -89
- package/dist/{_chunks/Settings-ButYcfrm.mjs → admin/Settings-DjyNURlS.mjs} +83 -82
- package/dist/{_chunks/getTranslation-D3h3Z3gU.mjs → admin/getTranslation-2OiEgVGt.mjs} +10593 -18925
- package/dist/{_chunks/getTranslation-BADoesEn.js → admin/getTranslation-DQ_WJ-7M.js} +11076 -19408
- package/dist/{_chunks/index-BXBnwuRw.js → admin/index-Bn2tfJrC.js} +382 -354
- package/dist/{_chunks/index-DDFAuQNT.js → admin/index-DAtClhqy.js} +184 -183
- package/dist/{_chunks/index-BvEdg518.mjs → admin/index-FVEbTfqO.mjs} +290 -262
- package/dist/{_chunks/index-DEi6nwfM.mjs → admin/index-gjWl-6E2.mjs} +34 -33
- package/dist/admin/index.js +3 -2
- package/dist/admin/index.mjs +2 -2
- package/dist/{_chunks/tools-BXzd0lx5.mjs → admin/tools-CzHTZaY_.mjs} +42 -39
- package/dist/{_chunks/tools-Q0uwDS9E.js → admin/tools-DALFhvPO.js} +49 -46
- package/dist/server/index.js +63511 -37933
- package/dist/server/index.mjs +63511 -37906
- package/package.json +43 -30
- /package/dist/{_chunks → admin}/CustomBlocksPage-COPOZ2-_.mjs +0 -0
- /package/dist/{_chunks → admin}/de-C_0Mj-Zo.mjs +0 -0
- /package/dist/{_chunks → admin}/de-DVNVpAt9.js +0 -0
- /package/dist/{_chunks → admin}/en-B7AAf1ie.mjs +0 -0
- /package/dist/{_chunks → admin}/en-C2hv5GsA.js +0 -0
- /package/dist/{_chunks → admin}/es-BzJqcIST.js +0 -0
- /package/dist/{_chunks → admin}/es-zdP8sd-f.mjs +0 -0
- /package/dist/{_chunks → admin}/fr-CtAgOgH1.mjs +0 -0
- /package/dist/{_chunks → admin}/fr-D3GwqAAJ.js +0 -0
- /package/dist/{style.css → admin/magic-editor-x.css} +0 -0
- /package/dist/{_chunks → admin}/pt-BmUw6YMP.mjs +0 -0
- /package/dist/{_chunks → admin}/pt-CFo0nTbj.js +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const s = require("react");
|
|
5
|
+
const reactIntl = require("react-intl");
|
|
6
|
+
const getTranslation = require("./getTranslation-DQ_WJ-7M.js");
|
|
6
7
|
const styled = require("styled-components");
|
|
7
8
|
const outline = require("@heroicons/react/24/outline");
|
|
8
9
|
const EditorJS = require("@editorjs/editorjs");
|
|
9
|
-
const tools = require("./tools-
|
|
10
|
+
const tools = require("./tools-DALFhvPO.js");
|
|
10
11
|
const admin = require("@strapi/strapi/admin");
|
|
11
|
-
const index = require("./index-
|
|
12
|
+
const index = require("./index-Bn2tfJrC.js");
|
|
12
13
|
const socket_ioClient = require("socket.io-client");
|
|
13
14
|
const Y = require("yjs");
|
|
14
15
|
const yIndexeddb = require("y-indexeddb");
|
|
@@ -31,7 +32,7 @@ function _interopNamespace(e) {
|
|
|
31
32
|
n.default = e;
|
|
32
33
|
return Object.freeze(n);
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
+
const s__default = /* @__PURE__ */ _interopDefault(s);
|
|
35
36
|
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
36
37
|
const EditorJS__default = /* @__PURE__ */ _interopDefault(EditorJS);
|
|
37
38
|
const Y__namespace = /* @__PURE__ */ _interopNamespace(Y);
|
|
@@ -780,11 +781,11 @@ const MediaLibComponent = ({
|
|
|
780
781
|
allowedTypes = ["images", "files", "videos", "audios"],
|
|
781
782
|
multiple = true
|
|
782
783
|
}) => {
|
|
783
|
-
const [isLoading, setIsLoading] =
|
|
784
|
-
const [retryCount, setRetryCount] =
|
|
784
|
+
const [isLoading, setIsLoading] = s.useState(true);
|
|
785
|
+
const [retryCount, setRetryCount] = s.useState(0);
|
|
785
786
|
const components = admin.useStrapiApp("MediaLibComponent", (state) => state.components);
|
|
786
787
|
const MediaLibraryDialog = components?.["media-library"];
|
|
787
|
-
|
|
788
|
+
s.useEffect(() => {
|
|
788
789
|
if (isOpen && !MediaLibraryDialog && retryCount < 5) {
|
|
789
790
|
const timer = setTimeout(() => {
|
|
790
791
|
setRetryCount((prev) => prev + 1);
|
|
@@ -793,13 +794,13 @@ const MediaLibComponent = ({
|
|
|
793
794
|
}
|
|
794
795
|
setIsLoading(false);
|
|
795
796
|
}, [isOpen, MediaLibraryDialog, retryCount]);
|
|
796
|
-
|
|
797
|
+
s.useEffect(() => {
|
|
797
798
|
if (!isOpen) {
|
|
798
799
|
setRetryCount(0);
|
|
799
800
|
setIsLoading(true);
|
|
800
801
|
}
|
|
801
802
|
}, [isOpen]);
|
|
802
|
-
|
|
803
|
+
s.useEffect(() => {
|
|
803
804
|
if (isOpen) {
|
|
804
805
|
console.log("[Magic Editor X] MediaLib opened");
|
|
805
806
|
console.log("[Magic Editor X] Available components:", Object.keys(components || {}));
|
|
@@ -807,7 +808,7 @@ const MediaLibComponent = ({
|
|
|
807
808
|
console.log("[Magic Editor X] Retry count:", retryCount);
|
|
808
809
|
}
|
|
809
810
|
}, [isOpen, components, MediaLibraryDialog, retryCount]);
|
|
810
|
-
const handleSelectAssets =
|
|
811
|
+
const handleSelectAssets = s.useCallback((files) => {
|
|
811
812
|
console.log("[Magic Editor X] Selected assets:", files);
|
|
812
813
|
if (!files || files.length === 0) {
|
|
813
814
|
onToggle();
|
|
@@ -829,7 +830,7 @@ const MediaLibComponent = ({
|
|
|
829
830
|
console.log("[Magic Editor X] Formatted files:", formattedFiles);
|
|
830
831
|
onChange(formattedFiles);
|
|
831
832
|
}, [onChange, onToggle]);
|
|
832
|
-
const handleClose =
|
|
833
|
+
const handleClose = s.useCallback(() => {
|
|
833
834
|
console.log("[Magic Editor X] MediaLib closing");
|
|
834
835
|
onToggle();
|
|
835
836
|
}, [onToggle]);
|
|
@@ -994,7 +995,7 @@ const MediaLibComponent = ({
|
|
|
994
995
|
}
|
|
995
996
|
) });
|
|
996
997
|
};
|
|
997
|
-
class MediaLibErrorBoundary extends
|
|
998
|
+
class MediaLibErrorBoundary extends s__default.default.Component {
|
|
998
999
|
constructor(props) {
|
|
999
1000
|
super(props);
|
|
1000
1001
|
this.state = { hasError: false, error: null };
|
|
@@ -1268,20 +1269,20 @@ const useMagicCollaboration = ({
|
|
|
1268
1269
|
const { get, post } = admin.useFetchClient();
|
|
1269
1270
|
const authContext = admin.useAuth("useMagicCollaboration", (state) => state);
|
|
1270
1271
|
const user = authContext?.user || null;
|
|
1271
|
-
const [status, setStatus] =
|
|
1272
|
-
const [error, setError] =
|
|
1273
|
-
const [peers, setPeers] =
|
|
1274
|
-
const [awareness, setAwareness] =
|
|
1275
|
-
const [collabRole, setCollabRole] =
|
|
1276
|
-
const [canEdit, setCanEdit] =
|
|
1277
|
-
const socketRef =
|
|
1278
|
-
const persistenceRef =
|
|
1279
|
-
const bootstrappedRef =
|
|
1280
|
-
const onRemoteUpdateRef =
|
|
1281
|
-
|
|
1272
|
+
const [status, setStatus] = s.useState(enabled ? "idle" : "disabled");
|
|
1273
|
+
const [error, setError] = s.useState(null);
|
|
1274
|
+
const [peers, setPeers] = s.useState([]);
|
|
1275
|
+
const [awareness, setAwareness] = s.useState({});
|
|
1276
|
+
const [collabRole, setCollabRole] = s.useState(null);
|
|
1277
|
+
const [canEdit, setCanEdit] = s.useState(null);
|
|
1278
|
+
const socketRef = s.useRef(null);
|
|
1279
|
+
const persistenceRef = s.useRef(null);
|
|
1280
|
+
const bootstrappedRef = s.useRef(false);
|
|
1281
|
+
const onRemoteUpdateRef = s.useRef(onRemoteUpdate);
|
|
1282
|
+
s.useEffect(() => {
|
|
1282
1283
|
onRemoteUpdateRef.current = onRemoteUpdate;
|
|
1283
1284
|
}, [onRemoteUpdate]);
|
|
1284
|
-
const { doc, blocksMap, textMap, metaMap } =
|
|
1285
|
+
const { doc, blocksMap, textMap, metaMap } = s.useMemo(() => {
|
|
1285
1286
|
const yDoc = new Y__namespace.Doc();
|
|
1286
1287
|
return {
|
|
1287
1288
|
doc: yDoc,
|
|
@@ -1293,7 +1294,7 @@ const useMagicCollaboration = ({
|
|
|
1293
1294
|
// Document metadata (time, blockOrder)
|
|
1294
1295
|
};
|
|
1295
1296
|
}, [roomId]);
|
|
1296
|
-
const getBlockText =
|
|
1297
|
+
const getBlockText = s.useCallback((blockId) => {
|
|
1297
1298
|
if (!blockId) return null;
|
|
1298
1299
|
let ytext = textMap.get(blockId);
|
|
1299
1300
|
if (!ytext) {
|
|
@@ -1302,7 +1303,7 @@ const useMagicCollaboration = ({
|
|
|
1302
1303
|
}
|
|
1303
1304
|
return ytext;
|
|
1304
1305
|
}, [textMap]);
|
|
1305
|
-
const setBlockText =
|
|
1306
|
+
const setBlockText = s.useCallback((blockId, html) => {
|
|
1306
1307
|
if (!blockId) return;
|
|
1307
1308
|
const ytext = getBlockText(blockId);
|
|
1308
1309
|
if (!ytext) return;
|
|
@@ -1316,18 +1317,18 @@ const useMagicCollaboration = ({
|
|
|
1316
1317
|
}
|
|
1317
1318
|
}, "local");
|
|
1318
1319
|
}, [doc, getBlockText]);
|
|
1319
|
-
const getBlockTextHtml =
|
|
1320
|
+
const getBlockTextHtml = s.useCallback((blockId) => {
|
|
1320
1321
|
if (!blockId) return "";
|
|
1321
1322
|
const ytext = textMap.get(blockId);
|
|
1322
1323
|
if (!ytext) return "";
|
|
1323
1324
|
return deltaToHtml(ytext.toDelta());
|
|
1324
1325
|
}, [textMap]);
|
|
1325
|
-
|
|
1326
|
+
s.useEffect(() => {
|
|
1326
1327
|
return () => {
|
|
1327
1328
|
doc.destroy();
|
|
1328
1329
|
};
|
|
1329
1330
|
}, [doc]);
|
|
1330
|
-
|
|
1331
|
+
s.useEffect(() => {
|
|
1331
1332
|
bootstrappedRef.current = false;
|
|
1332
1333
|
setPeers([]);
|
|
1333
1334
|
setAwareness({});
|
|
@@ -1342,7 +1343,7 @@ const useMagicCollaboration = ({
|
|
|
1342
1343
|
}
|
|
1343
1344
|
};
|
|
1344
1345
|
}, [roomId]);
|
|
1345
|
-
|
|
1346
|
+
s.useEffect(() => {
|
|
1346
1347
|
if (!enabled) return void 0;
|
|
1347
1348
|
const cleanupInterval = setInterval(() => {
|
|
1348
1349
|
const now = Date.now();
|
|
@@ -1361,14 +1362,14 @@ const useMagicCollaboration = ({
|
|
|
1361
1362
|
}, 1e4);
|
|
1362
1363
|
return () => clearInterval(cleanupInterval);
|
|
1363
1364
|
}, [enabled]);
|
|
1364
|
-
|
|
1365
|
+
s.useEffect(() => {
|
|
1365
1366
|
if (!enabled) {
|
|
1366
1367
|
setStatus("disabled");
|
|
1367
1368
|
} else if (status === "disabled") {
|
|
1368
1369
|
setStatus("idle");
|
|
1369
1370
|
}
|
|
1370
1371
|
}, [enabled, status]);
|
|
1371
|
-
|
|
1372
|
+
s.useEffect(() => {
|
|
1372
1373
|
if (!enabled || !roomId) {
|
|
1373
1374
|
return void 0;
|
|
1374
1375
|
}
|
|
@@ -1376,7 +1377,7 @@ const useMagicCollaboration = ({
|
|
|
1376
1377
|
console.log("[Magic Collab] [READY] Client ready, waiting for server sync...");
|
|
1377
1378
|
return void 0;
|
|
1378
1379
|
}, [enabled, roomId]);
|
|
1379
|
-
|
|
1380
|
+
s.useEffect(() => {
|
|
1380
1381
|
if (!enabled || !roomId || !doc) {
|
|
1381
1382
|
return void 0;
|
|
1382
1383
|
}
|
|
@@ -1402,11 +1403,11 @@ const useMagicCollaboration = ({
|
|
|
1402
1403
|
}
|
|
1403
1404
|
};
|
|
1404
1405
|
}, [enabled, roomId, doc]);
|
|
1405
|
-
const initialValueRef =
|
|
1406
|
-
|
|
1406
|
+
const initialValueRef = s.useRef(initialValue);
|
|
1407
|
+
s.useEffect(() => {
|
|
1407
1408
|
initialValueRef.current = initialValue;
|
|
1408
1409
|
}, [initialValue]);
|
|
1409
|
-
|
|
1410
|
+
s.useEffect(() => {
|
|
1410
1411
|
if (!enabled || !roomId || !user) {
|
|
1411
1412
|
return void 0;
|
|
1412
1413
|
}
|
|
@@ -1583,7 +1584,7 @@ const useMagicCollaboration = ({
|
|
|
1583
1584
|
setPeers([]);
|
|
1584
1585
|
};
|
|
1585
1586
|
}, [enabled, post, fieldName, roomId, user]);
|
|
1586
|
-
|
|
1587
|
+
s.useEffect(() => {
|
|
1587
1588
|
if (!enabled) {
|
|
1588
1589
|
console.log("[Magic Collab] [SKIP] Update handler not registered (disabled)");
|
|
1589
1590
|
return void 0;
|
|
@@ -1611,12 +1612,12 @@ const useMagicCollaboration = ({
|
|
|
1611
1612
|
doc.off("update", handler);
|
|
1612
1613
|
};
|
|
1613
1614
|
}, [doc, enabled]);
|
|
1614
|
-
const emitAwareness =
|
|
1615
|
+
const emitAwareness = s.useCallback((payload) => {
|
|
1615
1616
|
if (socketRef.current?.connected) {
|
|
1616
1617
|
socketRef.current.emit("collab:awareness", payload);
|
|
1617
1618
|
}
|
|
1618
1619
|
}, []);
|
|
1619
|
-
const localUserColor =
|
|
1620
|
+
const localUserColor = s.useMemo(() => {
|
|
1620
1621
|
return user ? getUserColor(user.id) : CURSOR_COLORS[0];
|
|
1621
1622
|
}, [user]);
|
|
1622
1623
|
return {
|
|
@@ -1658,15 +1659,15 @@ const useMagicCollaboration = ({
|
|
|
1658
1659
|
};
|
|
1659
1660
|
const useLicense = () => {
|
|
1660
1661
|
const { get } = admin.useFetchClient();
|
|
1661
|
-
const [isPremium, setIsPremium] =
|
|
1662
|
-
const [isAdvanced, setIsAdvanced] =
|
|
1663
|
-
const [isEnterprise, setIsEnterprise] =
|
|
1664
|
-
const [tier, setTier] =
|
|
1665
|
-
const [loading, setLoading] =
|
|
1666
|
-
const [error, setError] =
|
|
1667
|
-
const [licenseData, setLicenseData] =
|
|
1668
|
-
const [limits, setLimits] =
|
|
1669
|
-
|
|
1662
|
+
const [isPremium, setIsPremium] = s.useState(false);
|
|
1663
|
+
const [isAdvanced, setIsAdvanced] = s.useState(false);
|
|
1664
|
+
const [isEnterprise, setIsEnterprise] = s.useState(false);
|
|
1665
|
+
const [tier, setTier] = s.useState("free");
|
|
1666
|
+
const [loading, setLoading] = s.useState(true);
|
|
1667
|
+
const [error, setError] = s.useState(null);
|
|
1668
|
+
const [licenseData, setLicenseData] = s.useState(null);
|
|
1669
|
+
const [limits, setLimits] = s.useState(null);
|
|
1670
|
+
s.useEffect(() => {
|
|
1670
1671
|
let mounted = true;
|
|
1671
1672
|
const fetchLicense = async () => {
|
|
1672
1673
|
if (mounted) {
|
|
@@ -1787,13 +1788,13 @@ const useLicense = () => {
|
|
|
1787
1788
|
};
|
|
1788
1789
|
};
|
|
1789
1790
|
const useAIActions = ({ licenseKey, editorInstanceRef, isReady, onNoCredits }) => {
|
|
1790
|
-
const apiClientRef =
|
|
1791
|
-
|
|
1791
|
+
const apiClientRef = s__default.default.useRef(null);
|
|
1792
|
+
s__default.default.useEffect(() => {
|
|
1792
1793
|
if (licenseKey && !apiClientRef.current) {
|
|
1793
1794
|
apiClientRef.current = new tools.MagicEditorAPI(licenseKey);
|
|
1794
1795
|
}
|
|
1795
1796
|
}, [licenseKey]);
|
|
1796
|
-
const replaceText =
|
|
1797
|
+
const replaceText = s.useCallback((range, newText) => {
|
|
1797
1798
|
if (!range) return false;
|
|
1798
1799
|
try {
|
|
1799
1800
|
const selection = window.getSelection();
|
|
@@ -1812,7 +1813,7 @@ const useAIActions = ({ licenseKey, editorInstanceRef, isReady, onNoCredits }) =
|
|
|
1812
1813
|
return false;
|
|
1813
1814
|
}
|
|
1814
1815
|
}, [editorInstanceRef, isReady]);
|
|
1815
|
-
const appendText =
|
|
1816
|
+
const appendText = s.useCallback((range, additionalText) => {
|
|
1816
1817
|
if (!range) return false;
|
|
1817
1818
|
try {
|
|
1818
1819
|
const selection = window.getSelection();
|
|
@@ -1833,7 +1834,7 @@ const useAIActions = ({ licenseKey, editorInstanceRef, isReady, onNoCredits }) =
|
|
|
1833
1834
|
return false;
|
|
1834
1835
|
}
|
|
1835
1836
|
}, [editorInstanceRef, isReady]);
|
|
1836
|
-
const handleAIAction =
|
|
1837
|
+
const handleAIAction = s.useCallback(async (action, options, { text, range }) => {
|
|
1837
1838
|
if (!apiClientRef.current || !text) return;
|
|
1838
1839
|
const originalText = text;
|
|
1839
1840
|
const langNames = { en: "Englisch", de: "Deutsch", fr: "Französisch", es: "Spanisch" };
|
|
@@ -1943,14 +1944,14 @@ const useAIActions = ({ licenseKey, editorInstanceRef, isReady, onNoCredits }) =
|
|
|
1943
1944
|
};
|
|
1944
1945
|
const useWebtoolsLinks = () => {
|
|
1945
1946
|
const getPlugin = admin.useStrapiApp("WebtoolsLinks", (state) => state.getPlugin);
|
|
1946
|
-
const linksPlugin =
|
|
1947
|
+
const linksPlugin = s.useMemo(() => {
|
|
1947
1948
|
try {
|
|
1948
1949
|
return getPlugin?.("webtools-addon-links");
|
|
1949
1950
|
} catch (e) {
|
|
1950
1951
|
return null;
|
|
1951
1952
|
}
|
|
1952
1953
|
}, [getPlugin]);
|
|
1953
|
-
const isAvailable =
|
|
1954
|
+
const isAvailable = s.useMemo(() => {
|
|
1954
1955
|
const available = !!linksPlugin?.apis?.openLinkPicker;
|
|
1955
1956
|
if (typeof window !== "undefined" && !window.__WEBTOOLS_LINKS_CHECKED__) {
|
|
1956
1957
|
window.__WEBTOOLS_LINKS_CHECKED__ = true;
|
|
@@ -1962,7 +1963,7 @@ const useWebtoolsLinks = () => {
|
|
|
1962
1963
|
}
|
|
1963
1964
|
return available;
|
|
1964
1965
|
}, [linksPlugin]);
|
|
1965
|
-
const openLinkPicker =
|
|
1966
|
+
const openLinkPicker = s.useCallback(async ({ initialHref = "", initialText = "" } = {}) => {
|
|
1966
1967
|
if (!linksPlugin?.apis?.openLinkPicker) {
|
|
1967
1968
|
console.warn("[Magic Editor X] Webtools Link Picker not available");
|
|
1968
1969
|
return null;
|
|
@@ -2002,10 +2003,10 @@ const apiBase = "/magic-editor-x";
|
|
|
2002
2003
|
const useVersionHistory = () => {
|
|
2003
2004
|
const { get, post } = admin.useFetchClient();
|
|
2004
2005
|
const { tier } = useLicense();
|
|
2005
|
-
const [snapshots, setSnapshots] =
|
|
2006
|
-
const [loading, setLoading] =
|
|
2007
|
-
const [error, setError] =
|
|
2008
|
-
const fetchSnapshots =
|
|
2006
|
+
const [snapshots, setSnapshots] = s.useState([]);
|
|
2007
|
+
const [loading, setLoading] = s.useState(false);
|
|
2008
|
+
const [error, setError] = s.useState(null);
|
|
2009
|
+
const fetchSnapshots = s.useCallback(
|
|
2009
2010
|
async (roomId) => {
|
|
2010
2011
|
if (!roomId) return;
|
|
2011
2012
|
setLoading(true);
|
|
@@ -2021,7 +2022,7 @@ const useVersionHistory = () => {
|
|
|
2021
2022
|
},
|
|
2022
2023
|
[get]
|
|
2023
2024
|
);
|
|
2024
|
-
const restoreSnapshot =
|
|
2025
|
+
const restoreSnapshot = s.useCallback(
|
|
2025
2026
|
async (documentId, roomId) => {
|
|
2026
2027
|
if (!documentId) return;
|
|
2027
2028
|
setLoading(true);
|
|
@@ -2038,7 +2039,7 @@ const useVersionHistory = () => {
|
|
|
2038
2039
|
},
|
|
2039
2040
|
[get]
|
|
2040
2041
|
);
|
|
2041
|
-
const createSnapshot =
|
|
2042
|
+
const createSnapshot = s.useCallback(
|
|
2042
2043
|
async ({ roomId, contentType, entryId, fieldName, content }) => {
|
|
2043
2044
|
if (!roomId || !contentType || !entryId || !fieldName) return;
|
|
2044
2045
|
setLoading(true);
|
|
@@ -2561,11 +2562,11 @@ function createBlockClasses(blockConfigs) {
|
|
|
2561
2562
|
}
|
|
2562
2563
|
function useCustomBlocks() {
|
|
2563
2564
|
const { get } = admin.useFetchClient();
|
|
2564
|
-
const [customBlocks, setCustomBlocks] =
|
|
2565
|
-
const [isLoading, setIsLoading] =
|
|
2566
|
-
const [error, setError] =
|
|
2567
|
-
const [lastFetched, setLastFetched] =
|
|
2568
|
-
const fetchCustomBlocks =
|
|
2565
|
+
const [customBlocks, setCustomBlocks] = s.useState([]);
|
|
2566
|
+
const [isLoading, setIsLoading] = s.useState(true);
|
|
2567
|
+
const [error, setError] = s.useState(null);
|
|
2568
|
+
const [lastFetched, setLastFetched] = s.useState(null);
|
|
2569
|
+
const fetchCustomBlocks = s.useCallback(async () => {
|
|
2569
2570
|
try {
|
|
2570
2571
|
setIsLoading(true);
|
|
2571
2572
|
setError(null);
|
|
@@ -2584,10 +2585,10 @@ function useCustomBlocks() {
|
|
|
2584
2585
|
setIsLoading(false);
|
|
2585
2586
|
}
|
|
2586
2587
|
}, [get]);
|
|
2587
|
-
const refresh =
|
|
2588
|
+
const refresh = s.useCallback(() => {
|
|
2588
2589
|
return fetchCustomBlocks();
|
|
2589
2590
|
}, [fetchCustomBlocks]);
|
|
2590
|
-
|
|
2591
|
+
s.useEffect(() => {
|
|
2591
2592
|
fetchCustomBlocks();
|
|
2592
2593
|
}, [fetchCustomBlocks]);
|
|
2593
2594
|
return {
|
|
@@ -2839,14 +2840,14 @@ const SparklesIcon = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "24",
|
|
|
2839
2840
|
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17 19h4" })
|
|
2840
2841
|
] });
|
|
2841
2842
|
const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
2842
|
-
const [activeType, setActiveType] =
|
|
2843
|
-
const [isLoading, setIsLoading] =
|
|
2844
|
-
const [result, setResult] =
|
|
2845
|
-
const [error, setError] =
|
|
2846
|
-
const [credits, setCredits] =
|
|
2847
|
-
const [usage, setUsage] =
|
|
2848
|
-
const [apiClient, setApiClient] =
|
|
2849
|
-
|
|
2843
|
+
const [activeType, setActiveType] = s.useState(null);
|
|
2844
|
+
const [isLoading, setIsLoading] = s.useState(false);
|
|
2845
|
+
const [result, setResult] = s.useState(null);
|
|
2846
|
+
const [error, setError] = s.useState(null);
|
|
2847
|
+
const [credits, setCredits] = s.useState(0);
|
|
2848
|
+
const [usage, setUsage] = s.useState(null);
|
|
2849
|
+
const [apiClient, setApiClient] = s.useState(null);
|
|
2850
|
+
s.useEffect(() => {
|
|
2850
2851
|
if (licenseKey) {
|
|
2851
2852
|
const client = new tools.MagicEditorAPI(licenseKey);
|
|
2852
2853
|
setApiClient(client);
|
|
@@ -2858,7 +2859,7 @@ const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
|
2858
2859
|
});
|
|
2859
2860
|
}
|
|
2860
2861
|
}, [licenseKey]);
|
|
2861
|
-
const handleCorrection =
|
|
2862
|
+
const handleCorrection = s.useCallback(async (type) => {
|
|
2862
2863
|
if (!apiClient || !selectedText) return;
|
|
2863
2864
|
setActiveType(type);
|
|
2864
2865
|
setIsLoading(true);
|
|
@@ -2888,7 +2889,7 @@ const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
|
2888
2889
|
setIsLoading(false);
|
|
2889
2890
|
}
|
|
2890
2891
|
}, [apiClient, selectedText]);
|
|
2891
|
-
const handleApply =
|
|
2892
|
+
const handleApply = s.useCallback(() => {
|
|
2892
2893
|
if (result?.corrected) {
|
|
2893
2894
|
onApply(result.corrected);
|
|
2894
2895
|
}
|
|
@@ -2898,7 +2899,7 @@ const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
|
2898
2899
|
onClose();
|
|
2899
2900
|
}
|
|
2900
2901
|
};
|
|
2901
|
-
|
|
2902
|
+
s.useEffect(() => {
|
|
2902
2903
|
const handleKeyDown = (e) => {
|
|
2903
2904
|
if (e.key === "Escape") {
|
|
2904
2905
|
onClose();
|
|
@@ -3007,7 +3008,7 @@ const AIAssistantPopup = ({ selectedText, licenseKey, onClose, onApply }) => {
|
|
|
3007
3008
|
] })
|
|
3008
3009
|
] }) });
|
|
3009
3010
|
};
|
|
3010
|
-
const PanelWrapper = styled__default.default(getTranslation.
|
|
3011
|
+
const PanelWrapper = styled__default.default(getTranslation.S)`
|
|
3011
3012
|
width: 320px;
|
|
3012
3013
|
background: ${({ theme }) => theme.colors.neutral0};
|
|
3013
3014
|
border: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
@@ -3017,25 +3018,25 @@ const PanelWrapper = styled__default.default(getTranslation.R)`
|
|
|
3017
3018
|
flex-direction: column;
|
|
3018
3019
|
max-height: 70vh;
|
|
3019
3020
|
`;
|
|
3020
|
-
const Header$1 = styled__default.default(getTranslation.
|
|
3021
|
+
const Header$1 = styled__default.default(getTranslation.C)`
|
|
3021
3022
|
padding: 12px 16px;
|
|
3022
3023
|
border-bottom: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
3023
3024
|
`;
|
|
3024
|
-
const Content$1 = styled__default.default(getTranslation.
|
|
3025
|
+
const Content$1 = styled__default.default(getTranslation.S)`
|
|
3025
3026
|
padding: 12px 16px;
|
|
3026
3027
|
overflow-y: auto;
|
|
3027
3028
|
`;
|
|
3028
|
-
const Item = styled__default.default(getTranslation.
|
|
3029
|
+
const Item = styled__default.default(getTranslation.S)`
|
|
3029
3030
|
padding: 10px 12px;
|
|
3030
3031
|
border: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
3031
3032
|
border-radius: 6px;
|
|
3032
3033
|
margin-bottom: 10px;
|
|
3033
3034
|
`;
|
|
3034
|
-
const Meta = styled__default.default(getTranslation.
|
|
3035
|
+
const Meta = styled__default.default(getTranslation.A)`
|
|
3035
3036
|
color: ${({ theme }) => theme.colors.neutral500};
|
|
3036
3037
|
font-size: 12px;
|
|
3037
3038
|
`;
|
|
3038
|
-
const PremiumBadge = styled__default.default(getTranslation.
|
|
3039
|
+
const PremiumBadge = styled__default.default(getTranslation.S)`
|
|
3039
3040
|
background: ${({ theme }) => theme.colors.primary100};
|
|
3040
3041
|
color: ${({ theme }) => theme.colors.primary600};
|
|
3041
3042
|
border-radius: 6px;
|
|
@@ -3076,7 +3077,7 @@ const VersionHistoryPanel = ({
|
|
|
3076
3077
|
tier,
|
|
3077
3078
|
onClose
|
|
3078
3079
|
}) => {
|
|
3079
|
-
const { formatMessage } =
|
|
3080
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
3080
3081
|
const canRestore = tier !== "free";
|
|
3081
3082
|
const t = (id, defaultMessage) => formatMessage(
|
|
3082
3083
|
{ id: getTranslation.getTranslation(id), defaultMessage },
|
|
@@ -3084,33 +3085,33 @@ const VersionHistoryPanel = ({
|
|
|
3084
3085
|
);
|
|
3085
3086
|
return /* @__PURE__ */ jsxRuntime.jsxs(PanelWrapper, { "data-testid": "version-history-panel", children: [
|
|
3086
3087
|
/* @__PURE__ */ jsxRuntime.jsxs(Header$1, { justifyContent: "space-between", alignItems: "center", children: [
|
|
3087
|
-
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.
|
|
3088
|
+
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.C, { gap: 8, alignItems: "center", children: [
|
|
3088
3089
|
/* @__PURE__ */ jsxRuntime.jsx(outline.ClockIcon, { width: 18 }),
|
|
3089
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3090
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.A, { fontWeight: "bold", children: t("versionHistory.title", "Version History") })
|
|
3090
3091
|
] }),
|
|
3091
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3092
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Ct, { size: "S", variant: "tertiary", onClick: onClose, children: t("versionHistory.close", "Close") })
|
|
3092
3093
|
] }),
|
|
3093
3094
|
/* @__PURE__ */ jsxRuntime.jsxs(Content$1, { children: [
|
|
3094
|
-
loading && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3095
|
-
error && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3096
|
-
!loading && !error && snapshots.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3095
|
+
loading && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.A, { children: t("versionHistory.loading", "Loading versions...") }),
|
|
3096
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.A, { textColor: "danger600", children: error }),
|
|
3097
|
+
!loading && !error && snapshots.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.A, { children: t("versionHistory.noSnapshots", "No versions saved yet") }),
|
|
3097
3098
|
!loading && !error && snapshots.map((snap) => /* @__PURE__ */ jsxRuntime.jsxs(Item, { children: [
|
|
3098
|
-
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.
|
|
3099
|
-
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.
|
|
3099
|
+
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.C, { justifyContent: "space-between", alignItems: "center", children: [
|
|
3100
|
+
/* @__PURE__ */ jsxRuntime.jsxs(getTranslation.A, { fontWeight: "bold", children: [
|
|
3100
3101
|
t("versionHistory.version", "Version"),
|
|
3101
3102
|
" ",
|
|
3102
3103
|
snap.version
|
|
3103
3104
|
] }),
|
|
3104
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3105
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.A, { variant: "pi", children: formatDate(snap.createdAt) })
|
|
3105
3106
|
] }),
|
|
3106
3107
|
/* @__PURE__ */ jsxRuntime.jsxs(Meta, { children: [
|
|
3107
3108
|
t("versionHistory.createdBy", "By"),
|
|
3108
3109
|
" ",
|
|
3109
3110
|
snap.createdBy?.firstname ? `${snap.createdBy.firstname} ${snap.createdBy.lastname || ""}`.trim() : "—"
|
|
3110
3111
|
] }),
|
|
3111
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3112
|
-
canRestore ? /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3113
|
-
getTranslation.
|
|
3112
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.yn, { marginTop: 2, marginBottom: 2 }),
|
|
3113
|
+
canRestore ? /* @__PURE__ */ jsxRuntime.jsx(getTranslation.C, { gap: 8, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3114
|
+
getTranslation.Ct,
|
|
3114
3115
|
{
|
|
3115
3116
|
size: "S",
|
|
3116
3117
|
variant: "secondary",
|
|
@@ -3122,9 +3123,9 @@ const VersionHistoryPanel = ({
|
|
|
3122
3123
|
t("versionHistory.premiumOnly", "Premium feature")
|
|
3123
3124
|
] })
|
|
3124
3125
|
] }, snap.documentId || snap.id)),
|
|
3125
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3126
|
-
canRestore ? /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3127
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
3126
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.yn, { marginTop: 4, marginBottom: 4 }),
|
|
3127
|
+
canRestore ? /* @__PURE__ */ jsxRuntime.jsx(getTranslation.Ct, { size: "S", fullWidth: true, variant: "default", onClick: onCreate, disabled: loading, children: t("versionHistory.create", "Create Snapshot") }) : /* @__PURE__ */ jsxRuntime.jsxs(getTranslation.S, { children: [
|
|
3128
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Ct, { size: "S", fullWidth: true, variant: "default", disabled: true, children: t("versionHistory.create", "Create Snapshot") }),
|
|
3128
3129
|
/* @__PURE__ */ jsxRuntime.jsxs(PremiumBadge, { style: { marginTop: "8px", width: "100%", justifyContent: "center" }, children: [
|
|
3129
3130
|
/* @__PURE__ */ jsxRuntime.jsx(outline.ExclamationTriangleIcon, { width: 16 }),
|
|
3130
3131
|
t("versionHistory.premiumOnly", "Premium feature")
|
|
@@ -5313,7 +5314,7 @@ const getPeerName = (user = {}) => {
|
|
|
5313
5314
|
}
|
|
5314
5315
|
return user.email?.split("@")[0] || "Anonymous";
|
|
5315
5316
|
};
|
|
5316
|
-
const Editor =
|
|
5317
|
+
const Editor = s.forwardRef(({
|
|
5317
5318
|
name,
|
|
5318
5319
|
value,
|
|
5319
5320
|
onChange,
|
|
@@ -5327,19 +5328,19 @@ const Editor = m.forwardRef(({
|
|
|
5327
5328
|
placeholder,
|
|
5328
5329
|
...props
|
|
5329
5330
|
}, ref) => {
|
|
5330
|
-
const { formatMessage } =
|
|
5331
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
5331
5332
|
const t = (id, defaultMessage) => formatMessage({ id: getTranslation.getTranslation(id), defaultMessage });
|
|
5332
5333
|
const { licenseData, tier: licenseTier } = useLicense();
|
|
5333
5334
|
const { isAvailable: isWebtoolsAvailable, openLinkPicker: webtoolsOpenLinkPicker } = useWebtoolsLinks();
|
|
5334
5335
|
const { customBlocks, isLoading: isLoadingCustomBlocks } = useCustomBlocks();
|
|
5335
|
-
const editorRef =
|
|
5336
|
-
const editorInstanceRef =
|
|
5337
|
-
const containerRef =
|
|
5338
|
-
const webtoolsSelectionRef =
|
|
5339
|
-
const isReadyRef =
|
|
5340
|
-
const [isReady, setIsReady] =
|
|
5341
|
-
const [showCreditsModal, setShowCreditsModal] =
|
|
5342
|
-
const [creditsUpgradeInfo, setCreditsUpgradeInfo] =
|
|
5336
|
+
const editorRef = s.useRef(null);
|
|
5337
|
+
const editorInstanceRef = s.useRef(null);
|
|
5338
|
+
const containerRef = s.useRef(null);
|
|
5339
|
+
const webtoolsSelectionRef = s.useRef({ text: "", range: null, blockIndex: -1, existingAnchor: null, existingHref: "" });
|
|
5340
|
+
const isReadyRef = s.useRef(false);
|
|
5341
|
+
const [isReady, setIsReady] = s.useState(false);
|
|
5342
|
+
const [showCreditsModal, setShowCreditsModal] = s.useState(false);
|
|
5343
|
+
const [creditsUpgradeInfo, setCreditsUpgradeInfo] = s.useState(null);
|
|
5343
5344
|
const { handleAIAction } = useAIActions({
|
|
5344
5345
|
licenseKey: licenseData?.licenseKey,
|
|
5345
5346
|
editorInstanceRef,
|
|
@@ -5349,7 +5350,7 @@ const Editor = m.forwardRef(({
|
|
|
5349
5350
|
setShowCreditsModal(true);
|
|
5350
5351
|
}
|
|
5351
5352
|
});
|
|
5352
|
-
|
|
5353
|
+
s.useEffect(() => {
|
|
5353
5354
|
if (licenseData?.licenseKey) {
|
|
5354
5355
|
window.__MAGIC_EDITOR_LICENSE_KEY__ = licenseData.licenseKey;
|
|
5355
5356
|
}
|
|
@@ -5357,22 +5358,22 @@ const Editor = m.forwardRef(({
|
|
|
5357
5358
|
delete window.__MAGIC_EDITOR_LICENSE_KEY__;
|
|
5358
5359
|
};
|
|
5359
5360
|
}, [licenseData?.licenseKey]);
|
|
5360
|
-
const [blocksCount, setBlocksCount] =
|
|
5361
|
-
const [wordCount, setWordCount] =
|
|
5362
|
-
const [charCount, setCharCount] =
|
|
5363
|
-
const [isFocused, setIsFocused] =
|
|
5364
|
-
const [isFullscreen, setIsFullscreen] =
|
|
5365
|
-
const [editorHeight, setEditorHeight] =
|
|
5366
|
-
const [mediaLibBlockIndex, setMediaLibBlockIndex] =
|
|
5367
|
-
const [isMediaLibOpen, setIsMediaLibOpen] =
|
|
5368
|
-
const [showAIPopup, setShowAIPopup] =
|
|
5369
|
-
const [showAIToolbar, setShowAIToolbar] =
|
|
5370
|
-
const [aiToolbarPosition, setAIToolbarPosition] =
|
|
5371
|
-
const [aiSelectedText, setAISelectedText] =
|
|
5372
|
-
const aiSelectionRangeRef =
|
|
5373
|
-
const [aiLoading, setAILoading] =
|
|
5374
|
-
const [showVersionHistory, setShowVersionHistory] =
|
|
5375
|
-
|
|
5361
|
+
const [blocksCount, setBlocksCount] = s.useState(0);
|
|
5362
|
+
const [wordCount, setWordCount] = s.useState(0);
|
|
5363
|
+
const [charCount, setCharCount] = s.useState(0);
|
|
5364
|
+
const [isFocused, setIsFocused] = s.useState(false);
|
|
5365
|
+
const [isFullscreen, setIsFullscreen] = s.useState(false);
|
|
5366
|
+
const [editorHeight, setEditorHeight] = s.useState(400);
|
|
5367
|
+
const [mediaLibBlockIndex, setMediaLibBlockIndex] = s.useState(-1);
|
|
5368
|
+
const [isMediaLibOpen, setIsMediaLibOpen] = s.useState(false);
|
|
5369
|
+
const [showAIPopup, setShowAIPopup] = s.useState(false);
|
|
5370
|
+
const [showAIToolbar, setShowAIToolbar] = s.useState(false);
|
|
5371
|
+
const [aiToolbarPosition, setAIToolbarPosition] = s.useState({ top: 0, left: 0 });
|
|
5372
|
+
const [aiSelectedText, setAISelectedText] = s.useState("");
|
|
5373
|
+
const aiSelectionRangeRef = s.useRef(null);
|
|
5374
|
+
const [aiLoading, setAILoading] = s.useState(false);
|
|
5375
|
+
const [showVersionHistory, setShowVersionHistory] = s.useState(false);
|
|
5376
|
+
s.useEffect(() => {
|
|
5376
5377
|
if (!isWebtoolsAvailable || !editorRef.current) return;
|
|
5377
5378
|
const updateWebtoolsSelection = () => {
|
|
5378
5379
|
const selection = window.getSelection();
|
|
@@ -5416,13 +5417,13 @@ const Editor = m.forwardRef(({
|
|
|
5416
5417
|
document.removeEventListener("selectionchange", updateWebtoolsSelection);
|
|
5417
5418
|
};
|
|
5418
5419
|
}, [isWebtoolsAvailable, isReady]);
|
|
5419
|
-
const serializedInitialValue =
|
|
5420
|
+
const serializedInitialValue = s.useMemo(() => {
|
|
5420
5421
|
if (!value) {
|
|
5421
5422
|
return "";
|
|
5422
5423
|
}
|
|
5423
5424
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
5424
5425
|
}, [value]);
|
|
5425
|
-
const serializeForCompare =
|
|
5426
|
+
const serializeForCompare = s.useCallback((payload) => {
|
|
5426
5427
|
if (!payload) return "";
|
|
5427
5428
|
try {
|
|
5428
5429
|
const dataObj = typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
@@ -5437,9 +5438,9 @@ const Editor = m.forwardRef(({
|
|
|
5437
5438
|
return "";
|
|
5438
5439
|
}
|
|
5439
5440
|
}, []);
|
|
5440
|
-
const collabRoomId =
|
|
5441
|
+
const collabRoomId = s.useMemo(() => buildRoomId(name), [name]);
|
|
5441
5442
|
const collabEnabled = (attribute?.options?.collaboration?.enabled ?? true) && !disabled;
|
|
5442
|
-
const renderFromYDocRef =
|
|
5443
|
+
const renderFromYDocRef = s.useRef(null);
|
|
5443
5444
|
const {
|
|
5444
5445
|
doc: yDoc,
|
|
5445
5446
|
blocksMap: yBlocksMap,
|
|
@@ -5476,8 +5477,8 @@ const Editor = m.forwardRef(({
|
|
|
5476
5477
|
}
|
|
5477
5478
|
}
|
|
5478
5479
|
});
|
|
5479
|
-
const yTextBindingsRef =
|
|
5480
|
-
const bindBlockToYText =
|
|
5480
|
+
const yTextBindingsRef = s.useRef(/* @__PURE__ */ new Map());
|
|
5481
|
+
const bindBlockToYText = s.useCallback((blockId, element) => {
|
|
5481
5482
|
if (!collabEnabled || !blockId || !element || !yTextMap) return;
|
|
5482
5483
|
if (yTextBindingsRef.current.has(blockId)) {
|
|
5483
5484
|
const existing = yTextBindingsRef.current.get(blockId);
|
|
@@ -5552,7 +5553,7 @@ const Editor = m.forwardRef(({
|
|
|
5552
5553
|
});
|
|
5553
5554
|
console.log("[Magic Editor X] [CHAR-SYNC] Bound block to Y.Text:", blockId);
|
|
5554
5555
|
}, [collabEnabled, yTextMap, yDoc, getBlockText, collabHtmlToDelta, collabDeltaToHtml]);
|
|
5555
|
-
const unbindBlockFromYText =
|
|
5556
|
+
const unbindBlockFromYText = s.useCallback((blockId) => {
|
|
5556
5557
|
const binding = yTextBindingsRef.current.get(blockId);
|
|
5557
5558
|
if (!binding) return;
|
|
5558
5559
|
binding.ytext.unobserve(binding.ytextObserver);
|
|
@@ -5560,7 +5561,7 @@ const Editor = m.forwardRef(({
|
|
|
5560
5561
|
yTextBindingsRef.current.delete(blockId);
|
|
5561
5562
|
console.log("[Magic Editor X] [CHAR-SYNC] Unbound block from Y.Text:", blockId);
|
|
5562
5563
|
}, []);
|
|
5563
|
-
const bindAllBlocksToYText =
|
|
5564
|
+
const bindAllBlocksToYText = s.useCallback(() => {
|
|
5564
5565
|
if (!collabEnabled || !editorInstanceRef.current || !yTextMap) return;
|
|
5565
5566
|
const editor = editorInstanceRef.current;
|
|
5566
5567
|
if (!editor.blocks || typeof editor.blocks.getBlocksCount !== "function") return;
|
|
@@ -5588,8 +5589,8 @@ const Editor = m.forwardRef(({
|
|
|
5588
5589
|
}
|
|
5589
5590
|
}
|
|
5590
5591
|
}, [collabEnabled, yTextMap, getBlockText, setBlockText, bindBlockToYText]);
|
|
5591
|
-
const blockObserverRef =
|
|
5592
|
-
|
|
5592
|
+
const blockObserverRef = s.useRef(null);
|
|
5593
|
+
s.useEffect(() => {
|
|
5593
5594
|
if (!collabEnabled || !editorRef.current || !yTextMap) return;
|
|
5594
5595
|
const observer = new MutationObserver((mutations) => {
|
|
5595
5596
|
let hasNewBlocks = false;
|
|
@@ -5620,7 +5621,7 @@ const Editor = m.forwardRef(({
|
|
|
5620
5621
|
blockObserverRef.current = null;
|
|
5621
5622
|
};
|
|
5622
5623
|
}, [collabEnabled, yTextMap, bindAllBlocksToYText]);
|
|
5623
|
-
|
|
5624
|
+
s.useEffect(() => {
|
|
5624
5625
|
return () => {
|
|
5625
5626
|
yTextBindingsRef.current.forEach((binding, blockId) => {
|
|
5626
5627
|
binding.ytext.unobserve(binding.ytextObserver);
|
|
@@ -5637,12 +5638,12 @@ const Editor = m.forwardRef(({
|
|
|
5637
5638
|
restoreSnapshot,
|
|
5638
5639
|
createSnapshot
|
|
5639
5640
|
} = useVersionHistory();
|
|
5640
|
-
|
|
5641
|
+
s.useEffect(() => {
|
|
5641
5642
|
if (showVersionHistory && collabRoomId) {
|
|
5642
5643
|
fetchSnapshots(collabRoomId);
|
|
5643
5644
|
}
|
|
5644
5645
|
}, [showVersionHistory, collabRoomId, fetchSnapshots]);
|
|
5645
|
-
|
|
5646
|
+
s.useMemo(() => {
|
|
5646
5647
|
switch (collabRole) {
|
|
5647
5648
|
case "viewer":
|
|
5648
5649
|
return { icon: "V", text: "Viewer", color: "#3b82f6" };
|
|
@@ -5654,7 +5655,7 @@ const Editor = m.forwardRef(({
|
|
|
5654
5655
|
return null;
|
|
5655
5656
|
}
|
|
5656
5657
|
}, [collabRole]);
|
|
5657
|
-
|
|
5658
|
+
s.useMemo(() => {
|
|
5658
5659
|
switch (collabStatus) {
|
|
5659
5660
|
case "connected":
|
|
5660
5661
|
if (collabRole === "viewer") {
|
|
@@ -5678,15 +5679,15 @@ const Editor = m.forwardRef(({
|
|
|
5678
5679
|
return "Bereit";
|
|
5679
5680
|
}
|
|
5680
5681
|
}, [collabStatus, collabRole]);
|
|
5681
|
-
|
|
5682
|
-
const activeEditors =
|
|
5682
|
+
s.useMemo(() => collabPeers.slice(0, 3), [collabPeers]);
|
|
5683
|
+
const activeEditors = s.useMemo(() => {
|
|
5683
5684
|
return Object.values(collabAwareness || {}).filter(
|
|
5684
5685
|
(entry) => entry?.user && Date.now() - entry.lastUpdate < 3e4
|
|
5685
5686
|
);
|
|
5686
5687
|
}, [collabAwareness]);
|
|
5687
|
-
const lastCursorUpdateRef =
|
|
5688
|
-
const lastEmittedPositionRef =
|
|
5689
|
-
const getAbsoluteOffset =
|
|
5688
|
+
const lastCursorUpdateRef = s.useRef(0);
|
|
5689
|
+
const lastEmittedPositionRef = s.useRef(null);
|
|
5690
|
+
const getAbsoluteOffset = s.useCallback((container, node, offset) => {
|
|
5690
5691
|
if (!container || !node) return 0;
|
|
5691
5692
|
let absoluteOffset = 0;
|
|
5692
5693
|
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null, false);
|
|
@@ -5700,7 +5701,7 @@ const Editor = m.forwardRef(({
|
|
|
5700
5701
|
}
|
|
5701
5702
|
return absoluteOffset + offset;
|
|
5702
5703
|
}, []);
|
|
5703
|
-
const emitCursorPosition =
|
|
5704
|
+
const emitCursorPosition = s.useCallback(() => {
|
|
5704
5705
|
if (!collabEnabled || !emitAwareness || collabStatus !== "connected") {
|
|
5705
5706
|
return;
|
|
5706
5707
|
}
|
|
@@ -5750,7 +5751,7 @@ const Editor = m.forwardRef(({
|
|
|
5750
5751
|
} catch (err) {
|
|
5751
5752
|
}
|
|
5752
5753
|
}, [collabEnabled, emitAwareness, collabStatus, getAbsoluteOffset]);
|
|
5753
|
-
|
|
5754
|
+
s.useEffect(() => {
|
|
5754
5755
|
if (!collabEnabled || !editorRef.current) {
|
|
5755
5756
|
return void 0;
|
|
5756
5757
|
}
|
|
@@ -5790,7 +5791,7 @@ const Editor = m.forwardRef(({
|
|
|
5790
5791
|
}
|
|
5791
5792
|
};
|
|
5792
5793
|
}, [collabEnabled, emitCursorPosition]);
|
|
5793
|
-
const findTextPosition =
|
|
5794
|
+
const findTextPosition = s.useCallback((container, targetOffset) => {
|
|
5794
5795
|
if (!container || targetOffset === null || targetOffset === void 0) {
|
|
5795
5796
|
return null;
|
|
5796
5797
|
}
|
|
@@ -5820,8 +5821,8 @@ const Editor = m.forwardRef(({
|
|
|
5820
5821
|
}
|
|
5821
5822
|
return null;
|
|
5822
5823
|
}, []);
|
|
5823
|
-
|
|
5824
|
-
|
|
5824
|
+
s.useRef(null);
|
|
5825
|
+
s.useEffect(() => {
|
|
5825
5826
|
if (!collabEnabled || !editorRef.current || !isReady) {
|
|
5826
5827
|
return void 0;
|
|
5827
5828
|
}
|
|
@@ -5931,7 +5932,7 @@ const Editor = m.forwardRef(({
|
|
|
5931
5932
|
cursors?.forEach((el) => el.remove());
|
|
5932
5933
|
};
|
|
5933
5934
|
}, [collabEnabled, activeEditors, isReady, findTextPosition]);
|
|
5934
|
-
|
|
5935
|
+
s.useEffect(() => {
|
|
5935
5936
|
const state = {
|
|
5936
5937
|
status: collabStatus,
|
|
5937
5938
|
peers: collabPeers,
|
|
@@ -5948,13 +5949,13 @@ const Editor = m.forwardRef(({
|
|
|
5948
5949
|
}));
|
|
5949
5950
|
};
|
|
5950
5951
|
}, [collabStatus, collabPeers, collabError]);
|
|
5951
|
-
const isApplyingRemoteRef =
|
|
5952
|
-
const pendingRenderRef =
|
|
5953
|
-
const lastSerializedValueRef =
|
|
5954
|
-
|
|
5952
|
+
const isApplyingRemoteRef = s.useRef(false);
|
|
5953
|
+
const pendingRenderRef = s.useRef(null);
|
|
5954
|
+
const lastSerializedValueRef = s.useRef(serializeForCompare(serializedInitialValue || null));
|
|
5955
|
+
s.useEffect(() => {
|
|
5955
5956
|
lastSerializedValueRef.current = serializeForCompare(serializedInitialValue || null);
|
|
5956
5957
|
}, [serializedInitialValue, serializeForCompare]);
|
|
5957
|
-
const calculateStats =
|
|
5958
|
+
const calculateStats = s.useCallback((data) => {
|
|
5958
5959
|
if (!data?.blocks) {
|
|
5959
5960
|
setWordCount(0);
|
|
5960
5961
|
setCharCount(0);
|
|
@@ -5974,7 +5975,7 @@ const Editor = m.forwardRef(({
|
|
|
5974
5975
|
setCharCount(plainText.length);
|
|
5975
5976
|
setWordCount(plainText.split(/\s+/).filter((w) => w.length > 0).length);
|
|
5976
5977
|
}, []);
|
|
5977
|
-
const renderFromYDoc =
|
|
5978
|
+
const renderFromYDoc = s.useCallback(async () => {
|
|
5978
5979
|
if (!collabEnabled || !yBlocksMap || !yDoc) {
|
|
5979
5980
|
return;
|
|
5980
5981
|
}
|
|
@@ -6089,10 +6090,10 @@ const Editor = m.forwardRef(({
|
|
|
6089
6090
|
isApplyingRemoteRef.current = false;
|
|
6090
6091
|
}
|
|
6091
6092
|
}, [collabEnabled, yBlocksMap, yDoc, yMetaMap]);
|
|
6092
|
-
|
|
6093
|
+
s.useEffect(() => {
|
|
6093
6094
|
renderFromYDocRef.current = renderFromYDoc;
|
|
6094
6095
|
}, [renderFromYDoc]);
|
|
6095
|
-
const pushLocalToCollab =
|
|
6096
|
+
const pushLocalToCollab = s.useCallback((payload) => {
|
|
6096
6097
|
console.log("[Magic Editor X] [PUSH] pushLocalToCollab called, enabled:", collabEnabled, "yDoc:", !!yDoc, "yBlocksMap:", !!yBlocksMap);
|
|
6097
6098
|
if (!collabEnabled || !yDoc || !yBlocksMap) {
|
|
6098
6099
|
console.log("[Magic Editor X] [SKIP] Skipping push - not enabled or missing yDoc/yBlocksMap");
|
|
@@ -6137,20 +6138,20 @@ const Editor = m.forwardRef(({
|
|
|
6137
6138
|
console.error("[Magic Editor X] Failed to push local update", error2);
|
|
6138
6139
|
}
|
|
6139
6140
|
}, [collabEnabled, yDoc, yBlocksMap, yMetaMap]);
|
|
6140
|
-
const pushLocalToCollabRef =
|
|
6141
|
-
|
|
6141
|
+
const pushLocalToCollabRef = s.useRef(pushLocalToCollab);
|
|
6142
|
+
s.useEffect(() => {
|
|
6142
6143
|
pushLocalToCollabRef.current = pushLocalToCollab;
|
|
6143
6144
|
}, [pushLocalToCollab]);
|
|
6144
6145
|
const customPlaceholder = attribute?.options?.placeholder || placeholder || "Start writing your amazing content...";
|
|
6145
6146
|
attribute?.options?.minHeight || 400;
|
|
6146
|
-
const mediaLibToggleFunc =
|
|
6147
|
+
const mediaLibToggleFunc = s.useCallback(
|
|
6147
6148
|
getToggleFunc({
|
|
6148
6149
|
openStateSetter: setIsMediaLibOpen,
|
|
6149
6150
|
indexStateSetter: setMediaLibBlockIndex
|
|
6150
6151
|
}),
|
|
6151
6152
|
[]
|
|
6152
6153
|
);
|
|
6153
|
-
const handleMediaLibChange =
|
|
6154
|
+
const handleMediaLibChange = s.useCallback(
|
|
6154
6155
|
(data) => {
|
|
6155
6156
|
changeFunc({
|
|
6156
6157
|
indexStateSetter: setMediaLibBlockIndex,
|
|
@@ -6162,8 +6163,8 @@ const Editor = m.forwardRef(({
|
|
|
6162
6163
|
},
|
|
6163
6164
|
[mediaLibBlockIndex, mediaLibToggleFunc]
|
|
6164
6165
|
);
|
|
6165
|
-
const [customBlockImageCallback, setCustomBlockImageCallback] =
|
|
6166
|
-
const handleCustomBlockMediaLibChange =
|
|
6166
|
+
const [customBlockImageCallback, setCustomBlockImageCallback] = s.useState(null);
|
|
6167
|
+
const handleCustomBlockMediaLibChange = s.useCallback((data) => {
|
|
6167
6168
|
if (customBlockImageCallback && window.__MAGIC_EDITOR_IMAGE_CALLBACKS__) {
|
|
6168
6169
|
const callback = window.__MAGIC_EDITOR_IMAGE_CALLBACKS__[customBlockImageCallback];
|
|
6169
6170
|
if (callback) {
|
|
@@ -6182,7 +6183,7 @@ const Editor = m.forwardRef(({
|
|
|
6182
6183
|
setCustomBlockImageCallback(null);
|
|
6183
6184
|
setIsMediaLibOpen(false);
|
|
6184
6185
|
}, [customBlockImageCallback]);
|
|
6185
|
-
|
|
6186
|
+
s.useEffect(() => {
|
|
6186
6187
|
const handleOpenMediaLib = (event) => {
|
|
6187
6188
|
const { callbackId, allowedTypes } = event.detail || {};
|
|
6188
6189
|
if (callbackId) {
|
|
@@ -6193,7 +6194,7 @@ const Editor = m.forwardRef(({
|
|
|
6193
6194
|
window.addEventListener("magic-editor-open-media-lib", handleOpenMediaLib);
|
|
6194
6195
|
return () => window.removeEventListener("magic-editor-open-media-lib", handleOpenMediaLib);
|
|
6195
6196
|
}, []);
|
|
6196
|
-
const toggleFullscreen =
|
|
6197
|
+
const toggleFullscreen = s.useCallback(() => {
|
|
6197
6198
|
setIsFullscreen((prev) => {
|
|
6198
6199
|
if (!prev) {
|
|
6199
6200
|
document.body.classList.add("editor-fullscreen");
|
|
@@ -6203,7 +6204,7 @@ const Editor = m.forwardRef(({
|
|
|
6203
6204
|
return !prev;
|
|
6204
6205
|
});
|
|
6205
6206
|
}, []);
|
|
6206
|
-
|
|
6207
|
+
s.useEffect(() => {
|
|
6207
6208
|
const handleKeyDown = (e) => {
|
|
6208
6209
|
if (e.key === "Escape" && isFullscreen) {
|
|
6209
6210
|
toggleFullscreen();
|
|
@@ -6215,7 +6216,7 @@ const Editor = m.forwardRef(({
|
|
|
6215
6216
|
window.addEventListener("keydown", handleKeyDown);
|
|
6216
6217
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
6217
6218
|
}, [isFullscreen, toggleFullscreen]);
|
|
6218
|
-
const handleAIAssistant =
|
|
6219
|
+
const handleAIAssistant = s.useCallback(() => {
|
|
6219
6220
|
const selection = window.getSelection();
|
|
6220
6221
|
let text = selection?.toString().trim();
|
|
6221
6222
|
if (!text && editorInstanceRef.current && isReady) {
|
|
@@ -6256,7 +6257,7 @@ const Editor = m.forwardRef(({
|
|
|
6256
6257
|
setAISelectedText(text);
|
|
6257
6258
|
setShowAIToolbar(true);
|
|
6258
6259
|
}, [isReady]);
|
|
6259
|
-
const handleInsertBlock =
|
|
6260
|
+
const handleInsertBlock = s.useCallback((blockType) => {
|
|
6260
6261
|
if (!editorInstanceRef.current || !isReady) return;
|
|
6261
6262
|
if (blockType === "mediaLib") {
|
|
6262
6263
|
if (collabEnabled && collabCanEdit === false) {
|
|
@@ -6276,7 +6277,7 @@ const Editor = m.forwardRef(({
|
|
|
6276
6277
|
editor.blocks.insert(blockType, {}, {}, lastIndex, true);
|
|
6277
6278
|
editor.caret.setToBlock(lastIndex);
|
|
6278
6279
|
}, [isReady, collabEnabled, collabCanEdit]);
|
|
6279
|
-
const handleClear =
|
|
6280
|
+
const handleClear = s.useCallback(async () => {
|
|
6280
6281
|
if (!editorInstanceRef.current || !isReady) return;
|
|
6281
6282
|
if (window.confirm("Clear all content? This cannot be undone.")) {
|
|
6282
6283
|
await editorInstanceRef.current.clear();
|
|
@@ -6289,12 +6290,12 @@ const Editor = m.forwardRef(({
|
|
|
6289
6290
|
setCharCount(0);
|
|
6290
6291
|
}
|
|
6291
6292
|
}, [isReady, name, onChange, pushLocalToCollab]);
|
|
6292
|
-
const handleCopy =
|
|
6293
|
+
const handleCopy = s.useCallback(async () => {
|
|
6293
6294
|
if (!editorInstanceRef.current || !isReady) return;
|
|
6294
6295
|
const data = await editorInstanceRef.current.save();
|
|
6295
6296
|
await navigator.clipboard.writeText(JSON.stringify(data, null, 2));
|
|
6296
6297
|
}, [isReady]);
|
|
6297
|
-
|
|
6298
|
+
s.useEffect(() => {
|
|
6298
6299
|
if (isLoadingCustomBlocks) {
|
|
6299
6300
|
console.log("[Magic Editor X] Waiting for custom blocks to load...");
|
|
6300
6301
|
return;
|
|
@@ -6491,7 +6492,7 @@ const Editor = m.forwardRef(({
|
|
|
6491
6492
|
document.body.classList.remove("editor-fullscreen");
|
|
6492
6493
|
};
|
|
6493
6494
|
}, [isLoadingCustomBlocks, customBlocks]);
|
|
6494
|
-
|
|
6495
|
+
s.useEffect(() => {
|
|
6495
6496
|
const editor = editorInstanceRef.current;
|
|
6496
6497
|
if (!editor || !isReady) return;
|
|
6497
6498
|
const shouldBeReadOnly = disabled || collabEnabled && collabCanEdit === false;
|
|
@@ -6529,11 +6530,11 @@ const Editor = m.forwardRef(({
|
|
|
6529
6530
|
{ icon: outline.ExclamationTriangleIcon, label: "Warning", block: "warning" },
|
|
6530
6531
|
{ icon: outline.MinusIcon, label: "Divider", block: "delimiter" }
|
|
6531
6532
|
];
|
|
6532
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(getTranslation.
|
|
6533
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(getTranslation.Dd.Root, { name, id: name, error, required, hint, children: [
|
|
6533
6534
|
/* @__PURE__ */ jsxRuntime.jsx(FullscreenGlobalStyle, {}),
|
|
6534
6535
|
/* @__PURE__ */ jsxRuntime.jsx(EditorJSGlobalStyles, {}),
|
|
6535
6536
|
/* @__PURE__ */ jsxRuntime.jsx(tools.AIToast, {}),
|
|
6536
|
-
label && !isFullscreen && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
6537
|
+
label && !isFullscreen && /* @__PURE__ */ jsxRuntime.jsx(getTranslation.Dd.Label, { action: labelAction, children: label }),
|
|
6537
6538
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6538
6539
|
EditorContainer,
|
|
6539
6540
|
{
|
|
@@ -6747,7 +6748,7 @@ const Editor = m.forwardRef(({
|
|
|
6747
6748
|
onBlur: () => setIsFocused(false),
|
|
6748
6749
|
children: [
|
|
6749
6750
|
!isReady && /* @__PURE__ */ jsxRuntime.jsxs(LoadingOverlay, { children: [
|
|
6750
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
6751
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.kt, { small: true }),
|
|
6751
6752
|
/* @__PURE__ */ jsxRuntime.jsx(LoadingText, { children: "Initializing editor..." })
|
|
6752
6753
|
] }),
|
|
6753
6754
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -6832,8 +6833,8 @@ const Editor = m.forwardRef(({
|
|
|
6832
6833
|
}
|
|
6833
6834
|
),
|
|
6834
6835
|
!isFullscreen && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6835
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
6836
|
-
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.
|
|
6836
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Dd.Hint, {}),
|
|
6837
|
+
/* @__PURE__ */ jsxRuntime.jsx(getTranslation.Dd.Error, {})
|
|
6837
6838
|
] }),
|
|
6838
6839
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6839
6840
|
MediaLibComponent,
|