@stream-mdx/react 0.1.1 → 0.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.
- package/dist/components/index.cjs +497 -163
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.mjs +496 -163
- package/dist/{index-Bt1opGCs.d.cts → index-D7px9jug.d.cts} +27 -2
- package/dist/{index-Bt1opGCs.d.ts → index-D7px9jug.d.ts} +27 -2
- package/dist/index.cjs +3767 -2043
- package/dist/index.d.cts +43 -5
- package/dist/index.d.ts +43 -5
- package/dist/index.mjs +3991 -2265
- package/dist/mdx-client.cjs +60 -18
- package/dist/mdx-client.d.cts +11 -0
- package/dist/mdx-client.d.ts +11 -0
- package/dist/mdx-client.mjs +60 -18
- package/dist/mdx-coordinator.cjs +60 -18
- package/dist/mdx-coordinator.mjs +60 -18
- package/dist/renderer/node-views.cjs +466 -133
- package/dist/renderer/node-views.d.cts +1 -1
- package/dist/renderer/node-views.d.ts +1 -1
- package/dist/renderer/node-views.mjs +409 -68
- package/dist/renderer/patch-commit-scheduler.cjs +68 -7
- package/dist/renderer/patch-commit-scheduler.d.cts +6 -5
- package/dist/renderer/patch-commit-scheduler.d.ts +6 -5
- package/dist/renderer/patch-commit-scheduler.mjs +68 -7
- package/dist/renderer/store.cjs +481 -56
- package/dist/renderer/store.d.cts +2 -1
- package/dist/renderer/store.d.ts +2 -1
- package/dist/renderer/store.mjs +479 -47
- package/dist/renderer/virtualized-code.cjs +8 -2
- package/dist/renderer/virtualized-code.d.cts +4 -0
- package/dist/renderer/virtualized-code.d.ts +4 -0
- package/dist/renderer/virtualized-code.mjs +8 -2
- package/dist/renderer.cjs +3199 -2208
- package/dist/renderer.d.cts +4 -2
- package/dist/renderer.d.ts +4 -2
- package/dist/renderer.mjs +2956 -1957
- package/dist/streaming-markdown-DSC4L0xR.d.cts +157 -0
- package/dist/streaming-markdown-Dp1IDgMT.d.ts +157 -0
- package/dist/streaming-markdown.cjs +3950 -2248
- package/dist/streaming-markdown.d.cts +6 -95
- package/dist/streaming-markdown.d.ts +6 -95
- package/dist/streaming-markdown.mjs +3962 -2252
- package/dist/utils/inline-html.d.cts +1 -1
- package/dist/utils/inline-html.d.ts +1 -1
- package/package.json +3 -3
|
@@ -92,6 +92,8 @@ var init_mdx_client = __esm({
|
|
|
92
92
|
constructor(compileEndpoint = "/api/mdx-compile-v2") {
|
|
93
93
|
this.cache = /* @__PURE__ */ new Map();
|
|
94
94
|
this.inlineModules = /* @__PURE__ */ new Map();
|
|
95
|
+
this.compiledCache = /* @__PURE__ */ new Map();
|
|
96
|
+
this.compiledInflight = /* @__PURE__ */ new Map();
|
|
95
97
|
this.compileEndpoint = compileEndpoint;
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
@@ -116,34 +118,53 @@ var init_mdx_client = __esm({
|
|
|
116
118
|
throw error;
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
|
-
|
|
120
|
-
* Get compiled MDX by reference
|
|
121
|
-
*/
|
|
122
|
-
async getCompiled(ref) {
|
|
121
|
+
async getCompiledInternal(ref) {
|
|
123
122
|
const inline = this.inlineModules.get(ref.id);
|
|
124
123
|
if (inline) {
|
|
125
|
-
return
|
|
126
|
-
...inline,
|
|
127
|
-
dependencies: Array.isArray(inline.dependencies) ? [...inline.dependencies] : []
|
|
128
|
-
};
|
|
124
|
+
return this.cloneCompiled(inline);
|
|
129
125
|
}
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
126
|
+
const cached = this.compiledCache.get(ref.id);
|
|
127
|
+
if (cached) {
|
|
128
|
+
return this.cloneCompiled(cached);
|
|
133
129
|
}
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
const inflight = this.compiledInflight.get(ref.id);
|
|
131
|
+
if (inflight) {
|
|
132
|
+
const resolved = await inflight;
|
|
133
|
+
return this.cloneCompiled(resolved);
|
|
134
|
+
}
|
|
135
|
+
const fetchPromise = this.fetchCompiled(ref);
|
|
136
|
+
this.compiledInflight.set(ref.id, fetchPromise);
|
|
137
|
+
try {
|
|
138
|
+
const data = await fetchPromise;
|
|
139
|
+
this.compiledCache.set(ref.id, data);
|
|
140
|
+
return this.cloneCompiled(data);
|
|
141
|
+
} finally {
|
|
142
|
+
this.compiledInflight.delete(ref.id);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async getCompiled(ref, options) {
|
|
146
|
+
if (options?.signal) {
|
|
147
|
+
const inline = this.inlineModules.get(ref.id);
|
|
148
|
+
if (inline) {
|
|
149
|
+
return this.cloneCompiled(inline);
|
|
150
|
+
}
|
|
151
|
+
const cached = this.compiledCache.get(ref.id);
|
|
152
|
+
if (cached) {
|
|
153
|
+
return this.cloneCompiled(cached);
|
|
154
|
+
}
|
|
155
|
+
const data = await this.fetchCompiled(ref, options);
|
|
156
|
+
this.compiledCache.set(ref.id, data);
|
|
157
|
+
return this.cloneCompiled(data);
|
|
158
|
+
}
|
|
159
|
+
return this.getCompiledInternal(ref);
|
|
141
160
|
}
|
|
142
161
|
/**
|
|
143
162
|
* Clear compilation cache
|
|
144
163
|
*/
|
|
145
164
|
clearCache() {
|
|
146
165
|
this.cache.clear();
|
|
166
|
+
this.compiledCache.clear();
|
|
167
|
+
this.compiledInflight.clear();
|
|
147
168
|
}
|
|
148
169
|
registerInlineModule(compiled) {
|
|
149
170
|
this.inlineModules.set(compiled.id, {
|
|
@@ -180,6 +201,27 @@ var init_mdx_client = __esm({
|
|
|
180
201
|
cached: data.cached || false
|
|
181
202
|
};
|
|
182
203
|
}
|
|
204
|
+
async fetchCompiled(ref, options) {
|
|
205
|
+
const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
|
|
206
|
+
signal: options?.signal
|
|
207
|
+
});
|
|
208
|
+
if (!response.ok) {
|
|
209
|
+
throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
|
|
210
|
+
}
|
|
211
|
+
const data = await response.json();
|
|
212
|
+
return {
|
|
213
|
+
id: data.id,
|
|
214
|
+
code: data.code,
|
|
215
|
+
dependencies: data.dependencies || [],
|
|
216
|
+
timestamp: data.timestamp
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
cloneCompiled(compiled) {
|
|
220
|
+
return {
|
|
221
|
+
...compiled,
|
|
222
|
+
dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
|
|
223
|
+
};
|
|
224
|
+
}
|
|
183
225
|
};
|
|
184
226
|
MDXComponentFactory = class {
|
|
185
227
|
constructor(mdxClient) {
|
|
@@ -368,6 +410,7 @@ var init_mdx_client = __esm({
|
|
|
368
410
|
var components_exports = {};
|
|
369
411
|
__export(components_exports, {
|
|
370
412
|
ComponentRegistry: () => ComponentRegistry,
|
|
413
|
+
DefaultLinkSafetyModal: () => DefaultLinkSafetyModal,
|
|
371
414
|
defaultBlockComponents: () => defaultBlockComponents,
|
|
372
415
|
defaultInlineComponents: () => defaultInlineComponents,
|
|
373
416
|
mapHtmlToReact: () => mapHtmlToReact,
|
|
@@ -376,11 +419,118 @@ __export(components_exports, {
|
|
|
376
419
|
});
|
|
377
420
|
module.exports = __toCommonJS(components_exports);
|
|
378
421
|
var import_core = require("@stream-mdx/core");
|
|
422
|
+
|
|
423
|
+
// src/mdx-hydration-metrics.ts
|
|
424
|
+
var entries = /* @__PURE__ */ new Map();
|
|
425
|
+
var lastHydrationMs = null;
|
|
426
|
+
function now() {
|
|
427
|
+
if (typeof performance !== "undefined" && typeof performance.now === "function") {
|
|
428
|
+
return performance.now();
|
|
429
|
+
}
|
|
430
|
+
return Date.now();
|
|
431
|
+
}
|
|
432
|
+
function markMdxHydrationStart(id) {
|
|
433
|
+
if (!id) return;
|
|
434
|
+
const entry = entries.get(id) ?? { status: "compiled" };
|
|
435
|
+
if (entry.startedAt === void 0) {
|
|
436
|
+
entry.startedAt = now();
|
|
437
|
+
}
|
|
438
|
+
entry.status = "compiled";
|
|
439
|
+
entries.set(id, entry);
|
|
440
|
+
}
|
|
441
|
+
function markMdxHydrated(id) {
|
|
442
|
+
if (!id) return;
|
|
443
|
+
const entry = entries.get(id) ?? { status: "hydrated" };
|
|
444
|
+
if (entry.startedAt === void 0) {
|
|
445
|
+
entry.startedAt = now();
|
|
446
|
+
}
|
|
447
|
+
entry.hydratedAt = now();
|
|
448
|
+
entry.status = "hydrated";
|
|
449
|
+
entries.set(id, entry);
|
|
450
|
+
lastHydrationMs = entry.startedAt ? entry.hydratedAt - entry.startedAt : null;
|
|
451
|
+
}
|
|
452
|
+
function markMdxHydrationError(id) {
|
|
453
|
+
if (!id) return;
|
|
454
|
+
const entry = entries.get(id) ?? { status: "error" };
|
|
455
|
+
entry.status = "error";
|
|
456
|
+
entries.set(id, entry);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/mdx-hydration-context.ts
|
|
460
|
+
var import_react = __toESM(require("react"), 1);
|
|
461
|
+
var MdxHydrationContext = import_react.default.createContext({ controller: null });
|
|
462
|
+
|
|
463
|
+
// src/mdx-runtime.ts
|
|
464
|
+
var mdxRuntimePromise = null;
|
|
465
|
+
function loadMdxRuntime() {
|
|
466
|
+
if (!mdxRuntimePromise) {
|
|
467
|
+
mdxRuntimePromise = Promise.resolve().then(() => (init_mdx_client(), mdx_client_exports));
|
|
468
|
+
}
|
|
469
|
+
return mdxRuntimePromise;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/renderer/use-deferred-render.ts
|
|
473
|
+
var import_react3 = require("react");
|
|
474
|
+
function useDeferredRender(ref, options) {
|
|
475
|
+
const enabled = options?.enabled ?? true;
|
|
476
|
+
const [shouldRender, setShouldRender] = (0, import_react3.useState)(!enabled);
|
|
477
|
+
(0, import_react3.useEffect)(() => {
|
|
478
|
+
if (!enabled) {
|
|
479
|
+
setShouldRender(true);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const target = ref.current;
|
|
483
|
+
if (!target) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
let cancelled = false;
|
|
487
|
+
let idleId = null;
|
|
488
|
+
let timerId = null;
|
|
489
|
+
const scheduleRender = () => {
|
|
490
|
+
if (cancelled) return;
|
|
491
|
+
setShouldRender(true);
|
|
492
|
+
};
|
|
493
|
+
const runWithIdle = () => {
|
|
494
|
+
if (typeof globalThis.requestIdleCallback === "function") {
|
|
495
|
+
idleId = globalThis.requestIdleCallback(scheduleRender, { timeout: options?.idleTimeoutMs ?? 200 });
|
|
496
|
+
} else {
|
|
497
|
+
timerId = window.setTimeout(scheduleRender, options?.idleTimeoutMs ?? 200);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const observer = new IntersectionObserver(
|
|
501
|
+
(entries2) => {
|
|
502
|
+
for (const entry of entries2) {
|
|
503
|
+
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
504
|
+
observer.disconnect();
|
|
505
|
+
const debounceMs = options?.debounceMs ?? 80;
|
|
506
|
+
timerId = window.setTimeout(runWithIdle, debounceMs);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
{ rootMargin: options?.rootMargin ?? "200px 0px" }
|
|
512
|
+
);
|
|
513
|
+
observer.observe(target);
|
|
514
|
+
return () => {
|
|
515
|
+
cancelled = true;
|
|
516
|
+
observer.disconnect();
|
|
517
|
+
if (idleId !== null && typeof globalThis.cancelIdleCallback === "function") {
|
|
518
|
+
globalThis.cancelIdleCallback(idleId);
|
|
519
|
+
}
|
|
520
|
+
if (timerId !== null) {
|
|
521
|
+
window.clearTimeout(timerId);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
}, [enabled, options?.debounceMs, options?.idleTimeoutMs, options?.rootMargin, ref]);
|
|
525
|
+
return shouldRender;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/components/index.ts
|
|
379
529
|
var import_core2 = require("@stream-mdx/core");
|
|
380
|
-
var
|
|
530
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
381
531
|
|
|
382
532
|
// src/utils/inline-html.ts
|
|
383
|
-
var
|
|
533
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
384
534
|
var BACKTICK_CONTENT = /^`([\s\S]+)`$/;
|
|
385
535
|
var DEFAULT_INLINE_HTML_RENDERERS = {
|
|
386
536
|
kbd: (descriptor, ctx) => {
|
|
@@ -392,7 +542,7 @@ var DEFAULT_INLINE_HTML_RENDERERS = {
|
|
|
392
542
|
if (ctx.key !== void 0 && ctx.key !== null) {
|
|
393
543
|
props.key = ctx.key;
|
|
394
544
|
}
|
|
395
|
-
return
|
|
545
|
+
return import_react4.default.createElement("kbd", props, import_react4.default.createElement("code", { className: "inline-code" }, codeText));
|
|
396
546
|
}
|
|
397
547
|
return ctx.defaultRender();
|
|
398
548
|
}
|
|
@@ -410,9 +560,9 @@ function renderInlineHtmlSegment(raw, sanitized, options = {}) {
|
|
|
410
560
|
return null;
|
|
411
561
|
}
|
|
412
562
|
if (options.key !== void 0 && options.key !== null) {
|
|
413
|
-
return
|
|
563
|
+
return import_react4.default.createElement(import_react4.default.Fragment, { key: options.key }, descriptor.text);
|
|
414
564
|
}
|
|
415
|
-
return
|
|
565
|
+
return import_react4.default.createElement(import_react4.default.Fragment, {}, descriptor.text);
|
|
416
566
|
}
|
|
417
567
|
if (isInlineTag) {
|
|
418
568
|
const parsedElement = renderSanitizedHtmlTree(descriptor.sanitized, options.key);
|
|
@@ -427,15 +577,15 @@ function renderInlineHtmlSegment(raw, sanitized, options = {}) {
|
|
|
427
577
|
if (options.key !== void 0 && options.key !== null) {
|
|
428
578
|
props.key = options.key;
|
|
429
579
|
}
|
|
430
|
-
return
|
|
580
|
+
return import_react4.default.createElement("span", props);
|
|
431
581
|
};
|
|
432
582
|
const allRenderers = options.renderers ? { ...DEFAULT_INLINE_HTML_RENDERERS, ...options.renderers } : DEFAULT_INLINE_HTML_RENDERERS;
|
|
433
583
|
const renderer = allRenderers[descriptor.tagName];
|
|
434
584
|
if (renderer) {
|
|
435
585
|
const rendered = renderer(descriptor, { key: options.key, defaultRender });
|
|
436
586
|
if (rendered) {
|
|
437
|
-
if (options.key !== void 0 && options.key !== null &&
|
|
438
|
-
return
|
|
587
|
+
if (options.key !== void 0 && options.key !== null && import_react4.default.isValidElement(rendered) && rendered.key === null) {
|
|
588
|
+
return import_react4.default.cloneElement(rendered, { key: options.key });
|
|
439
589
|
}
|
|
440
590
|
return rendered;
|
|
441
591
|
}
|
|
@@ -547,21 +697,21 @@ function renderSanitizedHtmlTree(html, key) {
|
|
|
547
697
|
}
|
|
548
698
|
if (children.length === 1) {
|
|
549
699
|
const [child] = children;
|
|
550
|
-
if (
|
|
700
|
+
if (import_react4.default.isValidElement(child)) {
|
|
551
701
|
if (key !== void 0 && key !== null) {
|
|
552
|
-
return
|
|
702
|
+
return import_react4.default.cloneElement(child, { key });
|
|
553
703
|
}
|
|
554
704
|
return child;
|
|
555
705
|
}
|
|
556
706
|
if (typeof child === "string" || typeof child === "number") {
|
|
557
707
|
if (key !== void 0 && key !== null) {
|
|
558
|
-
return
|
|
708
|
+
return import_react4.default.createElement(import_react4.default.Fragment, { key }, child);
|
|
559
709
|
}
|
|
560
|
-
return
|
|
710
|
+
return import_react4.default.createElement(import_react4.default.Fragment, {}, child);
|
|
561
711
|
}
|
|
562
|
-
return
|
|
712
|
+
return import_react4.default.createElement(import_react4.default.Fragment, { key }, child);
|
|
563
713
|
}
|
|
564
|
-
return
|
|
714
|
+
return import_react4.default.createElement(import_react4.default.Fragment, { key }, ...children);
|
|
565
715
|
} catch {
|
|
566
716
|
return null;
|
|
567
717
|
}
|
|
@@ -586,9 +736,9 @@ function convertDomNode(node, key) {
|
|
|
586
736
|
}
|
|
587
737
|
});
|
|
588
738
|
if (children.length === 0) {
|
|
589
|
-
return
|
|
739
|
+
return import_react4.default.createElement(tagName, props);
|
|
590
740
|
}
|
|
591
|
-
return
|
|
741
|
+
return import_react4.default.createElement(tagName, props, ...children);
|
|
592
742
|
}
|
|
593
743
|
function getElementAttributes(element) {
|
|
594
744
|
const attrs = {};
|
|
@@ -648,7 +798,97 @@ var INLINE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
648
798
|
"mtd"
|
|
649
799
|
]);
|
|
650
800
|
|
|
801
|
+
// src/components/link-safety-modal.tsx
|
|
802
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
803
|
+
var DefaultLinkSafetyModal = ({ url, isOpen, isChecking, onClose, onConfirm, onCopy }) => {
|
|
804
|
+
if (!isOpen) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
808
|
+
"div",
|
|
809
|
+
{
|
|
810
|
+
className: "stream-mdx-link-modal-backdrop",
|
|
811
|
+
role: "dialog",
|
|
812
|
+
"aria-modal": "true",
|
|
813
|
+
"aria-label": "Link safety confirmation",
|
|
814
|
+
style: {
|
|
815
|
+
position: "fixed",
|
|
816
|
+
inset: 0,
|
|
817
|
+
display: "flex",
|
|
818
|
+
alignItems: "center",
|
|
819
|
+
justifyContent: "center",
|
|
820
|
+
background: "rgba(0, 0, 0, 0.4)",
|
|
821
|
+
zIndex: 9999,
|
|
822
|
+
padding: "24px"
|
|
823
|
+
},
|
|
824
|
+
onClick: onClose,
|
|
825
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
826
|
+
"div",
|
|
827
|
+
{
|
|
828
|
+
className: "stream-mdx-link-modal",
|
|
829
|
+
style: {
|
|
830
|
+
width: "min(520px, 100%)",
|
|
831
|
+
borderRadius: 12,
|
|
832
|
+
background: "var(--background, #fff)",
|
|
833
|
+
color: "var(--foreground, #111)",
|
|
834
|
+
border: "1px solid var(--border, rgba(0, 0, 0, 0.1))",
|
|
835
|
+
boxShadow: "0 20px 60px rgba(0, 0, 0, 0.25)",
|
|
836
|
+
padding: 20
|
|
837
|
+
},
|
|
838
|
+
onClick: (event) => event.stopPropagation(),
|
|
839
|
+
children: [
|
|
840
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontWeight: 600, marginBottom: 8 }, children: "Open external link?" }),
|
|
841
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: 13, opacity: 0.8, wordBreak: "break-all", marginBottom: 16 }, children: url }),
|
|
842
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: 8, justifyContent: "flex-end" }, children: [
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: onCopy, disabled: isChecking, style: buttonStyle, children: "Copy link" }),
|
|
844
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: onConfirm, disabled: isChecking, style: primaryButtonStyle, children: "Open link" }),
|
|
845
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: onClose, style: buttonStyle, children: "Cancel" })
|
|
846
|
+
] })
|
|
847
|
+
]
|
|
848
|
+
}
|
|
849
|
+
)
|
|
850
|
+
}
|
|
851
|
+
);
|
|
852
|
+
};
|
|
853
|
+
var buttonStyle = {
|
|
854
|
+
borderRadius: 8,
|
|
855
|
+
border: "1px solid var(--border, rgba(0, 0, 0, 0.1))",
|
|
856
|
+
padding: "6px 12px",
|
|
857
|
+
background: "var(--background, #fff)",
|
|
858
|
+
color: "inherit",
|
|
859
|
+
fontSize: 13
|
|
860
|
+
};
|
|
861
|
+
var primaryButtonStyle = {
|
|
862
|
+
...buttonStyle,
|
|
863
|
+
background: "var(--foreground, #111)",
|
|
864
|
+
color: "var(--background, #fff)",
|
|
865
|
+
borderColor: "var(--foreground, #111)"
|
|
866
|
+
};
|
|
867
|
+
|
|
651
868
|
// src/components/index.ts
|
|
869
|
+
var MdxRuntimeBoundary = class extends import_react5.default.Component {
|
|
870
|
+
constructor() {
|
|
871
|
+
super(...arguments);
|
|
872
|
+
this.state = { hasError: false };
|
|
873
|
+
}
|
|
874
|
+
static getDerivedStateFromError() {
|
|
875
|
+
return { hasError: true };
|
|
876
|
+
}
|
|
877
|
+
componentDidCatch(error) {
|
|
878
|
+
this.props.onError(error);
|
|
879
|
+
}
|
|
880
|
+
componentDidUpdate(prevProps) {
|
|
881
|
+
if (prevProps.resetKey !== this.props.resetKey && this.state.hasError) {
|
|
882
|
+
this.setState({ hasError: false });
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
render() {
|
|
886
|
+
if (this.state.hasError) {
|
|
887
|
+
return null;
|
|
888
|
+
}
|
|
889
|
+
return this.props.children;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
652
892
|
function renderInlineNodes(nodes, components) {
|
|
653
893
|
return nodes.map((node, index) => {
|
|
654
894
|
const key = `${node.kind}-${index}`;
|
|
@@ -656,31 +896,31 @@ function renderInlineNodes(nodes, components) {
|
|
|
656
896
|
case "text": {
|
|
657
897
|
const textComponent = components.text;
|
|
658
898
|
if (textComponent && textComponent !== defaultInlineComponents.text) {
|
|
659
|
-
return
|
|
899
|
+
return import_react5.default.createElement(textComponent, { key, text: node.text });
|
|
660
900
|
}
|
|
661
|
-
return
|
|
901
|
+
return import_react5.default.createElement(import_react5.default.Fragment, { key, children: node.text });
|
|
662
902
|
}
|
|
663
903
|
case "strong":
|
|
664
|
-
return
|
|
904
|
+
return import_react5.default.createElement(components.strong, {
|
|
665
905
|
key,
|
|
666
906
|
children: renderInlineNodes(node.children, components)
|
|
667
907
|
});
|
|
668
908
|
case "em":
|
|
669
|
-
return
|
|
909
|
+
return import_react5.default.createElement(components.em, {
|
|
670
910
|
key,
|
|
671
911
|
children: renderInlineNodes(node.children, components)
|
|
672
912
|
});
|
|
673
913
|
case "strike": {
|
|
674
|
-
const StrikeComponent = components.strike ?? ((props) =>
|
|
675
|
-
return
|
|
914
|
+
const StrikeComponent = components.strike ?? ((props) => import_react5.default.createElement("del", {}, props.children));
|
|
915
|
+
return import_react5.default.createElement(StrikeComponent, {
|
|
676
916
|
key,
|
|
677
917
|
children: renderInlineNodes(node.children, components)
|
|
678
918
|
});
|
|
679
919
|
}
|
|
680
920
|
case "code":
|
|
681
|
-
return
|
|
921
|
+
return import_react5.default.createElement(components.code, { key, text: node.text });
|
|
682
922
|
case "link":
|
|
683
|
-
return
|
|
923
|
+
return import_react5.default.createElement(
|
|
684
924
|
components.link,
|
|
685
925
|
{
|
|
686
926
|
key,
|
|
@@ -690,18 +930,18 @@ function renderInlineNodes(nodes, components) {
|
|
|
690
930
|
}
|
|
691
931
|
);
|
|
692
932
|
case "image":
|
|
693
|
-
return
|
|
933
|
+
return import_react5.default.createElement(components.image, {
|
|
694
934
|
key,
|
|
695
935
|
src: node.src,
|
|
696
936
|
alt: node.alt,
|
|
697
937
|
title: node.title
|
|
698
938
|
});
|
|
699
939
|
case "br":
|
|
700
|
-
return
|
|
940
|
+
return import_react5.default.createElement(import_react5.default.Fragment, { key }, import_react5.default.createElement(components.br, {}));
|
|
701
941
|
default: {
|
|
702
942
|
const component = components[node.kind];
|
|
703
943
|
if (component) {
|
|
704
|
-
return
|
|
944
|
+
return import_react5.default.createElement(component, { key, ...node });
|
|
705
945
|
}
|
|
706
946
|
return null;
|
|
707
947
|
}
|
|
@@ -709,18 +949,18 @@ function renderInlineNodes(nodes, components) {
|
|
|
709
949
|
});
|
|
710
950
|
}
|
|
711
951
|
var defaultInlineComponents = {
|
|
712
|
-
text: ({ text }) =>
|
|
713
|
-
strong: ({ children }) =>
|
|
714
|
-
em: ({ children }) =>
|
|
715
|
-
strike: ({ children }) =>
|
|
716
|
-
code: ({ text }) =>
|
|
952
|
+
text: ({ text }) => import_react5.default.createElement(import_react5.default.Fragment, {}, text),
|
|
953
|
+
strong: ({ children }) => import_react5.default.createElement("strong", {}, children),
|
|
954
|
+
em: ({ children }) => import_react5.default.createElement("em", {}, children),
|
|
955
|
+
strike: ({ children }) => import_react5.default.createElement("del", {}, children),
|
|
956
|
+
code: ({ text }) => import_react5.default.createElement(
|
|
717
957
|
"code",
|
|
718
958
|
{
|
|
719
959
|
className: "inline-code"
|
|
720
960
|
},
|
|
721
961
|
text
|
|
722
962
|
),
|
|
723
|
-
link: ({ href, title, children }) =>
|
|
963
|
+
link: ({ href, title, children }) => import_react5.default.createElement(
|
|
724
964
|
"a",
|
|
725
965
|
{
|
|
726
966
|
href,
|
|
@@ -731,15 +971,15 @@ var defaultInlineComponents = {
|
|
|
731
971
|
},
|
|
732
972
|
children
|
|
733
973
|
),
|
|
734
|
-
image: ({ src, alt, title }) =>
|
|
974
|
+
image: ({ src, alt, title }) => import_react5.default.createElement("img", {
|
|
735
975
|
src,
|
|
736
976
|
alt,
|
|
737
977
|
title,
|
|
738
978
|
className: "markdown-image"
|
|
739
979
|
}),
|
|
740
|
-
br: () =>
|
|
980
|
+
br: () => import_react5.default.createElement("br"),
|
|
741
981
|
// Custom extensible components
|
|
742
|
-
mention: ({ handle }) =>
|
|
982
|
+
mention: ({ handle }) => import_react5.default.createElement(
|
|
743
983
|
"span",
|
|
744
984
|
{
|
|
745
985
|
className: "mention",
|
|
@@ -747,7 +987,7 @@ var defaultInlineComponents = {
|
|
|
747
987
|
},
|
|
748
988
|
`@${handle}`
|
|
749
989
|
),
|
|
750
|
-
citation: ({ id }) =>
|
|
990
|
+
citation: ({ id }) => import_react5.default.createElement(
|
|
751
991
|
"span",
|
|
752
992
|
{
|
|
753
993
|
className: "citation",
|
|
@@ -755,7 +995,7 @@ var defaultInlineComponents = {
|
|
|
755
995
|
},
|
|
756
996
|
`[${id}]`
|
|
757
997
|
),
|
|
758
|
-
"math-inline": ({ tex }) =>
|
|
998
|
+
"math-inline": ({ tex }) => import_react5.default.createElement(
|
|
759
999
|
"span",
|
|
760
1000
|
{
|
|
761
1001
|
className: "math-inline",
|
|
@@ -763,27 +1003,27 @@ var defaultInlineComponents = {
|
|
|
763
1003
|
},
|
|
764
1004
|
`$${tex}$`
|
|
765
1005
|
),
|
|
766
|
-
"math-display": ({ tex }) =>
|
|
1006
|
+
"math-display": ({ tex }) => import_react5.default.createElement(
|
|
767
1007
|
"div",
|
|
768
1008
|
{
|
|
769
1009
|
className: "math-display markdown-math-display",
|
|
770
1010
|
"data-tex": tex,
|
|
771
1011
|
style: { overflowX: "auto" }
|
|
772
1012
|
},
|
|
773
|
-
|
|
1013
|
+
import_react5.default.createElement("span", { className: "math-display-content" }, `$$${tex}$$`)
|
|
774
1014
|
),
|
|
775
1015
|
// Footnote inline reference (superscript anchor)
|
|
776
1016
|
"footnote-ref": ({ label, number }) => {
|
|
777
1017
|
const n = number ?? "?";
|
|
778
1018
|
const href = number ? `#fn:${n}` : void 0;
|
|
779
1019
|
const id = number ? `fnref:${n}` : void 0;
|
|
780
|
-
return
|
|
1020
|
+
return import_react5.default.createElement("sup", { className: "footnote-ref" }, import_react5.default.createElement("a", { href, id, "data-label": label }, String(n)));
|
|
781
1021
|
}
|
|
782
1022
|
};
|
|
783
1023
|
var defaultBlockComponents = {
|
|
784
1024
|
paragraph: ({ inlines, raw, meta, children }) => {
|
|
785
1025
|
if (children !== void 0) {
|
|
786
|
-
return
|
|
1026
|
+
return import_react5.default.createElement(
|
|
787
1027
|
"p",
|
|
788
1028
|
{
|
|
789
1029
|
className: "markdown-paragraph"
|
|
@@ -797,7 +1037,7 @@ var defaultBlockComponents = {
|
|
|
797
1037
|
if (structured.length === 1) {
|
|
798
1038
|
return structured[0];
|
|
799
1039
|
}
|
|
800
|
-
return
|
|
1040
|
+
return import_react5.default.createElement(import_react5.default.Fragment, {}, ...structured);
|
|
801
1041
|
}
|
|
802
1042
|
const filteredInlines = inlines && raw && inlines.length > 0 ? inlines.filter((node) => !(node.kind === "text" && node.text === raw)) : inlines ?? [];
|
|
803
1043
|
const effectiveInlines = filteredInlines.length > 0 ? filteredInlines : raw ? [
|
|
@@ -806,7 +1046,7 @@ var defaultBlockComponents = {
|
|
|
806
1046
|
text: raw
|
|
807
1047
|
}
|
|
808
1048
|
] : [];
|
|
809
|
-
return
|
|
1049
|
+
return import_react5.default.createElement(
|
|
810
1050
|
"p",
|
|
811
1051
|
{
|
|
812
1052
|
className: "markdown-paragraph"
|
|
@@ -818,7 +1058,7 @@ var defaultBlockComponents = {
|
|
|
818
1058
|
const tag = `h${level}`;
|
|
819
1059
|
const onlyPlainText = Array.isArray(inlines) && inlines.length > 0 && inlines.every((node) => node.kind === "text");
|
|
820
1060
|
const children = onlyPlainText ? inlines.map((node) => node.kind === "text" ? node.text : "").join("") : renderInlineNodes(inlines, defaultInlineComponents);
|
|
821
|
-
return
|
|
1061
|
+
return import_react5.default.createElement(
|
|
822
1062
|
tag,
|
|
823
1063
|
{
|
|
824
1064
|
className: `markdown-heading markdown-h${level}`,
|
|
@@ -830,7 +1070,7 @@ var defaultBlockComponents = {
|
|
|
830
1070
|
code: ({ html, meta, lines, lang, preAttrs, codeAttrs }) => {
|
|
831
1071
|
const language = typeof lang === "string" ? lang : typeof meta?.lang === "string" ? String(meta.lang) : "text";
|
|
832
1072
|
if (html) {
|
|
833
|
-
return
|
|
1073
|
+
return import_react5.default.createElement("div", {
|
|
834
1074
|
className: `markdown-code-block language-${language || "text"}`,
|
|
835
1075
|
/* biome-ignore lint/security/noDangerouslySetInnerHtml: highlighted HTML is generated by our sanitizer */
|
|
836
1076
|
dangerouslySetInnerHTML: { __html: html }
|
|
@@ -840,20 +1080,20 @@ var defaultBlockComponents = {
|
|
|
840
1080
|
if (lines && lines.length > 0) {
|
|
841
1081
|
const preAttributes = attrsToProps(preAttrs);
|
|
842
1082
|
const codeAttributes = attrsToProps(codeAttrs);
|
|
843
|
-
return
|
|
1083
|
+
return import_react5.default.createElement(
|
|
844
1084
|
"pre",
|
|
845
1085
|
{
|
|
846
1086
|
...preAttributes,
|
|
847
1087
|
className: preAttributes.className ? `${preAttributes.className} markdown-code-block language-${language || "text"}` : `markdown-code-block language-${language || "text"}`
|
|
848
1088
|
},
|
|
849
|
-
|
|
1089
|
+
import_react5.default.createElement(
|
|
850
1090
|
"code",
|
|
851
1091
|
{
|
|
852
1092
|
...codeAttributes,
|
|
853
1093
|
className: codeAttributes.className ? `${codeAttributes.className} language-${language || "text"}` : `language-${language || "text"}`
|
|
854
1094
|
},
|
|
855
1095
|
lines.map(
|
|
856
|
-
(line) =>
|
|
1096
|
+
(line) => import_react5.default.createElement("span", {
|
|
857
1097
|
key: line.id,
|
|
858
1098
|
className: "line",
|
|
859
1099
|
/* biome-ignore lint/security/noDangerouslySetInnerHtml: line HTML is sanitized server-side */
|
|
@@ -863,34 +1103,44 @@ var defaultBlockComponents = {
|
|
|
863
1103
|
)
|
|
864
1104
|
);
|
|
865
1105
|
}
|
|
866
|
-
return
|
|
1106
|
+
return import_react5.default.createElement("pre", {
|
|
867
1107
|
className: `markdown-code-block language-${language || "text"}`,
|
|
868
1108
|
children: code
|
|
869
1109
|
});
|
|
870
1110
|
},
|
|
871
|
-
blockquote: ({ inlines, renderedContent }) =>
|
|
1111
|
+
blockquote: ({ inlines, renderedContent }) => import_react5.default.createElement(
|
|
872
1112
|
"blockquote",
|
|
873
1113
|
{
|
|
874
1114
|
className: "markdown-blockquote"
|
|
875
1115
|
},
|
|
876
1116
|
renderedContent ?? renderInlineNodes(inlines, defaultInlineComponents)
|
|
877
1117
|
),
|
|
1118
|
+
hr: (props) => import_react5.default.createElement("hr", props),
|
|
878
1119
|
list: ({ ordered, items }) => {
|
|
1120
|
+
if (items.length === 0) {
|
|
1121
|
+
return null;
|
|
1122
|
+
}
|
|
879
1123
|
const tag = ordered ? "ol" : "ul";
|
|
1124
|
+
const listStyle = ordered ? {
|
|
1125
|
+
["--list-indent"]: `calc(2.5rem + ${String(items.length).length}ch)`
|
|
1126
|
+
} : void 0;
|
|
880
1127
|
const listItems = items.map(
|
|
881
|
-
(item, index) =>
|
|
1128
|
+
(item, index) => import_react5.default.createElement(
|
|
882
1129
|
"li",
|
|
883
1130
|
{
|
|
884
1131
|
key: index,
|
|
885
|
-
className: "markdown-list-item"
|
|
1132
|
+
className: "markdown-list-item",
|
|
1133
|
+
"data-counter-text": ordered ? `${index + 1}.` : void 0,
|
|
1134
|
+
"data-list-depth": 0
|
|
886
1135
|
},
|
|
887
1136
|
renderInlineNodes(item, defaultInlineComponents)
|
|
888
1137
|
)
|
|
889
1138
|
);
|
|
890
|
-
return
|
|
1139
|
+
return import_react5.default.createElement(
|
|
891
1140
|
tag,
|
|
892
1141
|
{
|
|
893
|
-
className: `markdown-list ${ordered ? "ordered" : "unordered"}
|
|
1142
|
+
className: `markdown-list ${ordered ? "ordered" : "unordered"}`,
|
|
1143
|
+
style: listStyle
|
|
894
1144
|
},
|
|
895
1145
|
listItems
|
|
896
1146
|
);
|
|
@@ -900,29 +1150,62 @@ var defaultBlockComponents = {
|
|
|
900
1150
|
const htmlString = (0, import_core.sanitizeHTML)(raw);
|
|
901
1151
|
if (typeof window !== "undefined" && elements) {
|
|
902
1152
|
const content = mapHtmlToReact(htmlString, elements);
|
|
903
|
-
return
|
|
1153
|
+
return import_react5.default.createElement("div", { className: "markdown-html" }, content);
|
|
904
1154
|
}
|
|
905
|
-
return
|
|
1155
|
+
return import_react5.default.createElement("div", {
|
|
906
1156
|
className: "markdown-html",
|
|
907
1157
|
/* biome-ignore lint/security/noDangerouslySetInnerHtml: htmlString is sanitized before injection */
|
|
908
1158
|
dangerouslySetInnerHTML: { __html: htmlString }
|
|
909
1159
|
});
|
|
910
1160
|
},
|
|
911
|
-
mdx: ({ compiledRef, compiledModule, status, errorMessage }) => {
|
|
912
|
-
const [Comp, setComp] =
|
|
913
|
-
const [internalError, setInternalError] =
|
|
1161
|
+
mdx: ({ compiledRef, compiledModule, status, errorMessage, raw }) => {
|
|
1162
|
+
const [Comp, setComp] = import_react5.default.useState(null);
|
|
1163
|
+
const [internalError, setInternalError] = import_react5.default.useState(null);
|
|
1164
|
+
const [renderError, setRenderError] = import_react5.default.useState(null);
|
|
1165
|
+
const [retryKey, setRetryKey] = import_react5.default.useState(0);
|
|
1166
|
+
const hydrationContext = import_react5.default.useContext(MdxHydrationContext);
|
|
1167
|
+
const hydrationController = hydrationContext?.controller ?? null;
|
|
1168
|
+
const hydrationOptions = hydrationContext?.options;
|
|
1169
|
+
const containerRef = import_react5.default.useRef(null);
|
|
1170
|
+
const deferHydration = hydrationOptions?.strategy === "visible";
|
|
1171
|
+
const shouldHydrate = useDeferredRender(
|
|
1172
|
+
containerRef,
|
|
1173
|
+
deferHydration ? {
|
|
1174
|
+
enabled: true,
|
|
1175
|
+
rootMargin: hydrationOptions?.rootMargin,
|
|
1176
|
+
idleTimeoutMs: hydrationOptions?.idleTimeoutMs,
|
|
1177
|
+
debounceMs: hydrationOptions?.debounceMs
|
|
1178
|
+
} : { enabled: false }
|
|
1179
|
+
);
|
|
914
1180
|
const resolvedId = compiledModule?.id ?? (compiledRef?.id && compiledRef.id !== "pending" ? compiledRef.id : void 0);
|
|
1181
|
+
const handleRetry = import_react5.default.useCallback(() => {
|
|
1182
|
+
setInternalError(null);
|
|
1183
|
+
setRenderError(null);
|
|
1184
|
+
setComp(null);
|
|
1185
|
+
setRetryKey((prev) => prev + 1);
|
|
1186
|
+
}, []);
|
|
1187
|
+
const handleRuntimeError = import_react5.default.useCallback(
|
|
1188
|
+
(error) => {
|
|
1189
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
1190
|
+
setRenderError(message2);
|
|
1191
|
+
markMdxHydrationError(resolvedId ?? compiledRef?.id);
|
|
1192
|
+
},
|
|
1193
|
+
[resolvedId, compiledRef?.id]
|
|
1194
|
+
);
|
|
915
1195
|
const effectiveStatus = status ? status : resolvedId ? "compiled" : "pending";
|
|
916
|
-
const failureMessage = errorMessage ?? internalError ?? null;
|
|
1196
|
+
const failureMessage = errorMessage ?? internalError ?? renderError ?? null;
|
|
917
1197
|
const moduleDependencies = compiledModule?.dependencies;
|
|
918
|
-
|
|
1198
|
+
import_react5.default.useEffect(() => {
|
|
1199
|
+
if (!shouldHydrate) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
919
1202
|
if (status === "error") {
|
|
920
|
-
|
|
921
|
-
setInternalError(null);
|
|
1203
|
+
markMdxHydrationError(resolvedId ?? compiledRef?.id);
|
|
922
1204
|
return;
|
|
923
1205
|
}
|
|
924
1206
|
let cancelled = false;
|
|
925
1207
|
async function ensure() {
|
|
1208
|
+
let permit = null;
|
|
926
1209
|
try {
|
|
927
1210
|
if (status === "error" || !resolvedId || resolvedId === "pending") {
|
|
928
1211
|
if (!cancelled) {
|
|
@@ -931,7 +1214,17 @@ var defaultBlockComponents = {
|
|
|
931
1214
|
}
|
|
932
1215
|
return;
|
|
933
1216
|
}
|
|
934
|
-
|
|
1217
|
+
if (hydrationController) {
|
|
1218
|
+
permit = await hydrationController.acquire();
|
|
1219
|
+
if (cancelled) {
|
|
1220
|
+
permit.release();
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
setInternalError(null);
|
|
1225
|
+
setRenderError(null);
|
|
1226
|
+
markMdxHydrationStart(resolvedId);
|
|
1227
|
+
const { getMDXComponentFactory: getMDXComponentFactory2, registerInlineMdxModule: registerInlineMdxModule2 } = await loadMdxRuntime();
|
|
935
1228
|
if (compiledModule?.code) {
|
|
936
1229
|
registerInlineMdxModule2({
|
|
937
1230
|
id: compiledModule.id,
|
|
@@ -944,41 +1237,82 @@ var defaultBlockComponents = {
|
|
|
944
1237
|
if (!cancelled) {
|
|
945
1238
|
setComp(() => C);
|
|
946
1239
|
setInternalError(null);
|
|
1240
|
+
markMdxHydrated(resolvedId);
|
|
947
1241
|
}
|
|
948
1242
|
} catch (error) {
|
|
949
1243
|
if (!cancelled) {
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
1244
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
1245
|
+
setInternalError(message2);
|
|
1246
|
+
markMdxHydrationError(resolvedId);
|
|
953
1247
|
}
|
|
1248
|
+
} finally {
|
|
1249
|
+
permit?.release();
|
|
954
1250
|
}
|
|
955
1251
|
}
|
|
956
1252
|
ensure();
|
|
957
1253
|
return () => {
|
|
958
1254
|
cancelled = true;
|
|
959
1255
|
};
|
|
960
|
-
}, [compiledModule?.id, compiledModule?.code, moduleDependencies, resolvedId, status]);
|
|
1256
|
+
}, [compiledModule?.id, compiledModule?.code, moduleDependencies, resolvedId, status, shouldHydrate, retryKey]);
|
|
961
1257
|
const compileMode = compiledModule?.source === "worker" || compiledRef?.id?.startsWith("worker:") ? "worker" : "server";
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1258
|
+
const pendingId = resolvedId && resolvedId !== "pending" ? resolvedId : compiledRef?.id ?? "pending";
|
|
1259
|
+
const waitingForVisibility = deferHydration && !shouldHydrate && Boolean(resolvedId);
|
|
1260
|
+
const pendingLabel = waitingForVisibility ? "MDX ready (hydrate on view)\u2026" : compileMode === "worker" ? "Compiling MDX (client)\u2026" : "Compiling MDX (server)\u2026";
|
|
1261
|
+
const message = failureMessage ?? (compileMode === "worker" ? "MDX compilation failed in client mode. Try switching back to server rendering or restarting the stream." : "MDX compilation failed. Try restarting the stream.");
|
|
1262
|
+
const rawFallback = typeof raw === "string" && raw.trim().length > 0 ? import_react5.default.createElement("pre", { className: "markdown-mdx-fallback" }, raw) : null;
|
|
1263
|
+
const allowRetry = Boolean(internalError || renderError);
|
|
1264
|
+
const retryButton = allowRetry ? import_react5.default.createElement(
|
|
1265
|
+
"button",
|
|
1266
|
+
{
|
|
1267
|
+
type: "button",
|
|
1268
|
+
className: "markdown-mdx-retry",
|
|
1269
|
+
onClick: handleRetry
|
|
1270
|
+
},
|
|
1271
|
+
"Retry hydration"
|
|
1272
|
+
) : null;
|
|
1273
|
+
const errorPanel = import_react5.default.createElement(
|
|
1274
|
+
"div",
|
|
1275
|
+
{ className: "markdown-mdx-error" },
|
|
1276
|
+
import_react5.default.createElement(import_react5.default.Fragment, null, import_react5.default.createElement("strong", null, "MDX failed"), import_react5.default.createElement("div", null, message))
|
|
1277
|
+
);
|
|
1278
|
+
if (Comp && !failureMessage) {
|
|
1279
|
+
return import_react5.default.createElement(
|
|
965
1280
|
"div",
|
|
966
1281
|
{
|
|
967
|
-
className: "markdown-mdx
|
|
968
|
-
|
|
1282
|
+
className: "markdown-mdx",
|
|
1283
|
+
ref: containerRef,
|
|
1284
|
+
"data-mdx-ref": resolvedId ?? compiledRef?.id ?? "compiled",
|
|
1285
|
+
"data-mdx-status": failureMessage ? "error" : "compiled",
|
|
1286
|
+
"data-mdx-mode": compileMode
|
|
1287
|
+
},
|
|
1288
|
+
import_react5.default.createElement(
|
|
1289
|
+
MdxRuntimeBoundary,
|
|
1290
|
+
{ resetKey: retryKey, onError: handleRuntimeError },
|
|
1291
|
+
import_react5.default.createElement(Comp, {})
|
|
1292
|
+
)
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
if (failureMessage) {
|
|
1296
|
+
return import_react5.default.createElement(
|
|
1297
|
+
"div",
|
|
1298
|
+
{
|
|
1299
|
+
className: "markdown-mdx",
|
|
1300
|
+
ref: containerRef,
|
|
1301
|
+
"data-mdx-ref": pendingId,
|
|
969
1302
|
"data-mdx-status": "error",
|
|
970
1303
|
"data-mdx-mode": compileMode
|
|
971
1304
|
},
|
|
972
|
-
|
|
1305
|
+
errorPanel,
|
|
1306
|
+
rawFallback,
|
|
1307
|
+
retryButton
|
|
973
1308
|
);
|
|
974
1309
|
}
|
|
975
1310
|
if (!Comp) {
|
|
976
|
-
|
|
977
|
-
const pendingLabel = compileMode === "worker" ? "Compiling MDX (client)\u2026" : "Compiling MDX (server)\u2026";
|
|
978
|
-
return import_react3.default.createElement(
|
|
1311
|
+
return import_react5.default.createElement(
|
|
979
1312
|
"div",
|
|
980
1313
|
{
|
|
981
1314
|
className: "markdown-mdx",
|
|
1315
|
+
ref: containerRef,
|
|
982
1316
|
"data-mdx-ref": pendingId,
|
|
983
1317
|
"data-mdx-status": "pending",
|
|
984
1318
|
"data-mdx-mode": compileMode
|
|
@@ -986,41 +1320,31 @@ var defaultBlockComponents = {
|
|
|
986
1320
|
pendingLabel
|
|
987
1321
|
);
|
|
988
1322
|
}
|
|
989
|
-
return import_react3.default.createElement(
|
|
990
|
-
"div",
|
|
991
|
-
{
|
|
992
|
-
className: "markdown-mdx",
|
|
993
|
-
"data-mdx-ref": resolvedId ?? compiledRef?.id ?? "compiled",
|
|
994
|
-
"data-mdx-status": "compiled",
|
|
995
|
-
"data-mdx-mode": compileMode
|
|
996
|
-
},
|
|
997
|
-
import_react3.default.createElement(Comp, {})
|
|
998
|
-
);
|
|
999
1323
|
},
|
|
1000
1324
|
// Footnotes block rendered at page end
|
|
1001
1325
|
footnotes: ({ items }) => {
|
|
1002
|
-
if (!items || items.length === 0) return
|
|
1326
|
+
if (!items || items.length === 0) return import_react5.default.createElement(import_react5.default.Fragment, null);
|
|
1003
1327
|
const listItems = items.map(
|
|
1004
|
-
(item) =>
|
|
1328
|
+
(item) => import_react5.default.createElement(
|
|
1005
1329
|
"li",
|
|
1006
1330
|
{ key: item.number, id: `fn:${item.number}` },
|
|
1007
1331
|
renderInlineNodes(item.inlines, defaultInlineComponents),
|
|
1008
1332
|
" ",
|
|
1009
|
-
|
|
1333
|
+
import_react5.default.createElement("a", { href: `#fnref:${item.number}`, className: "footnote-backref", "aria-label": "Back to content" }, "\u21A9")
|
|
1010
1334
|
)
|
|
1011
1335
|
);
|
|
1012
|
-
return
|
|
1336
|
+
return import_react5.default.createElement("section", { className: "footnotes" }, import_react5.default.createElement("hr", {}), import_react5.default.createElement("ol", {}, listItems));
|
|
1013
1337
|
},
|
|
1014
1338
|
// Footnote definition placeholders (render nothing)
|
|
1015
|
-
"footnote-def": () =>
|
|
1339
|
+
"footnote-def": () => import_react5.default.createElement(import_react5.default.Fragment, null),
|
|
1016
1340
|
// Callouts block
|
|
1017
1341
|
callout: ({ kind, inlines = [] }) => {
|
|
1018
1342
|
const tone = (kind || "NOTE").toUpperCase();
|
|
1019
1343
|
const title = tone.charAt(0) + tone.slice(1).toLowerCase();
|
|
1020
|
-
return
|
|
1344
|
+
return import_react5.default.createElement(
|
|
1021
1345
|
"div",
|
|
1022
1346
|
{ className: `markdown-callout markdown-callout-${tone.toLowerCase()} border rounded p-3 my-3` },
|
|
1023
|
-
|
|
1347
|
+
import_react5.default.createElement("div", { className: "font-semibold mb-1" }, title),
|
|
1024
1348
|
inlines.length > 0 ? renderInlineNodes(inlines, defaultInlineComponents) : null
|
|
1025
1349
|
);
|
|
1026
1350
|
},
|
|
@@ -1035,7 +1359,7 @@ var defaultBlockComponents = {
|
|
|
1035
1359
|
const renderCells = (cells, tag, rowIdx) => cells.map((cell, i) => {
|
|
1036
1360
|
const columnAlign = align?.[i] ?? void 0;
|
|
1037
1361
|
const cellStyle = columnAlign ? { textAlign: columnAlign } : void 0;
|
|
1038
|
-
return
|
|
1362
|
+
return import_react5.default.createElement(
|
|
1039
1363
|
tag === "th" ? El.Th : El.Td,
|
|
1040
1364
|
{
|
|
1041
1365
|
key: `${rowIdx}-${i}`,
|
|
@@ -1046,14 +1370,14 @@ var defaultBlockComponents = {
|
|
|
1046
1370
|
renderInlineNodes(cell, defaultInlineComponents)
|
|
1047
1371
|
);
|
|
1048
1372
|
});
|
|
1049
|
-
return
|
|
1373
|
+
return import_react5.default.createElement(
|
|
1050
1374
|
El.Table,
|
|
1051
1375
|
{ className: "markdown-table" },
|
|
1052
|
-
header && header.length > 0 ?
|
|
1053
|
-
|
|
1376
|
+
header && header.length > 0 ? import_react5.default.createElement(El.Thead, {}, import_react5.default.createElement(El.Tr, {}, renderCells(header, "th", -1))) : null,
|
|
1377
|
+
import_react5.default.createElement(
|
|
1054
1378
|
El.Tbody,
|
|
1055
1379
|
{},
|
|
1056
|
-
rows.map((row, r) =>
|
|
1380
|
+
rows.map((row, r) => import_react5.default.createElement(El.Tr, { key: r }, renderCells(row, "td", r)))
|
|
1057
1381
|
)
|
|
1058
1382
|
);
|
|
1059
1383
|
}
|
|
@@ -1122,7 +1446,7 @@ var ComponentRegistry = class {
|
|
|
1122
1446
|
renderBlock(block) {
|
|
1123
1447
|
const Component = this.getBlockComponent(block.type);
|
|
1124
1448
|
const props = this.getBlockProps(block);
|
|
1125
|
-
return
|
|
1449
|
+
return import_react5.default.createElement(Component, {
|
|
1126
1450
|
key: block.id,
|
|
1127
1451
|
...props
|
|
1128
1452
|
});
|
|
@@ -1157,6 +1481,14 @@ var ComponentRegistry = class {
|
|
|
1157
1481
|
return {
|
|
1158
1482
|
inlines: block.payload.inline || []
|
|
1159
1483
|
};
|
|
1484
|
+
case "hr": {
|
|
1485
|
+
const range = block.payload.range;
|
|
1486
|
+
return {
|
|
1487
|
+
className: "markdown-hr",
|
|
1488
|
+
"data-start": typeof range?.from === "number" ? range.from : void 0,
|
|
1489
|
+
"data-end": typeof range?.to === "number" ? range.to : void 0
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1160
1492
|
case "code":
|
|
1161
1493
|
return {
|
|
1162
1494
|
html: block.payload.highlightedHtml,
|
|
@@ -1189,7 +1521,8 @@ var ComponentRegistry = class {
|
|
|
1189
1521
|
compiledRef: compiledRef ?? { id: "pending" },
|
|
1190
1522
|
compiledModule,
|
|
1191
1523
|
status,
|
|
1192
|
-
errorMessage
|
|
1524
|
+
errorMessage,
|
|
1525
|
+
raw: typeof block.payload.raw === "string" ? block.payload.raw : void 0
|
|
1193
1526
|
};
|
|
1194
1527
|
})();
|
|
1195
1528
|
case "table": {
|
|
@@ -1240,42 +1573,42 @@ var ComponentRegistry = class {
|
|
|
1240
1573
|
function getDefaultHtmlElements() {
|
|
1241
1574
|
return {
|
|
1242
1575
|
// Text semantics
|
|
1243
|
-
p: (props) =>
|
|
1244
|
-
strong: (props) =>
|
|
1245
|
-
em: (props) =>
|
|
1246
|
-
code: (props) =>
|
|
1247
|
-
pre: (props) =>
|
|
1248
|
-
span: (props) =>
|
|
1249
|
-
br: (props) =>
|
|
1250
|
-
hr: (props) =>
|
|
1576
|
+
p: (props) => import_react5.default.createElement("p", props),
|
|
1577
|
+
strong: (props) => import_react5.default.createElement("strong", props),
|
|
1578
|
+
em: (props) => import_react5.default.createElement("em", props),
|
|
1579
|
+
code: (props) => import_react5.default.createElement("code", props),
|
|
1580
|
+
pre: (props) => import_react5.default.createElement("pre", props),
|
|
1581
|
+
span: (props) => import_react5.default.createElement("span", props),
|
|
1582
|
+
br: (props) => import_react5.default.createElement("br", props),
|
|
1583
|
+
hr: (props) => import_react5.default.createElement("hr", props),
|
|
1251
1584
|
// Lists
|
|
1252
|
-
ul: (props) =>
|
|
1253
|
-
ol: (props) =>
|
|
1254
|
-
li: (props) =>
|
|
1585
|
+
ul: (props) => import_react5.default.createElement("ul", props),
|
|
1586
|
+
ol: (props) => import_react5.default.createElement("ol", props),
|
|
1587
|
+
li: (props) => import_react5.default.createElement("li", props),
|
|
1255
1588
|
// Links & media
|
|
1256
|
-
a: (props) =>
|
|
1257
|
-
img: (props) =>
|
|
1589
|
+
a: (props) => import_react5.default.createElement("a", props),
|
|
1590
|
+
img: (props) => import_react5.default.createElement("img", props),
|
|
1258
1591
|
// Blockquotes
|
|
1259
|
-
blockquote: (props) =>
|
|
1592
|
+
blockquote: (props) => import_react5.default.createElement("blockquote", props),
|
|
1260
1593
|
// Tables
|
|
1261
|
-
table: (props) =>
|
|
1262
|
-
thead: (props) =>
|
|
1263
|
-
tbody: (props) =>
|
|
1264
|
-
tr: (props) =>
|
|
1265
|
-
th: (props) =>
|
|
1266
|
-
td: (props) =>
|
|
1594
|
+
table: (props) => import_react5.default.createElement("table", props),
|
|
1595
|
+
thead: (props) => import_react5.default.createElement("thead", props),
|
|
1596
|
+
tbody: (props) => import_react5.default.createElement("tbody", props),
|
|
1597
|
+
tr: (props) => import_react5.default.createElement("tr", props),
|
|
1598
|
+
th: (props) => import_react5.default.createElement("th", props),
|
|
1599
|
+
td: (props) => import_react5.default.createElement("td", props),
|
|
1267
1600
|
// Generic
|
|
1268
|
-
div: (props) =>
|
|
1601
|
+
div: (props) => import_react5.default.createElement("div", props)
|
|
1269
1602
|
};
|
|
1270
1603
|
}
|
|
1271
1604
|
function getDefaultTableElements(overrides) {
|
|
1272
1605
|
const base = {
|
|
1273
|
-
Table: (props) =>
|
|
1274
|
-
Thead: (props) =>
|
|
1275
|
-
Tbody: (props) =>
|
|
1276
|
-
Tr: (props) =>
|
|
1277
|
-
Th: (props) =>
|
|
1278
|
-
Td: (props) =>
|
|
1606
|
+
Table: (props) => import_react5.default.createElement("table", props),
|
|
1607
|
+
Thead: (props) => import_react5.default.createElement("thead", props),
|
|
1608
|
+
Tbody: (props) => import_react5.default.createElement("tbody", props),
|
|
1609
|
+
Tr: (props) => import_react5.default.createElement("tr", props),
|
|
1610
|
+
Th: (props) => import_react5.default.createElement("th", props),
|
|
1611
|
+
Td: (props) => import_react5.default.createElement("td", props)
|
|
1279
1612
|
};
|
|
1280
1613
|
return { ...base, ...overrides || {} };
|
|
1281
1614
|
}
|
|
@@ -1289,12 +1622,12 @@ function mapHtmlToReact(html, elements) {
|
|
|
1289
1622
|
children.push(element);
|
|
1290
1623
|
}
|
|
1291
1624
|
});
|
|
1292
|
-
return
|
|
1625
|
+
return import_react5.default.createElement(import_react5.default.Fragment, {}, ...children);
|
|
1293
1626
|
}
|
|
1294
1627
|
function toReact(node, elements, key) {
|
|
1295
1628
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
1296
1629
|
const text = node.textContent ?? "";
|
|
1297
|
-
return
|
|
1630
|
+
return import_react5.default.createElement(import_react5.default.Fragment, { key }, text);
|
|
1298
1631
|
}
|
|
1299
1632
|
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
1300
1633
|
return null;
|
|
@@ -1316,9 +1649,9 @@ function toReact(node, elements, key) {
|
|
|
1316
1649
|
const component = elements[tag];
|
|
1317
1650
|
const elementChildren = children.length > 0 ? children : void 0;
|
|
1318
1651
|
if (component) {
|
|
1319
|
-
return
|
|
1652
|
+
return import_react5.default.createElement(component, { ...props, key }, elementChildren);
|
|
1320
1653
|
}
|
|
1321
|
-
return
|
|
1654
|
+
return import_react5.default.createElement(tag, { ...props, key }, elementChildren);
|
|
1322
1655
|
}
|
|
1323
1656
|
function attrsToProps(attrs) {
|
|
1324
1657
|
if (!attrs) return {};
|
|
@@ -1363,12 +1696,12 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1363
1696
|
nodes.forEach((node, idx) => {
|
|
1364
1697
|
if (node === null || node === void 0) return;
|
|
1365
1698
|
const key = `${baseKey}-${idx}`;
|
|
1366
|
-
if (
|
|
1367
|
-
target.push(node.key === key ? node :
|
|
1699
|
+
if (import_react5.default.isValidElement(node)) {
|
|
1700
|
+
target.push(node.key === key ? node : import_react5.default.cloneElement(node, { key }));
|
|
1368
1701
|
} else if (typeof node === "string" || typeof node === "number") {
|
|
1369
|
-
target.push(
|
|
1702
|
+
target.push(import_react5.default.createElement(import_react5.default.Fragment, { key }, node));
|
|
1370
1703
|
} else {
|
|
1371
|
-
target.push(
|
|
1704
|
+
target.push(import_react5.default.createElement(import_react5.default.Fragment, { key }, node));
|
|
1372
1705
|
}
|
|
1373
1706
|
});
|
|
1374
1707
|
};
|
|
@@ -1384,7 +1717,7 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1384
1717
|
}
|
|
1385
1718
|
const key = `paragraph-inline-group-${inlineGroupIndex++}`;
|
|
1386
1719
|
result.push(
|
|
1387
|
-
|
|
1720
|
+
import_react5.default.createElement(
|
|
1388
1721
|
"p",
|
|
1389
1722
|
{
|
|
1390
1723
|
key,
|
|
@@ -1402,7 +1735,7 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1402
1735
|
const inlineNodes = Array.isArray(segment.inline) ? segment.inline : [];
|
|
1403
1736
|
if (inlineNodes.length === 0) {
|
|
1404
1737
|
if (segment.value) {
|
|
1405
|
-
inlineBuffer.push(
|
|
1738
|
+
inlineBuffer.push(import_react5.default.createElement(import_react5.default.Fragment, { key }, segment.value));
|
|
1406
1739
|
}
|
|
1407
1740
|
break;
|
|
1408
1741
|
}
|
|
@@ -1430,14 +1763,14 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1430
1763
|
const status = segment.status ?? "pending";
|
|
1431
1764
|
let element;
|
|
1432
1765
|
if (status === "compiled") {
|
|
1433
|
-
element =
|
|
1766
|
+
element = import_react5.default.createElement("span", { className: "markdown-mdx-inline", "data-mdx-status": "compiled" });
|
|
1434
1767
|
} else if (status === "error") {
|
|
1435
1768
|
const message = segment.value || "MDX error";
|
|
1436
|
-
element =
|
|
1769
|
+
element = import_react5.default.createElement("span", { className: "markdown-mdx-inline text-destructive", "data-mdx-status": "error" }, message);
|
|
1437
1770
|
} else {
|
|
1438
|
-
element =
|
|
1771
|
+
element = import_react5.default.createElement("span", { className: "markdown-mdx-inline", "data-mdx-status": status }, segment.value);
|
|
1439
1772
|
}
|
|
1440
|
-
inlineBuffer.push(
|
|
1773
|
+
inlineBuffer.push(import_react5.default.createElement(import_react5.default.Fragment, { key }, element));
|
|
1441
1774
|
break;
|
|
1442
1775
|
}
|
|
1443
1776
|
case "html": {
|
|
@@ -1453,7 +1786,7 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1453
1786
|
result.push(element);
|
|
1454
1787
|
} else if (html) {
|
|
1455
1788
|
result.push(
|
|
1456
|
-
|
|
1789
|
+
import_react5.default.createElement("div", {
|
|
1457
1790
|
key,
|
|
1458
1791
|
className: "markdown-inline-html-block",
|
|
1459
1792
|
dangerouslySetInnerHTML: { __html: html }
|
|
@@ -1472,7 +1805,7 @@ function renderParagraphMixedSegments(segments, inlineComponents, inlineHtmlRend
|
|
|
1472
1805
|
flushInline();
|
|
1473
1806
|
if (result.length === 0) {
|
|
1474
1807
|
return [
|
|
1475
|
-
|
|
1808
|
+
import_react5.default.createElement(
|
|
1476
1809
|
"p",
|
|
1477
1810
|
{
|
|
1478
1811
|
key: "paragraph-inline-group-0",
|
|
@@ -1532,6 +1865,7 @@ var BLOCK_LEVEL_TAGS = /* @__PURE__ */ new Set([
|
|
|
1532
1865
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1533
1866
|
0 && (module.exports = {
|
|
1534
1867
|
ComponentRegistry,
|
|
1868
|
+
DefaultLinkSafetyModal,
|
|
1535
1869
|
defaultBlockComponents,
|
|
1536
1870
|
defaultInlineComponents,
|
|
1537
1871
|
mapHtmlToReact,
|