magic-editor-x 2.1.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +215 -89
  3. package/bin/magic-editor-x.mjs +190 -0
  4. package/dist/admin/{ConfigurationPage-CK2AbfGW.mjs → ConfigurationPage-3Dir3dAf.mjs} +3 -3
  5. package/dist/admin/{ConfigurationPage-CzsT_dO_.js → ConfigurationPage-YvnPnna6.js} +3 -3
  6. package/dist/admin/{CustomBlocksPage-CvLrsBds.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
  7. package/dist/admin/{CustomBlocksPage-B2A8S5MV.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
  8. package/dist/admin/{EditorField-7YCdXx-v.mjs → EditorField-B8pyAxPE.mjs} +5384 -278
  9. package/dist/admin/{EditorField-BdBCW15Q.js → EditorField-Diq1j8kc.js} +5378 -272
  10. package/dist/admin/{api-CmccMxlN.js → api-Dsq53giv.js} +1 -0
  11. package/dist/admin/{api-D5CAH0nh.mjs → api-RZ0Fz0BD.mjs} +1 -0
  12. package/dist/admin/de-62Vxb2iw.js +250 -0
  13. package/dist/admin/de-BVvwSYYO.mjs +250 -0
  14. package/dist/admin/de-BmmLBJli.mjs +41 -0
  15. package/dist/admin/{de-CkUYGb7U.js → de-BteRx2iA.js} +7 -1
  16. package/dist/admin/{de-rRIutpYJ.mjs → de-CFX5atOk.mjs} +7 -1
  17. package/dist/admin/de-DaJwN6nk.js +41 -0
  18. package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
  19. package/dist/admin/en-Cn78RZs-.js +41 -0
  20. package/dist/admin/{en-DulOcmXb.js → en-CyjAcccB.js} +7 -1
  21. package/dist/admin/en-D7mZWLGp.mjs +41 -0
  22. package/dist/admin/en-VlkaIzrM.js +250 -0
  23. package/dist/admin/{en-Puup8TFi.mjs → en-ea0tfA5i.mjs} +7 -1
  24. package/dist/admin/es-BT9oAcHf.js +250 -0
  25. package/dist/admin/es-BmGtLkJD.js +41 -0
  26. package/dist/admin/{es-BoQZC86B.js → es-C8GZFGjv.js} +7 -1
  27. package/dist/admin/es-C9-cXdb6.mjs +250 -0
  28. package/dist/admin/{es-257SSB7f.mjs → es-CEi_ycX8.mjs} +7 -1
  29. package/dist/admin/es-joykG5I9.mjs +41 -0
  30. package/dist/admin/{fr-C5rSdKU4.mjs → fr-BAMSvQbR.mjs} +7 -1
  31. package/dist/admin/fr-CrzxGe5e.mjs +41 -0
  32. package/dist/admin/fr-Ct_uPqxV.js +41 -0
  33. package/dist/admin/fr-D6KJqPWi.js +250 -0
  34. package/dist/admin/fr-DpU_qiXR.mjs +250 -0
  35. package/dist/admin/{fr-HxFcPpv4.js → fr-oRCJNdeJ.js} +7 -1
  36. package/dist/admin/index-C-lyON1B.mjs +303 -0
  37. package/dist/admin/index-iA0lued_.js +302 -0
  38. package/dist/admin/index.js +1 -1
  39. package/dist/admin/index.mjs +1 -1
  40. package/dist/admin/pt-BOrl6x-r.js +250 -0
  41. package/dist/admin/{pt-D6UuEtPy.mjs → pt-CQrfqsCN.mjs} +7 -1
  42. package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
  43. package/dist/admin/pt-chN2jrXl.js +41 -0
  44. package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
  45. package/dist/admin/{pt-Cjn2Sc9k.js → pt-tUeJ2Ywd.js} +7 -1
  46. package/dist/admin/{sanitize-DP5aeU7V.js → sanitize-Cb4jvBhj.js} +42 -11
  47. package/dist/admin/{sanitize-jjCot5PM.mjs → sanitize-ClkX823p.mjs} +45 -14
  48. package/dist/admin/{useT-91ruePzq.js → useT-BWZ_-Hel.js} +1 -1
  49. package/dist/admin/{useT-vgY88N_H.mjs → useT-pvHmgBFj.mjs} +1 -1
  50. package/dist/render/index.d.mts +75 -0
  51. package/dist/render/index.d.ts +75 -0
  52. package/dist/render/index.js +1420 -0
  53. package/dist/render/index.mjs +1398 -0
  54. package/dist/server/index.js +8081 -348
  55. package/dist/server/index.mjs +8084 -351
  56. package/package.json +21 -4
  57. package/schema/magic-editor-x.schema.json +967 -0
  58. package/types/index.d.ts +211 -0
  59. package/types/render.d.ts +75 -0
  60. package/dist/admin/de-BHPyA2S-.mjs +0 -103
  61. package/dist/admin/de-DBR893G4.js +0 -13
  62. package/dist/admin/de-RMs-_SCK.js +0 -103
  63. package/dist/admin/de-fBFh09Wl.mjs +0 -13
  64. package/dist/admin/en-BluCStLw.mjs +0 -103
  65. package/dist/admin/en-C81faOHP.js +0 -103
  66. package/dist/admin/en-D9Nfccux.mjs +0 -13
  67. package/dist/admin/en-gueRT44P.js +0 -13
  68. package/dist/admin/es-B0Zy8DVg.mjs +0 -13
  69. package/dist/admin/es-CQRI2Prp.mjs +0 -103
  70. package/dist/admin/es-D1QzY0JW.js +0 -103
  71. package/dist/admin/es-DRGs7meF.js +0 -13
  72. package/dist/admin/fr-B8rdLAIL.js +0 -13
  73. package/dist/admin/fr-Di3R6gOX.mjs +0 -103
  74. package/dist/admin/fr-R3_MbzT5.js +0 -103
  75. package/dist/admin/fr-oiUb2bb_.mjs +0 -13
  76. package/dist/admin/index-0_b1iroK.mjs +0 -156
  77. package/dist/admin/index-6SZLli70.js +0 -155
  78. package/dist/admin/pt-B3Jce6uT.mjs +0 -13
  79. package/dist/admin/pt-BCW1u_Hp.js +0 -103
  80. package/dist/admin/pt-BiWuSBcH.js +0 -13
  81. package/dist/admin/pt-Cr9AL408.mjs +0 -103
@@ -142,6 +142,13 @@ const normalizeEditorData = (value) => {
142
142
  }
143
143
  return result;
144
144
  };
145
+ const normalizeEditorDataSafe = (value) => {
146
+ try {
147
+ return normalizeEditorData(value);
148
+ } catch {
149
+ return null;
150
+ }
151
+ };
145
152
  const byteLength = (text) => {
146
153
  let bytes = 0;
147
154
  for (let i = 0; i < text.length; i += 1) {
@@ -231,6 +238,7 @@ const INLINE_CLASSES = Object.freeze({
231
238
  });
232
239
  const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
233
240
  const MAX_URL_LENGTH = 2048;
241
+ const TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
234
242
  const sanitizeUrl = (value, options = {}) => {
235
243
  const schemes = options.schemes || LINK_SCHEMES;
236
244
  const allowRelative = options.allowRelative !== false;
@@ -351,7 +359,7 @@ const BLOCK_POLICIES = {
351
359
  codeFlask: (d) => {
352
360
  const out = {
353
361
  code: plain(d.code, 5e5),
354
- language: /^[a-z0-9+#-]{1,32}$/i.test(d.language || "") ? d.language : "plaintext"
362
+ language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
355
363
  };
356
364
  if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
357
365
  return out;
@@ -378,21 +386,28 @@ const BLOCK_POLICIES = {
378
386
  if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
379
387
  cleanFile.id = file.id;
380
388
  if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
381
- return {
389
+ const out = {
382
390
  file: cleanFile,
383
391
  caption: inline(d.caption),
384
392
  withBorder: bool(d.withBorder),
385
393
  withBackground: bool(d.withBackground),
386
394
  stretched: bool(d.stretched)
387
395
  };
396
+ if (d.decorative === true) out.decorative = true;
397
+ return out;
398
+ },
399
+ simpleImage: (d, inline) => {
400
+ const out = {
401
+ url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
402
+ caption: inline(d.caption),
403
+ withBorder: bool(d.withBorder),
404
+ withBackground: bool(d.withBackground),
405
+ stretched: bool(d.stretched)
406
+ };
407
+ if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
408
+ if (d.decorative === true) out.decorative = true;
409
+ return out;
388
410
  },
389
- simpleImage: (d, inline) => ({
390
- url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
391
- caption: inline(d.caption),
392
- withBorder: bool(d.withBorder),
393
- withBackground: bool(d.withBackground),
394
- stretched: bool(d.stretched)
395
- }),
396
411
  linkTool: (d) => {
397
412
  const meta = isPlainObject(d.meta) ? d.meta : {};
398
413
  const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
@@ -411,7 +426,7 @@ const BLOCK_POLICIES = {
411
426
  return { file: cleanFile, title: plain(d.title, 255) };
412
427
  },
413
428
  embed: (d, inline) => ({
414
- service: /^[a-z0-9_-]{1,40}$/i.test(d.service || "") ? d.service : "",
429
+ service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
415
430
  source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
416
431
  embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
417
432
  width: int(d.width, 1, 1e4, void 0),
@@ -463,6 +478,7 @@ const sanitizeEditorData = (data, options) => {
463
478
  });
464
479
  return { time: data.time, blocks, version: data.version };
465
480
  };
481
+ const sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
466
482
  let purify = null;
467
483
  const instance = () => {
468
484
  if (purify) return purify;
@@ -502,7 +518,12 @@ const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat())
502
518
  const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
503
519
  ALLOWED_TAGS: [...INLINE_TAGS],
504
520
  ALLOWED_ATTR,
505
- ALLOW_DATA_ATTR: false
521
+ ALLOW_DATA_ATTR: false,
522
+ // DOMPurify checks attribute values like URIs; `api::article.article` looks
523
+ // like an unknown scheme and was dropped, which removed the entry reference
524
+ // of internal links whenever content was shown again. The values are
525
+ // validated by cleanInternalLinkAttributes in the hook above.
526
+ ADD_URI_SAFE_ATTR: [...INTERNAL_LINK_ATTRIBUTES]
506
527
  });
507
528
  const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
508
529
  ALLOWED_TAGS: [
@@ -585,13 +606,23 @@ const prepareRemoteData = (data, cache) => {
585
606
  }
586
607
  return { time: data && data.time || Date.now(), version: data && data.version || "2.31.7", blocks };
587
608
  };
609
+ exports.BLOCK_POLICIES = BLOCK_POLICIES;
588
610
  exports.EDITOR_DATA_LIMITS = EDITOR_DATA_LIMITS;
611
+ exports.INLINE_ATTRIBUTES = INLINE_ATTRIBUTES;
612
+ exports.INLINE_CLASSES = INLINE_CLASSES;
613
+ exports.INLINE_TAGS = INLINE_TAGS;
614
+ exports.cleanInternalLinkAttributes = cleanInternalLinkAttributes;
589
615
  exports.cloneJsonSafe = cloneJsonSafe;
590
616
  exports.computeStats = computeStats;
617
+ exports.escapeHtml = escapeHtml;
618
+ exports.hashString = hashString;
591
619
  exports.isPlainObject = isPlainObject;
620
+ exports.normalizeEditorDataSafe = normalizeEditorDataSafe;
592
621
  exports.prepareEditorValue = prepareEditorValue;
593
622
  exports.prepareRemoteData = prepareRemoteData;
594
623
  exports.sanitizeInline = sanitizeInline;
595
624
  exports.sanitizeSvg = sanitizeSvg;
625
+ exports.sanitizeTarget = sanitizeTarget;
596
626
  exports.sanitizeTemplate = sanitizeTemplate;
627
+ exports.sanitizeTunes = sanitizeTunes;
597
628
  exports.sanitizeUrl = sanitizeUrl;
@@ -139,6 +139,13 @@ const normalizeEditorData = (value) => {
139
139
  }
140
140
  return result;
141
141
  };
142
+ const normalizeEditorDataSafe = (value) => {
143
+ try {
144
+ return normalizeEditorData(value);
145
+ } catch {
146
+ return null;
147
+ }
148
+ };
142
149
  const byteLength = (text) => {
143
150
  let bytes = 0;
144
151
  for (let i = 0; i < text.length; i += 1) {
@@ -228,6 +235,7 @@ const INLINE_CLASSES = Object.freeze({
228
235
  });
229
236
  const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
230
237
  const MAX_URL_LENGTH = 2048;
238
+ const TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
231
239
  const sanitizeUrl = (value, options = {}) => {
232
240
  const schemes = options.schemes || LINK_SCHEMES;
233
241
  const allowRelative = options.allowRelative !== false;
@@ -348,7 +356,7 @@ const BLOCK_POLICIES = {
348
356
  codeFlask: (d) => {
349
357
  const out = {
350
358
  code: plain(d.code, 5e5),
351
- language: /^[a-z0-9+#-]{1,32}$/i.test(d.language || "") ? d.language : "plaintext"
359
+ language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
352
360
  };
353
361
  if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
354
362
  return out;
@@ -375,21 +383,28 @@ const BLOCK_POLICIES = {
375
383
  if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
376
384
  cleanFile.id = file.id;
377
385
  if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
378
- return {
386
+ const out = {
379
387
  file: cleanFile,
380
388
  caption: inline(d.caption),
381
389
  withBorder: bool(d.withBorder),
382
390
  withBackground: bool(d.withBackground),
383
391
  stretched: bool(d.stretched)
384
392
  };
393
+ if (d.decorative === true) out.decorative = true;
394
+ return out;
395
+ },
396
+ simpleImage: (d, inline) => {
397
+ const out = {
398
+ url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
399
+ caption: inline(d.caption),
400
+ withBorder: bool(d.withBorder),
401
+ withBackground: bool(d.withBackground),
402
+ stretched: bool(d.stretched)
403
+ };
404
+ if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
405
+ if (d.decorative === true) out.decorative = true;
406
+ return out;
385
407
  },
386
- simpleImage: (d, inline) => ({
387
- url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
388
- caption: inline(d.caption),
389
- withBorder: bool(d.withBorder),
390
- withBackground: bool(d.withBackground),
391
- stretched: bool(d.stretched)
392
- }),
393
408
  linkTool: (d) => {
394
409
  const meta = isPlainObject(d.meta) ? d.meta : {};
395
410
  const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
@@ -408,7 +423,7 @@ const BLOCK_POLICIES = {
408
423
  return { file: cleanFile, title: plain(d.title, 255) };
409
424
  },
410
425
  embed: (d, inline) => ({
411
- service: /^[a-z0-9_-]{1,40}$/i.test(d.service || "") ? d.service : "",
426
+ service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
412
427
  source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
413
428
  embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
414
429
  width: int(d.width, 1, 1e4, void 0),
@@ -460,6 +475,7 @@ const sanitizeEditorData = (data, options) => {
460
475
  });
461
476
  return { time: data.time, blocks, version: data.version };
462
477
  };
478
+ const sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
463
479
  let purify = null;
464
480
  const instance = () => {
465
481
  if (purify) return purify;
@@ -499,7 +515,12 @@ const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat())
499
515
  const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
500
516
  ALLOWED_TAGS: [...INLINE_TAGS],
501
517
  ALLOWED_ATTR,
502
- ALLOW_DATA_ATTR: false
518
+ ALLOW_DATA_ATTR: false,
519
+ // DOMPurify checks attribute values like URIs; `api::article.article` looks
520
+ // like an unknown scheme and was dropped, which removed the entry reference
521
+ // of internal links whenever content was shown again. The values are
522
+ // validated by cleanInternalLinkAttributes in the hook above.
523
+ ADD_URI_SAFE_ATTR: [...INTERNAL_LINK_ATTRIBUTES]
503
524
  });
504
525
  const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
505
526
  ALLOWED_TAGS: [
@@ -583,14 +604,24 @@ const prepareRemoteData = (data, cache) => {
583
604
  return { time: data && data.time || Date.now(), version: data && data.version || "2.31.7", blocks };
584
605
  };
585
606
  export {
607
+ BLOCK_POLICIES as B,
586
608
  EDITOR_DATA_LIMITS as E,
609
+ INLINE_TAGS as I,
587
610
  sanitizeInline as a,
588
611
  sanitizeSvg as b,
589
612
  sanitizeTemplate as c,
590
- cloneJsonSafe as d,
591
- computeStats as e,
592
- prepareRemoteData as f,
613
+ INLINE_ATTRIBUTES as d,
614
+ sanitizeTarget as e,
615
+ INLINE_CLASSES as f,
616
+ cleanInternalLinkAttributes as g,
617
+ computeStats as h,
593
618
  isPlainObject as i,
619
+ cloneJsonSafe as j,
620
+ sanitizeTunes as k,
621
+ hashString as l,
622
+ escapeHtml as m,
623
+ normalizeEditorDataSafe as n,
624
+ prepareRemoteData as o,
594
625
  prepareEditorValue as p,
595
626
  sanitizeUrl as s
596
627
  };
@@ -4,7 +4,7 @@ const react = require("react");
4
4
  const designSystem = require("@strapi/design-system");
5
5
  const admin = require("@strapi/strapi/admin");
6
6
  const reactIntl = require("react-intl");
7
- const index = require("./index-6SZLli70.js");
7
+ const index = require("./index-iA0lued_.js");
8
8
  const PageShell = ({
9
9
  title,
10
10
  subtitle,
@@ -3,7 +3,7 @@ import { useId, useState, useRef, useCallback } from "react";
3
3
  import { Flex, Box, Typography, Dialog, Button } from "@strapi/design-system";
4
4
  import { Page, Layouts, ConfirmDialog } from "@strapi/strapi/admin";
5
5
  import { useIntl } from "react-intl";
6
- import { g as getTranslation } from "./index-0_b1iroK.mjs";
6
+ import { g as getTranslation } from "./index-C-lyON1B.mjs";
7
7
  const PageShell = ({
8
8
  title,
9
9
  subtitle,
@@ -0,0 +1,75 @@
1
+ /** Types of `magic-editor-x/render`. */
2
+
3
+ import type { ImageFile, MagicEditorXTunes } from '../../types/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[];
@@ -0,0 +1,75 @@
1
+ /** Types of `magic-editor-x/render`. */
2
+
3
+ import type { ImageFile, MagicEditorXTunes } from '../../types/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[];