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,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-4AYzwS4-.js");
12
+ const index = require("./index-DRyctF9s.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;
@@ -1,9 +1,7 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useId, useCallback } from "react";
2
+ import { useId } from "react";
3
3
  import { Flex, Box, Typography } from "@strapi/design-system";
4
4
  import { Page, Layouts } from "@strapi/strapi/admin";
5
- import { useIntl } from "react-intl";
6
- import { U as getTranslation } from "./index-My6FjjHB.mjs";
7
5
  const PageShell = ({
8
6
  title,
9
7
  subtitle,
@@ -51,15 +49,7 @@ const SectionCard = ({ title, subtitle, action, headingTag = "h2", children }) =
51
49
  ] })
52
50
  }
53
51
  );
54
- const useT = () => {
55
- const { formatMessage } = useIntl();
56
- return useCallback(
57
- (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values),
58
- [formatMessage]
59
- );
60
- };
61
52
  export {
62
53
  PageShell as P,
63
- SectionCard as S,
64
- useT as u
54
+ SectionCard as S
65
55
  };
@@ -3,8 +3,6 @@ const jsxRuntime = require("react/jsx-runtime");
3
3
  const ReactNamespace = require("react");
4
4
  const designSystem = require("@strapi/design-system");
5
5
  const admin = require("@strapi/strapi/admin");
6
- const reactIntl = require("react-intl");
7
- const index = require("./index-DR8sHkTk.js");
8
6
  const PageShell = ({
9
7
  title,
10
8
  subtitle,
@@ -52,13 +50,5 @@ const SectionCard = ({ title, subtitle, action, headingTag = "h2", children }) =
52
50
  ] })
53
51
  }
54
52
  );
55
- const useT = () => {
56
- const { formatMessage } = reactIntl.useIntl();
57
- return ReactNamespace.useCallback(
58
- (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values),
59
- [formatMessage]
60
- );
61
- };
62
53
  exports.PageShell = PageShell;
63
54
  exports.SectionCard = SectionCard;
64
- exports.useT = useT;
@@ -1,17 +1,20 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useState, useRef, useEffect, useCallback, useMemo } from "react";
3
3
  import { useSearchParams } from "react-router-dom";
4
- import { Flex, Box, Badge, Typography, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Switch, IconButton, Loader, Button, Alert, Grid, Field, TextInput, Radio, Textarea, MultiSelect, MultiSelectOption, EmptyStateLayout, SingleSelect, SingleSelectOption, Modal } from "@strapi/design-system";
5
- import { Eye, Pencil, Duplicate, ArrowUp, ArrowDown, Trash, ArrowLeft, Check, Plus } from "@strapi/icons";
4
+ import { Flex, Box, Badge, Typography, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Switch, IconButton, Loader, Button, Field, TextInput, Tabs, Dialog, Alert, Grid, Radio, Textarea, MultiSelect, MultiSelectOption, EmptyStateLayout, SingleSelect, SingleSelectOption, Modal } from "@strapi/design-system";
5
+ import { Eye, Pencil, Duplicate, ArrowUp, ArrowDown, Trash, ArrowClockwise, ArrowLeft, Check, Plus } from "@strapi/icons";
6
6
  import { EmptyDocuments } from "@strapi/icons/symbols";
7
- import { useFetchClient, Form, Blocker, useNotification, useRBAC, Page } from "@strapi/strapi/admin";
8
- import { P as PERMISSIONS } from "./index-My6FjjHB.mjs";
9
- import { A as API, C as ConfirmAction, a as refocusIfLost, r as readApiError } from "./ConfirmAction-DuQwvRYi.mjs";
10
- import { u as useT, P as PageShell, S as SectionCard } from "./useT-Cmg1jwwG.mjs";
7
+ import { useFetchClient, useNotification, ConfirmDialog, Form, Blocker, useRBAC, Page } from "@strapi/strapi/admin";
8
+ import { P as PERMISSIONS } from "./index-CMYCZWOh.mjs";
9
+ import { A as API, r as readApiError } from "./api-CcTYyckq.mjs";
10
+ import { S as SectionCard, P as PageShell } from "./SectionCard-8ZNHkvn9.mjs";
11
+ import { C as ConfirmAction, r as refocusIfLost } from "./ConfirmAction-CZjpduc3.mjs";
11
12
  import "styled-components";
