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
@@ -3,11 +3,14 @@
3
3
  * Magic Editor X command line.
4
4
  *
5
5
  * npx magic-editor-x migrate --uid api::article.article --from body --to content [--apply]
6
+ * npx magic-editor-x media-file-ids [--apply] (2.5)
6
7
  *
7
8
  * Run it from the root of the Strapi project. It loads the project with
8
9
  * Strapi's programmatic API (compileStrapi, createStrapi().load(), destroy()),
9
10
  * without starting the HTTP server, runs the plugin's `migrate` service and
10
11
  * prints the report. Without `--apply` nothing is written (dry run).
12
+ * `media-file-ids` runs the plugin's `media` service `migrateFileIds`
13
+ * (the 2.5 migration, re-runnable).
11
14
  */
12
15
 
13
16
  import { createRequire } from 'node:module';
@@ -36,7 +39,14 @@ Options:
36
39
  --out <file> Also write the JSON report to a file
37
40
  -h, --help Show this help
38
41
 
39
- Exit code 1 when an option is invalid or a document failed.`;
42
+ Exit code 1 when an option is invalid or a document failed.
43
+
44
+ Usage: magic-editor-x media-file-ids [--apply] [--json] [--batch <n>]
45
+
46
+ Links the Media Library files of every Magic Editor X field (image, gallery,
47
+ video, audio, poster, track and attachment files) to their Media Library
48
+ entry by URL, and removes stored signatures of a private upload provider.
49
+ Safe to run again; without --apply nothing is written (dry run).`;
40
50
 
