magic-editor-x 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/README.md +493 -168
- package/dist/admin/{ConfigurationPage-3Dir3dAf.mjs → ConfigurationPage-BxLHIQdo.mjs} +450 -21
- package/dist/admin/{ConfigurationPage-YvnPnna6.js → ConfigurationPage-C-UktL1x.js} +479 -50
- package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
- package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
- package/dist/admin/{CustomBlocksPage-BiiL2ORG.js → CustomBlocksPage-CxcTfdOT.js} +135 -84
- package/dist/admin/{CustomBlocksPage-CR2BaP9O.mjs → CustomBlocksPage-D8aMbVXc.mjs} +92 -41
- package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
- package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
- package/dist/admin/TemplatesPage-Hn6gyu2l.js +993 -0
- package/dist/admin/TemplatesPage-jhYi6Zdf.mjs +993 -0
- package/dist/admin/{de-BmmLBJli.mjs → de-1cFMs-4c.mjs} +2 -0
- package/dist/admin/{de-BteRx2iA.js → de-2Ie5jy7j.js} +79 -1
- package/dist/admin/{de-62Vxb2iw.js → de-B1X46JJZ.js} +205 -2
- package/dist/admin/{de-CFX5atOk.mjs → de-BMY2LBaa.mjs} +79 -1
- package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
- package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
- package/dist/admin/{de-BVvwSYYO.mjs → de-DOiGaTNX.mjs} +205 -2
- package/dist/admin/{de-DaJwN6nk.js → de-Dn8athM8.js} +2 -0
- package/dist/admin/{en-CyjAcccB.js → en-Ah-Cw0Wd.js} +79 -1
- package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
- package/dist/admin/{en-VlkaIzrM.js → en-CDg_18Bt.js} +205 -2
- package/dist/admin/{en-Cn78RZs-.js → en-CIZ5Ggod.js} +2 -0
- package/dist/admin/{en-Cg2Ak5Cr.mjs → en-CU6UzV4g.mjs} +205 -2
- package/dist/admin/{en-ea0tfA5i.mjs → en-CvFiqti2.mjs} +79 -1
- package/dist/admin/{en-D7mZWLGp.mjs → en-Dc9y-6n9.mjs} +2 -0
- package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
- package/dist/admin/{es-BT9oAcHf.js → es-BCpJmUEM.js} +205 -2
- package/dist/admin/{es-C9-cXdb6.mjs → es-BmfffNM2.mjs} +205 -2
- package/dist/admin/{es-BmGtLkJD.js → es-C4IRHV5d.js} +2 -0
- package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
- package/dist/admin/{es-C8GZFGjv.js → es-Cr8JH85N.js} +79 -1
- package/dist/admin/{es-joykG5I9.mjs → es-D2Kw6E4N.mjs} +2 -0
- package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
- package/dist/admin/{es-CEi_ycX8.mjs → es-DbKHZz5l.mjs} +79 -1
- package/dist/admin/{fr-CrzxGe5e.mjs → fr-BOvvfEH7.mjs} +2 -0
- package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
- package/dist/admin/{fr-BAMSvQbR.mjs → fr-DQJ_7aq5.mjs} +79 -1
- package/dist/admin/{fr-DpU_qiXR.mjs → fr-DZd2XJP6.mjs} +205 -2
- package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
- package/dist/admin/{fr-oRCJNdeJ.js → fr-OJ4VW1kh.js} +79 -1
- package/dist/admin/{fr-D6KJqPWi.js → fr-ZcN0yM_2.js} +205 -2
- package/dist/admin/{fr-Ct_uPqxV.js → fr-Zkb8vfjN.js} +2 -0
- package/dist/admin/index-BHBRr562.js +1940 -0
- package/dist/admin/index-CQk1XeNb.mjs +1939 -0
- package/dist/admin/{EditorField-Diq1j8kc.js → index-Cm-fFUhE.js} +13704 -6766
- package/dist/admin/{EditorField-B8pyAxPE.mjs → index-XgfwqLfV.mjs} +10203 -3265
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{pt-chN2jrXl.js → pt-1IUyx6ae.js} +2 -0
- package/dist/admin/{pt-CQrfqsCN.mjs → pt-BSLzA17U.mjs} +79 -1
- package/dist/admin/{pt-jUqOR7Xh.mjs → pt-C3UdeIpd.mjs} +205 -2
- package/dist/admin/{pt-BOrl6x-r.js → pt-CImqDnLB.js} +205 -2
- package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
- package/dist/admin/{pt-tUeJ2Ywd.js → pt-D0I0_JYs.js} +79 -1
- package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
- package/dist/admin/{pt-Ga-4Hsv0.mjs → pt-etwsg3G4.mjs} +2 -0
- package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
- package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
- package/dist/admin/useT-CmaeZbCr.mjs +65 -0
- package/dist/admin/{useT-BWZ_-Hel.js → useT-D3sM9Zf7.js} +4 -70
- package/dist/blocks/index.d.mts +167 -0
- package/dist/blocks/index.d.ts +167 -0
- package/dist/blocks/index.js +631 -0
- package/dist/blocks/index.mjs +609 -0
- package/dist/react/index.d.mts +39 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.js +2687 -0
- package/dist/react/index.mjs +2657 -0
- package/dist/render/index.d.mts +131 -5
- package/dist/render/index.d.ts +131 -5
- package/dist/render/index.js +1679 -181
- package/dist/render/index.mjs +1679 -181
- package/dist/server/index.js +10645 -3716
- package/dist/server/index.mjs +10645 -3716
- package/dist/vue/index.d.mts +41 -0
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.js +2630 -0
- package/dist/vue/index.mjs +2610 -0
- package/package.json +30 -6
- package/schema/magic-editor-x.schema.json +540 -1
- package/types/blocks.d.ts +167 -0
- package/types/index.d.ts +127 -0
- package/types/react.d.ts +39 -0
- package/types/render.d.ts +131 -5
- package/types/vue.d.ts +41 -0
- package/dist/admin/api-Dsq53giv.js +0 -37
- package/dist/admin/api-RZ0Fz0BD.mjs +0 -38
- package/dist/admin/index-C-lyON1B.mjs +0 -303
- package/dist/admin/index-iA0lued_.js +0 -302
- package/dist/admin/sanitize-Cb4jvBhj.js +0 -628
- package/dist/admin/sanitize-ClkX823p.mjs +0 -627
- package/dist/admin/useT-pvHmgBFj.mjs +0 -131
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef } from "react";
|
|
3
|
+
import { Dialog, Button } from "@strapi/design-system";
|
|
4
|
+
import { ConfirmDialog } from "@strapi/strapi/admin";
|
|
5
|
+
const API = {
|
|
6
|
+
config: "/magic-editor-x/config",
|
|
7
|
+
link: "/magic-editor-x/link",
|
|
8
|
+
imageByFile: "/magic-editor-x/image/byFile",
|
|
9
|
+
imageByUrl: "/magic-editor-x/image/byUrl",
|
|
10
|
+
fileUpload: "/magic-editor-x/file/upload",
|
|
11
|
+
contentTypes: "/magic-editor-x/content-types",
|
|
12
|
+
linkTypes: "/magic-editor-x/links/types",
|
|
13
|
+
linkSearch: "/magic-editor-x/links/search",
|
|
14
|
+
qualityLinks: "/magic-editor-x/quality/links",
|
|
15
|
+
qualityLinkReport: "/magic-editor-x/quality/link-report",
|
|
16
|
+
customBlocks: "/magic-editor-x/custom-blocks",
|
|
17
|
+
customBlocksExport: "/magic-editor-x/custom-blocks/export",
|
|
18
|
+
customBlocksImport: "/magic-editor-x/custom-blocks/import",
|
|
19
|
+
customBlocksOrder: "/magic-editor-x/custom-blocks/order",
|
|
20
|
+
customBlock: (id) => `/magic-editor-x/custom-blocks/${encodeURIComponent(id)}`,
|
|
21
|
+
customBlockDuplicate: (id) => `/magic-editor-x/custom-blocks/${encodeURIComponent(id)}/duplicate`,
|
|
22
|
+
collaborationSession: "/magic-editor-x/collaboration/session",
|
|
23
|
+
history: "/magic-editor-x/history",
|
|
24
|
+
historyItem: (id) => `/magic-editor-x/history/${encodeURIComponent(id)}`,
|
|
25
|
+
ai: (action) => `/magic-editor-x/ai/${encodeURIComponent(action)}`,
|
|
26
|
+
aiAltText: "/magic-editor-x/ai/image/alt-text",
|
|
27
|
+
aiField: (action) => `/magic-editor-x/ai/field/${encodeURIComponent(action)}`,
|
|
28
|
+
grammarCheck: "/magic-editor-x/grammar/check",
|
|
29
|
+
comments: "/magic-editor-x/comments",
|
|
30
|
+
comment: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}`,
|
|
31
|
+
commentReplies: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/replies`,
|
|
32
|
+
commentResolve: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/resolve`,
|
|
33
|
+
commentReopen: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/reopen`,
|
|
34
|
+
templates: "/magic-editor-x/templates",
|
|
35
|
+
templateTargets: "/magic-editor-x/templates/targets",
|
|
36
|
+
templatesOrder: "/magic-editor-x/templates/order",
|
|
37
|
+
template: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}`,
|
|
38
|
+
templateDuplicate: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}/duplicate`,
|
|
39
|
+
templateUsage: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}/usage`,
|
|
40
|
+
settings: "/magic-editor-x/settings",
|
|
41
|
+
settingsAiTest: "/magic-editor-x/settings/ai/test",
|
|
42
|
+
settingsLanguageToolTest: "/magic-editor-x/settings/language-tool/test"
|
|
43
|
+
};
|
|
44
|
+
const readApiError = (error) => {
|
|
45
|
+
const response = error && error.response;
|
|
46
|
+
const body = response && response.data;
|
|
47
|
+
const apiError = body && body.error;
|
|
48
|
+
const status = response && response.status || (error && typeof error.status === "number" ? error.status : null) || (apiError && typeof apiError.status === "number" ? apiError.status : null);
|
|
49
|
+
return {
|
|
50
|
+
status: status || null,
|
|
51
|
+
message: apiError && apiError.message || body && body.message || null,
|
|
52
|
+
code: apiError && apiError.details && apiError.details.code || null,
|
|
53
|
+
details: apiError && apiError.details || null
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const canTakeFocus = (el) => Boolean(
|
|
57
|
+
el && el.isConnected && typeof el.focus === "function" && !el.disabled && (typeof el.getAttribute !== "function" || el.getAttribute("aria-disabled") !== "true")
|
|
58
|
+
);
|
|
59
|
+
const pickFocusTarget = (opener, fallback) => {
|
|
60
|
+
if (canTakeFocus(opener)) return opener;
|
|
61
|
+
if (canTakeFocus(fallback)) return fallback;
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const refocusIfLost = (opener, fallback, doc = globalThis.document) => {
|
|
65
|
+
if (!doc) return;
|
|
66
|
+
const active = doc.activeElement;
|
|
67
|
+
if (active && active !== doc.body) return;
|
|
68
|
+
const target = pickFocusTarget(opener, fallback);
|
|
69
|
+
if (target) target.focus();
|
|
70
|
+
};
|
|
71
|
+
const ConfirmAction = ({
|
|
72
|
+
trigger,
|
|
73
|
+
title,
|
|
74
|
+
body,
|
|
75
|
+
confirmLabel,
|
|
76
|
+
onConfirm,
|
|
77
|
+
variant = "danger",
|
|
78
|
+
disabled = false,
|
|
79
|
+
fallbackFocusRef
|
|
80
|
+
}) => {
|
|
81
|
+
const [open, setOpen] = useState(false);
|
|
82
|
+
const [busy, setBusy] = useState(false);
|
|
83
|
+
const triggerRef = useRef(null);
|
|
84
|
+
const restoreFocus = () => requestAnimationFrame(() => {
|
|
85
|
+
const active = document.activeElement;
|
|
86
|
+
if (active && active !== document.body) return;
|
|
87
|
+
const target = pickFocusTarget(triggerRef.current, fallbackFocusRef && fallbackFocusRef.current);
|
|
88
|
+
if (target) target.focus();
|
|
89
|
+
});
|
|
90
|
+
const onOpenChange = (next) => {
|
|
91
|
+
if (busy) return;
|
|
92
|
+
setOpen(next);
|
|
93
|
+
if (!next) restoreFocus();
|
|
94
|
+
};
|
|
95
|
+
const confirm = async (event) => {
|
|
96
|
+
if (event && typeof event.preventDefault === "function") event.preventDefault();
|
|
97
|
+
setBusy(true);
|
|
98
|
+
try {
|
|
99
|
+
await onConfirm();
|
|
100
|
+
setOpen(false);
|
|
101
|
+
restoreFocus();
|
|
102
|
+
} catch {
|
|
103
|
+
} finally {
|
|
104
|
+
setBusy(false);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ jsxs(Dialog.Root, { open, onOpenChange, children: [
|
|
108
|
+
/* @__PURE__ */ jsx(Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }),
|
|
109
|
+
/* @__PURE__ */ jsx(
|
|
110
|
+
ConfirmDialog,
|
|
111
|
+
{
|
|
112
|
+
title,
|
|
113
|
+
variant,
|
|
114
|
+
endAction: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant, onClick: confirm, loading: busy, disabled: busy, children: confirmLabel }),
|
|
115
|
+
children: body
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
] });
|
|
119
|
+
};
|
|
120
|
+
export {
|
|
121
|
+
API as A,
|
|
122
|
+
ConfirmAction as C,
|
|
123
|
+
refocusIfLost as a,
|
|
124
|
+
readApiError as r
|
|
125
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const ReactNamespace = require("react");
|
|
4
|
+
const designSystem = require("@strapi/design-system");
|
|
5
|
+
const admin = require("@strapi/strapi/admin");
|
|
6
|
+
const API = {
|
|
7
|
+
config: "/magic-editor-x/config",
|
|
8
|
+
link: "/magic-editor-x/link",
|
|
9
|
+
imageByFile: "/magic-editor-x/image/byFile",
|
|
10
|
+
imageByUrl: "/magic-editor-x/image/byUrl",
|
|
11
|
+
fileUpload: "/magic-editor-x/file/upload",
|
|
12
|
+
contentTypes: "/magic-editor-x/content-types",
|
|
13
|
+
linkTypes: "/magic-editor-x/links/types",
|
|
14
|
+
linkSearch: "/magic-editor-x/links/search",
|
|
15
|
+
qualityLinks: "/magic-editor-x/quality/links",
|
|
16
|
+
qualityLinkReport: "/magic-editor-x/quality/link-report",
|
|
17
|
+
customBlocks: "/magic-editor-x/custom-blocks",
|
|
18
|
+
customBlocksExport: "/magic-editor-x/custom-blocks/export",
|
|
19
|
+
customBlocksImport: "/magic-editor-x/custom-blocks/import",
|
|
20
|
+
customBlocksOrder: "/magic-editor-x/custom-blocks/order",
|
|
21
|
+
customBlock: (id) => `/magic-editor-x/custom-blocks/${encodeURIComponent(id)}`,
|
|
22
|
+
customBlockDuplicate: (id) => `/magic-editor-x/custom-blocks/${encodeURIComponent(id)}/duplicate`,
|
|
23
|
+
collaborationSession: "/magic-editor-x/collaboration/session",
|
|
24
|
+
history: "/magic-editor-x/history",
|
|
25
|
+
historyItem: (id) => `/magic-editor-x/history/${encodeURIComponent(id)}`,
|
|
26
|
+
ai: (action) => `/magic-editor-x/ai/${encodeURIComponent(action)}`,
|
|
27
|
+
aiAltText: "/magic-editor-x/ai/image/alt-text",
|
|
28
|
+
aiField: (action) => `/magic-editor-x/ai/field/${encodeURIComponent(action)}`,
|
|
29
|
+
grammarCheck: "/magic-editor-x/grammar/check",
|
|
30
|
+
comments: "/magic-editor-x/comments",
|
|
31
|
+
comment: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}`,
|
|
32
|
+
commentReplies: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/replies`,
|
|
33
|
+
commentResolve: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/resolve`,
|
|
34
|
+
commentReopen: (id) => `/magic-editor-x/comments/${encodeURIComponent(id)}/reopen`,
|
|
35
|
+
templates: "/magic-editor-x/templates",
|
|
36
|
+
templateTargets: "/magic-editor-x/templates/targets",
|
|
37
|
+
templatesOrder: "/magic-editor-x/templates/order",
|
|
38
|
+
template: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}`,
|
|
39
|
+
templateDuplicate: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}/duplicate`,
|
|
40
|
+
templateUsage: (id) => `/magic-editor-x/templates/${encodeURIComponent(id)}/usage`,
|
|
41
|
+
settings: "/magic-editor-x/settings",
|
|
42
|
+
settingsAiTest: "/magic-editor-x/settings/ai/test",
|
|
43
|
+
settingsLanguageToolTest: "/magic-editor-x/settings/language-tool/test"
|
|
44
|
+
};
|
|
45
|
+
const readApiError = (error) => {
|
|
46
|
+
const response = error && error.response;
|
|
47
|
+
const body = response && response.data;
|
|
48
|
+
const apiError = body && body.error;
|
|
49
|
+
const status = response && response.status || (error && typeof error.status === "number" ? error.status : null) || (apiError && typeof apiError.status === "number" ? apiError.status : null);
|
|
50
|
+
return {
|
|
51
|
+
status: status || null,
|
|
52
|
+
message: apiError && apiError.message || body && body.message || null,
|
|
53
|
+
code: apiError && apiError.details && apiError.details.code || null,
|
|
54
|
+
details: apiError && apiError.details || null
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const canTakeFocus = (el) => Boolean(
|
|
58
|
+
el && el.isConnected && typeof el.focus === "function" && !el.disabled && (typeof el.getAttribute !== "function" || el.getAttribute("aria-disabled") !== "true")
|
|
59
|
+
);
|
|
60
|
+
const pickFocusTarget = (opener, fallback) => {
|
|
61
|
+
if (canTakeFocus(opener)) return opener;
|
|
62
|
+
if (canTakeFocus(fallback)) return fallback;
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
const refocusIfLost = (opener, fallback, doc = globalThis.document) => {
|
|
66
|
+
if (!doc) return;
|
|
67
|
+
const active = doc.activeElement;
|
|
68
|
+
if (active && active !== doc.body) return;
|
|
69
|
+
const target = pickFocusTarget(opener, fallback);
|
|
70
|
+
if (target) target.focus();
|
|
71
|
+
};
|
|
72
|
+
const ConfirmAction = ({
|
|
73
|
+
trigger,
|
|
74
|
+
title,
|
|
75
|
+
body,
|
|
76
|
+
confirmLabel,
|
|
77
|
+
onConfirm,
|
|
78
|
+
variant = "danger",
|
|
79
|
+
disabled = false,
|
|
80
|
+
fallbackFocusRef
|
|
81
|
+
}) => {
|
|
82
|
+
const [open, setOpen] = ReactNamespace.useState(false);
|
|
83
|
+
const [busy, setBusy] = ReactNamespace.useState(false);
|
|
84
|
+
const triggerRef = ReactNamespace.useRef(null);
|
|
85
|
+
const restoreFocus = () => requestAnimationFrame(() => {
|
|
86
|
+
const active = document.activeElement;
|
|
87
|
+
if (active && active !== document.body) return;
|
|
88
|
+
const target = pickFocusTarget(triggerRef.current, fallbackFocusRef && fallbackFocusRef.current);
|
|
89
|
+
if (target) target.focus();
|
|
90
|
+
});
|
|
91
|
+
const onOpenChange = (next) => {
|
|
92
|
+
if (busy) return;
|
|
93
|
+
setOpen(next);
|
|
94
|
+
if (!next) restoreFocus();
|
|
95
|
+
};
|
|
96
|
+
const confirm = async (event) => {
|
|
97
|
+
if (event && typeof event.preventDefault === "function") event.preventDefault();
|
|
98
|
+
setBusy(true);
|
|
99
|
+
try {
|
|
100
|
+
await onConfirm();
|
|
101
|
+
setOpen(false);
|
|
102
|
+
restoreFocus();
|
|
103
|
+
} catch {
|
|
104
|
+
} finally {
|
|
105
|
+
setBusy(false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { open, onOpenChange, children: [
|
|
109
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }),
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
111
|
+
admin.ConfirmDialog,
|
|
112
|
+
{
|
|
113
|
+
title,
|
|
114
|
+
variant,
|
|
115
|
+
endAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { fullWidth: true, variant, onClick: confirm, loading: busy, disabled: busy, children: confirmLabel }),
|
|
116
|
+
children: body
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
] });
|
|
120
|
+
};
|
|
121
|
+
exports.API = API;
|
|
122
|
+
exports.ConfirmAction = ConfirmAction;
|
|
123
|
+
exports.readApiError = readApiError;
|
|
124
|
+
exports.refocusIfLost = refocusIfLost;
|
|
@@ -1,51 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const
|
|
4
|
+
const ReactNamespace = require("react");
|
|
5
5
|
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
|
|
11
|
-
const useT = require("./useT-
|
|
9
|
+
const index = require("./index-BHBRr562.js");
|
|
10
|
+
const ConfirmAction = require("./ConfirmAction-zLuIFj8t.js");
|
|
11
|
+
const useT = require("./useT-D3sM9Zf7.js");
|
|
12
12
|
const styled = require("styled-components");
|
|
13
|
-
const
|
|
13
|
+
const useBreakpoint = require("./useBreakpoint-D30eNTkF.js");
|
|
14
|
+
const reactIntl = require("react-intl");
|
|
14
15
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
15
16
|
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
17
|
const FIELD_TYPES = Object.freeze([
|
|
50
18
|
"text",
|
|
51
19
|
"textarea",
|
|
@@ -58,6 +26,7 @@ const FIELD_TYPES = Object.freeze([
|
|
|
58
26
|
]);
|
|
59
27
|
const TUNES = Object.freeze(["alignmentTune", "textVariant", "indentTune"]);
|
|
60
28
|
const BLOCK_TYPES = Object.freeze(["simple", "embedded-entry"]);
|
|
29
|
+
const LEGACY_NAMES = Object.freeze(["toc", "gallery", "video", "audio", "synced", "mention"]);
|
|
61
30
|
const RESERVED_NAMES = Object.freeze(
|
|
62
31
|
[
|
|
63
32
|
"paragraph",
|
|
@@ -69,11 +38,16 @@ const RESERVED_NAMES = Object.freeze(
|
|
|
69
38
|
"code",
|
|
70
39
|
"codeFlask",
|
|
71
40
|
"delimiter",
|
|
41
|
+
"toc",
|
|
72
42
|
"table",
|
|
73
43
|
"embed",
|
|
74
44
|
"raw",
|
|
75
45
|
"image",
|
|
76
46
|
"simpleImage",
|
|
47
|
+
"gallery",
|
|
48
|
+
"video",
|
|
49
|
+
"audio",
|
|
50
|
+
"synced",
|
|
77
51
|
"linkTool",
|
|
78
52
|
"attaches",
|
|
79
53
|
"personality",
|
|
@@ -89,6 +63,7 @@ const RESERVED_NAMES = Object.freeze(
|
|
|
89
63
|
"strikethrough",
|
|
90
64
|
"tooltip",
|
|
91
65
|
"hyperlink",
|
|
66
|
+
"mention",
|
|
92
67
|
"aiAssistant",
|
|
93
68
|
"textVariant",
|
|
94
69
|
"alignmentTune",
|
|
@@ -232,7 +207,8 @@ const validateBlock = (values, context = {}) => {
|
|
|
232
207
|
const name = String(values.name || "").trim();
|
|
233
208
|
if (!name) errors.name = "required";
|
|
234
209
|
else if (!NAME_PATTERN.test(name)) errors.name = "namePattern";
|
|
235
|
-
else if (RESERVED_NAMES.includes(name.toLowerCase())
|
|
210
|
+
else if (RESERVED_NAMES.includes(name.toLowerCase()) && !(LEGACY_NAMES.includes(name.toLowerCase()) && context.originalName === name))
|
|
211
|
+
errors.name = "reserved";
|
|
236
212
|
else if ((context.existingNames || []).some((other) => other.toLowerCase() === name.toLowerCase()))
|
|
237
213
|
errors.name = "taken";
|
|
238
214
|
const label = String(values.label || "").trim();
|
|
@@ -316,20 +292,20 @@ const fillTemplate = (template, fields) => {
|
|
|
316
292
|
};
|
|
317
293
|
const useCustomBlocks = () => {
|
|
318
294
|
const { get } = admin.useFetchClient();
|
|
319
|
-
const [status, setStatus] =
|
|
320
|
-
const [blocks, setBlocks] =
|
|
321
|
-
const [refreshError, setRefreshError] =
|
|
322
|
-
const [contentTypes, setContentTypes] =
|
|
323
|
-
const mounted =
|
|
324
|
-
const loaded =
|
|
325
|
-
|
|
295
|
+
const [status, setStatus] = ReactNamespace.useState("loading");
|
|
296
|
+
const [blocks, setBlocks] = ReactNamespace.useState([]);
|
|
297
|
+
const [refreshError, setRefreshError] = ReactNamespace.useState(false);
|
|
298
|
+
const [contentTypes, setContentTypes] = ReactNamespace.useState({ status: "loading", items: [] });
|
|
299
|
+
const mounted = ReactNamespace.useRef(true);
|
|
300
|
+
const loaded = ReactNamespace.useRef(false);
|
|
301
|
+
ReactNamespace.useEffect(() => {
|
|
326
302
|
mounted.current = true;
|
|
327
303
|
return () => {
|
|
328
304
|
mounted.current = false;
|
|
329
305
|
};
|
|
330
306
|
}, []);
|
|
331
|
-
const fetchBlocks =
|
|
332
|
-
() => get(
|
|
307
|
+
const fetchBlocks = ReactNamespace.useCallback(
|
|
308
|
+
() => get(ConfirmAction.API.customBlocks, { params: { all: "true" } }).then(
|
|
333
309
|
({ data }) => {
|
|
334
310
|
if (!mounted.current) return;
|
|
335
311
|
setBlocks(Array.isArray(data.data) ? data.data : []);
|
|
@@ -345,8 +321,8 @@ const useCustomBlocks = () => {
|
|
|
345
321
|
),
|
|
346
322
|
[get]
|
|
347
323
|
);
|
|
348
|
-
const fetchContentTypes =
|
|
349
|
-
() => get(
|
|
324
|
+
const fetchContentTypes = ReactNamespace.useCallback(
|
|
325
|
+
() => get(ConfirmAction.API.contentTypes).then(
|
|
350
326
|
({ data }) => {
|
|
351
327
|
if (mounted.current)
|
|
352
328
|
setContentTypes({ status: "ready", items: Array.isArray(data.data) ? data.data : [] });
|
|
@@ -357,15 +333,15 @@ const useCustomBlocks = () => {
|
|
|
357
333
|
),
|
|
358
334
|
[get]
|
|
359
335
|
);
|
|
360
|
-
|
|
336
|
+
ReactNamespace.useEffect(() => {
|
|
361
337
|
fetchBlocks();
|
|
362
338
|
fetchContentTypes();
|
|
363
339
|
}, [fetchBlocks, fetchContentTypes]);
|
|
364
|
-
const load =
|
|
340
|
+
const load = ReactNamespace.useCallback(() => {
|
|
365
341
|
if (!loaded.current) setStatus("loading");
|
|
366
342
|
return fetchBlocks();
|
|
367
343
|
}, [fetchBlocks]);
|
|
368
|
-
const loadContentTypes =
|
|
344
|
+
const loadContentTypes = ReactNamespace.useCallback(() => {
|
|
369
345
|
setContentTypes((current) => ({ ...current, status: "loading" }));
|
|
370
346
|
return fetchContentTypes();
|
|
371
347
|
}, [fetchContentTypes]);
|
|
@@ -456,11 +432,11 @@ const TemplateFrame = styled__default.default(designSystem.Box)`
|
|
|
456
432
|
}
|
|
457
433
|
`;
|
|
458
434
|
const IconPreview = ({ svg, label }) => {
|
|
459
|
-
const clean =
|
|
435
|
+
const clean = ReactNamespace.useMemo(() => index.sanitizeSvg(svg), [svg]);
|
|
460
436
|
return /* @__PURE__ */ jsxRuntime.jsx(IconFrame, { role: "img", "aria-label": label, dangerouslySetInnerHTML: { __html: clean } });
|
|
461
437
|
};
|
|
462
438
|
const TemplatePreview = ({ template, fields, label, empty }) => {
|
|
463
|
-
const clean =
|
|
439
|
+
const clean = ReactNamespace.useMemo(() => index.sanitizeTemplate(fillTemplate(template, fields)), [template, fields]);
|
|
464
440
|
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
465
441
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "p", children: label }),
|
|
466
442
|
/* @__PURE__ */ jsxRuntime.jsx(TemplateFrame, { marginTop: 2, padding: 4, hasRadius: true, borderColor: "neutral200", background: "neutral100", children: clean ? (
|
|
@@ -523,7 +499,7 @@ const RowActions = ({
|
|
|
523
499
|
}
|
|
524
500
|
),
|
|
525
501
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
526
|
-
|
|
502
|
+
ConfirmAction.ConfirmAction,
|
|
527
503
|
{
|
|
528
504
|
fallbackFocusRef,
|
|
529
505
|
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -600,7 +576,7 @@ const BlockList = ({
|
|
|
600
576
|
fallbackFocusRef
|
|
601
577
|
}) => {
|
|
602
578
|
const t = useT.useT();
|
|
603
|
-
const { isBelowLarge } = useBreakpoint();
|
|
579
|
+
const { isBelowLarge } = useBreakpoint.useBreakpoint();
|
|
604
580
|
const actions = { onEdit, onDuplicate, onMove, onDelete, fallbackFocusRef };
|
|
605
581
|
if (isBelowLarge) {
|
|
606
582
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -914,12 +890,16 @@ const BlockFormModal = ({
|
|
|
914
890
|
onClose
|
|
915
891
|
}) => {
|
|
916
892
|
const t = useT.useT();
|
|
917
|
-
const [values, setValues] =
|
|
918
|
-
const [serverErrors, setServerErrors] =
|
|
919
|
-
const [showErrors, setShowErrors] =
|
|
920
|
-
const [saving, setSaving] =
|
|
921
|
-
const
|
|
922
|
-
const
|
|
893
|
+
const [values, setValues] = ReactNamespace.useState(() => block ? fromDto(block) : emptyValues());
|
|
894
|
+
const [serverErrors, setServerErrors] = ReactNamespace.useState({});
|
|
895
|
+
const [showErrors, setShowErrors] = ReactNamespace.useState(false);
|
|
896
|
+
const [saving, setSaving] = ReactNamespace.useState(false);
|
|
897
|
+
const originalName = block ? block.name : null;
|
|
898
|
+
const errors = ReactNamespace.useMemo(
|
|
899
|
+
() => validateBlock(values, { existingNames: otherNames, originalName }),
|
|
900
|
+
[values, otherNames, originalName]
|
|
901
|
+
);
|
|
902
|
+
const visible = ReactNamespace.useMemo(
|
|
923
903
|
() => ({ ...showErrors ? errors : {}, ...serverErrors }),
|
|
924
904
|
[errors, serverErrors, showErrors]
|
|
925
905
|
);
|
|
@@ -1392,21 +1372,91 @@ const BlockFormModal = ({
|
|
|
1392
1372
|
}
|
|
1393
1373
|
);
|
|
1394
1374
|
};
|
|
1375
|
+
const CodeBlocksSection = () => {
|
|
1376
|
+
const t = useT.useT();
|
|
1377
|
+
const { locale } = reactIntl.useIntl();
|
|
1378
|
+
const { get } = admin.useFetchClient();
|
|
1379
|
+
const [server, setServer] = ReactNamespace.useState([]);
|
|
1380
|
+
ReactNamespace.useEffect(() => {
|
|
1381
|
+
let active = true;
|
|
1382
|
+
get(ConfirmAction.API.config).then(
|
|
1383
|
+
({ data }) => {
|
|
1384
|
+
if (active && data && data.data && Array.isArray(data.data.codeBlocks))
|
|
1385
|
+
setServer(data.data.codeBlocks);
|
|
1386
|
+
},
|
|
1387
|
+
() => {
|
|
1388
|
+
}
|
|
1389
|
+
);
|
|
1390
|
+
return () => {
|
|
1391
|
+
active = false;
|
|
1392
|
+
};
|
|
1393
|
+
}, [get]);
|
|
1394
|
+
const rows = ReactNamespace.useMemo(() => index.mergeCodeBlocks(server, index.codeBlocks(), locale), [server, locale]);
|
|
1395
|
+
if (!rows.length) return null;
|
|
1396
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1397
|
+
useT.SectionCard,
|
|
1398
|
+
{
|
|
1399
|
+
title: t("settings.blocks.code.title", "Defined in code"),
|
|
1400
|
+
subtitle: t(
|
|
1401
|
+
"settings.blocks.code.subtitle",
|
|
1402
|
+
"Blocks your app registers in code with the custom block SDK. They are changed in the code and cannot be edited here."
|
|
1403
|
+
),
|
|
1404
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "ul", margin: 0, padding: 0, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 3, children: rows.map((row) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1405
|
+
designSystem.Box,
|
|
1406
|
+
{
|
|
1407
|
+
tag: "li",
|
|
1408
|
+
padding: 4,
|
|
1409
|
+
hasRadius: true,
|
|
1410
|
+
borderColor: "neutral200",
|
|
1411
|
+
background: "neutral100",
|
|
1412
|
+
minWidth: 0,
|
|
1413
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 2, minWidth: 0, children: [
|
|
1414
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", alignItems: "center", children: [
|
|
1415
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "bold", textColor: "neutral800", tag: "h3", children: row.title }),
|
|
1416
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { children: t("settings.blocks.code.badge", "Defined in code") })
|
|
1417
|
+
] }),
|
|
1418
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: [
|
|
1419
|
+
row.name,
|
|
1420
|
+
" ·",
|
|
1421
|
+
" ",
|
|
1422
|
+
t("settings.blocks.code.version", "Version {version}", { version: row.version })
|
|
1423
|
+
] }),
|
|
1424
|
+
row.fields.length ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: t("settings.blocks.code.fields", "Fields: {fields}", {
|
|
1425
|
+
fields: row.fields.map((field) => `${field.key} (${field.type})`).join(", ")
|
|
1426
|
+
}) }) : null,
|
|
1427
|
+
row.presets.length ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("settings.blocks.code.presets", "Also in the presets: {presets}", {
|
|
1428
|
+
presets: row.presets.join(", ")
|
|
1429
|
+
}) }) : null,
|
|
1430
|
+
!row.inAdmin ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "warning600", children: t(
|
|
1431
|
+
"settings.blocks.code.noTool",
|
|
1432
|
+
"No editor tool is registered in the admin, so editors cannot insert this block."
|
|
1433
|
+
) }) : null,
|
|
1434
|
+
!row.onServer ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "warning600", children: t(
|
|
1435
|
+
"settings.blocks.code.noServer",
|
|
1436
|
+
"Not registered on the server: saved content of this block is cleaned with the generic policy."
|
|
1437
|
+
) }) : null
|
|
1438
|
+
] })
|
|
1439
|
+
},
|
|
1440
|
+
row.name
|
|
1441
|
+
)) }) })
|
|
1442
|
+
}
|
|
1443
|
+
);
|
|
1444
|
+
};
|
|
1395
1445
|
const CustomBlocksPage = () => {
|
|
1396
1446
|
const t = useT.useT();
|
|
1397
1447
|
const { post, put, del, get } = admin.useFetchClient();
|
|
1398
1448
|
const { toggleNotification } = admin.useNotification();
|
|
1399
1449
|
const { allowedActions, isLoading: rbacLoading } = admin.useRBAC(index.PERMISSIONS.customBlocksManage);
|
|
1400
1450
|
const data = useCustomBlocks();
|
|
1401
|
-
const [modal, setModal] =
|
|
1402
|
-
const [busyId, setBusyId] =
|
|
1403
|
-
const [exporting, setExporting] =
|
|
1404
|
-
const [importing, setImporting] =
|
|
1405
|
-
const [importReport, setImportReport] =
|
|
1406
|
-
const createRef =
|
|
1407
|
-
const fileRef =
|
|
1451
|
+
const [modal, setModal] = ReactNamespace.useState({ open: false, block: null, key: 0 });
|
|
1452
|
+
const [busyId, setBusyId] = ReactNamespace.useState(null);
|
|
1453
|
+
const [exporting, setExporting] = ReactNamespace.useState(false);
|
|
1454
|
+
const [importing, setImporting] = ReactNamespace.useState(false);
|
|
1455
|
+
const [importReport, setImportReport] = ReactNamespace.useState(null);
|
|
1456
|
+
const createRef = ReactNamespace.useRef(null);
|
|
1457
|
+
const fileRef = ReactNamespace.useRef(null);
|
|
1408
1458
|
const title = t("settings.blocks.title", "Custom blocks");
|
|
1409
|
-
const otherNames =
|
|
1459
|
+
const otherNames = ReactNamespace.useMemo(
|
|
1410
1460
|
() => data.blocks.filter((block) => !modal.block || block.id !== modal.block.id).map((block) => block.name),
|
|
1411
1461
|
[data.blocks, modal.block]
|
|
1412
1462
|
);
|
|
@@ -1435,7 +1485,7 @@ const CustomBlocksPage = () => {
|
|
|
1435
1485
|
] });
|
|
1436
1486
|
}
|
|
1437
1487
|
const failed = (error, fallback) => {
|
|
1438
|
-
const info =
|
|
1488
|
+
const info = ConfirmAction.readApiError(error);
|
|
1439
1489
|
toggleNotification({
|
|
1440
1490
|
type: "danger",
|
|
1441
1491
|
message: info.status === 404 ? t("settings.blocks.notFound", "This block no longer exists.") : fallback
|
|
@@ -1444,8 +1494,8 @@ const CustomBlocksPage = () => {
|
|
|
1444
1494
|
const onSubmit = async (values) => {
|
|
1445
1495
|
const payload = toPayload(values);
|
|
1446
1496
|
try {
|
|
1447
|
-
if (modal.block) await put(
|
|
1448
|
-
else await post(
|
|
1497
|
+
if (modal.block) await put(ConfirmAction.API.customBlock(modal.block.id), payload);
|
|
1498
|
+
else await post(ConfirmAction.API.customBlocks, payload);
|
|
1449
1499
|
toggleNotification({
|
|
1450
1500
|
type: "success",
|
|
1451
1501
|
message: modal.block ? t("settings.blocks.saved", "Block {label} saved.", { label: payload.label }) : t("settings.blocks.created", "Block {label} created.", { label: payload.label })
|
|
@@ -1454,7 +1504,7 @@ const CustomBlocksPage = () => {
|
|
|
1454
1504
|
await data.reload();
|
|
1455
1505
|
return { ok: true };
|
|
1456
1506
|
} catch (error) {
|
|
1457
|
-
const info =
|
|
1507
|
+
const info = ConfirmAction.readApiError(error);
|
|
1458
1508
|
if (info.status === 400) {
|
|
1459
1509
|
toggleNotification({
|
|
1460
1510
|
type: "warning",
|
|
@@ -1475,7 +1525,7 @@ const CustomBlocksPage = () => {
|
|
|
1475
1525
|
const onToggle = async (block, enabled) => {
|
|
1476
1526
|
setBusyId(block.id);
|
|
1477
1527
|
try {
|
|
1478
|
-
const { data: response } = await put(
|
|
1528
|
+
const { data: response } = await put(ConfirmAction.API.customBlock(block.id), withEnabled(block, enabled));
|
|
1479
1529
|
data.setBlocks((current) => current.map((item) => item.id === block.id ? response.data : item));
|
|
1480
1530
|
toggleNotification({
|
|
1481
1531
|
type: "success",
|
|
@@ -1484,7 +1534,7 @@ const CustomBlocksPage = () => {
|
|
|
1484
1534
|
})
|
|
1485
1535
|
});
|
|
1486
1536
|
} catch (error) {
|
|
1487
|
-
const info =
|
|
1537
|
+
const info = ConfirmAction.readApiError(error);
|
|
1488
1538
|
if (info.status === 400) {
|
|
1489
1539
|
toggleNotification({
|
|
1490
1540
|
type: "warning",
|
|
@@ -1502,7 +1552,7 @@ const CustomBlocksPage = () => {
|
|
|
1502
1552
|
const onDuplicate = async (block) => {
|
|
1503
1553
|
setBusyId(block.id);
|
|
1504
1554
|
try {
|
|
1505
|
-
const { data: response } = await post(
|
|
1555
|
+
const { data: response } = await post(ConfirmAction.API.customBlockDuplicate(block.id), {});
|
|
1506
1556
|
toggleNotification({
|
|
1507
1557
|
type: "success",
|
|
1508
1558
|
message: t("settings.blocks.duplicated", "Copy {label} created.", { label: response.data.label })
|
|
@@ -1524,18 +1574,18 @@ const CustomBlocksPage = () => {
|
|
|
1524
1574
|
const opener = typeof document !== "undefined" ? document.activeElement : null;
|
|
1525
1575
|
setBusyId(block.id);
|
|
1526
1576
|
try {
|
|
1527
|
-
const { data: response } = await put(
|
|
1577
|
+
const { data: response } = await put(ConfirmAction.API.customBlocksOrder, { ids });
|
|
1528
1578
|
data.setBlocks(response.data);
|
|
1529
1579
|
} catch (error) {
|
|
1530
1580
|
failed(error, t("settings.blocks.moveError", "The order could not be saved."));
|
|
1531
1581
|
} finally {
|
|
1532
1582
|
setBusyId(null);
|
|
1533
|
-
requestAnimationFrame(() =>
|
|
1583
|
+
requestAnimationFrame(() => ConfirmAction.refocusIfLost(opener, createRef.current));
|
|
1534
1584
|
}
|
|
1535
1585
|
};
|
|
1536
1586
|
const onDelete = async (block) => {
|
|
1537
1587
|
try {
|
|
1538
|
-
await del(
|
|
1588
|
+
await del(ConfirmAction.API.customBlock(block.id));
|
|
1539
1589
|
toggleNotification({
|
|
1540
1590
|
type: "success",
|
|
1541
1591
|
message: t("settings.blocks.deleted", "Block {label} deleted.", { label: block.label })
|
|
@@ -1549,7 +1599,7 @@ const CustomBlocksPage = () => {
|
|
|
1549
1599
|
const onExport = async () => {
|
|
1550
1600
|
setExporting(true);
|
|
1551
1601
|
try {
|
|
1552
|
-
const { data: response } = await get(
|
|
1602
|
+
const { data: response } = await get(ConfirmAction.API.customBlocksExport);
|
|
1553
1603
|
const blob = new Blob([JSON.stringify(response.data, null, 2)], { type: "application/json" });
|
|
1554
1604
|
const url = URL.createObjectURL(blob);
|
|
1555
1605
|
const link = document.createElement("a");
|
|
@@ -1588,7 +1638,7 @@ const CustomBlocksPage = () => {
|
|
|
1588
1638
|
});
|
|
1589
1639
|
return;
|
|
1590
1640
|
}
|
|
1591
|
-
const { data: response } = await post(
|
|
1641
|
+
const { data: response } = await post(ConfirmAction.API.customBlocksImport, parsed);
|
|
1592
1642
|
const { created, skipped } = response.data;
|
|
1593
1643
|
setImportReport({ created, skipped });
|
|
1594
1644
|
toggleNotification({
|
|
@@ -1600,7 +1650,7 @@ const CustomBlocksPage = () => {
|
|
|
1600
1650
|
});
|
|
1601
1651
|
await data.reload();
|
|
1602
1652
|
} catch (error) {
|
|
1603
|
-
const info =
|
|
1653
|
+
const info = ConfirmAction.readApiError(error);
|
|
1604
1654
|
toggleNotification({
|
|
1605
1655
|
type: "danger",
|
|
1606
1656
|
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.")
|
|
@@ -1722,6 +1772,7 @@ const CustomBlocksPage = () => {
|
|
|
1722
1772
|
fallbackFocusRef: createRef
|
|
1723
1773
|
}
|
|
1724
1774
|
),
|
|
1775
|
+
/* @__PURE__ */ jsxRuntime.jsx(CodeBlocksSection, {}),
|
|
1725
1776
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1726
1777
|
BlockFormModal,
|
|
1727
1778
|
{
|