@stream-mdx/react 0.5.0 → 1.0.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 (99) hide show
  1. package/CHANGELOG.md +371 -0
  2. package/README.md +79 -4
  3. package/dist/blocks-renderer-DAOBFBfi.d.ts +29 -0
  4. package/dist/blocks-renderer-DQEL1kJW.d.cts +29 -0
  5. package/dist/components/bottom-stick-scroll-area.cjs +117 -193
  6. package/dist/components/bottom-stick-scroll-area.mjs +112 -183
  7. package/dist/components/diff-renderer.cjs +86 -0
  8. package/dist/components/diff-renderer.d.cts +11 -0
  9. package/dist/components/diff-renderer.d.ts +11 -0
  10. package/dist/components/diff-renderer.mjs +66 -0
  11. package/dist/components/index.cjs +2761 -1508
  12. package/dist/components/index.d.cts +7 -2
  13. package/dist/components/index.d.ts +7 -2
  14. package/dist/components/index.mjs +2730 -1493
  15. package/dist/components/katex-math.cjs +220 -0
  16. package/dist/components/katex-math.d.cts +10 -0
  17. package/dist/components/katex-math.d.ts +10 -0
  18. package/dist/components/katex-math.mjs +188 -0
  19. package/dist/contexts/math-tracker.cjs +240 -521
  20. package/dist/contexts/math-tracker.mjs +235 -513
  21. package/dist/index-Cmne1yUK.d.cts +723 -0
  22. package/dist/index-D7dyyu3q.d.ts +723 -0
  23. package/dist/index.cjs +13029 -6475
  24. package/dist/index.d.cts +69 -39
  25. package/dist/index.d.ts +69 -39
  26. package/dist/index.mjs +13007 -6442
  27. package/dist/math/display-wrapper.cjs +7 -15
  28. package/dist/math/display-wrapper.d.cts +2 -2
  29. package/dist/math/display-wrapper.d.ts +2 -2
  30. package/dist/math/display-wrapper.mjs +2 -6
  31. package/dist/node-views-Bpc6Gkgl.d.cts +13 -0
  32. package/dist/node-views-DpnYdaAS.d.ts +13 -0
  33. package/dist/renderer/hooks.cjs +35 -20
  34. package/dist/renderer/hooks.d.cts +22 -1
  35. package/dist/renderer/hooks.d.ts +22 -1
  36. package/dist/renderer/hooks.mjs +27 -12
  37. package/dist/renderer/patch-batching.cjs +5 -8
  38. package/dist/renderer/patch-coalescing.cjs +5 -8
  39. package/dist/renderer/patch-commit-scheduler.cjs +138 -356
  40. package/dist/renderer/patch-commit-scheduler.d.cts +13 -1
  41. package/dist/renderer/patch-commit-scheduler.d.ts +13 -1
  42. package/dist/renderer/patch-commit-scheduler.mjs +133 -348
  43. package/dist/renderer/store.cjs +3775 -1373
  44. package/dist/renderer/store.d.cts +108 -3
  45. package/dist/renderer/store.d.ts +108 -3
  46. package/dist/renderer/store.mjs +3778 -1362
  47. package/dist/renderer/virtualized-code.cjs +415 -71
  48. package/dist/renderer/virtualized-code.d.cts +24 -23
  49. package/dist/renderer/virtualized-code.d.ts +24 -23
  50. package/dist/renderer/virtualized-code.mjs +409 -62
  51. package/dist/renderer.cjs +10655 -4334
  52. package/dist/renderer.d.cts +98 -29
  53. package/dist/renderer.d.ts +98 -29
  54. package/dist/renderer.mjs +10582 -4212
  55. package/dist/server-regions-CPLHGli0.d.cts +32 -0
  56. package/dist/server-regions-mUhyoKi7.d.ts +32 -0
  57. package/dist/server.cjs +10195 -3872
  58. package/dist/server.d.cts +17 -252
  59. package/dist/server.d.ts +17 -252
  60. package/dist/server.mjs +9997 -3649
  61. package/dist/{streaming-markdown-CEI9eDZm.d.ts → streaming-markdown-yELbJxyH.d.ts} +49 -55
  62. package/dist/{streaming-markdown-DRisClXb.d.cts → streaming-markdown-zVwFuaJG.d.cts} +49 -55
  63. package/dist/streaming-markdown.cjs +11660 -5378
  64. package/dist/streaming-markdown.d.cts +7 -2
  65. package/dist/streaming-markdown.d.ts +7 -2
  66. package/dist/streaming-markdown.mjs +11679 -5347
  67. package/dist/trusted-mdx/index.cjs +833 -0
  68. package/dist/trusted-mdx/index.d.cts +11 -0
  69. package/dist/trusted-mdx/index.d.ts +11 -0
  70. package/dist/trusted-mdx/index.mjs +807 -0
  71. package/dist/trusted-mdx/native-children-slot.cjs +45 -0
  72. package/dist/trusted-mdx/native-children-slot.d.cts +11 -0
  73. package/dist/trusted-mdx/native-children-slot.d.ts +11 -0
  74. package/dist/trusted-mdx/native-children-slot.mjs +24 -0
  75. package/dist/trusted-mdx/server.cjs +752 -0
  76. package/dist/trusted-mdx/server.d.cts +24 -0
  77. package/dist/trusted-mdx/server.d.ts +24 -0
  78. package/dist/trusted-mdx/server.mjs +724 -0
  79. package/dist/trusted-mdx-contract-ElKpkDI5.d.cts +113 -0
  80. package/dist/trusted-mdx-contract-ElKpkDI5.d.ts +113 -0
  81. package/dist/utils/inline-html.cjs +246 -147
  82. package/dist/utils/inline-html.d.cts +37 -6
  83. package/dist/utils/inline-html.d.ts +37 -6
  84. package/dist/utils/inline-html.mjs +237 -134
  85. package/package.json +41 -18
  86. package/dist/index-BVhp_pcF.d.ts +0 -251
  87. package/dist/index-EaeouYp2.d.cts +0 -251
  88. package/dist/mdx-client.cjs +0 -408
  89. package/dist/mdx-client.d.cts +0 -113
  90. package/dist/mdx-client.d.ts +0 -113
  91. package/dist/mdx-client.mjs +0 -369
  92. package/dist/mdx-coordinator.cjs +0 -584
  93. package/dist/mdx-coordinator.d.cts +0 -21
  94. package/dist/mdx-coordinator.d.ts +0 -21
  95. package/dist/mdx-coordinator.mjs +0 -550
  96. package/dist/renderer/node-views.cjs +0 -1887
  97. package/dist/renderer/node-views.d.cts +0 -14
  98. package/dist/renderer/node-views.d.ts +0 -14
  99. package/dist/renderer/node-views.mjs +0 -1861
