@stream-mdx/react 0.4.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 (106) hide show
  1. package/CHANGELOG.md +385 -4
  2. package/README.md +141 -16
  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 +268 -0
  6. package/dist/components/bottom-stick-scroll-area.d.cts +36 -0
  7. package/dist/components/bottom-stick-scroll-area.d.ts +36 -0
  8. package/dist/components/bottom-stick-scroll-area.mjs +249 -0
  9. package/dist/components/diff-renderer.cjs +86 -0
  10. package/dist/components/diff-renderer.d.cts +11 -0
  11. package/dist/components/diff-renderer.d.ts +11 -0
  12. package/dist/components/diff-renderer.mjs +66 -0
  13. package/dist/components/index.cjs +2879 -1295
  14. package/dist/components/index.d.cts +9 -2
  15. package/dist/components/index.d.ts +9 -2
  16. package/dist/components/index.mjs +2842 -1277
  17. package/dist/components/katex-math.cjs +220 -0
  18. package/dist/components/katex-math.d.cts +10 -0
  19. package/dist/components/katex-math.d.ts +10 -0
  20. package/dist/components/katex-math.mjs +188 -0
  21. package/dist/contexts/math-tracker.cjs +240 -521
  22. package/dist/contexts/math-tracker.mjs +235 -513
  23. package/dist/index-Cmne1yUK.d.cts +723 -0
  24. package/dist/index-D7dyyu3q.d.ts +723 -0
  25. package/dist/index.cjs +13180 -5640
  26. package/dist/index.d.cts +72 -40
  27. package/dist/index.d.ts +72 -40
  28. package/dist/index.mjs +12587 -5038
  29. package/dist/math/display-wrapper.cjs +7 -15
  30. package/dist/math/display-wrapper.d.cts +2 -2
  31. package/dist/math/display-wrapper.d.ts +2 -2
  32. package/dist/math/display-wrapper.mjs +2 -6
  33. package/dist/node-views-Bpc6Gkgl.d.cts +13 -0
  34. package/dist/node-views-DpnYdaAS.d.ts +13 -0
  35. package/dist/renderer/hooks.cjs +35 -20
  36. package/dist/renderer/hooks.d.cts +22 -1
  37. package/dist/renderer/hooks.d.ts +22 -1
  38. package/dist/renderer/hooks.mjs +27 -12
  39. package/dist/renderer/patch-batching.cjs +7 -8
  40. package/dist/renderer/patch-batching.d.cts +1 -1
  41. package/dist/renderer/patch-batching.d.ts +1 -1
  42. package/dist/renderer/patch-batching.mjs +2 -1
  43. package/dist/renderer/patch-coalescing.cjs +5 -8
  44. package/dist/renderer/patch-commit-scheduler.cjs +160 -326
  45. package/dist/renderer/patch-commit-scheduler.d.cts +28 -4
  46. package/dist/renderer/patch-commit-scheduler.d.ts +28 -4
  47. package/dist/renderer/patch-commit-scheduler.mjs +157 -318
  48. package/dist/renderer/store.cjs +3847 -1099
  49. package/dist/renderer/store.d.cts +111 -3
  50. package/dist/renderer/store.d.ts +111 -3
  51. package/dist/renderer/store.mjs +3847 -1085
  52. package/dist/renderer/virtualized-code.cjs +415 -71
  53. package/dist/renderer/virtualized-code.d.cts +24 -23
  54. package/dist/renderer/virtualized-code.d.ts +24 -23
  55. package/dist/renderer/virtualized-code.mjs +409 -62
  56. package/dist/renderer.cjs +10939 -3974
  57. package/dist/renderer.d.cts +100 -29
  58. package/dist/renderer.d.ts +100 -29
  59. package/dist/renderer.mjs +10711 -3697
  60. package/dist/server-regions-CPLHGli0.d.cts +32 -0
  61. package/dist/server-regions-mUhyoKi7.d.ts +32 -0
  62. package/dist/server.cjs +10286 -3365
  63. package/dist/server.d.cts +17 -247
  64. package/dist/server.d.ts +17 -247
  65. package/dist/server.mjs +10565 -3619
  66. package/dist/{streaming-markdown-DOc2uLiP.d.ts → streaming-markdown-yELbJxyH.d.ts} +51 -55
  67. package/dist/{streaming-markdown-D-JcByd9.d.cts → streaming-markdown-zVwFuaJG.d.cts} +51 -55
  68. package/dist/streaming-markdown.cjs +11828 -4879
  69. package/dist/streaming-markdown.d.cts +9 -2
  70. package/dist/streaming-markdown.d.ts +9 -2
  71. package/dist/streaming-markdown.mjs +11820 -4821
  72. package/dist/trusted-mdx/index.cjs +833 -0
  73. package/dist/trusted-mdx/index.d.cts +11 -0
  74. package/dist/trusted-mdx/index.d.ts +11 -0
  75. package/dist/trusted-mdx/index.mjs +807 -0
  76. package/dist/trusted-mdx/native-children-slot.cjs +45 -0
  77. package/dist/trusted-mdx/native-children-slot.d.cts +11 -0
  78. package/dist/trusted-mdx/native-children-slot.d.ts +11 -0
  79. package/dist/trusted-mdx/native-children-slot.mjs +24 -0
  80. package/dist/trusted-mdx/server.cjs +752 -0
  81. package/dist/trusted-mdx/server.d.cts +24 -0
  82. package/dist/trusted-mdx/server.d.ts +24 -0
  83. package/dist/trusted-mdx/server.mjs +724 -0
  84. package/dist/trusted-mdx-contract-ElKpkDI5.d.cts +113 -0
  85. package/dist/trusted-mdx-contract-ElKpkDI5.d.ts +113 -0
  86. package/dist/utils/inline-html.cjs +246 -147
  87. package/dist/utils/inline-html.d.cts +39 -6
  88. package/dist/utils/inline-html.d.ts +39 -6
  89. package/dist/utils/inline-html.mjs +237 -134
  90. package/package.json +52 -18
  91. package/shadcn/README.md +28 -0
  92. package/shadcn/bottom-stick-scroll-area.tsx +358 -0
  93. package/dist/index-D2MYusAM.d.cts +0 -248
  94. package/dist/index-D2MYusAM.d.ts +0 -248
  95. package/dist/mdx-client.cjs +0 -408
  96. package/dist/mdx-client.d.cts +0 -113
  97. package/dist/mdx-client.d.ts +0 -113
  98. package/dist/mdx-client.mjs +0 -369
  99. package/dist/mdx-coordinator.cjs +0 -563
  100. package/dist/mdx-coordinator.d.cts +0 -21
  101. package/dist/mdx-coordinator.d.ts +0 -21
  102. package/dist/mdx-coordinator.mjs +0 -529
  103. package/dist/renderer/node-views.cjs +0 -1642
  104. package/dist/renderer/node-views.d.cts +0 -12
  105. package/dist/renderer/node-views.d.ts +0 -12
  106. package/dist/renderer/node-views.mjs +0 -1616
