magic-editor-x 2.4.0 → 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 (95) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +129 -6
  3. package/bin/magic-editor-x.mjs +55 -8
  4. package/dist/admin/{AuditPage-guB0SiGS.mjs → AuditPage-Be78C7EC.mjs} +4 -3
  5. package/dist/admin/{AuditPage-C2u6z4aN.js → AuditPage-iQzpjH8H.js} +7 -6
  6. package/dist/admin/{ConfigurationPage-DiEpF1Rr.mjs → ConfigurationPage-C9CPBfWy.mjs} +186 -6
  7. package/dist/admin/{ConfigurationPage-D6uya-J1.js → ConfigurationPage-DefuBeYO.js} +191 -11
  8. package/dist/admin/Content-BttG50Mc.mjs +360 -0
  9. package/dist/admin/Content-V5MRBsI3.js +362 -0
  10. package/dist/admin/{CustomBlocksPage-Byt10-6c.mjs → CustomBlocksPage-DB5nnCsn.mjs} +5 -4
  11. package/dist/admin/{CustomBlocksPage-DP3h_wNd.js → CustomBlocksPage-Dg2rM3F4.js} +8 -7
  12. package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
  13. package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
  14. package/dist/admin/{MentionsWidget-sMkM9mHX.mjs → MentionsWidget-CJPZDk9Z.mjs} +2 -2
  15. package/dist/admin/{MentionsWidget-C2OCAmqq.js → MentionsWidget-DUz6YVIG.js} +2 -2
  16. package/dist/admin/{useT-CLPhBmBC.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
  17. package/dist/admin/{useT-BXJLIPN4.js → SectionCard-Bs-xiiH1.js} +0 -10
  18. package/dist/admin/{TemplatesPage-Yp4OqFE2.mjs → TemplatesPage-VsZ_Mc0R.mjs} +6 -5
  19. package/dist/admin/{TemplatesPage-DrSJdteI.js → TemplatesPage-dx4_yd_t.js} +13 -12
  20. package/dist/admin/{api-bix9RLLI.js → api-4AYzwS4-.js} +9 -1
  21. package/dist/admin/{api-2ZRpHM3d.mjs → api-CcTYyckq.mjs} +9 -1
  22. package/dist/admin/{de-zcV8D7nt.js → de-B6rdcOqQ.js} +103 -1
  23. package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
  24. package/dist/admin/{de-DiCZrmH8.mjs → de-Bip0sBRT.mjs} +19 -1
  25. package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
  26. package/dist/admin/{de-CKz6CG3V.mjs → de-CQA8hOpl.mjs} +103 -1
  27. package/dist/admin/{de-CbBDnXeT.js → de-CnnxKXj7.js} +19 -1
  28. package/dist/admin/{de-BhhGss1l.js → de-Dss5POqk.js} +12 -1
  29. package/dist/admin/{de-BNPIGqhs.mjs → de-zgHCYTLH.mjs} +12 -1
  30. package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
  31. package/dist/admin/{en-cYzqbASF.mjs → en-BCKaVgBM.mjs} +103 -1
  32. package/dist/admin/{en-B9ApE1y1.js → en-CJ17Sp_e.js} +12 -1
  33. package/dist/admin/{en-BMWhILnj.js → en-CbGkcq0Q.js} +103 -1
  34. package/dist/admin/{en-DCPMqFIa.mjs → en-Cd6Jk-J0.mjs} +19 -1
  35. package/dist/admin/{en-CpehF0Kv.js → en-D69Fe9ZO.js} +19 -1
  36. package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
  37. package/dist/admin/{en-gFLeK9Ng.mjs → en-Uhm7OouM.mjs} +12 -1
  38. package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
  39. package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
  40. package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
  41. package/dist/admin/{es-BmwBgEgz.mjs → es-BMkmfH88.mjs} +12 -1
  42. package/dist/admin/{es-Chs37IBR.mjs → es-Bz8d72Fa.mjs} +19 -1
  43. package/dist/admin/{es-CQPh8PXw.js → es-C8UotT8O.js} +103 -1
  44. package/dist/admin/{es-CawpzwyC.js → es-CcEDZpVQ.js} +19 -1
  45. package/dist/admin/{es-C0W31rl8.js → es-DJm3HFJt.js} +12 -1
  46. package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
  47. package/dist/admin/{es-DCamt1ek.mjs → es-pvPfNAld.mjs} +103 -1
  48. package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
  49. package/dist/admin/{fr-Dp5-XP29.mjs → fr-CKHZ0xxU.mjs} +19 -1
  50. package/dist/admin/{fr-iGeIfEcU.js → fr-CRM9VuAq.js} +12 -1
  51. package/dist/admin/{fr-CMWBNE5D.mjs → fr-CrIHmKYX.mjs} +12 -1
  52. package/dist/admin/{fr-COOsqexl.js → fr-Cx29jQ_g.js} +19 -1
  53. package/dist/admin/{fr-oW0t8bT5.mjs → fr-D4tL6Ag2.mjs} +103 -1
  54. package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
  55. package/dist/admin/{fr-DpC44Ol8.js → fr-DrUYv2jh.js} +103 -1
  56. package/dist/admin/{index-BVjf1gVC.mjs → index-C4ksUkEm.mjs} +9183 -6353
  57. package/dist/admin/{index-64wc26Bl.js → index-C5D3VqLq.js} +9170 -6340
  58. package/dist/admin/{index-D_Fv8Non.mjs → index-CMYCZWOh.mjs} +1053 -190
  59. package/dist/admin/{index-D6Z7i8ba.js → index-DRyctF9s.js} +961 -98
  60. package/dist/admin/index.js +1 -1
  61. package/dist/admin/index.mjs +2 -2
  62. package/dist/admin/{math-vsK_06ZR.js → math-D6jmskGS.js} +1 -1
  63. package/dist/admin/{math-CIQ4Z_mY.mjs → math-DntdSWKX.mjs} +1 -1
  64. package/dist/admin/{pt-DALDvfBn.mjs → pt-B8x7v-Xw.mjs} +19 -1
  65. package/dist/admin/{pt-DXy7G1x7.js → pt-BYn2xx78.js} +19 -1
  66. package/dist/admin/{pt-Bo0Pm_Pt.js → pt-CojQcz-p.js} +103 -1
  67. package/dist/admin/{pt-uGpfRQLC.mjs → pt-CuoIihKx.mjs} +103 -1
  68. package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
  69. package/dist/admin/{pt-DFNgZ5_k.mjs → pt-DDlPJYtB.mjs} +12 -1
  70. package/dist/admin/{pt-BHmXk2d9.js → pt-DPVAycXJ.js} +12 -1
  71. package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
  72. package/dist/admin/useT-Bpw__IXT.js +12 -0
  73. package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
  74. package/dist/blocks/index.d.mts +124 -0
  75. package/dist/blocks/index.d.ts +124 -0
  76. package/dist/blocks/index.js +172 -3
  77. package/dist/blocks/index.mjs +172 -3
  78. package/dist/math/index.js +6 -2
  79. package/dist/math/index.mjs +6 -2
  80. package/dist/react/index.js +1376 -1067
  81. package/dist/react/index.mjs +1376 -1067
  82. package/dist/render/index.d.mts +22 -0
  83. package/dist/render/index.d.ts +22 -0
  84. package/dist/render/index.js +1376 -1067
  85. package/dist/render/index.mjs +1376 -1067
  86. package/dist/server/index.js +28894 -24197
  87. package/dist/server/index.mjs +28893 -24196
  88. package/dist/server/mcp-worker.js +11319 -0
  89. package/dist/vue/index.js +1376 -1067
  90. package/dist/vue/index.mjs +1376 -1067
  91. package/package.json +7 -7
  92. package/schema/magic-editor-x.schema.json +9 -1
  93. package/types/blocks.d.ts +124 -0
  94. package/types/index.d.ts +10 -1
  95. package/types/render.d.ts +22 -0
@@ -0,0 +1,360 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useState, useRef, useEffect, useId, useCallback } from "react";
3
+ import { Typography, Flex, Button, Box, TextButton, Dialog } from "@strapi/design-system";
4
+ import styled from "styled-components";
5
+ import { useFetchClient, getFetchClient } from "@strapi/strapi/admin";
6
+ import { A as API, r as readApiError } from "./api-CcTYyckq.mjs";
7
+ import { u as useT } from "./useT-Cb-R3kyA.mjs";
8
+ import { bh as createTabId, bi as isLoggedOut, bj as nextDelay, bk as IDLE_AFTER_MS, bl as fieldsWith, bm as fieldProblems } from "./index-CMYCZWOh.mjs";
9
+ import { useIntl } from "react-intl";
10
+ import { r as requestFieldPanel } from "./entry-panel-events-XRuUoLZ9.mjs";
11
+ const useEntryPresence = ({ uid, documentId, locale }) => {
12
+ const { post } = useFetchClient();
13
+ const [state, setState] = useState({
14
+ status: "loading",
15
+ enabled: false,
16
+ softLock: false,
17
+ canEdit: false,
18
+ editors: []
19
+ });
20
+ const [tabId] = useState(createTabId);
21
+ const postRef = useRef(post);
22
+ useEffect(() => {
23
+ postRef.current = post;
24
+ }, [post]);
25
+ useEffect(() => {
26
+ if (!uid || !documentId) return void 0;
27
+ let active = true;
28
+ let timer = null;
29
+ let failures = 0;
30
+ let lastInput = Date.now();
31
+ const body = (extra = {}) => ({
32
+ uid,
33
+ documentId,
34
+ ...locale ? { locale } : {},
35
+ tabId,
36
+ ...extra
37
+ });
38
+ const isIdle = () => document.visibilityState === "hidden" || Date.now() - lastInput > IDLE_AFTER_MS;
39
+ const beat = async () => {
40
+ window.clearTimeout(timer);
41
+ let delay;
42
+ try {
43
+ const { data } = await postRef.current(API.presence, body({ idle: isIdle() }));
44
+ if (!active) return;
45
+ failures = 0;
46
+ const value = data && data.data || {};
47
+ setState({
48
+ status: "ready",
49
+ enabled: value.enabled === true,
50
+ softLock: value.softLock === true,
51
+ canEdit: value.canEdit === true,
52
+ editors: Array.isArray(value.editors) ? value.editors : []
53
+ });
54
+ if (value.enabled !== true) return;
55
+ delay = nextDelay(0);
56
+ } catch (error) {
57
+ if (!active) return;
58
+ const { status } = readApiError(error);
59
+ if (status === 404 || status === 403) {
60
+ setState((current) => ({ ...current, status: "unavailable", editors: [] }));
61
+ return;
62
+ }
63
+ failures += 1;
64
+ setState((current) => ({ ...current, status: current.status === "ready" ? "ready" : "error" }));
65
+ delay = nextDelay(failures, status);
66
+ }
67
+ timer = window.setTimeout(beat, delay);
68
+ };
69
+ const onInput = () => {
70
+ const wasIdle = Date.now() - lastInput > IDLE_AFTER_MS;
71
+ lastInput = Date.now();
72
+ if (wasIdle && failures === 0) beat();
73
+ };
74
+ const onVisibility = () => {
75
+ if (document.visibilityState === "visible") lastInput = Date.now();
76
+ if (failures === 0) beat();
77
+ };
78
+ window.addEventListener("keydown", onInput, true);
79
+ window.addEventListener("pointerdown", onInput, true);
80
+ document.addEventListener("visibilitychange", onVisibility);
81
+ beat();
82
+ return () => {
83
+ active = false;
84
+ window.clearTimeout(timer);
85
+ window.removeEventListener("keydown", onInput, true);
86
+ window.removeEventListener("pointerdown", onInput, true);
87
+ document.removeEventListener("visibilitychange", onVisibility);
88
+ if (!isLoggedOut())
89
+ getFetchClient().post(API.presence, body({ leave: true })).catch(() => {
90
+ });
91
+ };
92
+ }, [uid, documentId, locale, tabId]);
93
+ return state;
94
+ };
95
+ const List = styled.ul`
96
+ list-style: none;
97
+ margin: 0;
98
+ padding: 0;
99
+ display: flex;
100
+ flex-direction: column;
101
+ gap: ${({ theme }) => theme.spaces[2]};
102
+ min-width: 0;
103
+ `;
104
+ const Row = styled.li`
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: space-between;
108
+ gap: ${({ theme }) => theme.spaces[2]};
109
+ min-width: 0;
110
+ `;
111
+ const Dot = styled.span`
112
+ flex: 0 0 auto;
113
+ width: 0.8rem;
114
+ height: 0.8rem;
115
+ border-radius: 50%;
116
+ background: ${({ theme, $color, $idle }) => $idle ? theme.colors.neutral300 : theme.colors[`${$color}600`] || theme.colors.primary600};
117
+ `;
118
+ const Wrap = styled(Typography)`
119
+ display: block;
120
+ min-width: 0;
121
+ overflow-wrap: anywhere;
122
+ `;
123
+ const EntryPanelSection = ({ title, children, testId }) => {
124
+ const id = useId();
125
+ return /* @__PURE__ */ jsxs(
126
+ Flex,
127
+ {
128
+ tag: "section",
129
+ "aria-labelledby": id,
130
+ direction: "column",
131
+ alignItems: "stretch",
132
+ gap: 2,
133
+ width: "100%",
134
+ "data-testid": testId,
135
+ "data-mex-panel-section": "",
136
+ children: [
137
+ /* @__PURE__ */ jsx(Typography, { id, tag: "h3", variant: "omega", fontWeight: "bold", textColor: "neutral800", children: title }),
138
+ children
139
+ ]
140
+ }
141
+ );
142
+ };
143
+ const PresenceSection = ({ t, presence }) => {
144
+ if (presence.status === "unavailable" || presence.status === "ready" && !presence.enabled) return null;
145
+ return /* @__PURE__ */ jsx(EntryPanelSection, { title: t("entryPanel.presence.title", "Editing now"), testId: "mex-panel-presence", children: /* @__PURE__ */ jsx("div", { "aria-live": "polite", children: presence.status === "loading" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.loading", "Loading") }) : presence.editors.length ? /* @__PURE__ */ jsx(List, { children: presence.editors.map((editor) => /* @__PURE__ */ jsx(Row, { "data-testid": "mex-panel-editor", children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", minWidth: 0, children: [
146
+ /* @__PURE__ */ jsx(Dot, { $color: editor.color, $idle: editor.idle, "aria-hidden": "true" }),
147
+ /* @__PURE__ */ jsx(Wrap, { variant: "omega", textColor: "neutral800", children: editor.idle ? t("entryPanel.presence.idle", "{name} has this entry open (idle)", {
148
+ name: editor.name
149
+ }) : t("entryPanel.presence.editing", "{name} is editing this entry", {
150
+ name: editor.name
151
+ }) })
152
+ ] }) }, editor.id)) }) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.presence.empty", "Nobody else is editing this entry right now.") }) }) });
153
+ };
154
+ const FieldRow = ({ t, field, text, action, actionLabel, panel }) => {
155
+ const [hint, setHint] = useState(false);
156
+ const group = field.label.includes(" › ") ? field.label.slice(0, field.label.lastIndexOf(" › ")) : field.label;
157
+ return /* @__PURE__ */ jsxs(Row, { children: [
158
+ /* @__PURE__ */ jsxs(Box, { minWidth: 0, children: [
159
+ /* @__PURE__ */ jsx(Wrap, { variant: "pi", fontWeight: "bold", textColor: "neutral800", children: field.label }),
160
+ /* @__PURE__ */ jsx(Wrap, { variant: "pi", textColor: "neutral600", children: text }),
161
+ /* @__PURE__ */ jsx("div", { "aria-live": "polite", children: hint ? /* @__PURE__ */ jsx(Wrap, { variant: "pi", textColor: "neutral700", "data-testid": "mex-panel-hint", children: t("entryPanel.openGroup", "Open “{group}” in the form first, then choose {action} again.", {
162
+ group,
163
+ action
164
+ }) }) : null })
165
+ ] }),
166
+ /* @__PURE__ */ jsx(Box, { flex: "0 0 auto", children: /* @__PURE__ */ jsx(
167
+ TextButton,
168
+ {
169
+ "aria-label": actionLabel,
170
+ onClick: () => setHint(!requestFieldPanel({ field: field.field, path: field.path, panel })),
171
+ children: action
172
+ }
173
+ ) })
174
+ ] });
175
+ };
176
+ const CommentsSection = ({ t, summary }) => {
177
+ if (!summary.data || !summary.data.comments.enabled) return null;
178
+ const fields = fieldsWith(summary.data.fields, (field) => field.openThreads || 0);
179
+ return /* @__PURE__ */ jsx(EntryPanelSection, { title: t("entryPanel.comments.title", "Comments"), testId: "mex-panel-comments", children: fields.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
180
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.comments.count", "{count, plural, one {# open thread} other {# open threads}}", {
181
+ count: summary.data.comments.open
182
+ }) }),
183
+ /* @__PURE__ */ jsx(List, { children: fields.map((field) => /* @__PURE__ */ jsx(
184
+ FieldRow,
185
+ {
186
+ t,
187
+ field,
188
+ panel: "comments",
189
+ text: t("entryPanel.comments.field", "{count, plural, one {# open} other {# open}}", {
190
+ count: field.openThreads
191
+ }),
192
+ action: t("entryPanel.comments.show", "Show"),
193
+ actionLabel: t("entryPanel.comments.showLabel", "Show comments in {field}", {
194
+ field: field.label
195
+ })
196
+ },
197
+ field.path
198
+ )) })
199
+ ] }) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
200
+ "entryPanel.comments.empty",
201
+ "No open comments. To start one, select text in a field and choose Comment."
202
+ ) }) });
203
+ };
204
+ const QualitySection = ({ t, summary }) => {
205
+ const { formatDate } = useIntl();
206
+ if (!summary.data) return null;
207
+ const { quality, links } = summary.data;
208
+ const fields = fieldsWith(summary.data.fields, fieldProblems);
209
+ return /* @__PURE__ */ jsxs(EntryPanelSection, { title: t("entryPanel.quality.title", "Quality"), testId: "mex-panel-quality", children: [
210
+ fields.length ? /* @__PURE__ */ jsx(List, { children: fields.map((field) => {
211
+ const issues = field.issues.errors + field.issues.warnings;
212
+ const broken = field.brokenLinks && field.brokenLinks.draft || 0;
213
+ return /* @__PURE__ */ jsx(
214
+ FieldRow,
215
+ {
216
+ t,
217
+ field,
218
+ panel: "quality",
219
+ text: [
220
+ issues ? t("entryPanel.quality.issues", "{count, plural, one {# issue} other {# issues}}", {
221
+ count: issues
222
+ }) : null,
223
+ broken ? t(
224
+ "entryPanel.quality.broken",
225
+ "{count, plural, one {# broken link} other {# broken links}}",
226
+ {
227
+ count: broken
228
+ }
229
+ ) : null
230
+ ].filter(Boolean).join(" · "),
231
+ action: t("entryPanel.quality.check", "Check"),
232
+ actionLabel: t("entryPanel.quality.checkLabel", "Check {field}", { field: field.label })
233
+ },
234
+ field.path
235
+ );
236
+ }) }) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.quality.empty", "No problems found in the saved draft.") }),
237
+ quality.errors + quality.warnings || links.enabled && links.draft ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.quality.savedDraft", "Counts are for the saved draft. Save to update them.") }) : null,
238
+ links.enabled && links.published ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
239
+ "entryPanel.quality.published",
240
+ "{count, plural, one {The published version has # broken link.} other {The published version has # broken links.}}",
241
+ { count: links.published }
242
+ ) }) : null,
243
+ links.enabled ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: links.lastRun && links.lastRun.finishedAt ? t("entryPanel.quality.lastRun", "Links last checked {date}", {
244
+ date: formatDate(links.lastRun.finishedAt, { dateStyle: "medium", timeStyle: "short" })
245
+ }) : t("entryPanel.quality.noRun", "The scheduled link check has not run yet.") }) : null
246
+ ] });
247
+ };
248
+ const SummaryStatus = ({ t, summary }) => {
249
+ if (summary.status === "loading" && !summary.data)
250
+ return /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.loading", "Loading") });
251
+ if (summary.status === "error" && !summary.data)
252
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
253
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("entryPanel.error", "Comments and quality could not be loaded.") }),
254
+ /* @__PURE__ */ jsx(Button, { size: "S", variant: "tertiary", onClick: summary.reload, children: t("entryPanel.retry", "Try again") })
255
+ ] });
256
+ return null;
257
+ };
258
+ const ENTRY_PANEL_SECTIONS = [
259
+ { id: "presence", Component: PresenceSection },
260
+ { id: "summary-status", Component: SummaryStatus },
261
+ { id: "comments", Component: CommentsSection },
262
+ { id: "quality", Component: QualitySection }
263
+ ];
264
+ const FOCUS_REFRESH_MS = 1e4;
265
+ const Sections = styled(Flex)`
266
+ & > [data-mex-panel-section] ~ [data-mex-panel-section] {
267
+ border-top: 1px solid ${({ theme }) => theme.colors.neutral150};
268
+ padding-top: ${({ theme }) => theme.spaces[3]};
269
+ }
270
+ `;
271
+ const useEntrySummary = ({ uid, documentId, locale }, version) => {
272
+ const { get } = useFetchClient();
273
+ const [state, setState] = useState({ status: "loading", data: null });
274
+ const requestRef = useRef(0);
275
+ const lastRef = useRef(0);
276
+ const load = useCallback(() => {
277
+ const id = requestRef.current + 1;
278
+ requestRef.current = id;
279
+ lastRef.current = Date.now();
280
+ get(API.entrySummary, { params: { uid, documentId, ...locale ? { locale } : {} } }).then(
281
+ ({ data }) => {
282
+ if (requestRef.current === id) setState({ status: "ready", data: data && data.data || null });
283
+ },
284
+ () => {
285
+ if (requestRef.current === id) setState((current) => ({ ...current, status: "error" }));
286
+ }
287
+ );
288
+ }, [get, uid, documentId, locale]);
289
+ useEffect(() => {
290
+ load();
291
+ }, [load, version]);
292
+ useEffect(() => {
293
+ const onFocus = () => {
294
+ if (Date.now() - lastRef.current > FOCUS_REFRESH_MS) load();
295
+ };
296
+ window.addEventListener("focus", onFocus);
297
+ return () => window.removeEventListener("focus", onFocus);
298
+ }, [load]);
299
+ const reload = useCallback(() => {
300
+ setState((current) => ({ ...current, status: "loading" }));
301
+ load();
302
+ }, [load]);
303
+ return { ...state, reload };
304
+ };
305
+ const useAcknowledged = (key) => {
306
+ const storageKey = `magic-editor-x:soft-lock:${key}`;
307
+ const read = () => {
308
+ try {
309
+ return window.sessionStorage.getItem(storageKey) === "1";
310
+ } catch {
311
+ return false;
312
+ }
313
+ };
314
+ const [acknowledged, setAcknowledged] = useState(read);
315
+ const acknowledge = useCallback(() => {
316
+ setAcknowledged(true);
317
+ try {
318
+ window.sessionStorage.setItem(storageKey, "1");
319
+ } catch {
320
+ }
321
+ }, [storageKey]);
322
+ return [acknowledged, acknowledge];
323
+ };
324
+ const EntryPanelContent = ({ uid, documentId, locale, version }) => {
325
+ const t = useT();
326
+ const target = { uid, documentId, locale };
327
+ const presence = useEntryPresence(target);
328
+ const summary = useEntrySummary(target, version);
329
+ const continueRef = useRef(null);
330
+ const [acknowledged, acknowledge] = useAcknowledged(`${uid}|${documentId}|${locale || "-"}`);
331
+ const others = presence.editors.filter((editor) => !editor.idle);
332
+ const lockOpen = presence.status === "ready" && presence.softLock && presence.canEdit && !acknowledged && others.length > 0;
333
+ const names = others.map((editor) => editor.name);
334
+ return /* @__PURE__ */ jsxs(Sections, { direction: "column", alignItems: "stretch", gap: 3, width: "100%", "data-testid": "mex-entry-panel", children: [
335
+ ENTRY_PANEL_SECTIONS.map(({ id, Component }) => /* @__PURE__ */ jsx(Component, { t, target, presence, summary }, id)),
336
+ /* @__PURE__ */ jsx(Dialog.Root, { open: lockOpen, onOpenChange: (open) => !open ? acknowledge() : void 0, children: /* @__PURE__ */ jsxs(
337
+ Dialog.Content,
338
+ {
339
+ "data-testid": "mex-soft-lock",
340
+ onOpenAutoFocus: (event) => {
341
+ event.preventDefault();
342
+ if (continueRef.current) continueRef.current.focus();
343
+ },
344
+ children: [
345
+ /* @__PURE__ */ jsx(Dialog.Header, { children: t("entryPanel.softLock.title", "Someone else is editing this entry") }),
346
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsx(Dialog.Description, { children: t(
347
+ "entryPanel.softLock.body",
348
+ "{names} {count, plural, one {is} other {are}} editing this entry right now. To avoid overwriting each other's changes, agree who changes what.",
349
+ { names: names.join(", "), count: names.length }
350
+ ) }) }),
351
+ /* @__PURE__ */ jsx(Dialog.Footer, { children: /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { ref: continueRef, fullWidth: true, onClick: acknowledge, children: t("entryPanel.softLock.continue", "Continue editing") }) }) })
352
+ ]
353
+ }
354
+ ) })
355
+ ] });
356
+ };
357
+ export {
358
+ EntryPanelContent,
359
+ EntryPanelContent as default
360
+ };