magic-editor-x 2.0.0 → 2.2.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 (93) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +315 -103
  3. package/bin/magic-editor-x.mjs +190 -0
  4. package/dist/admin/{ConfigurationPage-DvAifELO.mjs → ConfigurationPage-3Dir3dAf.mjs} +126 -7
  5. package/dist/admin/{ConfigurationPage-B1uCIE3J.js → ConfigurationPage-YvnPnna6.js} +125 -4
  6. package/dist/admin/{CustomBlocksPage-6eWCOreU.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
  7. package/dist/admin/{CustomBlocksPage-6-OQwpXQ.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
  8. package/dist/admin/EditorField-B8pyAxPE.mjs +11935 -0
  9. package/dist/admin/EditorField-Diq1j8kc.js +11970 -0
  10. package/dist/admin/{api-B-RsxJCs.js → api-Dsq53giv.js} +3 -0
  11. package/dist/admin/{api-C4XsDZxd.mjs → api-RZ0Fz0BD.mjs} +3 -0
  12. package/dist/admin/de-62Vxb2iw.js +250 -0
  13. package/dist/admin/de-BVvwSYYO.mjs +250 -0
  14. package/dist/admin/de-BmmLBJli.mjs +41 -0
  15. package/dist/admin/{de-BMxADn2Z.mjs → de-Bt6pYIWi.mjs} +16 -1
  16. package/dist/admin/{de-DcDPRzV4.js → de-BteRx2iA.js} +28 -1
  17. package/dist/admin/{de-n5V6c5RT.mjs → de-CFX5atOk.mjs} +28 -1
  18. package/dist/admin/{de-Dx7vUW0Z.js → de-CVbi685U.js} +16 -1
  19. package/dist/admin/de-DaJwN6nk.js +41 -0
  20. package/dist/admin/{en-sNn4z9lA.js → en-BX362fTp.js} +16 -1
  21. package/dist/admin/{en-BQ5Pxe2o.mjs → en-B_HltUxZ.mjs} +16 -1
  22. package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
  23. package/dist/admin/en-Cn78RZs-.js +41 -0
  24. package/dist/admin/{en-D-DGftl0.js → en-CyjAcccB.js} +28 -1
  25. package/dist/admin/en-D7mZWLGp.mjs +41 -0
  26. package/dist/admin/en-VlkaIzrM.js +250 -0
  27. package/dist/admin/{en-BqNm3nMQ.mjs → en-ea0tfA5i.mjs} +28 -1
  28. package/dist/admin/es-BT9oAcHf.js +250 -0
  29. package/dist/admin/es-BmGtLkJD.js +41 -0
  30. package/dist/admin/{es-Di0pyQCh.js → es-C8GZFGjv.js} +28 -1
  31. package/dist/admin/es-C9-cXdb6.mjs +250 -0
  32. package/dist/admin/{es-SzeTV4q8.mjs → es-CEi_ycX8.mjs} +28 -1
  33. package/dist/admin/{es-DVsXnS0N.js → es-CHHEZi44.js} +16 -1
  34. package/dist/admin/{es-B6NYq0VH.mjs → es-CrhwOq-5.mjs} +16 -1
  35. package/dist/admin/es-joykG5I9.mjs +41 -0
  36. package/dist/admin/{fr-DmG3_Cn-.mjs → fr-5djKfQ3s.mjs} +16 -1
  37. package/dist/admin/{fr-Fwxcj4SM.js → fr-B3SL0TBV.js} +16 -1
  38. package/dist/admin/{fr-DhgPYHIH.mjs → fr-BAMSvQbR.mjs} +28 -1
  39. package/dist/admin/fr-CrzxGe5e.mjs +41 -0
  40. package/dist/admin/fr-Ct_uPqxV.js +41 -0
  41. package/dist/admin/fr-D6KJqPWi.js +250 -0
  42. package/dist/admin/fr-DpU_qiXR.mjs +250 -0
  43. package/dist/admin/{fr-D6F--jIB.js → fr-oRCJNdeJ.js} +28 -1
  44. package/dist/admin/index-C-lyON1B.mjs +303 -0
  45. package/dist/admin/index-iA0lued_.js +302 -0
  46. package/dist/admin/index.js +1 -1
  47. package/dist/admin/index.mjs +1 -1
  48. package/dist/admin/pt-BOrl6x-r.js +250 -0
  49. package/dist/admin/{pt-BbdwHlWF.mjs → pt-BdnY2Cth.mjs} +16 -1
  50. package/dist/admin/{pt-BvSl1btT.mjs → pt-CQrfqsCN.mjs} +28 -1
  51. package/dist/admin/{pt-C6nr71Yw.js → pt-EVwCuBUK.js} +16 -1
  52. package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
  53. package/dist/admin/pt-chN2jrXl.js +41 -0
  54. package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
  55. package/dist/admin/{pt-BPo0ex21.js → pt-tUeJ2Ywd.js} +28 -1
  56. package/dist/admin/{sanitize-9UVcXFfc.js → sanitize-Cb4jvBhj.js} +88 -12
  57. package/dist/admin/{sanitize-D4kfZ_ly.mjs → sanitize-ClkX823p.mjs} +89 -13
  58. package/dist/admin/{useT-B5M49wGH.js → useT-BWZ_-Hel.js} +1 -1
  59. package/dist/admin/{useT-CjX6fL2m.mjs → useT-pvHmgBFj.mjs} +1 -1
  60. package/dist/render/index.d.mts +75 -0
  61. package/dist/render/index.d.ts +75 -0
  62. package/dist/render/index.js +1420 -0
  63. package/dist/render/index.mjs +1398 -0
  64. package/dist/server/index.js +9562 -589
  65. package/dist/server/index.mjs +9565 -592
  66. package/package.json +21 -4
  67. package/schema/magic-editor-x.schema.json +967 -0
  68. package/types/index.d.ts +211 -0
  69. package/types/render.d.ts +75 -0
  70. package/dist/admin/EditorField-DocyD2Q3.js +0 -5506
  71. package/dist/admin/EditorField-ThSoOCPm.mjs +0 -5471
  72. package/dist/admin/de-B8XFFhHh.js +0 -95
  73. package/dist/admin/de-DBR893G4.js +0 -13
  74. package/dist/admin/de-RAxzvrwm.mjs +0 -95
  75. package/dist/admin/de-fBFh09Wl.mjs +0 -13
  76. package/dist/admin/en-BzfyifEU.mjs +0 -95
  77. package/dist/admin/en-D9Nfccux.mjs +0 -13
  78. package/dist/admin/en-DcWUTE2J.js +0 -95
  79. package/dist/admin/en-gueRT44P.js +0 -13
  80. package/dist/admin/es-B0Zy8DVg.mjs +0 -13
  81. package/dist/admin/es-BOtVc9qv.js +0 -95
  82. package/dist/admin/es-C2OJVYkV.mjs +0 -95
  83. package/dist/admin/es-DRGs7meF.js +0 -13
  84. package/dist/admin/fr-B8rdLAIL.js +0 -13
  85. package/dist/admin/fr-Bpo5Uq1f.mjs +0 -95
  86. package/dist/admin/fr-DfxKaOc_.js +0 -95
  87. package/dist/admin/fr-oiUb2bb_.mjs +0 -13
  88. package/dist/admin/index-CwfaB5-e.js +0 -155
  89. package/dist/admin/index-D1Q5Rlt6.mjs +0 -156
  90. package/dist/admin/pt-B3Jce6uT.mjs +0 -13
  91. package/dist/admin/pt-BiWuSBcH.js +0 -13
  92. package/dist/admin/pt-DqCXuI4S.mjs +0 -95
  93. package/dist/admin/pt-LCvjwk0y.js +0 -95
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/Schero94/Magic-Editor-X/main/docs/site/img/icon.svg" alt="Magic Editor X" width="96" height="96" />
3
+ </p>
4
+
1
5
  # Magic Editor X
2
6
 
3
7
  Block editor for Strapi 5: an [Editor.js](https://editorjs.io/) custom field with Media Library uploads, custom blocks, version history, live collaboration across several servers and an optional AI assistant that uses your own provider. Free and open source under the MIT license.
@@ -19,7 +23,13 @@ Live docs: <https://schero94.github.io/Magic-Editor-X/>
19
23
  - [Live collaboration](#live-collaboration)
20
24
  - [Running several instances](#running-several-instances)
21
25
  - [AI assistant](#ai-assistant)
26
+ - [Field presets](#field-presets)
27
+ - [Writing tools](#writing-tools)
28
+ - [Paste, import and migration](#paste-import-and-migration)
29
+ - [Version history](#version-history)
30
+ - [Quality checks](#quality-checks)
22
31
  - [Data format](#data-format)
32
+ - [Rendering content](#rendering-content)
23
33
  - [Admin API and permissions](#admin-api-and-permissions)
24
34
  - [Security and privacy](#security-and-privacy)
25
35
  - [Troubleshooting](#troubleshooting)
@@ -39,11 +49,16 @@ Every feature is available in every installation. There is nothing to activate,
39
49
  - code: plain code (`code`), code with syntax highlighting (`codeFlask`; Prism with JavaScript, TypeScript, JSX/TSX, JSON, HTML, CSS/SCSS, PHP, Python, Ruby, Go, Rust, Java, Kotlin, Swift, C, C++, C#, SQL, Bash, YAML, Markdown, GraphQL, Docker and diff);
40
50
  - media: image upload by file or URL into the Media Library (`image`), picking images from the Media Library (`mediaLib`, inserts `image` blocks), image by URL without upload (`simpleImage`), file attachments (`attaches`), embeds such as YouTube, Vimeo, CodePen, GitHub, Figma and others (`embed`);
41
51
  - other: link preview card (`linkTool`), person card (`personality`), call-to-action button (`button`), raw HTML (`raw`).
42
- - **Inline tools:** bold, italic, link with target and rel (`hyperlink`), marker, underline, strikethrough, inline code, tooltip, and the AI assistant when it is enabled.
52
+ - **Inline tools:** bold, italic, link with target and rel (`hyperlink`, with a built-in picker that links an entry of your content types, see [Internal links](#internal-links)), marker, underline, strikethrough, inline code, tooltip, and the AI assistant when it is enabled.
43
53
  - **Block tunes:** alignment (`alignmentTune`), text variant call-out / citation / details (`textVariant`), indent (`indentTune`).
44
- - **Editing:** undo and redo, drag and drop of blocks, full screen mode, block and word count.
54
+ - **Field presets:** per field in the Content-Type Builder: allowed blocks and heading levels, character and block limits, required alternative text, allowed links, AI and live collaboration on or off, publishing guard. Enforced on every save and over the live channel, not only in the editor. See [Field presets](#field-presets).
55
+ - **Writing:** Markdown shortcuts (`#`, `-`, `1.`, `[]`, `>`, ` ``` `, `---`, `**bold**`, `_italic_`, `~~strike~~`, `` `code` ``), find and replace, keyboard shortcut help, focus mode, actions for several selected blocks, counts with reading time, undo and redo, drag and drop, full screen. See [Writing tools](#writing-tools).
56
+ - **Paste and import:** Word, Google Docs, LibreOffice, web pages and Markdown become real blocks; a CLI migrates Strapi Blocks, Markdown and HTML fields. See [Paste, import and migration](#paste-import-and-migration).
57
+ - **Media:** alternative text and "decorative image" on image blocks; images keep their Media Library id and responsive formats.
58
+ - **Quality checks:** accessibility lint (alternative texts, heading order, link texts, table headers, contrast of custom colours) and a link check, with an optional publishing guard. See [Quality checks](#quality-checks).
59
+ - **Renderers, schema and types:** `magic-editor-x/render` (HTML, plain text, Markdown; framework-free and XSS-safe), `magic-editor-x/schema` (JSON Schema) and `magic-editor-x/types` (TypeScript). See [Rendering content](#rendering-content).
45
60
  - **Custom blocks:** define your own blocks in Settings: simple blocks with fields (text, textarea, URL, number, select, checkbox, image, colour) and an optional HTML template, or embedded-entry blocks that link an entry of another content type. Import and export as JSON.
46
- - **Version history:** save versions of a field, preview and restore them; automatic versions during live sessions.
61
+ - **Version history:** named versions, a word-level comparison with the current content, restore of the whole field or a single block; automatic versions during live sessions.
47
62
  - **Live collaboration:** several admins edit the same field at the same time with character-level merging, presence avatars and read-only viewers. Works with several Node processes behind a load balancer without sticky sessions.
48
63
  - **AI assistant:** improve, fix grammar, shorten, expand, summarize, simplify, translate, change tone and continue writing, using Anthropic, OpenAI or any OpenAI-compatible server (for example a local model) with your own key.
49
64
  - **Strapi-native admin:** built with the Strapi Design System, light and dark mode, keyboard accessible, admin in English, German, French, Spanish and Portuguese.
@@ -58,6 +73,11 @@ Every feature is available in every installation. There is nothing to activate,
58
73
  | ![AI assistant dialog](docs/site/img/ai-1440.png) | ![Settings, configuration page](docs/site/img/settings-configuration-1440.png) |
59
74
  | ![Settings, custom blocks list](docs/site/img/settings-custom-blocks-1440.png) | ![Custom block form](docs/site/img/custom-block-modal-1440.png) |
60
75
 
76
+ | ![Field presets in the Content-Type Builder](docs/site/img/field-presets-1440.png) | ![Content that does not match its field settings](docs/site/img/preset-problems-1440.png) |
77
+ | ![Find and replace](docs/site/img/find-replace-1440.png) | ![Quality checks and link check](docs/site/img/quality-panel-1440.png) |
78
+ | ![Version comparison with per-block restore](docs/site/img/history-diff-1440.png) | ![Image block with alternative text](docs/site/img/image-alt-1440.png) |
79
+ | ![Actions for several selected blocks](docs/site/img/block-actions-1440.png) | ![Keyboard shortcuts](docs/site/img/shortcuts-1440.png) |
80
+
61
81
  ![Editor on a 390 px wide screen](docs/site/img/editor-mobile-390.png)
62
82
 
63
83
  All screenshots use synthetic data.
@@ -75,13 +95,17 @@ All screenshots use synthetic data.
75
95
 
76
96
  ## Screens
77
97
 
78
- | Screen | Where | Who can open it |
79
- | --------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
80
- | Editor field | Content Manager, edit view | Everyone who can read the field. Uploads, version history and the AI assistant need the permissions in [Admin API and permissions](#admin-api-and-permissions). |
81
- | Version history | Clock button in the editor toolbar of a saved document | `access` and Content Manager read on the document; saving and restoring need update. |
82
- | AI assistant | Inline toolbar (select text) | `access` and `ai.use`, when an administrator turned the assistant on. |
83
- | Configuration | Settings > Magic Editor X > Configuration | `settings.read` (view), `settings.update` (edit). |
84
- | Custom blocks | Settings > Magic Editor X > Custom blocks | `custom-blocks.manage`. |
98
+ | Screen | Where | Who can open it |
99
+ | ------------------------------ | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100
+ | Editor field | Content Manager, edit view | Everyone who can read the field. Uploads, version history and the AI assistant need the permissions in [Admin API and permissions](#admin-api-and-permissions). |
101
+ | Version history | Clock button in the editor toolbar of a saved document | `access` and Content Manager read on the document; saving, naming and restoring need update. |
102
+ | Find and replace | Magnifier button, or Ctrl/Cmd+Shift+F in the editor | Everyone who can read the field; replacing needs update. |
103
+ | Quality checks | Seal button in the editor toolbar (the number counts problems) | Everyone who can read the field; the link check needs `access`. |
104
+ | Keyboard shortcuts, focus mode | More (…) button, or Ctrl/Cmd+/ | Everyone who can read the field. |
105
+ | Field options | Content-Type Builder, Magic Editor X field, Basic and Advanced settings | Content-Type Builder access (development mode). |
106
+ | AI assistant | Inline toolbar (select text) | `access` and `ai.use`, when an administrator turned the assistant on. |
107
+ | Configuration | Settings > Magic Editor X > Configuration | `settings.read` (view), `settings.update` (edit). |
108
+ | Custom blocks | Settings > Magic Editor X > Custom blocks | `custom-blocks.manage`. |
85
109
 
86
110
  ## Compatibility
87
111
 
@@ -118,7 +142,7 @@ npm run build
118
142
  npm run develop
119
143
  ```
120
144
 
121
- Add the field in the Content-Type Builder: **Add another field > Custom > Magic Editor X**. In its settings you can set a placeholder and a minimum height (120 to 2000 px).
145
+ Add the field in the Content-Type Builder: **Add another field > Custom > Magic Editor X**. In its settings you can set a placeholder, a preset and the other [field presets](#field-presets), and a minimum height (120 to 2000 px).
122
146
 
123
147
  After the first start, Super Admins can use everything. Other roles need the plugin actions listed in [Admin API and permissions](#admin-api-and-permissions) (Settings > Administration Panel > Roles > Plugins > Magic Editor X).
124
148
 
@@ -128,30 +152,40 @@ After the first start, Super Admins can use everything. Other roles need the plu
128
152
 
129
153
  All keys are optional. Infrastructure options live in `config/plugins`; the AI provider is edited at runtime in Settings > Magic Editor X > Configuration.
130
154
 
131
- | Key | Type | Default | Effect |
132
- | --------------------------------------- | ---------------------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
133
- | `debug` | boolean | `false` | Writes debug log lines (never content or personal data). |
134
- | `rawHtml` | `'sanitize'` \| `'allow'` \| `'disable'` | `'sanitize'` | Raw HTML block on save: `sanitize` removes scripts, event handlers, iframes and unsafe URLs; `allow` stores the HTML as typed; `disable` empties it. |
135
- | `sanitizeOnSave` | boolean | `true` | Normalise and sanitise Magic Editor X values on every Document Service write. Turning this off is not recommended. |
136
- | `encryptionKey` | string (32+ characters) | unset | Key for the stored AI provider key. Prefer the `MAGIC_EDITOR_X_ENCRYPTION_KEY` environment variable. |
137
- | `uploads.maxImageBytes` | integer | `10485760` (10 MiB) | Largest image accepted by file or URL (hard cap 500 MiB). |
138
- | `uploads.maxFileBytes` | integer | `20971520` (20 MiB) | Largest attachment. |
139
- | `linkPreview.enabled` | boolean | `true` | Link preview cards. When `false`, `GET /magic-editor-x/link` answers 404. |
140
- | `linkPreview.timeoutMs` | integer | `8000` | Time limit for fetching a page (1000 to 30000). |
141
- | `api.autoParseJSON` | boolean | `true` | Turn 1.x JSON strings into objects in Content API GET responses. |
142
- | `ai.allowPrivateBaseUrl` | boolean | `false` | Allow AI base URLs on loopback or private networks (for local models). Owner decision; not editable in the admin. |
143
- | `ai.apiKey` | string | unset | Provider key from the environment. When set it wins over a key stored in the settings. |
144
- | `ai.requestsPerMinute` | integer | `20` | AI requests per admin per minute, counted per process. |
145
- | `ai.timeoutMs` | integer | `60000` | Time limit for one provider request. |
146
- | `collaboration.enabled` | boolean | `true` | Live collaboration and its Socket.IO server. |
147
- | `collaboration.path` | string | `'/magic-editor-x/realtime'` | Socket.IO path on the Strapi HTTP server. |
148
- | `collaboration.allowedOrigins` | string[] | `[]` | Extra browser origins allowed to open the socket. The admin URL and the server URL are always allowed. |
149
- | `collaboration.pollIntervalMs` | integer | `400` | How often each process reads updates written by other processes (50 to 10000). |
150
- | `collaboration.roomTtlMinutes` | integer | `30` | Keep a room's live state this long after the last person left. |
151
- | `collaboration.maxMessageBytes` | integer | `2097152` (2 MiB) | Largest accepted socket message. |
152
- | `collaboration.snapshotIntervalMinutes` | integer | `10` | Automatic version while people edit live. `0` turns it off. |
153
- | `collaboration.tokenTtlSeconds` | integer | `60` | Lifetime of the one-time token that opens the socket. |
154
- | `history.maxSnapshotsPerField` | integer | `50` | Versions kept per field and locale; older ones are deleted. |
155
+ | Key | Type | Default | Effect |
156
+ | --------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157
+ | `debug` | boolean | `false` | Writes debug log lines (never content or personal data). |
158
+ | `rawHtml` | `'sanitize'` \| `'allow'` \| `'disable'` | `'sanitize'` | Raw HTML block on save: `sanitize` removes scripts, event handlers, iframes and unsafe URLs; `allow` stores the HTML as typed; `disable` empties it. |
159
+ | `sanitizeOnSave` | boolean | `true` | Normalise and sanitise Magic Editor X values on every Document Service write. Turning this off is not recommended. |
160
+ | `encryptionKey` | string (32+ characters) | unset | Key for the stored AI provider key. Prefer the `MAGIC_EDITOR_X_ENCRYPTION_KEY` environment variable. |
161
+ | `uploads.maxImageBytes` | integer | `10485760` (10 MiB) | Largest image accepted by file or URL (hard cap 500 MiB). |
162
+ | `uploads.maxFileBytes` | integer | `20971520` (20 MiB) | Largest attachment. |
163
+ | `linkPreview.enabled` | boolean | `true` | Link preview cards. When `false`, `GET /magic-editor-x/link` answers 404. |
164
+ | `linkPreview.timeoutMs` | integer | `8000` | Time limit for fetching a page (1000 to 30000). |
165
+ | `api.autoParseJSON` | boolean | `true` | Turn 1.x JSON strings into objects in Content API GET responses. |
166
+ | `ai.allowPrivateBaseUrl` | boolean | `false` | Allow AI base URLs on loopback or private networks (for local models). Owner decision; not editable in the admin. |
167
+ | `ai.apiKey` | string | unset | Provider key from the environment. When set it wins over a key stored in the settings. |
168
+ | `ai.requestsPerMinute` | integer | `20` | AI requests per admin per minute, counted per process. |
169
+ | `ai.timeoutMs` | integer | `60000` | Time limit for one provider request. |
170
+ | `collaboration.enabled` | boolean | `true` | Live collaboration and its Socket.IO server. |
171
+ | `collaboration.path` | string | `'/magic-editor-x/realtime'` | Socket.IO path on the Strapi HTTP server. |
172
+ | `collaboration.allowedOrigins` | string[] | `[]` | Extra browser origins allowed to open the socket. The admin URL and the server URL are always allowed. |
173
+ | `collaboration.pollIntervalMs` | integer | `400` | How often each process reads updates written by other processes (50 to 10000). |
174
+ | `collaboration.roomTtlMinutes` | integer | `30` | Keep a room's live state this long after the last person left. |
175
+ | `collaboration.maxMessageBytes` | integer | `2097152` (2 MiB) | Largest accepted socket message. |
176
+ | `collaboration.snapshotIntervalMinutes` | integer | `10` | Automatic version while people edit live. `0` turns it off. |
177
+ | `collaboration.tokenTtlSeconds` | integer | `60` | Lifetime of the one-time token that opens the socket. |
178
+ | `collaboration.maxConnectionsPerAdmin` | integer | `20` | Open live sockets per admin across all processes. |
179
+ | `collaboration.maxRoomsPerAdmin` | integer | `20` | Different fields one admin may have open live at the same time, across all processes. |
180
+ | `collaboration.revalidateSeconds` | integer | `60` | Full permission re-check of open sockets. Role, permission and user changes are applied within about a second anyway. |
181
+ | `collaboration.rateLimit` | object | `{ sessionsPerMinute: 60, updatesPer10s: 300, bytesPer10s: 8388608 }` | Session tokens per admin and minute (shared by all processes), updates and update bytes per socket in 10 seconds. |
182
+ | `collaboration.compaction` | object | `{ enabled: true, idleSeconds: 60, minBytes: 262144, ratio: 4, checkIntervalSeconds: 30 }` | Rebuilds an idle room whose live state is `ratio` times larger than a fresh copy (and at least `minBytes`) as a new generation, once across all processes. Open editors switch without reconnecting; edits that had not reached the server yet are kept. Bounds: `idleSeconds` 15 to 86400, `minBytes` 1 KiB to 512 MiB, `ratio` 1.5 to 1000, `checkIntervalSeconds` 1 to 3600. |
183
+ | `history.maxSnapshotsPerField` | integer | `50` | Versions kept per field and locale; older ones are deleted. |
184
+ | `links.urlPattern` | string | `''` | `href` of internal links, for example `'/{locale}/{collection}/{slug}'` or `'https://www.example.com/{collection}/{documentId}'`. Placeholders: `{documentId}`, `{locale}`, `{slug}`, `{collection}`, `{singular}`. Empty means `'/{collection}/{documentId}'`. See [Internal links](#internal-links). |
185
+ | `qualityChecks.externalLinks` | object | `{ enabled: false, timeoutMs: 5000, perMinute: 30 }` | External link check of the quality panel; keys below. |
186
+ | `qualityChecks.externalLinks.enabled` | boolean | `false` | Lets the quality panel check external links (outgoing requests through the SSRF-protected fetcher; owner opt-in). |
187
+ | `qualityChecks.externalLinks.timeoutMs` | integer | `5000` | Time limit per request and per redirect hop (1000 to 15000). |
188
+ | `qualityChecks.externalLinks.perMinute` | integer | `30` | External URLs one admin may check per minute, shared by all processes. |
155
189
 
156
190
  The validator rejects wrong types and ranges at startup and names the key, never the value. Keys from 1.x that no longer exist are ignored with a warning; see [Migrating from 1.x](#migrating-from-1x).
157
191
 
@@ -181,12 +215,22 @@ Settings > Magic Editor X > Configuration stores these values in the Strapi stor
181
215
 
182
216
  When a document has been saved once, the editor joins the room of its field. Everyone with Content Manager read access to that document, locale and field and the `collaborate` action can join; people with update access can type, others watch as viewers.
183
217
 
184
- - Edits merge at character level when two people type in the same text field of a block, and per block otherwise. Every client and server converge on the same document (Yjs CRDT).
185
- - Presence avatars show who is in the room; the badge shows the connection state (Connecting, Syncing, Live, Reconnecting).
186
- - Changes made by others become part of your form. Save the entry as usual to store them.
187
- - Text typed during a short network or server interruption is kept and sent after the reconnect.
218
+ How it works:
219
+
220
+ - **Conflict-free structure.** The field is shared as a Yjs document in which every block has a stable id and every part of its data has its own shared type: texts merge character by character, and every table cell, list item, checklist entry, tune (alignment, text variant, indent) and custom block field is merged separately. Two people can edit different cells of one table, different items of one list, or the text and the alignment of one paragraph at the same time and both changes are kept. When two people change the same number, switch or option at the same moment, one value wins on every screen. The stored Editor.js JSON does not change.
221
+ - **Presence.** Avatars with first name and last initial (never e-mail addresses), coloured carets and selections of the others in the text, a coloured marker at the block someone is editing and an "away" state after a minute without activity or when the tab is hidden. Joins and leaves are announced politely to screen readers. Colours follow the light and dark theme; the caret does not blink when reduced motion is requested.
222
+ - **Connection state** in the toolbar: Connecting, Syncing, Live, Reconnecting, Offline, View only, or Live editing unavailable.
223
+ - **Offline and reconnects.** You can keep typing while the connection is gone. Unsent changes are kept, sent again after the reconnect and merged with what others did meanwhile, without duplicates. Reconnects use exponential backoff with jitter and a new one-time token; waking a laptop or returning to a tab reconnects at once. Closing the tab leaves the room immediately.
224
+ - **Undo and redo** (toolbar, Cmd/Ctrl+Z, Shift+Cmd/Ctrl+Z) only revert your own changes, never what others typed (the last 200 steps).
225
+ - **Saving.** Changes made by others become part of your form. Save, publish and discard work as usual. Version history restores into the live room, so everyone sees the restored content. Each locale has its own room.
226
+ - **Permissions** are checked when you join, re-checked within about a second when roles, permissions or users change (on every process), and every `collaboration.revalidateSeconds`. An admin who loses update access becomes a viewer; one who loses read access is disconnected.
227
+ - **Nothing typed is lost.** Edits are stored in the database before they are confirmed. When a room is cleaned up `collaboration.roomTtlMinutes` after the last person left and contains edits nobody saved, a version is created first, so they can be restored from the history.
228
+
229
+ Limits:
230
+
188
231
  - A new entry that has not been saved yet has no room.
189
- - Access is checked again every five minutes; an admin who loses access is disconnected.
232
+ - Text formatting (bold, links, …) is part of the text; two people formatting the same word at the same moment can produce nested tags, which the sanitiser keeps valid.
233
+ - Up to 5000 blocks per field (the stored-content limit); rooms above 64 MiB of history refuse further edits until they are compacted.
190
234
 
191
235
  ## Running several instances
192
236
 
@@ -198,9 +242,11 @@ How it works:
198
242
  - The session token is signed with a key derived from `admin.auth.secret`, so any process can accept a token issued by another one. All processes must use the same `ADMIN_JWT_SECRET`.
199
243
  - Every update is written to the table `magic_editor_x_collab_updates` before it is acknowledged. Other processes read new rows every `collaboration.pollIntervalMs` and send them to their own sockets.
200
244
  - Presence is stored in `magic_editor_x_collab_presence` with heartbeats; leases and one-time keys in `magic_editor_x_locks`. Seeding a room, compaction, automatic versions and cleanup each run once across all processes.
201
- - Clients resynchronise their state every 20 seconds and after each reconnect, so a process restart loses nothing that was acknowledged.
245
+ - Every process keeps the active rooms in memory, checks every update before it is stored (only the structures the editor uses, every dependency present, every touched block valid within the content limits) and relays it.
246
+ - Clients resynchronise their state every 20 seconds and after each reconnect, so a process restart or deploy loses nothing that was acknowledged.
247
+ - Permission changes set a signal in `magic_editor_x_locks` that every process checks every second. Session and AI rate limits are counted in `magic_editor_x_counters`, so they apply to the whole cluster.
202
248
 
203
- The plugin creates these three tables on startup. They are not content types, so Strapi's schema sync leaves them alone.
249
+ The plugin creates these four tables on startup. They are not content types, so Strapi's schema sync leaves them alone.
204
250
 
205
251
  Behind a proxy, also set `server.proxy` in `config/server` (`koa: true` and the number of trusted hops in `maxIpsCount`) so Strapi sees the real client address.
206
252
 
@@ -219,9 +265,80 @@ The assistant is off until an administrator turns it on in Settings > Magic Edit
219
265
  - The key stays on the server. It is encrypted at rest with `MAGIC_EDITOR_X_ENCRYPTION_KEY` or read from `ai.apiKey`, and it is never sent to the browser or written to logs.
220
266
  - The selected text (with its inline formatting) and a fixed instruction are sent to the provider. Nothing else from the document is sent. The text is never logged.
221
267
  - Base URLs must be public https URLs. Loopback and private hosts are allowed only with `ai.allowPrivateBaseUrl: true` in `config/plugins`. Redirects are not followed.
222
- - Input is limited by "Max input characters", output by "Max output tokens". Each admin can send `ai.requestsPerMinute` requests per minute per process.
268
+ - Input is limited by "Max input characters", output by "Max output tokens". Each admin can send `ai.requestsPerMinute` requests per minute; the counter is shared by all processes.
223
269
  - The answer is sanitised to the inline tags the editor uses before it reaches the browser. The admin reviews the suggestion and chooses Replace selection; nothing changes before that.
224
270
 
271
+ ## Field presets
272
+
273
+ Each Magic Editor X field can have its own rules, set in the Content-Type Builder (field settings). They are stored as custom field options in the schema and enforced in three places with the same code (`shared/presets.mjs`): the editor offers only what the field allows, the realtime server refuses new blocks a preset does not allow, and every write (Content Manager, Content API, imports, code) is checked by the Document Service middleware.
274
+
275
+ | Option (`options.*`) | Where in the field settings | Values | Effect |
276
+ | ---------------------- | --------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
277
+ | `preset` | Basic | `full` (default), `article`, `basic`, `minimal` | Allowed blocks, inline tools and heading levels, see below. |
278
+ | `linkTargets` | Basic | `all` (default), `internal`, `external`, `none` | Which links are allowed: entries of the site (internal links), web addresses, both or none. Link blocks (`linkTool`, `button`, `personality`) count as web addresses. |
279
+ | `requireAlt` | Basic | checkbox | Images need an alternative text or the "decorative image" mark. |
280
+ | `allowedBlocks` | Advanced | comma-separated block names, for example `paragraph, header, list, image, myHero` | Replaces the preset's block list (custom blocks by name). `paragraph` is always allowed. |
281
+ | `headingLevels` | Advanced | `2-4`, `2,3`, `1, 3-5` | Replaces the preset's heading levels. |
282
+ | `maxBlocks` | Advanced | number, empty or 0 = no limit | Block limit, shown in the toolbar (`12 / 20 blocks`). |
283
+ | `maxCharacters` | Advanced | number, empty or 0 = no limit | Visible characters, counted like the toolbar (`380 / 400 characters`). |
284
+ | `disableAi` | Advanced | checkbox | No AI button in this field; the AI route answers 403 for requests from it. |
285
+ | `disableCollaboration` | Advanced | checkbox | No live editing in this field (the session route answers 403). |
286
+ | `publishGuard` | Advanced | checkbox | Publishing is refused while the [quality checks](#quality-checks) report errors in this field. |
287
+
288
+ | Preset | Blocks | Inline tools | Headings |
289
+ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------- |
290
+ | `full` | all, custom blocks included | all | H1-H6 |
291
+ | `article` | paragraph, header, list, checklist, quote, warning, alert, toggle, code, codeFlask, delimiter, table, embed, image (and the Media Library picker), linkTool, attaches, button | all | H2-H4 |
292
+ | `basic` | paragraph, header, list, quote, image, delimiter | bold, italic, underline, strikethrough, link | H2-H3 |
293
+ | `minimal` | paragraph, list | bold, italic, link | none |
294
+
295
+ How the rules apply:
296
+
297
+ - **Editor:** blocks that are not allowed leave the toolbox, the conversion menu and paste handling; heading levels and inline tools are limited; Markdown shortcuts and pasted content follow the preset (a pasted H1 becomes the nearest allowed level, a table becomes text). Existing content that no longer fits is kept, listed under "Field settings" in the quality panel with **Fix automatically** (changes heading levels, turns blocks that are not allowed into paragraphs, removes links that are not allowed), and a note under the field says that saving fails until it is fixed.
298
+ - **Save:** a value that breaks a rule is refused with 400 `ValidationError`, `details.code: 'PRESET_VIOLATION'`, `details.violations: [{ field, code, blockId, index, params }]` (codes `BLOCK_NOT_ALLOWED`, `HEADING_LEVEL`, `LINK_NOT_ALLOWED`, `ALT_REQUIRED`, `TOO_MANY_BLOCKS`, `TOO_MANY_CHARACTERS`) and `details.errors` with the field path, so the Content Manager shows the reason on the field. Errors carry rule codes and block ids only, never content. Inline formatting a preset leaves out (for example a marker in a `basic` field) is removed on save; the text stays.
299
+ - **Live editing:** the server refuses updates that add a block type or heading level the preset does not allow (blocks that existed before stay editable). Limits and alternative texts are checked on save only, so typing is never refused half-way.
300
+
301
+ Changing a preset never changes stored content by itself. Turning `sanitizeOnSave` off also turns the save check off.
302
+
303
+ ## Writing tools
304
+
305
+ | Tool | How |
306
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
307
+ | Markdown shortcuts | At the start of an empty paragraph: `#` to `######` + Space (heading), `-`, `*` or `+` + Space (bulleted list), `1.` + Space (numbered list, other numbers set the start), `[]` or `[x]` + Space (checklist), `>` + Space (quote), ` ``` ` (optionally with a language) + Enter (code block), `---` + Enter (delimiter). While typing: `**bold**`, `__bold__`, `*italic*`, `_italic_`, `~~strike~~`, `` `code` ``. Never inside code, raw HTML or tables; only blocks and marks the field allows. |
308
+ | Find and replace | Magnifier button or Ctrl/Cmd+Shift+F. Searches every text block, list item, table cell, caption and code block; keeps formatting; match case, whole words, regular expressions (off by default, patterns up to 200 characters). Enter / Shift+Enter move between matches, the current match is highlighted. Replacements are normal edits (undo, collaboration). A match cannot span differently formatted text. |
309
+ | Keyboard shortcuts | Ctrl/Cmd+/ or More > Keyboard shortcuts: editor, block and inline tool shortcuts and the Markdown shortcuts of this field. |
310
+ | Focus mode | More > Focus mode: full screen, narrower text column, other blocks dimmed. Escape leaves. |
311
+ | Several selected blocks | Select across blocks (Shift+Arrow at a block edge, Ctrl/Cmd+A twice, or drag across blocks): move up or down, duplicate, copy as Markdown, delete, convert to text, heading, list or quote. |
312
+ | Counts | Blocks, words, characters and reading time (200 words per minute) in the toolbar, with the field's limits. |
313
+ | Alternative text | Image and image-by-URL blocks: "Alternative text" field (prefilled from the Media Library) and "Decorative image (no alternative text)". Required when the field has `requireAlt`. |
314
+ | Language and direction | The editor gets the content locale as `lang` (spell checking) and writes right to left for Arabic, Hebrew, Persian, Urdu and other RTL locales. |
315
+
316
+ ## Paste, import and migration
317
+
318
+ **Paste.** Pasting from Word, Google Docs, LibreOffice, web pages (two or more blocks) or Markdown text creates real blocks: headings, nested lists, checklists, quotes, code, tables, links, bold, italic, underline and strikethrough. Styles, classes, comments and scripts are removed; the clipboard HTML is parsed into an inert document and never attached to the page. Images from the web are copied into the Media Library through the same SSRF-protected path as "image by URL" (at most 10 per paste) when you may upload; images Word keeps on your disk (`file:`) cannot be pasted and are counted in a message. Blocks the field does not allow become paragraphs. Ctrl/Cmd+Shift+V pastes plain text. Pastes into code, raw HTML and table cells are not changed.
319
+
320
+ **Migrate an existing field.** Add a Magic Editor X field next to the old one, then run from the project root (the old field is kept):
321
+
322
+ ```bash
323
+ npx magic-editor-x migrate --uid api::article.article --from body --to content # dry run, writes nothing
324
+ npx magic-editor-x migrate --uid api::article.article --from body --to content --apply # convert
325
+ ```
326
+
327
+ Options: `--format auto|blocks|markdown|html` (auto: Blocks fields as Strapi Blocks, Rich text as Markdown, text and string as HTML when they contain tags, else Markdown, JSON as Strapi Blocks or Editor.js), `--locale <code>` or `--locale '*'` (all locales), `--overwrite` (replace a target that already has content), `--batch 50`, `--limit <n>`, `--json` (machine-readable report on stdout; Strapi's own log lines go to stderr), `--out report.json`. Re-running skips converted documents (idempotent). The report counts scanned, converted, skipped and failed documents and lists lossy conversions (for example a skipped image) by document id and note, never content. Drafts are converted; publish afterwards. The same is available in code: `strapi.plugin('magic-editor-x').service('migrate').run({ uid, from, to, format, locale, dryRun, overwrite })`.
328
+
329
+ ## Version history
330
+
331
+ The clock button opens the versions of the field (per document and locale). **Save current version** stores the editor content, optionally with a name ("Before legal review", up to 120 characters); the pencil renames a version. Open a version with the eye button: **Preview** shows it, **Changes** compares it with the current editor content: added, removed, moved and changed blocks, changes marked word by word (`<ins>`/`<del>` with text labels, not colour alone) and formatting-only changes. **Restore this block** puts a single block back (at its old place, or over the current block); **Restore** replaces the whole field. Save the entry to keep a restore. Automatic versions are taken during live sessions (`collaboration.snapshotIntervalMinutes`).
332
+
333
+ ## Quality checks
334
+
335
+ The seal button opens the quality panel; its number counts problems. It never blocks editing.
336
+
337
+ - **Accessibility lint** (`shared/quality.mjs`): images without alternative text (an error when the field has `requireAlt`, otherwise a warning; decorative images are fine), skipped heading levels, more than one H1, empty headings, empty links (error), link texts such as "click here", "hier", "cliquez ici", "aquí", "clique aqui" (English, German, French, Spanish, Portuguese), tables without a header row, and custom-block colour pairs below 4.5:1. Click an issue to jump to its block.
338
+ - **Field settings:** content that breaks the field's [preset](#field-presets), with automatic fixes.
339
+ - **Check links** (`POST /magic-editor-x/quality/links`): internal links (entries you cannot read answer "Not checked", so nothing is revealed; "Not published" for drafts of Draft & Publish types), Media Library files (needs Media Library read) and, only when `qualityChecks.externalLinks.enabled` is true, external links through the SSRF-protected fetcher (public addresses only, pinned DNS, redirects re-checked, HEAD then a capped GET, rate limited per admin across processes, cached for 10 minutes). URLs are never logged.
340
+ - **Publishing guard:** with the field option `publishGuard`, publishing a document whose field has errors answers 400 `details.code: 'QUALITY_GATE'` with `details.issues: [{ field, rule, blockId, locale? }]` and `details.errors` for the form. Warnings never block.
341
+
225
342
  ## Data format
226
343
 
227
344
  The field stores an Editor.js document as JSON:
@@ -244,49 +361,90 @@ The field stores an Editor.js document as JSON:
244
361
 
245
362
  Data of each block type as stored after sanitising (`shared/sanitize-policy.mjs`):
246
363
 
247
- | Block | `data` |
248
- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
249
- | `paragraph` | `{ text }` (inline HTML) |
250
- | `header` | `{ text, level: 1-6 }` |
251
- | `list` | `{ style: 'ordered' \| 'unordered' \| 'checklist', meta?: { start?, counterType? }, items: [{ content, meta?, items: [...] }] }` |
252
- | `checklist` | `{ items: [{ text, checked }] }` |
253
- | `quote` | `{ text, caption, alignment: 'left' \| 'center' }` |
254
- | `warning` | `{ title, message }` |
255
- | `alert` | `{ type: 'primary' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger' \| 'light' \| 'dark', align: 'left' \| 'center' \| 'right', message }` |
256
- | `toggle` | `{ text, status: 'open' \| 'closed', fk?, items }` (the next `items` blocks are its content) |
257
- | `code` | `{ code }` (plain text) |
258
- | `codeFlask` | `{ code, language, showlinenumbers? }` |
259
- | `raw` | `{ html }` (see `rawHtml`) |
260
- | `table` | `{ withHeadings, stretched, content: string[][] }` |
261
- | `image` | `{ file: { url, mime?, alt?, width?, height?, size?, formats?, id?, documentId? }, caption, withBorder, withBackground, stretched }` |
262
- | `simpleImage` | `{ url, caption, withBorder, withBackground, stretched }` |
263
- | `linkTool` | `{ link, meta: { title, description, site_name?, image?: { url } } }` |
264
- | `attaches` | `{ file: { url, name?, extension?, size?, title? }, title }` |
265
- | `embed` | `{ service, source, embed, width?, height?, caption }` (`embed` is always https) |
266
- | `personality` | `{ name, description, link, photo }` |
267
- | `button` | `{ text, link, style, openInNewTab }` |
268
- | `delimiter` | `{}` |
269
- | custom simple block | `{ content, <field values>, blockType: 'simple', blockName }` |
270
- | custom embedded-entry block | `{ entry: { id, documentId, title, <display fields> }, contentType, displayMode }` |
271
-
272
- Inline HTML may contain `b`, `strong`, `i`, `em`, `u`, `s`, `mark`, `code`, `a` (`href`, `target`, `rel`, `title`), `br`, `span` (class `cdx-tooltip` with `data-tooltip`), `sub` and `sup`. Links allow `http`, `https`, `mailto`, `tel` and relative URLs. Escape plain-text fields (`code`, `personality`, `button.text`, link card text) when you render them.
364
+ | Block | `data` |
365
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
366
+ | `paragraph` | `{ text }` (inline HTML) |
367
+ | `header` | `{ text, level: 1-6 }` |
368
+ | `list` | `{ style: 'ordered' \| 'unordered' \| 'checklist', meta?: { start?, counterType? }, items: [{ content, meta?, items: [...] }] }` |
369
+ | `checklist` | `{ items: [{ text, checked }] }` |
370
+ | `quote` | `{ text, caption, alignment: 'left' \| 'center' }` |
371
+ | `warning` | `{ title, message }` |
372
+ | `alert` | `{ type: 'primary' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger' \| 'light' \| 'dark', align: 'left' \| 'center' \| 'right', message }` |
373
+ | `toggle` | `{ text, status: 'open' \| 'closed', fk?, items }` (the next `items` blocks are its content) |
374
+ | `code` | `{ code }` (plain text) |
375
+ | `codeFlask` | `{ code, language, showlinenumbers? }` |
376
+ | `raw` | `{ html }` (see `rawHtml`) |
377
+ | `table` | `{ withHeadings, stretched, content: string[][] }` |
378
+ | `image` | `{ file: { url, mime?, alt?, width?, height?, size?, formats?, id?, documentId? }, caption, withBorder, withBackground, stretched, decorative? }` (`id`/`documentId` reference the Media Library file, `formats` its responsive sizes; `decorative: true` = intentionally empty alternative text) |
379
+ | `simpleImage` | `{ url, caption, withBorder, withBackground, stretched, alt?, decorative? }` |
380
+ | `linkTool` | `{ link, meta: { title, description, site_name?, image?: { url } } }` |
381
+ | `attaches` | `{ file: { url, name?, extension?, size?, title? }, title }` |
382
+ | `embed` | `{ service, source, embed, width?, height?, caption }` (`embed` is always https) |
383
+ | `personality` | `{ name, description, link, photo }` |
384
+ | `button` | `{ text, link, style, openInNewTab }` |
385
+ | `delimiter` | `{}` |
386
+ | custom simple block | `{ content, <field values>, blockType: 'simple', blockName }` |
387
+ | custom embedded-entry block | `{ entry: { id, documentId, title, <display fields> }, contentType, displayMode }` |
388
+
389
+ Inline HTML may contain `b`, `strong`, `i`, `em`, `u`, `s`, `mark`, `code`, `a` (`href`, `target`, `rel`, `title`, and for internal links `data-mex-uid`, `data-mex-document-id`, `data-mex-locale`), `br`, `span` (class `cdx-tooltip` with `data-tooltip`), `sub` and `sup`. Links allow `http`, `https`, `mailto`, `tel` and relative URLs. Escape plain-text fields (`code`, `personality`, `button.text`, link card text) when you render them.
390
+
391
+ ### Internal links
392
+
393
+ The link tool (`CMD+K`) has a **Link to an entry** button: choose a content type, search by title (arrow keys move through the results, Enter picks, Escape closes) and the selected text becomes a link to that entry. The picker lists only the content types and entries you can read in the Content Manager, with its conditions and field permissions. The link is stored as plain HTML:
394
+
395
+ ```html
396
+ <a
397
+ href="/articles/x7k2m9q4p1v8"
398
+ data-mex-uid="api::article.article"
399
+ data-mex-document-id="x7k2m9q4p1v8"
400
+ data-mex-locale="en"
401
+ >our guide</a
402
+ >
403
+ ```
404
+
405
+ - `href` is always a normal URL, so every frontend can render the link as it is. It is built on the server from `links.urlPattern` when the link is inserted: `{documentId}`, `{locale}` (empty for types without i18n; empty path segments are removed), `{slug}` (the first `uid` attribute of the type, or the documentId when there is none), `{collection}` (plural API name) and `{singular}` (singular API name). Values are URL-encoded. The pattern must be a site-relative path or an `http(s)` URL with a fixed host. Without a pattern the link is `/{collection}/{documentId}`.
406
+ - `data-mex-uid`, `data-mex-document-id` and `data-mex-locale` identify the entry, so a frontend can resolve the current URL itself (for example when a slug changed after the link was inserted). They are kept only when they are valid and only on `<a>`; a link whose address you edit by hand becomes a normal link.
407
+ - **Links follow slug changes** because the entry reference is stored, not only the URL: render with `renderHtml(value, { links: ({ uid, documentId, locale, href }) => urlFor(uid, documentId, locale) })` (see [Rendering content](#rendering-content)), or in server code `await strapi.plugin('magic-editor-x').service('links').resolveHrefs(value, { status: 'published' })`, which re-renders every internal `href` from `links.urlPattern` and the entry's current slug (one query per type and locale; links to deleted entries keep their stored `href`; it does not check admin permissions, so use it for content the caller may already see).
273
408
 
274
409
  Tunes are stored per block in `tunes`: `alignmentTune: { alignment }`, `textVariant: '' | 'call-out' | 'citation' | 'details'`, `indentTune: { indentLevel }`.
275
410
 
276
411
  The Content API returns the object as stored. Entries saved with 1.x may still contain a JSON string until they are saved again; with `api.autoParseJSON` (default) the plugin parses such strings in Content API GET responses.
277
412
 
413
+ ## Rendering content
414
+
415
+ `npm i magic-editor-x` also gives you a framework-free renderer (ESM and CommonJS, no dependencies, no Node built-ins, so it runs in Node, browsers and edge runtimes), a JSON Schema and TypeScript types:
416
+
417
+ ```js
418
+ import { renderHtml, renderText, renderMarkdown } from 'magic-editor-x/render';
419
+
420
+ const html = renderHtml(entry.body, {
421
+ links: ({ uid, documentId, locale, href }) => `/${locale}/articles/${slugs.get(documentId)}`, // internal links follow slug changes
422
+ media: (file) => file, // refresh Media Library files by file.id / file.documentId if you like
423
+ overrides: { myHero: (block, h) => `<section class="hero">${h.escape(block.data.title)}</section>` },
424
+ });
425
+ const text = renderText(entry.body); // search index, meta description
426
+ const markdown = renderMarkdown(entry.body); // feeds, LLM context, export
427
+ ```
428
+
429
+ - **Safe by default:** stored inline HTML is re-parsed and only the editor's own tags and attributes survive (entities are decoded before URL checks, `javascript:`/`data:` links are dropped, `target="_blank"` gets `rel="noopener noreferrer"`), so the output is safe even for content that did not pass the server sanitiser. Raw HTML blocks are left out unless you pass `rawHtml: 'allow'` together with your own `sanitizeRaw` function. Embeds become iframes (`sandbox`, `loading="lazy"`, `referrerpolicy`) only for `embedHosts` (default: YouTube, youtube-nocookie, Vimeo player, CodePen, Twitch, Figma, Miro); other embeds become links.
430
+ - **Output:** HTML elements with stable `mex-` classes (tunes as `mex-align-*`, `mex-variant-*`, `mex-indent-N`), images with `srcset` from the Media Library `formats`, width, height and lazy loading (`imageSizes`, default `100vw`), decorative images with `alt=""`, toggles as `<details>`. Custom blocks render as `<div class="mex-block mex-<name>" data-mex-block>` with escaped values unless you pass an override. Markdown is CommonMark plus GFM tables and task lists; plain text uses blank lines between blocks.
431
+ - **Deterministic:** the same value always gives the same string.
432
+ - **Schema:** `magic-editor-x/schema` is a JSON Schema (draft 2020-12) of the stored value with one data schema per block type; validate content in CI. **Types:** `import type { MagicEditorXData, MagicEditorXBlock } from 'magic-editor-x/types'`.
433
+
434
+ React, Vue and Astro components on top of the renderer are planned for 2.3.
435
+
278
436
  ## Admin API and permissions
279
437
 
280
438
  ### Permissions
281
439
 
282
- | Action | Label in Roles | Gates |
283
- | --------------------------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
284
- | `plugin::magic-editor-x.access` | Use the editor (uploads, link previews, custom blocks, version history) | Editor configuration, link previews, uploads (with the Media Library permission), content type list, custom block list, version history, collaboration and AI routes |
285
- | `plugin::magic-editor-x.collaborate` | Edit together in real time | Joining live rooms |
286
- | `plugin::magic-editor-x.ai.use` | Use the AI assistant | AI requests |
287
- | `plugin::magic-editor-x.custom-blocks.manage` | Manage custom blocks | Settings > Custom blocks and its routes |
288
- | `plugin::magic-editor-x.settings.read` | Read settings | Settings > Configuration (read) |
289
- | `plugin::magic-editor-x.settings.update` | Update settings | Saving settings, testing the AI connection |
440
+ | Action | Label in Roles | Gates |
441
+ | --------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
442
+ | `plugin::magic-editor-x.access` | Use the editor (uploads, link previews, custom blocks, version history) | Editor configuration, link previews, uploads (with the Media Library permission), content type list, internal-link search, custom block list, version history, collaboration and AI routes |
443
+ | `plugin::magic-editor-x.collaborate` | Edit together in real time | Joining live rooms |
444
+ | `plugin::magic-editor-x.ai.use` | Use the AI assistant | AI requests |
445
+ | `plugin::magic-editor-x.custom-blocks.manage` | Manage custom blocks | Settings > Custom blocks and its routes |
446
+ | `plugin::magic-editor-x.settings.read` | Read settings | Settings > Configuration (read) |
447
+ | `plugin::magic-editor-x.settings.update` | Update settings | Saving settings, testing the AI connection |
290
448
 
291
449
  Uploads also need the Media Library action `plugin::upload.assets.create`. Version history and collaboration also apply the Content Manager permissions of the document: read access (including conditions such as "is creator", locale and field permissions) to list versions and join a room, update access to save versions, restore and type. A document you cannot read answers 404, the same as a document that does not exist.
292
450
 
@@ -296,30 +454,34 @@ Super Admins have all actions. The `access` action keeps its 1.x id, so roles th
296
454
 
297
455
  All routes are admin routes served at `/magic-editor-x/...` and need an admin session (`Authorization: Bearer <admin JWT>`). There are no Content API routes. Errors use the Strapi envelope `{ "data": null, "error": { "status", "name", "message", "details" } }`; validation errors carry `details.fieldErrors` keyed by field path. Editor.js tool routes answer `{ "success": 0, "message" }` on errors, as the tools expect.
298
456
 
299
- | Method | Path | Actions | Body / query | Response |
300
- | ------ | --------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
301
- | GET | `/magic-editor-x/config` | access | | `{ data: { collaboration, ai, uploads, linkPreview, rawHtml, permissions } }` |
302
- | GET | `/magic-editor-x/link` | access | `?url=` | `{ success: 1, link, meta }` |
303
- | POST | `/magic-editor-x/image/byFile` | access, upload | multipart `image` | `{ success: 1, file: { url, ... } }` |
304
- | POST | `/magic-editor-x/image/byUrl` | access, upload | `{ url }` | `{ success: 1, file }` |
305
- | POST | `/magic-editor-x/file/upload` | access, upload | multipart `file` | `{ success: 1, file: { url, name, title, size, extension } }` |
306
- | GET | `/magic-editor-x/content-types` | access | | `{ data: [{ uid, kind, displayName, attributes }] }` (types you can read) |
307
- | GET | `/magic-editor-x/custom-blocks` | access (`?all=true` also needs custom-blocks.manage) | `?all=true` | `{ data: [block] }` |
308
- | GET | `/magic-editor-x/custom-blocks/export` | custom-blocks.manage | | `{ data: { format: 'magic-editor-x/custom-blocks', version: 2, exportedAt, blocks } }` |
309
- | POST | `/magic-editor-x/custom-blocks/import` | custom-blocks.manage | export document | `{ data: { created: [name], skipped: [{ name, reason }] } }` |
310
- | PUT | `/magic-editor-x/custom-blocks/order` | custom-blocks.manage | `{ ids }` (every block once) | `{ data: [block] }` |
311
- | POST | `/magic-editor-x/custom-blocks` | custom-blocks.manage | block definition | 201 `{ data: block }` |
312
- | PUT | `/magic-editor-x/custom-blocks/:id` | custom-blocks.manage | full block definition | `{ data: block }` |
313
- | DELETE | `/magic-editor-x/custom-blocks/:id` | custom-blocks.manage | | `{ data: { id } }` |
314
- | POST | `/magic-editor-x/custom-blocks/:id/duplicate` | custom-blocks.manage | | 201 `{ data: block }` |
315
- | POST | `/magic-editor-x/collaboration/session` | access, collaborate | `{ uid, documentId, locale?, field, initialValue? }` | `{ data: { token, path, canEdit, expiresAt } }` |
316
- | GET | `/magic-editor-x/history` | access | `?uid&documentId&locale&field` | `{ data: [version], meta: { canRestore, canCreate } }` |
317
- | GET | `/magic-editor-x/history/:id` | access | | `{ data: { ...version, content } }` |
318
- | POST | `/magic-editor-x/history` | access | `{ uid, documentId, locale?, field, content }` | 201 new version, 200 with `meta.created: false` when unchanged |
319
- | POST | `/magic-editor-x/ai/:action` | access, ai.use | `{ text, language?, tone? }` | `{ data: { text } }` |
320
- | GET | `/magic-editor-x/settings` | settings.read | | `{ data: { ai, environment } }` (no secrets) |
321
- | PUT | `/magic-editor-x/settings` | settings.read, settings.update | `{ ai: { enabled, provider, baseUrl, model, maxInputChars, maxOutputTokens, apiKey? } }` | `{ data: { ai, environment } }` |
322
- | POST | `/magic-editor-x/settings/ai/test` | settings.read, settings.update | `{ ai: {...} }` | `{ data: { ok: true } }` |
457
+ | Method | Path | Actions | Body / query | Response |
458
+ | ------ | --------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
459
+ | GET | `/magic-editor-x/config` | access | | `{ data: { collaboration, ai, uploads, linkPreview, rawHtml, permissions } }` |
460
+ | GET | `/magic-editor-x/link` | access | `?url=` | `{ success: 1, link, meta }` |
461
+ | POST | `/magic-editor-x/image/byFile` | access, upload | multipart `image` | `{ success: 1, file: { url, ... } }` |
462
+ | POST | `/magic-editor-x/image/byUrl` | access, upload | `{ url }` | `{ success: 1, file }` |
463
+ | POST | `/magic-editor-x/file/upload` | access, upload | multipart `file` | `{ success: 1, file: { url, name, title, size, extension } }` |
464
+ | GET | `/magic-editor-x/content-types` | access | | `{ data: [{ uid, kind, displayName, attributes }] }` (types you can read) |
465
+ | GET | `/magic-editor-x/links/types` | access | | `{ data: [{ uid, kind, displayName, localized }] }` (API types you can read) |
466
+ | GET | `/magic-editor-x/links/search` | access (+ Content Manager read) | `?uid=api::x.y&q=&locale=&page=` (`q` up to 100 characters) | `{ data: [{ documentId, uid, locale, title, href, status? }], meta: { pagination } }` (up to 20 readable entries; unknown or unreadable type 404) |
467
+ | GET | `/magic-editor-x/custom-blocks` | access (`?all=true` also needs custom-blocks.manage) | `?all=true` | `{ data: [block] }` |
468
+ | GET | `/magic-editor-x/custom-blocks/export` | custom-blocks.manage | | `{ data: { format: 'magic-editor-x/custom-blocks', version: 2, exportedAt, blocks } }` |
469
+ | POST | `/magic-editor-x/custom-blocks/import` | custom-blocks.manage | export document | `{ data: { created: [name], skipped: [{ name, reason }] } }` |
470
+ | PUT | `/magic-editor-x/custom-blocks/order` | custom-blocks.manage | `{ ids }` (every block once) | `{ data: [block] }` |
471
+ | POST | `/magic-editor-x/custom-blocks` | custom-blocks.manage | block definition | 201 `{ data: block }` |
472
+ | PUT | `/magic-editor-x/custom-blocks/:id` | custom-blocks.manage | full block definition | `{ data: block }` |
473
+ | DELETE | `/magic-editor-x/custom-blocks/:id` | custom-blocks.manage | | `{ data: { id } }` |
474
+ | POST | `/magic-editor-x/custom-blocks/:id/duplicate` | custom-blocks.manage | | 201 `{ data: block }` |
475
+ | POST | `/magic-editor-x/collaboration/session` | access, collaborate | `{ uid, documentId, locale?, field, initialValue? }` | `{ data: { token, path, canEdit, expiresAt } }` |
476
+ | GET | `/magic-editor-x/history` | access | `?uid&documentId&locale&field` | `{ data: [version], meta: { canRestore, canCreate } }` |
477
+ | GET | `/magic-editor-x/history/:id` | access | | `{ data: { ...version, content } }` |
478
+ | POST | `/magic-editor-x/history` | access | `{ uid, documentId, locale?, field, content, label? }` | 201 new version, 200 with `meta.created: false` when unchanged (a `label` then names the latest version) |
479
+ | PUT | `/magic-editor-x/history/:id` | access (+ Content Manager update) | `{ label }` (up to 120 characters, `''` or `null` clears) | `{ data: version }`; 403 for read-only access, 404 without read access |
480
+ | POST | `/magic-editor-x/quality/links` | access (+ Content Manager read per type, Media Library read) | `{ internal?: [{ uid, documentId, locale? }] (max 100), media?: [id] (max 100), external?: [url] (max 20) }` | `{ data: { internal: [{ uid, documentId, locale, status }], media: [{ id, status }], external: [{ url, status, code? }] } }`; 429 above `qualityChecks.externalLinks.perMinute` |
481
+ | POST | `/magic-editor-x/ai/:action` | access, ai.use | `{ text, language?, tone?, target: { uid, field } }` | `{ data: { text } }`; 403 when the field turns AI off |
482
+ | GET | `/magic-editor-x/settings` | settings.read | | `{ data: { ai, environment } }` (no secrets) |
483
+ | PUT | `/magic-editor-x/settings` | settings.read, settings.update | `{ ai: { enabled, provider, baseUrl, model, maxInputChars, maxOutputTokens, apiKey? } }` | `{ data: { ai, environment } }` |
484
+ | POST | `/magic-editor-x/settings/ai/test` | settings.read, settings.update | `{ ai: {...} }` | `{ data: { ok: true } }` |
323
485
 
324
486
  `upload` means `plugin::upload.assets.create`. AI actions: `improve`, `grammar`, `shorten`, `expand`, `summarize`, `simplify`, `translate` (with `language`), `tone` (with `tone`), `continue`. Provider problems answer with `name: 'AIProviderError'` and `details.code` (`DISABLED`, `NOT_CONFIGURED`, `NO_API_KEY`, `AUTH_FAILED`, `PROVIDER_RATE_LIMIT`, `TIMEOUT`, `REFUSED`, `PROVIDER_ERROR`). Too long text answers 413, too many requests 429.
325
487
 
@@ -354,14 +516,61 @@ Content-Type: application/json
354
516
  - **Stored content:** every Magic Editor X value is normalised and sanitised on save by a Document Service middleware (Content Manager, Content API, imports and code). Unknown keys of known block types are dropped, URLs are checked, inline HTML is limited to the tags above and the raw HTML block follows `rawHtml`. Values over 5 MiB, with more than 5000 blocks or nested deeper than 24 levels are rejected with 400, never truncated. The admin sanitises again before rendering (DOMPurify with the same rules).
355
517
  - **Outgoing requests:** link previews and images by URL only fetch public http(s) addresses: the host is resolved once, every address must be public, the connection is pinned to that address, redirects are re-checked (at most 3), and size, type and time are limited. The AI provider is called only when an administrator configured it.
356
518
  - **Uploads** are checked by their first bytes (not by the file name or the browser's MIME type) and stored through the Media Library with the admin as creator.
357
- - **Collaboration:** tokens are signed, expire after `collaboration.tokenTtlSeconds` and work once; the socket accepts the admin and server origins and `collaboration.allowedOrigins`; messages are size-limited and must be valid Yjs updates; viewers cannot write.
519
+ - **Collaboration:** tokens are signed, bound to admin, document, locale and field, expire after `collaboration.tokenTtlSeconds` and work once on any process; the socket accepts the admin and server origins and `collaboration.allowedOrigins` and only clients of the current protocol; every update is checked (allowed structures only, no prototype keys, dependencies present, touched blocks valid) before it is stored or relayed, and a socket that keeps sending invalid updates is closed; names and colours of other people come from the server, never from a client; remote content is sanitised before the editor renders it; updates, sessions, sockets and rooms per admin are rate limited; viewers cannot write. See [docs/security-audit-2.1.md](./docs/security-audit-2.1.md).
520
+ - **Field presets** are enforced on the server (save middleware and realtime guard), not only in the editor; see [Field presets](#field-presets).
521
+ - **Paste, import and rendering:** pasted and imported HTML/Markdown is parsed into an inert document and rebuilt from the editor's own tags only, then sanitised again on save; `magic-editor-x/render` re-parses stored inline HTML and never trusts it. The link check fetches external URLs only when the owner turns it on, through the SSRF-protected fetcher, rate limited, without logging URLs. See [docs/security-audit-2.2.md](./docs/security-audit-2.2.md).
358
522
  - **Secrets:** the AI key is encrypted with AES-256-GCM (random IV, versioned format) and never returned. Changing the provider or base URL requires entering the key again, so a stored key cannot be sent to another host.
359
523
  - **Logs** contain operation names and error codes only, never content, URLs with queries, tokens, user ids or email addresses.
360
524
  - **Stored data:** custom block definitions, versions (field content and the admin who saved it), live rooms (Yjs updates, removed `collaboration.roomTtlMinutes` after the last person left) and presence rows (admin display name, colour, caret position; removed when the socket closes or after missed heartbeats).
361
- - **Content Security Policy:** Editor.js and the Design System add inline styles, which Strapi's default `style-src 'unsafe-inline'` allows. The socket connects to the same origin as the admin, which `connect-src 'self'` covers; add the `wss:` origin only when the admin runs on another host. Embed iframes need `frame-src` only on your frontend.
525
+ - **Content Security Policy:** Editor.js and the Design System add inline styles, which Strapi's default `style-src 'unsafe-inline'` allows. The socket connects to the same origin as the admin, which `connect-src 'self'` covers; add the `wss:` origin only when the admin runs on another host. Embeds and external images in the editor preview need `frame-src` and `img-src` sources; see [Content Security Policy](#content-security-policy) below.
362
526
 
363
527
  Report vulnerabilities privately through GitHub security advisories on the repository.
364
528
 
529
+ ### Content Security Policy
530
+
531
+ Strapi's default admin CSP (`strapi::security`) has no `frame-src`, so embed iframes fall back to `default-src 'self'`, and its `img-src` allows only `'self'`, `data:`, `blob:` and `market-assets.strapi.io`. YouTube, Vimeo and the other embeds, and images from other hosts (for example link preview images), are therefore blocked in the editor preview. The stored content is not affected and your frontend has its own CSP.
532
+
533
+ The plugin never changes the CSP. Instead:
534
+
535
+ - **Settings > Magic Editor X > Configuration** shows a "Content Security Policy" notice when sources are missing: what is blocked and the exact `config/middlewares.js` snippet, with a copy button. The server reads the effective `strapi::security` configuration once at startup (string and object entries, `useDefaults`, `frame-src`, `child-src`, `default-src`, `img-src`) and returns it in `GET /magic-editor-x/settings` as `data.environment.csp` (`{ active, frameSrcMissing, imgSrcMissing, snippet }`). Only CSP sources are returned; browsers receive them in every response header anyway.
536
+ - **In the editor**, a blocked embed or image is replaced by a placeholder inside the block ("This embed is blocked by your Content Security Policy.") with a link to the settings page for admins who can read the settings. The block data is saved unchanged.
537
+
538
+ The snippet for Strapi's defaults (merge it into your existing `strapi::security` entry and keep your other directives, for example the hosts of your upload provider; Strapi merges arrays with its defaults by position):
539
+
540
+ ```js
541
+ // config/middlewares.js
542
+ module.exports = [
543
+ // ...other middlewares
544
+ {
545
+ name: 'strapi::security',
546
+ config: {
547
+ contentSecurityPolicy: {
548
+ useDefaults: true,
549
+ directives: {
550
+ 'frame-src': [
551
+ "'self'",
552
+ 'https://www.youtube.com',
553
+ 'https://player.vimeo.com',
554
+ 'https://platform.twitter.com',
555
+ 'https://www.instagram.com',
556
+ 'https://codepen.io',
557
+ 'https://imgur.com',
558
+ 'https://assets.pinterest.com',
559
+ 'https://miro.com',
560
+ 'https://www.figma.com',
561
+ 'https://www.facebook.com',
562
+ ],
563
+ 'img-src': ["'self'", 'data:', 'blob:', 'https://market-assets.strapi.io', 'https:'],
564
+ },
565
+ },
566
+ },
567
+ },
568
+ // ...other middlewares
569
+ ];
570
+ ```
571
+
572
+ Add only the services you use. Instead of `https:` in `img-src` you can list your image hosts; the notice then counts external images as allowed. GitHub gist embeds load a `data:` iframe that inherits the admin CSP and needs a remote script, so they stay blocked under a strict policy, and Imgur's embed URL uses `http:`, which an `https` admin blocks as mixed content.
573
+
365
574
  ## Troubleshooting
366
575
 
367
576
  | Symptom | Cause | Fix |
@@ -371,11 +580,14 @@ Report vulnerabilities privately through GitHub security advisories on the repos
371
580
  | No version history (clock) button | The entry was never saved | Save the entry once. |
372
581
  | Badge shows "Live editing unavailable" | No `collaborate` action, no read access to the document, or `collaboration.enabled: false` | Grant the action or check the Content Manager permissions. |
373
582
  | Badge stays at "Connecting" or "Reconnecting" | The proxy does not forward WebSocket upgrades on `collaboration.path`, or the origin is not allowed | Allow upgrades on the path; add the admin origin to `collaboration.allowedOrigins` when the admin runs on another host. |
583
+ | "Reload the page to keep editing live" | The browser still runs the admin of an older version after an update | Reload the page. |
374
584
  | Settings say the API key cannot be stored | `MAGIC_EDITOR_X_ENCRYPTION_KEY` is missing or shorter than 32 characters | Set the variable and restart, or use `ai.apiKey`. |
375
585
  | Settings say the stored key is unreadable | The encryption key changed | Enter the provider key again. |
376
586
  | AI error "The AI provider rejected the key." | Wrong key for this provider | Enter the key again and use Test connection. |
377
587
  | Startup error `[magic-editor-x] invalid configuration for: <key>` | Wrong type or range in `config/plugins` | Fix the named key (see the reference table). |
378
588
  | 400 "A Magic Editor X field contains invalid content" | The value is not editor JSON, too large or too deep | Send an Editor.js object within the limits. |
589
+ | 400 "A Magic Editor X field does not match its field settings" | The content breaks the field's preset (`details.violations` lists rule codes and block ids) | Open the quality panel of the field and use Fix automatically, or change the content or the field options. |
590
+ | 400 "Quality checks failed for a Magic Editor X field" on publish | The field has `publishGuard` and the quality checks report errors | Fix the errors listed in the quality panel (missing alternative texts, empty links). |
379
591
 
380
592
  ## Migrating from 1.x
381
593