@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.
Files changed (45) hide show
  1. package/dist/components/index.cjs +497 -163
  2. package/dist/components/index.d.cts +1 -1
  3. package/dist/components/index.d.ts +1 -1
  4. package/dist/components/index.mjs +496 -163
  5. package/dist/{index-Bt1opGCs.d.cts → index-D7px9jug.d.cts} +27 -2
  6. package/dist/{index-Bt1opGCs.d.ts → index-D7px9jug.d.ts} +27 -2
  7. package/dist/index.cjs +3767 -2043
  8. package/dist/index.d.cts +43 -5
  9. package/dist/index.d.ts +43 -5
  10. package/dist/index.mjs +3991 -2265
  11. package/dist/mdx-client.cjs +60 -18
  12. package/dist/mdx-client.d.cts +11 -0
  13. package/dist/mdx-client.d.ts +11 -0
  14. package/dist/mdx-client.mjs +60 -18
  15. package/dist/mdx-coordinator.cjs +60 -18
  16. package/dist/mdx-coordinator.mjs +60 -18
  17. package/dist/renderer/node-views.cjs +466 -133
  18. package/dist/renderer/node-views.d.cts +1 -1
  19. package/dist/renderer/node-views.d.ts +1 -1
  20. package/dist/renderer/node-views.mjs +409 -68
  21. package/dist/renderer/patch-commit-scheduler.cjs +68 -7
  22. package/dist/renderer/patch-commit-scheduler.d.cts +6 -5
  23. package/dist/renderer/patch-commit-scheduler.d.ts +6 -5
  24. package/dist/renderer/patch-commit-scheduler.mjs +68 -7
  25. package/dist/renderer/store.cjs +481 -56
  26. package/dist/renderer/store.d.cts +2 -1
  27. package/dist/renderer/store.d.ts +2 -1
  28. package/dist/renderer/store.mjs +479 -47
  29. package/dist/renderer/virtualized-code.cjs +8 -2
  30. package/dist/renderer/virtualized-code.d.cts +4 -0
  31. package/dist/renderer/virtualized-code.d.ts +4 -0
  32. package/dist/renderer/virtualized-code.mjs +8 -2
  33. package/dist/renderer.cjs +3199 -2208
  34. package/dist/renderer.d.cts +4 -2
  35. package/dist/renderer.d.ts +4 -2
  36. package/dist/renderer.mjs +2956 -1957
  37. package/dist/streaming-markdown-DSC4L0xR.d.cts +157 -0
  38. package/dist/streaming-markdown-Dp1IDgMT.d.ts +157 -0
  39. package/dist/streaming-markdown.cjs +3950 -2248
  40. package/dist/streaming-markdown.d.cts +6 -95
  41. package/dist/streaming-markdown.d.ts +6 -95
  42. package/dist/streaming-markdown.mjs +3962 -2252
  43. package/dist/utils/inline-html.d.cts +1 -1
  44. package/dist/utils/inline-html.d.ts +1 -1
  45. package/package.json +3 -3