12
- import { n as normalizeScope, T as TEMPLATE_LIMITS, i as isEmptyDocument, c as containsSynced, P as PRESET_NAMES, E as EditorFieldBody, R as RenderedContent, r as resetEditorConfigCache } from "./index-k8_a5o1A.mjs";
13
+ import { u as useT } from "./useT-Cb-R3kyA.mjs";
14
+ import { n as normalizeScope, T as TEMPLATE_LIMITS, i as isEmptyDocument, c as containsSynced, V as VersionDiff, p as previewLines, P as PRESET_NAMES, E as EditorFieldBody, R as RenderedContent, r as resetEditorConfigCache } from "./index-C4ksUkEm.mjs";
13
15
  import { u as useBreakpoint } from "./useBreakpoint-DCfn6pDG.mjs";
14
16
  import { D as DraftSync } from "./DraftSync-CUxOMG-E.mjs";
17
+ import { useIntl } from "react-intl";
15
18
  const fieldKey = (entry) => `${entry.uid}|${entry.field}`;
16
19
  const fieldFromKey = (key) => {
17
20
  const [uid, field] = String(key).split("|");
@@ -397,6 +400,293 @@ const TemplateList = ({ templates, busyId, onToggle, ...actions }) => {
397
400
  ] }, template.id)) })
398
401
  ] });
399
402
  };
