magic-editor-x 2.3.0 → 2.4.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +299 -142
  3. package/dist/admin/AuditPage-C2u6z4aN.js +381 -0
  4. package/dist/admin/AuditPage-guB0SiGS.mjs +381 -0
  5. package/dist/admin/{ConfigurationPage-C-UktL1x.js → ConfigurationPage-D6uya-J1.js} +228 -13
  6. package/dist/admin/{ConfigurationPage-BxLHIQdo.mjs → ConfigurationPage-DiEpF1Rr.mjs} +222 -7
  7. package/dist/admin/ConfirmAction-CUhpngYU.js +71 -0
  8. package/dist/admin/ConfirmAction-CZjpduc3.mjs +72 -0
  9. package/dist/admin/{CustomBlocksPage-D8aMbVXc.mjs → CustomBlocksPage-Byt10-6c.mjs} +6 -4
  10. package/dist/admin/{CustomBlocksPage-CxcTfdOT.js → CustomBlocksPage-DP3h_wNd.js} +21 -19
  11. package/dist/admin/MentionsWidget-C2OCAmqq.js +227 -0
  12. package/dist/admin/MentionsWidget-sMkM9mHX.mjs +225 -0
  13. package/dist/admin/{TemplatesPage-Hn6gyu2l.js → TemplatesPage-DrSJdteI.js} +313 -17
  14. package/dist/admin/{TemplatesPage-jhYi6Zdf.mjs → TemplatesPage-Yp4OqFE2.mjs} +305 -9
  15. package/dist/admin/{ConfirmAction-DuQwvRYi.mjs → api-2ZRpHM3d.mjs} +19 -70
  16. package/dist/admin/{ConfirmAction-zLuIFj8t.js → api-bix9RLLI.js} +19 -70
  17. package/dist/admin/auditText-DIIYVR6k.mjs +110 -0
  18. package/dist/admin/auditText-DUhWu2Nx.js +109 -0
  19. package/dist/admin/comments-C7P41lan.js +86 -0
  20. package/dist/admin/comments-hfIbLQNO.mjs +87 -0
  21. package/dist/admin/{de-BMY2LBaa.mjs → de-BNPIGqhs.mjs} +41 -2
  22. package/dist/admin/{de-2Ie5jy7j.js → de-BhhGss1l.js} +41 -2
  23. package/dist/admin/{de-DOiGaTNX.mjs → de-CKz6CG3V.mjs} +191 -5
  24. package/dist/admin/{de-C3AsGauQ.js → de-CbBDnXeT.js} +140 -1
  25. package/dist/admin/{de-BUS1hUw0.mjs → de-DiCZrmH8.mjs} +140 -1
  26. package/dist/admin/{de-B1X46JJZ.js → de-zcV8D7nt.js} +191 -5
  27. package/dist/admin/{en-Ah-Cw0Wd.js → en-B9ApE1y1.js} +41 -2
  28. package/dist/admin/{en-CDg_18Bt.js → en-BMWhILnj.js} +191 -5
  29. package/dist/admin/{en-BkEjpC3i.js → en-CpehF0Kv.js} +140 -1
  30. package/dist/admin/{en-GCzgS9Aw.mjs → en-DCPMqFIa.mjs} +140 -1
  31. package/dist/admin/{en-CU6UzV4g.mjs → en-cYzqbASF.mjs} +191 -5
  32. package/dist/admin/{en-CvFiqti2.mjs → en-gFLeK9Ng.mjs} +41 -2
  33. package/dist/admin/{es-DbKHZz5l.mjs → es-BmwBgEgz.mjs} +41 -2
  34. package/dist/admin/{es-Cr8JH85N.js → es-C0W31rl8.js} +41 -2
  35. package/dist/admin/{es-BCpJmUEM.js → es-CQPh8PXw.js} +191 -5
  36. package/dist/admin/{es-C4pEnDRv.js → es-CawpzwyC.js} +140 -1
  37. package/dist/admin/{es-DHBBZKl2.mjs → es-Chs37IBR.mjs} +140 -1
  38. package/dist/admin/{es-BmfffNM2.mjs → es-DCamt1ek.mjs} +191 -5
  39. package/dist/admin/{fr-DQJ_7aq5.mjs → fr-CMWBNE5D.mjs} +41 -2
  40. package/dist/admin/{fr-C2aLSwEu.js → fr-COOsqexl.js} +140 -1
  41. package/dist/admin/{fr-Dvq4xk2e.mjs → fr-Dp5-XP29.mjs} +140 -1
  42. package/dist/admin/{fr-ZcN0yM_2.js → fr-DpC44Ol8.js} +191 -5
  43. package/dist/admin/{fr-OJ4VW1kh.js → fr-iGeIfEcU.js} +41 -2
  44. package/dist/admin/{fr-DZd2XJP6.mjs → fr-oW0t8bT5.mjs} +191 -5
  45. package/dist/admin/{index-Cm-fFUhE.js → index-64wc26Bl.js} +13851 -6746
  46. package/dist/admin/{index-XgfwqLfV.mjs → index-BVjf1gVC.mjs} +13788 -6682
  47. package/dist/admin/{index-BHBRr562.js → index-D6Z7i8ba.js} +1003 -53
  48. package/dist/admin/{index-CQk1XeNb.mjs → index-D_Fv8Non.mjs} +1032 -82
  49. package/dist/admin/index.js +2 -1
  50. package/dist/admin/index.mjs +3 -2
  51. package/dist/admin/math-CIQ4Z_mY.mjs +47 -0
  52. package/dist/admin/math-vsK_06ZR.js +49 -0
  53. package/dist/admin/{pt-D0I0_JYs.js → pt-BHmXk2d9.js} +41 -2
  54. package/dist/admin/{pt-CImqDnLB.js → pt-Bo0Pm_Pt.js} +191 -5
  55. package/dist/admin/{pt-CilDggGF.mjs → pt-DALDvfBn.mjs} +140 -1
  56. package/dist/admin/{pt-BSLzA17U.mjs → pt-DFNgZ5_k.mjs} +41 -2
  57. package/dist/admin/{pt-DX0OAIoL.js → pt-DXy7G1x7.js} +140 -1
  58. package/dist/admin/{pt-C3UdeIpd.mjs → pt-uGpfRQLC.mjs} +191 -5
  59. package/dist/admin/{useT-D3sM9Zf7.js → useT-BXJLIPN4.js} +1 -1
  60. package/dist/admin/{useT-CmaeZbCr.mjs → useT-CLPhBmBC.mjs} +1 -1
  61. package/dist/blocks/index.d.mts +2 -0
  62. package/dist/blocks/index.d.ts +2 -0
  63. package/dist/blocks/index.js +13 -2
  64. package/dist/blocks/index.mjs +13 -2
  65. package/dist/math/index.d.mts +27 -0
  66. package/dist/math/index.d.ts +27 -0
  67. package/dist/math/index.js +164 -0
  68. package/dist/math/index.mjs +134 -0
  69. package/dist/react/index.js +673 -91
  70. package/dist/react/index.mjs +673 -91
  71. package/dist/render/index.d.mts +26 -0
  72. package/dist/render/index.d.ts +26 -0
  73. package/dist/render/index.js +779 -106
  74. package/dist/render/index.mjs +779 -106
  75. package/dist/server/index.js +10419 -4103
  76. package/dist/server/index.mjs +10419 -4103
  77. package/dist/vue/index.js +673 -91
  78. package/dist/vue/index.mjs +673 -91
  79. package/package.json +8 -2
  80. package/schema/magic-editor-x.schema.json +127 -2
  81. package/types/blocks.d.ts +2 -0
  82. package/types/index.d.ts +42 -0
  83. package/types/math.d.ts +27 -0
  84. package/types/render.d.ts +26 -0
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const ReactNamespace = require("react");
4
+ const designSystem = require("@strapi/design-system");
5
+ const admin = require("@strapi/strapi/admin");
6
+ const canTakeFocus = (el) => Boolean(
7
+ el && el.isConnected && typeof el.focus === "function" && !el.disabled && (typeof el.getAttribute !== "function" || el.getAttribute("aria-disabled") !== "true")
8
+ );
9
+ const pickFocusTarget = (opener, fallback) => {
10
+ if (canTakeFocus(opener)) return opener;
11
+ if (canTakeFocus(fallback)) return fallback;
12
+ return null;
13
+ };
14
+ const refocusIfLost = (opener, fallback, doc = globalThis.document) => {
15
+ if (!doc) return;
16
+ const active = doc.activeElement;
17
+ if (active && active !== doc.body) return;
18
+ const target = pickFocusTarget(opener, fallback);
19
+ if (target) target.focus();
20
+ };
21
+ const ConfirmAction = ({
22
+ trigger,
23
+ title,
24
+ body,
25
+ confirmLabel,
26
+ onConfirm,
27
+ variant = "danger",
28
+ disabled = false,
29
+ fallbackFocusRef
30
+ }) => {
31
+ const [open, setOpen] = ReactNamespace.useState(false);
32
+ const [busy, setBusy] = ReactNamespace.useState(false);
33
+ const triggerRef = ReactNamespace.useRef(null);
34
+ const restoreFocus = () => requestAnimationFrame(() => {
35
+ const active = document.activeElement;
36
+ if (active && active !== document.body) return;
37
+ const target = pickFocusTarget(triggerRef.current, fallbackFocusRef && fallbackFocusRef.current);
38
+ if (target) target.focus();
39
+ });
40
+ const onOpenChange = (next) => {
41
+ if (busy) return;
42
+ setOpen(next);
43
+ if (!next) restoreFocus();
44
+ };
45
+ const confirm = async (event) => {
46
+ if (event && typeof event.preventDefault === "function") event.preventDefault();
47
+ setBusy(true);
48
+ try {
49
+ await onConfirm();
50
+ setOpen(false);
51
+ restoreFocus();
52
+ } catch {
53
+ } finally {
54
+ setBusy(false);
55
+ }
56
+ };
57
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { open, onOpenChange, children: [
58
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }),
59
+ /* @__PURE__ */ jsxRuntime.jsx(
60
+ admin.ConfirmDialog,
61
+ {
62
+ title,
63
+ variant,
64
+ endAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { fullWidth: true, variant, onClick: confirm, loading: busy, disabled: busy, children: confirmLabel }),
65
+ children: body
66
+ }
67
+ )
68
+ ] });
69
+ };
70
+ exports.ConfirmAction = ConfirmAction;
71
+ exports.refocusIfLost = refocusIfLost;
@@ -0,0 +1,72 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useState, useRef } from "react";
3
+ import { Dialog, Button } from "@strapi/design-system";
4
+ import { ConfirmDialog } from "@strapi/strapi/admin";
5
+ const canTakeFocus = (el) => Boolean(
6
+ el && el.isConnected && typeof el.focus === "function" && !el.disabled && (typeof el.getAttribute !== "function" || el.getAttribute("aria-disabled") !== "true")
7
+ );
8
+ const pickFocusTarget = (opener, fallback) => {
9
+ if (canTakeFocus(opener)) return opener;
10
+ if (canTakeFocus(fallback)) return fallback;
11
+ return null;
12
+ };
13
+ const refocusIfLost = (opener, fallback, doc = globalThis.document) => {
14
+ if (!doc) return;
15
+ const active = doc.activeElement;
16
+ if (active && active !== doc.body) return;
17
+ const target = pickFocusTarget(opener, fallback);
18
+ if (target) target.focus();
19
+ };
20
+ const ConfirmAction = ({
21
+ trigger,
22
+ title,
23
+ body,
24
+ confirmLabel,
25
+ onConfirm,
26
+ variant = "danger",
27
+ disabled = false,
28
+ fallbackFocusRef
29
+ }) => {
30
+ const [open, setOpen] = useState(false);
31
+ const [busy, setBusy] = useState(false);
32
+ const triggerRef = useRef(null);
33
+ const restoreFocus = () => requestAnimationFrame(() => {
34
+ const active = document.activeElement;
35
+ if (active && active !== document.body) return;
36
+ const target = pickFocusTarget(triggerRef.current, fallbackFocusRef && fallbackFocusRef.current);
37
+ if (target) target.focus();
38
+ });
39
+ const onOpenChange = (next) => {
40
+ if (busy) return;
41
+ setOpen(next);
42
+ if (!next) restoreFocus();
43
+ };
44
+ const confirm = async (event) => {
45
+ if (event && typeof event.preventDefault === "function") event.preventDefault();
46
+ setBusy(true);
47
+ try {
48
+ await onConfirm();
49
+ setOpen(false);
50
+ restoreFocus();
51
+ } catch {
52
+ } finally {
53
+ setBusy(false);
54
+ }
55
+ };
56
+ return /* @__PURE__ */ jsxs(Dialog.Root, { open, onOpenChange, children: [
57
+ /* @__PURE__ */ jsx(Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }),
58
+ /* @__PURE__ */ jsx(
59
+ ConfirmDialog,
60
+ {
61
+ title,
62
+ variant,
63
+ endAction: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant, onClick: confirm, loading: busy, disabled: busy, children: confirmLabel }),
64
+ children: body
65
+ }
66
+ )
67
+ ] });
68
+ };
69
+ export {
70
+ ConfirmAction as C,
71
+ refocusIfLost as r
72
+ };
@@ -4,9 +4,10 @@ import { Box, Typography, Flex, Badge, Table, Thead, Tr, Th, VisuallyHidden, Tbo
4
4
  import { Pencil, Duplicate, ArrowUp, ArrowDown, Trash, Plus, Upload, Download } from "@strapi/icons";
5
5
  import { EmptyDocuments } from "@strapi/icons/symbols";
6
6
  import { useFetchClient, useNotification, useRBAC, Page } from "@strapi/strapi/admin";
7
- import { s as sanitizeSvg, a as sanitizeTemplate, m as mergeCodeBlocks, c as codeBlocks, P as PERMISSIONS } from "./index-CQk1XeNb.mjs";
8
- import { A as API, C as ConfirmAction, r as readApiError, a as refocusIfLost } from "./ConfirmAction-DuQwvRYi.mjs";
9
- import { u as useT, S as SectionCard, P as PageShell } from "./useT-CmaeZbCr.mjs";
7
+ import { s as sanitizeSvg, a as sanitizeTemplate, m as mergeCodeBlocks, c as codeBlocks, P as PERMISSIONS } from "./index-D_Fv8Non.mjs";
8
+ import { A as API, r as readApiError } from "./api-2ZRpHM3d.mjs";
9
+ import { u as useT, S as SectionCard, P as PageShell } from "./useT-CLPhBmBC.mjs";
10
+ import { C as ConfirmAction, r as refocusIfLost } from "./ConfirmAction-CZjpduc3.mjs";
10
11
  import styled from "styled-components";
11
12
  import { u as useBreakpoint } from "./useBreakpoint-DCfn6pDG.mjs";
12
13
  import { useIntl } from "react-intl";
@@ -22,7 +23,7 @@ const FIELD_TYPES = Object.freeze([
22
23
  ]);
23
24
  const TUNES = Object.freeze(["alignmentTune", "textVariant", "indentTune"]);
24
25
  const BLOCK_TYPES = Object.freeze(["simple", "embedded-entry"]);
25
- const LEGACY_NAMES = Object.freeze(["toc", "gallery", "video", "audio", "synced", "mention"]);
26
+ const LEGACY_NAMES = Object.freeze(["toc", "gallery", "video", "audio", "synced", "mention", "math"]);
26
27
  const RESERVED_NAMES = Object.freeze(
27
28
  [
28
29
  "paragraph",
@@ -44,6 +45,7 @@ const RESERVED_NAMES = Object.freeze(
44
45
  "video",
45
46
  "audio",
46
47
  "synced",
48
+ "math",
47
49
  "linkTool",
48
50
  "attaches",
49
51
  "personality",
@@ -6,9 +6,10 @@ const designSystem = require("@strapi/design-system");
6
6
  const icons = require("@strapi/icons");
7
7
  const symbols = require("@strapi/icons/symbols");
8
8
  const admin = require("@strapi/strapi/admin");
9
- const index = require("./index-BHBRr562.js");
10
- const ConfirmAction = require("./ConfirmAction-zLuIFj8t.js");
11
- const useT = require("./useT-D3sM9Zf7.js");
9
+ const index = require("./index-D6Z7i8ba.js");
10
+ const api = require("./api-bix9RLLI.js");
11
+ const useT = require("./useT-BXJLIPN4.js");
12
+ const ConfirmAction = require("./ConfirmAction-CUhpngYU.js");
12
13
  const styled = require("styled-components");
13
14
  const useBreakpoint = require("./useBreakpoint-D30eNTkF.js");
14
15
  const reactIntl = require("react-intl");
@@ -26,7 +27,7 @@ const FIELD_TYPES = Object.freeze([
26
27
  ]);
27
28
  const TUNES = Object.freeze(["alignmentTune", "textVariant", "indentTune"]);
28
29
  const BLOCK_TYPES = Object.freeze(["simple", "embedded-entry"]);
29
- const LEGACY_NAMES = Object.freeze(["toc", "gallery", "video", "audio", "synced", "mention"]);
30
+ const LEGACY_NAMES = Object.freeze(["toc", "gallery", "video", "audio", "synced", "mention", "math"]);
30
31
  const RESERVED_NAMES = Object.freeze(
31
32
  [
32
33
  "paragraph",
@@ -48,6 +49,7 @@ const RESERVED_NAMES = Object.freeze(
48
49
  "video",
49
50
  "audio",
50
51
  "synced",
52
+ "math",
51
53
  "linkTool",
52
54
  "attaches",
53
55
  "personality",
@@ -305,7 +307,7 @@ const useCustomBlocks = () => {
305
307
  };
306
308
  }, []);
307
309
  const fetchBlocks = ReactNamespace.useCallback(
308
- () => get(ConfirmAction.API.customBlocks, { params: { all: "true" } }).then(
310
+ () => get(api.API.customBlocks, { params: { all: "true" } }).then(
309
311
  ({ data }) => {
310
312
  if (!mounted.current) return;
311
313
  setBlocks(Array.isArray(data.data) ? data.data : []);
@@ -322,7 +324,7 @@ const useCustomBlocks = () => {
322
324
  [get]
323
325
  );
324
326
  const fetchContentTypes = ReactNamespace.useCallback(
325
- () => get(ConfirmAction.API.contentTypes).then(
327
+ () => get(api.API.contentTypes).then(
326
328
  ({ data }) => {
327
329
  if (mounted.current)
328
330
  setContentTypes({ status: "ready", items: Array.isArray(data.data) ? data.data : [] });
@@ -1379,7 +1381,7 @@ const CodeBlocksSection = () => {
1379
1381
  const [server, setServer] = ReactNamespace.useState([]);
1380
1382
  ReactNamespace.useEffect(() => {
1381
1383
  let active = true;
1382
- get(ConfirmAction.API.config).then(
1384
+ get(api.API.config).then(
1383
1385
  ({ data }) => {
1384
1386
  if (active && data && data.data && Array.isArray(data.data.codeBlocks))
1385
1387
  setServer(data.data.codeBlocks);
@@ -1485,7 +1487,7 @@ const CustomBlocksPage = () => {
1485
1487
  ] });
1486
1488
  }
1487
1489
  const failed = (error, fallback) => {
1488
- const info = ConfirmAction.readApiError(error);
1490
+ const info = api.readApiError(error);
1489
1491
  toggleNotification({
1490
1492
  type: "danger",
1491
1493
  message: info.status === 404 ? t("settings.blocks.notFound", "This block no longer exists.") : fallback
@@ -1494,8 +1496,8 @@ const CustomBlocksPage = () => {
1494
1496
  const onSubmit = async (values) => {
1495
1497
  const payload = toPayload(values);
1496
1498
  try {
1497
- if (modal.block) await put(ConfirmAction.API.customBlock(modal.block.id), payload);
1498
- else await post(ConfirmAction.API.customBlocks, payload);
1499
+ if (modal.block) await put(api.API.customBlock(modal.block.id), payload);
1500
+ else await post(api.API.customBlocks, payload);
1499
1501
  toggleNotification({
1500
1502
  type: "success",
1501
1503
  message: modal.block ? t("settings.blocks.saved", "Block {label} saved.", { label: payload.label }) : t("settings.blocks.created", "Block {label} created.", { label: payload.label })
@@ -1504,7 +1506,7 @@ const CustomBlocksPage = () => {
1504
1506
  await data.reload();
1505
1507
  return { ok: true };
1506
1508
  } catch (error) {
1507
- const info = ConfirmAction.readApiError(error);
1509
+ const info = api.readApiError(error);
1508
1510
  if (info.status === 400) {
1509
1511
  toggleNotification({
1510
1512
  type: "warning",
@@ -1525,7 +1527,7 @@ const CustomBlocksPage = () => {
1525
1527
  const onToggle = async (block, enabled) => {
1526
1528
  setBusyId(block.id);
1527
1529
  try {
1528
- const { data: response } = await put(ConfirmAction.API.customBlock(block.id), withEnabled(block, enabled));
1530
+ const { data: response } = await put(api.API.customBlock(block.id), withEnabled(block, enabled));
1529
1531
  data.setBlocks((current) => current.map((item) => item.id === block.id ? response.data : item));
1530
1532
  toggleNotification({
1531
1533
  type: "success",
@@ -1534,7 +1536,7 @@ const CustomBlocksPage = () => {
1534
1536
  })
1535
1537
  });
1536
1538
  } catch (error) {
1537
- const info = ConfirmAction.readApiError(error);
1539
+ const info = api.readApiError(error);
1538
1540
  if (info.status === 400) {
1539
1541
  toggleNotification({
1540
1542
  type: "warning",
@@ -1552,7 +1554,7 @@ const CustomBlocksPage = () => {
1552
1554
  const onDuplicate = async (block) => {
1553
1555
  setBusyId(block.id);
1554
1556
  try {
1555
- const { data: response } = await post(ConfirmAction.API.customBlockDuplicate(block.id), {});
1557
+ const { data: response } = await post(api.API.customBlockDuplicate(block.id), {});
1556
1558
  toggleNotification({
1557
1559
  type: "success",
1558
1560
  message: t("settings.blocks.duplicated", "Copy {label} created.", { label: response.data.label })
@@ -1574,7 +1576,7 @@ const CustomBlocksPage = () => {
1574
1576
  const opener = typeof document !== "undefined" ? document.activeElement : null;
1575
1577
  setBusyId(block.id);
1576
1578
  try {
1577
- const { data: response } = await put(ConfirmAction.API.customBlocksOrder, { ids });
1579
+ const { data: response } = await put(api.API.customBlocksOrder, { ids });
1578
1580
  data.setBlocks(response.data);
1579
1581
  } catch (error) {
1580
1582
  failed(error, t("settings.blocks.moveError", "The order could not be saved."));
@@ -1585,7 +1587,7 @@ const CustomBlocksPage = () => {
1585
1587
  };
1586
1588
  const onDelete = async (block) => {
1587
1589
  try {
1588
- await del(ConfirmAction.API.customBlock(block.id));
1590
+ await del(api.API.customBlock(block.id));
1589
1591
  toggleNotification({
1590
1592
  type: "success",
1591
1593
  message: t("settings.blocks.deleted", "Block {label} deleted.", { label: block.label })
@@ -1599,7 +1601,7 @@ const CustomBlocksPage = () => {
1599
1601
  const onExport = async () => {
1600
1602
  setExporting(true);
1601
1603
  try {
1602
- const { data: response } = await get(ConfirmAction.API.customBlocksExport);
1604
+ const { data: response } = await get(api.API.customBlocksExport);
1603
1605
  const blob = new Blob([JSON.stringify(response.data, null, 2)], { type: "application/json" });
1604
1606
  const url = URL.createObjectURL(blob);
1605
1607
  const link = document.createElement("a");
@@ -1638,7 +1640,7 @@ const CustomBlocksPage = () => {
1638
1640
  });
1639
1641
  return;
1640
1642
  }
1641
- const { data: response } = await post(ConfirmAction.API.customBlocksImport, parsed);
1643
+ const { data: response } = await post(api.API.customBlocksImport, parsed);
1642
1644
  const { created, skipped } = response.data;
1643
1645
  setImportReport({ created, skipped });
1644
1646
  toggleNotification({
@@ -1650,7 +1652,7 @@ const CustomBlocksPage = () => {
1650
1652
  });
1651
1653
  await data.reload();
1652
1654
  } catch (error) {
1653
- const info = ConfirmAction.readApiError(error);
1655
+ const info = api.readApiError(error);
1654
1656
  toggleNotification({
1655
1657
  type: "danger",
1656
1658
  message: info.status === 400 ? t("settings.blocks.importRejected", "The file is not a Magic Editor X custom block export.") : t("settings.blocks.importError", "The import failed. Nothing was imported.")
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const ReactNamespace = require("react");
5
+ const reactIntl = require("react-intl");
6
+ const reactRouterDom = require("react-router-dom");
7
+ const designSystem = require("@strapi/design-system");
8
+ const icons = require("@strapi/icons");
9
+ const admin = require("@strapi/strapi/admin");
10
+ const styled = require("styled-components");
11
+ const api = require("./api-bix9RLLI.js");
12
+ const index = require("./index-D6Z7i8ba.js");
13
+ const comments = require("./comments-C7P41lan.js");
14
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
16
+ const notificationPath = (item) => {
17
+ const target = item && item.target ? item.target : {};
18
+ const uid = encodeURIComponent(String(target.uid || ""));
19
+ const path = target.kind === "singleType" ? `/content-manager/single-types/${uid}` : `/content-manager/collection-types/${uid}/${encodeURIComponent(String(target.documentId || ""))}`;
20
+ const params = new URLSearchParams();
21
+ if (target.locale) params.set("plugins[i18n][locale]", target.locale);
22
+ params.set("mexThread", String(item.threadId || ""));
23
+ return `${path}?${params.toString()}`;
24
+ };
25
+ const POLL_MS = 6e4;
26
+ const PAGE_SIZE = 5;
27
+ const List = styled__default.default.ul`
28
+ list-style: none;
29
+ margin: 0;
30
+ padding: 0;
31
+ display: flex;
32
+ flex-direction: column;
33
+ gap: ${({ theme }) => theme.spaces[2]};
34
+ min-width: 0;
35
+ `;
36
+ const Item = styled__default.default.li`
37
+ display: flex;
38
+ align-items: flex-start;
39
+ gap: ${({ theme }) => theme.spaces[2]};
40
+ min-width: 0;
41
+ padding: ${({ theme }) => theme.spaces[2]};
42
+ border-radius: ${({ theme }) => theme.borderRadius};
43
+ background: ${({ theme, $unread }) => $unread ? theme.colors.primary100 : "transparent"};
44
+ `;
45
+ const Dot = styled__default.default.span`
46
+ flex: 0 0 auto;
47
+ width: 0.8rem;
48
+ height: 0.8rem;
49
+ margin-top: 0.6rem;
50
+ border-radius: 50%;
51
+ background: ${({ theme, $unread }) => $unread ? theme.colors.primary600 : "transparent"};
52
+ `;
53
+ const ItemLink = styled__default.default(reactRouterDom.Link)`
54
+ flex: 1 1 auto;
55
+ min-width: 0;
56
+ color: inherit;
57
+ text-decoration: none;
58
+ border-radius: ${({ theme }) => theme.borderRadius};
59
+ &:hover span:first-child {
60
+ text-decoration: underline;
61
+ }
62
+ &:focus-visible {
63
+ outline: 2px solid ${({ theme }) => theme.colors.primary600};
64
+ outline-offset: 2px;
65
+ }
66
+ `;
67
+ const Wrap = styled__default.default(designSystem.Typography)`
68
+ display: block;
69
+ overflow-wrap: anywhere;
70
+ min-width: 0;
71
+ `;
72
+ const MentionsWidget = () => {
73
+ const { formatMessage, formatRelativeTime } = reactIntl.useIntl();
74
+ const { get, post } = admin.useFetchClient();
75
+ const [state, setState] = ReactNamespace.useState({ loading: true, error: false, items: [], unread: 0 });
76
+ const [announcement, setAnnouncement] = ReactNamespace.useState("");
77
+ const requestRef = ReactNamespace.useRef(0);
78
+ const t = ReactNamespace.useCallback(
79
+ (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values),
80
+ [formatMessage]
81
+ );
82
+ const load = ReactNamespace.useCallback(() => {
83
+ const id = requestRef.current + 1;
84
+ requestRef.current = id;
85
+ return get(api.API.notifications, { params: { pageSize: PAGE_SIZE } }).then(
86
+ ({ data }) => {
87
+ if (requestRef.current !== id) return;
88
+ setState({
89
+ loading: false,
90
+ error: false,
91
+ items: Array.isArray(data.data) ? data.data : [],
92
+ unread: Number(data.meta && data.meta.unread) || 0
93
+ });
94
+ },
95
+ () => {
96
+ if (requestRef.current !== id) return;
97
+ setState((current) => ({ ...current, loading: false, error: true }));
98
+ }
99
+ );
100
+ }, [get]);
101
+ ReactNamespace.useEffect(() => {
102
+ let timer = null;
103
+ const schedule = () => {
104
+ window.clearTimeout(timer);
105
+ if (document.visibilityState === "hidden") return;
106
+ timer = window.setTimeout(async () => {
107
+ await load();
108
+ schedule();
109
+ }, POLL_MS);
110
+ };
111
+ const onWake = () => {
112
+ if (document.visibilityState === "hidden") {
113
+ window.clearTimeout(timer);
114
+ return;
115
+ }
116
+ load();
117
+ schedule();
118
+ };
119
+ load();
120
+ schedule();
121
+ window.addEventListener("focus", onWake);
122
+ document.addEventListener("visibilitychange", onWake);
123
+ return () => {
124
+ window.clearTimeout(timer);
125
+ window.removeEventListener("focus", onWake);
126
+ document.removeEventListener("visibilitychange", onWake);
127
+ };
128
+ }, [load]);
129
+ const act = async (request, message) => {
130
+ try {
131
+ await request();
132
+ setAnnouncement(message);
133
+ await load();
134
+ } catch {
135
+ setAnnouncement(t("widget.mentions.failed", "This did not work. Try again."));
136
+ }
137
+ };
138
+ if (state.loading && !state.items.length) {
139
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.Loading, { children: t("widget.mentions.loading", "Loading mentions") });
140
+ }
141
+ if (state.error && !state.items.length) {
142
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.Error, { children: t("widget.mentions.error", "Mentions could not be loaded.") });
143
+ }
144
+ if (!state.items.length) {
145
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.NoData, { children: t(
146
+ "widget.mentions.empty",
147
+ "No mentions yet. When someone mentions you in a comment or replies to your thread, it shows up here."
148
+ ) });
149
+ }
150
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-mentions-widget", children: [
151
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
152
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("widget.mentions.unread", "{count, plural, =0 {All read} one {# unread} other {# unread}}", {
153
+ count: state.unread
154
+ }) }),
155
+ state.unread ? /* @__PURE__ */ jsxRuntime.jsx(
156
+ designSystem.Button,
157
+ {
158
+ size: "S",
159
+ variant: "tertiary",
160
+ onClick: () => act(
161
+ () => post(api.API.notificationsReadAll, {}),
162
+ t("widget.mentions.allRead", "All notifications marked as read")
163
+ ),
164
+ children: t("widget.mentions.markAll", "Mark all as read")
165
+ }
166
+ ) : null
167
+ ] }),
168
+ /* @__PURE__ */ jsxRuntime.jsx(List, { children: state.items.map((item) => {
169
+ const actor = item.actor && item.actor.name ? item.actor.name : t("widget.mentions.deletedUser", "Deleted user");
170
+ const what = item.kind === "mention" ? t("widget.mentions.mentioned", "{name} mentioned you", { name: actor }) : t("widget.mentions.replied", "{name} replied in a thread you are in", { name: actor });
171
+ const where = item.target.title ? t("widget.mentions.where", "{title} ({type})", {
172
+ title: item.target.title,
173
+ type: item.target.typeName
174
+ }) : item.target.typeName;
175
+ const { value, unit } = comments.relativeTimeParts(item.createdAt);
176
+ return /* @__PURE__ */ jsxRuntime.jsxs(
177
+ Item,
178
+ {
179
+ $unread: !item.read,
180
+ "data-testid": "mex-mention-item",
181
+ "data-read": item.read ? "true" : "false",
182
+ children: [
183
+ /* @__PURE__ */ jsxRuntime.jsx(Dot, { $unread: !item.read, "aria-hidden": "true" }),
184
+ /* @__PURE__ */ jsxRuntime.jsxs(ItemLink, { to: notificationPath(item), children: [
185
+ /* @__PURE__ */ jsxRuntime.jsxs(Wrap, { variant: "omega", fontWeight: item.read ? "regular" : "bold", textColor: "neutral800", children: [
186
+ what,
187
+ item.read ? null : /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: ` (${t("widget.mentions.new", "unread")})` })
188
+ ] }),
189
+ /* @__PURE__ */ jsxRuntime.jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
190
+ where,
191
+ " · ",
192
+ formatRelativeTime(value, unit, { numeric: "auto" })
193
+ ] }),
194
+ item.snippet ? /* @__PURE__ */ jsxRuntime.jsx(Wrap, { variant: "pi", textColor: "neutral700", children: item.snippet }) : null
195
+ ] }),
196
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { flex: "0 0 auto", children: item.read ? /* @__PURE__ */ jsxRuntime.jsx(
197
+ designSystem.IconButton,
198
+ {
199
+ label: t("widget.mentions.markUnread", "Mark as unread"),
200
+ variant: "ghost",
201
+ onClick: () => act(
202
+ () => post(api.API.notificationUnread(item.id), {}),
203
+ t("widget.mentions.markedUnread", "Marked as unread")
204
+ ),
205
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Bell, {})
206
+ }
207
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
208
+ designSystem.IconButton,
209
+ {
210
+ label: t("widget.mentions.markRead", "Mark as read"),
211
+ variant: "ghost",
212
+ onClick: () => act(
213
+ () => post(api.API.notificationRead(item.id), {}),
214
+ t("widget.mentions.markedRead", "Marked as read")
215
+ ),
216
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {})
217
+ }
218
+ ) })
219
+ ]
220
+ },
221
+ item.id
222
+ );
223
+ }) }),
224
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { "aria-live": "polite", "aria-atomic": "true", children: announcement })
225
+ ] });
226
+ };
227
+ exports.MentionsWidget = MentionsWidget;