magic-editor-x 2.1.0 → 2.3.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.
- package/CHANGELOG.md +125 -0
- package/README.md +593 -142
- package/bin/magic-editor-x.mjs +190 -0
- package/dist/admin/{ConfigurationPage-CK2AbfGW.mjs → ConfigurationPage-BxLHIQdo.mjs} +450 -21
- package/dist/admin/{ConfigurationPage-CzsT_dO_.js → ConfigurationPage-C-UktL1x.js} +479 -50
- package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
- package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
- package/dist/admin/{CustomBlocksPage-CvLrsBds.js → CustomBlocksPage-CxcTfdOT.js} +135 -84
- package/dist/admin/{CustomBlocksPage-B2A8S5MV.mjs → CustomBlocksPage-D8aMbVXc.mjs} +92 -41
- package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
- package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
- package/dist/admin/TemplatesPage-Hn6gyu2l.js +993 -0
- package/dist/admin/TemplatesPage-jhYi6Zdf.mjs +993 -0
- package/dist/admin/de-1cFMs-4c.mjs +43 -0
- package/dist/admin/{de-CkUYGb7U.js → de-2Ie5jy7j.js} +86 -2
- package/dist/admin/de-B1X46JJZ.js +453 -0
- package/dist/admin/{de-rRIutpYJ.mjs → de-BMY2LBaa.mjs} +86 -2
- package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
- package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
- package/dist/admin/de-DOiGaTNX.mjs +453 -0
- package/dist/admin/de-Dn8athM8.js +43 -0
- package/dist/admin/{en-DulOcmXb.js → en-Ah-Cw0Wd.js} +86 -2
- package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
- package/dist/admin/en-CDg_18Bt.js +453 -0
- package/dist/admin/en-CIZ5Ggod.js +43 -0
- package/dist/admin/en-CU6UzV4g.mjs +453 -0
- package/dist/admin/{en-Puup8TFi.mjs → en-CvFiqti2.mjs} +86 -2
- package/dist/admin/en-Dc9y-6n9.mjs +43 -0
- package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
- package/dist/admin/es-BCpJmUEM.js +453 -0
- package/dist/admin/es-BmfffNM2.mjs +453 -0
- package/dist/admin/es-C4IRHV5d.js +43 -0
- package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
- package/dist/admin/{es-BoQZC86B.js → es-Cr8JH85N.js} +86 -2
- package/dist/admin/es-D2Kw6E4N.mjs +43 -0
- package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
- package/dist/admin/{es-257SSB7f.mjs → es-DbKHZz5l.mjs} +86 -2
- package/dist/admin/fr-BOvvfEH7.mjs +43 -0
- package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
- package/dist/admin/{fr-C5rSdKU4.mjs → fr-DQJ_7aq5.mjs} +86 -2
- package/dist/admin/fr-DZd2XJP6.mjs +453 -0
- package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
- package/dist/admin/{fr-HxFcPpv4.js → fr-OJ4VW1kh.js} +86 -2
- package/dist/admin/fr-ZcN0yM_2.js +453 -0
- package/dist/admin/fr-Zkb8vfjN.js +43 -0
- package/dist/admin/index-BHBRr562.js +1940 -0
- package/dist/admin/index-CQk1XeNb.mjs +1939 -0
- package/dist/admin/index-Cm-fFUhE.js +18908 -0
- package/dist/admin/index-XgfwqLfV.mjs +18873 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/pt-1IUyx6ae.js +43 -0
- package/dist/admin/{pt-D6UuEtPy.mjs → pt-BSLzA17U.mjs} +86 -2
- package/dist/admin/pt-C3UdeIpd.mjs +453 -0
- package/dist/admin/pt-CImqDnLB.js +453 -0
- package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
- package/dist/admin/{pt-Cjn2Sc9k.js → pt-D0I0_JYs.js} +86 -2
- package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
- package/dist/admin/pt-etwsg3G4.mjs +43 -0
- package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
- package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
- package/dist/admin/useT-CmaeZbCr.mjs +65 -0
- package/dist/admin/{useT-91ruePzq.js → useT-D3sM9Zf7.js} +4 -70
- package/dist/blocks/index.d.mts +167 -0
- package/dist/blocks/index.d.ts +167 -0
- package/dist/blocks/index.js +631 -0
- package/dist/blocks/index.mjs +609 -0
- package/dist/react/index.d.mts +39 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.js +2687 -0
- package/dist/react/index.mjs +2657 -0
- package/dist/render/index.d.mts +201 -0
- package/dist/render/index.d.ts +201 -0
- package/dist/render/index.js +2918 -0
- package/dist/render/index.mjs +2896 -0
- package/dist/server/index.js +19400 -4738
- package/dist/server/index.mjs +19403 -4741
- package/dist/vue/index.d.mts +41 -0
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.js +2630 -0
- package/dist/vue/index.mjs +2610 -0
- package/package.json +49 -8
- package/schema/magic-editor-x.schema.json +1506 -0
- package/types/blocks.d.ts +167 -0
- package/types/index.d.ts +338 -0
- package/types/react.d.ts +39 -0
- package/types/render.d.ts +201 -0
- package/types/vue.d.ts +41 -0
- package/dist/admin/EditorField-7YCdXx-v.mjs +0 -6829
- package/dist/admin/EditorField-BdBCW15Q.js +0 -6864
- package/dist/admin/api-CmccMxlN.js +0 -36
- package/dist/admin/api-D5CAH0nh.mjs +0 -37
- package/dist/admin/de-BHPyA2S-.mjs +0 -103
- package/dist/admin/de-DBR893G4.js +0 -13
- package/dist/admin/de-RMs-_SCK.js +0 -103
- package/dist/admin/de-fBFh09Wl.mjs +0 -13
- package/dist/admin/en-BluCStLw.mjs +0 -103
- package/dist/admin/en-C81faOHP.js +0 -103
- package/dist/admin/en-D9Nfccux.mjs +0 -13
- package/dist/admin/en-gueRT44P.js +0 -13
- package/dist/admin/es-B0Zy8DVg.mjs +0 -13
- package/dist/admin/es-CQRI2Prp.mjs +0 -103
- package/dist/admin/es-D1QzY0JW.js +0 -103
- package/dist/admin/es-DRGs7meF.js +0 -13
- package/dist/admin/fr-B8rdLAIL.js +0 -13
- package/dist/admin/fr-Di3R6gOX.mjs +0 -103
- package/dist/admin/fr-R3_MbzT5.js +0 -103
- package/dist/admin/fr-oiUb2bb_.mjs +0 -13
- package/dist/admin/index-0_b1iroK.mjs +0 -156
- package/dist/admin/index-6SZLli70.js +0 -155
- package/dist/admin/pt-B3Jce6uT.mjs +0 -13
- package/dist/admin/pt-BCW1u_Hp.js +0 -103
- package/dist/admin/pt-BiWuSBcH.js +0 -13
- package/dist/admin/pt-Cr9AL408.mjs +0 -103
- package/dist/admin/sanitize-DP5aeU7V.js +0 -597
- package/dist/admin/sanitize-jjCot5PM.mjs +0 -596
- package/dist/admin/useT-vgY88N_H.mjs +0 -131
|
@@ -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
|
+
}
|