403
+ const MAX_LABEL_LENGTH = 120;
404
+ const TRIGGERS = {
405
+ manual: { key: "settings.syncedVersions.trigger.manual", text: "Saved" },
406
+ restore: { key: "settings.syncedVersions.trigger.restore", text: "Restored" }
407
+ };
408
+ const SyncedVersions = ({ template, current, dirty, onRestored }) => {
409
+ const t = useT();
410
+ const { formatDate } = useIntl();
411
+ const { get, put, post } = useFetchClient();
412
+ const { toggleNotification } = useNotification();
413
+ const [state, setState] = useState({ loading: true, error: false, items: [] });
414
+ const [preview, setPreview] = useState(null);
415
+ const [tab, setTab] = useState("preview");
416
+ const [renaming, setRenaming] = useState(null);
417
+ const [renameBusy, setRenameBusy] = useState(false);
418
+ const [confirm, setConfirm] = useState(null);
419
+ const [restoring, setRestoring] = useState(false);
420
+ const renameButtons = useRef(/* @__PURE__ */ new Map());
421
+ const fetchList = useCallback(
422
+ () => get(API.templateVersions(template.id)).then(
423
+ ({ data }) => setState({ loading: false, error: false, items: data.data || [] }),
424
+ () => setState((value) => ({ ...value, loading: false, error: true }))
425
+ ),
426
+ [get, template.id]
427
+ );
428
+ useEffect(() => {
429
+ fetchList();
430
+ }, [fetchList, template.updatedAt]);
431
+ const reload = () => {
432
+ setState((value) => ({ ...value, loading: true, error: false }));
433
+ return fetchList();
434
+ };
435
+ const showPreview = async (item) => {
436
+ if (preview && preview.item.id === item.id) {
437
+ setPreview(null);
438
+ return;
439
+ }
440
+ setTab("preview");
441
+ setPreview({ item, loading: true });
442
+ try {
443
+ const { data } = await get(API.templateVersion(template.id, item.id));
444
+ setPreview({
445
+ item,
446
+ loading: false,
447
+ content: data.data.content,
448
+ lines: previewLines(data.data.content)
449
+ });
450
+ } catch {
451
+ setPreview({ item, loading: false, error: true });
452
+ }
453
+ };
454
+ const endRename = (id) => {
455
+ setRenaming(null);
456
+ window.requestAnimationFrame(() => {
457
+ const button = renameButtons.current.get(id);
458
+ if (button) button.focus();
459
+ });
460
+ };
461
+ const saveRename = async (event) => {
462
+ if (event) event.preventDefault();
463
+ if (!renaming || renameBusy || renaming.value.trim().length > MAX_LABEL_LENGTH) return;
464
+ setRenameBusy(true);
465
+ try {
466
+ await put(API.templateVersion(template.id, renaming.id), { label: renaming.value.trim() || null });
467
+ toggleNotification({
468
+ type: "success",
469
+ message: t("settings.syncedVersions.renamed", "Version name saved.")
470
+ });
471
+ const id = renaming.id;
472
+ await reload();
473
+ endRename(id);
474
+ } catch (error) {
475
+ toggleNotification({
476
+ type: "danger",
477
+ message: readApiError(error).message || t("settings.syncedVersions.renameFailed", "The name could not be saved.")
478
+ });
479
+ } finally {
480
+ setRenameBusy(false);
481
+ }
482
+ };
483
+ const restore = async () => {
484
+ const item = confirm;
485
+ setRestoring(true);
486
+ try {
487
+ const { data } = await post(API.templateVersionRestore(template.id, item.id), {});
488
+ toggleNotification({
489
+ type: "success",
490
+ message: t(
491
+ "settings.syncedVersions.restored",
492
+ "Version {version} restored. Every field that uses this synced block shows it now.",
493
+ { version: item.version }
494
+ )
495
+ });
496
+ setConfirm(null);
497
+ onRestored(data.data);
498
+ } catch (error) {
499
+ const info = readApiError(error);
500
+ toggleNotification({
501
+ type: "danger",
502
+ message: info.status === 400 ? t(
503
+ "settings.syncedVersions.restoreInvalid",
504
+ 'This version cannot be restored with the current settings (for example a field in "Where it is offered" no longer exists).'
505
+ ) : t("settings.syncedVersions.restoreFailed", "This version could not be restored.")
506
+ });
507
+ } finally {
508
+ setRestoring(false);
509
+ }
510
+ };
511
+ return /* @__PURE__ */ jsxs(
512
+ SectionCard,
513
+ {
514
+ title: t("settings.syncedVersions.title", "Versions"),
515
+ subtitle: t(
516
+ "settings.syncedVersions.subtitle",
517
+ "Every save of this synced block is kept as a version. Restoring a version saves it again as the newest one."
518
+ ),
519
+ children: [
520
+ state.loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("settings.syncedVersions.loading", "Loading versions") }) }) : null,
521
+ state.error ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
522
+ /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: t("settings.syncedVersions.error", "Versions could not be loaded.") }),
523
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsx(ArrowClockwise, {}), onClick: reload, children: t("settings.retry", "Try again") })
524
+ ] }) : null,
525
+ !state.loading && !state.error && state.items.length === 0 ? /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: t("settings.syncedVersions.empty", "No versions yet. They are created when you save.") }) : null,
526
+ !state.error && state.items.length > 0 ? /* @__PURE__ */ jsx(
527
+ Flex,
528
+ {
529
+ tag: "ul",
530
+ direction: "column",
531
+ alignItems: "stretch",
532
+ gap: 2,
533
+ "aria-label": t("settings.syncedVersions.listLabel", "Versions of this synced block"),
534
+ children: state.items.map((item, index) => {
535
+ const trigger = TRIGGERS[item.trigger] || TRIGGERS.manual;
536
+ const when = item.createdAt ? formatDate(new Date(item.createdAt), { dateStyle: "medium", timeStyle: "short" }) : "";
537
+ const versionText = t("settings.syncedVersions.version", "Version {version}", {
538
+ version: item.version
539
+ });
540
+ return /* @__PURE__ */ jsxs(
541
+ Box,
542
+ {
543
+ tag: "li",
544
+ padding: 3,
545
+ hasRadius: true,
546
+ borderColor: "neutral200",
547
+ background: "neutral0",
548
+ children: [
549
+ /* @__PURE__ */ jsxs(Flex, { gap: 3, justifyContent: "space-between", wrap: "wrap", children: [
550
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, flex: "1 1 20rem", children: [
551
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", minWidth: 0, children: [
552
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", style: { overflowWrap: "anywhere" }, children: item.label || versionText }),
553
+ item.label ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: versionText }) : null,
554
+ /* @__PURE__ */ jsx(Badge, { children: t(trigger.key, trigger.text) }),
555
+ index === 0 ? /* @__PURE__ */ jsx(Badge, { backgroundColor: "success100", textColor: "success700", children: t("settings.syncedVersions.current", "Current") }) : null
556
+ ] }),
557
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: item.createdBy ? t("settings.syncedVersions.byline", "{date} by {name}", {
558
+ date: when,
559
+ name: item.createdBy.name
560
+ }) : when }),
561
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: t(
562
+ "settings.syncedVersions.details",
563
+ "{name} · {blocks, plural, one {# block} other {# blocks}}",
564
+ { name: item.name, blocks: item.blockCount }
565
+ ) })
566
+ ] }),
567
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
568
+ /* @__PURE__ */ jsx(
569
+ IconButton,
570
+ {
571
+ label: t("settings.syncedVersions.preview", "Preview version {version}", {
572
+ version: item.version
573
+ }),
574
+ variant: "tertiary",
575
+ "aria-expanded": Boolean(preview && preview.item.id === item.id),
576
+ onClick: () => showPreview(item),
577
+ children: /* @__PURE__ */ jsx(Eye, {})
578
+ }
579
+ ),
580
+ /* @__PURE__ */ jsx(
581
+ IconButton,
582
+ {
583
+ ref: (node) => {
584
+ if (node) renameButtons.current.set(item.id, node);
585
+ else renameButtons.current.delete(item.id);
586
+ },
587
+ label: t("settings.syncedVersions.rename", "Rename version {version}", {
588
+ version: item.version
589
+ }),
590
+ variant: "tertiary",
591
+ onClick: () => setRenaming({ id: item.id, value: item.label || "" }),
592
+ children: /* @__PURE__ */ jsx(Pencil, {})
593
+ }
594
+ ),
595
+ index > 0 ? /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => setConfirm(item), children: t("settings.syncedVersions.restore", "Restore") }) : null
596
+ ] })
597
+ ] }),
598
+ renaming && renaming.id === item.id ? /* @__PURE__ */ jsx(Box, { tag: "form", marginTop: 3, onSubmit: saveRename, noValidate: true, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
599
+ /* @__PURE__ */ jsxs(
600
+ Field.Root,
601
+ {
602
+ name: `mex-synced-version-label-${item.id}`,
603
+ hint: t("settings.syncedVersions.renameHint", "Leave empty to remove the name."),
604
+ error: renaming.value.trim().length > MAX_LABEL_LENGTH ? t("settings.syncedVersions.labelTooLong", "Use 120 characters or fewer.") : void 0,
605
+ children: [
606
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.syncedVersions.renameLabel", "Version name") }),
607
+ /* @__PURE__ */ jsx(
608
+ TextInput,
609
+ {
610
+ autoFocus: true,
611
+ value: renaming.value,
612
+ onChange: (event) => setRenaming({ ...renaming, value: event.target.value }),
613
+ onKeyDown: (event) => {
614
+ if (event.key === "Escape") {
615
+ event.preventDefault();
616
+ event.stopPropagation();
617
+ endRename(item.id);
618
+ }
619
+ }
620
+ }
621
+ ),
622
+ /* @__PURE__ */ jsx(Field.Hint, {}),
623
+ /* @__PURE__ */ jsx(Field.Error, {})
624
+ ]
625
+ }
626
+ ),
627
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
628
+ /* @__PURE__ */ jsx(Button, { type: "submit", size: "S", loading: renameBusy, children: t("settings.syncedVersions.renameSave", "Save name") }),
629
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "S", variant: "tertiary", onClick: () => endRename(item.id), children: t("settings.syncedVersions.renameCancel", "Cancel") })
630
+ ] })
631
+ ] }) }) : null,
632
+ preview && preview.item.id === item.id ? /* @__PURE__ */ jsxs(Box, { marginTop: 3, padding: 3, background: "neutral100", hasRadius: true, minWidth: 0, children: [
633
+ preview.loading ? /* @__PURE__ */ jsx(Loader, { small: true, children: t("settings.syncedVersions.previewLoading", "Loading preview") }) : null,
634
+ preview.error ? /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: t("settings.syncedVersions.previewError", "The preview could not be loaded.") }) : null,
635
+ preview.content ? /* @__PURE__ */ jsxs(Tabs.Root, { value: tab, onValueChange: setTab, children: [
636
+ /* @__PURE__ */ jsxs(Tabs.List, { "aria-label": t("settings.syncedVersions.tabs", "Version views"), children: [
637
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "preview", children: t("settings.syncedVersions.tab.preview", "Preview") }),
638
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "changes", children: t("settings.syncedVersions.tab.changes", "Changes") })
639
+ ] }),
640
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "preview", children: /* @__PURE__ */ jsx(Box, { paddingTop: 3, children: preview.lines.map((line, lineIndex) => /* @__PURE__ */ jsx(
641
+ Typography,
642
+ {
643
+ tag: "p",
644
+ variant: "pi",
645
+ textColor: "neutral800",
646
+ style: { overflowWrap: "anywhere" },
647
+ children: line
648
+ },
649
+ lineIndex
650
+ )) }) }),
651
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "changes", children: /* @__PURE__ */ jsx(Box, { paddingTop: 3, children: tab === "changes" ? /* @__PURE__ */ jsx(
652
+ VersionDiff,
653
+ {
654
+ t,
655
+ version: preview.content,
656
+ current: current || { blocks: [] },
657
+ versionNumber: item.version,
658
+ canRestore: false
659
+ }
660
+ ) : null }) })
661
+ ] }) : null
662
+ ] }) : null
663
+ ]
664
+ },
665
+ item.id
666
+ );
667
+ })
668
+ }
669
+ ) : null,
670
+ /* @__PURE__ */ jsx(Dialog.Root, { open: Boolean(confirm), onOpenChange: (open) => !open && !restoring && setConfirm(null), children: confirm ? /* @__PURE__ */ jsx(
671
+ ConfirmDialog,
672
+ {
673
+ title: t("settings.syncedVersions.confirmTitle", "Restore version {version}?", {
674
+ version: confirm.version
675
+ }),
676
+ endAction: /* @__PURE__ */ jsx(Button, { variant: "danger-light", loading: restoring, onClick: restore, children: t("settings.syncedVersions.restore", "Restore") }),
677
+ children: dirty ? t(
678
+ "settings.syncedVersions.confirmBodyDirty",
679
+ "The synced block is saved with the content of this version, and every field that uses it shows it at once. Your unsaved changes in this form are lost."
680
+ ) : t(
681
+ "settings.syncedVersions.confirmBody",
682
+ "The synced block is saved with the content of this version, and every field that uses it shows it at once."
683
+ )
684
+ }
685
+ ) : null })
686
+ ]
687
+ }
688
+ );
689
+ };
400
690
  const EDITOR_TARGET = Object.freeze({
401
691
  uid: null,
402
692
  documentId: null,
@@ -428,7 +718,7 @@ const errorText = (t, code) => {
428
718
  });
429
719
  return code;
430
720
  };