@@ -1,550 +0,0 @@
1
- "use client";
2
- "use client";
3
-
4
- // src/mdx-coordinator.ts
5
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
-
7
- // src/mdx-client.ts
8
- import React from "react";
9
- import * as ReactJsxRuntime from "react/jsx-runtime";
10
- var withClassName = (tag, className) => {
11
- return (props) => React.createElement(tag, { className, ...props });
12
- };
13
- function assignMdxChildKey(child, index) {
14
- if (child == null) return child;
15
- if (Array.isArray(child)) {
16
- return child.map((entry, subIndex) => assignMdxChildKey(entry, `${index}-${subIndex}`));
17
- }
18
- if (React.isValidElement(child)) {
19
- if (child.key !== null && child.key !== void 0) {
20
- return child;
21
- }
22
- return React.cloneElement(child, { key: index });
23
- }
24
- return child;
25
- }
26
- var MDXClient = class {
27
- constructor(compileEndpoint = "/api/mdx-compile-v2") {
28
- this.cache = /* @__PURE__ */ new Map();
29
- this.inlineModules = /* @__PURE__ */ new Map();
30
- this.compiledCache = /* @__PURE__ */ new Map();
31
- this.compiledInflight = /* @__PURE__ */ new Map();
32
- this.compileEndpoint = compileEndpoint;
33
- }
34
- /**
35
- * Compile MDX block on server
36
- */
37
- async compile(block) {
38
- if (block.type !== "mdx") {
39
- throw new Error("Block is not MDX type");
40
- }
41
- const cacheKey = `${block.id}\0${block.payload.raw ?? ""}`;
42
- const cachedPromise = this.cache.get(cacheKey);
43
- if (cachedPromise) {
44
- return cachedPromise;
45
- }
46
- const compilationPromise = this.doCompile(block);
47
- this.cache.set(cacheKey, compilationPromise);
48
- try {
49
- const result = await compilationPromise;
50
- return result;
51
- } catch (error) {
52
- this.cache.delete(cacheKey);
53
- throw error;
54
- }
55
- }
56
- async getCompiledInternal(ref) {
57
- const inline = this.inlineModules.get(ref.id);
58
- if (inline) {
59
- return this.cloneCompiled(inline);
60
- }
61
- const cached = this.compiledCache.get(ref.id);
62
- if (cached) {
63
- return this.cloneCompiled(cached);
64
- }
65
- const inflight = this.compiledInflight.get(ref.id);
66
- if (inflight) {
67
- const resolved = await inflight;
68
- return this.cloneCompiled(resolved);
69
- }
70
- const fetchPromise = this.fetchCompiled(ref);
71
- this.compiledInflight.set(ref.id, fetchPromise);
72
- try {
73
- const data = await fetchPromise;
74
- this.compiledCache.set(ref.id, data);
75
- return this.cloneCompiled(data);
76
- } finally {
77
- this.compiledInflight.delete(ref.id);
78
- }
79
- }
80
- async getCompiled(ref, options) {
81
- if (options?.signal) {
82
- const inline = this.inlineModules.get(ref.id);
83
- if (inline) {
84
- return this.cloneCompiled(inline);
85
- }
86
- const cached = this.compiledCache.get(ref.id);
87
- if (cached) {
88
- return this.cloneCompiled(cached);
89
- }
90
- const data = await this.fetchCompiled(ref, options);
91
- this.compiledCache.set(ref.id, data);
92
- return this.cloneCompiled(data);
93
- }
94
- return this.getCompiledInternal(ref);
95
- }
96
- /**
97
- * Clear compilation cache
98
- */
99
- clearCache() {
100
- this.cache.clear();
101
- this.compiledCache.clear();
102
- this.compiledInflight.clear();
103
- }
104
- registerInlineModule(compiled) {
105
- this.inlineModules.set(compiled.id, {
106
- ...compiled,
107
- dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
108
- });
109
- }
110
- clearInlineModules() {
111
- this.inlineModules.clear();
112
- }
113
- /**
114
- * Actual compilation implementation
115
- */
116
- async doCompile(block) {
117
- const response = await fetch(this.compileEndpoint, {
118
- method: "POST",
119
- headers: {
120
- "Content-Type": "application/json"
121
- },
122
- body: JSON.stringify({
123
- content: block.payload.raw,
124
- blockId: block.id
125
- })
126
- });
127
- if (!response.ok) {
128
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
129
- throw new Error(`MDX compilation failed: ${error.error || response.statusText}`);
130
- }
131
- const data = await response.json();
132
- return {
133
- id: data.id,
134
- code: data.code,
135
- dependencies: data.dependencies || [],
136
- cached: data.cached || false
137
- };
138
- }
139
- async fetchCompiled(ref, options) {
140
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
141
- signal: options?.signal
142
- });
143
- if (!response.ok) {
144
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
145
- }
146
- const data = await response.json();
147
- return {
148
- id: data.id,
149
- code: data.code,
150
- dependencies: data.dependencies || [],
151
- timestamp: data.timestamp
152
- };
153
- }
154
- cloneCompiled(compiled) {
155
- return {
156
- ...compiled,
157
- dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
158
- };
159
- }
160
- };
161
- var MDXComponentFactory = class {
162
- constructor(mdxClient) {
163
- this.components = /* @__PURE__ */ new Map();
164
- this.customComponents = /* @__PURE__ */ new Map();
165
- this.mdxClient = mdxClient;
166
- this.baseComponents = this.createBaseComponents();
167
- }
168
- registerInlineModule(module) {
169
- this.mdxClient.registerInlineModule(module);
170
- this.components.delete(module.id);
171
- }
172
- /**
173
- * Create React component from compiled MDX
174
- */
175
- async createComponent(ref) {
176
- const cached = this.components.get(ref.id);
177
- if (cached) {
178
- return cached;
179
- }
180
- const compiled = await this.mdxClient.getCompiled(ref);
181
- const component = this.evaluateCompiledMDX(compiled);
182
- this.components.set(ref.id, component);
183
- return component;
184
- }
185
- /**
186
- * Safely evaluate compiled MDX code
187
- */
188
- evaluateCompiledMDX(compiled) {
189
- try {
190
- const context = this.createEvaluationContext();
191
- const argNames = Object.keys(context);
192
- const argValues = Object.values(context);
193
- const moduleExports = new Function(...argNames, compiled.code)(...argValues);
194
- const MDXComponent = this.resolveEvaluatedModule(moduleExports);
195
- return (props) => {
196
- const registryComponents = this.getComponents();
197
- const incomingComponents = props?.components;
198
- const mergedComponents = incomingComponents ? { ...registryComponents, ...incomingComponents } : registryComponents;
199
- return React.createElement(MDXComponent, {
200
- ...props,
201
- components: mergedComponents
202
- });
203
- };
204
- } catch (error) {
205
- console.error("Failed to evaluate MDX:", error);
206
- return () => React.createElement(
207
- "div",
208
- {
209
- className: "mdx-error"
210
- },
211
- `MDX Error: ${error instanceof Error ? error.message : "Unknown error"}`
212
- );
213
- }
214
- }
215
- /**
216
- * Create safe evaluation context for MDX
217
- */
218
- createEvaluationContext() {
219
- const runtime = ReactJsxRuntime;
220
- const createElementWithChildren = (type, props, key) => {
221
- const baseProps = props ?? {};
222
- const finalProps = key === void 0 || key === null ? baseProps : { ...baseProps, key };
223
- if (Array.isArray(finalProps.children)) {
224
- finalProps.children = finalProps.children.map((child, index) => assignMdxChildKey(child, index));
225
- }
226
- return React.createElement(type, finalProps);
227
- };
228
- const runtimeJsx = typeof runtime.jsx === "function" ? runtime.jsx.bind(runtime) : createElementWithChildren;
229
- const runtimeJsxs = typeof runtime.jsxs === "function" ? runtime.jsxs.bind(runtime) : createElementWithChildren;
230
- const runtimeJsxDEV = typeof runtime.jsxDEV === "function" ? runtime.jsxDEV.bind(runtime) : (type, props, key, ..._rest) => createElementWithChildren(type, props, key);
231
- const jsxRuntime = {
232
- jsx: runtimeJsx,
233
- jsxs: runtimeJsxs,
234
- jsxDEV: runtimeJsxDEV,
235
- Fragment: runtime.Fragment ?? React.Fragment
236
- };
237
- return {
238
- __mdx_runtime: jsxRuntime,
239
- React,
240
- Fragment: React.Fragment,
241
- useState: React.useState,
242
- useEffect: React.useEffect,
243
- useMemo: React.useMemo,
244
- useCallback: React.useCallback,
245
- useRef: React.useRef,
246
- useContext: React.useContext,
247
- useReducer: React.useReducer,
248
- useLayoutEffect: React.useLayoutEffect,
249
- console: {
250
- log: console.log,
251
- warn: console.warn,
252
- error: console.error
253
- }
254
- };
255
- }
256
- resolveEvaluatedModule(output) {
257
- if (!output) {
258
- throw new Error("Compiled MDX module returned no exports");
259
- }
260
- if (typeof output === "function") {
261
- return output;
262
- }
263
- if (typeof output.default === "function") {
264
- return output.default;
265
- }
266
- if (typeof output.MDXContent === "function") {
267
- return output.MDXContent;
268
- }
269
- throw new Error("Compiled MDX module did not export a component");
270
- }
271
- getComponents() {
272
- if (this.customComponents.size === 0) {
273
- return { ...this.baseComponents };
274
- }
275
- const merged = { ...this.baseComponents };
276
- for (const [key, component] of this.customComponents) {
277
- merged[key] = component;
278
- }
279
- return merged;
280
- }
281
- /**
282
- * Register or replace custom MDX components
283
- */
284
- registerComponents(components, options) {
285
- if (options?.replace) {
286
- this.customComponents.clear();
287
- }
288
- for (const [key, component] of Object.entries(components)) {
289
- if (!component) continue;
290
- this.customComponents.set(key, component);
291
- }
292
- }
293
- /**
294
- * Get base MDX components
295
- */
296
- createBaseComponents() {
297
- return {
298
- // Standard HTML elements
299
- h1: withClassName("h1", "mdx-h1"),
300
- h2: withClassName("h2", "mdx-h2"),
301
- h3: withClassName("h3", "mdx-h3"),
302
- h4: withClassName("h4", "mdx-h4"),
303
- h5: withClassName("h5", "mdx-h5"),
304
- h6: withClassName("h6", "mdx-h6"),
305
- p: withClassName("p", "mdx-p"),
306
- strong: withClassName("strong", "mdx-strong"),
307
- em: withClassName("em", "mdx-em"),
308
- code: withClassName("code", "mdx-code"),
309
- pre: withClassName("pre", "mdx-pre"),
310
- ul: withClassName("ul", "mdx-ul"),
311
- ol: withClassName("ol", "mdx-ol"),
312
- li: withClassName("li", "mdx-li"),
313
- blockquote: withClassName("blockquote", "mdx-blockquote"),
314
- a: (props) => React.createElement("a", {
315
- className: "mdx-link",
316
- target: props.href?.startsWith("http") ? "_blank" : void 0,
317
- rel: props.href?.startsWith("http") ? "noopener noreferrer" : void 0,
318
- ...props
319
- }),
320
- img: (props) => React.createElement("img", { className: "mdx-img", ...props }),
321
- table: withClassName("table", "mdx-table"),
322
- thead: withClassName("thead", "mdx-thead"),
323
- tbody: withClassName("tbody", "mdx-tbody"),
324
- tr: withClassName("tr", "mdx-tr"),
325
- th: withClassName("th", "mdx-th"),
326
- td: withClassName("td", "mdx-td")
327
- };
328
- }
329
- /**
330
- * Clear component cache
331
- */
332
- clearCache() {
333
- this.components.clear();
334
- }
335
- clearCustomComponents() {
336
- this.customComponents.clear();
337
- }
338
- };
339
- var globalMDXClient = null;
340
- var globalComponentFactory = null;
341
- function getMDXClient(compileEndpoint) {
342
- if (!globalMDXClient) {
343
- globalMDXClient = new MDXClient(compileEndpoint);
344
- }
345
- return globalMDXClient;
346
- }
347
- function getMDXComponentFactory(compileEndpoint) {
348
- if (!globalComponentFactory) {
349
- const client = getMDXClient(compileEndpoint);
350
- globalComponentFactory = new MDXComponentFactory(client);
351
- }
352
- return globalComponentFactory;
353
- }
354
- function registerInlineMdxModule(compiled) {
355
- const factory = getMDXComponentFactory();
356
- factory.registerInlineModule({
357
- id: compiled.id,
358
- code: compiled.code,
359
- dependencies: compiled.dependencies ?? []
360
- });
361
- }
362
-
363
- // src/mdx-coordinator.ts
364
- function useMdxCoordinator(blocks, compileEndpoint, options) {
365
- const mdxClientRef = useRef(getMDXClient(compileEndpoint));
366
- const mode = options?.mode ?? "server";
367
- const [compiledMap, setCompiledMap] = useState(/* @__PURE__ */ new Map());
368
- const blockSignatureRef = useRef(/* @__PURE__ */ new Map());
369
- const failedSignatureRef = useRef(/* @__PURE__ */ new Map());
370
- const applyCompiledRef = useCallback(
371
- (block, compiledId) => {
372
- if (mode === "worker") {
373
- return;
374
- }
375
- if (options?.workerClient) {
376
- options.workerClient.setMdxCompiled(block.id, compiledId, block.payload.raw ?? "");
377
- return;
378
- }
379
- const store = options?.store;
380
- if (!store) {
381
- return;
382
- }
383
- const currentBlocks = store.getBlocks();
384
- const index = currentBlocks.findIndex((candidate) => candidate.id === block.id);
385
- if (index === -1) return;
386
- const current = currentBlocks[index];
387
- if ((current.payload.raw ?? "") !== (block.payload.raw ?? "")) {
388
- return;
389
- }
390
- if (current.payload.compiledMdxRef?.id === compiledId) {
391
- return;
392
- }
393
- store.applyPatches([
394
- {
395
- op: "setProps",
396
- at: { blockId: block.id, nodeId: block.id },
397
- props: {
398
- block: {
399
- ...current,
400
- payload: {
401
- ...current.payload,
402
- compiledMdxRef: { id: compiledId },
403
- meta: {
404
- ...current.payload.meta ?? {},
405
- mdxStatus: "compiled"
406
- }
407
- }
408
- }
409
- }
410
- }
411
- ]);
412
- },
413
- [options?.workerClient, options?.store, mode]
414
- );
415
- useEffect(() => {
416
- if (mode === "worker") {
417
- return;
418
- }
419
- const targets = blocks.filter((b) => {
420
- if (b.type !== "mdx" || !b.isFinalized || b.payload.compiledMdxRef || compiledMap.has(b.id)) {
421
- return false;
422
- }
423
- const raw = b.payload.raw ?? "";
424
- return failedSignatureRef.current.get(b.id) !== raw;
425
- });
426
- if (targets.length === 0) return;
427
- let cancelled = false;
428
- (async () => {
429
- for (const block of targets) {
430
- try {
431
- const compiled = await mdxClientRef.current.compile(block);
432
- if (cancelled) return;
433
- registerInlineMdxModule({
434
- id: compiled.id,
435
- code: compiled.code,
436
- dependencies: compiled.dependencies
437
- });
438
- setCompiledMap((prev) => {
439
- if (prev.has(block.id)) return prev;
440
- const next = new Map(prev);
441
- next.set(block.id, compiled.id);
442
- return next;
443
- });
444
- failedSignatureRef.current.delete(block.id);
445
- applyCompiledRef(block, compiled.id);
446
- } catch (e) {
447
- console.warn("MDX compile failed for block", block.id, e);
448
- failedSignatureRef.current.set(block.id, block.payload.raw ?? "");
449
- if (options?.workerClient) {
450
- options.workerClient.setMdxError(block.id, e instanceof Error ? e.message : String(e), block.payload.raw ?? "");
451
- } else if (options?.store) {
452
- const currentBlocks = options.store.getBlocks();
453
- const current = currentBlocks.find((candidate) => candidate.id === block.id);
454
- if (!current || (current.payload.raw ?? "") !== (block.payload.raw ?? "")) {
455
- continue;
456
- }
457
- options.store.applyPatches([
458
- {
459
- op: "setProps",
460
- at: { blockId: block.id, nodeId: block.id },
461
- props: {
462
- block: {
463
- ...current,
464
- payload: {
465
- ...current.payload,
466
- meta: { ...current.payload.meta ?? {}, mdxStatus: "error", mdxError: e instanceof Error ? e.message : String(e) }
467
- }
468
- }
469
- }
470
- }
471
- ]);
472
- }
473
- }
474
- }
475
- })();
476
- return () => {
477
- cancelled = true;
478
- };
479
- }, [blocks, compiledMap, applyCompiledRef, options?.workerClient, options?.store, mode]);
480
- useEffect(() => {
481
- if (mode === "worker") {
482
- return;
483
- }
484
- const blockMap = new Map(blocks.map((block) => [block.id, block]));
485
- setCompiledMap((prev) => {
486
- let mutated = false;
487
- const next = new Map(prev);
488
- for (const [blockId] of prev) {
489
- const candidate = blockMap.get(blockId);
490
- if (!candidate || candidate.type !== "mdx") {
491
- next.delete(blockId);
492
- mutated = true;
493
- continue;
494
- }
495
- const previousSignature = blockSignatureRef.current.get(blockId);
496
- const currentSignature = candidate.payload.raw ?? "";
497
- if (previousSignature !== void 0 && previousSignature !== currentSignature) {
498
- next.delete(blockId);
499
- failedSignatureRef.current.delete(blockId);
500
- mutated = true;
501
- }
502
- }
503
- return mutated ? next : prev;
504
- });
505
- const signatureMap = /* @__PURE__ */ new Map();
506
- for (const block of blocks) {
507
- if (block.type === "mdx") {
508
- signatureMap.set(block.id, block.payload.raw ?? "");
509
- if (!block.isFinalized || block.payload.compiledMdxRef) {
510
- failedSignatureRef.current.delete(block.id);
511
- }
512
- }
513
- }
514
- blockSignatureRef.current = signatureMap;
515
- }, [blocks, mode]);
516
- const derivedBlocks = useMemo(() => {
517
- if (mode === "worker") {
518
- return blocks;
519
- }
520
- if (options?.workerClient) {
521
- return blocks;
522
- }
523
- if (compiledMap.size === 0) return blocks;
524
- let changed = false;
525
- const out = blocks.map((b) => {
526
- if (b.type === "mdx" && !b.payload.compiledMdxRef) {
527
- const id = compiledMap.get(b.id);
528
- if (id) {
529
- changed = true;
530
- return {
531
- ...b,
532
- payload: {
533
- ...b.payload,
534
- compiledMdxRef: { id }
535
- }
536
- };
537
- }
538
- }
539
- return b;
540
- });
541
- return changed ? out : blocks;
542
- }, [blocks, compiledMap, mode, options?.workerClient]);
543
- if (options?.workerClient) {
544
- return blocks;
545
- }
546
- return derivedBlocks;
547
- }
548
- export {
549
- useMdxCoordinator
550
- };