magic-editor-x 2.1.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 (81) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +215 -89
  3. package/bin/magic-editor-x.mjs +190 -0
  4. package/dist/admin/{ConfigurationPage-CK2AbfGW.mjs → ConfigurationPage-3Dir3dAf.mjs} +3 -3
  5. package/dist/admin/{ConfigurationPage-CzsT_dO_.js → ConfigurationPage-YvnPnna6.js} +3 -3
  6. package/dist/admin/{CustomBlocksPage-CvLrsBds.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
  7. package/dist/admin/{CustomBlocksPage-B2A8S5MV.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
  8. package/dist/admin/{EditorField-7YCdXx-v.mjs → EditorField-B8pyAxPE.mjs} +5384 -278
  9. package/dist/admin/{EditorField-BdBCW15Q.js → EditorField-Diq1j8kc.js} +5378 -272
  10. package/dist/admin/{api-CmccMxlN.js → api-Dsq53giv.js} +1 -0
  11. package/dist/admin/{api-D5CAH0nh.mjs → api-RZ0Fz0BD.mjs} +1 -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-CkUYGb7U.js → de-BteRx2iA.js} +7 -1
  16. package/dist/admin/{de-rRIutpYJ.mjs → de-CFX5atOk.mjs} +7 -1
  17. package/dist/admin/de-DaJwN6nk.js +41 -0
  18. package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
  19. package/dist/admin/en-Cn78RZs-.js +41 -0
  20. package/dist/admin/{en-DulOcmXb.js → en-CyjAcccB.js} +7 -1
  21. package/dist/admin/en-D7mZWLGp.mjs +41 -0
  22. package/dist/admin/en-VlkaIzrM.js +250 -0
  23. package/dist/admin/{en-Puup8TFi.mjs → en-ea0tfA5i.mjs} +7 -1
  24. package/dist/admin/es-BT9oAcHf.js +250 -0
  25. package/dist/admin/es-BmGtLkJD.js +41 -0
  26. package/dist/admin/{es-BoQZC86B.js → es-C8GZFGjv.js} +7 -1
  27. package/dist/admin/es-C9-cXdb6.mjs +250 -0
  28. package/dist/admin/{es-257SSB7f.mjs → es-CEi_ycX8.mjs} +7 -1
  29. package/dist/admin/es-joykG5I9.mjs +41 -0
  30. package/dist/admin/{fr-C5rSdKU4.mjs → fr-BAMSvQbR.mjs} +7 -1
  31. package/dist/admin/fr-CrzxGe5e.mjs +41 -0
  32. package/dist/admin/fr-Ct_uPqxV.js +41 -0
  33. package/dist/admin/fr-D6KJqPWi.js +250 -0
  34. package/dist/admin/fr-DpU_qiXR.mjs +250 -0
  35. package/dist/admin/{fr-HxFcPpv4.js → fr-oRCJNdeJ.js} +7 -1
  36. package/dist/admin/index-C-lyON1B.mjs +303 -0
  37. package/dist/admin/index-iA0lued_.js +302 -0
  38. package/dist/admin/index.js +1 -1
  39. package/dist/admin/index.mjs +1 -1
  40. package/dist/admin/pt-BOrl6x-r.js +250 -0
  41. package/dist/admin/{pt-D6UuEtPy.mjs → pt-CQrfqsCN.mjs} +7 -1
  42. package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
  43. package/dist/admin/pt-chN2jrXl.js +41 -0
  44. package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
  45. package/dist/admin/{pt-Cjn2Sc9k.js → pt-tUeJ2Ywd.js} +7 -1
  46. package/dist/admin/{sanitize-DP5aeU7V.js → sanitize-Cb4jvBhj.js} +42 -11
  47. package/dist/admin/{sanitize-jjCot5PM.mjs → sanitize-ClkX823p.mjs} +45 -14
  48. package/dist/admin/{useT-91ruePzq.js → useT-BWZ_-Hel.js} +1 -1
  49. package/dist/admin/{useT-vgY88N_H.mjs → useT-pvHmgBFj.mjs} +1 -1
  50. package/dist/render/index.d.mts +75 -0
  51. package/dist/render/index.d.ts +75 -0
  52. package/dist/render/index.js +1420 -0
  53. package/dist/render/index.mjs +1398 -0
  54. package/dist/server/index.js +8081 -348
  55. package/dist/server/index.mjs +8084 -351
  56. package/package.json +21 -4
  57. package/schema/magic-editor-x.schema.json +967 -0
  58. package/types/index.d.ts +211 -0
  59. package/types/render.d.ts +75 -0
  60. package/dist/admin/de-BHPyA2S-.mjs +0 -103
  61. package/dist/admin/de-DBR893G4.js +0 -13
  62. package/dist/admin/de-RMs-_SCK.js +0 -103
  63. package/dist/admin/de-fBFh09Wl.mjs +0 -13
  64. package/dist/admin/en-BluCStLw.mjs +0 -103
  65. package/dist/admin/en-C81faOHP.js +0 -103
  66. package/dist/admin/en-D9Nfccux.mjs +0 -13
  67. package/dist/admin/en-gueRT44P.js +0 -13
  68. package/dist/admin/es-B0Zy8DVg.mjs +0 -13
  69. package/dist/admin/es-CQRI2Prp.mjs +0 -103
  70. package/dist/admin/es-D1QzY0JW.js +0 -103
  71. package/dist/admin/es-DRGs7meF.js +0 -13
  72. package/dist/admin/fr-B8rdLAIL.js +0 -13
  73. package/dist/admin/fr-Di3R6gOX.mjs +0 -103
  74. package/dist/admin/fr-R3_MbzT5.js +0 -103
  75. package/dist/admin/fr-oiUb2bb_.mjs +0 -13
  76. package/dist/admin/index-0_b1iroK.mjs +0 -156
  77. package/dist/admin/index-6SZLli70.js +0 -155
  78. package/dist/admin/pt-B3Jce6uT.mjs +0 -13
  79. package/dist/admin/pt-BCW1u_Hp.js +0 -103
  80. package/dist/admin/pt-BiWuSBcH.js +0 -13
  81. package/dist/admin/pt-Cr9AL408.mjs +0 -103
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Magic Editor X command line.
4
+ *
5
+ * npx magic-editor-x migrate --uid api::article.article --from body --to content [--apply]
6
+ *
7
+ * Run it from the root of the Strapi project. It loads the project with
8
+ * Strapi's programmatic API (compileStrapi, createStrapi().load(), destroy()),
9
+ * without starting the HTTP server, runs the plugin's `migrate` service and
10
+ * prints the report. Without `--apply` nothing is written (dry run).
11
+ */
12
+
13
+ import { createRequire } from 'node:module';
14
+ import { join } from 'node:path';
15
+ import { realpathSync, writeFileSync } from 'node:fs';
16
+ import { pathToFileURL } from 'node:url';
17
+ import { parseArgs } from 'node:util';
18
+
19
+ const HELP = `Usage: magic-editor-x migrate --uid <uid> --from <field> --to <field> [options]
20
+
21
+ Copies and converts a Strapi Blocks, Rich text (Markdown), text or JSON field
22
+ into a Magic Editor X field of the same content type. The source field is not
23
+ changed. Documents whose target field already has content are skipped.
24
+
25
+ Options:
26
+ --uid <uid> Content type, for example api::article.article
27
+ --from <field> Source field (blocks, richtext, text, string or json)
28
+ --to <field> Target Magic Editor X field (top level)
29
+ --format <format> auto (default), blocks, markdown or html
30
+ --locale <code> Locale code, or * for every locale (default: default locale)
31
+ --apply Write the converted content (default: dry run)
32
+ --overwrite Also replace target fields that already have content
33
+ --batch <n> Documents per page, 1-500 (default 50)
34
+ --limit <n> Stop after n documents
35
+ --json Print the report as JSON
36
+ --out <file> Also write the JSON report to a file
37
+ -h, --help Show this help
38
+
39
+ Exit code 1 when an option is invalid or a document failed.`;
40
+
41
+ /**
42
+ * Parses and validates the command line.
43
+ * @param {string[]} argv - Arguments after the script name.
44
+ * @returns {{ help: true } | { help: false, json: boolean, out?: string, options: object }} Parsed command.
45
+ * @throws {Error} When an argument is invalid.
46
+ */
47
+ export const parseCommand = (argv) => {
48
+ const { values, positionals } = parseArgs({
49
+ args: argv,
50
+ allowPositionals: true,
51
+ strict: true,
52
+ options: {
53
+ uid: { type: 'string' },
54
+ from: { type: 'string' },
55
+ to: { type: 'string' },
56
+ format: { type: 'string' },
57
+ locale: { type: 'string' },
58
+ apply: { type: 'boolean' },
59
+ overwrite: { type: 'boolean' },
60
+ batch: { type: 'string' },
61
+ limit: { type: 'string' },
62
+ json: { type: 'boolean' },
63
+ out: { type: 'string' },
64
+ help: { type: 'boolean', short: 'h' },
65
+ },
66
+ });
67
+ 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
+ const integer = (name) => {
72
+ if (values[name] === undefined) return undefined;
73
+ if (!/^\d{1,7}$/.test(values[name])) throw new Error(`--${name} must be a positive integer`);
74
+ return Number(values[name]);
75
+ };
76
+ const options = {
77
+ uid: values.uid,
78
+ from: values.from,
79
+ to: values.to,
80
+ format: values.format || 'auto',
81
+ dryRun: !values.apply,
82
+ overwrite: Boolean(values.overwrite),
83
+ };
84
+ if (values.locale) options.locale = values.locale;
85
+ const batch = integer('batch');
86
+ if (batch !== undefined) options.batchSize = batch;
87
+ const limit = integer('limit');
88
+ if (limit !== undefined) options.limit = limit;
89
+ return { help: false, json: Boolean(values.json), out: values.out, options };
90
+ };
91
+
92
+ /**
93
+ * Formats a report for people.
94
+ * @param {object} report - Migration report.
95
+ * @returns {string} Text.
96
+ */
97
+ export const formatReport = (report) => {
98
+ const lines = [
99
+ `${report.dryRun ? 'Dry run' : 'Migration'}: ${report.uid} ${report.from} -> ${report.to} (format ${report.format})`,
100
+ ` scanned ${report.scanned}`,
101
+ ` ${report.dryRun ? 'would convert' : 'converted '} ${report.converted}`,
102
+ ` skipped (target) ${report.skippedExisting}`,
103
+ ` skipped (empty) ${report.skippedEmpty}`,
104
+ ` failed ${report.failed.length}`,
105
+ ` lossy ${report.lossy.length}`,
106
+ ];
107
+ for (const entry of report.failed)
108
+ lines.push(` failed ${entry.documentId} ${entry.locale || '-'} ${entry.code}`);
109
+ for (const entry of report.lossy)
110
+ lines.push(` lossy ${entry.documentId} ${entry.locale || '-'} ${entry.notes.join(', ')}`);
111
+ if (report.dryRun) lines.push('Nothing was written. Run again with --apply to convert.');
112
+ return lines.join('\n');
113
+ };
114
+
115
+ /**
116
+ * Runs the command.
117
+ * @param {string[]} argv - Arguments.
118
+ * @returns {Promise<number>} Exit code.
119
+ */
120
+ export const main = async (argv) => {
121
+ let command;
122
+ try {
123
+ command = parseCommand(argv);
124
+ } catch (error) {
125
+ process.stderr.write(`${error.message}\n\n${HELP}\n`);
126
+ return 1;
127
+ }
128
+ if (command.help) {
129
+ process.stdout.write(`${HELP}\n`);
130
+ return 0;
131
+ }
132
+ const projectRequire = createRequire(join(process.cwd(), 'package.json'));
133
+ let core;
134
+ try {
135
+ core = projectRequire('@strapi/strapi');
136
+ } catch {
137
+ process.stderr.write(
138
+ 'Run this command from the root of a Strapi 5 project (@strapi/strapi was not found).\n'
139
+ );
140
+ return 1;
141
+ }
142
+ // Strapi logs to stdout. Keep stdout for the report only (machine-readable
143
+ // with --json): everything Strapi prints goes to stderr.
144
+ const stdoutWrite = process.stdout.write.bind(process.stdout);
145
+ process.stdout.write = process.stderr.write.bind(process.stderr);
146
+ const print = (text) => stdoutWrite(text);
147
+ const appContext = await core.compileStrapi();
148
+ const app = await core.createStrapi(appContext).load();
149
+ let code;
150
+ try {
151
+ const plugin = app.plugin('magic-editor-x');
152
+ if (!plugin)
153
+ throw Object.assign(new Error('Magic Editor X is not installed in this project'), {
154
+ code: 'NO_PLUGIN',
155
+ });
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;
160
+ } catch (error) {
161
+ process.stderr.write(`${error && error.message ? error.message : 'Migration failed'}\n`);
162
+ code = 1;
163
+ } finally {
164
+ await app.destroy();
165
+ process.stdout.write = stdoutWrite;
166
+ }
167
+ return code;
168
+ };
169
+
170
+ /**
171
+ * True when this file is the entry point (also through the npm bin symlink).
172
+ * @returns {boolean} Result.
173
+ */
174
+ const isEntryPoint = () => {
175
+ try {
176
+ return Boolean(process.argv[1]) && pathToFileURL(realpathSync(process.argv[1])).href === import.meta.url;
177
+ } catch {
178
+ return false;
179
+ }
180
+ };
181
+
182
+ if (isEntryPoint()) {
183
+ main(process.argv.slice(2)).then(
184
+ (code) => process.exit(code),
185
+ (error) => {
186
+ process.stderr.write(`${error && error.message ? error.message : 'Migration failed'}\n`);
187
+ process.exit(1);
188
+ }
189
+ );
190
+ }
@@ -2,11 +2,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Box, Flex, Typography, Switch, Grid, Field, SingleSelect, SingleSelectOption, TextInput, TextButton, NumberInput, Button, Badge, Alert, IconButton } from "@strapi/design-system";
3
3
  import { useForm, useFetchClient, useClipboard, useNotification, useRBAC, Page, Form, Blocker } from "@strapi/strapi/admin";
