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.
- package/CHANGELOG.md +107 -0
- package/README.md +315 -103
- package/bin/magic-editor-x.mjs +190 -0
- package/dist/admin/{ConfigurationPage-DvAifELO.mjs → ConfigurationPage-3Dir3dAf.mjs} +126 -7
- package/dist/admin/{ConfigurationPage-B1uCIE3J.js → ConfigurationPage-YvnPnna6.js} +125 -4
- package/dist/admin/{CustomBlocksPage-6eWCOreU.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
- package/dist/admin/{CustomBlocksPage-6-OQwpXQ.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
- package/dist/admin/EditorField-B8pyAxPE.mjs +11935 -0
- package/dist/admin/EditorField-Diq1j8kc.js +11970 -0
- package/dist/admin/{api-B-RsxJCs.js → api-Dsq53giv.js} +3 -0
- package/dist/admin/{api-C4XsDZxd.mjs → api-RZ0Fz0BD.mjs} +3 -0
- package/dist/admin/de-62Vxb2iw.js +250 -0
- package/dist/admin/de-BVvwSYYO.mjs +250 -0
- package/dist/admin/de-BmmLBJli.mjs +41 -0
- package/dist/admin/{de-BMxADn2Z.mjs → de-Bt6pYIWi.mjs} +16 -1
- package/dist/admin/{de-DcDPRzV4.js → de-BteRx2iA.js} +28 -1
- package/dist/admin/{de-n5V6c5RT.mjs → de-CFX5atOk.mjs} +28 -1
- package/dist/admin/{de-Dx7vUW0Z.js → de-CVbi685U.js} +16 -1
- package/dist/admin/de-DaJwN6nk.js +41 -0
- package/dist/admin/{en-sNn4z9lA.js → en-BX362fTp.js} +16 -1
- package/dist/admin/{en-BQ5Pxe2o.mjs → en-B_HltUxZ.mjs} +16 -1
- package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
- package/dist/admin/en-Cn78RZs-.js +41 -0
- package/dist/admin/{en-D-DGftl0.js → en-CyjAcccB.js} +28 -1
- package/dist/admin/en-D7mZWLGp.mjs +41 -0
- package/dist/admin/en-VlkaIzrM.js +250 -0
- package/dist/admin/{en-BqNm3nMQ.mjs → en-ea0tfA5i.mjs} +28 -1
- package/dist/admin/es-BT9oAcHf.js +250 -0
- package/dist/admin/es-BmGtLkJD.js +41 -0
- package/dist/admin/{es-Di0pyQCh.js → es-C8GZFGjv.js} +28 -1
- package/dist/admin/es-C9-cXdb6.mjs +250 -0
- package/dist/admin/{es-SzeTV4q8.mjs → es-CEi_ycX8.mjs} +28 -1
- package/dist/admin/{es-DVsXnS0N.js → es-CHHEZi44.js} +16 -1
- package/dist/admin/{es-B6NYq0VH.mjs → es-CrhwOq-5.mjs} +16 -1
- package/dist/admin/es-joykG5I9.mjs +41 -0
- package/dist/admin/{fr-DmG3_Cn-.mjs → fr-5djKfQ3s.mjs} +16 -1
- package/dist/admin/{fr-Fwxcj4SM.js → fr-B3SL0TBV.js} +16 -1
- package/dist/admin/{fr-DhgPYHIH.mjs → fr-BAMSvQbR.mjs} +28 -1
- package/dist/admin/fr-CrzxGe5e.mjs +41 -0
- package/dist/admin/fr-Ct_uPqxV.js +41 -0
- package/dist/admin/fr-D6KJqPWi.js +250 -0
- package/dist/admin/fr-DpU_qiXR.mjs +250 -0
- package/dist/admin/{fr-D6F--jIB.js → fr-oRCJNdeJ.js} +28 -1
- package/dist/admin/index-C-lyON1B.mjs +303 -0
- package/dist/admin/index-iA0lued_.js +302 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/pt-BOrl6x-r.js +250 -0
- package/dist/admin/{pt-BbdwHlWF.mjs → pt-BdnY2Cth.mjs} +16 -1
- package/dist/admin/{pt-BvSl1btT.mjs → pt-CQrfqsCN.mjs} +28 -1
- package/dist/admin/{pt-C6nr71Yw.js → pt-EVwCuBUK.js} +16 -1
- package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
- package/dist/admin/pt-chN2jrXl.js +41 -0
- package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
- package/dist/admin/{pt-BPo0ex21.js → pt-tUeJ2Ywd.js} +28 -1
- package/dist/admin/{sanitize-9UVcXFfc.js → sanitize-Cb4jvBhj.js} +88 -12
- package/dist/admin/{sanitize-D4kfZ_ly.mjs → sanitize-ClkX823p.mjs} +89 -13
- package/dist/admin/{useT-B5M49wGH.js → useT-BWZ_-Hel.js} +1 -1
- package/dist/admin/{useT-CjX6fL2m.mjs → useT-pvHmgBFj.mjs} +1 -1
- package/dist/render/index.d.mts +75 -0
- package/dist/render/index.d.ts +75 -0
- package/dist/render/index.js +1420 -0
- package/dist/render/index.mjs +1398 -0
- package/dist/server/index.js +9562 -589
- package/dist/server/index.mjs +9565 -592
- package/package.json +21 -4
- package/schema/magic-editor-x.schema.json +967 -0
- package/types/index.d.ts +211 -0
- package/types/render.d.ts +75 -0
- package/dist/admin/EditorField-DocyD2Q3.js +0 -5506
- package/dist/admin/EditorField-ThSoOCPm.mjs +0 -5471
- package/dist/admin/de-B8XFFhHh.js +0 -95
- package/dist/admin/de-DBR893G4.js +0 -13
- package/dist/admin/de-RAxzvrwm.mjs +0 -95
- package/dist/admin/de-fBFh09Wl.mjs +0 -13
- package/dist/admin/en-BzfyifEU.mjs +0 -95
- package/dist/admin/en-D9Nfccux.mjs +0 -13
- package/dist/admin/en-DcWUTE2J.js +0 -95
- package/dist/admin/en-gueRT44P.js +0 -13
- package/dist/admin/es-B0Zy8DVg.mjs +0 -13
- package/dist/admin/es-BOtVc9qv.js +0 -95
- package/dist/admin/es-C2OJVYkV.mjs +0 -95
- package/dist/admin/es-DRGs7meF.js +0 -13
- package/dist/admin/fr-B8rdLAIL.js +0 -13
- package/dist/admin/fr-Bpo5Uq1f.mjs +0 -95
- package/dist/admin/fr-DfxKaOc_.js +0 -95
- package/dist/admin/fr-oiUb2bb_.mjs +0 -13
- package/dist/admin/index-CwfaB5-e.js +0 -155
- package/dist/admin/index-D1Q5Rlt6.mjs +0 -156
- package/dist/admin/pt-B3Jce6uT.mjs +0 -13
- package/dist/admin/pt-BiWuSBcH.js +0 -13
- package/dist/admin/pt-DqCXuI4S.mjs +0 -95
- package/dist/admin/pt-LCvjwk0y.js +0 -95
|
@@ -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
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Flex, Typography, Switch, Grid, Field, SingleSelect, SingleSelectOption, TextInput, TextButton, NumberInput, Button, Badge, Alert } from "@strapi/design-system";
|
|
3
|
-
import { useForm, useFetchClient, useNotification, useRBAC, Page, Form, Blocker } from "@strapi/strapi/admin";
|
|
4
|
-
import { Check } from "@strapi/icons";
|
|
5
|
-
import { P as PERMISSIONS } from "./index-
|
|
6
|
-
import { u as useT, S as SectionCard, P as PageShell, C as ConfirmAction } from "./useT-
|
|
2
|
+
import { Box, Flex, Typography, Switch, Grid, Field, SingleSelect, SingleSelectOption, TextInput, TextButton, NumberInput, Button, Badge, Alert, IconButton } from "@strapi/design-system";
|
|
3
|
+
import { useForm, useFetchClient, useClipboard, useNotification, useRBAC, Page, Form, Blocker } from "@strapi/strapi/admin";
|
|
4
|
+
import { Duplicate, Check } from "@strapi/icons";
|
|
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
|
-
import "styled-components";
|
|
9
|
-
import { A as API, r as readApiError } from "./api-
|
|
8
|
+
import styled from "styled-components";
|
|
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);
|
|
@@ -611,6 +611,124 @@ const EnvironmentSection = ({ environment }) => {
|
|
|
611
611
|
}
|
|
612
612
|
);
|
|
613
613
|
};
|
|
614
|
+
const CodeBlock = styled.pre`
|
|
615
|
+
margin: 0;
|
|
616
|
+
max-width: 100%;
|
|
617
|
+
overflow-x: auto;
|
|
618
|
+
padding: ${({ theme }) => theme.spaces[4]};
|
|
619
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
620
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
621
|
+
background: ${({ theme }) => theme.colors.neutral100};
|
|
622
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
623
|
+
font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
|
|
624
|
+
font-size: ${({ theme }) => theme.fontSizes[1]};
|
|
625
|
+
line-height: 1.6;
|
|
626
|
+
white-space: pre;
|
|
627
|
+
|
|
628
|
+
&:focus-visible {
|
|
629
|
+
outline: 2px solid ${({ theme }) => theme.colors.primary600};
|
|
630
|
+
outline-offset: 2px;
|
|
631
|
+
}
|
|
632
|
+
`;
|
|
633
|
+
const selectText = (node) => {
|
|
634
|
+
if (!node || typeof window.getSelection !== "function") return;
|
|
635
|
+
const range = document.createRange();
|
|
636
|
+
range.selectNodeContents(node);
|
|
637
|
+
const selection = window.getSelection();
|
|
638
|
+
selection.removeAllRanges();
|
|
639
|
+
selection.addRange(range);
|
|
640
|
+
node.focus();
|
|
641
|
+
};
|
|
642
|
+
const CspSection = ({ csp }) => {
|
|
643
|
+
const t = useT();
|
|
644
|
+
const { copy } = useClipboard();
|
|
645
|
+
const { toggleNotification } = useNotification();
|
|
646
|
+
const codeRef = useRef(null);
|
|
647
|
+
const [alertOpen, setAlertOpen] = useState(true);
|
|
648
|
+
const frameMissing = csp && Array.isArray(csp.frameSrcMissing) && csp.frameSrcMissing || [];
|
|
649
|
+
const imgMissing = Boolean(csp && csp.imgSrcMissing);
|
|
650
|
+
if (!csp || !csp.active || !csp.snippet || !frameMissing.length && !imgMissing) return null;
|
|
651
|
+
const onCopy = async () => {
|
|
652
|
+
const ok = await copy(csp.snippet);
|
|
653
|
+
if (ok) {
|
|
654
|
+
toggleNotification({
|
|
655
|
+
type: "success",
|
|
656
|
+
message: t("settings.csp.copied", "Snippet copied to the clipboard.")
|
|
657
|
+
});
|
|
658
|
+
} else {
|
|
659
|
+
selectText(codeRef.current);
|
|
660
|
+
toggleNotification({
|
|
661
|
+
type: "warning",
|
|
662
|
+
message: t(
|
|
663
|
+
"settings.csp.copyFailed",
|
|
664
|
+
"The browser did not allow copying. The snippet is selected; copy it with Ctrl+C or Cmd+C."
|
|
665
|
+
)
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const allowed = t("settings.csp.allowed", "Allowed");
|
|
670
|
+
const codeLabel = t("settings.csp.codeLabel", "Snippet for config/middlewares.js");
|
|
671
|
+
return /* @__PURE__ */ jsxs(
|
|
672
|
+
SectionCard,
|
|
673
|
+
{
|
|
674
|
+
title: t("settings.csp.title", "Content Security Policy"),
|
|
675
|
+
subtitle: t(
|
|
676
|
+
"settings.csp.subtitle",
|
|
677
|
+
"The admin Content Security Policy is set in config/middlewares.js. The plugin never changes it."
|
|
678
|
+
),
|
|
679
|
+
children: [
|
|
680
|
+
alertOpen ? /* @__PURE__ */ jsx(
|
|
681
|
+
Alert,
|
|
682
|
+
{
|
|
683
|
+
variant: "warning",
|
|
684
|
+
closeLabel: t("settings.close", "Close"),
|
|
685
|
+
onClose: () => setAlertOpen(false),
|
|
686
|
+
title: t("settings.csp.alertTitle", "Some editor previews are blocked"),
|
|
687
|
+
children: t(
|
|
688
|
+
"settings.csp.alertBody",
|
|
689
|
+
"Your Content Security Policy blocks content the editor shows. Stored content is not affected; editors see a placeholder instead. To allow it, add the sources below to the strapi::security middleware and restart Strapi."
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
) : null,
|
|
693
|
+
/* @__PURE__ */ jsx(
|
|
694
|
+
PropertyList,
|
|
695
|
+
{
|
|
696
|
+
items: [
|
|
697
|
+
{
|
|
698
|
+
key: "frame",
|
|
699
|
+
label: t("settings.csp.frames", "Embeds (frame-src)"),
|
|
700
|
+
value: frameMissing.length ? t("settings.csp.framesBlocked", "Blocked: {sources}", { sources: frameMissing.join(", ") }) : allowed
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
key: "img",
|
|
704
|
+
label: t("settings.csp.images", "External images (img-src)"),
|
|
705
|
+
value: imgMissing ? t(
|
|
706
|
+
"settings.csp.imagesBlocked",
|
|
707
|
+
"Blocked: images from other hosts (for example link previews)"
|
|
708
|
+
) : allowed,
|
|
709
|
+
hint: imgMissing ? t(
|
|
710
|
+
"settings.csp.imagesHint",
|
|
711
|
+
"The snippet adds https:. You can list your image hosts instead."
|
|
712
|
+
) : void 0
|
|
713
|
+
}
|
|
714
|
+
]
|
|
715
|
+
}
|
|
716
|
+
),
|
|
717
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, minWidth: 0, children: [
|
|
718
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
719
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", id: "mex-csp-snippet-label", children: codeLabel }),
|
|
720
|
+
/* @__PURE__ */ jsx(IconButton, { label: t("settings.csp.copy", "Copy the snippet"), variant: "tertiary", onClick: onCopy, children: /* @__PURE__ */ jsx(Duplicate, {}) })
|
|
721
|
+
] }),
|
|
722
|
+
/* @__PURE__ */ jsx(Box, { minWidth: 0, children: /* @__PURE__ */ jsx(CodeBlock, { ref: codeRef, tabIndex: 0, "aria-labelledby": "mex-csp-snippet-label", children: /* @__PURE__ */ jsx("code", { children: csp.snippet }) }) }),
|
|
723
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
|
|
724
|
+
"settings.csp.mergeHint",
|
|
725
|
+
"Keep your other directives (for example the hosts of your upload provider) and restart Strapi after the change."
|
|
726
|
+
) })
|
|
727
|
+
] })
|
|
728
|
+
]
|
|
729
|
+
}
|
|
730
|
+
);
|
|
731
|
+
};
|
|
614
732
|
const RBAC = [...PERMISSIONS.settingsRead, ...PERMISSIONS.settingsUpdate];
|
|
615
733
|
const testErrorText = (t, code) => {
|
|
616
734
|
switch (code) {
|
|
@@ -753,6 +871,7 @@ const ConfigurationPage = () => {
|
|
|
753
871
|
) : null,
|
|
754
872
|
/* @__PURE__ */ jsx(AiSection, { form, readOnly, onTest }),
|
|
755
873
|
/* @__PURE__ */ jsx(EnvironmentSection, { environment: form.dto.environment }),
|
|
874
|
+
/* @__PURE__ */ jsx(CspSection, { csp: form.dto.environment && form.dto.environment.csp }),
|
|
756
875
|
/* @__PURE__ */ jsxs(Form, { method: "PUT", initialValues: form.saved, children: [
|
|
757
876
|
/* @__PURE__ */ jsx(DraftSync, { values: form.draft }),
|
|
758
877
|
/* @__PURE__ */ jsx(Blocker, {})
|
|
@@ -4,12 +4,14 @@ 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-
|
|
8
|
-
const useT = require("./useT-
|
|
7
|
+
const index = require("./index-iA0lued_.js");
|
|
8
|
+
const useT = require("./useT-BWZ_-Hel.js");
|
|
9
9
|
const react = require("react");
|
|
10
|
-
require("styled-components");
|
|
11
|
-
const api = require("./api-
|
|
10
|
+
const styled = require("styled-components");
|
|
11
|
+
const api = require("./api-Dsq53giv.js");
|
|
12
12
|
const reactIntl = require("react-intl");
|
|
13
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
14
|
+
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
13
15
|
const DraftSync = ({ values }) => {
|
|
14
16
|
const setValues = admin.useForm("MagicEditorXDraftSync", (state) => state.setValues);
|
|
15
17
|
react.useEffect(() => {
|
|
@@ -613,6 +615,124 @@ const EnvironmentSection = ({ environment }) => {
|
|
|
613
615
|
}
|
|
614
616
|
);
|
|
615
617
|
};
|
|
618
|
+
const CodeBlock = styled__default.default.pre`
|
|
619
|
+
margin: 0;
|
|
620
|
+
max-width: 100%;
|
|
621
|
+
overflow-x: auto;
|
|
622
|
+
padding: ${({ theme }) => theme.spaces[4]};
|
|
623
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
624
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
625
|
+
background: ${({ theme }) => theme.colors.neutral100};
|
|
626
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
627
|
+
font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
|
|
628
|
+
font-size: ${({ theme }) => theme.fontSizes[1]};
|
|
629
|
+
line-height: 1.6;
|
|
630
|
+
white-space: pre;
|
|
631
|
+
|
|
632
|
+
&:focus-visible {
|
|
633
|
+
outline: 2px solid ${({ theme }) => theme.colors.primary600};
|
|
634
|
+
outline-offset: 2px;
|
|
635
|
+
}
|
|
636
|
+
`;
|
|
637
|
+
const selectText = (node) => {
|
|
638
|
+
if (!node || typeof window.getSelection !== "function") return;
|
|
639
|
+
const range = document.createRange();
|
|
640
|
+
range.selectNodeContents(node);
|
|
641
|
+
const selection = window.getSelection();
|
|
642
|
+
selection.removeAllRanges();
|
|
643
|
+
selection.addRange(range);
|
|
644
|
+
node.focus();
|
|
645
|
+
};
|
|
646
|
+
const CspSection = ({ csp }) => {
|
|
647
|
+
const t = useT.useT();
|
|
648
|
+
const { copy } = admin.useClipboard();
|
|
649
|
+
const { toggleNotification } = admin.useNotification();
|
|
650
|
+
const codeRef = react.useRef(null);
|
|
651
|
+
const [alertOpen, setAlertOpen] = react.useState(true);
|
|
652
|
+
const frameMissing = csp && Array.isArray(csp.frameSrcMissing) && csp.frameSrcMissing || [];
|
|
653
|
+
const imgMissing = Boolean(csp && csp.imgSrcMissing);
|
|
654
|
+
if (!csp || !csp.active || !csp.snippet || !frameMissing.length && !imgMissing) return null;
|
|
655
|
+
const onCopy = async () => {
|
|
656
|
+
const ok = await copy(csp.snippet);
|
|
657
|
+
if (ok) {
|
|
658
|
+
toggleNotification({
|
|
659
|
+
type: "success",
|
|
660
|
+
message: t("settings.csp.copied", "Snippet copied to the clipboard.")
|
|
661
|
+
});
|
|
662
|
+
} else {
|
|
663
|
+
selectText(codeRef.current);
|
|
664
|
+
toggleNotification({
|
|
665
|
+
type: "warning",
|
|
666
|
+
message: t(
|
|
667
|
+
"settings.csp.copyFailed",
|
|
668
|
+
"The browser did not allow copying. The snippet is selected; copy it with Ctrl+C or Cmd+C."
|
|
669
|
+
)
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
const allowed = t("settings.csp.allowed", "Allowed");
|
|
674
|
+
const codeLabel = t("settings.csp.codeLabel", "Snippet for config/middlewares.js");
|
|
675
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
676
|
+
useT.SectionCard,
|
|
677
|
+
{
|
|
678
|
+
title: t("settings.csp.title", "Content Security Policy"),
|
|
679
|
+
subtitle: t(
|
|
680
|
+
"settings.csp.subtitle",
|
|
681
|
+
"The admin Content Security Policy is set in config/middlewares.js. The plugin never changes it."
|
|
682
|
+
),
|
|
683
|
+
children: [
|
|
684
|
+
alertOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
685
|
+
designSystem.Alert,
|
|
686
|
+
{
|
|
687
|
+
variant: "warning",
|
|
688
|
+
closeLabel: t("settings.close", "Close"),
|
|
689
|
+
onClose: () => setAlertOpen(false),
|
|
690
|
+
title: t("settings.csp.alertTitle", "Some editor previews are blocked"),
|
|
691
|
+
children: t(
|
|
692
|
+
"settings.csp.alertBody",
|
|
693
|
+
"Your Content Security Policy blocks content the editor shows. Stored content is not affected; editors see a placeholder instead. To allow it, add the sources below to the strapi::security middleware and restart Strapi."
|
|
694
|
+
)
|
|
695
|
+
}
|
|
696
|
+
) : null,
|
|
697
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
698
|
+
PropertyList,
|
|
699
|
+
{
|
|
700
|
+
items: [
|
|
701
|
+
{
|
|
702
|
+
key: "frame",
|
|
703
|
+
label: t("settings.csp.frames", "Embeds (frame-src)"),
|
|
704
|
+
value: frameMissing.length ? t("settings.csp.framesBlocked", "Blocked: {sources}", { sources: frameMissing.join(", ") }) : allowed
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
key: "img",
|
|
708
|
+
label: t("settings.csp.images", "External images (img-src)"),
|
|
709
|
+
value: imgMissing ? t(
|
|
710
|
+
"settings.csp.imagesBlocked",
|
|
711
|
+
"Blocked: images from other hosts (for example link previews)"
|
|
712
|
+
) : allowed,
|
|
713
|
+
hint: imgMissing ? t(
|
|
714
|
+
"settings.csp.imagesHint",
|
|
715
|
+
"The snippet adds https:. You can list your image hosts instead."
|
|
716
|
+
) : void 0
|
|
717
|
+
}
|
|
718
|
+
]
|
|
719
|
+
}
|
|
720
|
+
),
|
|
721
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, minWidth: 0, children: [
|
|
722
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
723
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", id: "mex-csp-snippet-label", children: codeLabel }),
|
|
724
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.IconButton, { label: t("settings.csp.copy", "Copy the snippet"), variant: "tertiary", onClick: onCopy, children: /* @__PURE__ */ jsxRuntime.jsx(icons.Duplicate, {}) })
|
|
725
|
+
] }),
|
|
726
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, { ref: codeRef, tabIndex: 0, "aria-labelledby": "mex-csp-snippet-label", children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: csp.snippet }) }) }),
|
|
727
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t(
|
|
728
|
+
"settings.csp.mergeHint",
|
|
729
|
+
"Keep your other directives (for example the hosts of your upload provider) and restart Strapi after the change."
|
|
730
|
+
) })
|
|
731
|
+
] })
|
|
732
|
+
]
|
|
733
|
+
}
|
|
734
|
+
);
|
|
735
|
+
};
|
|
616
736
|
const RBAC = [...index.PERMISSIONS.settingsRead, ...index.PERMISSIONS.settingsUpdate];
|
|
617
737
|
const testErrorText = (t, code) => {
|
|
618
738
|
switch (code) {
|
|
@@ -755,6 +875,7 @@ const ConfigurationPage = () => {
|
|
|
755
875
|
) : null,
|
|
756
876
|
/* @__PURE__ */ jsxRuntime.jsx(AiSection, { form, readOnly, onTest }),
|
|
757
877
|
/* @__PURE__ */ jsxRuntime.jsx(EnvironmentSection, { environment: form.dto.environment }),
|
|
878
|
+
/* @__PURE__ */ jsxRuntime.jsx(CspSection, { csp: form.dto.environment && form.dto.environment.csp }),
|
|
758
879
|
/* @__PURE__ */ jsxRuntime.jsxs(admin.Form, { method: "PUT", initialValues: form.saved, children: [
|
|
759
880
|
/* @__PURE__ */ jsxRuntime.jsx(DraftSync, { values: form.draft }),
|
|
760
881
|
/* @__PURE__ */ jsxRuntime.jsx(admin.Blocker, {})
|
|
@@ -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-
|
|
10
|
-
const api = require("./api-
|
|
11
|
-
const useT = require("./useT-
|
|
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-
|
|
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-
|
|
8
|
-
import { A as API, r as readApiError } from "./api-
|
|
9
|
-
import { u as useT, C as ConfirmAction, P as PageShell, S as SectionCard, r as refocusIfLost } from "./useT-
|
|
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-
|
|
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();
|