@stream-mdx/react 0.3.0 → 0.4.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/README.md CHANGED
@@ -42,9 +42,10 @@ export function Demo({ text }: { text: string }) {
42
42
 
43
43
  ## Docs
44
44
 
45
- - API reference: `docs/PUBLIC_API.md`
46
- - React integration guide: `docs/REACT_INTEGRATION_GUIDE.md`
47
- - Plugins & worker customization: `docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md`
45
+ - API reference: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/PUBLIC_API.md
46
+ - React integration guide: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/REACT_INTEGRATION_GUIDE.md
47
+ - Plugins & worker customization: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md
48
+ - Full docs site: https://kmccleary3301.github.io/stream-mdx/
48
49
 
49
50
  ## Addons
50
51
 
@@ -1054,15 +1054,17 @@ var defaultBlockComponents = {
1054
1054
  effectiveInlines.length > 0 ? renderInlineNodes(effectiveInlines, defaultInlineComponents) : raw ?? ""
1055
1055
  );
1056
1056
  },
1057
- heading: ({ level, inlines, text }) => {
1057
+ heading: ({ level, inlines, text, meta }) => {
1058
1058
  const tag = `h${level}`;
1059
1059
  const onlyPlainText = Array.isArray(inlines) && inlines.length > 0 && inlines.every((node) => node.kind === "text");
1060
1060
  const children = onlyPlainText ? inlines.map((node) => node.kind === "text" ? node.text : "").join("") : renderInlineNodes(inlines, defaultInlineComponents);
1061
+ const headingId = typeof meta?.headingId === "string" && meta.headingId.length > 0 ? meta.headingId : void 0;
1061
1062
  return import_react5.default.createElement(
1062
1063
  tag,
1063
1064
  {
1064
1065
  className: `markdown-heading markdown-h${level}`,
1065
- ...text ? { "data-heading-text": text } : {}
1066
+ ...text ? { "data-heading-text": text } : {},
1067
+ ...headingId ? { id: headingId, "data-heading-id": headingId } : {}
1066
1068
  },
1067
1069
  children
1068
1070
  );
@@ -1147,7 +1149,7 @@ var defaultBlockComponents = {
1147
1149
  },
1148
1150
  html: ({ __trustedHtml, elements }) => {
1149
1151
  const raw = typeof __trustedHtml === "string" ? __trustedHtml : __trustedHtml.toString();
1150
- const htmlString = (0, import_core.sanitizeHTML)(raw);
1152
+ const htmlString = typeof window === "undefined" ? raw : (0, import_core.sanitizeHTML)(raw);
1151
1153
  if (typeof window !== "undefined" && elements) {
1152
1154
  const content = mapHtmlToReact(htmlString, elements);
1153
1155
  return import_react5.default.createElement("div", { className: "markdown-html" }, content);
@@ -1505,7 +1507,9 @@ var ComponentRegistry = class {
1505
1507
  case "html": {
1506
1508
  const trusted = block.payload.sanitizedHtml ?? block.payload.raw;
1507
1509
  return {
1508
- __trustedHtml: (0, import_core.createTrustedHTML)(trusted),
1510
+ // Server render should not depend on DOMPurify (which requires a DOM `window`).
1511
+ // In worker-compiled flows, `sanitizedHtml` is already sanitized at the source.
1512
+ __trustedHtml: typeof window === "undefined" ? String(trusted ?? "") : (0, import_core.createTrustedHTML)(String(trusted ?? "")),
1509
1513
  elements: this.htmlElements
1510
1514
  };
1511
1515
  }
@@ -1,3 +1,3 @@
1
1
  import '@stream-mdx/core';
2
2
  import 'react';
3
- export { C as ComponentRegistry, D as DefaultLinkSafetyModal, L as LinkSafetyModalProps, f as defaultBlockComponents, e as defaultInlineComponents, m as mapHtmlToReact, r as renderInlineNodes, g as renderParagraphMixedSegments } from '../index-D7px9jug.cjs';
3
+ export { C as ComponentRegistry, D as DefaultLinkSafetyModal, L as LinkSafetyModalProps, e as defaultBlockComponents, d as defaultInlineComponents, m as mapHtmlToReact, r as renderInlineNodes, f as renderParagraphMixedSegments } from '../index-D2MYusAM.cjs';
@@ -1,3 +1,3 @@
1
1
  import '@stream-mdx/core';
2
2
  import 'react';
3
- export { C as ComponentRegistry, D as DefaultLinkSafetyModal, L as LinkSafetyModalProps, f as defaultBlockComponents, e as defaultInlineComponents, m as mapHtmlToReact, r as renderInlineNodes, g as renderParagraphMixedSegments } from '../index-D7px9jug.js';
3
+ export { C as ComponentRegistry, D as DefaultLinkSafetyModal, L as LinkSafetyModalProps, e as defaultBlockComponents, d as defaultInlineComponents, m as mapHtmlToReact, r as renderInlineNodes, f as renderParagraphMixedSegments } from '../index-D2MYusAM.js';
@@ -1021,15 +1021,17 @@ var defaultBlockComponents = {
1021
1021
  effectiveInlines.length > 0 ? renderInlineNodes(effectiveInlines, defaultInlineComponents) : raw ?? ""
1022
1022
  );
1023
1023
  },
1024
- heading: ({ level, inlines, text }) => {
1024
+ heading: ({ level, inlines, text, meta }) => {
1025
1025
  const tag = `h${level}`;
1026
1026
  const onlyPlainText = Array.isArray(inlines) && inlines.length > 0 && inlines.every((node) => node.kind === "text");
1027
1027
  const children = onlyPlainText ? inlines.map((node) => node.kind === "text" ? node.text : "").join("") : renderInlineNodes(inlines, defaultInlineComponents);
1028
+ const headingId = typeof meta?.headingId === "string" && meta.headingId.length > 0 ? meta.headingId : void 0;
1028
1029
  return React4.createElement(
1029
1030
  tag,
1030
1031
  {
1031
1032
  className: `markdown-heading markdown-h${level}`,
1032
- ...text ? { "data-heading-text": text } : {}
1033
+ ...text ? { "data-heading-text": text } : {},
1034
+ ...headingId ? { id: headingId, "data-heading-id": headingId } : {}
1033
1035
  },
1034
1036
  children
1035
1037
  );
@@ -1114,7 +1116,7 @@ var defaultBlockComponents = {
1114
1116
  },
1115
1117
  html: ({ __trustedHtml, elements }) => {
1116
1118
  const raw = typeof __trustedHtml === "string" ? __trustedHtml : __trustedHtml.toString();
1117
- const htmlString = sanitizeHTML(raw);
1119
+ const htmlString = typeof window === "undefined" ? raw : sanitizeHTML(raw);
1118
1120
  if (typeof window !== "undefined" && elements) {
1119
1121
  const content = mapHtmlToReact(htmlString, elements);
1120
1122
  return React4.createElement("div", { className: "markdown-html" }, content);
@@ -1472,7 +1474,9 @@ var ComponentRegistry = class {
1472
1474
  case "html": {
1473
1475
  const trusted = block.payload.sanitizedHtml ?? block.payload.raw;
1474
1476
  return {
1475
- __trustedHtml: createTrustedHTML(trusted),
1477
+ // Server render should not depend on DOMPurify (which requires a DOM `window`).
1478
+ // In worker-compiled flows, `sanitizedHtml` is already sanitized at the source.
1479
+ __trustedHtml: typeof window === "undefined" ? String(trusted ?? "") : createTrustedHTML(String(trusted ?? "")),
1476
1480
  elements: this.htmlElements
1477
1481
  };
1478
1482
  }
@@ -245,4 +245,4 @@ declare class ComponentRegistry {
245
245
  declare function mapHtmlToReact(html: string, elements: HtmlElements): React.ReactNode;
246
246
  declare function renderParagraphMixedSegments(segments: MixedContentSegment[], inlineComponents: InlineComponents, inlineHtmlRenderers: InlineHtmlRendererMap): React.ReactNode[];
247
247
 
248
- export { type BlockComponents as B, ComponentRegistry as C, DefaultLinkSafetyModal as D, type HtmlElements as H, type InlineComponents as I, type LinkSafetyModalProps as L, type Renderer as R, type TableElements as T, type RendererConfig as a, type CodeHighlightRangeRequest as b, type InlineHtmlRendererMap as c, type InlineHtmlRenderer as d, defaultInlineComponents as e, defaultBlockComponents as f, renderParagraphMixedSegments as g, mapHtmlToReact as m, renderInlineNodes as r };
248
+ export { type BlockComponents as B, ComponentRegistry as C, DefaultLinkSafetyModal as D, type HtmlElements as H, type InlineHtmlRendererMap as I, type LinkSafetyModalProps as L, type Renderer as R, type TableElements as T, type InlineComponents as a, type InlineHtmlRenderer as b, type RendererConfig as c, defaultInlineComponents as d, defaultBlockComponents as e, renderParagraphMixedSegments as f, type CodeHighlightRangeRequest as g, mapHtmlToReact as m, renderInlineNodes as r };
@@ -245,4 +245,4 @@ declare class ComponentRegistry {
245
245
  declare function mapHtmlToReact(html: string, elements: HtmlElements): React.ReactNode;
246
246
  declare function renderParagraphMixedSegments(segments: MixedContentSegment[], inlineComponents: InlineComponents, inlineHtmlRenderers: InlineHtmlRendererMap): React.ReactNode[];
247
247
 
248
- export { type BlockComponents as B, ComponentRegistry as C, DefaultLinkSafetyModal as D, type HtmlElements as H, type InlineComponents as I, type LinkSafetyModalProps as L, type Renderer as R, type TableElements as T, type RendererConfig as a, type CodeHighlightRangeRequest as b, type InlineHtmlRendererMap as c, type InlineHtmlRenderer as d, defaultInlineComponents as e, defaultBlockComponents as f, renderParagraphMixedSegments as g, mapHtmlToReact as m, renderInlineNodes as r };
248
+ export { type BlockComponents as B, ComponentRegistry as C, DefaultLinkSafetyModal as D, type HtmlElements as H, type InlineHtmlRendererMap as I, type LinkSafetyModalProps as L, type Renderer as R, type TableElements as T, type InlineComponents as a, type InlineHtmlRenderer as b, type RendererConfig as c, defaultInlineComponents as d, defaultBlockComponents as e, renderParagraphMixedSegments as f, type CodeHighlightRangeRequest as g, mapHtmlToReact as m, renderInlineNodes as r };