@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
@@ -0,0 +1,113 @@
1
+ import { Block, TrustedMdxFlowChildSpan, TrustedMdxArtifact } from '@stream-mdx/core';
2
+ import { ElementType, ReactNode, ComponentType } from 'react';
3
+
4
+ interface TrustedMdxRenderProps {
5
+ readonly components?: Readonly<Record<string, ElementType>>;
6
+ readonly children?: ReactNode;
7
+ }
8
+ type TrustedMdxNativeChildFallback = (index: number) => ReactNode;
9
+ type TrustedMdxNativeChildrenFactory = (fallback: TrustedMdxNativeChildFallback) => ReactNode;
10
+ type TrustedMdxNativeChildOwner = {
11
+ readonly kind: "block";
12
+ readonly blockId: string;
13
+ } | {
14
+ readonly kind: "prepared-tree";
15
+ readonly blockId: string;
16
+ } | {
17
+ readonly kind: "continuation";
18
+ readonly ownerIndex: number;
19
+ } | null;
20
+ /** Private compiler-region invocation props; host components receive TrustedMdxRenderProps only. */
21
+ interface TrustedMdxCompiledRegionProps extends Omit<TrustedMdxRenderProps, "children"> {
22
+ readonly children?: ReactNode | TrustedMdxNativeChildrenFactory;
23
+ }
24
+ /** The compiler closure is invoked locally, not transported as an ordinary React component prop. */
25
+ type TrustedMdxCompiledRegion = (props: TrustedMdxCompiledRegionProps) => ReactNode;
26
+ interface TrustedMdxRevision {
27
+ /** The entire accepted authored document, without per-block concatenation or repair. */
28
+ readonly source: string;
29
+ /** Blocks belonging to that document's completed, committed worker revision. */
30
+ readonly blocks: readonly Block[];
31
+ }
32
+ type TrustedMdxBlockProjection = {
33
+ readonly kind: "render";
34
+ readonly regions: readonly TrustedMdxCompiledRegion[];
35
+ readonly placement: "flow" | "inline";
36
+ readonly rootElementName?: string | null;
37
+ /** The compiler-authored flow root replaces only children represented by its worker owners. */
38
+ readonly nativeChildren?: true;
39
+ /** Per-child owner, inline-run continuation, or null for a compiler-only child. */
40
+ readonly nativeChildOwners?: readonly TrustedMdxNativeChildOwner[];
41
+ readonly flowChildren?: readonly TrustedMdxFlowChildSpan[];
42
+ /** Top-level worker blocks consumed or replaced by this exact flow region. */
43
+ readonly nativeFlowOwnedBlockIds?: readonly string[];
44
+ /** The exact full worker block is the compiler-authored flow root. */
45
+ readonly wholeBlockFlowRoot?: true;
46
+ /** This block is rendered only inside its compiler-authored flow parent. */
47
+ readonly nativeFlowParent?: true;
48
+ } | {
49
+ /** Server projection carries React content, never evaluated closures or component maps. */
50
+ readonly kind: "server-content";
51
+ readonly content: ReactNode;
52
+ readonly placement: "flow" | "inline";
53
+ readonly nativeChildren?: true;
54
+ readonly nativeChildOwners?: readonly TrustedMdxNativeChildOwner[];
55
+ readonly flowChildren?: readonly TrustedMdxFlowChildSpan[];
56
+ readonly nativeFlowOwnedBlockIds?: readonly string[];
57
+ readonly wholeBlockFlowRoot?: true;
58
+ readonly nativeFlowParent?: true;
59
+ readonly rootElementName?: string | null;
60
+ } | {
61
+ readonly kind: "native-child";
62
+ readonly nativeFlowParent: true;
63
+ } | {
64
+ readonly kind: "module";
65
+ readonly nativeFlowParent?: true;
66
+ } | {
67
+ readonly kind: "unmapped";
68
+ readonly diagnostic: string;
69
+ readonly placement?: "flow" | "inline";
70
+ readonly nativeFlowParent?: true;
71
+ };
72
+ interface TrustedMdxDocumentSnapshot {
73
+ readonly requestedRevision: number;
74
+ /** Revision supplying the currently projected bindings; may be older than requested. */
75
+ readonly projectionRevision: number | null;
76
+ /** Advances only when a host confirms that projected content actually committed. */
77
+ readonly renderedRevision: number | null;
78
+ readonly status: "idle" | "compiling" | "ready" | "error" | "disposed";
79
+ readonly error: string | null;
80
+ readonly components: Readonly<Record<string, ElementType>>;
81
+ readonly layout: ComponentType<TrustedMdxRenderProps> | null;
82
+ readonly projections: Readonly<Record<string, TrustedMdxBlockProjection>>;
83
+ }
84
+ /** Evaluation and component identities are owned by this lease, never another document. */
85
+ interface TrustedMdxDocument {
86
+ readonly getSnapshot: () => TrustedMdxDocumentSnapshot;
87
+ readonly subscribe: (listener: () => void) => () => void;
88
+ readonly compileRevision: (revision: TrustedMdxRevision) => Promise<void>;
89
+ readonly confirmRenderedRevision: (revision: number) => void;
90
+ /** Rejects that candidate and restores the last actually committed module, if any. */
91
+ readonly reportRenderError: (revision: number, error: unknown) => void;
92
+ readonly clear: () => void;
93
+ readonly dispose: () => void;
94
+ }
95
+ interface TrustedMdxEngine {
96
+ readonly createDocument: () => TrustedMdxDocument;
97
+ /** Changes whenever the engine invalidates existing authorization/cache state. */
98
+ readonly getGeneration: () => number;
99
+ readonly subscribe: (listener: () => void) => () => void;
100
+ /** Invalidates shared pure compilation artifacts and all extant lease revisions. */
101
+ readonly clearCache: () => void;
102
+ readonly dispose: () => void;
103
+ }
104
+ interface TrustedMdxEngineOptions {
105
+ readonly components?: Readonly<Record<string, ElementType>>;
106
+ /** Explicit host bindings; absent authored imports are rejected, not fetched. */
107
+ readonly imports?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
108
+ /** Optional explicit host compiler. The addon otherwise compiles locally. */
109
+ readonly compile?: (source: string) => Promise<TrustedMdxArtifact>;
110
+ readonly compilerIdentity?: string;
111
+ }
112
+
113
+ export type { TrustedMdxEngineOptions as T, TrustedMdxEngine as a, TrustedMdxBlockProjection as b, TrustedMdxDocument as c, TrustedMdxDocumentSnapshot as d, TrustedMdxRenderProps as e, TrustedMdxRevision as f, TrustedMdxNativeChildOwner as g };
@@ -0,0 +1,113 @@
1
+ import { Block, TrustedMdxFlowChildSpan, TrustedMdxArtifact } from '@stream-mdx/core';
2
+ import { ElementType, ReactNode, ComponentType } from 'react';
3
+
4
+ interface TrustedMdxRenderProps {
5
+ readonly components?: Readonly<Record<string, ElementType>>;
6
+ readonly children?: ReactNode;
7
+ }
8
+ type TrustedMdxNativeChildFallback = (index: number) => ReactNode;
9
+ type TrustedMdxNativeChildrenFactory = (fallback: TrustedMdxNativeChildFallback) => ReactNode;
10
+ type TrustedMdxNativeChildOwner = {
11
+ readonly kind: "block";
12
+ readonly blockId: string;
13
+ } | {
14
+ readonly kind: "prepared-tree";
15
+ readonly blockId: string;
16
+ } | {
17
+ readonly kind: "continuation";
18
+ readonly ownerIndex: number;
19
+ } | null;
20
+ /** Private compiler-region invocation props; host components receive TrustedMdxRenderProps only. */
21
+ interface TrustedMdxCompiledRegionProps extends Omit<TrustedMdxRenderProps, "children"> {
22
+ readonly children?: ReactNode | TrustedMdxNativeChildrenFactory;
23
+ }
24
+ /** The compiler closure is invoked locally, not transported as an ordinary React component prop. */
25
+ type TrustedMdxCompiledRegion = (props: TrustedMdxCompiledRegionProps) => ReactNode;
26
+ interface TrustedMdxRevision {
27
+ /** The entire accepted authored document, without per-block concatenation or repair. */
28
+ readonly source: string;
29
+ /** Blocks belonging to that document's completed, committed worker revision. */
30
+ readonly blocks: readonly Block[];
31
+ }
32
+ type TrustedMdxBlockProjection = {
33
+ readonly kind: "render";
34
+ readonly regions: readonly TrustedMdxCompiledRegion[];
35
+ readonly placement: "flow" | "inline";
36
+ readonly rootElementName?: string | null;
37
+ /** The compiler-authored flow root replaces only children represented by its worker owners. */
38
+ readonly nativeChildren?: true;
39
+ /** Per-child owner, inline-run continuation, or null for a compiler-only child. */
40
+ readonly nativeChildOwners?: readonly TrustedMdxNativeChildOwner[];
41
+ readonly flowChildren?: readonly TrustedMdxFlowChildSpan[];
42
+ /** Top-level worker blocks consumed or replaced by this exact flow region. */
43
+ readonly nativeFlowOwnedBlockIds?: readonly string[];
44
+ /** The exact full worker block is the compiler-authored flow root. */
45
+ readonly wholeBlockFlowRoot?: true;
46
+ /** This block is rendered only inside its compiler-authored flow parent. */
47
+ readonly nativeFlowParent?: true;
48
+ } | {
49
+ /** Server projection carries React content, never evaluated closures or component maps. */
50
+ readonly kind: "server-content";
51
+ readonly content: ReactNode;
52
+ readonly placement: "flow" | "inline";
53
+ readonly nativeChildren?: true;
54
+ readonly nativeChildOwners?: readonly TrustedMdxNativeChildOwner[];
55
+ readonly flowChildren?: readonly TrustedMdxFlowChildSpan[];
56
+ readonly nativeFlowOwnedBlockIds?: readonly string[];
57
+ readonly wholeBlockFlowRoot?: true;
58
+ readonly nativeFlowParent?: true;
59
+ readonly rootElementName?: string | null;
60
+ } | {
61
+ readonly kind: "native-child";
62
+ readonly nativeFlowParent: true;
63
+ } | {
64
+ readonly kind: "module";
65
+ readonly nativeFlowParent?: true;
66
+ } | {
67
+ readonly kind: "unmapped";
68
+ readonly diagnostic: string;
69
+ readonly placement?: "flow" | "inline";
70
+ readonly nativeFlowParent?: true;
71
+ };
72
+ interface TrustedMdxDocumentSnapshot {
73
+ readonly requestedRevision: number;
74
+ /** Revision supplying the currently projected bindings; may be older than requested. */
75
+ readonly projectionRevision: number | null;
76
+ /** Advances only when a host confirms that projected content actually committed. */
77
+ readonly renderedRevision: number | null;
78
+ readonly status: "idle" | "compiling" | "ready" | "error" | "disposed";
79
+ readonly error: string | null;
80
+ readonly components: Readonly<Record<string, ElementType>>;
81
+ readonly layout: ComponentType<TrustedMdxRenderProps> | null;
82
+ readonly projections: Readonly<Record<string, TrustedMdxBlockProjection>>;
83
+ }
84
+ /** Evaluation and component identities are owned by this lease, never another document. */
85
+ interface TrustedMdxDocument {
86
+ readonly getSnapshot: () => TrustedMdxDocumentSnapshot;
87
+ readonly subscribe: (listener: () => void) => () => void;
88
+ readonly compileRevision: (revision: TrustedMdxRevision) => Promise<void>;
89
+ readonly confirmRenderedRevision: (revision: number) => void;
90
+ /** Rejects that candidate and restores the last actually committed module, if any. */
91
+ readonly reportRenderError: (revision: number, error: unknown) => void;
92
+ readonly clear: () => void;
93
+ readonly dispose: () => void;
94
+ }
95
+ interface TrustedMdxEngine {
96
+ readonly createDocument: () => TrustedMdxDocument;
97
+ /** Changes whenever the engine invalidates existing authorization/cache state. */
98
+ readonly getGeneration: () => number;
99
+ readonly subscribe: (listener: () => void) => () => void;
100
+ /** Invalidates shared pure compilation artifacts and all extant lease revisions. */
101
+ readonly clearCache: () => void;
102
+ readonly dispose: () => void;
103
+ }
104
+ interface TrustedMdxEngineOptions {
105
+ readonly components?: Readonly<Record<string, ElementType>>;
106
+ /** Explicit host bindings; absent authored imports are rejected, not fetched. */
107
+ readonly imports?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
108
+ /** Optional explicit host compiler. The addon otherwise compiles locally. */
109
+ readonly compile?: (source: string) => Promise<TrustedMdxArtifact>;
110
+ readonly compilerIdentity?: string;
111
+ }
112
+
113
+ export type { TrustedMdxEngineOptions as T, TrustedMdxEngine as a, TrustedMdxBlockProjection as b, TrustedMdxDocument as c, TrustedMdxDocumentSnapshot as d, TrustedMdxRenderProps as e, TrustedMdxRevision as f, TrustedMdxNativeChildOwner as g };