magic-editor-x 2.3.1 → 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 +74 -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-CFP3lp9p.js → ConfigurationPage-D6uya-J1.js} +228 -13
  6. package/dist/admin/{ConfigurationPage-CYGDLjM7.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-B5Q33N-s.mjs → CustomBlocksPage-Byt10-6c.mjs} +6 -4
  10. package/dist/admin/{CustomBlocksPage-DzPOSpfn.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-BVkgafCK.js → TemplatesPage-DrSJdteI.js} +313 -17
  14. package/dist/admin/{TemplatesPage-4A8JNO_Z.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-DQVE0ymw.js → index-64wc26Bl.js} +17467 -10369
  46. package/dist/admin/{index-k8_a5o1A.mjs → index-BVjf1gVC.mjs} +13786 -6687
  47. package/dist/admin/{index-DR8sHkTk.js → index-D6Z7i8ba.js} +1003 -53
  48. package/dist/admin/{index-My6FjjHB.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-DNphiBQR.js → useT-BXJLIPN4.js} +1 -1
  60. package/dist/admin/{useT-Cmg1jwwG.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,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-2ZRpHM3d.mjs";
10
+ import { g as getTranslation } from "./index-D_Fv8Non.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
+ };
@@ -7,13 +7,15 @@ const designSystem = require("@strapi/design-system");
7
7
  const icons = require("@strapi/icons");
8
8
  const symbols = require("@strapi/icons/symbols");
9
9
  const admin = require("@strapi/strapi/admin");
10
- const index$1 = require("./index-DR8sHkTk.js");
11
- const ConfirmAction = require("./ConfirmAction-zLuIFj8t.js");
12
- const useT = require("./useT-DNphiBQR.js");
10
+ const index$1 = require("./index-D6Z7i8ba.js");
11
+ const api = require("./api-bix9RLLI.js");
12
+ const useT = require("./useT-BXJLIPN4.js");
13
+ const ConfirmAction = require("./ConfirmAction-CUhpngYU.js");
13
14
  require("styled-components");
14
- const index = require("./index-DQVE0ymw.js");
15
+ const index = require("./index-64wc26Bl.js");
15
16
  const useBreakpoint = require("./useBreakpoint-D30eNTkF.js");
16
17
  const DraftSync = require("./DraftSync-BIA8cZgA.js");
18
+ const reactIntl = require("react-intl");
17
19
  const fieldKey = (entry) => `${entry.uid}|${entry.field}`;
18
20
  const fieldFromKey = (key) => {
19
21
  const [uid, field] = String(key).split("|");
@@ -110,7 +112,7 @@ const useTemplateList = () => {
110
112
  };
111
113
  }, []);