4
4
  import { Duplicate, Check } from "@strapi/icons";
5
- import { P as PERMISSIONS } from "./index-0_b1iroK.mjs";
6
- import { u as useT, S as SectionCard, P as PageShell, C as ConfirmAction } from "./useT-vgY88N_H.mjs";
5
+ import { P as PERMISSIONS } from "./index-C-lyON1B.mjs";
6
+ import { u as useT, S as SectionCard, P as PageShell, C as ConfirmAction } from "./useT-pvHmgBFj.mjs";
7
7
  import { useEffect, useState, useRef, useCallback, useMemo } from "react";
8
8
  import styled from "styled-components";
9
- import { A as API, r as readApiError } from "./api-D5CAH0nh.mjs";
9
+ import { A as API, r as readApiError } from "./api-RZ0Fz0BD.mjs";
10
10
  import { useIntl } from "react-intl";
11
11
  const DraftSync = ({ values }) => {
12
12
  const setValues = useForm("MagicEditorXDraftSync", (state) => state.setValues);
@@ -4,11 +4,11 @@ const jsxRuntime = require("react/jsx-runtime");
4
4
  const designSystem = require("@strapi/design-system");
5
5
  const admin = require("@strapi/strapi/admin");
6
6
  const icons = require("@strapi/icons");
7
- const index = require("./index-6SZLli70.js");
8
- const useT = require("./useT-91ruePzq.js");
7
+ const index = require("./index-iA0lued_.js");
8
+ const useT = require("./useT-BWZ_-Hel.js");
9
9
  const react = require("react");
10
10
  const styled = require("styled-components");
11
- const api = require("./api-CmccMxlN.js");
11
+ const api = require("./api-Dsq53giv.js");
12
12
  const reactIntl = require("react-intl");
13
13
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
14
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
@@ -6,11 +6,11 @@ const designSystem = require("@strapi/design-system");
6
6
  const icons = require("@strapi/icons");
7
7
  const symbols = require("@strapi/icons/symbols");
8
8
  const admin = require("@strapi/strapi/admin");
9
- const index = require("./index-6SZLli70.js");
10
- const api = require("./api-CmccMxlN.js");
11
- const useT = require("./useT-91ruePzq.js");
9
+ const index = require("./index-iA0lued_.js");
10
+ const api = require("./api-Dsq53giv.js");
11
+ const useT = require("./useT-BWZ_-Hel.js");
12
12
  const styled = require("styled-components");
13
- const sanitize = require("./sanitize-DP5aeU7V.js");
13
+ const sanitize = require("./sanitize-Cb4jvBhj.js");
14
14
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
15
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
16
16
  const toQuery = (breakpoint) => typeof breakpoint === "string" ? breakpoint.replace(/^\s*@media\s*/i, "").trim() : "";
@@ -4,11 +4,11 @@ import { Box, Typography, Flex, Badge, Table, Thead, Tr, Th, VisuallyHidden, Tbo
4
4
  import { Pencil, Duplicate, ArrowUp, ArrowDown, Trash, Plus, Upload, Download } from "@strapi/icons";
5
5
  import { EmptyDocuments } from "@strapi/icons/symbols";
6
6
  import { useFetchClient, useNotification, useRBAC, Page } from "@strapi/strapi/admin";
7
- import { P as PERMISSIONS } from "./index-0_b1iroK.mjs";
8
- import { A as API, r as readApiError } from "./api-D5CAH0nh.mjs";
9
- import { u as useT, C as ConfirmAction, P as PageShell, S as SectionCard, r as refocusIfLost } from "./useT-vgY88N_H.mjs";
7
+ import { P as PERMISSIONS } from "./index-C-lyON1B.mjs";
8
+ import { A as API, r as readApiError } from "./api-RZ0Fz0BD.mjs";
9
+ import { u as useT, C as ConfirmAction, P as PageShell, S as SectionCard, r as refocusIfLost } from "./useT-pvHmgBFj.mjs";
10
10
  import styled, { useTheme } from "styled-components";
11
- import { b as sanitizeSvg, c as sanitizeTemplate } from "./sanitize-jjCot5PM.mjs";
11
+ import { b as sanitizeSvg, c as sanitizeTemplate } from "./sanitize-ClkX823p.mjs";
12
12
  const toQuery = (breakpoint) => typeof breakpoint === "string" ? breakpoint.replace(/^\s*@media\s*/i, "").trim() : "";
13
13
  const useBreakpoint = () => {
14
14
  const theme = useTheme();