magic-editor-x 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +593 -142
  3. package/bin/magic-editor-x.mjs +190 -0
  4. package/dist/admin/{ConfigurationPage-CK2AbfGW.mjs → ConfigurationPage-BxLHIQdo.mjs} +450 -21
  5. package/dist/admin/{ConfigurationPage-CzsT_dO_.js → ConfigurationPage-C-UktL1x.js} +479 -50
  6. package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
  7. package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
  8. package/dist/admin/{CustomBlocksPage-CvLrsBds.js → CustomBlocksPage-CxcTfdOT.js} +135 -84
  9. package/dist/admin/{CustomBlocksPage-B2A8S5MV.mjs → CustomBlocksPage-D8aMbVXc.mjs} +92 -41
  10. package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
  11. package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
  12. package/dist/admin/TemplatesPage-Hn6gyu2l.js +993 -0
  13. package/dist/admin/TemplatesPage-jhYi6Zdf.mjs +993 -0
  14. package/dist/admin/de-1cFMs-4c.mjs +43 -0
  15. package/dist/admin/{de-CkUYGb7U.js → de-2Ie5jy7j.js} +86 -2
  16. package/dist/admin/de-B1X46JJZ.js +453 -0
  17. package/dist/admin/{de-rRIutpYJ.mjs → de-BMY2LBaa.mjs} +86 -2
  18. package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
  19. package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
  20. package/dist/admin/de-DOiGaTNX.mjs +453 -0
  21. package/dist/admin/de-Dn8athM8.js +43 -0
  22. package/dist/admin/{en-DulOcmXb.js → en-Ah-Cw0Wd.js} +86 -2
  23. package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
  24. package/dist/admin/en-CDg_18Bt.js +453 -0
  25. package/dist/admin/en-CIZ5Ggod.js +43 -0
  26. package/dist/admin/en-CU6UzV4g.mjs +453 -0
  27. package/dist/admin/{en-Puup8TFi.mjs → en-CvFiqti2.mjs} +86 -2
  28. package/dist/admin/en-Dc9y-6n9.mjs +43 -0
  29. package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
  30. package/dist/admin/es-BCpJmUEM.js +453 -0
  31. package/dist/admin/es-BmfffNM2.mjs +453 -0
  32. package/dist/admin/es-C4IRHV5d.js +43 -0
  33. package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
  34. package/dist/admin/{es-BoQZC86B.js → es-Cr8JH85N.js} +86 -2
  35. package/dist/admin/es-D2Kw6E4N.mjs +43 -0
  36. package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
  37. package/dist/admin/{es-257SSB7f.mjs → es-DbKHZz5l.mjs} +86 -2
  38. package/dist/admin/fr-BOvvfEH7.mjs +43 -0
  39. package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
  40. package/dist/admin/{fr-C5rSdKU4.mjs → fr-DQJ_7aq5.mjs} +86 -2
  41. package/dist/admin/fr-DZd2XJP6.mjs +453 -0
  42. package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
  43. package/dist/admin/{fr-HxFcPpv4.js → fr-OJ4VW1kh.js} +86 -2
  44. package/dist/admin/fr-ZcN0yM_2.js +453 -0
  45. package/dist/admin/fr-Zkb8vfjN.js +43 -0
  46. package/dist/admin/index-BHBRr562.js +1940 -0
  47. package/dist/admin/index-CQk1XeNb.mjs +1939 -0
  48. package/dist/admin/index-Cm-fFUhE.js +18908 -0
  49. package/dist/admin/index-XgfwqLfV.mjs +18873 -0
  50. package/dist/admin/index.js +1 -1
  51. package/dist/admin/index.mjs +2 -2
  52. package/dist/admin/pt-1IUyx6ae.js +43 -0
  53. package/dist/admin/{pt-D6UuEtPy.mjs → pt-BSLzA17U.mjs} +86 -2
  54. package/dist/admin/pt-C3UdeIpd.mjs +453 -0
  55. package/dist/admin/pt-CImqDnLB.js +453 -0
  56. package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
  57. package/dist/admin/{pt-Cjn2Sc9k.js → pt-D0I0_JYs.js} +86 -2
  58. package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
  59. package/dist/admin/pt-etwsg3G4.mjs +43 -0
  60. package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
  61. package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
  62. package/dist/admin/useT-CmaeZbCr.mjs +65 -0
  63. package/dist/admin/{useT-91ruePzq.js → useT-D3sM9Zf7.js} +4 -70
  64. package/dist/blocks/index.d.mts +167 -0
  65. package/dist/blocks/index.d.ts +167 -0
  66. package/dist/blocks/index.js +631 -0
  67. package/dist/blocks/index.mjs +609 -0
  68. package/dist/react/index.d.mts +39 -0
  69. package/dist/react/index.d.ts +39 -0
  70. package/dist/react/index.js +2687 -0
  71. package/dist/react/index.mjs +2657 -0
  72. package/dist/render/index.d.mts +201 -0
  73. package/dist/render/index.d.ts +201 -0
  74. package/dist/render/index.js +2918 -0
  75. package/dist/render/index.mjs +2896 -0
  76. package/dist/server/index.js +19400 -4738
  77. package/dist/server/index.mjs +19403 -4741
  78. package/dist/vue/index.d.mts +41 -0
  79. package/dist/vue/index.d.ts +41 -0
  80. package/dist/vue/index.js +2630 -0
  81. package/dist/vue/index.mjs +2610 -0
  82. package/package.json +49 -8
  83. package/schema/magic-editor-x.schema.json +1506 -0
  84. package/types/blocks.d.ts +167 -0
  85. package/types/index.d.ts +338 -0
  86. package/types/react.d.ts +39 -0
  87. package/types/render.d.ts +201 -0
  88. package/types/vue.d.ts +41 -0
  89. package/dist/admin/EditorField-7YCdXx-v.mjs +0 -6829
  90. package/dist/admin/EditorField-BdBCW15Q.js +0 -6864
  91. package/dist/admin/api-CmccMxlN.js +0 -36
  92. package/dist/admin/api-D5CAH0nh.mjs +0 -37
  93. package/dist/admin/de-BHPyA2S-.mjs +0 -103
  94. package/dist/admin/de-DBR893G4.js +0 -13
  95. package/dist/admin/de-RMs-_SCK.js +0 -103
  96. package/dist/admin/de-fBFh09Wl.mjs +0 -13
  97. package/dist/admin/en-BluCStLw.mjs +0 -103
  98. package/dist/admin/en-C81faOHP.js +0 -103
  99. package/dist/admin/en-D9Nfccux.mjs +0 -13
  100. package/dist/admin/en-gueRT44P.js +0 -13
  101. package/dist/admin/es-B0Zy8DVg.mjs +0 -13
  102. package/dist/admin/es-CQRI2Prp.mjs +0 -103
  103. package/dist/admin/es-D1QzY0JW.js +0 -103
  104. package/dist/admin/es-DRGs7meF.js +0 -13
  105. package/dist/admin/fr-B8rdLAIL.js +0 -13
  106. package/dist/admin/fr-Di3R6gOX.mjs +0 -103
  107. package/dist/admin/fr-R3_MbzT5.js +0 -103
  108. package/dist/admin/fr-oiUb2bb_.mjs +0 -13
  109. package/dist/admin/index-0_b1iroK.mjs +0 -156
  110. package/dist/admin/index-6SZLli70.js +0 -155
  111. package/dist/admin/pt-B3Jce6uT.mjs +0 -13
  112. package/dist/admin/pt-BCW1u_Hp.js +0 -103
  113. package/dist/admin/pt-BiWuSBcH.js +0 -13
  114. package/dist/admin/pt-Cr9AL408.mjs +0 -103
  115. package/dist/admin/sanitize-DP5aeU7V.js +0 -597
  116. package/dist/admin/sanitize-jjCot5PM.mjs +0 -596
  117. package/dist/admin/useT-vgY88N_H.mjs +0 -131
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Custom block SDK (`magic-editor-x/blocks`): one definition per block type
3
+ * for the server, the admin editor tool and the renderers.
4
+ */
5
+
6
+ import type { HtmlHelpers, RenderNode, RenderBlock } from './render.js';
7
+
8
+ export type BlockFieldType = 'text' | 'inline' | 'url' | 'enum' | 'number' | 'boolean' | 'array' | 'object';
9
+
10
+ interface FieldBase {
11
+ /** Human-readable name (JSON Schema `title`, at most 100 characters). */
12
+ label?: string;
13
+ }
14
+ /** Plain text, cut to `max` (default 1000, at most 100000). Rendering escapes it. */
15
+ export interface TextField extends FieldBase {
16
+ type: 'text';
17
+ max?: number;
18
+ multiline?: boolean;
19
+ default?: string;
20
+ }
21
+ /** Inline HTML through the shared inline policy (input cut to `max`, default 10000). */
22
+ export interface InlineField extends FieldBase {
23
+ type: 'inline';
24
+ max?: number;
25
+ default?: string;
26
+ }
27
+ /** URL checked with `sanitizeUrl` (`schemes` default http/https, site-relative allowed unless `relative: false`); '' when not allowed. */
28
+ export interface UrlField extends FieldBase {
29
+ type: 'url';
30
+ schemes?: Array<'http' | 'https' | 'mailto' | 'tel'>;
31
+ relative?: boolean;
32
+ }
33
+ /** One of `values` (1 to 100 strings); invalid values become `default` (first value). */
34
+ export interface EnumField<V extends string = string> extends FieldBase {
35
+ type: 'enum';
36
+ values: readonly V[];
37
+ default?: V;
38
+ }
39
+ /** Finite number in `min..max`; invalid values become `default` (the key is omitted without one). */
40
+ export interface NumberField extends FieldBase {
41
+ type: 'number';
42
+ min?: number;
43
+ max?: number;
44
+ integer?: boolean;
45
+ default?: number;
46
+ }
47
+ export interface BooleanField extends FieldBase {
48
+ type: 'boolean';
49
+ default?: boolean;
50
+ }
51
+ /** At most `max` items (default 50, at most 500); items of another type are dropped. */
52
+ export interface ArrayField extends FieldBase {
53
+ type: 'array';
54
+ items: BlockField;
55
+ max?: number;
56
+ }
57
+ export interface ObjectField extends FieldBase {
58
+ type: 'object';
59
+ fields: BlockSchema;
60
+ }
61
+ export type BlockField =
62
+ TextField | InlineField | UrlField | EnumField | NumberField | BooleanField | ArrayField | ObjectField;
63
+
64
+ /** Field descriptors by key (1 to 50 keys matching `/^[A-Za-z][A-Za-z0-9_]{0,63}$/`, nesting at most 4 levels). */
65
+ export type BlockSchema = Record<string, BlockField>;
66
+
67
+ /** Stored value type of one field. */
68
+ export type FieldValue<F> =
69
+ F extends EnumField<infer V>
70
+ ? V
71
+ : F extends TextField | InlineField | UrlField
72
+ ? string
73
+ : F extends NumberField
74
+ ? number
75
+ : F extends BooleanField
76
+ ? boolean
77
+ : F extends ArrayField
78
+ ? Array<FieldValue<F['items']>>
79
+ : F extends ObjectField
80
+ ? BlockData<F['fields']>
81
+ : unknown;
82
+
83
+ /** Stored `data` of a block with this schema (numbers without a default may be missing). */
84
+ export type BlockData<S extends BlockSchema> = { [K in keyof S]: FieldValue<S[K]> };
85
+
86
+ export interface BlockTextHelpers {
87
+ /** Plain text of inline HTML. */
88
+ text(html: unknown): string;
89
+ }
90
+ export interface BlockMarkdownHelpers extends BlockTextHelpers {
91
+ /** Escapes Markdown punctuation. */
92
+ escape(text: unknown): string;
93
+ /** Markdown of inline HTML (links resolved with `options.links`). */
94
+ inline(html: unknown): string;
95
+ }
96
+
97
+ export interface BlockDefinitionInput<S extends BlockSchema = BlockSchema> {
98
+ /** Block type: `/^[A-Za-z][A-Za-z0-9_-]{1,49}$/`, not a built-in tool name (`RESERVED_BLOCK_NAMES`). */
99
+ name: string;
100
+ /** Integer 1 to 1000000 (default 1); shown in Settings > Custom blocks. */
101
+ version?: number;
102
+ title?: string;
103
+ description?: string;
104
+ schema: S;
105
+ /** Extra cleaning after the schema; its result is cleaned by the schema again. A throw keeps the schema-clean data. */
106
+ sanitize?: (
107
+ data: BlockData<S>,
108
+ helpers: {
109
+ sanitizeUrl(value: unknown, options?: { schemes?: string[]; allowRelative?: boolean }): string;
110
+ }
111
+ ) => BlockData<S>;
112
+ /** Plain text (renderText, search snippets); default: text and inline fields, one per line. */
113
+ text?: (data: BlockData<S>, helpers: BlockTextHelpers) => string;
114
+ /** Markdown (renderMarkdown); escape what you output. Default: text and inline fields as paragraphs. */
115
+ markdown?: (data: BlockData<S>, helpers: BlockMarkdownHelpers) => string;
116
+ /**
117
+ * Render-tree output (HTML, React, Vue): return nodes made with `helpers.h`,
118
+ * `helpers.textNode`, `helpers.inlineNodes` (validated like overrides), `[]`
119
+ * for nothing, or null/undefined for the default rendering. A string is used
120
+ * only with `rawHtml: 'allow'` + `sanitizeRaw`.
121
+ */
122
+ render?: (
123
+ block: RenderBlock & { data: BlockData<S> },
124
+ helpers: HtmlHelpers
125
+ ) => RenderNode | Array<RenderNode | string> | string | null | undefined;
126
+ /** Named presets that include the block (`full` always does). */
127
+ presets?: Array<'article' | 'basic' | 'minimal'>;
128
+ }
129
+
130
+ export type BlockDefinition<S extends BlockSchema = BlockSchema> = Readonly<
131
+ Omit<BlockDefinitionInput<S>, 'version' | 'presets'> & {
132
+ version: number;
133
+ presets: ReadonlyArray<'article' | 'basic' | 'minimal'>;
134
+ }
135
+ >;
136
+
137
+ /** Validates and freezes a definition; throws `BlockDefinitionError` with a clear message. */
138
+ export function defineBlock<const S extends BlockSchema>(
139
+ definition: BlockDefinitionInput<S>
140
+ ): BlockDefinition<S>;
141
+ /** JSON Schema (2020-12) of the block's stored `data`. */
142
+ export function blockJsonSchema(
143
+ definition: BlockDefinition<any> | BlockDefinitionInput<any>
144
+ ): Record<string, unknown>;
145
+ /** Problem with a block name, or null when it can be used. */
146
+ export function blockNameProblem(name: unknown): string | null;
147
+
148
+ export class BlockDefinitionError extends Error {
149
+ name: 'BlockDefinitionError';
150
+ code: 'INVALID_DEFINITION' | 'RESERVED_NAME' | 'NAME_TAKEN' | 'REGISTRY_SEALED';
151
+ }
152
+
153
+ export const BLOCK_FIELD_TYPES: readonly BlockFieldType[];
154
+ export const BLOCK_PRESETS: readonly ['article', 'basic', 'minimal'];
155
+ export const RESERVED_BLOCK_NAMES: readonly string[];
156
+ export const BLOCK_LIMITS: Readonly<{
157
+ maxFields: number;
158
+ maxDepth: number;
159
+ maxText: number;
160
+ defaultText: number;
161
+ defaultInline: number;
162
+ maxItems: number;
163
+ defaultItems: number;
164
+ maxEnumValues: number;
165
+ maxValues: number;
166
+ maxUrl: number;
167
+ }>;
@@ -0,0 +1,338 @@
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
+ /**
104
+ * Focal point of an image in 0..1 (two decimals) from the top left corner.
105
+ * Media Library formats are resized, not cropped, so it applies to every format.
106
+ */
107
+ export interface FocalPoint {
108
+ x: number;
109
+ y: number;
110
+ }
111
+ export interface ImageData {
112
+ file: ImageFile;
113
+ caption: InlineHtml;
114
+ withBorder: boolean;
115
+ withBackground: boolean;
116
+ stretched: boolean;
117
+ /** True when the image is decorative (rendered with an empty alt). */
118
+ decorative?: boolean;
119
+ focalPoint?: FocalPoint;
120
+ }
121
+ export interface SimpleImageData {
122
+ url: Url;
123
+ caption: InlineHtml;
124
+ withBorder: boolean;
125
+ withBackground: boolean;
126
+ stretched: boolean;
127
+ /** Alternative text. */
128
+ alt?: string;
129
+ /** True when the image is decorative (rendered with an empty alt). */
130
+ decorative?: boolean;
131
+ }
132
+ export interface GalleryImage {
133
+ /** Media Library image; `alt` is the alternative text of this image. */
134
+ file: ImageFile;
135
+ caption: InlineHtml;
136
+ /** True when the image is decorative (rendered with an empty alt). */
137
+ decorative?: boolean;
138
+ focalPoint?: FocalPoint;
139
+ }
140
+ export interface GalleryData {
141
+ /** At most 50 images. */
142
+ images: GalleryImage[];
143
+ /** Layout hint for frontends. */
144
+ layout: 'grid' | 'carousel';
145
+ /** Columns of the grid layout (1 to 6, hint). */
146
+ columns: number;
147
+ caption: InlineHtml;
148
+ /**
149
+ * Built-in block marker (2.3 writes 1). Tells the built-in block apart from a
150
+ * custom block created before 2.3 under the same name, whose data is kept as is.
151
+ */
152
+ _mex: number;
153
+ }
154
+ /** Media Library file of a video, audio or text track. */
155
+ export interface MediaFile {
156
+ url: Url;
157
+ id?: number | string;
158
+ documentId?: string;
159
+ mime?: string;
160
+ name?: string;
161
+ hash?: string;
162
+ ext?: string;
163
+ width?: number;
164
+ height?: number;
165
+ size?: number;
166
+ }
167
+ /** WebVTT text track from the Media Library. */
168
+ export interface MediaTrack {
169
+ file: MediaFile;
170
+ kind: 'captions' | 'subtitles' | 'descriptions' | 'chapters';
171
+ /** BCP 47 language tag or ''. */
172
+ srclang: string;
173
+ label: string;
174
+ /** At most one track per block is the default. */
175
+ default?: boolean;
176
+ }
177
+ export interface VideoData {
178
+ /** Media Library video (`video/*`). */
179
+ file: MediaFile;
180
+ /** Media Library image shown before playback. */
181
+ poster?: ImageFile;
182
+ title: string;
183
+ caption: InlineHtml;
184
+ loop: boolean;
185
+ muted: boolean;
186
+ /** At most 8 tracks. */
187
+ tracks: MediaTrack[];
188
+ /**
189
+ * Built-in block marker (2.3 writes 1). Tells the built-in block apart from a
190
+ * custom block created before 2.3 under the same name, whose data is kept as is.
191
+ */
192
+ _mex: number;
193
+ }
194
+ export interface AudioData {
195
+ /** Media Library audio (`audio/*`). */
196
+ file: MediaFile;
197
+ title: string;
198
+ caption: InlineHtml;
199
+ loop: boolean;
200
+ /** At most 8 tracks. */
201
+ tracks: MediaTrack[];
202
+ /**
203
+ * Built-in block marker (2.3 writes 1). Tells the built-in block apart from a
204
+ * custom block created before 2.3 under the same name, whose data is kept as is.
205
+ */
206
+ _mex: number;
207
+ }
208
+ export interface LinkToolData {
209
+ link: Url;
210
+ meta: { title: string; description: string; site_name?: string; image?: { url: Url } };
211
+ }
212
+ export interface AttachesData {
213
+ file: { url: Url; name?: string; extension?: string; size?: number; title?: string };
214
+ title: string;
215
+ }
216
+ export interface EmbedData {
217
+ service: string;
218
+ source: Url;
219
+ embed: Url;
220
+ width?: number;
221
+ height?: number;
222
+ caption: InlineHtml;
223
+ }
224
+ export interface PersonalityData {
225
+ name: string;
226
+ description: string;
227
+ link: Url;
228
+ photo: Url;
229
+ }
230
+ export interface ButtonData {
231
+ text: string;
232
+ link: Url;
233
+ style: 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' | 'success';
234
+ openInNewTab: boolean;
235
+ }
236
+ export type DelimiterData = Record<string, never>;
237
+ /** Table of contents: entries are built from the headings when the content is rendered. */
238
+ export interface TocData {
239
+ /** Plain-text title ('' for none). */
240
+ title: string;
241
+ /** Lowest heading level listed (1 to 6, at most `maxLevel`). */
242
+ minLevel: number;
243
+ /** Highest heading level listed (1 to 6). */
244
+ maxLevel: number;
245
+ style: 'ordered' | 'unordered';
246
+ /**
247
+ * Built-in block marker (2.3 writes 1). Tells the built-in block apart from a
248
+ * custom block created before 2.3 under the same name, whose data is kept as is.
249
+ */
250
+ _mex: number;
251
+ }
252
+
253
+ /**
254
+ * Synced block (2.3): a reference to shared content (a Settings > Templates
255
+ * source of kind `synced`). Only the reference is stored; `?mex=` output,
256
+ * GraphQL `…Rendered`/`…Resolved` and the renderers (`options.synced`) expand it.
257
+ */
258
+ export interface SyncedData {
259
+ /** documentId of the source ('' when invalid). */
260
+ ref: string;
261
+ /**
262
+ * Built-in block marker (2.3 writes 1). Tells the built-in block apart from a
263
+ * custom block created before 2.3 under the same name, whose data is kept as is.
264
+ */
265
+ _mex: number;
266
+ }
267
+
268
+ /** Data per built-in block type. */
269
+ export interface BlockDataMap {
270
+ paragraph: ParagraphData;
271
+ header: HeaderData;
272
+ quote: QuoteData;
273
+ list: ListData;
274
+ checklist: ChecklistData;
275
+ warning: WarningData;
276
+ alert: AlertData;
277
+ toggle: ToggleData;
278
+ code: CodeData;
279
+ codeFlask: CodeFlaskData;
280
+ raw: RawData;
281
+ table: TableData;
282
+ image: ImageData;
283
+ simpleImage: SimpleImageData;
284
+ gallery: GalleryData;
285
+ video: VideoData;
286
+ audio: AudioData;
287
+ linkTool: LinkToolData;
288
+ attaches: AttachesData;
289
+ embed: EmbedData;
290
+ personality: PersonalityData;
291
+ button: ButtonData;
292
+ delimiter: DelimiterData;
293
+ toc: TocData;
294
+ synced: SyncedData;
295
+ }
296
+
297
+ export type BuiltInBlockType = keyof BlockDataMap;
298
+
299
+ /** A built-in block, discriminated by `type`. */
300
+ export type BuiltInBlock = {
301
+ [T in BuiltInBlockType]: { id: string; type: T; data: BlockDataMap[T]; tunes?: MagicEditorXTunes };
302
+ }[BuiltInBlockType];
303
+
304
+ /** A custom block defined in Settings > Magic Editor X > Custom blocks. */
305
+ export interface CustomBlock {
306
+ id: string;
307
+ type: string;
308
+ data: Record<string, unknown>;
309
+ tunes?: MagicEditorXTunes;
310
+ }
311
+
312
+ export type MagicEditorXBlock = BuiltInBlock | CustomBlock;
313
+
314
+ /** Stored value of a Magic Editor X field (`null` when empty). */
315
+ export interface MagicEditorXData {
316
+ time: number;
317
+ blocks: MagicEditorXBlock[];
318
+ version: string;
319
+ }
320
+
321
+ export type MagicEditorXValue = MagicEditorXData | null;
322
+
323
+ export type {
324
+ RenderOptions,
325
+ InternalLinkRef,
326
+ RenderBlock,
327
+ HtmlHelpers,
328
+ RenderNode,
329
+ RenderElementNode,
330
+ RenderTextNode,
331
+ RenderRawNode,
332
+ CodeRenderOptions,
333
+ OverrideResult,
334
+ renderHtml,
335
+ renderTree,
336
+ renderText,
337
+ renderMarkdown,
338
+ } from './render.js';
@@ -0,0 +1,39 @@
1
+ /** Types of `magic-editor-x/react` (React 18 and 19; needs `@types/react` for TypeScript). */
2
+
3
+ import type { ComponentType, ReactElement, ReactNode } from 'react';
4
+ import type { RenderBlock, RenderNode, RenderOptions } from './render.js';
5
+
6
+ /** Helpers handed to a block component. */
7
+ export interface ReactBlockHelpers {
8
+ /** Plain text of stored inline HTML. */
9
+ text(html: unknown): string;
10
+ /** Validated URL or ''. */
11
+ url(value: unknown, schemes?: string[]): string;
12
+ /** React nodes of stored inline HTML (strict parser, links resolved). */
13
+ inline(html: unknown): ReactNode[];
14
+ /** React nodes of child blocks (toggle content), with your components applied. */
15
+ renderBlocks(blocks: RenderBlock[]): ReactNode[];
16
+ }
17
+
18
+ /** Props of a block component in `components`. */
19
+ export interface BlockComponentProps {
20
+ block: RenderBlock;
21
+ helpers: ReactBlockHelpers;
22
+ /** The default output of the block. */
23
+ children: ReactNode[];
24
+ }
25
+
26
+ export interface MagicEditorXContentProps {
27
+ /** Stored field value (object, JSON string, 1.x shapes). null renders nothing. */
28
+ value: unknown;
29
+ /** Render options (links, media, embedHosts, imageSizes, code, rawHtml + sanitizeRaw, overrides). */
30
+ options?: RenderOptions;
31
+ /** Per-type components; return null to hide a block. */
32
+ components?: Record<string, ComponentType<BlockComponentProps>>;
33
+ }
34
+
35
+ /** Renders stored content as React elements (a fragment, no wrapper element). */
36
+ export declare function MagicEditorXContent(props: MagicEditorXContentProps): ReactElement;
37
+ /** React nodes of a `renderTree` result. */
38
+ export declare function treeToReact(nodes: RenderNode[]): ReactNode[];
39
+ export default MagicEditorXContent;