112
114
  const fetchTemplates = ReactNamespace.useCallback(
113
- () => get(ConfirmAction.API.templates, { params: { all: "true" } }).then(
115
+ () => get(api.API.templates, { params: { all: "true" } }).then(
114
116
  ({ data }) => {
115
117
  if (!mounted.current) return;
116
118
  setTemplates(Array.isArray(data.data) ? data.data : []);
@@ -127,7 +129,7 @@ const useTemplateList = () => {
127
129
  [get]
128
130
  );
129
131
  const fetchTargets = ReactNamespace.useCallback(
130
- () => get(ConfirmAction.API.templateTargets).then(
132
+ () => get(api.API.templateTargets).then(
131
133
  ({ data }) => {
132
134
  if (mounted.current)
133
135
  setTargets({ status: "ready", items: Array.isArray(data.data) ? data.data : [] });
@@ -163,7 +165,7 @@ const SyncedUsage = ({ template }) => {
163
165
  const [state, setState] = ReactNamespace.useState({ status: "loading", usage: null });
164
166
  ReactNamespace.useEffect(() => {
165
167
  const controller = new AbortController();
166
- get(ConfirmAction.API.templateUsage(template.id), { signal: controller.signal }).then(
168
+ get(api.API.templateUsage(template.id), { signal: controller.signal }).then(
167
169
  ({ data }) => {
168
170
  if (!controller.signal.aborted) setState({ status: "ready", usage: data.data });
169
171
  },
@@ -399,6 +401,293 @@ const TemplateList = ({ templates, busyId, onToggle, ...actions }) => {
399
401
  ] }, template.id)) })
400
402
  ] });
401
403
  };
404
+ const MAX_LABEL_LENGTH = 120;
405
+ const TRIGGERS = {
406
+ manual: { key: "settings.syncedVersions.trigger.manual", text: "Saved" },
407
+ restore: { key: "settings.syncedVersions.trigger.restore", text: "Restored" }
408
+ };
409
+ const SyncedVersions = ({ template, current, dirty, onRestored }) => {
410
+ const t = useT.useT();
411
+ const { formatDate } = reactIntl.useIntl();
412
+ const { get, put, post } = admin.useFetchClient();
413
+ const { toggleNotification } = admin.useNotification();
414
+ const [state, setState] = ReactNamespace.useState({ loading: true, error: false, items: [] });
415
+ const [preview, setPreview] = ReactNamespace.useState(null);
416
+ const [tab, setTab] = ReactNamespace.useState("preview");
417
+ const [renaming, setRenaming] = ReactNamespace.useState(null);
418
+ const [renameBusy, setRenameBusy] = ReactNamespace.useState(false);
419
+ const [confirm, setConfirm] = ReactNamespace.useState(null);
420
+ const [restoring, setRestoring] = ReactNamespace.useState(false);
421
+ const renameButtons = ReactNamespace.useRef(/* @__PURE__ */ new Map());
422
+ const fetchList = ReactNamespace.useCallback(
423
+ () => get(api.API.templateVersions(template.id)).then(
424
+ ({ data }) => setState({ loading: false, error: false, items: data.data || [] }),
425
+ () => setState((value) => ({ ...value, loading: false, error: true }))
426
+ ),
427
+ [get, template.id]
428
+ );
429
+ ReactNamespace.useEffect(() => {
430
+ fetchList();
431
+ }, [fetchList, template.updatedAt]);
432
+ const reload = () => {
433
+ setState((value) => ({ ...value, loading: true, error: false }));
434
+ return fetchList();
435
+ };
436
+ const showPreview = async (item) => {
437
+ if (preview && preview.item.id === item.id) {
438
+ setPreview(null);
439
+ return;
440
+ }
441
+ setTab("preview");
442
+ setPreview({ item, loading: true });
443
+ try {
444
+ const { data } = await get(api.API.templateVersion(template.id, item.id));
445
+ setPreview({
446
+ item,
447
+ loading: false,
448
+ content: data.data.content,
449
+ lines: index.previewLines(data.data.content)
450
+ });
451
+ } catch {
452
+ setPreview({ item, loading: false, error: true });
453
+ }
454
+ };
455
+ const endRename = (id) => {
456
+ setRenaming(null);
457
+ window.requestAnimationFrame(() => {
458
+ const button = renameButtons.current.get(id);
459
+ if (button) button.focus();
460
+ });
461
+ };
462
+ const saveRename = async (event) => {
463
+ if (event) event.preventDefault();
464
+ if (!renaming || renameBusy || renaming.value.trim().length > MAX_LABEL_LENGTH) return;
465
+ setRenameBusy(true);
466
+ try {
467
+ await put(api.API.templateVersion(template.id, renaming.id), { label: renaming.value.trim() || null });
468
+ toggleNotification({
469
+ type: "success",
470
+ message: t("settings.syncedVersions.renamed", "Version name saved.")
471
+ });
472
+ const id = renaming.id;
473
+ await reload();
474
+ endRename(id);
475
+ } catch (error) {
476
+ toggleNotification({
477
+ type: "danger",
478
+ message: api.readApiError(error).message || t("settings.syncedVersions.renameFailed", "The name could not be saved.")
479
+ });
480
+ } finally {
481
+ setRenameBusy(false);
482
+ }
483
+ };
484
+ const restore = async () => {
485
+ const item = confirm;
486
+ setRestoring(true);
487
+ try {
488
+ const { data } = await post(api.API.templateVersionRestore(template.id, item.id), {});
489
+ toggleNotification({
490
+ type: "success",
491
+ message: t(
492
+ "settings.syncedVersions.restored",
493
+ "Version {version} restored. Every field that uses this synced block shows it now.",
494
+ { version: item.version }
495
+ )
496
+ });
497
+ setConfirm(null);
498
+ onRestored(data.data);
499
+ } catch (error) {
500
+ const info = api.readApiError(error);
501
+ toggleNotification({
502
+ type: "danger",
503
+ message: info.status === 400 ? t(
504
+ "settings.syncedVersions.restoreInvalid",
505
+ 'This version cannot be restored with the current settings (for example a field in "Where it is offered" no longer exists).'
506
+ ) : t("settings.syncedVersions.restoreFailed", "This version could not be restored.")
507
+ });
508
+ } finally {
509
+ setRestoring(false);
510
+ }
511
+ };
512
+ return /* @__PURE__ */ jsxRuntime.jsxs(
513
+ useT.SectionCard,
514
+ {
515
+ title: t("settings.syncedVersions.title", "Versions"),
516
+ subtitle: t(
517
+ "settings.syncedVersions.subtitle",
518
+ "Every save of this synced block is kept as a version. Restoring a version saves it again as the newest one."
519
+ ),
520
+ children: [
521
+ state.loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: t("settings.syncedVersions.loading", "Loading versions") }) }) : null,
522
+ state.error ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
523
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: t("settings.syncedVersions.error", "Versions could not be loaded.") }),
524
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}), onClick: reload, children: t("settings.retry", "Try again") })
525
+ ] }) : null,
526
+ !state.loading && !state.error && state.items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: t("settings.syncedVersions.empty", "No versions yet. They are created when you save.") }) : null,
527
+ !state.error && state.items.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
528
+ designSystem.Flex,
529
+ {
530
+ tag: "ul",
531
+ direction: "column",
532
+ alignItems: "stretch",
533
+ gap: 2,
534
+ "aria-label": t("settings.syncedVersions.listLabel", "Versions of this synced block"),
535
+ children: state.items.map((item, index$12) => {
536
+ const trigger = TRIGGERS[item.trigger] || TRIGGERS.manual;
537
+ const when = item.createdAt ? formatDate(new Date(item.createdAt), { dateStyle: "medium", timeStyle: "short" }) : "";
538
+ const versionText = t("settings.syncedVersions.version", "Version {version}", {
539
+ version: item.version
540
+ });
541
+ return /* @__PURE__ */ jsxRuntime.jsxs(
542
+ designSystem.Box,
543
+ {
544
+ tag: "li",
545
+ padding: 3,
546
+ hasRadius: true,
547
+ borderColor: "neutral200",
548
+ background: "neutral0",
549
+ children: [
550
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, justifyContent: "space-between", wrap: "wrap", children: [
551
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, flex: "1 1 20rem", children: [
552
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", minWidth: 0, children: [
553
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "bold", style: { overflowWrap: "anywhere" }, children: item.label || versionText }),
554
+ item.label ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: versionText }) : null,
555
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { children: t(trigger.key, trigger.text) }),
556
+ index$12 === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "success100", textColor: "success700", children: t("settings.syncedVersions.current", "Current") }) : null
557
+ ] }),
558
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: item.createdBy ? t("settings.syncedVersions.byline", "{date} by {name}", {
559
+ date: when,
560
+ name: item.createdBy.name
561
+ }) : when }),
562
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: t(
563
+ "settings.syncedVersions.details",
564
+ "{name} · {blocks, plural, one {# block} other {# blocks}}",
565
+ { name: item.name, blocks: item.blockCount }
566
+ ) })
567
+ ] }),
568
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
569
+ /* @__PURE__ */ jsxRuntime.jsx(
570
+ designSystem.IconButton,
571
+ {
572
+ label: t("settings.syncedVersions.preview", "Preview version {version}", {
573
+ version: item.version
574
+ }),
575
+ variant: "tertiary",
576
+ "aria-expanded": Boolean(preview && preview.item.id === item.id),
577
+ onClick: () => showPreview(item),
578
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Eye, {})
579
+ }
580
+ ),
581
+ /* @__PURE__ */ jsxRuntime.jsx(
582
+ designSystem.IconButton,
583
+ {
584
+ ref: (node) => {
585
+ if (node) renameButtons.current.set(item.id, node);
586
+ else renameButtons.current.delete(item.id);
587
+ },
588
+ label: t("settings.syncedVersions.rename", "Rename version {version}", {
589
+ version: item.version
590
+ }),
591
+ variant: "tertiary",
592
+ onClick: () => setRenaming({ id: item.id, value: item.label || "" }),
593
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {})
594
+ }
595
+ ),
596
+ index$12 > 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", onClick: () => setConfirm(item), children: t("settings.syncedVersions.restore", "Restore") }) : null
597
+ ] })
598
+ ] }),
599
+ renaming && renaming.id === item.id ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "form", marginTop: 3, onSubmit: saveRename, noValidate: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
600
+ /* @__PURE__ */ jsxRuntime.jsxs(
601
+ designSystem.Field.Root,
602
+ {
603
+ name: `mex-synced-version-label-${item.id}`,
604
+ hint: t("settings.syncedVersions.renameHint", "Leave empty to remove the name."),
605
+ error: renaming.value.trim().length > MAX_LABEL_LENGTH ? t("settings.syncedVersions.labelTooLong", "Use 120 characters or fewer.") : void 0,
606
+ children: [
607
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.syncedVersions.renameLabel", "Version name") }),
608
+ /* @__PURE__ */ jsxRuntime.jsx(
609
+ designSystem.TextInput,
610
+ {
611
+ autoFocus: true,
612
+ value: renaming.value,
613
+ onChange: (event) => setRenaming({ ...renaming, value: event.target.value }),
614
+ onKeyDown: (event) => {
615
+ if (event.key === "Escape") {
616
+ event.preventDefault();
617
+ event.stopPropagation();
618
+ endRename(item.id);
619
+ }
620
+ }
621
+ }
622
+ ),
623
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
624
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
625
+ ]
626
+ }
627
+ ),
628
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
629
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { type: "submit", size: "S", loading: renameBusy, children: t("settings.syncedVersions.renameSave", "Save name") }),
630
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { type: "button", size: "S", variant: "tertiary", onClick: () => endRename(item.id), children: t("settings.syncedVersions.renameCancel", "Cancel") })
631
+ ] })
632
+ ] }) }) : null,
633
+ preview && preview.item.id === item.id ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginTop: 3, padding: 3, background: "neutral100", hasRadius: true, minWidth: 0, children: [
634
+ preview.loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: t("settings.syncedVersions.previewLoading", "Loading preview") }) : null,
635
+ preview.error ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: t("settings.syncedVersions.previewError", "The preview could not be loaded.") }) : null,
636
+ preview.content ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.Root, { value: tab, onValueChange: setTab, children: [
637
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.List, { "aria-label": t("settings.syncedVersions.tabs", "Version views"), children: [
638
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "preview", children: t("settings.syncedVersions.tab.preview", "Preview") }),
639
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "changes", children: t("settings.syncedVersions.tab.changes", "Changes") })
640
+ ] }),
641
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "preview", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 3, children: preview.lines.map((line, lineIndex) => /* @__PURE__ */ jsxRuntime.jsx(
642
+ designSystem.Typography,
643
+ {
644
+ tag: "p",
645
+ variant: "pi",
646
+ textColor: "neutral800",
647
+ style: { overflowWrap: "anywhere" },
648
+ children: line
649
+ },
650
+ lineIndex
651
+ )) }) }),
652
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "changes", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 3, children: tab === "changes" ? /* @__PURE__ */ jsxRuntime.jsx(
653
+ index.VersionDiff,
654
+ {
655
+ t,
656
+ version: preview.content,
657
+ current: current || { blocks: [] },
658
+ versionNumber: item.version,
659
+ canRestore: false
660
+ }
661
+ ) : null }) })
662
+ ] }) : null
663
+ ] }) : null
664
+ ]
665
+ },
666
+ item.id
667
+ );
668
+ })
669
+ }
670
+ ) : null,
671
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: Boolean(confirm), onOpenChange: (open) => !open && !restoring && setConfirm(null), children: confirm ? /* @__PURE__ */ jsxRuntime.jsx(
672
+ admin.ConfirmDialog,
673
+ {
674
+ title: t("settings.syncedVersions.confirmTitle", "Restore version {version}?", {
675
+ version: confirm.version
676
+ }),
677
+ endAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", loading: restoring, onClick: restore, children: t("settings.syncedVersions.restore", "Restore") }),
678
+ children: dirty ? t(
679
+ "settings.syncedVersions.confirmBodyDirty",
680
+ "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."
681
+ ) : t(
682
+ "settings.syncedVersions.confirmBody",
683
+ "The synced block is saved with the content of this version, and every field that uses it shows it at once."
684
+ )
685
+ }
686
+ ) : null })
687
+ ]
688
+ }
689
+ );
690
+ };
402
691
  const EDITOR_TARGET = Object.freeze({
403
692
  uid: null,
404
693
  documentId: null,
@@ -430,7 +719,7 @@ const errorText = (t, code) => {
430
719
  });
431
720
  return code;
432
721
  };
