magic-editor-x 2.3.1 → 2.5.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 +125 -0
- package/README.md +428 -148
- package/bin/magic-editor-x.mjs +55 -8
- package/dist/admin/AuditPage-Be78C7EC.mjs +382 -0
- package/dist/admin/AuditPage-iQzpjH8H.js +382 -0
- package/dist/admin/{ConfigurationPage-CYGDLjM7.mjs → ConfigurationPage-C9CPBfWy.mjs} +405 -10
- package/dist/admin/{ConfigurationPage-CFP3lp9p.js → ConfigurationPage-DefuBeYO.js} +415 -20
- package/dist/admin/ConfirmAction-CUhpngYU.js +71 -0
- package/dist/admin/ConfirmAction-CZjpduc3.mjs +72 -0
- package/dist/admin/Content-BttG50Mc.mjs +360 -0
- package/dist/admin/Content-V5MRBsI3.js +362 -0
- package/dist/admin/{CustomBlocksPage-B5Q33N-s.mjs → CustomBlocksPage-DB5nnCsn.mjs} +8 -5
- package/dist/admin/{CustomBlocksPage-DzPOSpfn.js → CustomBlocksPage-Dg2rM3F4.js} +26 -23
- package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
- package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
- package/dist/admin/MentionsWidget-CJPZDk9Z.mjs +225 -0
- package/dist/admin/MentionsWidget-DUz6YVIG.js +227 -0
- package/dist/admin/{useT-Cmg1jwwG.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
- package/dist/admin/{useT-DNphiBQR.js → SectionCard-Bs-xiiH1.js} +0 -10
- package/dist/admin/{TemplatesPage-4A8JNO_Z.mjs → TemplatesPage-VsZ_Mc0R.mjs} +307 -10
- package/dist/admin/{TemplatesPage-BVkgafCK.js → TemplatesPage-dx4_yd_t.js} +321 -24
- package/dist/admin/{ConfirmAction-zLuIFj8t.js → api-4AYzwS4-.js} +28 -71
- package/dist/admin/{ConfirmAction-DuQwvRYi.mjs → api-CcTYyckq.mjs} +28 -71
- package/dist/admin/auditText-DIIYVR6k.mjs +110 -0
- package/dist/admin/auditText-DUhWu2Nx.js +109 -0
- package/dist/admin/comments-C7P41lan.js +86 -0
- package/dist/admin/comments-hfIbLQNO.mjs +87 -0
- package/dist/admin/{de-B1X46JJZ.js → de-B6rdcOqQ.js} +293 -5
- package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
- package/dist/admin/{de-BUS1hUw0.mjs → de-Bip0sBRT.mjs} +158 -1
- package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
- package/dist/admin/{de-DOiGaTNX.mjs → de-CQA8hOpl.mjs} +293 -5
- package/dist/admin/{de-C3AsGauQ.js → de-CnnxKXj7.js} +158 -1
- package/dist/admin/{de-2Ie5jy7j.js → de-Dss5POqk.js} +53 -3
- package/dist/admin/{de-BMY2LBaa.mjs → de-zgHCYTLH.mjs} +53 -3
- package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
- package/dist/admin/{en-CU6UzV4g.mjs → en-BCKaVgBM.mjs} +293 -5
- package/dist/admin/{en-Ah-Cw0Wd.js → en-CJ17Sp_e.js} +53 -3
- package/dist/admin/{en-CDg_18Bt.js → en-CbGkcq0Q.js} +293 -5
- package/dist/admin/{en-GCzgS9Aw.mjs → en-Cd6Jk-J0.mjs} +158 -1
- package/dist/admin/{en-BkEjpC3i.js → en-D69Fe9ZO.js} +158 -1
- package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
- package/dist/admin/{en-CvFiqti2.mjs → en-Uhm7OouM.mjs} +53 -3
- package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
- package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
- package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
- package/dist/admin/{es-DbKHZz5l.mjs → es-BMkmfH88.mjs} +53 -3
- package/dist/admin/{es-DHBBZKl2.mjs → es-Bz8d72Fa.mjs} +158 -1
- package/dist/admin/{es-BCpJmUEM.js → es-C8UotT8O.js} +293 -5
- package/dist/admin/{es-C4pEnDRv.js → es-CcEDZpVQ.js} +158 -1
- package/dist/admin/{es-Cr8JH85N.js → es-DJm3HFJt.js} +53 -3
- package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
- package/dist/admin/{es-BmfffNM2.mjs → es-pvPfNAld.mjs} +293 -5
- package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
- package/dist/admin/{fr-Dvq4xk2e.mjs → fr-CKHZ0xxU.mjs} +158 -1
- package/dist/admin/{fr-OJ4VW1kh.js → fr-CRM9VuAq.js} +53 -3
- package/dist/admin/{fr-DQJ_7aq5.mjs → fr-CrIHmKYX.mjs} +53 -3
- package/dist/admin/{fr-C2aLSwEu.js → fr-Cx29jQ_g.js} +158 -1
- package/dist/admin/{fr-DZd2XJP6.mjs → fr-D4tL6Ag2.mjs} +293 -5
- package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
- package/dist/admin/{fr-ZcN0yM_2.js → fr-DrUYv2jh.js} +293 -5
- package/dist/admin/{index-k8_a5o1A.mjs → index-C4ksUkEm.mjs} +20059 -10130
- package/dist/admin/{index-DQVE0ymw.js → index-C5D3VqLq.js} +21272 -11344
- package/dist/admin/index-CMYCZWOh.mjs +3752 -0
- package/dist/admin/index-DRyctF9s.js +3753 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/math-D6jmskGS.js +49 -0
- package/dist/admin/math-DntdSWKX.mjs +47 -0
- package/dist/admin/{pt-CilDggGF.mjs → pt-B8x7v-Xw.mjs} +158 -1
- package/dist/admin/{pt-DX0OAIoL.js → pt-BYn2xx78.js} +158 -1
- package/dist/admin/{pt-CImqDnLB.js → pt-CojQcz-p.js} +293 -5
- package/dist/admin/{pt-C3UdeIpd.mjs → pt-CuoIihKx.mjs} +293 -5
- package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
- package/dist/admin/{pt-BSLzA17U.mjs → pt-DDlPJYtB.mjs} +53 -3
- package/dist/admin/{pt-D0I0_JYs.js → pt-DPVAycXJ.js} +53 -3
- package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
- package/dist/admin/useT-Bpw__IXT.js +12 -0
- package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
- package/dist/blocks/index.d.mts +126 -0
- package/dist/blocks/index.d.ts +126 -0
- package/dist/blocks/index.js +184 -4
- package/dist/blocks/index.mjs +184 -4
- package/dist/math/index.d.mts +27 -0
- package/dist/math/index.d.ts +27 -0
- package/dist/math/index.js +168 -0
- package/dist/math/index.mjs +138 -0
- package/dist/react/index.js +1650 -759
- package/dist/react/index.mjs +1650 -759
- package/dist/render/index.d.mts +48 -0
- package/dist/render/index.d.ts +48 -0
- package/dist/render/index.js +1755 -773
- package/dist/render/index.mjs +1755 -773
- package/dist/server/index.js +29475 -18462
- package/dist/server/index.mjs +29475 -18462
- package/dist/server/mcp-worker.js +11319 -0
- package/dist/vue/index.js +1650 -759
- package/dist/vue/index.mjs +1650 -759
- package/package.json +14 -8
- package/schema/magic-editor-x.schema.json +135 -2
- package/types/blocks.d.ts +126 -0
- package/types/index.d.ts +52 -1
- package/types/math.d.ts +27 -0
- package/types/render.d.ts +48 -0
- package/dist/admin/index-DR8sHkTk.js +0 -1940
- package/dist/admin/index-My6FjjHB.mjs +0 -1939
package/dist/blocks/index.d.mts
CHANGED
|
@@ -153,6 +153,8 @@ export class BlockDefinitionError extends Error {
|
|
|
153
153
|
export const BLOCK_FIELD_TYPES: readonly BlockFieldType[];
|
|
154
154
|
export const BLOCK_PRESETS: readonly ['article', 'basic', 'minimal'];
|
|
155
155
|
export const RESERVED_BLOCK_NAMES: readonly string[];
|
|
156
|
+
/** Built-in names that code blocks may still use (2.4: `math`, a built-in added after the SDK shipped). */
|
|
157
|
+
export const SDK_COMPATIBLE_NAMES: readonly string[];
|
|
156
158
|
export const BLOCK_LIMITS: Readonly<{
|
|
157
159
|
maxFields: number;
|
|
158
160
|
maxDepth: number;
|
|
@@ -165,3 +167,127 @@ export const BLOCK_LIMITS: Readonly<{
|
|
|
165
167
|
maxValues: number;
|
|
166
168
|
maxUrl: number;
|
|
167
169
|
}>;
|
|
170
|
+
|
|
171
|
+
/* ------------------------------------------------------------------ 2.5 */
|
|
172
|
+
|
|
173
|
+
/** Attribute types of an inline annotation. */
|
|
174
|
+
export type InlineAnnotationFieldType = 'text' | 'enum' | 'url';
|
|
175
|
+
|
|
176
|
+
export interface InlineAnnotationAttributeInput {
|
|
177
|
+
type: InlineAnnotationFieldType;
|
|
178
|
+
label?: string;
|
|
179
|
+
/** Without a required value the annotation is unwrapped on save (its text stays). */
|
|
180
|
+
required?: boolean;
|
|
181
|
+
/** `text`: 1-1000 characters (default 200). */
|
|
182
|
+
max?: number;
|
|
183
|
+
/** `enum`: 1-50 distinct strings. */
|
|
184
|
+
values?: readonly string[];
|
|
185
|
+
/** `url`: subset of http, https, mailto, tel (default http + https). */
|
|
186
|
+
schemes?: ReadonlyArray<'http' | 'https' | 'mailto' | 'tel'>;
|
|
187
|
+
/** `url`: allow site-relative URLs (default true). */
|
|
188
|
+
relative?: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** What `render` and `resolve` see of one annotation (clean values). */
|
|
192
|
+
export interface InlineAnnotationUse {
|
|
193
|
+
name: string;
|
|
194
|
+
attrs: Record<string, string>;
|
|
195
|
+
text: string;
|
|
196
|
+
/** Value from `resolve` (server output) or the `resolveAnnotation` render option. */
|
|
197
|
+
resolved?: string | Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The one element that wraps the annotated text (validated: allowed tags and attributes only). */
|
|
201
|
+
export interface InlineAnnotationWrapper {
|
|
202
|
+
tag:
|
|
203
|
+
| 'abbr'
|
|
204
|
+
| 'dfn'
|
|
205
|
+
| 'span'
|
|
206
|
+
| 'a'
|
|
207
|
+
| 'mark'
|
|
208
|
+
| 'cite'
|
|
209
|
+
| 'q'
|
|
210
|
+
| 'small'
|
|
211
|
+
| 'em'
|
|
212
|
+
| 'strong'
|
|
213
|
+
| 'b'
|
|
214
|
+
| 'i'
|
|
215
|
+
| 'u'
|
|
216
|
+
| 's'
|
|
217
|
+
| 'time'
|
|
218
|
+
| 'data'
|
|
219
|
+
| 'bdi'
|
|
220
|
+
| 'kbd'
|
|
221
|
+
| 'var'
|
|
222
|
+
| 'ins'
|
|
223
|
+
| 'del';
|
|
224
|
+
/** `title`, `class`, `lang`, `dir`, `href` (only on `a`), `datetime`, `value`, `cite`, `aria-label`, `data-*` (not `data-mex-*`). */
|
|
225
|
+
attrs?: Record<string, string | number | null | undefined | false>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Context of a server-side `resolve` call (Content API `?mex=`, GraphQL `…Rendered`). */
|
|
229
|
+
export interface InlineAnnotationResolveContext {
|
|
230
|
+
status: 'draft' | 'published';
|
|
231
|
+
/**
|
|
232
|
+
* Permission-aware lookup: only `api::` types the caller may `find`, the
|
|
233
|
+
* query sanitised with the caller's auth, the request's publication status,
|
|
234
|
+
* at most 100 rows, every row sanitised for output.
|
|
235
|
+
*/
|
|
236
|
+
find(
|
|
237
|
+
uid: string,
|
|
238
|
+
query?: { filters?: Record<string, unknown>; fields?: string[]; locale?: string | null; limit?: number }
|
|
239
|
+
): Promise<Array<Record<string, unknown>>>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface InlineAnnotationDefinitionInput {
|
|
243
|
+
/** `/^[a-z][a-z0-9-]{1,39}$/`; `abbreviation` is built in. */
|
|
244
|
+
name: string;
|
|
245
|
+
label?: string;
|
|
246
|
+
description?: string;
|
|
247
|
+
/** 0-8 attributes, keys `/^[a-z][a-z0-9]{0,23}$/`, stored as `data-mex-a-<key>`. */
|
|
248
|
+
attributes: Record<string, InlineAnnotationAttributeInput>;
|
|
249
|
+
/** Presets that offer the annotation without the field option `inlineAnnotations`. */
|
|
250
|
+
presets?: ReadonlyArray<'full' | 'article' | 'basic' | 'minimal'>;
|
|
251
|
+
/** Keyboard shortcut of the editor tool: one of `ANNOTATION_SHORTCUTS` (Ctrl on Windows/Linux). */
|
|
252
|
+
shortcut?: 'CMD+SHIFT+0' | 'CMD+SHIFT+1' | 'CMD+SHIFT+8';
|
|
253
|
+
/**
|
|
254
|
+
* Server only: one call per response with every distinct use (at most 200);
|
|
255
|
+
* return the values in the same order (string up to 2000 characters or a plain object).
|
|
256
|
+
*/
|
|
257
|
+
resolve?: (
|
|
258
|
+
items: ReadonlyArray<{ attrs: Record<string, string>; locale: string | null }>,
|
|
259
|
+
context: InlineAnnotationResolveContext
|
|
260
|
+
) => Promise<ReadonlyArray<unknown>> | ReadonlyArray<unknown>;
|
|
261
|
+
/** Wrapper of the annotated text; `false` renders the text only; null/undefined/throw = default span. */
|
|
262
|
+
render?: (annotation: InlineAnnotationUse) => InlineAnnotationWrapper | false | null | undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export type InlineAnnotationDefinition = Readonly<
|
|
266
|
+
Required<Pick<InlineAnnotationDefinitionInput, 'name' | 'label'>> &
|
|
267
|
+
Omit<InlineAnnotationDefinitionInput, 'name' | 'label' | 'attributes' | 'presets'> & {
|
|
268
|
+
attributes: Readonly<Record<string, Readonly<InlineAnnotationAttributeInput & { required: boolean }>>>;
|
|
269
|
+
presets: readonly string[];
|
|
270
|
+
}
|
|
271
|
+
>;
|
|
272
|
+
|
|
273
|
+
export function defineInlineAnnotation(
|
|
274
|
+
definition: InlineAnnotationDefinitionInput
|
|
275
|
+
): InlineAnnotationDefinition;
|
|
276
|
+
export function annotationJsonSchema(definition: InlineAnnotationDefinition): Record<string, unknown>;
|
|
277
|
+
/** The built-in abbreviation (`title`, required): renders `<abbr title>`. */
|
|
278
|
+
export const abbreviationAnnotation: InlineAnnotationDefinition;
|
|
279
|
+
export const ANNOTATION_ATTRIBUTE: 'data-mex-annotation';
|
|
280
|
+
export const ANNOTATION_VALUE_PREFIX: 'data-mex-a-';
|
|
281
|
+
export const ANNOTATION_FIELD_TYPES: readonly InlineAnnotationFieldType[];
|
|
282
|
+
export const ANNOTATION_PRESETS: readonly ['full', 'article', 'basic', 'minimal'];
|
|
283
|
+
export const ANNOTATION_SHORTCUTS: readonly ['CMD+SHIFT+0', 'CMD+SHIFT+1', 'CMD+SHIFT+8'];
|
|
284
|
+
export const ANNOTATION_RENDER_TAGS: readonly InlineAnnotationWrapper['tag'][];
|
|
285
|
+
export const ANNOTATION_LIMITS: Readonly<{
|
|
286
|
+
attributes: number;
|
|
287
|
+
text: number;
|
|
288
|
+
textDefault: number;
|
|
289
|
+
values: number;
|
|
290
|
+
registered: number;
|
|
291
|
+
label: number;
|
|
292
|
+
resolveItems: number;
|
|
293
|
+
}>;
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -153,6 +153,8 @@ export class BlockDefinitionError extends Error {
|
|
|
153
153
|
export const BLOCK_FIELD_TYPES: readonly BlockFieldType[];
|
|
154
154
|
export const BLOCK_PRESETS: readonly ['article', 'basic', 'minimal'];
|
|
155
155
|
export const RESERVED_BLOCK_NAMES: readonly string[];
|
|
156
|
+
/** Built-in names that code blocks may still use (2.4: `math`, a built-in added after the SDK shipped). */
|
|
157
|
+
export const SDK_COMPATIBLE_NAMES: readonly string[];
|
|
156
158
|
export const BLOCK_LIMITS: Readonly<{
|
|
157
159
|
maxFields: number;
|
|
158
160
|
maxDepth: number;
|
|
@@ -165,3 +167,127 @@ export const BLOCK_LIMITS: Readonly<{
|
|
|
165
167
|
maxValues: number;
|
|
166
168
|
maxUrl: number;
|
|
167
169
|
}>;
|
|
170
|
+
|
|
171
|
+
/* ------------------------------------------------------------------ 2.5 */
|
|
172
|
+
|
|
173
|
+
/** Attribute types of an inline annotation. */
|
|
174
|
+
export type InlineAnnotationFieldType = 'text' | 'enum' | 'url';
|
|
175
|
+
|
|
176
|
+
export interface InlineAnnotationAttributeInput {
|
|
177
|
+
type: InlineAnnotationFieldType;
|
|
178
|
+
label?: string;
|
|
179
|
+
/** Without a required value the annotation is unwrapped on save (its text stays). */
|
|
180
|
+
required?: boolean;
|
|
181
|
+
/** `text`: 1-1000 characters (default 200). */
|
|
182
|
+
max?: number;
|
|
183
|
+
/** `enum`: 1-50 distinct strings. */
|
|
184
|
+
values?: readonly string[];
|
|
185
|
+
/** `url`: subset of http, https, mailto, tel (default http + https). */
|
|
186
|
+
schemes?: ReadonlyArray<'http' | 'https' | 'mailto' | 'tel'>;
|
|
187
|
+
/** `url`: allow site-relative URLs (default true). */
|
|
188
|
+
relative?: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** What `render` and `resolve` see of one annotation (clean values). */
|
|
192
|
+
export interface InlineAnnotationUse {
|
|
193
|
+
name: string;
|
|
194
|
+
attrs: Record<string, string>;
|
|
195
|
+
text: string;
|
|
196
|
+
/** Value from `resolve` (server output) or the `resolveAnnotation` render option. */
|
|
197
|
+
resolved?: string | Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The one element that wraps the annotated text (validated: allowed tags and attributes only). */
|
|
201
|
+
export interface InlineAnnotationWrapper {
|
|
202
|
+
tag:
|
|
203
|
+
| 'abbr'
|
|
204
|
+
| 'dfn'
|
|
205
|
+
| 'span'
|
|
206
|
+
| 'a'
|
|
207
|
+
| 'mark'
|
|
208
|
+
| 'cite'
|
|
209
|
+
| 'q'
|
|
210
|
+
| 'small'
|
|
211
|
+
| 'em'
|
|
212
|
+
| 'strong'
|
|
213
|
+
| 'b'
|
|
214
|
+
| 'i'
|
|
215
|
+
| 'u'
|
|
216
|
+
| 's'
|
|
217
|
+
| 'time'
|
|
218
|
+
| 'data'
|
|
219
|
+
| 'bdi'
|
|
220
|
+
| 'kbd'
|
|
221
|
+
| 'var'
|
|
222
|
+
| 'ins'
|
|
223
|
+
| 'del';
|
|
224
|
+
/** `title`, `class`, `lang`, `dir`, `href` (only on `a`), `datetime`, `value`, `cite`, `aria-label`, `data-*` (not `data-mex-*`). */
|
|
225
|
+
attrs?: Record<string, string | number | null | undefined | false>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Context of a server-side `resolve` call (Content API `?mex=`, GraphQL `…Rendered`). */
|
|
229
|
+
export interface InlineAnnotationResolveContext {
|
|
230
|
+
status: 'draft' | 'published';
|
|
231
|
+
/**
|
|
232
|
+
* Permission-aware lookup: only `api::` types the caller may `find`, the
|
|
233
|
+
* query sanitised with the caller's auth, the request's publication status,
|
|
234
|
+
* at most 100 rows, every row sanitised for output.
|
|
235
|
+
*/
|
|
236
|
+
find(
|
|
237
|
+
uid: string,
|
|
238
|
+
query?: { filters?: Record<string, unknown>; fields?: string[]; locale?: string | null; limit?: number }
|
|
239
|
+
): Promise<Array<Record<string, unknown>>>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface InlineAnnotationDefinitionInput {
|
|
243
|
+
/** `/^[a-z][a-z0-9-]{1,39}$/`; `abbreviation` is built in. */
|
|
244
|
+
name: string;
|
|
245
|
+
label?: string;
|
|
246
|
+
description?: string;
|
|
247
|
+
/** 0-8 attributes, keys `/^[a-z][a-z0-9]{0,23}$/`, stored as `data-mex-a-<key>`. */
|
|
248
|
+
attributes: Record<string, InlineAnnotationAttributeInput>;
|
|
249
|
+
/** Presets that offer the annotation without the field option `inlineAnnotations`. */
|
|
250
|
+
presets?: ReadonlyArray<'full' | 'article' | 'basic' | 'minimal'>;
|
|
251
|
+
/** Keyboard shortcut of the editor tool: one of `ANNOTATION_SHORTCUTS` (Ctrl on Windows/Linux). */
|
|
252
|
+
shortcut?: 'CMD+SHIFT+0' | 'CMD+SHIFT+1' | 'CMD+SHIFT+8';
|
|
253
|
+
/**
|
|
254
|
+
* Server only: one call per response with every distinct use (at most 200);
|
|
255
|
+
* return the values in the same order (string up to 2000 characters or a plain object).
|
|
256
|
+
*/
|
|
257
|
+
resolve?: (
|
|
258
|
+
items: ReadonlyArray<{ attrs: Record<string, string>; locale: string | null }>,
|
|
259
|
+
context: InlineAnnotationResolveContext
|
|
260
|
+
) => Promise<ReadonlyArray<unknown>> | ReadonlyArray<unknown>;
|
|
261
|
+
/** Wrapper of the annotated text; `false` renders the text only; null/undefined/throw = default span. */
|
|
262
|
+
render?: (annotation: InlineAnnotationUse) => InlineAnnotationWrapper | false | null | undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export type InlineAnnotationDefinition = Readonly<
|
|
266
|
+
Required<Pick<InlineAnnotationDefinitionInput, 'name' | 'label'>> &
|
|
267
|
+
Omit<InlineAnnotationDefinitionInput, 'name' | 'label' | 'attributes' | 'presets'> & {
|
|
268
|
+
attributes: Readonly<Record<string, Readonly<InlineAnnotationAttributeInput & { required: boolean }>>>;
|
|
269
|
+
presets: readonly string[];
|
|
270
|
+
}
|
|
271
|
+
>;
|
|
272
|
+
|
|
273
|
+
export function defineInlineAnnotation(
|
|
274
|
+
definition: InlineAnnotationDefinitionInput
|
|
275
|
+
): InlineAnnotationDefinition;
|
|
276
|
+
export function annotationJsonSchema(definition: InlineAnnotationDefinition): Record<string, unknown>;
|
|
277
|
+
/** The built-in abbreviation (`title`, required): renders `<abbr title>`. */
|
|
278
|
+
export const abbreviationAnnotation: InlineAnnotationDefinition;
|
|
279
|
+
export const ANNOTATION_ATTRIBUTE: 'data-mex-annotation';
|
|
280
|
+
export const ANNOTATION_VALUE_PREFIX: 'data-mex-a-';
|
|
281
|
+
export const ANNOTATION_FIELD_TYPES: readonly InlineAnnotationFieldType[];
|
|
282
|
+
export const ANNOTATION_PRESETS: readonly ['full', 'article', 'basic', 'minimal'];
|
|
283
|
+
export const ANNOTATION_SHORTCUTS: readonly ['CMD+SHIFT+0', 'CMD+SHIFT+1', 'CMD+SHIFT+8'];
|
|
284
|
+
export const ANNOTATION_RENDER_TAGS: readonly InlineAnnotationWrapper['tag'][];
|
|
285
|
+
export const ANNOTATION_LIMITS: Readonly<{
|
|
286
|
+
attributes: number;
|
|
287
|
+
text: number;
|
|
288
|
+
textDefault: number;
|
|
289
|
+
values: number;
|
|
290
|
+
registered: number;
|
|
291
|
+
label: number;
|
|
292
|
+
resolveItems: number;
|
|
293
|
+
}>;
|
package/dist/blocks/index.js
CHANGED
|
@@ -19,14 +19,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// shared/blocks/index.mjs
|
|
20
20
|
var index_exports = {};
|
|
21
21
|
__export(index_exports, {
|
|
22
|
+
ANNOTATION_ATTRIBUTE: () => ANNOTATION_ATTRIBUTE,
|
|
23
|
+
ANNOTATION_FIELD_TYPES: () => ANNOTATION_FIELD_TYPES,
|
|
24
|
+
ANNOTATION_LIMITS: () => ANNOTATION_LIMITS,
|
|
25
|
+
ANNOTATION_PRESETS: () => ANNOTATION_PRESETS,
|
|
26
|
+
ANNOTATION_RENDER_TAGS: () => ANNOTATION_RENDER_TAGS,
|
|
27
|
+
ANNOTATION_SHORTCUTS: () => ANNOTATION_SHORTCUTS,
|
|
28
|
+
ANNOTATION_VALUE_PREFIX: () => ANNOTATION_VALUE_PREFIX,
|
|
22
29
|
BLOCK_FIELD_TYPES: () => BLOCK_FIELD_TYPES,
|
|
23
30
|
BLOCK_LIMITS: () => BLOCK_LIMITS,
|
|
24
31
|
BLOCK_PRESETS: () => BLOCK_PRESETS,
|
|
25
32
|
BlockDefinitionError: () => BlockDefinitionError,
|
|
26
33
|
RESERVED_BLOCK_NAMES: () => RESERVED_BLOCK_NAMES,
|
|
34
|
+
SDK_COMPATIBLE_NAMES: () => SDK_COMPATIBLE_NAMES,
|
|
35
|
+
abbreviationAnnotation: () => abbreviationAnnotation,
|
|
36
|
+
annotationJsonSchema: () => annotationJsonSchema,
|
|
27
37
|
blockJsonSchema: () => blockJsonSchema,
|
|
28
38
|
blockNameProblem: () => blockNameProblem,
|
|
29
|
-
defineBlock: () => defineBlock
|
|
39
|
+
defineBlock: () => defineBlock,
|
|
40
|
+
defineInlineAnnotation: () => defineInlineAnnotation
|
|
30
41
|
});
|
|
31
42
|
module.exports = __toCommonJS(index_exports);
|
|
32
43
|
|
|
@@ -45,7 +56,9 @@ var MARKED_BLOCKS = Object.freeze({
|
|
|
45
56
|
keys: Object.freeze(["file", "title", "caption", "loop", "tracks"]),
|
|
46
57
|
anchor: Object.freeze(["file", "object"])
|
|
47
58
|
}),
|
|
48
|
-
synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) })
|
|
59
|
+
synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) }),
|
|
60
|
+
// 2.4: math block. A Settings custom block named `math` could exist before 2.4.
|
|
61
|
+
math: Object.freeze({ keys: Object.freeze(["tex", "display"]), anchor: Object.freeze(["tex", "string"]) })
|
|
49
62
|
});
|
|
50
63
|
|
|
51
64
|
// shared/editor-data.mjs
|
|
@@ -57,6 +70,10 @@ var EDITOR_DATA_LIMITS = Object.freeze({
|
|
|
57
70
|
maxTypeLength: 64
|
|
58
71
|
});
|
|
59
72
|
|
|
73
|
+
// shared/table.mjs
|
|
74
|
+
var TABLE_LIMITS = Object.freeze({ rows: 500, cols: 100, merges: 1e3, caption: 4e3 });
|
|
75
|
+
var TABLE_ALIGNS = Object.freeze(["left", "center", "right"]);
|
|
76
|
+
|
|
60
77
|
// shared/sanitize-policy.mjs
|
|
61
78
|
var INLINE_TAGS = Object.freeze([
|
|
62
79
|
"b",
|
|
@@ -86,10 +103,17 @@ var INTERNAL_LINK_RULES = Object.freeze({
|
|
|
86
103
|
// Boolean flag: written as "true"; an empty value (`<a data-mex-mention>`) is accepted and normalised.
|
|
87
104
|
"data-mex-mention": /^(?:|true)$/
|
|
88
105
|
});
|
|
106
|
+
var MATH_ATTRIBUTE = "data-mex-math";
|
|
107
|
+
var FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
|
|
108
|
+
var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
|
|
109
|
+
span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
|
|
110
|
+
mark: ["data-mex-highlight"]
|
|
111
|
+
});
|
|
89
112
|
var INLINE_ATTRIBUTES = Object.freeze({
|
|
90
113
|
a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
|
|
91
|
-
span: ["class", "data-tooltip"],
|
|
92
|
-
|
|
114
|
+
span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
|
|
115
|
+
sup: [...FOOTNOTE_ATTRIBUTES],
|
|
116
|
+
mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
|
|
93
117
|
u: ["class"],
|
|
94
118
|
s: ["class"],
|
|
95
119
|
code: ["class"]
|
|
@@ -204,6 +228,7 @@ var RESERVED_BLOCK_NAMES = Object.freeze([
|
|
|
204
228
|
"textVariant",
|
|
205
229
|
"indentTune"
|
|
206
230
|
]);
|
|
231
|
+
var SDK_COMPATIBLE_NAMES = Object.freeze(["math"]);
|
|
207
232
|
var RESERVED = new Set(RESERVED_BLOCK_NAMES.map((name) => name.toLowerCase()));
|
|
208
233
|
var BLOCK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{1,49}$/;
|
|
209
234
|
var KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
@@ -629,3 +654,158 @@ var copyData = (value) => {
|
|
|
629
654
|
}
|
|
630
655
|
return value;
|
|
631
656
|
};
|
|
657
|
+
|
|
658
|
+
// shared/render/nodes.mjs
|
|
659
|
+
var STYLE_PROPERTIES = Object.freeze(["object-position"]);
|
|
660
|
+
|
|
661
|
+
// shared/blocks/annotations.mjs
|
|
662
|
+
var ANNOTATION_ATTRIBUTE = "data-mex-annotation";
|
|
663
|
+
var ANNOTATION_VALUE_PREFIX = "data-mex-a-";
|
|
664
|
+
var ANNOTATION_NAME = /^[a-z][a-z0-9-]{1,39}$/;
|
|
665
|
+
var ANNOTATION_KEY = /^[a-z][a-z0-9]{0,23}$/;
|
|
666
|
+
var ANNOTATION_FIELD_TYPES = Object.freeze(["text", "enum", "url"]);
|
|
667
|
+
var ANNOTATION_LIMITS = Object.freeze({
|
|
668
|
+
attributes: 8,
|
|
669
|
+
text: 1e3,
|
|
670
|
+
textDefault: 200,
|
|
671
|
+
values: 50,
|
|
672
|
+
registered: 50,
|
|
673
|
+
label: 100,
|
|
674
|
+
resolveItems: 200
|
|
675
|
+
});
|
|
676
|
+
var ANNOTATION_PRESETS = Object.freeze(["full", "article", "basic", "minimal"]);
|
|
677
|
+
var ANNOTATION_RENDER_TAGS = Object.freeze([
|
|
678
|
+
"abbr",
|
|
679
|
+
"dfn",
|
|
680
|
+
"span",
|
|
681
|
+
"a",
|
|
682
|
+
"mark",
|
|
683
|
+
"cite",
|
|
684
|
+
"q",
|
|
685
|
+
"small",
|
|
686
|
+
"em",
|
|
687
|
+
"strong",
|
|
688
|
+
"b",
|
|
689
|
+
"i",
|
|
690
|
+
"u",
|
|
691
|
+
"s",
|
|
692
|
+
"time",
|
|
693
|
+
"data",
|
|
694
|
+
"bdi",
|
|
695
|
+
"kbd",
|
|
696
|
+
"var",
|
|
697
|
+
"ins",
|
|
698
|
+
"del"
|
|
699
|
+
]);
|
|
700
|
+
var ANNOTATION_SHORTCUTS = Object.freeze(["CMD+SHIFT+0", "CMD+SHIFT+1", "CMD+SHIFT+8"]);
|
|
701
|
+
var ABBREVIATION = "abbreviation";
|
|
702
|
+
var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
703
|
+
var fail2 = (name, message, code = "INVALID_DEFINITION") => {
|
|
704
|
+
throw new BlockDefinitionError(`Magic Editor X inline annotation ${name}: ${message}`, code);
|
|
705
|
+
};
|
|
706
|
+
var defined = /* @__PURE__ */ new WeakSet();
|
|
707
|
+
var normalizeAttribute = (where, input) => {
|
|
708
|
+
if (!isObject2(input)) fail2(where, 'an attribute must be an object with a "type"');
|
|
709
|
+
const { type } = input;
|
|
710
|
+
if (!ANNOTATION_FIELD_TYPES.includes(type)) fail2(where, `unknown attribute type ${JSON.stringify(type)}`);
|
|
711
|
+
const allowed = { text: ["max"], enum: ["values"], url: ["schemes", "relative"] }[type];
|
|
712
|
+
for (const key of Object.keys(input))
|
|
713
|
+
if (!["type", "label", "required", ...allowed].includes(key))
|
|
714
|
+
fail2(where, `unknown option "${key}" for a ${type} attribute`);
|
|
715
|
+
const out = { type, required: input.required === true };
|
|
716
|
+
if (input.label !== void 0) {
|
|
717
|
+
if (typeof input.label !== "string" || input.label.length > ANNOTATION_LIMITS.label)
|
|
718
|
+
fail2(where, `"label" must be a string of at most ${ANNOTATION_LIMITS.label} characters`);
|
|
719
|
+
out.label = input.label;
|
|
720
|
+
}
|
|
721
|
+
if (input.required !== void 0 && typeof input.required !== "boolean")
|
|
722
|
+
fail2(where, '"required" must be a boolean');
|
|
723
|
+
if (type === "text") {
|
|
724
|
+
const max = input.max === void 0 ? ANNOTATION_LIMITS.textDefault : input.max;
|
|
725
|
+
if (!Number.isInteger(max) || max < 1 || max > ANNOTATION_LIMITS.text)
|
|
726
|
+
fail2(where, `"max" must be an integer from 1 to ${ANNOTATION_LIMITS.text}`);
|
|
727
|
+
out.max = max;
|
|
728
|
+
} else if (type === "enum") {
|
|
729
|
+
const { values } = input;
|
|
730
|
+
if (!Array.isArray(values) || !values.length || values.length > ANNOTATION_LIMITS.values || !values.every((value) => typeof value === "string" && value.length >= 1 && value.length <= 100) || new Set(values).size !== values.length)
|
|
731
|
+
fail2(where, `"values" must be 1 to ${ANNOTATION_LIMITS.values} distinct strings`);
|
|
732
|
+
out.values = Object.freeze([...values]);
|
|
733
|
+
} else {
|
|
734
|
+
const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
|
|
735
|
+
if (!Array.isArray(schemes) || !schemes.length || !schemes.every((scheme) => LINK_SCHEMES.includes(scheme)))
|
|
736
|
+
fail2(where, `"schemes" must be a non-empty subset of ${LINK_SCHEMES.join(", ")}`);
|
|
737
|
+
if (input.relative !== void 0 && typeof input.relative !== "boolean")
|
|
738
|
+
fail2(where, '"relative" must be a boolean');
|
|
739
|
+
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
740
|
+
out.relative = input.relative !== false;
|
|
741
|
+
}
|
|
742
|
+
return Object.freeze(out);
|
|
743
|
+
};
|
|
744
|
+
var defineInlineAnnotation = (definition) => {
|
|
745
|
+
if (!isObject2(definition)) fail2("(unnamed)", "the definition must be an object");
|
|
746
|
+
const { name } = definition;
|
|
747
|
+
if (typeof name !== "string" || !ANNOTATION_NAME.test(name))
|
|
748
|
+
fail2(JSON.stringify(name), "the name must match /^[a-z][a-z0-9-]{1,39}$/");
|
|
749
|
+
for (const key of Object.keys(definition))
|
|
750
|
+
if (!["name", "label", "description", "attributes", "presets", "resolve", "render", "shortcut"].includes(
|
|
751
|
+
key
|
|
752
|
+
))
|
|
753
|
+
fail2(name, `unknown key "${key}"`);
|
|
754
|
+
for (const key of ["label", "description"])
|
|
755
|
+
if (definition[key] !== void 0 && (typeof definition[key] !== "string" || definition[key].length > (key === "label" ? 100 : 500)))
|
|
756
|
+
fail2(name, `"${key}" must be a short string`);
|
|
757
|
+
if (!isObject2(definition.attributes)) fail2(name, '"attributes" must be an object');
|
|
758
|
+
const keys = Object.keys(definition.attributes);
|
|
759
|
+
if (keys.length > ANNOTATION_LIMITS.attributes)
|
|
760
|
+
fail2(name, `at most ${ANNOTATION_LIMITS.attributes} attributes`);
|
|
761
|
+
const attributes = {};
|
|
762
|
+
for (const key of keys) {
|
|
763
|
+
if (!ANNOTATION_KEY.test(key)) fail2(name, `attribute key "${key}" must match /^[a-z][a-z0-9]{0,23}$/`);
|
|
764
|
+
attributes[key] = normalizeAttribute(`${name}.${key}`, definition.attributes[key]);
|
|
765
|
+
}
|
|
766
|
+
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
767
|
+
if (!Array.isArray(presets) || !presets.every((preset) => ANNOTATION_PRESETS.includes(preset)))
|
|
768
|
+
fail2(name, `"presets" must list only ${ANNOTATION_PRESETS.join(", ")}`);
|
|
769
|
+
if (definition.shortcut !== void 0 && !ANNOTATION_SHORTCUTS.includes(definition.shortcut))
|
|
770
|
+
fail2(name, `"shortcut" must be one of ${ANNOTATION_SHORTCUTS.join(", ")}`);
|
|
771
|
+
for (const key of ["resolve", "render"])
|
|
772
|
+
if (definition[key] !== void 0 && typeof definition[key] !== "function")
|
|
773
|
+
fail2(name, `"${key}" must be a function`);
|
|
774
|
+
const out = Object.freeze({
|
|
775
|
+
name,
|
|
776
|
+
label: definition.label || name,
|
|
777
|
+
...definition.description ? { description: definition.description } : {},
|
|
778
|
+
attributes: Object.freeze(attributes),
|
|
779
|
+
presets: Object.freeze([...new Set(presets)]),
|
|
780
|
+
...definition.shortcut ? { shortcut: definition.shortcut } : {},
|
|
781
|
+
...definition.resolve ? { resolve: definition.resolve } : {},
|
|
782
|
+
...definition.render ? { render: definition.render } : {}
|
|
783
|
+
});
|
|
784
|
+
defined.add(out);
|
|
785
|
+
return out;
|
|
786
|
+
};
|
|
787
|
+
var annotationJsonSchema = (definition) => {
|
|
788
|
+
const properties = {};
|
|
789
|
+
const required = [];
|
|
790
|
+
for (const [key, field] of Object.entries(definition.attributes)) {
|
|
791
|
+
const schema = field.type === "text" ? { type: "string", minLength: 1, maxLength: field.max } : field.type === "enum" ? { type: "string", enum: [...field.values] } : { type: "string", format: "uri-reference", maxLength: 2048 };
|
|
792
|
+
if (field.label) schema.title = field.label;
|
|
793
|
+
properties[key] = schema;
|
|
794
|
+
if (field.required) required.push(key);
|
|
795
|
+
}
|
|
796
|
+
return {
|
|
797
|
+
title: definition.label,
|
|
798
|
+
type: "object",
|
|
799
|
+
properties,
|
|
800
|
+
...required.length ? { required } : {},
|
|
801
|
+
additionalProperties: false,
|
|
802
|
+
"x-mex-stored-as": `<span ${ANNOTATION_ATTRIBUTE}="${definition.name}" ${ANNOTATION_VALUE_PREFIX}<key>="\u2026">`
|
|
803
|
+
};
|
|
804
|
+
};
|
|
805
|
+
var abbreviationAnnotation = defineInlineAnnotation({
|
|
806
|
+
name: ABBREVIATION,
|
|
807
|
+
label: "Abbreviation",
|
|
808
|
+
description: "Short form with its full form (shown as a tooltip and read by screen readers).",
|
|
809
|
+
attributes: { title: { type: "text", max: 200, required: true, label: "Full form" } },
|
|
810
|
+
render: (annotation) => ({ tag: "abbr", attrs: { title: annotation.attrs.title } })
|
|
811
|
+
});
|