magic-editor-x 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/README.md +315 -103
- package/bin/magic-editor-x.mjs +190 -0
- package/dist/admin/{ConfigurationPage-DvAifELO.mjs → ConfigurationPage-3Dir3dAf.mjs} +126 -7
- package/dist/admin/{ConfigurationPage-B1uCIE3J.js → ConfigurationPage-YvnPnna6.js} +125 -4
- package/dist/admin/{CustomBlocksPage-6eWCOreU.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
- package/dist/admin/{CustomBlocksPage-6-OQwpXQ.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
- package/dist/admin/EditorField-B8pyAxPE.mjs +11935 -0
- package/dist/admin/EditorField-Diq1j8kc.js +11970 -0
- package/dist/admin/{api-B-RsxJCs.js → api-Dsq53giv.js} +3 -0
- package/dist/admin/{api-C4XsDZxd.mjs → api-RZ0Fz0BD.mjs} +3 -0
- package/dist/admin/de-62Vxb2iw.js +250 -0
- package/dist/admin/de-BVvwSYYO.mjs +250 -0
- package/dist/admin/de-BmmLBJli.mjs +41 -0
- package/dist/admin/{de-BMxADn2Z.mjs → de-Bt6pYIWi.mjs} +16 -1
- package/dist/admin/{de-DcDPRzV4.js → de-BteRx2iA.js} +28 -1
- package/dist/admin/{de-n5V6c5RT.mjs → de-CFX5atOk.mjs} +28 -1
- package/dist/admin/{de-Dx7vUW0Z.js → de-CVbi685U.js} +16 -1
- package/dist/admin/de-DaJwN6nk.js +41 -0
- package/dist/admin/{en-sNn4z9lA.js → en-BX362fTp.js} +16 -1
- package/dist/admin/{en-BQ5Pxe2o.mjs → en-B_HltUxZ.mjs} +16 -1
- package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
- package/dist/admin/en-Cn78RZs-.js +41 -0
- package/dist/admin/{en-D-DGftl0.js → en-CyjAcccB.js} +28 -1
- package/dist/admin/en-D7mZWLGp.mjs +41 -0
- package/dist/admin/en-VlkaIzrM.js +250 -0
- package/dist/admin/{en-BqNm3nMQ.mjs → en-ea0tfA5i.mjs} +28 -1
- package/dist/admin/es-BT9oAcHf.js +250 -0
- package/dist/admin/es-BmGtLkJD.js +41 -0
- package/dist/admin/{es-Di0pyQCh.js → es-C8GZFGjv.js} +28 -1
- package/dist/admin/es-C9-cXdb6.mjs +250 -0
- package/dist/admin/{es-SzeTV4q8.mjs → es-CEi_ycX8.mjs} +28 -1
- package/dist/admin/{es-DVsXnS0N.js → es-CHHEZi44.js} +16 -1
- package/dist/admin/{es-B6NYq0VH.mjs → es-CrhwOq-5.mjs} +16 -1
- package/dist/admin/es-joykG5I9.mjs +41 -0
- package/dist/admin/{fr-DmG3_Cn-.mjs → fr-5djKfQ3s.mjs} +16 -1
- package/dist/admin/{fr-Fwxcj4SM.js → fr-B3SL0TBV.js} +16 -1
- package/dist/admin/{fr-DhgPYHIH.mjs → fr-BAMSvQbR.mjs} +28 -1
- package/dist/admin/fr-CrzxGe5e.mjs +41 -0
- package/dist/admin/fr-Ct_uPqxV.js +41 -0
- package/dist/admin/fr-D6KJqPWi.js +250 -0
- package/dist/admin/fr-DpU_qiXR.mjs +250 -0
- package/dist/admin/{fr-D6F--jIB.js → fr-oRCJNdeJ.js} +28 -1
- package/dist/admin/index-C-lyON1B.mjs +303 -0
- package/dist/admin/index-iA0lued_.js +302 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/pt-BOrl6x-r.js +250 -0
- package/dist/admin/{pt-BbdwHlWF.mjs → pt-BdnY2Cth.mjs} +16 -1
- package/dist/admin/{pt-BvSl1btT.mjs → pt-CQrfqsCN.mjs} +28 -1
- package/dist/admin/{pt-C6nr71Yw.js → pt-EVwCuBUK.js} +16 -1
- package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
- package/dist/admin/pt-chN2jrXl.js +41 -0
- package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
- package/dist/admin/{pt-BPo0ex21.js → pt-tUeJ2Ywd.js} +28 -1
- package/dist/admin/{sanitize-9UVcXFfc.js → sanitize-Cb4jvBhj.js} +88 -12
- package/dist/admin/{sanitize-D4kfZ_ly.mjs → sanitize-ClkX823p.mjs} +89 -13
- package/dist/admin/{useT-B5M49wGH.js → useT-BWZ_-Hel.js} +1 -1
- package/dist/admin/{useT-CjX6fL2m.mjs → useT-pvHmgBFj.mjs} +1 -1
- package/dist/render/index.d.mts +75 -0
- package/dist/render/index.d.ts +75 -0
- package/dist/render/index.js +1420 -0
- package/dist/render/index.mjs +1398 -0
- package/dist/server/index.js +9562 -589
- package/dist/server/index.mjs +9565 -592
- package/package.json +21 -4
- package/schema/magic-editor-x.schema.json +967 -0
- package/types/index.d.ts +211 -0
- package/types/render.d.ts +75 -0
- package/dist/admin/EditorField-DocyD2Q3.js +0 -5506
- package/dist/admin/EditorField-ThSoOCPm.mjs +0 -5471
- package/dist/admin/de-B8XFFhHh.js +0 -95
- package/dist/admin/de-DBR893G4.js +0 -13
- package/dist/admin/de-RAxzvrwm.mjs +0 -95
- package/dist/admin/de-fBFh09Wl.mjs +0 -13
- package/dist/admin/en-BzfyifEU.mjs +0 -95
- package/dist/admin/en-D9Nfccux.mjs +0 -13
- package/dist/admin/en-DcWUTE2J.js +0 -95
- package/dist/admin/en-gueRT44P.js +0 -13
- package/dist/admin/es-B0Zy8DVg.mjs +0 -13
- package/dist/admin/es-BOtVc9qv.js +0 -95
- package/dist/admin/es-C2OJVYkV.mjs +0 -95
- package/dist/admin/es-DRGs7meF.js +0 -13
- package/dist/admin/fr-B8rdLAIL.js +0 -13
- package/dist/admin/fr-Bpo5Uq1f.mjs +0 -95
- package/dist/admin/fr-DfxKaOc_.js +0 -95
- package/dist/admin/fr-oiUb2bb_.mjs +0 -13
- package/dist/admin/index-CwfaB5-e.js +0 -155
- package/dist/admin/index-D1Q5Rlt6.mjs +0 -156
- package/dist/admin/pt-B3Jce6uT.mjs +0 -13
- package/dist/admin/pt-BiWuSBcH.js +0 -13
- package/dist/admin/pt-DqCXuI4S.mjs +0 -95
- package/dist/admin/pt-LCvjwk0y.js +0 -95
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of a stored Magic Editor X field value (`magic-editor-x/types`).
|
|
3
|
+
*
|
|
4
|
+
* They match the JSON Schema `magic-editor-x/schema` and the server's
|
|
5
|
+
* sanitising policy. Strings marked `InlineHtml` contain inline HTML limited to
|
|
6
|
+
* b, strong, i, em, u, s, mark, code, a, br, span, sub and sup; render them
|
|
7
|
+
* with `magic-editor-x/render` or your own sanitiser, never as trusted HTML.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Inline HTML (see the file header). */
|
|
11
|
+
export type InlineHtml = string;
|
|
12
|
+
/** http(s), mailto, tel or site-relative URL; '' when the stored URL was not allowed. */
|
|
13
|
+
export type Url = string;
|
|
14
|
+
|
|
15
|
+
export interface MagicEditorXTunes {
|
|
16
|
+
alignmentTune?: { alignment: 'left' | 'center' | 'right' | 'justify' };
|
|
17
|
+
textVariant?: '' | 'call-out' | 'citation' | 'details';
|
|
18
|
+
indentTune?: { indentLevel: number };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ListCounterType = 'numeric' | 'lower-roman' | 'upper-roman' | 'lower-alpha' | 'upper-alpha';
|
|
22
|
+
|
|
23
|
+
export interface ListItem {
|
|
24
|
+
content: InlineHtml;
|
|
25
|
+
meta?: { checked?: boolean; start?: number; counterType?: ListCounterType };
|
|
26
|
+
items: Array<ListItem | InlineHtml>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ParagraphData {
|
|
30
|
+
text: InlineHtml;
|
|
31
|
+
}
|
|
32
|
+
export interface HeaderData {
|
|
33
|
+
text: InlineHtml;
|
|
34
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
35
|
+
}
|
|
36
|
+
export interface QuoteData {
|
|
37
|
+
text: InlineHtml;
|
|
38
|
+
caption: InlineHtml;
|
|
39
|
+
alignment: 'left' | 'center';
|
|
40
|
+
}
|
|
41
|
+
export interface ListData {
|
|
42
|
+
style: 'ordered' | 'unordered' | 'checklist';
|
|
43
|
+
items: Array<ListItem | InlineHtml>;
|
|
44
|
+
meta?: { start?: number; counterType?: ListCounterType };
|
|
45
|
+
}
|
|
46
|
+
export interface ChecklistData {
|
|
47
|
+
items: Array<{ text: InlineHtml; checked: boolean }>;
|
|
48
|
+
}
|
|
49
|
+
export interface WarningData {
|
|
50
|
+
title: InlineHtml;
|
|
51
|
+
message: InlineHtml;
|
|
52
|
+
}
|
|
53
|
+
export interface AlertData {
|
|
54
|
+
type: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger' | 'light' | 'dark';
|
|
55
|
+
align: 'left' | 'center' | 'right';
|
|
56
|
+
message: InlineHtml;
|
|
57
|
+
}
|
|
58
|
+
export interface ToggleData {
|
|
59
|
+
text: InlineHtml;
|
|
60
|
+
status: 'open' | 'closed';
|
|
61
|
+
fk?: string;
|
|
62
|
+
/** Number of blocks right after the toggle that form its content. */
|
|
63
|
+
items: number;
|
|
64
|
+
}
|
|
65
|
+
export interface CodeData {
|
|
66
|
+
code: string;
|
|
67
|
+
}
|
|
68
|
+
export interface CodeFlaskData {
|
|
69
|
+
code: string;
|
|
70
|
+
language: string;
|
|
71
|
+
showlinenumbers?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface RawData {
|
|
74
|
+
/** Raw HTML, sanitised or emptied according to the server's `rawHtml` option. */
|
|
75
|
+
html: string;
|
|
76
|
+
}
|
|
77
|
+
export interface TableData {
|
|
78
|
+
withHeadings: boolean;
|
|
79
|
+
stretched: boolean;
|
|
80
|
+
content: InlineHtml[][];
|
|
81
|
+
}
|
|
82
|
+
export interface MediaFormat {
|
|
83
|
+
url: Url;
|
|
84
|
+
width?: number;
|
|
85
|
+
height?: number;
|
|
86
|
+
[key: string]: unknown;
|
|
87
|
+
}
|
|
88
|
+
export interface ImageFile {
|
|
89
|
+
url: Url;
|
|
90
|
+
/** Media Library file id. */
|
|
91
|
+
id?: number | string;
|
|
92
|
+
documentId?: string;
|
|
93
|
+
alt?: string;
|
|
94
|
+
mime?: string;
|
|
95
|
+
name?: string;
|
|
96
|
+
hash?: string;
|
|
97
|
+
ext?: string;
|
|
98
|
+
width?: number;
|
|
99
|
+
height?: number;
|
|
100
|
+
size?: number;
|
|
101
|
+
formats?: Record<string, MediaFormat>;
|
|
102
|
+
}
|
|
103
|
+
export interface ImageData {
|
|
104
|
+
file: ImageFile;
|
|
105
|
+
caption: InlineHtml;
|
|
106
|
+
withBorder: boolean;
|
|
107
|
+
withBackground: boolean;
|
|
108
|
+
stretched: boolean;
|
|
109
|
+
/** True when the image is decorative (rendered with an empty alt). */
|
|
110
|
+
decorative?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface SimpleImageData {
|
|
113
|
+
url: Url;
|
|
114
|
+
caption: InlineHtml;
|
|
115
|
+
withBorder: boolean;
|
|
116
|
+
withBackground: boolean;
|
|
117
|
+
stretched: boolean;
|
|
118
|
+
/** Alternative text. */
|
|
119
|
+
alt?: string;
|
|
120
|
+
/** True when the image is decorative (rendered with an empty alt). */
|
|
121
|
+
decorative?: boolean;
|
|
122
|
+
}
|
|
123
|
+
export interface LinkToolData {
|
|
124
|
+
link: Url;
|
|
125
|
+
meta: { title: string; description: string; site_name?: string; image?: { url: Url } };
|
|
126
|
+
}
|
|
127
|
+
export interface AttachesData {
|
|
128
|
+
file: { url: Url; name?: string; extension?: string; size?: number; title?: string };
|
|
129
|
+
title: string;
|
|
130
|
+
}
|
|
131
|
+
export interface EmbedData {
|
|
132
|
+
service: string;
|
|
133
|
+
source: Url;
|
|
134
|
+
embed: Url;
|
|
135
|
+
width?: number;
|
|
136
|
+
height?: number;
|
|
137
|
+
caption: InlineHtml;
|
|
138
|
+
}
|
|
139
|
+
export interface PersonalityData {
|
|
140
|
+
name: string;
|
|
141
|
+
description: string;
|
|
142
|
+
link: Url;
|
|
143
|
+
photo: Url;
|
|
144
|
+
}
|
|
145
|
+
export interface ButtonData {
|
|
146
|
+
text: string;
|
|
147
|
+
link: Url;
|
|
148
|
+
style: 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' | 'success';
|
|
149
|
+
openInNewTab: boolean;
|
|
150
|
+
}
|
|
151
|
+
export type DelimiterData = Record<string, never>;
|
|
152
|
+
|
|
153
|
+
/** Data per built-in block type. */
|
|
154
|
+
export interface BlockDataMap {
|
|
155
|
+
paragraph: ParagraphData;
|
|
156
|
+
header: HeaderData;
|
|
157
|
+
quote: QuoteData;
|
|
158
|
+
list: ListData;
|
|
159
|
+
checklist: ChecklistData;
|
|
160
|
+
warning: WarningData;
|
|
161
|
+
alert: AlertData;
|
|
162
|
+
toggle: ToggleData;
|
|
163
|
+
code: CodeData;
|
|
164
|
+
codeFlask: CodeFlaskData;
|
|
165
|
+
raw: RawData;
|
|
166
|
+
table: TableData;
|
|
167
|
+
image: ImageData;
|
|
168
|
+
simpleImage: SimpleImageData;
|
|
169
|
+
linkTool: LinkToolData;
|
|
170
|
+
attaches: AttachesData;
|
|
171
|
+
embed: EmbedData;
|
|
172
|
+
personality: PersonalityData;
|
|
173
|
+
button: ButtonData;
|
|
174
|
+
delimiter: DelimiterData;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type BuiltInBlockType = keyof BlockDataMap;
|
|
178
|
+
|
|
179
|
+
/** A built-in block, discriminated by `type`. */
|
|
180
|
+
export type BuiltInBlock = {
|
|
181
|
+
[T in BuiltInBlockType]: { id: string; type: T; data: BlockDataMap[T]; tunes?: MagicEditorXTunes };
|
|
182
|
+
}[BuiltInBlockType];
|
|
183
|
+
|
|
184
|
+
/** A custom block defined in Settings > Magic Editor X > Custom blocks. */
|
|
185
|
+
export interface CustomBlock {
|
|
186
|
+
id: string;
|
|
187
|
+
type: string;
|
|
188
|
+
data: Record<string, unknown>;
|
|
189
|
+
tunes?: MagicEditorXTunes;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type MagicEditorXBlock = BuiltInBlock | CustomBlock;
|
|
193
|
+
|
|
194
|
+
/** Stored value of a Magic Editor X field (`null` when empty). */
|
|
195
|
+
export interface MagicEditorXData {
|
|
196
|
+
time: number;
|
|
197
|
+
blocks: MagicEditorXBlock[];
|
|
198
|
+
version: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type MagicEditorXValue = MagicEditorXData | null;
|
|
202
|
+
|
|
203
|
+
export type {
|
|
204
|
+
RenderOptions,
|
|
205
|
+
InternalLinkRef,
|
|
206
|
+
RenderBlock,
|
|
207
|
+
HtmlHelpers,
|
|
208
|
+
renderHtml,
|
|
209
|
+
renderText,
|
|
210
|
+
renderMarkdown,
|
|
211
|
+
} from './render.js';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Types of `magic-editor-x/render`. */
|
|
2
|
+
|
|
3
|
+
import type { ImageFile, MagicEditorXTunes } from './index.js';
|
|
4
|
+
|
|
5
|
+
/** Reference of an internal link (`<a data-mex-uid data-mex-document-id data-mex-locale>`). */
|
|
6
|
+
export interface InternalLinkRef {
|
|
7
|
+
uid: string;
|
|
8
|
+
documentId: string;
|
|
9
|
+
locale: string | null;
|
|
10
|
+
/** The href stored when the link was inserted (fallback). */
|
|
11
|
+
href: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Block handed to an override. `data` is cleaned for built-in types and as stored for custom blocks. */
|
|
15
|
+
export interface RenderBlock {
|
|
16
|
+
id: string;
|
|
17
|
+
type: string;
|
|
18
|
+
data: Record<string, any>;
|
|
19
|
+
tunes?: MagicEditorXTunes;
|
|
20
|
+
/** Toggle content. */
|
|
21
|
+
children: RenderBlock[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HtmlHelpers {
|
|
25
|
+
/** Escapes text for HTML. */
|
|
26
|
+
escape(text: unknown): string;
|
|
27
|
+
/** Safe HTML of stored inline HTML (links resolved with `options.links`). */
|
|
28
|
+
inline(html: unknown): string;
|
|
29
|
+
/** Plain text of stored inline HTML. */
|
|
30
|
+
text(html: unknown): string;
|
|
31
|
+
/** Validated URL or ''. */
|
|
32
|
+
url(value: unknown, schemes?: string[]): string;
|
|
33
|
+
/** Renders toggle children. */
|
|
34
|
+
renderChildren(blocks: RenderBlock[]): string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RenderOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Per-type output. Return a string to replace the default output of that
|
|
40
|
+
* block, or undefined to keep it. HTML overrides are responsible for
|
|
41
|
+
* escaping what they output (use the helpers).
|
|
42
|
+
*/
|
|
43
|
+
overrides?: Record<
|
|
44
|
+
string,
|
|
45
|
+
(block: RenderBlock, helpers: HtmlHelpers & Record<string, any>) => string | undefined
|
|
46
|
+
>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves internal links at render time, so links follow slug changes.
|
|
49
|
+
* Return a URL to use it, `false` to render the link text without a link,
|
|
50
|
+
* or null/undefined to keep the stored href. The result is validated.
|
|
51
|
+
*/
|
|
52
|
+
links?: (ref: InternalLinkRef) => string | false | null | undefined;
|
|
53
|
+
/** Refreshes a Media Library file (url, alt, formats) by `file.id`/`documentId`; the result is validated. */
|
|
54
|
+
media?: (file: ImageFile, block: { id: string; type: string }) => ImageFile | null | undefined;
|
|
55
|
+
/** Raw HTML blocks are omitted unless 'allow' and `sanitizeRaw` are both given. */
|
|
56
|
+
rawHtml?: 'omit' | 'allow';
|
|
57
|
+
/** Your HTML sanitiser for raw HTML blocks (for example sanitize-html or DOMPurify). */
|
|
58
|
+
sanitizeRaw?: (html: string) => string;
|
|
59
|
+
/** Hosts allowed in embed iframes (exact match, https only). Defaults to `DEFAULT_EMBED_HOSTS`. */
|
|
60
|
+
embedHosts?: string[];
|
|
61
|
+
/** `sizes` attribute for images with Media Library formats. Default '100vw'. */
|
|
62
|
+
imageSizes?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Renders a stored value to HTML. Empty or invalid input gives ''. */
|
|
66
|
+
export function renderHtml(value: unknown, options?: RenderOptions): string;
|
|
67
|
+
/** Renders a stored value to plain text. */
|
|
68
|
+
export function renderText(value: unknown, options?: RenderOptions): string;
|
|
69
|
+
/** Renders a stored value to Markdown (CommonMark + GFM tables and task lists). */
|
|
70
|
+
export function renderMarkdown(value: unknown, options?: RenderOptions): string;
|
|
71
|
+
export function escapeHtml(text: unknown): string;
|
|
72
|
+
export function escapeMarkdown(text: string): string;
|
|
73
|
+
export function inlineToHtml(html: unknown, options?: Pick<RenderOptions, 'links'>): string;
|
|
74
|
+
export function inlineToText(html: unknown): string;
|
|
75
|
+
export const DEFAULT_EMBED_HOSTS: readonly string[];
|