@@ -1,529 +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;
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 applyCompiledRef = useCallback(
370
- (block, compiledId) => {
371
- if (mode === "worker") {
372
- return;
373
- }
374
- if (options?.workerClient) {
375
- options.workerClient.setMdxCompiled(block.id, compiledId);
376
- return;
377
- }
378
- const store = options?.store;
379
- if (!store) {
380
- return;
381
- }
382
- const currentBlocks = store.getBlocks();
383
- const index = currentBlocks.findIndex((candidate) => candidate.id === block.id);
384
- if (index === -1) return;
385
- const current = currentBlocks[index];
386
- if (current.payload.compiledMdxRef?.id === compiledId) {
387
- return;
388
- }
389
- store.applyPatches([
390
- {
391
- op: "setProps",
392
- at: { blockId: block.id, nodeId: block.id },
393
- props: {
394
- block: {
395
- ...current,
396
- payload: {
397
- ...current.payload,
398
- compiledMdxRef: { id: compiledId },
399
- meta: {
400
- ...current.payload.meta ?? {},
401
- mdxStatus: "compiled"
402
- }
403
- }
404
- }
405
- }
406
- }
407
- ]);
408
- },
409
- [options?.workerClient, options?.store, mode]
410
- );
411
- useEffect(() => {
412
- if (mode === "worker") {
413
- return;
414
- }
415
- const targets = blocks.filter((b) => b.type === "mdx" && b.isFinalized && !b.payload.compiledMdxRef && !compiledMap.has(b.id));
416
- if (targets.length === 0) return;
417
- let cancelled = false;
418
- (async () => {
419
- for (const block of targets) {
420
- try {
421
- const compiled = await mdxClientRef.current.compile(block);
422
- if (cancelled) return;
423
- registerInlineMdxModule({
424
- id: compiled.id,
425
- code: compiled.code,
426
- dependencies: compiled.dependencies
427
- });
428
- setCompiledMap((prev) => {
429
- if (prev.has(block.id)) return prev;
430
- const next = new Map(prev);
431
- next.set(block.id, compiled.id);
432
- return next;
433
- });
434
- applyCompiledRef(block, compiled.id);
435
- } catch (e) {
436
- console.warn("MDX compile failed for block", block.id, e);
437
- if (options?.workerClient) {
438
- options.workerClient.setMdxError(block.id, e instanceof Error ? e.message : String(e));
439
- } else if (options?.store) {
440
- options.store.applyPatches([
441
- {
442
- op: "setProps",
443
- at: { blockId: block.id, nodeId: block.id },
444
- props: {
445
- block: {
446
- ...block,
447
- payload: {
448
- ...block.payload,
449
- meta: { ...block.payload.meta ?? {}, mdxStatus: "error", mdxError: e instanceof Error ? e.message : String(e) }
450
- }
451
- }
452
- }
453
- }
454
- ]);
455
- }
456
- }
457
- }
458
- })();
459
- return () => {
460
- cancelled = true;
461
- };
462
- }, [blocks, compiledMap, applyCompiledRef, options?.workerClient, options?.store, mode]);
463
- useEffect(() => {
464
- if (mode === "worker") {
465
- return;
466
- }
467
- const blockMap = new Map(blocks.map((block) => [block.id, block]));
468
- setCompiledMap((prev) => {
469
- let mutated = false;
470
- const next = new Map(prev);
471
- for (const [blockId] of prev) {
472
- const candidate = blockMap.get(blockId);
473
- if (!candidate || candidate.type !== "mdx") {
474
- next.delete(blockId);
475
- mutated = true;
476
- continue;
477
- }
478
- const previousSignature = blockSignatureRef.current.get(blockId);
479
- const currentSignature = candidate.payload.raw ?? "";
480
- if (previousSignature !== void 0 && previousSignature !== currentSignature) {
481
- next.delete(blockId);
482
- mutated = true;
483
- }
484
- }
485
- return mutated ? next : prev;
486
- });
487
- const signatureMap = /* @__PURE__ */ new Map();
488
- for (const block of blocks) {
489
- if (block.type === "mdx") {
490
- signatureMap.set(block.id, block.payload.raw ?? "");
491
- }
492
- }
493
- blockSignatureRef.current = signatureMap;
494
- }, [blocks, mode]);
495
- const derivedBlocks = useMemo(() => {
496
- if (mode === "worker") {
497
- return blocks;
498
- }
499
- if (options?.workerClient) {
500
- return blocks;
501
- }
502
- if (compiledMap.size === 0) return blocks;
503
- let changed = false;
504
- const out = blocks.map((b) => {
505
- if (b.type === "mdx" && !b.payload.compiledMdxRef) {
506
- const id = compiledMap.get(b.id);
507
- if (id) {
508
- changed = true;
509
- return {
510
- ...b,
511
- payload: {
512
- ...b.payload,
513
- compiledMdxRef: { id }
514
- }
515
- };
516
- }
517
- }
518
- return b;
519
- });
520
- return changed ? out : blocks;
521
- }, [blocks, compiledMap, mode, options?.workerClient]);
522
- if (options?.workerClient) {
523
- return blocks;
524
- }
525
- return derivedBlocks;
526
- }
527
- export {
528
- useMdxCoordinator
529
- };