magic-editor-x 1.6.0 → 2.0.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 +268 -0
- package/LICENSE +1 -7
- package/README.md +324 -981
- package/dist/admin/ConfigurationPage-B1uCIE3J.js +767 -0
- package/dist/admin/ConfigurationPage-DvAifELO.mjs +767 -0
- package/dist/admin/CustomBlocksPage-6-OQwpXQ.mjs +1741 -0
- package/dist/admin/CustomBlocksPage-6eWCOreU.js +1743 -0
- package/dist/admin/EditorField-DocyD2Q3.js +5506 -0
- package/dist/admin/EditorField-ThSoOCPm.mjs +5471 -0
- package/dist/admin/api-B-RsxJCs.js +34 -0
- package/dist/admin/api-C4XsDZxd.mjs +35 -0
- package/dist/admin/de-B8XFFhHh.js +95 -0
- package/dist/admin/de-BMxADn2Z.mjs +231 -0
- package/dist/admin/de-DBR893G4.js +13 -0
- package/dist/admin/de-DcDPRzV4.js +155 -0
- package/dist/admin/de-Dx7vUW0Z.js +231 -0
- package/dist/admin/de-RAxzvrwm.mjs +95 -0
- package/dist/admin/de-fBFh09Wl.mjs +13 -0
- package/dist/admin/de-n5V6c5RT.mjs +155 -0
- package/dist/admin/en-BQ5Pxe2o.mjs +231 -0
- package/dist/admin/en-BqNm3nMQ.mjs +155 -0
- package/dist/admin/en-BzfyifEU.mjs +95 -0
- package/dist/admin/en-D-DGftl0.js +155 -0
- package/dist/admin/en-D9Nfccux.mjs +13 -0
- package/dist/admin/en-DcWUTE2J.js +95 -0
- package/dist/admin/en-gueRT44P.js +13 -0
- package/dist/admin/en-sNn4z9lA.js +231 -0
- package/dist/admin/es-B0Zy8DVg.mjs +13 -0
- package/dist/admin/es-B6NYq0VH.mjs +231 -0
- package/dist/admin/es-BOtVc9qv.js +95 -0
- package/dist/admin/es-C2OJVYkV.mjs +95 -0
- package/dist/admin/es-DRGs7meF.js +13 -0
- package/dist/admin/es-DVsXnS0N.js +231 -0
- package/dist/admin/es-Di0pyQCh.js +155 -0
- package/dist/admin/es-SzeTV4q8.mjs +155 -0
- package/dist/admin/fr-B8rdLAIL.js +13 -0
- package/dist/admin/fr-Bpo5Uq1f.mjs +95 -0
- package/dist/admin/fr-D6F--jIB.js +155 -0
- package/dist/admin/fr-DfxKaOc_.js +95 -0
- package/dist/admin/fr-DhgPYHIH.mjs +155 -0
- package/dist/admin/fr-DmG3_Cn-.mjs +231 -0
- package/dist/admin/fr-Fwxcj4SM.js +231 -0
- package/dist/admin/fr-oiUb2bb_.mjs +13 -0
- package/dist/admin/index-CwfaB5-e.js +155 -0
- package/dist/admin/index-D1Q5Rlt6.mjs +156 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/pt-B3Jce6uT.mjs +13 -0
- package/dist/admin/pt-BPo0ex21.js +155 -0
- package/dist/admin/pt-BbdwHlWF.mjs +231 -0
- package/dist/admin/pt-BiWuSBcH.js +13 -0
- package/dist/admin/pt-BvSl1btT.mjs +155 -0
- package/dist/admin/pt-C6nr71Yw.js +231 -0
- package/dist/admin/pt-DqCXuI4S.mjs +95 -0
- package/dist/admin/pt-LCvjwk0y.js +95 -0
- package/dist/admin/sanitize-9UVcXFfc.js +552 -0
- package/dist/admin/sanitize-D4kfZ_ly.mjs +551 -0
- package/dist/admin/useT-B5M49wGH.js +130 -0
- package/dist/admin/useT-CjX6fL2m.mjs +131 -0
- package/dist/server/index.js +4150 -64739
- package/dist/server/index.mjs +4150 -64748
- package/package.json +90 -66
- package/strapi-admin.js +3 -0
- package/strapi-server.js +3 -0
- package/COPYRIGHT_NOTICE.txt +0 -20
- package/dist/admin/App-BwMEZnS-.mjs +0 -2144
- package/dist/admin/App-HNr2tizR.js +0 -2147
- package/dist/admin/CustomBlocksPage-BjcA7MGz.js +0 -1519
- package/dist/admin/CustomBlocksPage-COPOZ2-_.mjs +0 -1517
- package/dist/admin/LicensePage-D0DMTF41.mjs +0 -392
- package/dist/admin/LicensePage-D0_9yPkw.js +0 -394
- package/dist/admin/LiveCollaborationPanel-CZAbgAVr.js +0 -223
- package/dist/admin/LiveCollaborationPanel-D8z72afw.mjs +0 -221
- package/dist/admin/Settings-DRenvRcG.js +0 -441
- package/dist/admin/Settings-DjyNURlS.mjs +0 -439
- package/dist/admin/de-C_0Mj-Zo.mjs +0 -296
- package/dist/admin/de-DVNVpAt9.js +0 -296
- package/dist/admin/en-B7AAf1ie.mjs +0 -296
- package/dist/admin/en-C2hv5GsA.js +0 -296
- package/dist/admin/es-BzJqcIST.js +0 -274
- package/dist/admin/es-zdP8sd-f.mjs +0 -274
- package/dist/admin/fr-CtAgOgH1.mjs +0 -274
- package/dist/admin/fr-D3GwqAAJ.js +0 -274
- package/dist/admin/getTranslation-2OiEgVGt.mjs +0 -49459
- package/dist/admin/getTranslation-DQ_WJ-7M.js +0 -49475
- package/dist/admin/index-Bn2tfJrC.js +0 -2186
- package/dist/admin/index-DAtClhqy.js +0 -6956
- package/dist/admin/index-FVEbTfqO.mjs +0 -2187
- package/dist/admin/index-gjWl-6E2.mjs +0 -6934
- package/dist/admin/magic-editor-x.css +0 -1103
- package/dist/admin/pt-BmUw6YMP.mjs +0 -274
- package/dist/admin/pt-CFo0nTbj.js +0 -274
- package/dist/admin/tools-CzHTZaY_.mjs +0 -2268
- package/dist/admin/tools-DALFhvPO.js +0 -2299
- package/pics/collab-magiceditorX.png +0 -0
- package/pics/editorX.png +0 -0
- package/pics/liveCollabwidget1.png +0 -0
|
@@ -0,0 +1,1743 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const designSystem = require("@strapi/design-system");
|
|
6
|
+
const icons = require("@strapi/icons");
|
|
7
|
+
const symbols = require("@strapi/icons/symbols");
|
|
8
|
+
const admin = require("@strapi/strapi/admin");
|
|
9
|
+
const index = require("./index-CwfaB5-e.js");
|
|
10
|
+
const api = require("./api-B-RsxJCs.js");
|
|
11
|
+
const useT = require("./useT-B5M49wGH.js");
|
|
12
|
+
const styled = require("styled-components");
|
|
13
|
+
const sanitize = require("./sanitize-9UVcXFfc.js");
|
|
14
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
15
|
+
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
16
|
+
const toQuery = (breakpoint) => typeof breakpoint === "string" ? breakpoint.replace(/^\s*@media\s*/i, "").trim() : "";
|
|
17
|
+
const useBreakpoint = () => {
|
|
18
|
+
const theme = styled.useTheme();
|
|
19
|
+
const queries = react.useMemo(
|
|
20
|
+
() => ({
|
|
21
|
+
small: toQuery(theme && theme.breakpoints && theme.breakpoints.small) || "(min-width: 520px)",
|
|
22
|
+
medium: toQuery(theme && theme.breakpoints && theme.breakpoints.medium) || "(min-width: 768px)",
|
|
23
|
+
large: toQuery(theme && theme.breakpoints && theme.breakpoints.large) || "(min-width: 1080px)"
|
|
24
|
+
}),
|
|
25
|
+
[theme]
|
|
26
|
+
);
|
|
27
|
+
const read = react.useMemo(
|
|
28
|
+
() => () => {
|
|
29
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
30
|
+
return { small: true, medium: true, large: true };
|
|
31
|
+
}
|
|
32
|
+
return Object.fromEntries(
|
|
33
|
+
Object.entries(queries).map(([key, query]) => [key, window.matchMedia(query).matches])
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
[queries]
|
|
37
|
+
);
|
|
38
|
+
const [matches, setMatches] = react.useState(read);
|
|
39
|
+
react.useEffect(() => {
|
|
40
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return void 0;
|
|
41
|
+
const lists = Object.values(queries).map((query) => window.matchMedia(query));
|
|
42
|
+
const update = () => setMatches(read());
|
|
43
|
+
update();
|
|
44
|
+
lists.forEach((list) => list.addEventListener("change", update));
|
|
45
|
+
return () => lists.forEach((list) => list.removeEventListener("change", update));
|
|
46
|
+
}, [queries, read]);
|
|
47
|
+
return { isBelowSmall: !matches.small, isBelowMedium: !matches.medium, isBelowLarge: !matches.large };
|
|
48
|
+
};
|
|
49
|
+
const FIELD_TYPES = Object.freeze([
|
|
50
|
+
"text",
|
|
51
|
+
"textarea",
|
|
52
|
+
"url",
|
|
53
|
+
"number",
|
|
54
|
+
"select",
|
|
55
|
+
"checkbox",
|
|
56
|
+
"image",
|
|
57
|
+
"color"
|
|
58
|
+
]);
|
|
59
|
+
const TUNES = Object.freeze(["alignmentTune", "textVariant", "indentTune"]);
|
|
60
|
+
const BLOCK_TYPES = Object.freeze(["simple", "embedded-entry"]);
|
|
61
|
+
const RESERVED_NAMES = Object.freeze(
|
|
62
|
+
[
|
|
63
|
+
"paragraph",
|
|
64
|
+
"header",
|
|
65
|
+
"list",
|
|
66
|
+
"checklist",
|
|
67
|
+
"quote",
|
|
68
|
+
"warning",
|
|
69
|
+
"code",
|
|
70
|
+
"codeFlask",
|
|
71
|
+
"delimiter",
|
|
72
|
+
"table",
|
|
73
|
+
"embed",
|
|
74
|
+
"raw",
|
|
75
|
+
"image",
|
|
76
|
+
"simpleImage",
|
|
77
|
+
"linkTool",
|
|
78
|
+
"attaches",
|
|
79
|
+
"personality",
|
|
80
|
+
"mediaLib",
|
|
81
|
+
"alert",
|
|
82
|
+
"toggle",
|
|
83
|
+
"button",
|
|
84
|
+
"bold",
|
|
85
|
+
"italic",
|
|
86
|
+
"marker",
|
|
87
|
+
"inlineCode",
|
|
88
|
+
"underline",
|
|
89
|
+
"strikethrough",
|
|
90
|
+
"tooltip",
|
|
91
|
+
"hyperlink",
|
|
92
|
+
"aiAssistant",
|
|
93
|
+
"textVariant",
|
|
94
|
+
"alignmentTune",
|
|
95
|
+
"indentTune",
|
|
96
|
+
"embeddedEntry"
|
|
97
|
+
].map((name) => name.toLowerCase())
|
|
98
|
+
);
|
|
99
|
+
const NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]{1,49}$/;
|
|
100
|
+
const FIELD_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]{0,39}$/;
|
|
101
|
+
const SHORTCUT_PATTERN = /^(CMD|CTRL|ALT|SHIFT|OPTION)(\+(CMD|CTRL|ALT|SHIFT|OPTION|[A-Z0-9]))+$/;
|
|
102
|
+
let keySeed = 0;
|
|
103
|
+
const nextKey = () => {
|
|
104
|
+
keySeed += 1;
|
|
105
|
+
return `field-${keySeed}`;
|
|
106
|
+
};
|
|
107
|
+
const deriveName = (label) => {
|
|
108
|
+
const words = String(label || "").normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/[^A-Za-z0-9]+/g, " ").trim().split(" ").filter(Boolean);
|
|
109
|
+
if (!words.length) return "";
|
|
110
|
+
let name = words.map(
|
|
111
|
+
(word, index2) => index2 === 0 ? word.toLowerCase() : word[0].toUpperCase() + word.slice(1).toLowerCase()
|
|
112
|
+
).join("");
|
|
113
|
+
if (!/^[a-zA-Z]/.test(name)) name = `block${name}`;
|
|
114
|
+
if (name.length < 2) name = `${name}Block`;
|
|
115
|
+
return name.slice(0, 50);
|
|
116
|
+
};
|
|
117
|
+
const optionsToText = (options) => (Array.isArray(options) ? options : []).map(
|
|
118
|
+
(option) => typeof option === "string" ? option : option.label && option.label !== option.value ? `${option.value} | ${option.label}` : option.value
|
|
119
|
+
).join("\n");
|
|
120
|
+
const textToOptions = (text) => String(text || "").split("\n").map((line) => line.trim()).filter(Boolean).map((line) => {
|
|
121
|
+
const index2 = line.indexOf("|");
|
|
122
|
+
if (index2 < 0) return line;
|
|
123
|
+
const value = line.slice(0, index2).trim();
|
|
124
|
+
const label = line.slice(index2 + 1).trim();
|
|
125
|
+
return label && label !== value ? { value, label } : value;
|
|
126
|
+
});
|
|
127
|
+
const emptyValues = () => ({
|
|
128
|
+
name: "",
|
|
129
|
+
nameTouched: false,
|
|
130
|
+
label: "",
|
|
131
|
+
blockType: "simple",
|
|
132
|
+
description: "",
|
|
133
|
+
icon: "",
|
|
134
|
+
contentType: "",
|
|
135
|
+
titleField: "",
|
|
136
|
+
displayFields: [],
|
|
137
|
+
previewFields: [],
|
|
138
|
+
fields: [],
|
|
139
|
+
template: "",
|
|
140
|
+
placeholder: "",
|
|
141
|
+
inlineToolbar: true,
|
|
142
|
+
tunes: [],
|
|
143
|
+
shortcut: "",
|
|
144
|
+
enabled: true,
|
|
145
|
+
sortOrder: null
|
|
146
|
+
});
|
|
147
|
+
const emptyField = (index2 = 0) => ({
|
|
148
|
+
key: nextKey(),
|
|
149
|
+
name: `field${index2 + 1}`,
|
|
150
|
+
label: "",
|
|
151
|
+
type: "text",
|
|
152
|
+
required: false,
|
|
153
|
+
placeholder: "",
|
|
154
|
+
default: "",
|
|
155
|
+
optionsText: ""
|
|
156
|
+
});
|
|
157
|
+
const fromDto = (dto) => ({
|
|
158
|
+
...emptyValues(),
|
|
159
|
+
name: dto.name || "",
|
|
160
|
+
nameTouched: true,
|
|
161
|
+
label: dto.label || "",
|
|
162
|
+
blockType: BLOCK_TYPES.includes(dto.blockType) ? dto.blockType : "simple",
|
|
163
|
+
description: dto.description || "",
|
|
164
|
+
icon: dto.icon || "",
|
|
165
|
+
contentType: dto.contentType || "",
|
|
166
|
+
titleField: dto.titleField || "",
|
|
167
|
+
displayFields: Array.isArray(dto.displayFields) ? dto.displayFields : [],
|
|
168
|
+
previewFields: Array.isArray(dto.previewFields) ? dto.previewFields : [],
|
|
169
|
+
fields: (Array.isArray(dto.fields) ? dto.fields : []).map((field) => ({
|
|
170
|
+
key: nextKey(),
|
|
171
|
+
name: field.name || "",
|
|
172
|
+
label: field.label || "",
|
|
173
|
+
type: FIELD_TYPES.includes(field.type) ? field.type : "text",
|
|
174
|
+
required: Boolean(field.required),
|
|
175
|
+
placeholder: field.placeholder || "",
|
|
176
|
+
default: field.default === void 0 || field.default === null ? "" : field.default,
|
|
177
|
+
optionsText: optionsToText(field.options)
|
|
178
|
+
})),
|
|
179
|
+
template: dto.template || "",
|
|
180
|
+
placeholder: dto.placeholder || "",
|
|
181
|
+
inlineToolbar: dto.inlineToolbar !== false,
|
|
182
|
+
tunes: Array.isArray(dto.tunes) ? dto.tunes.filter((tune) => TUNES.includes(tune)) : [],
|
|
183
|
+
shortcut: dto.shortcut || "",
|
|
184
|
+
enabled: dto.enabled !== false,
|
|
185
|
+
sortOrder: Number.isInteger(dto.sortOrder) ? dto.sortOrder : null
|
|
186
|
+
});
|
|
187
|
+
const toPayload = (values) => {
|
|
188
|
+
const simple = values.blockType === "simple";
|
|
189
|
+
const optional = (value) => {
|
|
190
|
+
const text = String(value || "").trim();
|
|
191
|
+
return text ? text : null;
|
|
192
|
+
};
|
|
193
|
+
const payload = {
|
|
194
|
+
name: String(values.name || "").trim(),
|
|
195
|
+
label: String(values.label || "").trim(),
|
|
196
|
+
blockType: values.blockType,
|
|
197
|
+
description: optional(values.description),
|
|
198
|
+
icon: optional(values.icon),
|
|
199
|
+
contentType: simple ? null : optional(values.contentType),
|
|
200
|
+
titleField: simple ? null : optional(values.titleField),
|
|
201
|
+
displayFields: simple ? [] : values.displayFields,
|
|
202
|
+
previewFields: simple ? [] : values.previewFields,
|
|
203
|
+
fields: simple ? values.fields.map((field) => {
|
|
204
|
+
const out = {
|
|
205
|
+
name: String(field.name || "").trim(),
|
|
206
|
+
label: String(field.label || "").trim(),
|
|
207
|
+
type: field.type
|
|
208
|
+
};
|
|
209
|
+
if (field.required) out.required = true;
|
|
210
|
+
if (String(field.placeholder || "").trim()) out.placeholder = String(field.placeholder).trim();
|
|
211
|
+
if (field.type === "checkbox") {
|
|
212
|
+
if (field.default === true || field.default === "true") out.default = true;
|
|
213
|
+
} else if (field.type === "number") {
|
|
214
|
+
if (field.default !== "" && field.default !== null && Number.isFinite(Number(field.default)))
|
|
215
|
+
out.default = Number(field.default);
|
|
216
|
+
} else if (String(field.default ?? "") !== "") out.default = String(field.default);
|
|
217
|
+
if (field.type === "select") out.options = textToOptions(field.optionsText);
|
|
218
|
+
return out;
|
|
219
|
+
}) : [],
|
|
220
|
+
template: simple ? optional(values.template) : null,
|
|
221
|
+
placeholder: optional(values.placeholder),
|
|
222
|
+
inlineToolbar: Boolean(values.inlineToolbar),
|
|
223
|
+
tunes: values.tunes.filter((tune) => TUNES.includes(tune)),
|
|
224
|
+
shortcut: optional(values.shortcut ? String(values.shortcut).toUpperCase().replace(/\s+/g, "") : ""),
|
|
225
|
+
enabled: Boolean(values.enabled)
|
|
226
|
+
};
|
|
227
|
+
if (Number.isInteger(values.sortOrder)) payload.sortOrder = values.sortOrder;
|
|
228
|
+
return payload;
|
|
229
|
+
};
|
|
230
|
+
const validateBlock = (values, context = {}) => {
|
|
231
|
+
const errors = {};
|
|
232
|
+
const name = String(values.name || "").trim();
|
|
233
|
+
if (!name) errors.name = "required";
|
|
234
|
+
else if (!NAME_PATTERN.test(name)) errors.name = "namePattern";
|
|
235
|
+
else if (RESERVED_NAMES.includes(name.toLowerCase())) errors.name = "reserved";
|
|
236
|
+
else if ((context.existingNames || []).some((other) => other.toLowerCase() === name.toLowerCase()))
|
|
237
|
+
errors.name = "taken";
|
|
238
|
+
const label = String(values.label || "").trim();
|
|
239
|
+
if (!label) errors.label = "required";
|
|
240
|
+
else if (label.length > 100) errors.label = "tooLong";
|
|
241
|
+
if (!BLOCK_TYPES.includes(values.blockType)) errors.blockType = "required";
|
|
242
|
+
if (String(values.description || "").length > 1e3) errors.description = "tooLong";
|
|
243
|
+
if (String(values.icon || "").length > 1e4) errors.icon = "tooLong";
|
|
244
|
+
if (String(values.placeholder || "").length > 200) errors.placeholder = "tooLong";
|
|
245
|
+
const shortcut = String(values.shortcut || "").toUpperCase().replace(/\s+/g, "");
|
|
246
|
+
if (shortcut && !SHORTCUT_PATTERN.test(shortcut)) errors.shortcut = "shortcut";
|
|
247
|
+
if (values.blockType === "simple") {
|
|
248
|
+
if (String(values.template || "").length > 2e4) errors.template = "tooLong";
|
|
249
|
+
if (values.fields.length > 20) errors.fields = "tooMany";
|
|
250
|
+
const seen = /* @__PURE__ */ new Set();
|
|
251
|
+
values.fields.forEach((field, index2) => {
|
|
252
|
+
const fieldName = String(field.name || "").trim();
|
|
253
|
+
if (!fieldName) errors[`fields.${index2}.name`] = "required";
|
|
254
|
+
else if (!FIELD_NAME_PATTERN.test(fieldName)) errors[`fields.${index2}.name`] = "fieldName";
|
|
255
|
+
else if (seen.has(fieldName)) errors[`fields.${index2}.name`] = "duplicate";
|
|
256
|
+
seen.add(fieldName);
|
|
257
|
+
const fieldLabel = String(field.label || "").trim();
|
|
258
|
+
if (!fieldLabel) errors[`fields.${index2}.label`] = "required";
|
|
259
|
+
else if (fieldLabel.length > 100) errors[`fields.${index2}.label`] = "tooLong";
|
|
260
|
+
if (String(field.placeholder || "").length > 200) errors[`fields.${index2}.placeholder`] = "tooLong";
|
|
261
|
+
if (String(field.default ?? "").length > 2e3) errors[`fields.${index2}.default`] = "tooLong";
|
|
262
|
+
if (field.type === "number" && field.default !== "" && field.default !== null && !Number.isFinite(Number(field.default))) {
|
|
263
|
+
errors[`fields.${index2}.default`] = "number";
|
|
264
|
+
}
|
|
265
|
+
if (field.type === "select") {
|
|
266
|
+
const options = textToOptions(field.optionsText);
|
|
267
|
+
if (!options.length) errors[`fields.${index2}.options`] = "options";
|
|
268
|
+
else if (options.length > 50) errors[`fields.${index2}.options`] = "tooMany";
|
|
269
|
+
else if (options.some(
|
|
270
|
+
(option) => (typeof option === "string" ? option : option.value).length > 100 || typeof option === "object" && option.label.length > 100
|
|
271
|
+
)) {
|
|
272
|
+
errors[`fields.${index2}.options`] = "tooLong";
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
if (values.titleField && !FIELD_NAME_PATTERN.test(values.titleField)) errors.titleField = "fieldName";
|
|
278
|
+
if (values.displayFields.length > 20) errors.displayFields = "tooMany";
|
|
279
|
+
if (values.previewFields.length > 20) errors.previewFields = "tooMany";
|
|
280
|
+
}
|
|
281
|
+
return errors;
|
|
282
|
+
};
|
|
283
|
+
const mapServerErrors = (details) => {
|
|
284
|
+
const out = {};
|
|
285
|
+
const fieldErrors = details && typeof details === "object" ? details.fieldErrors || {} : {};
|
|
286
|
+
for (const [key, messages] of Object.entries(fieldErrors)) {
|
|
287
|
+
const message = Array.isArray(messages) ? messages[0] : String(messages || "");
|
|
288
|
+
if (message) out[key] = { server: message };
|
|
289
|
+
}
|
|
290
|
+
const formErrors = details && Array.isArray(details.formErrors) ? details.formErrors : [];
|
|
291
|
+
if (formErrors[0]) out._form = { server: formErrors[0] };
|
|
292
|
+
return out;
|
|
293
|
+
};
|
|
294
|
+
const withEnabled = (dto, enabled) => ({ ...toPayload(fromDto(dto)), enabled });
|
|
295
|
+
const moveId = (ids, id, direction) => {
|
|
296
|
+
const index2 = ids.indexOf(id);
|
|
297
|
+
const target = index2 + direction;
|
|
298
|
+
if (index2 < 0 || target < 0 || target >= ids.length) return null;
|
|
299
|
+
const next = ids.slice();
|
|
300
|
+
[next[index2], next[target]] = [next[target], next[index2]];
|
|
301
|
+
return next;
|
|
302
|
+
};
|
|
303
|
+
const fillTemplate = (template, fields) => {
|
|
304
|
+
const escape = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
305
|
+
const values = new Map(
|
|
306
|
+
fields.map((field) => [
|
|
307
|
+
String(field.name),
|
|
308
|
+
String(field.default ?? "") || String(field.label || field.name)
|
|
309
|
+
])
|
|
310
|
+
);
|
|
311
|
+
values.set("content", "Content");
|
|
312
|
+
return String(template || "").replace(
|
|
313
|
+
/\{\{\s*([A-Za-z][A-Za-z0-9_]{0,39})\s*\}\}/g,
|
|
314
|
+
(match, key) => values.has(key) ? escape(values.get(key)) : match
|
|
315
|
+
);
|
|
316
|
+
};
|
|
317
|
+
const useCustomBlocks = () => {
|
|
318
|
+
const { get } = admin.useFetchClient();
|
|
319
|
+
const [status, setStatus] = react.useState("loading");
|
|
320
|
+
const [blocks, setBlocks] = react.useState([]);
|
|
321
|
+
const [refreshError, setRefreshError] = react.useState(false);
|
|
322
|
+
const [contentTypes, setContentTypes] = react.useState({ status: "loading", items: [] });
|
|
323
|
+
const mounted = react.useRef(true);
|
|
324
|
+
const loaded = react.useRef(false);
|
|
325
|
+
react.useEffect(() => {
|
|
326
|
+
mounted.current = true;
|
|
327
|
+
return () => {
|
|
328
|
+
mounted.current = false;
|
|
329
|
+
};
|
|
330
|
+
}, []);
|
|
331
|
+
const fetchBlocks = react.useCallback(
|
|
332
|
+
() => get(api.API.customBlocks, { params: { all: "true" } }).then(
|
|
333
|
+
({ data }) => {
|
|
334
|
+
if (!mounted.current) return;
|
|
335
|
+
setBlocks(Array.isArray(data.data) ? data.data : []);
|
|
336
|
+
setRefreshError(false);
|
|
337
|
+
loaded.current = true;
|
|
338
|
+
setStatus("ready");
|
|
339
|
+
},
|
|
340
|
+
() => {
|
|
341
|
+
if (!mounted.current) return;
|
|
342
|
+
if (loaded.current) setRefreshError(true);
|
|
343
|
+
else setStatus("error");
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
[get]
|
|
347
|
+
);
|
|
348
|
+
const fetchContentTypes = react.useCallback(
|
|
349
|
+
() => get(api.API.contentTypes).then(
|
|
350
|
+
({ data }) => {
|
|
351
|
+
if (mounted.current)
|
|
352
|
+
setContentTypes({ status: "ready", items: Array.isArray(data.data) ? data.data : [] });
|
|
353
|
+
},
|
|
354
|
+
() => {
|
|
355
|
+
if (mounted.current) setContentTypes({ status: "error", items: [] });
|
|
356
|
+
}
|
|
357
|
+
),
|
|
358
|
+
[get]
|
|
359
|
+
);
|
|
360
|
+
react.useEffect(() => {
|
|
361
|
+
fetchBlocks();
|
|
362
|
+
fetchContentTypes();
|
|
363
|
+
}, [fetchBlocks, fetchContentTypes]);
|
|
364
|
+
const load = react.useCallback(() => {
|
|
365
|
+
if (!loaded.current) setStatus("loading");
|
|
366
|
+
return fetchBlocks();
|
|
367
|
+
}, [fetchBlocks]);
|
|
368
|
+
const loadContentTypes = react.useCallback(() => {
|
|
369
|
+
setContentTypes((current) => ({ ...current, status: "loading" }));
|
|
370
|
+
return fetchContentTypes();
|
|
371
|
+
}, [fetchContentTypes]);
|
|
372
|
+
return {
|
|
373
|
+
status,
|
|
374
|
+
blocks,
|
|
375
|
+
setBlocks,
|
|
376
|
+
refreshError,
|
|
377
|
+
reload: load,
|
|
378
|
+
contentTypes,
|
|
379
|
+
reloadContentTypes: loadContentTypes
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
const blockErrorText = (t, error) => {
|
|
383
|
+
if (!error) return void 0;
|
|
384
|
+
if (typeof error === "object") return error.server;
|
|
385
|
+
switch (error) {
|
|
386
|
+
case "required":
|
|
387
|
+
return t("settings.validation.required", "This field is required.");
|
|
388
|
+
case "namePattern":
|
|
389
|
+
return t(
|
|
390
|
+
"settings.blocks.validation.name",
|
|
391
|
+
"Start with a letter; use 2 to 50 letters, digits, - or _."
|
|
392
|
+
);
|
|
393
|
+
case "reserved":
|
|
394
|
+
return t(
|
|
395
|
+
"settings.blocks.validation.reserved",
|
|
396
|
+
"This name is used by a built-in tool. Choose another one."
|
|
397
|
+
);
|
|
398
|
+
case "taken":
|
|
399
|
+
return t("settings.blocks.validation.taken", "Another block already uses this name.");
|
|
400
|
+
case "fieldName":
|
|
401
|
+
return t(
|
|
402
|
+
"settings.blocks.validation.fieldName",
|
|
403
|
+
"Start with a letter; use up to 40 letters, digits or _."
|
|
404
|
+
);
|
|
405
|
+
case "duplicate":
|
|
406
|
+
return t("settings.blocks.validation.duplicate", "Field names must be unique.");
|
|
407
|
+
case "options":
|
|
408
|
+
return t("settings.blocks.validation.options", "A select field needs at least one option.");
|
|
409
|
+
case "number":
|
|
410
|
+
return t("settings.blocks.validation.number", "Enter a number.");
|
|
411
|
+
case "shortcut":
|
|
412
|
+
return t("settings.blocks.validation.shortcut", "Use a combination such as CMD+SHIFT+K.");
|
|
413
|
+
case "tooMany":
|
|
414
|
+
return t("settings.blocks.validation.tooMany", "Too many entries.");
|
|
415
|
+
case "tooLong":
|
|
416
|
+
return t("settings.blocks.validation.tooLong", "This text is too long.");
|
|
417
|
+
default:
|
|
418
|
+
return t("settings.validation.invalid", "Check this value.");
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const fieldTypeLabel = (t, type) => ({
|
|
422
|
+
text: t("settings.blocks.fieldType.text", "Text"),
|
|
423
|
+
textarea: t("settings.blocks.fieldType.textarea", "Long text"),
|
|
424
|
+
url: t("settings.blocks.fieldType.url", "Link (URL)"),
|
|
425
|
+
number: t("settings.blocks.fieldType.number", "Number"),
|
|
426
|
+
select: t("settings.blocks.fieldType.select", "Choice list"),
|
|
427
|
+
checkbox: t("settings.blocks.fieldType.checkbox", "Checkbox"),
|
|
428
|
+
image: t("settings.blocks.fieldType.image", "Image (Media Library)"),
|
|
429
|
+
color: t("settings.blocks.fieldType.color", "Colour")
|
|
430
|
+
})[type] || type;
|
|
431
|
+
const blockTypeLabel = (t, type) => type === "embedded-entry" ? t("settings.blocks.type.embedded", "Embedded entry") : t("settings.blocks.type.simple", "Simple block");
|
|
432
|
+
const IconFrame = styled__default.default.span`
|
|
433
|
+
display: inline-flex;
|
|
434
|
+
align-items: center;
|
|
435
|
+
justify-content: center;
|
|
436
|
+
width: 3.2rem;
|
|
437
|
+
height: 3.2rem;
|
|
438
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
439
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
440
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
441
|
+
background: ${({ theme }) => theme.colors.neutral0};
|
|
442
|
+
|
|
443
|
+
svg {
|
|
444
|
+
width: 2rem;
|
|
445
|
+
height: 2rem;
|
|
446
|
+
}
|
|
447
|
+
`;
|
|
448
|
+
const TemplateFrame = styled__default.default(designSystem.Box)`
|
|
449
|
+
overflow-wrap: anywhere;
|
|
450
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
451
|
+
font-size: ${({ theme }) => theme.fontSizes[2]};
|
|
452
|
+
|
|
453
|
+
img {
|
|
454
|
+
max-width: 100%;
|
|
455
|
+
height: auto;
|
|
456
|
+
}
|
|
457
|
+
`;
|
|
458
|
+
const IconPreview = ({ svg, label }) => {
|
|
459
|
+
const clean = react.useMemo(() => sanitize.sanitizeSvg(svg), [svg]);
|
|
460
|
+
return /* @__PURE__ */ jsxRuntime.jsx(IconFrame, { role: "img", "aria-label": label, dangerouslySetInnerHTML: { __html: clean } });
|
|
461
|
+
};
|
|
462
|
+
const TemplatePreview = ({ template, fields, label, empty }) => {
|
|
463
|
+
const clean = react.useMemo(() => sanitize.sanitizeTemplate(fillTemplate(template, fields)), [template, fields]);
|
|
464
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
465
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "p", children: label }),
|
|
466
|
+
/* @__PURE__ */ jsxRuntime.jsx(TemplateFrame, { marginTop: 2, padding: 4, hasRadius: true, borderColor: "neutral200", background: "neutral100", children: clean ? (
|
|
467
|
+
// sanitised template HTML from sanitizeTemplate (DOMPurify)
|
|
468
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: clean } })
|
|
469
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: empty }) })
|
|
470
|
+
] });
|
|
471
|
+
};
|
|
472
|
+
const RowActions = ({
|
|
473
|
+
block,
|
|
474
|
+
index: index2,
|
|
475
|
+
count,
|
|
476
|
+
busy,
|
|
477
|
+
onEdit,
|
|
478
|
+
onDuplicate,
|
|
479
|
+
onMove,
|
|
480
|
+
onDelete,
|
|
481
|
+
fallbackFocusRef
|
|
482
|
+
}) => {
|
|
483
|
+
const t = useT.useT();
|
|
484
|
+
const label = block.label || block.name;
|
|
485
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, wrap: "wrap", children: [
|
|
486
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
487
|
+
designSystem.IconButton,
|
|
488
|
+
{
|
|
489
|
+
label: t("settings.blocks.action.edit", "Edit {label}", { label }),
|
|
490
|
+
variant: "ghost",
|
|
491
|
+
onClick: () => onEdit(block),
|
|
492
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {})
|
|
493
|
+
}
|
|
494
|
+
),
|
|
495
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
496
|
+
designSystem.IconButton,
|
|
497
|
+
{
|
|
498
|
+
label: t("settings.blocks.action.duplicate", "Duplicate {label}", { label }),
|
|
499
|
+
variant: "ghost",
|
|
500
|
+
disabled: busy,
|
|
501
|
+
onClick: () => onDuplicate(block),
|
|
502
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Duplicate, {})
|
|
503
|
+
}
|
|
504
|
+
),
|
|
505
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
506
|
+
designSystem.IconButton,
|
|
507
|
+
{
|
|
508
|
+
label: t("settings.blocks.action.moveUp", "Move {label} up", { label }),
|
|
509
|
+
variant: "ghost",
|
|
510
|
+
disabled: busy || index2 === 0,
|
|
511
|
+
onClick: () => onMove(block, -1),
|
|
512
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUp, {})
|
|
513
|
+
}
|
|
514
|
+
),
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
516
|
+
designSystem.IconButton,
|
|
517
|
+
{
|
|
518
|
+
label: t("settings.blocks.action.moveDown", "Move {label} down", { label }),
|
|
519
|
+
variant: "ghost",
|
|
520
|
+
disabled: busy || index2 === count - 1,
|
|
521
|
+
onClick: () => onMove(block, 1),
|
|
522
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDown, {})
|
|
523
|
+
}
|
|
524
|
+
),
|
|
525
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
526
|
+
useT.ConfirmAction,
|
|
527
|
+
{
|
|
528
|
+
fallbackFocusRef,
|
|
529
|
+
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
530
|
+
designSystem.IconButton,
|
|
531
|
+
{
|
|
532
|
+
label: t("settings.blocks.action.delete", "Delete {label}", { label }),
|
|
533
|
+
variant: "ghost",
|
|
534
|
+
disabled: busy,
|
|
535
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
|
|
536
|
+
}
|
|
537
|
+
),
|
|
538
|
+
title: t("settings.blocks.delete.title", "Delete the block {label}?", { label }),
|
|
539
|
+
body: t(
|
|
540
|
+
"settings.blocks.delete.body",
|
|
541
|
+
"The block disappears from the editor toolbox. Content that already uses it keeps its data, but the editor shows it as unavailable until a block named {name} exists again. This cannot be undone.",
|
|
542
|
+
{ name: block.name }
|
|
543
|
+
),
|
|
544
|
+
confirmLabel: t("settings.blocks.delete.confirm", "Delete block"),
|
|
545
|
+
onConfirm: () => onDelete(block)
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
] });
|
|
549
|
+
};
|
|
550
|
+
const EnabledSwitch = ({ block, busy, onToggle }) => {
|
|
551
|
+
const t = useT.useT();
|
|
552
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
553
|
+
designSystem.Switch,
|
|
554
|
+
{
|
|
555
|
+
checked: block.enabled,
|
|
556
|
+
disabled: busy,
|
|
557
|
+
onCheckedChange: (checked) => onToggle(block, checked === true),
|
|
558
|
+
"aria-label": t("settings.blocks.action.toggle", "Show {label} in the editor toolbox", {
|
|
559
|
+
label: block.label || block.name
|
|
560
|
+
}),
|
|
561
|
+
onLabel: t("settings.switch.on", "On"),
|
|
562
|
+
offLabel: t("settings.switch.off", "Off"),
|
|
563
|
+
visibleLabels: true
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
};
|
|
567
|
+
const Identity = ({ block }) => {
|
|
568
|
+
const t = useT.useT();
|
|
569
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "center", minWidth: 0, children: [
|
|
570
|
+
block.icon ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
571
|
+
IconPreview,
|
|
572
|
+
{
|
|
573
|
+
svg: block.icon,
|
|
574
|
+
label: t("settings.blocks.list.icon", "Icon of {label}", { label: block.label })
|
|
575
|
+
}
|
|
576
|
+
) : null,
|
|
577
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
578
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
579
|
+
designSystem.Typography,
|
|
580
|
+
{
|
|
581
|
+
variant: "omega",
|
|
582
|
+
fontWeight: "bold",
|
|
583
|
+
textColor: "neutral800",
|
|
584
|
+
style: { overflowWrap: "anywhere" },
|
|
585
|
+
children: block.label
|
|
586
|
+
}
|
|
587
|
+
),
|
|
588
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: block.name })
|
|
589
|
+
] })
|
|
590
|
+
] });
|
|
591
|
+
};
|
|
592
|
+
const BlockList = ({
|
|
593
|
+
blocks,
|
|
594
|
+
busyId,
|
|
595
|
+
onEdit,
|
|
596
|
+
onDuplicate,
|
|
597
|
+
onMove,
|
|
598
|
+
onDelete,
|
|
599
|
+
onToggle,
|
|
600
|
+
fallbackFocusRef
|
|
601
|
+
}) => {
|
|
602
|
+
const t = useT.useT();
|
|
603
|
+
const { isBelowLarge } = useBreakpoint();
|
|
604
|
+
const actions = { onEdit, onDuplicate, onMove, onDelete, fallbackFocusRef };
|
|
605
|
+
if (isBelowLarge) {
|
|
606
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
607
|
+
designSystem.Flex,
|
|
608
|
+
{
|
|
609
|
+
tag: "ul",
|
|
610
|
+
direction: "column",
|
|
611
|
+
alignItems: "stretch",
|
|
612
|
+
gap: 3,
|
|
613
|
+
"aria-label": t("settings.blocks.list.label", "Custom blocks"),
|
|
614
|
+
children: blocks.map((block, index2) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
615
|
+
designSystem.Box,
|
|
616
|
+
{
|
|
617
|
+
tag: "li",
|
|
618
|
+
background: "neutral0",
|
|
619
|
+
hasRadius: true,
|
|
620
|
+
shadow: "tableShadow",
|
|
621
|
+
padding: 4,
|
|
622
|
+
minWidth: 0,
|
|
623
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
624
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 3, children: [
|
|
625
|
+
/* @__PURE__ */ jsxRuntime.jsx(Identity, { block }),
|
|
626
|
+
/* @__PURE__ */ jsxRuntime.jsx(EnabledSwitch, { block, busy: busyId === block.id, onToggle })
|
|
627
|
+
] }),
|
|
628
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, wrap: "wrap", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { children: blockTypeLabel(t, block.blockType) }) }),
|
|
629
|
+
block.description ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: block.description }) : null,
|
|
630
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
631
|
+
RowActions,
|
|
632
|
+
{
|
|
633
|
+
block,
|
|
634
|
+
index: index2,
|
|
635
|
+
count: blocks.length,
|
|
636
|
+
busy: busyId === block.id,
|
|
637
|
+
...actions
|
|
638
|
+
}
|
|
639
|
+
)
|
|
640
|
+
] })
|
|
641
|
+
},
|
|
642
|
+
block.id
|
|
643
|
+
))
|
|
644
|
+
}
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 5, rowCount: blocks.length + 1, children: [
|
|
648
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
|
|
649
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: t("settings.blocks.list.block", "Block") }) }),
|
|
650
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: t("settings.blocks.list.type", "Type") }) }),
|
|
651
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: t("settings.blocks.list.description", "Description") }) }),
|
|
652
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: t("settings.blocks.list.enabled", "In toolbox") }) }),
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: t("settings.blocks.list.actions", "Actions") }) })
|
|
654
|
+
] }) }),
|
|
655
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: blocks.map((block, index2) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
|
|
656
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(Identity, { block }) }),
|
|
657
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { children: blockTypeLabel(t, block.blockType) }) }),
|
|
658
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
659
|
+
designSystem.Typography,
|
|
660
|
+
{
|
|
661
|
+
textColor: block.description ? "neutral800" : "neutral600",
|
|
662
|
+
style: { overflowWrap: "anywhere" },
|
|
663
|
+
children: block.description || t("settings.blocks.list.noDescription", "No description")
|
|
664
|
+
}
|
|
665
|
+
) }),
|
|
666
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(EnabledSwitch, { block, busy: busyId === block.id, onToggle }) }),
|
|
667
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
668
|
+
RowActions,
|
|
669
|
+
{
|
|
670
|
+
block,
|
|
671
|
+
index: index2,
|
|
672
|
+
count: blocks.length,
|
|
673
|
+
busy: busyId === block.id,
|
|
674
|
+
...actions
|
|
675
|
+
}
|
|
676
|
+
) }) })
|
|
677
|
+
] }, block.id)) })
|
|
678
|
+
] });
|
|
679
|
+
};
|
|
680
|
+
const FieldsEditor = ({ fields, onChange, errors }) => {
|
|
681
|
+
const t = useT.useT();
|
|
682
|
+
const update = (index2, patch) => onChange(fields.map((field, i) => i === index2 ? { ...field, ...patch } : field));
|
|
683
|
+
const move = (index2, direction) => {
|
|
684
|
+
const target = index2 + direction;
|
|
685
|
+
if (target < 0 || target >= fields.length) return;
|
|
686
|
+
const next = fields.slice();
|
|
687
|
+
[next[index2], next[target]] = [next[target], next[index2]];
|
|
688
|
+
onChange(next);
|
|
689
|
+
};
|
|
690
|
+
const err = (path) => blockErrorText(t, errors[path]);
|
|
691
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
692
|
+
fields.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t(
|
|
693
|
+
"settings.blocks.fields.empty",
|
|
694
|
+
"No fields yet. Without fields the block has one text area named content."
|
|
695
|
+
) }) : null,
|
|
696
|
+
fields.map((field, index2) => {
|
|
697
|
+
const name = field.label || field.name || t("settings.blocks.fields.unnamed", "Field {number}", { number: index2 + 1 });
|
|
698
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
699
|
+
designSystem.Box,
|
|
700
|
+
{
|
|
701
|
+
padding: 4,
|
|
702
|
+
hasRadius: true,
|
|
703
|
+
borderColor: "neutral200",
|
|
704
|
+
background: "neutral100",
|
|
705
|
+
minWidth: 0,
|
|
706
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
707
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
708
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "bold", tag: "h4", textColor: "neutral800", children: t("settings.blocks.fields.heading", "Field {number}", { number: index2 + 1 }) }),
|
|
709
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, children: [
|
|
710
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
711
|
+
designSystem.IconButton,
|
|
712
|
+
{
|
|
713
|
+
label: t("settings.blocks.fields.moveUp", "Move field {name} up", { name }),
|
|
714
|
+
variant: "ghost",
|
|
715
|
+
disabled: index2 === 0,
|
|
716
|
+
onClick: () => move(index2, -1),
|
|
717
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUp, {})
|
|
718
|
+
}
|
|
719
|
+
),
|
|
720
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
721
|
+
designSystem.IconButton,
|
|
722
|
+
{
|
|
723
|
+
label: t("settings.blocks.fields.moveDown", "Move field {name} down", { name }),
|
|
724
|
+
variant: "ghost",
|
|
725
|
+
disabled: index2 === fields.length - 1,
|
|
726
|
+
onClick: () => move(index2, 1),
|
|
727
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDown, {})
|
|
728
|
+
}
|
|
729
|
+
),
|
|
730
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
731
|
+
designSystem.IconButton,
|
|
732
|
+
{
|
|
733
|
+
label: t("settings.blocks.fields.remove", "Remove field {name}", { name }),
|
|
734
|
+
variant: "ghost",
|
|
735
|
+
onClick: () => onChange(fields.filter((_, i) => i !== index2)),
|
|
736
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
] })
|
|
740
|
+
] }),
|
|
741
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, children: [
|
|
742
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `fields.${index2}.label`, error: err(`fields.${index2}.label`), required: true, children: [
|
|
743
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.label", "Label") }),
|
|
744
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
745
|
+
designSystem.TextInput,
|
|
746
|
+
{
|
|
747
|
+
value: field.label,
|
|
748
|
+
onChange: (event) => update(index2, { label: event.target.value })
|
|
749
|
+
}
|
|
750
|
+
),
|
|
751
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
752
|
+
] }) }),
|
|
753
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
754
|
+
designSystem.Field.Root,
|
|
755
|
+
{
|
|
756
|
+
name: `fields.${index2}.name`,
|
|
757
|
+
error: err(`fields.${index2}.name`),
|
|
758
|
+
hint: t("settings.blocks.fields.nameHint", "Stored data key and template placeholder."),
|
|
759
|
+
required: true,
|
|
760
|
+
children: [
|
|
761
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.name", "Key") }),
|
|
762
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
763
|
+
designSystem.TextInput,
|
|
764
|
+
{
|
|
765
|
+
value: field.name,
|
|
766
|
+
onChange: (event) => update(index2, { name: event.target.value })
|
|
767
|
+
}
|
|
768
|
+
),
|
|
769
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
770
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
771
|
+
]
|
|
772
|
+
}
|
|
773
|
+
) }),
|
|
774
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `fields.${index2}.type`, children: [
|
|
775
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.type", "Type") }),
|
|
776
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
777
|
+
designSystem.SingleSelect,
|
|
778
|
+
{
|
|
779
|
+
value: field.type,
|
|
780
|
+
onChange: (value) => update(index2, { type: String(value), default: "" }),
|
|
781
|
+
children: FIELD_TYPES.map((type) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: type, children: fieldTypeLabel(t, type) }, type))
|
|
782
|
+
}
|
|
783
|
+
)
|
|
784
|
+
] }) }),
|
|
785
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `fields.${index2}.placeholder`, error: err(`fields.${index2}.placeholder`), children: [
|
|
786
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.placeholder", "Placeholder") }),
|
|
787
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
788
|
+
designSystem.TextInput,
|
|
789
|
+
{
|
|
790
|
+
value: field.placeholder,
|
|
791
|
+
disabled: ["checkbox", "image", "select", "color"].includes(field.type),
|
|
792
|
+
onChange: (event) => update(index2, { placeholder: event.target.value })
|
|
793
|
+
}
|
|
794
|
+
),
|
|
795
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
796
|
+
] }) }),
|
|
797
|
+
field.type === "select" ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 12, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
798
|
+
designSystem.Field.Root,
|
|
799
|
+
{
|
|
800
|
+
name: `fields.${index2}.options`,
|
|
801
|
+
error: err(`fields.${index2}.options`),
|
|
802
|
+
hint: t(
|
|
803
|
+
"settings.blocks.fields.optionsHint",
|
|
804
|
+
'One option per line. Use "value | label" when the label differs.'
|
|
805
|
+
),
|
|
806
|
+
required: true,
|
|
807
|
+
children: [
|
|
808
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.options", "Options") }),
|
|
809
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
810
|
+
designSystem.Textarea,
|
|
811
|
+
{
|
|
812
|
+
value: field.optionsText,
|
|
813
|
+
onChange: (event) => update(index2, { optionsText: event.target.value })
|
|
814
|
+
}
|
|
815
|
+
),
|
|
816
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
817
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
818
|
+
]
|
|
819
|
+
}
|
|
820
|
+
) }) : null,
|
|
821
|
+
field.type !== "image" && field.type !== "checkbox" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
822
|
+
designSystem.Grid.Item,
|
|
823
|
+
{
|
|
824
|
+
col: 6,
|
|
825
|
+
xs: 12,
|
|
826
|
+
s: 12,
|
|
827
|
+
m: 6,
|
|
828
|
+
direction: "column",
|
|
829
|
+
alignItems: "stretch",
|
|
830
|
+
minWidth: 0,
|
|
831
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `fields.${index2}.default`, error: err(`fields.${index2}.default`), children: [
|
|
832
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.fields.default", "Default value") }),
|
|
833
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
834
|
+
designSystem.TextInput,
|
|
835
|
+
{
|
|
836
|
+
value: String(field.default ?? ""),
|
|
837
|
+
onChange: (event) => update(index2, { default: event.target.value })
|
|
838
|
+
}
|
|
839
|
+
),
|
|
840
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
841
|
+
] })
|
|
842
|
+
}
|
|
843
|
+
) : null,
|
|
844
|
+
field.type === "checkbox" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
845
|
+
designSystem.Grid.Item,
|
|
846
|
+
{
|
|
847
|
+
col: 6,
|
|
848
|
+
xs: 12,
|
|
849
|
+
s: 12,
|
|
850
|
+
m: 6,
|
|
851
|
+
direction: "column",
|
|
852
|
+
alignItems: "flex-start",
|
|
853
|
+
minWidth: 0,
|
|
854
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
855
|
+
designSystem.Checkbox,
|
|
856
|
+
{
|
|
857
|
+
checked: field.default === true || field.default === "true",
|
|
858
|
+
onCheckedChange: (checked) => update(index2, { default: checked === true }),
|
|
859
|
+
children: t("settings.blocks.fields.defaultChecked", "Checked by default")
|
|
860
|
+
}
|
|
861
|
+
)
|
|
862
|
+
}
|
|
863
|
+
) : null,
|
|
864
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
865
|
+
designSystem.Grid.Item,
|
|
866
|
+
{
|
|
867
|
+
col: 6,
|
|
868
|
+
xs: 12,
|
|
869
|
+
s: 12,
|
|
870
|
+
m: 6,
|
|
871
|
+
direction: "column",
|
|
872
|
+
alignItems: "flex-start",
|
|
873
|
+
minWidth: 0,
|
|
874
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
875
|
+
designSystem.Checkbox,
|
|
876
|
+
{
|
|
877
|
+
checked: field.required,
|
|
878
|
+
onCheckedChange: (checked) => update(index2, { required: checked === true }),
|
|
879
|
+
children: t("settings.blocks.fields.required", "Required")
|
|
880
|
+
}
|
|
881
|
+
)
|
|
882
|
+
}
|
|
883
|
+
)
|
|
884
|
+
] })
|
|
885
|
+
] })
|
|
886
|
+
},
|
|
887
|
+
field.key
|
|
888
|
+
);
|
|
889
|
+
}),
|
|
890
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
891
|
+
designSystem.Button,
|
|
892
|
+
{
|
|
893
|
+
variant: "secondary",
|
|
894
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
|
|
895
|
+
disabled: fields.length >= 20,
|
|
896
|
+
onClick: () => onChange([...fields, emptyField(fields.length)]),
|
|
897
|
+
children: t("settings.blocks.fields.add", "Add field")
|
|
898
|
+
}
|
|
899
|
+
) }),
|
|
900
|
+
errors.fields ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "danger600", children: blockErrorText(t, errors.fields) }) : null
|
|
901
|
+
] });
|
|
902
|
+
};
|
|
903
|
+
const SubHeading = ({ title, subtitle }) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, children: [
|
|
904
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", textColor: "neutral800", children: title }),
|
|
905
|
+
subtitle ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: subtitle }) : null
|
|
906
|
+
] });
|
|
907
|
+
const BlockFormModal = ({
|
|
908
|
+
open,
|
|
909
|
+
block,
|
|
910
|
+
otherNames,
|
|
911
|
+
contentTypes,
|
|
912
|
+
onRetryContentTypes,
|
|
913
|
+
onSubmit,
|
|
914
|
+
onClose
|
|
915
|
+
}) => {
|
|
916
|
+
const t = useT.useT();
|
|
917
|
+
const [values, setValues] = react.useState(() => block ? fromDto(block) : emptyValues());
|
|
918
|
+
const [serverErrors, setServerErrors] = react.useState({});
|
|
919
|
+
const [showErrors, setShowErrors] = react.useState(false);
|
|
920
|
+
const [saving, setSaving] = react.useState(false);
|
|
921
|
+
const errors = react.useMemo(() => validateBlock(values, { existingNames: otherNames }), [values, otherNames]);
|
|
922
|
+
const visible = react.useMemo(
|
|
923
|
+
() => ({ ...showErrors ? errors : {}, ...serverErrors }),
|
|
924
|
+
[errors, serverErrors, showErrors]
|
|
925
|
+
);
|
|
926
|
+
const err = (path) => blockErrorText(t, visible[path]);
|
|
927
|
+
const set = (patch) => {
|
|
928
|
+
setValues((current) => ({ ...current, ...patch }));
|
|
929
|
+
setServerErrors((current) => {
|
|
930
|
+
const next = { ...current };
|
|
931
|
+
Object.keys(patch).forEach((key) => delete next[key]);
|
|
932
|
+
delete next._form;
|
|
933
|
+
return next;
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
const onLabel = (label) => {
|
|
937
|
+
if (values.nameTouched) set({ label });
|
|
938
|
+
else set({ label, name: deriveName(label) });
|
|
939
|
+
};
|
|
940
|
+
const selectedType = contentTypes.items.find((ct) => ct.uid === values.contentType);
|
|
941
|
+
const attributeOptions = selectedType ? selectedType.attributes : Array.from(new Set(contentTypes.items.flatMap((ct) => ct.attributes)));
|
|
942
|
+
const submit = async () => {
|
|
943
|
+
setShowErrors(true);
|
|
944
|
+
if (Object.keys(errors).length) return;
|
|
945
|
+
setSaving(true);
|
|
946
|
+
try {
|
|
947
|
+
const result = await onSubmit(values);
|
|
948
|
+
if (!result.ok && result.errors) setServerErrors(result.errors);
|
|
949
|
+
} finally {
|
|
950
|
+
setSaving(false);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const title = block ? t("settings.blocks.modal.editTitle", "Edit block {label}", { label: block.label }) : t("settings.blocks.modal.createTitle", "Create a custom block");
|
|
954
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
955
|
+
designSystem.Modal.Root,
|
|
956
|
+
{
|
|
957
|
+
open,
|
|
958
|
+
onOpenChange: (next) => {
|
|
959
|
+
if (!next && !saving) onClose();
|
|
960
|
+
},
|
|
961
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
|
|
962
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { closeLabel: t("settings.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
|
|
963
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
964
|
+
visible._form ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
965
|
+
designSystem.Alert,
|
|
966
|
+
{
|
|
967
|
+
variant: "danger",
|
|
968
|
+
closeLabel: t("settings.close", "Close"),
|
|
969
|
+
onClose: () => setServerErrors({}),
|
|
970
|
+
children: visible._form.server
|
|
971
|
+
}
|
|
972
|
+
) : null,
|
|
973
|
+
showErrors && Object.keys(errors).length ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "danger600", role: "status", children: t("settings.blocks.modal.invalid", "Some values need attention. They are marked below.") }) : null,
|
|
974
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
975
|
+
/* @__PURE__ */ jsxRuntime.jsx(SubHeading, { title: t("settings.blocks.modal.basics", "Basics") }),
|
|
976
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, children: [
|
|
977
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
978
|
+
designSystem.Field.Root,
|
|
979
|
+
{
|
|
980
|
+
name: "label",
|
|
981
|
+
error: err("label"),
|
|
982
|
+
hint: t("settings.blocks.form.labelHint", "Shown in the editor toolbox."),
|
|
983
|
+
required: true,
|
|
984
|
+
children: [
|
|
985
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.label", "Label") }),
|
|
986
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.TextInput, { value: values.label, onChange: (event) => onLabel(event.target.value) }),
|
|
987
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
988
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
989
|
+
]
|
|
990
|
+
}
|
|
991
|
+
) }),
|
|
992
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
993
|
+
designSystem.Field.Root,
|
|
994
|
+
{
|
|
995
|
+
name: "name",
|
|
996
|
+
error: err("name"),
|
|
997
|
+
hint: block ? t(
|
|
998
|
+
"settings.blocks.form.nameHintEdit",
|
|
999
|
+
"Stored as the block type in content. Renaming hides existing blocks of the old name."
|
|
1000
|
+
) : t(
|
|
1001
|
+
"settings.blocks.form.nameHint",
|
|
1002
|
+
"Identifier stored with the content. Filled from the label until you edit it."
|
|
1003
|
+
),
|
|
1004
|
+
required: true,
|
|
1005
|
+
children: [
|
|
1006
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.name", "Name") }),
|
|
1007
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1008
|
+
designSystem.TextInput,
|
|
1009
|
+
{
|
|
1010
|
+
value: values.name,
|
|
1011
|
+
onChange: (event) => set({ name: event.target.value, nameTouched: true })
|
|
1012
|
+
}
|
|
1013
|
+
),
|
|
1014
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1015
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1016
|
+
]
|
|
1017
|
+
}
|
|
1018
|
+
) }),
|
|
1019
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, xs: 12, s: 12, m: 6, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "blockType", error: err("blockType"), required: true, children: [
|
|
1020
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.type", "Type") }),
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1022
|
+
designSystem.SingleSelect,
|
|
1023
|
+
{
|
|
1024
|
+
value: values.blockType,
|
|
1025
|
+
onChange: (value) => set({ blockType: String(value) }),
|
|
1026
|
+
children: [
|
|
1027
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "simple", children: blockTypeLabel(t, "simple") }),
|
|
1028
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "embedded-entry", children: blockTypeLabel(t, "embedded-entry") })
|
|
1029
|
+
]
|
|
1030
|
+
}
|
|
1031
|
+
),
|
|
1032
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1033
|
+
] }) }),
|
|
1034
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1035
|
+
designSystem.Grid.Item,
|
|
1036
|
+
{
|
|
1037
|
+
col: 6,
|
|
1038
|
+
xs: 12,
|
|
1039
|
+
s: 12,
|
|
1040
|
+
m: 6,
|
|
1041
|
+
direction: "column",
|
|
1042
|
+
alignItems: "flex-start",
|
|
1043
|
+
minWidth: 0,
|
|
1044
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, paddingTop: { initial: 0, medium: 6 }, alignItems: "center", children: [
|
|
1045
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1046
|
+
designSystem.Switch,
|
|
1047
|
+
{
|
|
1048
|
+
checked: values.enabled,
|
|
1049
|
+
onCheckedChange: (checked) => set({ enabled: checked === true }),
|
|
1050
|
+
"aria-label": t("settings.blocks.form.enabled", "Show in the editor toolbox"),
|
|
1051
|
+
onLabel: t("settings.switch.on", "On"),
|
|
1052
|
+
offLabel: t("settings.switch.off", "Off")
|
|
1053
|
+
}
|
|
1054
|
+
),
|
|
1055
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", children: t("settings.blocks.form.enabled", "Show in the editor toolbox") })
|
|
1056
|
+
] })
|
|
1057
|
+
}
|
|
1058
|
+
),
|
|
1059
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 12, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "description", error: err("description"), children: [
|
|
1060
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.description", "Description") }),
|
|
1061
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1062
|
+
designSystem.Textarea,
|
|
1063
|
+
{
|
|
1064
|
+
value: values.description,
|
|
1065
|
+
onChange: (event) => set({ description: event.target.value })
|
|
1066
|
+
}
|
|
1067
|
+
),
|
|
1068
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1069
|
+
] }) }),
|
|
1070
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 12, direction: "column", alignItems: "stretch", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1071
|
+
designSystem.Field.Root,
|
|
1072
|
+
{
|
|
1073
|
+
name: "icon",
|
|
1074
|
+
error: err("icon"),
|
|
1075
|
+
hint: t(
|
|
1076
|
+
"settings.blocks.form.iconHint",
|
|
1077
|
+
"Optional SVG markup. Scripts, styles and links are removed."
|
|
1078
|
+
),
|
|
1079
|
+
children: [
|
|
1080
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.icon", "Icon (SVG)") }),
|
|
1081
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-start", children: [
|
|
1082
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { flex: "1 1 auto", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1083
|
+
designSystem.Textarea,
|
|
1084
|
+
{
|
|
1085
|
+
value: values.icon,
|
|
1086
|
+
onChange: (event) => set({ icon: event.target.value })
|
|
1087
|
+
}
|
|
1088
|
+
) }),
|
|
1089
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1090
|
+
IconPreview,
|
|
1091
|
+
{
|
|
1092
|
+
svg: values.icon,
|
|
1093
|
+
label: t("settings.blocks.form.iconPreview", "Icon preview")
|
|
1094
|
+
}
|
|
1095
|
+
)
|
|
1096
|
+
] }),
|
|
1097
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1098
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1099
|
+
]
|
|
1100
|
+
}
|
|
1101
|
+
) })
|
|
1102
|
+
] })
|
|
1103
|
+
] }),
|
|
1104
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
1105
|
+
values.blockType === "simple" ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1106
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1107
|
+
SubHeading,
|
|
1108
|
+
{
|
|
1109
|
+
title: t("settings.blocks.modal.fields", "Fields"),
|
|
1110
|
+
subtitle: t(
|
|
1111
|
+
"settings.blocks.modal.fieldsHint",
|
|
1112
|
+
"Inputs editors fill in for each block. Use {example} in the template to show a value.",
|
|
1113
|
+
{
|
|
1114
|
+
example: "{{key}}"
|
|
1115
|
+
}
|
|
1116
|
+
)
|
|
1117
|
+
}
|
|
1118
|
+
),
|
|
1119
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1120
|
+
FieldsEditor,
|
|
1121
|
+
{
|
|
1122
|
+
fields: values.fields,
|
|
1123
|
+
errors: visible,
|
|
1124
|
+
onChange: (fields) => set({ fields })
|
|
1125
|
+
}
|
|
1126
|
+
),
|
|
1127
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1128
|
+
designSystem.Field.Root,
|
|
1129
|
+
{
|
|
1130
|
+
name: "template",
|
|
1131
|
+
error: err("template"),
|
|
1132
|
+
hint: t(
|
|
1133
|
+
"settings.blocks.form.templateHint",
|
|
1134
|
+
"Optional HTML layout for the block. Allowed: basic text, list, image and link tags."
|
|
1135
|
+
),
|
|
1136
|
+
children: [
|
|
1137
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.template", "HTML template") }),
|
|
1138
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1139
|
+
designSystem.Textarea,
|
|
1140
|
+
{
|
|
1141
|
+
value: values.template,
|
|
1142
|
+
onChange: (event) => set({ template: event.target.value })
|
|
1143
|
+
}
|
|
1144
|
+
),
|
|
1145
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1146
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1147
|
+
]
|
|
1148
|
+
}
|
|
1149
|
+
),
|
|
1150
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1151
|
+
TemplatePreview,
|
|
1152
|
+
{
|
|
1153
|
+
template: values.template,
|
|
1154
|
+
fields: values.fields,
|
|
1155
|
+
label: t("settings.blocks.form.templatePreview", "Preview"),
|
|
1156
|
+
empty: t(
|
|
1157
|
+
"settings.blocks.form.templateEmpty",
|
|
1158
|
+
"No template. The editor shows the fields as a form."
|
|
1159
|
+
)
|
|
1160
|
+
}
|
|
1161
|
+
),
|
|
1162
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "placeholder", error: err("placeholder"), children: [
|
|
1163
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.placeholder", "Placeholder") }),
|
|
1164
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1165
|
+
designSystem.TextInput,
|
|
1166
|
+
{
|
|
1167
|
+
value: values.placeholder,
|
|
1168
|
+
onChange: (event) => set({ placeholder: event.target.value })
|
|
1169
|
+
}
|
|
1170
|
+
),
|
|
1171
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1172
|
+
] })
|
|
1173
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1174
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1175
|
+
SubHeading,
|
|
1176
|
+
{
|
|
1177
|
+
title: t("settings.blocks.modal.entry", "Embedded entry"),
|
|
1178
|
+
subtitle: t(
|
|
1179
|
+
"settings.blocks.modal.entryHint",
|
|
1180
|
+
"Editors pick an entry; only entries they can read in the Content Manager are listed."
|
|
1181
|
+
)
|
|
1182
|
+
}
|
|
1183
|
+
),
|
|
1184
|
+
contentTypes.status === "error" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1185
|
+
designSystem.Alert,
|
|
1186
|
+
{
|
|
1187
|
+
variant: "warning",
|
|
1188
|
+
closeLabel: t("settings.close", "Close"),
|
|
1189
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", size: "S", onClick: onRetryContentTypes, children: t("settings.retry", "Try again") }),
|
|
1190
|
+
children: t("settings.blocks.contentTypes.error", "Content types could not be loaded.")
|
|
1191
|
+
}
|
|
1192
|
+
) : null,
|
|
1193
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, children: [
|
|
1194
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1195
|
+
designSystem.Grid.Item,
|
|
1196
|
+
{
|
|
1197
|
+
col: 6,
|
|
1198
|
+
xs: 12,
|
|
1199
|
+
s: 12,
|
|
1200
|
+
m: 6,
|
|
1201
|
+
direction: "column",
|
|
1202
|
+
alignItems: "stretch",
|
|
1203
|
+
minWidth: 0,
|
|
1204
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1205
|
+
designSystem.Field.Root,
|
|
1206
|
+
{
|
|
1207
|
+
name: "contentType",
|
|
1208
|
+
hint: t("settings.blocks.form.contentTypeHint", "Leave empty to let editors choose."),
|
|
1209
|
+
children: [
|
|
1210
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.contentType", "Content type") }),
|
|
1211
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1212
|
+
designSystem.SingleSelect,
|
|
1213
|
+
{
|
|
1214
|
+
value: values.contentType,
|
|
1215
|
+
placeholder: t("settings.blocks.form.anyContentType", "Any content type"),
|
|
1216
|
+
onClear: () => set({ contentType: "" }),
|
|
1217
|
+
clearLabel: t("settings.blocks.form.clearContentType", "Clear content type"),
|
|
1218
|
+
onChange: (value) => set({ contentType: String(value) }),
|
|
1219
|
+
children: contentTypes.items.map((ct) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: ct.uid, children: ct.displayName }, ct.uid))
|
|
1220
|
+
}
|
|
1221
|
+
),
|
|
1222
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
1223
|
+
]
|
|
1224
|
+
}
|
|
1225
|
+
)
|
|
1226
|
+
}
|
|
1227
|
+
),
|
|
1228
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1229
|
+
designSystem.Grid.Item,
|
|
1230
|
+
{
|
|
1231
|
+
col: 6,
|
|
1232
|
+
xs: 12,
|
|
1233
|
+
s: 12,
|
|
1234
|
+
m: 6,
|
|
1235
|
+
direction: "column",
|
|
1236
|
+
alignItems: "stretch",
|
|
1237
|
+
minWidth: 0,
|
|
1238
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "titleField", error: err("titleField"), children: [
|
|
1239
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.titleField", "Title field") }),
|
|
1240
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1241
|
+
designSystem.SingleSelect,
|
|
1242
|
+
{
|
|
1243
|
+
value: values.titleField,
|
|
1244
|
+
placeholder: t(
|
|
1245
|
+
"settings.blocks.form.titleFieldPlaceholder",
|
|
1246
|
+
"Detected automatically"
|
|
1247
|
+
),
|
|
1248
|
+
onClear: () => set({ titleField: "" }),
|
|
1249
|
+
clearLabel: t("settings.blocks.form.clearTitleField", "Clear title field"),
|
|
1250
|
+
onChange: (value) => set({ titleField: String(value) }),
|
|
1251
|
+
children: attributeOptions.map((name) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: name, children: name }, name))
|
|
1252
|
+
}
|
|
1253
|
+
),
|
|
1254
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1255
|
+
] })
|
|
1256
|
+
}
|
|
1257
|
+
),
|
|
1258
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1259
|
+
designSystem.Grid.Item,
|
|
1260
|
+
{
|
|
1261
|
+
col: 6,
|
|
1262
|
+
xs: 12,
|
|
1263
|
+
s: 12,
|
|
1264
|
+
m: 6,
|
|
1265
|
+
direction: "column",
|
|
1266
|
+
alignItems: "stretch",
|
|
1267
|
+
minWidth: 0,
|
|
1268
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1269
|
+
designSystem.Field.Root,
|
|
1270
|
+
{
|
|
1271
|
+
name: "displayFields",
|
|
1272
|
+
error: err("displayFields"),
|
|
1273
|
+
hint: t("settings.blocks.form.displayFieldsHint", "Stored with the block."),
|
|
1274
|
+
children: [
|
|
1275
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.displayFields", "Stored fields") }),
|
|
1276
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1277
|
+
designSystem.MultiSelect,
|
|
1278
|
+
{
|
|
1279
|
+
value: values.displayFields,
|
|
1280
|
+
withTags: true,
|
|
1281
|
+
onChange: (value) => set({ displayFields: value }),
|
|
1282
|
+
children: attributeOptions.map((name) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: name, children: name }, name))
|
|
1283
|
+
}
|
|
1284
|
+
),
|
|
1285
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1286
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1287
|
+
]
|
|
1288
|
+
}
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
),
|
|
1292
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1293
|
+
designSystem.Grid.Item,
|
|
1294
|
+
{
|
|
1295
|
+
col: 6,
|
|
1296
|
+
xs: 12,
|
|
1297
|
+
s: 12,
|
|
1298
|
+
m: 6,
|
|
1299
|
+
direction: "column",
|
|
1300
|
+
alignItems: "stretch",
|
|
1301
|
+
minWidth: 0,
|
|
1302
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1303
|
+
designSystem.Field.Root,
|
|
1304
|
+
{
|
|
1305
|
+
name: "previewFields",
|
|
1306
|
+
error: err("previewFields"),
|
|
1307
|
+
hint: t("settings.blocks.form.previewFieldsHint", "Shown in the editor card."),
|
|
1308
|
+
children: [
|
|
1309
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.previewFields", "Preview fields") }),
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1311
|
+
designSystem.MultiSelect,
|
|
1312
|
+
{
|
|
1313
|
+
value: values.previewFields,
|
|
1314
|
+
withTags: true,
|
|
1315
|
+
onChange: (value) => set({ previewFields: value }),
|
|
1316
|
+
children: attributeOptions.map((name) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: name, children: name }, name))
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1320
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1321
|
+
]
|
|
1322
|
+
}
|
|
1323
|
+
)
|
|
1324
|
+
}
|
|
1325
|
+
)
|
|
1326
|
+
] })
|
|
1327
|
+
] }),
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
1329
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1330
|
+
/* @__PURE__ */ jsxRuntime.jsx(SubHeading, { title: t("settings.blocks.modal.advanced", "Advanced") }),
|
|
1331
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "center", children: [
|
|
1332
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1333
|
+
designSystem.Switch,
|
|
1334
|
+
{
|
|
1335
|
+
checked: values.inlineToolbar,
|
|
1336
|
+
onCheckedChange: (checked) => set({ inlineToolbar: checked === true }),
|
|
1337
|
+
"aria-label": t(
|
|
1338
|
+
"settings.blocks.form.inlineToolbar",
|
|
1339
|
+
"Allow text formatting (inline toolbar)"
|
|
1340
|
+
),
|
|
1341
|
+
onLabel: t("settings.switch.on", "On"),
|
|
1342
|
+
offLabel: t("settings.switch.off", "Off")
|
|
1343
|
+
}
|
|
1344
|
+
),
|
|
1345
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", children: t("settings.blocks.form.inlineToolbar", "Allow text formatting (inline toolbar)") })
|
|
1346
|
+
] }),
|
|
1347
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { tag: "fieldset", margin: 0, padding: 0, borderWidth: 0, children: [
|
|
1348
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", tag: "legend", children: t("settings.blocks.form.tunes", "Block settings") }),
|
|
1349
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 4, wrap: "wrap", paddingTop: 2, children: TUNES.map((tune) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1350
|
+
designSystem.Checkbox,
|
|
1351
|
+
{
|
|
1352
|
+
checked: values.tunes.includes(tune),
|
|
1353
|
+
onCheckedChange: (checked) => set({
|
|
1354
|
+
tunes: checked === true ? [...values.tunes, tune] : values.tunes.filter((item) => item !== tune)
|
|
1355
|
+
}),
|
|
1356
|
+
children: {
|
|
1357
|
+
alignmentTune: t("settings.blocks.tune.alignment", "Alignment"),
|
|
1358
|
+
textVariant: t("settings.blocks.tune.textVariant", "Text variant"),
|
|
1359
|
+
indentTune: t("settings.blocks.tune.indent", "Indent")
|
|
1360
|
+
}[tune]
|
|
1361
|
+
},
|
|
1362
|
+
tune
|
|
1363
|
+
)) })
|
|
1364
|
+
] }),
|
|
1365
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1366
|
+
designSystem.Field.Root,
|
|
1367
|
+
{
|
|
1368
|
+
name: "shortcut",
|
|
1369
|
+
error: err("shortcut"),
|
|
1370
|
+
hint: t("settings.blocks.form.shortcutHint", "Optional, for example CMD+SHIFT+K."),
|
|
1371
|
+
children: [
|
|
1372
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("settings.blocks.form.shortcut", "Keyboard shortcut") }),
|
|
1373
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1374
|
+
designSystem.TextInput,
|
|
1375
|
+
{
|
|
1376
|
+
value: values.shortcut,
|
|
1377
|
+
onChange: (event) => set({ shortcut: event.target.value })
|
|
1378
|
+
}
|
|
1379
|
+
),
|
|
1380
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1381
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1382
|
+
]
|
|
1383
|
+
}
|
|
1384
|
+
)
|
|
1385
|
+
] })
|
|
1386
|
+
] }) }),
|
|
1387
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
|
|
1388
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", disabled: saving, children: t("settings.cancel", "Cancel") }) }),
|
|
1389
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: submit, loading: saving, disabled: saving, children: block ? t("settings.blocks.modal.save", "Save block") : t("settings.blocks.modal.create", "Create block") })
|
|
1390
|
+
] })
|
|
1391
|
+
] })
|
|
1392
|
+
}
|
|
1393
|
+
);
|
|
1394
|
+
};
|
|
1395
|
+
const CustomBlocksPage = () => {
|
|
1396
|
+
const t = useT.useT();
|
|
1397
|
+
const { post, put, del, get } = admin.useFetchClient();
|
|
1398
|
+
const { toggleNotification } = admin.useNotification();
|
|
1399
|
+
const { allowedActions, isLoading: rbacLoading } = admin.useRBAC(index.PERMISSIONS.customBlocksManage);
|
|
1400
|
+
const data = useCustomBlocks();
|
|
1401
|
+
const [modal, setModal] = react.useState({ open: false, block: null, key: 0 });
|
|
1402
|
+
const [busyId, setBusyId] = react.useState(null);
|
|
1403
|
+
const [exporting, setExporting] = react.useState(false);
|
|
1404
|
+
const [importing, setImporting] = react.useState(false);
|
|
1405
|
+
const [importReport, setImportReport] = react.useState(null);
|
|
1406
|
+
const createRef = react.useRef(null);
|
|
1407
|
+
const fileRef = react.useRef(null);
|
|
1408
|
+
const title = t("settings.blocks.title", "Custom blocks");
|
|
1409
|
+
const otherNames = react.useMemo(
|
|
1410
|
+
() => data.blocks.filter((block) => !modal.block || block.id !== modal.block.id).map((block) => block.name),
|
|
1411
|
+
[data.blocks, modal.block]
|
|
1412
|
+
);
|
|
1413
|
+
if (rbacLoading || data.status === "loading") {
|
|
1414
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
|
|
1415
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: title }),
|
|
1416
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {})
|
|
1417
|
+
] });
|
|
1418
|
+
}
|
|
1419
|
+
if (!allowedActions.canManage) {
|
|
1420
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
|
|
1421
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: title }),
|
|
1422
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.NoPermissions, {})
|
|
1423
|
+
] });
|
|
1424
|
+
}
|
|
1425
|
+
if (data.status === "error") {
|
|
1426
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
|
|
1427
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: title }),
|
|
1428
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1429
|
+
admin.Page.Error,
|
|
1430
|
+
{
|
|
1431
|
+
content: t("settings.blocks.loadError", "The custom blocks could not be loaded."),
|
|
1432
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", onClick: data.reload, children: t("settings.retry", "Try again") })
|
|
1433
|
+
}
|
|
1434
|
+
)
|
|
1435
|
+
] });
|
|
1436
|
+
}
|
|
1437
|
+
const failed = (error, fallback) => {
|
|
1438
|
+
const info = api.readApiError(error);
|
|
1439
|
+
toggleNotification({
|
|
1440
|
+
type: "danger",
|
|
1441
|
+
message: info.status === 404 ? t("settings.blocks.notFound", "This block no longer exists.") : fallback
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1444
|
+
const onSubmit = async (values) => {
|
|
1445
|
+
const payload = toPayload(values);
|
|
1446
|
+
try {
|
|
1447
|
+
if (modal.block) await put(api.API.customBlock(modal.block.id), payload);
|
|
1448
|
+
else await post(api.API.customBlocks, payload);
|
|
1449
|
+
toggleNotification({
|
|
1450
|
+
type: "success",
|
|
1451
|
+
message: modal.block ? t("settings.blocks.saved", "Block {label} saved.", { label: payload.label }) : t("settings.blocks.created", "Block {label} created.", { label: payload.label })
|
|
1452
|
+
});
|
|
1453
|
+
setModal((current) => ({ ...current, open: false, block: null }));
|
|
1454
|
+
await data.reload();
|
|
1455
|
+
return { ok: true };
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
const info = api.readApiError(error);
|
|
1458
|
+
if (info.status === 400) {
|
|
1459
|
+
toggleNotification({
|
|
1460
|
+
type: "warning",
|
|
1461
|
+
message: t(
|
|
1462
|
+
"settings.blocks.rejected",
|
|
1463
|
+
"The server rejected some values. They are marked in the form."
|
|
1464
|
+
)
|
|
1465
|
+
});
|
|
1466
|
+
return { ok: false, errors: mapServerErrors(info.details) };
|
|
1467
|
+
}
|
|
1468
|
+
failed(
|
|
1469
|
+
error,
|
|
1470
|
+
t("settings.blocks.saveError", "The block could not be saved. Your changes are still in the form.")
|
|
1471
|
+
);
|
|
1472
|
+
return { ok: false };
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
const onToggle = async (block, enabled) => {
|
|
1476
|
+
setBusyId(block.id);
|
|
1477
|
+
try {
|
|
1478
|
+
const { data: response } = await put(api.API.customBlock(block.id), withEnabled(block, enabled));
|
|
1479
|
+
data.setBlocks((current) => current.map((item) => item.id === block.id ? response.data : item));
|
|
1480
|
+
toggleNotification({
|
|
1481
|
+
type: "success",
|
|
1482
|
+
message: enabled ? t("settings.blocks.enabled", "Block {label} is shown in the toolbox.", { label: block.label }) : t("settings.blocks.disabled", "Block {label} is hidden from the toolbox.", {
|
|
1483
|
+
label: block.label
|
|
1484
|
+
})
|
|
1485
|
+
});
|
|
1486
|
+
} catch (error) {
|
|
1487
|
+
const info = api.readApiError(error);
|
|
1488
|
+
if (info.status === 400) {
|
|
1489
|
+
toggleNotification({
|
|
1490
|
+
type: "warning",
|
|
1491
|
+
message: t(
|
|
1492
|
+
"settings.blocks.toggleInvalid",
|
|
1493
|
+
"Block {label} has invalid settings. Edit it to fix them first.",
|
|
1494
|
+
{ label: block.label }
|
|
1495
|
+
)
|
|
1496
|
+
});
|
|
1497
|
+
} else failed(error, t("settings.blocks.toggleError", "The block could not be updated."));
|
|
1498
|
+
} finally {
|
|
1499
|
+
setBusyId(null);
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
const onDuplicate = async (block) => {
|
|
1503
|
+
setBusyId(block.id);
|
|
1504
|
+
try {
|
|
1505
|
+
const { data: response } = await post(api.API.customBlockDuplicate(block.id), {});
|
|
1506
|
+
toggleNotification({
|
|
1507
|
+
type: "success",
|
|
1508
|
+
message: t("settings.blocks.duplicated", "Copy {label} created.", { label: response.data.label })
|
|
1509
|
+
});
|
|
1510
|
+
await data.reload();
|
|
1511
|
+
} catch (error) {
|
|
1512
|
+
failed(error, t("settings.blocks.duplicateError", "The block could not be duplicated."));
|
|
1513
|
+
} finally {
|
|
1514
|
+
setBusyId(null);
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
const onMove = async (block, direction) => {
|
|
1518
|
+
const ids = moveId(
|
|
1519
|
+
data.blocks.map((item) => item.id),
|
|
1520
|
+
block.id,
|
|
1521
|
+
direction
|
|
1522
|
+
);
|
|
1523
|
+
if (!ids) return;
|
|
1524
|
+
const opener = typeof document !== "undefined" ? document.activeElement : null;
|
|
1525
|
+
setBusyId(block.id);
|
|
1526
|
+
try {
|
|
1527
|
+
const { data: response } = await put(api.API.customBlocksOrder, { ids });
|
|
1528
|
+
data.setBlocks(response.data);
|
|
1529
|
+
} catch (error) {
|
|
1530
|
+
failed(error, t("settings.blocks.moveError", "The order could not be saved."));
|
|
1531
|
+
} finally {
|
|
1532
|
+
setBusyId(null);
|
|
1533
|
+
requestAnimationFrame(() => useT.refocusIfLost(opener, createRef.current));
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
const onDelete = async (block) => {
|
|
1537
|
+
try {
|
|
1538
|
+
await del(api.API.customBlock(block.id));
|
|
1539
|
+
toggleNotification({
|
|
1540
|
+
type: "success",
|
|
1541
|
+
message: t("settings.blocks.deleted", "Block {label} deleted.", { label: block.label })
|
|
1542
|
+
});
|
|
1543
|
+
data.setBlocks((current) => current.filter((item) => item.id !== block.id));
|
|
1544
|
+
} catch (error) {
|
|
1545
|
+
failed(error, t("settings.blocks.deleteError", "The block could not be deleted."));
|
|
1546
|
+
throw error;
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
const onExport = async () => {
|
|
1550
|
+
setExporting(true);
|
|
1551
|
+
try {
|
|
1552
|
+
const { data: response } = await get(api.API.customBlocksExport);
|
|
1553
|
+
const blob = new Blob([JSON.stringify(response.data, null, 2)], { type: "application/json" });
|
|
1554
|
+
const url = URL.createObjectURL(blob);
|
|
1555
|
+
const link = document.createElement("a");
|
|
1556
|
+
link.href = url;
|
|
1557
|
+
link.download = "magic-editor-x-custom-blocks.json";
|
|
1558
|
+
document.body.appendChild(link);
|
|
1559
|
+
link.click();
|
|
1560
|
+
link.remove();
|
|
1561
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
1562
|
+
toggleNotification({
|
|
1563
|
+
type: "success",
|
|
1564
|
+
message: t("settings.blocks.exported", "Exported {count, plural, one {# block} other {# blocks}}.", {
|
|
1565
|
+
count: response.data.blocks.length
|
|
1566
|
+
})
|
|
1567
|
+
});
|
|
1568
|
+
} catch (error) {
|
|
1569
|
+
failed(error, t("settings.blocks.exportError", "The export could not be created."));
|
|
1570
|
+
} finally {
|
|
1571
|
+
setExporting(false);
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
const onImportFile = async (event) => {
|
|
1575
|
+
const input = event.target;
|
|
1576
|
+
const file = input.files && input.files[0];
|
|
1577
|
+
input.value = "";
|
|
1578
|
+
if (!file) return;
|
|
1579
|
+
setImporting(true);
|
|
1580
|
+
try {
|
|
1581
|
+
let parsed;
|
|
1582
|
+
try {
|
|
1583
|
+
parsed = JSON.parse(await file.text());
|
|
1584
|
+
} catch {
|
|
1585
|
+
toggleNotification({
|
|
1586
|
+
type: "danger",
|
|
1587
|
+
message: t("settings.blocks.importInvalidFile", "The file is not valid JSON.")
|
|
1588
|
+
});
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const { data: response } = await post(api.API.customBlocksImport, parsed);
|
|
1592
|
+
const { created, skipped } = response.data;
|
|
1593
|
+
setImportReport({ created, skipped });
|
|
1594
|
+
toggleNotification({
|
|
1595
|
+
type: created.length ? "success" : "warning",
|
|
1596
|
+
message: t("settings.blocks.imported", "Import finished: {created} created, {skipped} skipped.", {
|
|
1597
|
+
created: created.length,
|
|
1598
|
+
skipped: skipped.length
|
|
1599
|
+
})
|
|
1600
|
+
});
|
|
1601
|
+
await data.reload();
|
|
1602
|
+
} catch (error) {
|
|
1603
|
+
const info = api.readApiError(error);
|
|
1604
|
+
toggleNotification({
|
|
1605
|
+
type: "danger",
|
|
1606
|
+
message: info.status === 400 ? t("settings.blocks.importRejected", "The file is not a Magic Editor X custom block export.") : t("settings.blocks.importError", "The import failed. Nothing was imported.")
|
|
1607
|
+
});
|
|
1608
|
+
} finally {
|
|
1609
|
+
setImporting(false);
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
const createButton = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1613
|
+
designSystem.Button,
|
|
1614
|
+
{
|
|
1615
|
+
ref: createRef,
|
|
1616
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
|
|
1617
|
+
onClick: () => setModal((current) => ({ open: true, block: null, key: current.key + 1 })),
|
|
1618
|
+
children: t("settings.blocks.create", "Create block")
|
|
1619
|
+
}
|
|
1620
|
+
);
|
|
1621
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1622
|
+
useT.PageShell,
|
|
1623
|
+
{
|
|
1624
|
+
title,
|
|
1625
|
+
subtitle: t(
|
|
1626
|
+
"settings.blocks.subtitle",
|
|
1627
|
+
"Define your own blocks for the editor toolbox: simple blocks with fields and an HTML layout, or blocks that embed a Content Manager entry."
|
|
1628
|
+
),
|
|
1629
|
+
primaryAction: createButton,
|
|
1630
|
+
secondaryAction: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
|
|
1631
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1632
|
+
designSystem.Button,
|
|
1633
|
+
{
|
|
1634
|
+
variant: "tertiary",
|
|
1635
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Upload, {}),
|
|
1636
|
+
loading: importing,
|
|
1637
|
+
disabled: importing,
|
|
1638
|
+
onClick: () => fileRef.current && fileRef.current.click(),
|
|
1639
|
+
children: t("settings.blocks.import", "Import")
|
|
1640
|
+
}
|
|
1641
|
+
),
|
|
1642
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1643
|
+
designSystem.Button,
|
|
1644
|
+
{
|
|
1645
|
+
variant: "tertiary",
|
|
1646
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
|
|
1647
|
+
loading: exporting,
|
|
1648
|
+
disabled: exporting || data.blocks.length === 0,
|
|
1649
|
+
onClick: onExport,
|
|
1650
|
+
children: t("settings.blocks.export", "Export")
|
|
1651
|
+
}
|
|
1652
|
+
),
|
|
1653
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1654
|
+
"input",
|
|
1655
|
+
{
|
|
1656
|
+
ref: fileRef,
|
|
1657
|
+
type: "file",
|
|
1658
|
+
accept: "application/json,.json",
|
|
1659
|
+
hidden: true,
|
|
1660
|
+
"aria-label": t("settings.blocks.importFile", "Custom block export file"),
|
|
1661
|
+
onChange: onImportFile
|
|
1662
|
+
}
|
|
1663
|
+
)
|
|
1664
|
+
] }),
|
|
1665
|
+
children: [
|
|
1666
|
+
data.refreshError ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1667
|
+
designSystem.Alert,
|
|
1668
|
+
{
|
|
1669
|
+
variant: "danger",
|
|
1670
|
+
closeLabel: t("settings.close", "Close"),
|
|
1671
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", size: "S", onClick: data.reload, children: t("settings.retry", "Try again") }),
|
|
1672
|
+
children: t(
|
|
1673
|
+
"settings.blocks.refreshError",
|
|
1674
|
+
"The list could not be refreshed. It shows the last loaded state."
|
|
1675
|
+
)
|
|
1676
|
+
}
|
|
1677
|
+
) : null,
|
|
1678
|
+
importReport && importReport.skipped.length ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1679
|
+
designSystem.Alert,
|
|
1680
|
+
{
|
|
1681
|
+
variant: "warning",
|
|
1682
|
+
closeLabel: t("settings.close", "Close"),
|
|
1683
|
+
onClose: () => setImportReport(null),
|
|
1684
|
+
title: t("settings.blocks.importSkippedTitle", "Some blocks were not imported"),
|
|
1685
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "ul", paddingTop: 1, children: importReport.skipped.map((entry, index2) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "li", variant: "pi", textColor: "neutral800", children: entry.reason === "exists" ? t(
|
|
1686
|
+
"settings.blocks.importSkippedExists",
|
|
1687
|
+
"{name}: a block with this name already exists.",
|
|
1688
|
+
{ name: entry.name || "?" }
|
|
1689
|
+
) : t("settings.blocks.importSkippedInvalid", "{name}: the definition is not valid.", {
|
|
1690
|
+
name: entry.name || "?"
|
|
1691
|
+
}) }, `${entry.name}-${index2}`)) })
|
|
1692
|
+
}
|
|
1693
|
+
) : null,
|
|
1694
|
+
data.blocks.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(useT.SectionCard, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1695
|
+
designSystem.EmptyStateLayout,
|
|
1696
|
+
{
|
|
1697
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(symbols.EmptyDocuments, { width: "16rem", height: "8.8rem" }),
|
|
1698
|
+
content: t(
|
|
1699
|
+
"settings.blocks.empty",
|
|
1700
|
+
"No custom blocks yet. Blocks you create here appear in the editor toolbox of every Magic Editor X field."
|
|
1701
|
+
),
|
|
1702
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1703
|
+
designSystem.Button,
|
|
1704
|
+
{
|
|
1705
|
+
variant: "secondary",
|
|
1706
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
|
|
1707
|
+
onClick: () => setModal((current) => ({ open: true, block: null, key: current.key + 1 })),
|
|
1708
|
+
children: t("settings.blocks.create", "Create block")
|
|
1709
|
+
}
|
|
1710
|
+
)
|
|
1711
|
+
}
|
|
1712
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1713
|
+
BlockList,
|
|
1714
|
+
{
|
|
1715
|
+
blocks: data.blocks,
|
|
1716
|
+
busyId,
|
|
1717
|
+
onEdit: (block) => setModal((current) => ({ open: true, block, key: current.key + 1 })),
|
|
1718
|
+
onDuplicate,
|
|
1719
|
+
onMove,
|
|
1720
|
+
onDelete,
|
|
1721
|
+
onToggle,
|
|
1722
|
+
fallbackFocusRef: createRef
|
|
1723
|
+
}
|
|
1724
|
+
),
|
|
1725
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1726
|
+
BlockFormModal,
|
|
1727
|
+
{
|
|
1728
|
+
open: modal.open,
|
|
1729
|
+
block: modal.block,
|
|
1730
|
+
otherNames,
|
|
1731
|
+
contentTypes: data.contentTypes,
|
|
1732
|
+
onRetryContentTypes: data.reloadContentTypes,
|
|
1733
|
+
onSubmit,
|
|
1734
|
+
onClose: () => setModal((current) => ({ ...current, open: false, block: null }))
|
|
1735
|
+
},
|
|
1736
|
+
modal.key
|
|
1737
|
+
)
|
|
1738
|
+
]
|
|
1739
|
+
}
|
|
1740
|
+
);
|
|
1741
|
+
};
|
|
1742
|
+
exports.CustomBlocksPage = CustomBlocksPage;
|
|
1743
|
+
exports.default = CustomBlocksPage;
|