433
- const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack }) => {
722
+ const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack, onRestored }) => {
434
723
  const t = useT.useT();
435
724
  const saved = ReactNamespace.useMemo(() => template ? fromDto(template) : emptyValues(), [template]);
436
725
  const [values, setValues] = ReactNamespace.useState(saved);
@@ -714,6 +1003,7 @@ const TemplateEditor = ({ template, targets, onRetryTargets, onSubmit, onBack })
714
1003
  )
715
1004
  }
716
1005
  ),
1006
+ savedSynced && onRestored ? /* @__PURE__ */ jsxRuntime.jsx(SyncedVersions, { template, current: values.blocks, dirty, onRestored }) : null,
717
1007
  /* @__PURE__ */ jsxRuntime.jsxs(admin.Form, { method: "PUT", initialValues: savedKey, children: [
718
1008
  /* @__PURE__ */ jsxRuntime.jsx(DraftSync.DraftSync, { values: draftKey }),
719
1009
  /* @__PURE__ */ jsxRuntime.jsx(admin.Blocker, {})
@@ -774,7 +1064,7 @@ const TemplatesPage = () => {
774
1064
  ] });
775
1065
  }
776
1066
  const failed = (error, fallback) => {
777
- const info = ConfirmAction.readApiError(error);
1067
+ const info = api.readApiError(error);
778
1068
  toggleNotification({
779
1069
  type: "danger",
780
1070
  message: info.status === 404 ? t("settings.templates.notFound", "This template no longer exists.") : fallback
@@ -787,8 +1077,8 @@ const TemplatesPage = () => {
787
1077
  const onSubmit = async (values) => {
788
1078
  const payload = toPayload(values);
789
1079
  try {
790
- if (editing.template) await put(ConfirmAction.API.template(editing.template.id), payload);
791
- else await post(ConfirmAction.API.templates, payload);
1080
+ if (editing.template) await put(api.API.template(editing.template.id), payload);
1081
+ else await post(api.API.templates, payload);
792
1082
  toggleNotification({
793
1083
  type: "success",
794
1084
  message: editing.template ? t("settings.templates.saved", "Template {name} saved.", { name: payload.name }) : t("settings.templates.created", "Template {name} created.", { name: payload.name })
@@ -798,7 +1088,7 @@ const TemplatesPage = () => {
798
1088
  backToList();
799
1089
  return { ok: true };
800
1090
  } catch (error) {
801
- const info = ConfirmAction.readApiError(error);
1091
+ const info = api.readApiError(error);
802
1092
  if (info.status === 400) {
803
1093
  toggleNotification({
804
1094
  type: "warning",
@@ -819,6 +1109,11 @@ const TemplatesPage = () => {
819
1109
  return { ok: false };
820
1110
  }
821
1111
  };
1112
+ const onRestored = async (template) => {
1113
+ index.resetEditorConfigCache();
1114
+ await data.reload();
1115
+ setEditing({ template, key: `${template.id}:${template.updatedAt || Date.now()}` });
1116
+ };
822
1117
  if (editing) {
823
1118
  return /* @__PURE__ */ jsxRuntime.jsx(
824
1119
  TemplateEditor,
@@ -827,7 +1122,8 @@ const TemplatesPage = () => {
827
1122
  targets: data.targets,
828
1123
  onRetryTargets: data.reloadTargets,
829
1124
  onSubmit,
830
- onBack: backToList
1125
+ onBack: backToList,
1126
+ onRestored
831
1127
  },
832
1128
  editing.key
833
1129
  );
@@ -835,7 +1131,7 @@ const TemplatesPage = () => {
835
1131
  const onToggle = async (template, enabled) => {
836
1132
  setBusyId(template.id);
837
1133
  try {
838
- const { data: response } = await put(ConfirmAction.API.template(template.id), withEnabled(template, enabled));
1134
+ const { data: response } = await put(api.API.template(template.id), withEnabled(template, enabled));
839
1135
  data.setTemplates((current) => current.map((item) => item.id === template.id ? response.data : item));
840
1136
  toggleNotification({
841
1137
  type: "success",
@@ -852,7 +1148,7 @@ const TemplatesPage = () => {
852
1148
  const onDuplicate = async (template) => {
853
1149
  setBusyId(template.id);
854
1150
  try {
855
- const { data: response } = await post(ConfirmAction.API.templateDuplicate(template.id), {});
1151
+ const { data: response } = await post(api.API.templateDuplicate(template.id), {});
856
1152
  toggleNotification({
857
1153
  type: "success",
858
1154
  message: t("settings.templates.duplicated", "Copy {name} created. It is off until you turn it on.", {
@@ -878,7 +1174,7 @@ const TemplatesPage = () => {
878
1174
  const opener = typeof document !== "undefined" ? document.activeElement : null;
879
1175
  setBusyId(template.id);
880
1176
  try {
881
- const { data: response } = await put(ConfirmAction.API.templatesOrder, { ids });
1177
+ const { data: response } = await put(api.API.templatesOrder, { ids });
882
1178
  data.setTemplates(response.data);
883
1179
  } catch (error) {
884
1180
  failed(error, t("settings.templates.moveError", "The order could not be saved."));
@@ -889,7 +1185,7 @@ const TemplatesPage = () => {
889
1185
  };
890
1186
  const onDelete = async (template) => {
891
1187
  try {
892
- await del(ConfirmAction.API.template(template.id));
1188
+ await del(api.API.template(template.id));
893
1189
  toggleNotification({
894
1190
  type: "success",
895
1191
  message: t("settings.templates.deleted", "Template {name} deleted.", { name: template.name })