magic-editor-x 2.3.1 → 2.5.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 (106) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +428 -148
  3. package/bin/magic-editor-x.mjs +55 -8
  4. package/dist/admin/AuditPage-Be78C7EC.mjs +382 -0
  5. package/dist/admin/AuditPage-iQzpjH8H.js +382 -0
  6. package/dist/admin/{ConfigurationPage-CYGDLjM7.mjs → ConfigurationPage-C9CPBfWy.mjs} +405 -10
  7. package/dist/admin/{ConfigurationPage-CFP3lp9p.js → ConfigurationPage-DefuBeYO.js} +415 -20
  8. package/dist/admin/ConfirmAction-CUhpngYU.js +71 -0
  9. package/dist/admin/ConfirmAction-CZjpduc3.mjs +72 -0
  10. package/dist/admin/Content-BttG50Mc.mjs +360 -0
  11. package/dist/admin/Content-V5MRBsI3.js +362 -0
  12. package/dist/admin/{CustomBlocksPage-B5Q33N-s.mjs → CustomBlocksPage-DB5nnCsn.mjs} +8 -5
  13. package/dist/admin/{CustomBlocksPage-DzPOSpfn.js → CustomBlocksPage-Dg2rM3F4.js} +26 -23
  14. package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
  15. package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
  16. package/dist/admin/MentionsWidget-CJPZDk9Z.mjs +225 -0
  17. package/dist/admin/MentionsWidget-DUz6YVIG.js +227 -0
  18. package/dist/admin/{useT-Cmg1jwwG.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
  19. package/dist/admin/{useT-DNphiBQR.js → SectionCard-Bs-xiiH1.js} +0 -10
  20. package/dist/admin/{TemplatesPage-4A8JNO_Z.mjs → TemplatesPage-VsZ_Mc0R.mjs} +307 -10
  21. package/dist/admin/{TemplatesPage-BVkgafCK.js → TemplatesPage-dx4_yd_t.js} +321 -24
  22. package/dist/admin/{ConfirmAction-zLuIFj8t.js → api-4AYzwS4-.js} +28 -71
  23. package/dist/admin/{ConfirmAction-DuQwvRYi.mjs → api-CcTYyckq.mjs} +28 -71
  24. package/dist/admin/auditText-DIIYVR6k.mjs +110 -0
  25. package/dist/admin/auditText-DUhWu2Nx.js +109 -0
  26. package/dist/admin/comments-C7P41lan.js +86 -0
  27. package/dist/admin/comments-hfIbLQNO.mjs +87 -0
  28. package/dist/admin/{de-B1X46JJZ.js → de-B6rdcOqQ.js} +293 -5
  29. package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
  30. package/dist/admin/{de-BUS1hUw0.mjs → de-Bip0sBRT.mjs} +158 -1
  31. package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
  32. package/dist/admin/{de-DOiGaTNX.mjs → de-CQA8hOpl.mjs} +293 -5
  33. package/dist/admin/{de-C3AsGauQ.js → de-CnnxKXj7.js} +158 -1
  34. package/dist/admin/{de-2Ie5jy7j.js → de-Dss5POqk.js} +53 -3
  35. package/dist/admin/{de-BMY2LBaa.mjs → de-zgHCYTLH.mjs} +53 -3
  36. package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
  37. package/dist/admin/{en-CU6UzV4g.mjs → en-BCKaVgBM.mjs} +293 -5
  38. package/dist/admin/{en-Ah-Cw0Wd.js → en-CJ17Sp_e.js} +53 -3
  39. package/dist/admin/{en-CDg_18Bt.js → en-CbGkcq0Q.js} +293 -5
  40. package/dist/admin/{en-GCzgS9Aw.mjs → en-Cd6Jk-J0.mjs} +158 -1
  41. package/dist/admin/{en-BkEjpC3i.js → en-D69Fe9ZO.js} +158 -1
  42. package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
  43. package/dist/admin/{en-CvFiqti2.mjs → en-Uhm7OouM.mjs} +53 -3
  44. package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
  45. package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
  46. package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
  47. package/dist/admin/{es-DbKHZz5l.mjs → es-BMkmfH88.mjs} +53 -3
  48. package/dist/admin/{es-DHBBZKl2.mjs → es-Bz8d72Fa.mjs} +158 -1
  49. package/dist/admin/{es-BCpJmUEM.js → es-C8UotT8O.js} +293 -5
  50. package/dist/admin/{es-C4pEnDRv.js → es-CcEDZpVQ.js} +158 -1
  51. package/dist/admin/{es-Cr8JH85N.js → es-DJm3HFJt.js} +53 -3
  52. package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
  53. package/dist/admin/{es-BmfffNM2.mjs → es-pvPfNAld.mjs} +293 -5
  54. package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
  55. package/dist/admin/{fr-Dvq4xk2e.mjs → fr-CKHZ0xxU.mjs} +158 -1
  56. package/dist/admin/{fr-OJ4VW1kh.js → fr-CRM9VuAq.js} +53 -3
  57. package/dist/admin/{fr-DQJ_7aq5.mjs → fr-CrIHmKYX.mjs} +53 -3
  58. package/dist/admin/{fr-C2aLSwEu.js → fr-Cx29jQ_g.js} +158 -1
  59. package/dist/admin/{fr-DZd2XJP6.mjs → fr-D4tL6Ag2.mjs} +293 -5
  60. package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
  61. package/dist/admin/{fr-ZcN0yM_2.js → fr-DrUYv2jh.js} +293 -5
  62. package/dist/admin/{index-k8_a5o1A.mjs → index-C4ksUkEm.mjs} +20059 -10130
  63. package/dist/admin/{index-DQVE0ymw.js → index-C5D3VqLq.js} +21272 -11344
  64. package/dist/admin/index-CMYCZWOh.mjs +3752 -0
  65. package/dist/admin/index-DRyctF9s.js +3753 -0
  66. package/dist/admin/index.js +2 -1
  67. package/dist/admin/index.mjs +3 -2
  68. package/dist/admin/math-D6jmskGS.js +49 -0
  69. package/dist/admin/math-DntdSWKX.mjs +47 -0
  70. package/dist/admin/{pt-CilDggGF.mjs → pt-B8x7v-Xw.mjs} +158 -1
  71. package/dist/admin/{pt-DX0OAIoL.js → pt-BYn2xx78.js} +158 -1
  72. package/dist/admin/{pt-CImqDnLB.js → pt-CojQcz-p.js} +293 -5
  73. package/dist/admin/{pt-C3UdeIpd.mjs → pt-CuoIihKx.mjs} +293 -5
  74. package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
  75. package/dist/admin/{pt-BSLzA17U.mjs → pt-DDlPJYtB.mjs} +53 -3
  76. package/dist/admin/{pt-D0I0_JYs.js → pt-DPVAycXJ.js} +53 -3
  77. package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
  78. package/dist/admin/useT-Bpw__IXT.js +12 -0
  79. package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
  80. package/dist/blocks/index.d.mts +126 -0
  81. package/dist/blocks/index.d.ts +126 -0
  82. package/dist/blocks/index.js +184 -4
  83. package/dist/blocks/index.mjs +184 -4
  84. package/dist/math/index.d.mts +27 -0
  85. package/dist/math/index.d.ts +27 -0
  86. package/dist/math/index.js +168 -0
  87. package/dist/math/index.mjs +138 -0
  88. package/dist/react/index.js +1650 -759
  89. package/dist/react/index.mjs +1650 -759
  90. package/dist/render/index.d.mts +48 -0
  91. package/dist/render/index.d.ts +48 -0
  92. package/dist/render/index.js +1755 -773
  93. package/dist/render/index.mjs +1755 -773
  94. package/dist/server/index.js +29475 -18462
  95. package/dist/server/index.mjs +29475 -18462
  96. package/dist/server/mcp-worker.js +11319 -0
  97. package/dist/vue/index.js +1650 -759
  98. package/dist/vue/index.mjs +1650 -759
  99. package/package.json +14 -8
  100. package/schema/magic-editor-x.schema.json +135 -2
  101. package/types/blocks.d.ts +126 -0
  102. package/types/index.d.ts +52 -1
  103. package/types/math.d.ts +27 -0
  104. package/types/render.d.ts +48 -0
  105. package/dist/admin/index-DR8sHkTk.js +0 -1940
  106. package/dist/admin/index-My6FjjHB.mjs +0 -1939
@@ -0,0 +1,199 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { Link } from "react-router-dom";
5
+ import { Flex, Typography, Button } from "@strapi/design-system";
6
+ import { Widget, useFetchClient } from "@strapi/strapi/admin";
7
+ import styled from "styled-components";
8
+ import { A as API } from "./api-CcTYyckq.mjs";
9
+ import { u as useT } from "./useT-Cb-R3kyA.mjs";
10
+ import { r as relativeTimeParts } from "./comments-hfIbLQNO.mjs";
11
+ import { e as entryPath } from "./index-CMYCZWOh.mjs";
12
+ const POLL_MS = 6e4;
13
+ const PAGE_SIZE = 5;
14
+ const List = styled.ul`
15
+ list-style: none;
16
+ margin: 0;
17
+ padding: 0;
18
+ display: flex;
19
+ flex-direction: column;
20
+ gap: ${({ theme }) => theme.spaces[1]};
21
+ min-width: 0;
22
+ `;
23
+ const ItemLink = styled(Link)`
24
+ display: block;
25
+ min-width: 0;
26
+ padding: ${({ theme }) => theme.spaces[2]};
27
+ border-radius: ${({ theme }) => theme.borderRadius};
28
+ color: inherit;
29
+ text-decoration: none;
30
+ &:hover {
31
+ background: ${({ theme }) => theme.colors.neutral100};
32
+ }
33
+ &:hover span:first-child {
34
+ text-decoration: underline;
35
+ }
36
+ &:focus-visible {
37
+ outline: 2px solid ${({ theme }) => theme.colors.primary600};
38
+ outline-offset: 2px;
39
+ }
40
+ `;
41
+ const Wrap = styled(Typography)`
42
+ display: block;
43
+ overflow-wrap: anywhere;
44
+ min-width: 0;
45
+ `;
46
+ const useWidgetData = (path) => {
47
+ const { get } = useFetchClient();
48
+ const [state, setState] = useState({ loading: true, error: false, items: [], meta: {} });
49
+ const requestRef = useRef(0);
50
+ const load = useCallback(() => {
51
+ const id = requestRef.current + 1;
52
+ requestRef.current = id;
53
+ return get(path, { params: { pageSize: PAGE_SIZE } }).then(
54
+ ({ data }) => {
55
+ if (requestRef.current !== id) return;
56
+ setState({
57
+ loading: false,
58
+ error: false,
59
+ items: Array.isArray(data.data) ? data.data : [],
60
+ meta: data.meta || {}
61
+ });
62
+ },
63
+ () => {
64
+ if (requestRef.current !== id) return;
65
+ setState((current) => ({ ...current, loading: false, error: true }));
66
+ }
67
+ );
68
+ }, [get, path]);
69
+ useEffect(() => {
70
+ let timer = null;
71
+ const schedule = () => {
72
+ window.clearTimeout(timer);
73
+ if (document.visibilityState === "hidden") return;
74
+ timer = window.setTimeout(async () => {
75
+ await load();
76
+ schedule();
77
+ }, POLL_MS);
78
+ };
79
+ const onWake = () => {
80
+ if (document.visibilityState === "hidden") {
81
+ window.clearTimeout(timer);
82
+ return;
83
+ }
84
+ load();
85
+ schedule();
86
+ };
87
+ load();
88
+ schedule();
89
+ window.addEventListener("focus", onWake);
90
+ document.addEventListener("visibilitychange", onWake);
91
+ return () => {
92
+ window.clearTimeout(timer);
93
+ window.removeEventListener("focus", onWake);
94
+ document.removeEventListener("visibilitychange", onWake);
95
+ };
96
+ }, [load]);
97
+ return { ...state, reload: load };
98
+ };
99
+ const ErrorState = ({ text, retry, onRetry }) => /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "center", children: [
100
+ /* @__PURE__ */ jsx(Widget.Error, { children: text }),
101
+ /* @__PURE__ */ jsx(Button, { size: "S", variant: "tertiary", onClick: onRetry, children: retry })
102
+ ] });
103
+ const entryName = (t, target) => target.title ? t("widget.openThreads.where", "{title} ({type})", { title: target.title, type: target.typeName }) : target.typeName;
104
+ const OpenThreadsWidget = () => {
105
+ const t = useT();
106
+ const { formatRelativeTime } = useIntl();
107
+ const state = useWidgetData(API.widgetOpenThreads);
108
+ if (state.loading && !state.items.length)
109
+ return /* @__PURE__ */ jsx(Widget.Loading, { children: t("widget.openThreads.loading", "Loading threads") });
110
+ if (state.error && !state.items.length)
111
+ return /* @__PURE__ */ jsx(
112
+ ErrorState,
113
+ {
114
+ text: t("widget.openThreads.error", "Threads could not be loaded."),
115
+ retry: t("widget.retry", "Try again"),
116
+ onRetry: state.reload
117
+ }
118
+ );
119
+ if (!state.items.length)
120
+ return /* @__PURE__ */ jsx(Widget.NoData, { children: t(
121
+ "widget.openThreads.empty",
122
+ "No open threads. Threads you start or are mentioned in stay here until they are resolved."
123
+ ) });
124
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-open-threads-widget", children: [
125
+ /* @__PURE__ */ jsx(List, { children: state.items.map((item) => {
126
+ const { value, unit } = relativeTimeParts(item.updatedAt);
127
+ const why = item.started ? t("widget.openThreads.started", "You started this thread") : t("widget.openThreads.mentioned", "You were mentioned");
128
+ return /* @__PURE__ */ jsx("li", { "data-testid": "mex-open-thread", children: /* @__PURE__ */ jsxs(ItemLink, { to: entryPath(item.target, { mexThread: item.threadId }), children: [
129
+ /* @__PURE__ */ jsx(Wrap, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: item.excerpt || item.snippet || entryName(t, item.target) }),
130
+ /* @__PURE__ */ jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
131
+ entryName(t, item.target),
132
+ " · ",
133
+ why,
134
+ " · ",
135
+ formatRelativeTime(value, unit, { numeric: "auto" })
136
+ ] })
137
+ ] }) }, item.threadId);
138
+ }) }),
139
+ state.meta.more ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("widget.openThreads.more", "More open threads are not shown. Resolve threads to see the rest.") }) : null
140
+ ] });
141
+ };
142
+ const BrokenLinksWidget = () => {
143
+ const t = useT();
144
+ const { formatDate } = useIntl();
145
+ const state = useWidgetData(API.widgetBrokenLinks);
146
+ if (state.loading && !state.items.length && !state.meta.lastRun)
147
+ return /* @__PURE__ */ jsx(Widget.Loading, { children: t("widget.brokenLinks.loading", "Loading links") });
148
+ if (state.error && !state.items.length)
149
+ return /* @__PURE__ */ jsx(
150
+ ErrorState,
151
+ {
152
+ text: t("widget.brokenLinks.error", "Broken links could not be loaded."),
153
+ retry: t("widget.retry", "Try again"),
154
+ onRetry: state.reload
155
+ }
156
+ );
157
+ if (state.meta.enabled === false)
158
+ return /* @__PURE__ */ jsx(Widget.NoData, { children: t("widget.brokenLinks.off", "The scheduled link check is turned off in the server configuration.") });
159
+ if (!state.meta.lastRun)
160
+ return /* @__PURE__ */ jsx(Widget.NoData, { children: t(
161
+ "widget.brokenLinks.noRun",
162
+ "The scheduled link check has not run yet. Results show up here after it runs."
163
+ ) });
164
+ const checked = t("widget.brokenLinks.lastRun", "Last check {date}", {
165
+ date: formatDate(state.meta.lastRun.finishedAt, { dateStyle: "medium", timeStyle: "short" })
166
+ });
167
+ if (!state.items.length)
168
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "center", children: [
169
+ /* @__PURE__ */ jsx(Widget.NoData, { children: t("widget.brokenLinks.empty", "No broken links in the entries you can read.") }),
170
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: checked })
171
+ ] });
172
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-broken-links-widget", children: [
173
+ /* @__PURE__ */ jsx(List, { children: state.items.map((item) => /* @__PURE__ */ jsx(
174
+ "li",
175
+ {
176
+ "data-testid": "mex-broken-entry",
177
+ children: /* @__PURE__ */ jsxs(ItemLink, { to: entryPath(item.target), children: [
178
+ /* @__PURE__ */ jsx(Wrap, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: entryName(t, item.target) }),
179
+ /* @__PURE__ */ jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
180
+ t(
181
+ "widget.brokenLinks.count",
182
+ "{count, plural, one {# broken link} other {# broken links}}",
183
+ {
184
+ count: item.problems
185
+ }
186
+ ),
187
+ item.target.locale ? ` · ${item.target.locale}` : ""
188
+ ] })
189
+ ] })
190
+ },
191
+ `${item.target.uid}|${item.target.documentId}|${item.target.locale || ""}`
192
+ )) }),
193
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: state.meta.more ? t("widget.brokenLinks.more", "More entries have broken links. {date}", { date: checked }) : checked })
194
+ ] });
195
+ };
196
+ export {
197
+ BrokenLinksWidget,
198
+ OpenThreadsWidget
199
+ };
@@ -0,0 +1,201 @@
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 admin = require("@strapi/strapi/admin");
9
+ const styled = require("styled-components");
10
+ const api = require("./api-4AYzwS4-.js");
11
+ const useT = require("./useT-Bpw__IXT.js");
12
+ const comments = require("./comments-C7P41lan.js");
13
+ const index = require("./index-DRyctF9s.js");
14
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
16
+ const POLL_MS = 6e4;
17
+ const PAGE_SIZE = 5;
18
+ const List = styled__default.default.ul`
19
+ list-style: none;
20
+ margin: 0;
21
+ padding: 0;
22
+ display: flex;
23
+ flex-direction: column;
24
+ gap: ${({ theme }) => theme.spaces[1]};
25
+ min-width: 0;
26
+ `;
27
+ const ItemLink = styled__default.default(reactRouterDom.Link)`
28
+ display: block;
29
+ min-width: 0;
30
+ padding: ${({ theme }) => theme.spaces[2]};
31
+ border-radius: ${({ theme }) => theme.borderRadius};
32
+ color: inherit;
33
+ text-decoration: none;
34
+ &:hover {
35
+ background: ${({ theme }) => theme.colors.neutral100};
36
+ }
37
+ &:hover span:first-child {
38
+ text-decoration: underline;
39
+ }
40
+ &:focus-visible {
41
+ outline: 2px solid ${({ theme }) => theme.colors.primary600};
42
+ outline-offset: 2px;
43
+ }
44
+ `;
45
+ const Wrap = styled__default.default(designSystem.Typography)`
46
+ display: block;
47
+ overflow-wrap: anywhere;
48
+ min-width: 0;
49
+ `;
50
+ const useWidgetData = (path) => {
51
+ const { get } = admin.useFetchClient();
52
+ const [state, setState] = ReactNamespace.useState({ loading: true, error: false, items: [], meta: {} });
53
+ const requestRef = ReactNamespace.useRef(0);
54
+ const load = ReactNamespace.useCallback(() => {
55
+ const id = requestRef.current + 1;
56
+ requestRef.current = id;
57
+ return get(path, { params: { pageSize: PAGE_SIZE } }).then(
58
+ ({ data }) => {
59
+ if (requestRef.current !== id) return;
60
+ setState({
61
+ loading: false,
62
+ error: false,
63
+ items: Array.isArray(data.data) ? data.data : [],
64
+ meta: data.meta || {}
65
+ });
66
+ },
67
+ () => {
68
+ if (requestRef.current !== id) return;
69
+ setState((current) => ({ ...current, loading: false, error: true }));
70
+ }
71
+ );
72
+ }, [get, path]);
73
+ ReactNamespace.useEffect(() => {
74
+ let timer = null;
75
+ const schedule = () => {
76
+ window.clearTimeout(timer);
77
+ if (document.visibilityState === "hidden") return;
78
+ timer = window.setTimeout(async () => {
79
+ await load();
80
+ schedule();
81
+ }, POLL_MS);
82
+ };
83
+ const onWake = () => {
84
+ if (document.visibilityState === "hidden") {
85
+ window.clearTimeout(timer);
86
+ return;
87
+ }
88
+ load();
89
+ schedule();
90
+ };
91
+ load();
92
+ schedule();
93
+ window.addEventListener("focus", onWake);
94
+ document.addEventListener("visibilitychange", onWake);
95
+ return () => {
96
+ window.clearTimeout(timer);
97
+ window.removeEventListener("focus", onWake);
98
+ document.removeEventListener("visibilitychange", onWake);
99
+ };
100
+ }, [load]);
101
+ return { ...state, reload: load };
102
+ };
103
+ const ErrorState = ({ text, retry, onRetry }) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "center", children: [
104
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.Error, { children: text }),
105
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { size: "S", variant: "tertiary", onClick: onRetry, children: retry })
106
+ ] });
107
+ const entryName = (t, target) => target.title ? t("widget.openThreads.where", "{title} ({type})", { title: target.title, type: target.typeName }) : target.typeName;
108
+ const OpenThreadsWidget = () => {
109
+ const t = useT.useT();
110
+ const { formatRelativeTime } = reactIntl.useIntl();
111
+ const state = useWidgetData(api.API.widgetOpenThreads);
112
+ if (state.loading && !state.items.length)
113
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.Loading, { children: t("widget.openThreads.loading", "Loading threads") });
114
+ if (state.error && !state.items.length)
115
+ return /* @__PURE__ */ jsxRuntime.jsx(
116
+ ErrorState,
117
+ {
118
+ text: t("widget.openThreads.error", "Threads could not be loaded."),
119
+ retry: t("widget.retry", "Try again"),
120
+ onRetry: state.reload
121
+ }
122
+ );
123
+ if (!state.items.length)
124
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.NoData, { children: t(
125
+ "widget.openThreads.empty",
126
+ "No open threads. Threads you start or are mentioned in stay here until they are resolved."
127
+ ) });
128
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-open-threads-widget", children: [
129
+ /* @__PURE__ */ jsxRuntime.jsx(List, { children: state.items.map((item) => {
130
+ const { value, unit } = comments.relativeTimeParts(item.updatedAt);
131
+ const why = item.started ? t("widget.openThreads.started", "You started this thread") : t("widget.openThreads.mentioned", "You were mentioned");
132
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { "data-testid": "mex-open-thread", children: /* @__PURE__ */ jsxRuntime.jsxs(ItemLink, { to: index.entryPath(item.target, { mexThread: item.threadId }), children: [
133
+ /* @__PURE__ */ jsxRuntime.jsx(Wrap, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: item.excerpt || item.snippet || entryName(t, item.target) }),
134
+ /* @__PURE__ */ jsxRuntime.jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
135
+ entryName(t, item.target),
136
+ " · ",
137
+ why,
138
+ " · ",
139
+ formatRelativeTime(value, unit, { numeric: "auto" })
140
+ ] })
141
+ ] }) }, item.threadId);
142
+ }) }),
143
+ state.meta.more ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("widget.openThreads.more", "More open threads are not shown. Resolve threads to see the rest.") }) : null
144
+ ] });
145
+ };
146
+ const BrokenLinksWidget = () => {
147
+ const t = useT.useT();
148
+ const { formatDate } = reactIntl.useIntl();
149
+ const state = useWidgetData(api.API.widgetBrokenLinks);
150
+ if (state.loading && !state.items.length && !state.meta.lastRun)
151
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.Loading, { children: t("widget.brokenLinks.loading", "Loading links") });
152
+ if (state.error && !state.items.length)
153
+ return /* @__PURE__ */ jsxRuntime.jsx(
154
+ ErrorState,
155
+ {
156
+ text: t("widget.brokenLinks.error", "Broken links could not be loaded."),
157
+ retry: t("widget.retry", "Try again"),
158
+ onRetry: state.reload
159
+ }
160
+ );
161
+ if (state.meta.enabled === false)
162
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.NoData, { children: t("widget.brokenLinks.off", "The scheduled link check is turned off in the server configuration.") });
163
+ if (!state.meta.lastRun)
164
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.NoData, { children: t(
165
+ "widget.brokenLinks.noRun",
166
+ "The scheduled link check has not run yet. Results show up here after it runs."
167
+ ) });
168
+ const checked = t("widget.brokenLinks.lastRun", "Last check {date}", {
169
+ date: formatDate(state.meta.lastRun.finishedAt, { dateStyle: "medium", timeStyle: "short" })
170
+ });
171
+ if (!state.items.length)
172
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "center", children: [
173
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Widget.NoData, { children: t("widget.brokenLinks.empty", "No broken links in the entries you can read.") }),
174
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: checked })
175
+ ] });
176
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-broken-links-widget", children: [
177
+ /* @__PURE__ */ jsxRuntime.jsx(List, { children: state.items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
178
+ "li",
179
+ {
180
+ "data-testid": "mex-broken-entry",
181
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ItemLink, { to: index.entryPath(item.target), children: [
182
+ /* @__PURE__ */ jsxRuntime.jsx(Wrap, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: entryName(t, item.target) }),
183
+ /* @__PURE__ */ jsxRuntime.jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
184
+ t(
185
+ "widget.brokenLinks.count",
186
+ "{count, plural, one {# broken link} other {# broken links}}",
187
+ {
188
+ count: item.problems
189
+ }
190
+ ),
191
+ item.target.locale ? ` · ${item.target.locale}` : ""
192
+ ] })
193
+ ] })
194
+ },
195
+ `${item.target.uid}|${item.target.documentId}|${item.target.locale || ""}`
196
+ )) }),
197
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: state.meta.more ? t("widget.brokenLinks.more", "More entries have broken links. {date}", { date: checked }) : checked })
198
+ ] });
199
+ };
200
+ exports.BrokenLinksWidget = BrokenLinksWidget;
201
+ exports.OpenThreadsWidget = OpenThreadsWidget;
@@ -0,0 +1,225 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { Link } from "react-router-dom";
5
+ import { Flex, Typography, Button, VisuallyHidden, Box, IconButton } from "@strapi/design-system";
6
+ import { Bell, Check } from "@strapi/icons";
7
+ import { useFetchClient, Widget } from "@strapi/strapi/admin";
8
+ import styled from "styled-components";
9
+ import { A as API } from "./api-CcTYyckq.mjs";
10
+ import { g as getTranslation } from "./index-CMYCZWOh.mjs";
11
+ import { r as relativeTimeParts } from "./comments-hfIbLQNO.mjs";
12
+ const notificationPath = (item) => {
13
+ const target = item && item.target ? item.target : {};
14
+ const uid = encodeURIComponent(String(target.uid || ""));
15
+ const path = target.kind === "singleType" ? `/content-manager/single-types/${uid}` : `/content-manager/collection-types/${uid}/${encodeURIComponent(String(target.documentId || ""))}`;
16
+ const params = new URLSearchParams();
17
+ if (target.locale) params.set("plugins[i18n][locale]", target.locale);
18
+ params.set("mexThread", String(item.threadId || ""));
19
+ return `${path}?${params.toString()}`;
20
+ };
21
+ const POLL_MS = 6e4;
22
+ const PAGE_SIZE = 5;
23
+ const List = styled.ul`
24
+ list-style: none;
25
+ margin: 0;
26
+ padding: 0;
27
+ display: flex;
28
+ flex-direction: column;
29
+ gap: ${({ theme }) => theme.spaces[2]};
30
+ min-width: 0;
31
+ `;
32
+ const Item = styled.li`
33
+ display: flex;
34
+ align-items: flex-start;
35
+ gap: ${({ theme }) => theme.spaces[2]};
36
+ min-width: 0;
37
+ padding: ${({ theme }) => theme.spaces[2]};
38
+ border-radius: ${({ theme }) => theme.borderRadius};
39
+ background: ${({ theme, $unread }) => $unread ? theme.colors.primary100 : "transparent"};
40
+ `;
41
+ const Dot = styled.span`
42
+ flex: 0 0 auto;
43
+ width: 0.8rem;
44
+ height: 0.8rem;
45
+ margin-top: 0.6rem;
46
+ border-radius: 50%;
47
+ background: ${({ theme, $unread }) => $unread ? theme.colors.primary600 : "transparent"};
48
+ `;
49
+ const ItemLink = styled(Link)`
50
+ flex: 1 1 auto;
51
+ min-width: 0;
52
+ color: inherit;
53
+ text-decoration: none;
54
+ border-radius: ${({ theme }) => theme.borderRadius};
55
+ &:hover span:first-child {
56
+ text-decoration: underline;
57
+ }
58
+ &:focus-visible {
59
+ outline: 2px solid ${({ theme }) => theme.colors.primary600};
60
+ outline-offset: 2px;
61
+ }
62
+ `;
63
+ const Wrap = styled(Typography)`
64
+ display: block;
65
+ overflow-wrap: anywhere;
66
+ min-width: 0;
67
+ `;
68
+ const MentionsWidget = () => {
69
+ const { formatMessage, formatRelativeTime } = useIntl();
70
+ const { get, post } = useFetchClient();
71
+ const [state, setState] = useState({ loading: true, error: false, items: [], unread: 0 });
72
+ const [announcement, setAnnouncement] = useState("");
73
+ const requestRef = useRef(0);
74
+ const t = useCallback(
75
+ (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values),
76
+ [formatMessage]
77
+ );
78
+ const load = useCallback(() => {
79
+ const id = requestRef.current + 1;
80
+ requestRef.current = id;
81
+ return get(API.notifications, { params: { pageSize: PAGE_SIZE } }).then(
82
+ ({ data }) => {
83
+ if (requestRef.current !== id) return;
84
+ setState({
85
+ loading: false,
86
+ error: false,
87
+ items: Array.isArray(data.data) ? data.data : [],
88
+ unread: Number(data.meta && data.meta.unread) || 0
89
+ });
90
+ },
91
+ () => {
92
+ if (requestRef.current !== id) return;
93
+ setState((current) => ({ ...current, loading: false, error: true }));
94
+ }
95
+ );
96
+ }, [get]);
97
+ useEffect(() => {
98
+ let timer = null;
99
+ const schedule = () => {
100
+ window.clearTimeout(timer);
101
+ if (document.visibilityState === "hidden") return;
102
+ timer = window.setTimeout(async () => {
103
+ await load();
104
+ schedule();
105
+ }, POLL_MS);
106
+ };
107
+ const onWake = () => {
108
+ if (document.visibilityState === "hidden") {
109
+ window.clearTimeout(timer);
110
+ return;
111
+ }
112
+ load();
113
+ schedule();
114
+ };
115
+ load();
116
+ schedule();
117
+ window.addEventListener("focus", onWake);
118
+ document.addEventListener("visibilitychange", onWake);
119
+ return () => {
120
+ window.clearTimeout(timer);
121
+ window.removeEventListener("focus", onWake);
122
+ document.removeEventListener("visibilitychange", onWake);
123
+ };
124
+ }, [load]);
125
+ const act = async (request, message) => {
126
+ try {
127
+ await request();
128
+ setAnnouncement(message);
129
+ await load();
130
+ } catch {
131
+ setAnnouncement(t("widget.mentions.failed", "This did not work. Try again."));
132
+ }
133
+ };
134
+ if (state.loading && !state.items.length) {
135
+ return /* @__PURE__ */ jsx(Widget.Loading, { children: t("widget.mentions.loading", "Loading mentions") });
136
+ }
137
+ if (state.error && !state.items.length) {
138
+ return /* @__PURE__ */ jsx(Widget.Error, { children: t("widget.mentions.error", "Mentions could not be loaded.") });
139
+ }
140
+ if (!state.items.length) {
141
+ return /* @__PURE__ */ jsx(Widget.NoData, { children: t(
142
+ "widget.mentions.empty",
143
+ "No mentions yet. When someone mentions you in a comment or replies to your thread, it shows up here."
144
+ ) });
145
+ }
146
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-testid": "mex-mentions-widget", children: [
147
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
148
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("widget.mentions.unread", "{count, plural, =0 {All read} one {# unread} other {# unread}}", {
149
+ count: state.unread
150
+ }) }),
151
+ state.unread ? /* @__PURE__ */ jsx(
152
+ Button,
153
+ {
154
+ size: "S",
155
+ variant: "tertiary",
156
+ onClick: () => act(
157
+ () => post(API.notificationsReadAll, {}),
158
+ t("widget.mentions.allRead", "All notifications marked as read")
159
+ ),
160
+ children: t("widget.mentions.markAll", "Mark all as read")
161
+ }
162
+ ) : null
163
+ ] }),
164
+ /* @__PURE__ */ jsx(List, { children: state.items.map((item) => {
165
+ const actor = item.actor && item.actor.name ? item.actor.name : t("widget.mentions.deletedUser", "Deleted user");
166
+ 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 });
167
+ const where = item.target.title ? t("widget.mentions.where", "{title} ({type})", {
168
+ title: item.target.title,
169
+ type: item.target.typeName
170
+ }) : item.target.typeName;
171
+ const { value, unit } = relativeTimeParts(item.createdAt);
172
+ return /* @__PURE__ */ jsxs(
173
+ Item,
174
+ {
175
+ $unread: !item.read,
176
+ "data-testid": "mex-mention-item",
177
+ "data-read": item.read ? "true" : "false",
178
+ children: [
179
+ /* @__PURE__ */ jsx(Dot, { $unread: !item.read, "aria-hidden": "true" }),
180
+ /* @__PURE__ */ jsxs(ItemLink, { to: notificationPath(item), children: [
181
+ /* @__PURE__ */ jsxs(Wrap, { variant: "omega", fontWeight: item.read ? "regular" : "bold", textColor: "neutral800", children: [
182
+ what,
183
+ item.read ? null : /* @__PURE__ */ jsx(VisuallyHidden, { children: ` (${t("widget.mentions.new", "unread")})` })
184
+ ] }),
185
+ /* @__PURE__ */ jsxs(Wrap, { variant: "pi", textColor: "neutral600", children: [
186
+ where,
187
+ " · ",
188
+ formatRelativeTime(value, unit, { numeric: "auto" })
189
+ ] }),
190
+ item.snippet ? /* @__PURE__ */ jsx(Wrap, { variant: "pi", textColor: "neutral700", children: item.snippet }) : null
191
+ ] }),
192
+ /* @__PURE__ */ jsx(Box, { flex: "0 0 auto", children: item.read ? /* @__PURE__ */ jsx(
193
+ IconButton,
194
+ {
195
+ label: t("widget.mentions.markUnread", "Mark as unread"),
196
+ variant: "ghost",
197
+ onClick: () => act(
198
+ () => post(API.notificationUnread(item.id), {}),
199
+ t("widget.mentions.markedUnread", "Marked as unread")
200
+ ),
201
+ children: /* @__PURE__ */ jsx(Bell, {})
202
+ }
203
+ ) : /* @__PURE__ */ jsx(
204
+ IconButton,
205
+ {
206
+ label: t("widget.mentions.markRead", "Mark as read"),
207
+ variant: "ghost",
208
+ onClick: () => act(
209
+ () => post(API.notificationRead(item.id), {}),
210
+ t("widget.mentions.markedRead", "Marked as read")
211
+ ),
212
+ children: /* @__PURE__ */ jsx(Check, {})
213
+ }
214
+ ) })
215
+ ]
216
+ },
217
+ item.id
218
+ );
219
+ }) }),
220
+ /* @__PURE__ */ jsx(VisuallyHidden, { "aria-live": "polite", "aria-atomic": "true", children: announcement })
221
+ ] });
222
+ };
223
+ export {
224
+ MentionsWidget
225
+ };