41
51
  /**
42
52
  * Parses and validates the command line.
@@ -65,14 +75,25 @@ export const parseCommand = (argv) => {
65
75
  },
66
76
  });
67
77
  if (values.help) return { help: true };
68
- if (positionals.length !== 1 || positionals[0] !== 'migrate')
69
- throw new Error('Unknown command (expected "migrate")');
70
- for (const name of ['uid', 'from', 'to']) if (!values[name]) throw new Error(`--${name} is required`);
71
78
  const integer = (name) => {
72
79
  if (values[name] === undefined) return undefined;
73
80
  if (!/^\d{1,7}$/.test(values[name])) throw new Error(`--${name} must be a positive integer`);
74
81
  return Number(values[name]);
75
82
  };
83
+ if (positionals.length === 1 && positionals[0] === 'media-file-ids') {
84
+ for (const name of ['uid', 'from', 'to', 'format', 'locale', 'overwrite', 'limit', 'out'])
85
+ if (values[name] !== undefined) throw new Error(`--${name} is not an option of media-file-ids`);
86
+ const batch = integer('batch');
87
+ return {
88
+ help: false,
89
+ command: 'media-file-ids',
90
+ json: Boolean(values.json),
91
+ options: { dryRun: !values.apply, ...(batch !== undefined ? { batchSize: batch } : {}) },
92
+ };
93
+ }
94
+ if (positionals.length !== 1 || positionals[0] !== 'migrate')
95
+ throw new Error('Unknown command (expected "migrate" or "media-file-ids")');
96
+ for (const name of ['uid', 'from', 'to']) if (!values[name]) throw new Error(`--${name} is required`);
76
97
  const options = {
77
98
  uid: values.uid,
78
99
  from: values.from,
@@ -89,6 +110,26 @@ export const parseCommand = (argv) => {
89
110
  return { help: false, json: Boolean(values.json), out: values.out, options };
90
111
  };
91
112
 
113
+ /**
114
+ * Formats a media file id report for people (2.5).
115
+ * @param {object} report - `media.migrateFileIds` report.
116
+ * @returns {string} Text.
117
+ */
118
+ export const formatMediaReport = (report) => {
119
+ const lines = [
120
+ `${report.dryRun ? 'Dry run' : 'Migration'}: Media Library file ids`,
121
+ ` models ${report.models}`,
122
+ ` rows scanned ${report.scanned}`,
123
+ ` ${report.dryRun ? 'would change' : 'changed '} ${report.changedValues}`,
124
+ ` files linked ${report.linked}`,
125
+ ` signatures removed ${report.unsigned}`,
126
+ ` not in library ${report.unmatched}`,
127
+ ` failed ${report.failed}`,
128
+ ];
129
+ if (report.dryRun) lines.push('Nothing was written. Run again with --apply to write.');
130
+ return lines.join('\n');
131
+ };
132
+
92
133
  /**
93
134
  * Formats a report for people.
94
135
  * @param {object} report - Migration report.
@@ -153,10 +194,16 @@ export const main = async (argv) => {
153
194
  throw Object.assign(new Error('Magic Editor X is not installed in this project'), {
154
195
  code: 'NO_PLUGIN',
155
196
  });
156
- const report = await plugin.service('migrate').run(command.options);
157
- if (command.out) writeFileSync(command.out, `${JSON.stringify(report, null, 2)}\n`);
158
- print(`${command.json ? JSON.stringify(report, null, 2) : formatReport(report)}\n`);
159
- code = report.failed.length > 0 ? 1 : 0;
197
+ if (command.command === 'media-file-ids') {
198
+ const report = await plugin.service('media').migrateFileIds(command.options);
199
+ print(`${command.json ? JSON.stringify(report, null, 2) : formatMediaReport(report)}\n`);
200
+ code = report.failed > 0 ? 1 : 0;
201
+ } else {
202
+ const report = await plugin.service('migrate').run(command.options);
203
+ if (command.out) writeFileSync(command.out, `${JSON.stringify(report, null, 2)}\n`);
204
+ print(`${command.json ? JSON.stringify(report, null, 2) : formatReport(report)}\n`);
205
+ code = report.failed.length > 0 ? 1 : 0;
206
+ }
160
207
  } catch (error) {
161
208
  process.stderr.write(`${error && error.message ? error.message : 'Migration failed'}\n`);
162
209
  code = 1;
@@ -0,0 +1,382 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { Flex, Typography, Button, Loader, EmptyStateLayout, Box, Badge, Table, Thead, Tr, Th, Tbody, Td, Alert, Grid, Field, SingleSelect, SingleSelectOption, TextInput } from "@strapi/design-system";
5
+ import { ArrowClockwise, Filter } from "@strapi/icons";
6
+ import { useFetchClient, useRBAC, useQueryParams, Page, Pagination } from "@strapi/strapi/admin";
7
+ import { P as PERMISSIONS } from "./index-CMYCZWOh.mjs";
8
+ import { A as API } from "./api-CcTYyckq.mjs";
9
+ import { P as PageShell, S as SectionCard } from "./SectionCard-8ZNHkvn9.mjs";
10
+ import { u as useBreakpoint } from "./useBreakpoint-DCfn6pDG.mjs";
11
+ import { u as useT } from "./useT-Cb-R3kyA.mjs";
12
+ import { c as changeSummary, e as eventLabel, a as actorLabel, E as EVENT_LABELS } from "./auditText-DIIYVR6k.mjs";
13
+ const ALL = "__all__";
14
+ const UID_PATTERN = /^(api|plugin)::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/;
15
+ const DOCUMENT_ID_PATTERN = /^[a-z0-9]{1,64}$/;
16
+ const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
17
+ const FILTER_KEYS = ["event", "actor", "uid", "documentId", "from", "to"];
18
+ const readFilters = (query) => {
19
+ const text = (key) => typeof query[key] === "string" ? query[key] : "";
20
+ return {
21
+ event: text("event"),
22
+ actor: /^\d{1,10}$/.test(text("actor")) ? text("actor") : "",
23
+ uid: text("uid"),
24
+ documentId: text("documentId"),
25
+ from: DATE_PATTERN.test(text("from")) ? text("from") : "",
26
+ to: DATE_PATTERN.test(text("to")) ? text("to") : ""
27
+ };
28
+ };
29
+ const AuditFilters = ({ t, applied, actors, active, onApply, onReset }) => {
30
+ const [draft, setDraft] = useState(applied);
31
+ const uidInvalid = draft.uid !== "" && !UID_PATTERN.test(draft.uid);
32
+ const documentInvalid = draft.documentId !== "" && !DOCUMENT_ID_PATTERN.test(draft.documentId);
33
+ const documentWithoutUid = draft.documentId !== "" && draft.uid === "";
34
+ const rangeInvalid = Boolean(draft.from && draft.to && draft.from > draft.to);
35
+ const canApply = !uidInvalid && !documentInvalid && !documentWithoutUid && !rangeInvalid;
36
+ const apply = (event) => {
37
+ if (event) event.preventDefault();
38
+ if (canApply) onApply(draft);
39
+ };
40
+ const reset = onReset;
41
+ return /* @__PURE__ */ jsx(
42
+ SectionCard,
43
+ {
44
+ title: t("settings.audit.filters", "Filters"),
45
+ action: active ? /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: reset, children: t("settings.audit.reset", "Reset filters") }) : null,
46
+ children: /* @__PURE__ */ jsxs(Box, { tag: "form", onSubmit: apply, noValidate: true, children: [
47
+ /* @__PURE__ */ jsxs(Grid.Root, { gap: { initial: 4, medium: 6 }, children: [
48
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(Field.Root, { name: "event", children: [
49
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.event", "Event") }),
50
+ /* @__PURE__ */ jsxs(
51
+ SingleSelect,
52
+ {
53
+ value: draft.event || ALL,
54
+ onChange: (value) => setDraft({ ...draft, event: value === ALL ? "" : String(value) }),
55
+ children: [
56
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: ALL, children: t("settings.audit.filter.allEvents", "All events") }),
57
+ Object.keys(EVENT_LABELS).map((event) => /* @__PURE__ */ jsx(SingleSelectOption, { value: event, children: eventLabel(t, event) }, event))
58
+ ]
59
+ }
60
+ )
61
+ ] }) }),
62
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(Field.Root, { name: "actor", children: [
63
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.actor", "Changed by") }),
64
+ /* @__PURE__ */ jsxs(
65
+ SingleSelect,
66
+ {
67
+ value: draft.actor || ALL,
68
+ onChange: (value) => setDraft({ ...draft, actor: value === ALL ? "" : String(value) }),
69
+ children: [
70
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: ALL, children: t("settings.audit.filter.allActors", "Everyone") }),
71
+ actors.map((actor) => /* @__PURE__ */ jsx(SingleSelectOption, { value: String(actor.id), children: actor.name || t("settings.audit.actor.unnamed", "Admin without a name") }, actor.id))
72
+ ]
73
+ }
74
+ )
75
+ ] }) }),
76
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(
77
+ Field.Root,
78
+ {
79
+ name: "uid",
80
+ error: uidInvalid ? t("settings.audit.filter.uidInvalid", "Use a uid such as api::article.article.") : void 0,
81
+ children: [
82
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.uid", "Content type") }),
83
+ /* @__PURE__ */ jsx(
84
+ TextInput,
85
+ {
86
+ value: draft.uid,
87
+ placeholder: "api::article.article",
88
+ onChange: (event) => setDraft({ ...draft, uid: event.target.value.trim() })
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsx(Field.Error, {})
92
+ ]
93
+ }
94
+ ) }),
95
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(
96
+ Field.Root,
97
+ {
98
+ name: "documentId",
99
+ hint: t("settings.audit.filter.documentHint", "Needs a content type."),
100
+ error: documentInvalid ? t("settings.audit.filter.documentInvalid", "Use lowercase letters and digits only.") : documentWithoutUid ? t("settings.audit.filter.documentHint", "Needs a content type.") : void 0,
101
+ children: [
102
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.document", "Document id") }),
103
+ /* @__PURE__ */ jsx(
104
+ TextInput,
105
+ {
106
+ value: draft.documentId,
107
+ onChange: (event) => setDraft({ ...draft, documentId: event.target.value.trim() })
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsx(Field.Hint, {}),
111
+ /* @__PURE__ */ jsx(Field.Error, {})
112
+ ]
113
+ }
114
+ ) }),
115
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(Field.Root, { name: "from", children: [
116
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.from", "From") }),
117
+ /* @__PURE__ */ jsx(
118
+ TextInput,
119
+ {
120
+ type: "date",
121
+ value: draft.from,
122
+ onChange: (event) => setDraft({ ...draft, from: event.target.value })
123
+ }
124
+ )
125
+ ] }) }),
126
+ /* @__PURE__ */ jsx(Grid.Item, { col: 4, s: 6, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(
127
+ Field.Root,
128
+ {
129
+ name: "to",
130
+ error: rangeInvalid ? t("settings.audit.filter.rangeInvalid", "The end is before the start.") : void 0,
131
+ children: [
132
+ /* @__PURE__ */ jsx(Field.Label, { children: t("settings.audit.filter.to", "To") }),
133
+ /* @__PURE__ */ jsx(
134
+ TextInput,
135
+ {
136
+ type: "date",
137
+ value: draft.to,
138
+ onChange: (event) => setDraft({ ...draft, to: event.target.value })
139
+ }
140
+ ),
141
+ /* @__PURE__ */ jsx(Field.Error, {})
142
+ ]
143
+ }
144
+ ) })
145
+ ] }),
146
+ /* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", paddingTop: 6, children: /* @__PURE__ */ jsx(Button, { type: "submit", startIcon: /* @__PURE__ */ jsx(Filter, {}), disabled: !canApply, children: t("settings.audit.apply", "Apply filters") }) })
147
+ ] })
148
+ }
149
+ );
150
+ };
151
+ const AuditPage = () => {
152
+ const t = useT();
153
+ const { formatDate } = useIntl();
154
+ const { get } = useFetchClient();
155
+ const { isBelowLarge } = useBreakpoint();
156
+ const audit = useRBAC(PERMISSIONS.auditRead);
157
+ const settings = useRBAC(PERMISSIONS.settingsRead);
158
+ const [{ query }, setQuery] = useQueryParams();
159
+ const applied = readFilters(query);
160
+ const page = Math.max(1, Number(query.page) || 1);
161
+ const pageSize = [10, 25, 50, 100].includes(Number(query.pageSize)) ? Number(query.pageSize) : 25;
162
+ const [result, setResult] = useState({
163
+ key: null,
164
+ failed: false,
165
+ items: [],
166
+ pagination: null,
167
+ enabled: true
168
+ });
169
+ const [nonce, setNonce] = useState(0);
170
+ const [actors, setActors] = useState([]);
171
+ const allowed = audit.allowedActions.canRead && settings.allowedActions.canRead;
172
+ const appliedKey = JSON.stringify(applied);
173
+ const requestKey = `${appliedKey}|${page}|${pageSize}|${nonce}`;
174
+ const title = t("settings.audit.title", "Audit trail");
175
+ const state = {
176
+ ...result,
177
+ status: result.key !== requestKey ? "loading" : result.failed ? "error" : "ready"
178
+ };
179
+ const params = { page, pageSize };
180
+ if (applied.event) params.event = applied.event;
181
+ if (applied.actor) params.actor = applied.actor;
182
+ if (UID_PATTERN.test(applied.uid)) params.uid = applied.uid;
183
+ if (params.uid && DOCUMENT_ID_PATTERN.test(applied.documentId)) params.documentId = applied.documentId;
184
+ if (applied.from) params.from = `${applied.from}T00:00:00`;
185
+ if (applied.to) params.to = `${applied.to}T23:59:59`;
186
+ const paramsKey = JSON.stringify(params);
187
+ useEffect(() => {
188
+ if (!allowed) return void 0;
189
+ let active2 = true;
190
+ get(API.audit, { params: JSON.parse(paramsKey) }).then(
191
+ ({ data }) => {
192
+ if (!active2) return;
193
+ setResult({
194
+ key: requestKey,
195
+ failed: false,
196
+ items: data.data || [],
197
+ pagination: data.meta && data.meta.pagination || null,
198
+ enabled: !(data.meta && data.meta.enabled === false)
199
+ });
200
+ },
201
+ () => {
202
+ if (active2) setResult((current) => ({ ...current, key: requestKey, failed: true }));
203
+ }
204
+ );
205
+ return () => {
206
+ active2 = false;
207
+ };
208
+ }, [allowed, get, paramsKey, requestKey]);
209
+ const load = () => setNonce((value) => value + 1);
210
+ useEffect(() => {
211
+ if (!allowed) return;
212
+ get(API.auditActors).then(
213
+ ({ data }) => setActors(data.data || []),
214
+ () => setActors([])
215
+ );
216
+ }, [allowed, get]);
217
+ if (audit.isLoading || settings.isLoading) {
218
+ return /* @__PURE__ */ jsxs(Page.Main, { children: [
219
+ /* @__PURE__ */ jsx(Page.Title, { children: title }),
220
+ /* @__PURE__ */ jsx(Page.Loading, {})
221
+ ] });
222
+ }
223
+ if (!allowed) {
224
+ return /* @__PURE__ */ jsxs(Page.Main, { children: [
225
+ /* @__PURE__ */ jsx(Page.Title, { children: title }),
226
+ /* @__PURE__ */ jsx(Page.NoPermissions, {})
227
+ ] });
228
+ }
229
+ const apply = (draft) => {
230
+ const next = { page: 1, pageSize };
231
+ for (const key of FILTER_KEYS) next[key] = draft[key] || void 0;
232
+ setQuery(next);
233
+ };
234
+ const reset = () => {
235
+ const cleared = Object.fromEntries(FILTER_KEYS.map((key) => [key, void 0]));
236
+ setQuery({ ...cleared, page: 1, pageSize });
237
+ };
238
+ const active = FILTER_KEYS.some((key) => applied[key]);
239
+ const when = (value) => formatDate(new Date(value), { dateStyle: "medium", timeStyle: "short" });
240
+ const targetText = (item) => {
241
+ const target = item.target || {};
242
+ if (!target.uid) return t("settings.audit.target.none", "Plugin settings");
243
+ const parts = [target.uid];
244
+ if (target.documentId) parts.push(target.documentId);
245
+ if (target.locale) parts.push(target.locale);
246
+ if (target.field) parts.push(target.field);
247
+ return parts.join(" · ");
248
+ };
249
+ const filters = /* @__PURE__ */ jsx(
250
+ AuditFilters,
251
+ {
252
+ t,
253
+ applied,
254
+ actors,
255
+ active,
256
+ onApply: apply,
257
+ onReset: reset
258
+ },
259
+ appliedKey
260
+ );
261
+ let results;
262
+ if (state.status === "error") {
263
+ results = /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
264
+ /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: t("settings.audit.error", "The audit trail could not be loaded.") }),
265
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsx(ArrowClockwise, {}), onClick: load, children: t("settings.retry", "Try again") })
266
+ ] });
267
+ } else if (state.status === "loading" && state.items.length === 0) {
268
+ results = /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 6, children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("settings.audit.loading", "Loading the audit trail") }) });
269
+ } else if (state.items.length === 0) {
270
+ results = /* @__PURE__ */ jsx(
271
+ EmptyStateLayout,
272
+ {
273
+ content: active ? t("settings.audit.emptyFiltered", "No events match these filters.") : t("settings.audit.empty", "No events recorded yet.")
274
+ }
275
+ );
276
+ } else if (isBelowLarge) {
277
+ results = /* @__PURE__ */ jsx(Flex, { tag: "ul", direction: "column", alignItems: "stretch", gap: 3, "aria-label": title, children: state.items.map((item) => {
278
+ const summary = changeSummary(t, item);
279
+ return /* @__PURE__ */ jsx(
280
+ Box,
281
+ {
282
+ tag: "li",
283
+ padding: 4,
284
+ hasRadius: true,
285
+ borderColor: "neutral200",
286
+ background: "neutral0",
287
+ minWidth: 0,
288
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
289
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
290
+ /* @__PURE__ */ jsx(Badge, { children: eventLabel(t, item.event) }),
291
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: when(item.createdAt) })
292
+ ] }),
293
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: actorLabel(t, item.actor) }),
294
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: targetText(item) }),
295
+ summary ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral800", style: { overflowWrap: "anywhere" }, children: summary }) : null
296
+ ] })
297
+ },
298
+ item.id
299
+ );
300
+ }) });
301
+ } else {
302
+ results = /* @__PURE__ */ jsxs(Table, { colCount: 5, rowCount: state.items.length + 1, children: [
303
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
304
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: t("settings.audit.col.time", "Time") }) }),
305
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: t("settings.audit.col.event", "Event") }) }),
306
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: t("settings.audit.col.actor", "Changed by") }) }),
307
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: t("settings.audit.col.target", "Where") }) }),
308
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: t("settings.audit.col.changes", "Changes") }) })
309
+ ] }) }),
310
+ /* @__PURE__ */ jsx(Tbody, { children: state.items.map((item) => /* @__PURE__ */ jsxs(Tr, { children: [
311
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: when(item.createdAt) }) }),
312
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Badge, { children: eventLabel(t, item.event) }) }),
313
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: actorLabel(t, item.actor) }) }),
314
+ /* @__PURE__ */ jsx(Td, { style: { whiteSpace: "normal" }, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: targetText(item) }) }),
315
+ /* @__PURE__ */ jsx(Td, { style: { whiteSpace: "normal" }, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", style: { overflowWrap: "anywhere" }, children: changeSummary(t, item) }) })
316
+ ] }, item.id)) })
317
+ ] });
318
+ }
319
+ return /* @__PURE__ */ jsxs(
320
+ PageShell,
321
+ {
322
+ title,
323
+ subtitle: t(
324
+ "settings.audit.subtitle",
325
+ "Who changed what and when in editor fields, templates, synced blocks, comments, AI actions and settings. Only counts and block ids are kept, never the content."
326
+ ),
327
+ primaryAction: /* @__PURE__ */ jsx(
328
+ Button,
329
+ {
330
+ variant: "secondary",
331
+ startIcon: /* @__PURE__ */ jsx(ArrowClockwise, {}),
332
+ onClick: load,
333
+ loading: state.status === "loading",
334
+ children: t("settings.audit.refresh", "Refresh")
335
+ }
336
+ ),
337
+ children: [
338
+ !state.enabled ? /* @__PURE__ */ jsx(
339
+ Alert,
340
+ {
341
+ variant: "warning",
342
+ closeLabel: t("settings.close", "Close"),
343
+ title: t("settings.audit.offTitle", "Recording is off"),
344
+ children: t(
345
+ "settings.audit.off",
346
+ "The audit trail is turned off in config/plugins.js (audit.enabled). Earlier events are still shown."
347
+ )
348
+ }
349
+ ) : null,
350
+ filters,
351
+ /* @__PURE__ */ jsxs(
352
+ SectionCard,
353
+ {
354
+ title: t("settings.audit.results", "Events"),
355
+ subtitle: state.pagination ? t("settings.audit.total", "{total, plural, one {# event} other {# events}}", {
356
+ total: state.pagination.total
357
+ }) : void 0,
358
+ children: [
359
+ /* @__PURE__ */ jsx(Box, { "aria-busy": state.status === "loading", "data-mex-audit-results": true, minWidth: 0, children: results }),
360
+ state.pagination && state.pagination.total > 0 ? /* @__PURE__ */ jsxs(
361
+ Pagination.Root,
362
+ {
363
+ pageCount: state.pagination.pageCount,
364
+ total: state.pagination.total,
365
+ defaultPageSize: 25,
366
+ children: [
367
+ /* @__PURE__ */ jsx(Pagination.PageSize, { options: ["10", "25", "50", "100"] }),
368
+ /* @__PURE__ */ jsx(Pagination.Links, {})
369
+ ]
370
+ }
371
+ ) : null
372
+ ]
373
+ }
374
+ )
375
+ ]
376
+ }
377
+ );
378
+ };
379
+ export {
380
+ AuditPage,
381
+ AuditPage as default
382
+ };