@@ -61,6 +61,8 @@ var MDXClient = class {
61
61
  constructor(compileEndpoint = "/api/mdx-compile-v2") {
62
62
  this.cache = /* @__PURE__ */ new Map();
63
63
  this.inlineModules = /* @__PURE__ */ new Map();
64
+ this.compiledCache = /* @__PURE__ */ new Map();
65
+ this.compiledInflight = /* @__PURE__ */ new Map();
64
66
  this.compileEndpoint = compileEndpoint;
65
67
  }
66
68
  /**
@@ -85,34 +87,53 @@ var MDXClient = class {
85
87
  throw error;
86
88
  }
87
89
  }
88
- /**
89
- * Get compiled MDX by reference
90
- */
91
- async getCompiled(ref) {
90
+ async getCompiledInternal(ref) {
92
91
  const inline = this.inlineModules.get(ref.id);
93
92
  if (inline) {
94
- return {
95
- ...inline,
96
- dependencies: Array.isArray(inline.dependencies) ? [...inline.dependencies] : []
97
- };
93
+ return this.cloneCompiled(inline);
98
94
  }
99
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`);
100
- if (!response.ok) {
101
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
95
+ const cached = this.compiledCache.get(ref.id);
96
+ if (cached) {
97
+ return this.cloneCompiled(cached);
98
+ }
99
+ const inflight = this.compiledInflight.get(ref.id);
100
+ if (inflight) {
101
+ const resolved = await inflight;
102
+ return this.cloneCompiled(resolved);
103
+ }
104
+ const fetchPromise = this.fetchCompiled(ref);
105
+ this.compiledInflight.set(ref.id, fetchPromise);
106
+ try {
107
+ const data = await fetchPromise;
108
+ this.compiledCache.set(ref.id, data);
109
+ return this.cloneCompiled(data);
110
+ } finally {
111
+ this.compiledInflight.delete(ref.id);
102
112
  }
103
- const data = await response.json();
104
- return {
105
- id: data.id,
106
- code: data.code,
107
- dependencies: data.dependencies || [],
108
- timestamp: data.timestamp
109
- };
113
+ }
114
+ async getCompiled(ref, options) {
115
+ if (options?.signal) {
116
+ const inline = this.inlineModules.get(ref.id);
117
+ if (inline) {
118
+ return this.cloneCompiled(inline);
119
+ }
120
+ const cached = this.compiledCache.get(ref.id);
121
+ if (cached) {
122
+ return this.cloneCompiled(cached);
123
+ }
124
+ const data = await this.fetchCompiled(ref, options);
125
+ this.compiledCache.set(ref.id, data);
126
+ return this.cloneCompiled(data);
127
+ }
128
+ return this.getCompiledInternal(ref);
110
129
  }
111
130
  /**
112
131
  * Clear compilation cache
113
132
  */
114
133
  clearCache() {
115
134
  this.cache.clear();
135
+ this.compiledCache.clear();
136
+ this.compiledInflight.clear();
116
137
  }
117
138
  registerInlineModule(compiled) {
118
139
  this.inlineModules.set(compiled.id, {
@@ -149,6 +170,27 @@ var MDXClient = class {
149
170
  cached: data.cached || false
150
171
  };
151
172
  }
173
+ async fetchCompiled(ref, options) {
174
+ const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
175
+ signal: options?.signal
176
+ });
177
+ if (!response.ok) {
178
+ throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
179
+ }
180
+ const data = await response.json();
181
+ return {
182
+ id: data.id,
183
+ code: data.code,
184
+ dependencies: data.dependencies || [],
185
+ timestamp: data.timestamp
186
+ };
187
+ }
188
+ cloneCompiled(compiled) {
189
+ return {
190
+ ...compiled,
191
+ dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
192
+ };
193
+ }
152
194
  };
153
195
  var MDXComponentFactory = class {
154
196
  constructor(mdxClient) {
@@ -1,6 +1,9 @@
1
1
  import { Block } from '@stream-mdx/core';
2
2
  import React from 'react';
3
3
 
4
+ type CompiledFetchOptions = {
5
+ signal?: AbortSignal;
6
+ };
4
7
  /**
5
8
  * MDX compilation client
6
9
  */
@@ -8,17 +11,23 @@ declare class MDXClient {
8
11
  private compileEndpoint;
9
12
  private cache;
10
13
  private inlineModules;
14
+ private compiledCache;
15
+ private compiledInflight;
11
16
  constructor(compileEndpoint?: string);
12
17
  /**
13
18
  * Compile MDX block on server
14
19
  */
15
20
  compile(block: Block): Promise<CompiledMDX>;
21
+ private getCompiledInternal;
16
22
  /**
17
23
  * Get compiled MDX by reference
18
24
  */
19
25
  getCompiled(ref: {
20
26
  id: string;
21
27
  }): Promise<CompiledMDX>;
28
+ getCompiled(ref: {
29
+ id: string;
30
+ }, options: CompiledFetchOptions): Promise<CompiledMDX>;
22
31
  /**
23
32
  * Clear compilation cache
24
33
  */
@@ -29,6 +38,8 @@ declare class MDXClient {
29
38
  * Actual compilation implementation
30
39
  */
31
40
  private doCompile;
41
+ private fetchCompiled;
42
+ private cloneCompiled;
32
43
  }
33
44
  /**
34
45
  * Compiled MDX result
@@ -1,6 +1,9 @@
1
1
  import { Block } from '@stream-mdx/core';
2
2
  import React from 'react';
3
3
 
4
+ type CompiledFetchOptions = {
5
+ signal?: AbortSignal;
6
+ };
4
7
  /**
5
8
  * MDX compilation client
6
9
  */
@@ -8,17 +11,23 @@ declare class MDXClient {
8
11
  private compileEndpoint;
9
12
  private cache;
10
13
  private inlineModules;
14
+ private compiledCache;
15
+ private compiledInflight;
11
16
  constructor(compileEndpoint?: string);
12
17
  /**
13
18
  * Compile MDX block on server
14
19
  */
15
20
  compile(block: Block): Promise<CompiledMDX>;
21
+ private getCompiledInternal;
16
22
  /**
17
23
  * Get compiled MDX by reference
18
24
  */
19
25
  getCompiled(ref: {
20
26
  id: string;
21
27
  }): Promise<CompiledMDX>;
28
+ getCompiled(ref: {
29
+ id: string;
30
+ }, options: CompiledFetchOptions): Promise<CompiledMDX>;
22
31
  /**
23
32
  * Clear compilation cache
24
33
  */
@@ -29,6 +38,8 @@ declare class MDXClient {
29
38
  * Actual compilation implementation
30
39
  */
31
40
  private doCompile;
41
+ private fetchCompiled;
42
+ private cloneCompiled;
32
43
  }
33
44
  /**
34
45
  * Compiled MDX result
@@ -23,6 +23,8 @@ var MDXClient = class {
23
23
  constructor(compileEndpoint = "/api/mdx-compile-v2") {
24
24
  this.cache = /* @__PURE__ */ new Map();
25
25
  this.inlineModules = /* @__PURE__ */ new Map();
26
+ this.compiledCache = /* @__PURE__ */ new Map();
27
+ this.compiledInflight = /* @__PURE__ */ new Map();
26
28
  this.compileEndpoint = compileEndpoint;
27
29
  }
28
30
  /**
@@ -47,34 +49,53 @@ var MDXClient = class {
47
49
  throw error;
48
50
  }
49
51
  }
50
- /**
51
- * Get compiled MDX by reference
52
- */
53
- async getCompiled(ref) {
52
+ async getCompiledInternal(ref) {
54
53
  const inline = this.inlineModules.get(ref.id);
55
54
  if (inline) {
56
- return {
57
- ...inline,
58
- dependencies: Array.isArray(inline.dependencies) ? [...inline.dependencies] : []
59
- };
55
+ return this.cloneCompiled(inline);
60
56
  }
61
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`);
62
- if (!response.ok) {
63
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
57
+ const cached = this.compiledCache.get(ref.id);
58
+ if (cached) {
59
+ return this.cloneCompiled(cached);
60
+ }
61
+ const inflight = this.compiledInflight.get(ref.id);
62
+ if (inflight) {
63
+ const resolved = await inflight;
64
+ return this.cloneCompiled(resolved);
65
+ }
66
+ const fetchPromise = this.fetchCompiled(ref);
67
+ this.compiledInflight.set(ref.id, fetchPromise);
68
+ try {
69
+ const data = await fetchPromise;
70
+ this.compiledCache.set(ref.id, data);
71
+ return this.cloneCompiled(data);
72
+ } finally {
73
+ this.compiledInflight.delete(ref.id);
64
74
  }
65
- const data = await response.json();
66
- return {
67
- id: data.id,
68
- code: data.code,
69
- dependencies: data.dependencies || [],
70
- timestamp: data.timestamp
71
- };
75
+ }
76
+ async getCompiled(ref, options) {
77
+ if (options?.signal) {
78
+ const inline = this.inlineModules.get(ref.id);
79
+ if (inline) {
80
+ return this.cloneCompiled(inline);
81
+ }
82
+ const cached = this.compiledCache.get(ref.id);
83
+ if (cached) {
84
+ return this.cloneCompiled(cached);
85
+ }
86
+ const data = await this.fetchCompiled(ref, options);
87
+ this.compiledCache.set(ref.id, data);
88
+ return this.cloneCompiled(data);
89
+ }
90
+ return this.getCompiledInternal(ref);
72
91
  }
73
92
  /**
74
93
  * Clear compilation cache
75
94
  */
76
95
  clearCache() {
77
96
  this.cache.clear();
97
+ this.compiledCache.clear();
98
+ this.compiledInflight.clear();
78
99
  }
79
100
  registerInlineModule(compiled) {
80
101
  this.inlineModules.set(compiled.id, {
@@ -111,6 +132,27 @@ var MDXClient = class {
111
132
  cached: data.cached || false
112
133
  };
113
134
  }
135
+ async fetchCompiled(ref, options) {
136
+ const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
137
+ signal: options?.signal
138
+ });
139
+ if (!response.ok) {
140
+ throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
141
+ }
142
+ const data = await response.json();
143
+ return {
144
+ id: data.id,
145
+ code: data.code,
146
+ dependencies: data.dependencies || [],
147
+ timestamp: data.timestamp
148
+ };
149
+ }
150
+ cloneCompiled(compiled) {
151
+ return {
152
+ ...compiled,
153
+ dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
154
+ };
155
+ }
114
156
  };
115
157
  var MDXComponentFactory = class {
116
158
  constructor(mdxClient) {
@@ -60,6 +60,8 @@ var MDXClient = class {
60
60
  constructor(compileEndpoint = "/api/mdx-compile-v2") {
61
61
  this.cache = /* @__PURE__ */ new Map();
62
62
  this.inlineModules = /* @__PURE__ */ new Map();
63
+ this.compiledCache = /* @__PURE__ */ new Map();
64
+ this.compiledInflight = /* @__PURE__ */ new Map();
63
65
  this.compileEndpoint = compileEndpoint;
64
66
  }
65
67
  /**
@@ -84,34 +86,53 @@ var MDXClient = class {
84
86
  throw error;
85
87
  }
86
88
  }
87
- /**
88
- * Get compiled MDX by reference
89
- */
90
- async getCompiled(ref) {
89
+ async getCompiledInternal(ref) {
91
90
  const inline = this.inlineModules.get(ref.id);
92
91
  if (inline) {
93
- return {
94
- ...inline,
95
- dependencies: Array.isArray(inline.dependencies) ? [...inline.dependencies] : []
96
- };
92
+ return this.cloneCompiled(inline);
97
93
  }
98
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`);
99
- if (!response.ok) {
100
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
94
+ const cached = this.compiledCache.get(ref.id);
95
+ if (cached) {
96
+ return this.cloneCompiled(cached);
97
+ }
98
+ const inflight = this.compiledInflight.get(ref.id);
99
+ if (inflight) {
100
+ const resolved = await inflight;
101
+ return this.cloneCompiled(resolved);
102
+ }
103
+ const fetchPromise = this.fetchCompiled(ref);
104
+ this.compiledInflight.set(ref.id, fetchPromise);
105
+ try {
106
+ const data = await fetchPromise;
107
+ this.compiledCache.set(ref.id, data);
108
+ return this.cloneCompiled(data);
109
+ } finally {
110
+ this.compiledInflight.delete(ref.id);
101
111
  }
102
- const data = await response.json();
103
- return {
104
- id: data.id,
105
- code: data.code,
106
- dependencies: data.dependencies || [],
107
- timestamp: data.timestamp
108
- };
112
+ }
113
+ async getCompiled(ref, options) {
114
+ if (options?.signal) {
115
+ const inline = this.inlineModules.get(ref.id);
116
+ if (inline) {
117
+ return this.cloneCompiled(inline);
118
+ }
119
+ const cached = this.compiledCache.get(ref.id);
120
+ if (cached) {
121
+ return this.cloneCompiled(cached);
122
+ }
123
+ const data = await this.fetchCompiled(ref, options);
124
+ this.compiledCache.set(ref.id, data);
125
+ return this.cloneCompiled(data);
126
+ }
127
+ return this.getCompiledInternal(ref);
109
128
  }
110
129
  /**
111
130
  * Clear compilation cache
112
131
  */
113
132
  clearCache() {
114
133
  this.cache.clear();
134
+ this.compiledCache.clear();
135
+ this.compiledInflight.clear();
115
136
  }
116
137
  registerInlineModule(compiled) {
117
138
  this.inlineModules.set(compiled.id, {
@@ -148,6 +169,27 @@ var MDXClient = class {
148
169
  cached: data.cached || false
149
170
  };
150
171
  }
172
+ async fetchCompiled(ref, options) {
173
+ const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
174
+ signal: options?.signal
175
+ });
176
+ if (!response.ok) {
177
+ throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
178
+ }
179
+ const data = await response.json();
180
+ return {
181
+ id: data.id,
182
+ code: data.code,
183
+ dependencies: data.dependencies || [],
184
+ timestamp: data.timestamp
185
+ };
186
+ }
187
+ cloneCompiled(compiled) {
188
+ return {
189
+ ...compiled,
190
+ dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
191
+ };
192
+ }
151
193
  };
152
194
  var MDXComponentFactory = class {
153
195
  constructor(mdxClient) {
@@ -27,6 +27,8 @@ var MDXClient = class {
27
27
  constructor(compileEndpoint = "/api/mdx-compile-v2") {
28
28
  this.cache = /* @__PURE__ */ new Map();
29
29
  this.inlineModules = /* @__PURE__ */ new Map();
30
+ this.compiledCache = /* @__PURE__ */ new Map();
31
+ this.compiledInflight = /* @__PURE__ */ new Map();
30
32
  this.compileEndpoint = compileEndpoint;
31
33
  }
32
34
  /**
@@ -51,34 +53,53 @@ var MDXClient = class {
51
53
  throw error;
52
54
  }
53
55
  }
54
- /**
55
- * Get compiled MDX by reference
56
- */
57
- async getCompiled(ref) {
56
+ async getCompiledInternal(ref) {
58
57
  const inline = this.inlineModules.get(ref.id);
59
58
  if (inline) {
60
- return {
61
- ...inline,
62
- dependencies: Array.isArray(inline.dependencies) ? [...inline.dependencies] : []
63
- };
59
+ return this.cloneCompiled(inline);
64
60
  }
65
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`);
66
- if (!response.ok) {
67
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
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);
68
78
  }
69
- const data = await response.json();
70
- return {
71
- id: data.id,
72
- code: data.code,
73
- dependencies: data.dependencies || [],
74
- timestamp: data.timestamp
75
- };
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);
76
95
  }
77
96
  /**
78
97
  * Clear compilation cache
79
98
  */
80
99
  clearCache() {
81
100
  this.cache.clear();
101
+ this.compiledCache.clear();
102
+ this.compiledInflight.clear();
82
103
  }
83
104
  registerInlineModule(compiled) {
84
105
  this.inlineModules.set(compiled.id, {
@@ -115,6 +136,27 @@ var MDXClient = class {
115
136
  cached: data.cached || false
116
137
  };
117
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
+ }
118
160
  };
119
161
  var MDXComponentFactory = class {
120
162
  constructor(mdxClient) {