431
- const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack }) => {
721
+ const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack, onRestored }) => {
432
722
  const t = useT();
433
723
  const saved = useMemo(() => template ? fromDto(template) : emptyValues(), [template]);
434
724
  const [values, setValues] = useState(saved);
@@ -712,6 +1002,7 @@ const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack })
712
1002
  )
713
1003
  }
714
1004
  ),
1005
+ savedSynced && onRestored ? /* @__PURE__ */ jsx(SyncedVersions, { template, current: values.blocks, dirty, onRestored }) : null,
715
1006
  /* @__PURE__ */ jsxs(Form, { method: "PUT", initialValues: savedKey, children: [
716
1007
  /* @__PURE__ */ jsx(DraftSync, { values: draftKey }),
717
1008
  /* @__PURE__ */ jsx(Blocker, {})
@@ -817,6 +1108,11 @@ const TemplatesPage = () => {
817
1108
  return { ok: false };
818
1109
  }
819
1110
  };
1111
+ const onRestored = async (template) => {
1112
+ resetEditorConfigCache();
1113
+ await data.reload();
1114
+ setEditing({ template, key: `${template.id}:${template.updatedAt || Date.now()}` });
1115
+ };
820
1116
  if (editing) {
821
1117
  return /* @__PURE__ */ jsx(
822
1118
  TemplateEditor,
@@ -825,7 +1121,8 @@ const TemplatesPage = () => {
825
1121
  targets: data.targets,
826
1122
  onRetryTargets: data.reloadTargets,
827
1123
  onSubmit,
828
- onBack: backToList
1124
+ onBack: backToList,
1125
+ onRestored
829
1126
  },
830
1127
  editing.key
831
1128
  );
@@ -976,7 +1273,7 @@ const TemplatesPage = () => {
976
1273
  setPreview(null);
977
1274
  requestAnimationFrame(() => refocusIfLost(previewOpenerRef.current, createRef.current));
978
1275
  },
979
- children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
1276
+ children: /* @__PURE__ */ jsxs(Modal.Content, { "aria-describedby": void 0, children: [
980
1277
  /* @__PURE__ */ jsx(Modal.Header, { closeLabel: t("settings.close", "Close"), children: /* @__PURE__ */ jsx(Modal.Title, { children: t("settings.templates.preview.title", "Preview of {name}", { name: preview.name }) }) }),
981
1278
  /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(Box, { "data-testid": "mex-settings-template-preview", children: /* @__PURE__ */ jsx(RenderedContent, { value: preview.blocks, t }) }) }),
982
1279
  /* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("settings.close", "Close") }) }) })