@frontmcp/ui 0.6.1 → 0.6.2
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/bridge/core/bridge-factory.d.ts +1 -0
- package/bridge/core/bridge-factory.d.ts.map +1 -1
- package/bridge/index.d.ts +1 -1
- package/bridge/index.d.ts.map +1 -1
- package/bridge/index.js +39 -881
- package/bundler/browser-components.d.ts +42 -0
- package/bundler/browser-components.d.ts.map +1 -0
- package/bundler/bundler.d.ts +78 -4
- package/bundler/bundler.d.ts.map +1 -1
- package/bundler/index.d.ts +8 -8
- package/bundler/index.d.ts.map +1 -1
- package/bundler/index.js +1315 -1854
- package/bundler/types.d.ts +188 -7
- package/bundler/types.d.ts.map +1 -1
- package/esm/bridge/{index.js → index.mjs} +40 -877
- package/esm/bundler/{index.js → index.mjs} +1391 -1895
- package/esm/{index.js → index.mjs} +215 -3091
- package/esm/layouts/{index.js → index.mjs} +3 -3
- package/esm/package.json +9 -8
- package/esm/react/index.mjs +1183 -0
- package/esm/renderers/index.mjs +611 -0
- package/esm/universal/{index.js → index.mjs} +266 -70
- package/index.d.ts +1 -4
- package/index.d.ts.map +1 -1
- package/index.js +208 -3113
- package/layouts/base.d.ts.map +1 -1
- package/layouts/index.js +3 -3
- package/layouts/presets.d.ts.map +1 -1
- package/package.json +9 -8
- package/react/Badge.d.ts.map +1 -1
- package/react/hooks/context.d.ts.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +57 -2001
- package/react/types.d.ts.map +1 -1
- package/renderers/index.d.ts +9 -4
- package/renderers/index.d.ts.map +1 -1
- package/renderers/index.js +328 -88
- package/renderers/mdx.renderer.d.ts +99 -0
- package/renderers/mdx.renderer.d.ts.map +1 -0
- package/renderers/react.renderer.d.ts +22 -13
- package/renderers/react.renderer.d.ts.map +1 -1
- package/renderers/transpiler.d.ts +49 -0
- package/renderers/transpiler.d.ts.map +1 -0
- package/universal/cached-runtime.d.ts +25 -1
- package/universal/cached-runtime.d.ts.map +1 -1
- package/universal/index.js +266 -70
- package/universal/runtime-builder.d.ts.map +1 -1
- package/universal/types.d.ts.map +1 -1
- package/web-components/elements/fmcp-input.d.ts.map +1 -1
- package/web-components/elements/fmcp-select.d.ts.map +1 -1
- package/web-components/index.d.ts +0 -1
- package/web-components/index.d.ts.map +1 -1
- package/bundler/cache.d.ts +0 -173
- package/bundler/cache.d.ts.map +0 -1
- package/bundler/file-cache/component-builder.d.ts +0 -167
- package/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/bundler/file-cache/index.d.ts +0 -12
- package/bundler/file-cache/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/bundler/file-cache/storage/index.d.ts +0 -11
- package/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/interface.d.ts +0 -152
- package/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/bundler/file-cache/storage/redis.d.ts +0 -139
- package/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/bundler/sandbox/executor.d.ts +0 -14
- package/bundler/sandbox/executor.d.ts.map +0 -1
- package/bundler/sandbox/policy.d.ts +0 -62
- package/bundler/sandbox/policy.d.ts.map +0 -1
- package/esm/bridge/adapters/base-adapter.d.ts +0 -104
- package/esm/bridge/adapters/base-adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/claude.adapter.d.ts +0 -67
- package/esm/bridge/adapters/claude.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/ext-apps.adapter.d.ts +0 -143
- package/esm/bridge/adapters/ext-apps.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/gemini.adapter.d.ts +0 -64
- package/esm/bridge/adapters/gemini.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/generic.adapter.d.ts +0 -56
- package/esm/bridge/adapters/generic.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/index.d.ts +0 -26
- package/esm/bridge/adapters/index.d.ts.map +0 -1
- package/esm/bridge/adapters/openai.adapter.d.ts +0 -65
- package/esm/bridge/adapters/openai.adapter.d.ts.map +0 -1
- package/esm/bridge/core/adapter-registry.d.ts +0 -122
- package/esm/bridge/core/adapter-registry.d.ts.map +0 -1
- package/esm/bridge/core/bridge-factory.d.ts +0 -199
- package/esm/bridge/core/bridge-factory.d.ts.map +0 -1
- package/esm/bridge/core/index.d.ts +0 -10
- package/esm/bridge/core/index.d.ts.map +0 -1
- package/esm/bridge/index.d.ts +0 -62
- package/esm/bridge/index.d.ts.map +0 -1
- package/esm/bridge/runtime/iife-generator.d.ts +0 -62
- package/esm/bridge/runtime/iife-generator.d.ts.map +0 -1
- package/esm/bridge/runtime/index.d.ts +0 -10
- package/esm/bridge/runtime/index.d.ts.map +0 -1
- package/esm/bridge/types.d.ts +0 -386
- package/esm/bridge/types.d.ts.map +0 -1
- package/esm/bundler/bundler.d.ts +0 -208
- package/esm/bundler/bundler.d.ts.map +0 -1
- package/esm/bundler/cache.d.ts +0 -173
- package/esm/bundler/cache.d.ts.map +0 -1
- package/esm/bundler/file-cache/component-builder.d.ts +0 -167
- package/esm/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/esm/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/esm/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/esm/bundler/file-cache/index.d.ts +0 -12
- package/esm/bundler/file-cache/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/esm/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/index.d.ts +0 -11
- package/esm/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/interface.d.ts +0 -152
- package/esm/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/redis.d.ts +0 -139
- package/esm/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/esm/bundler/index.d.ts +0 -43
- package/esm/bundler/index.d.ts.map +0 -1
- package/esm/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/esm/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/esm/bundler/sandbox/executor.d.ts +0 -14
- package/esm/bundler/sandbox/executor.d.ts.map +0 -1
- package/esm/bundler/sandbox/policy.d.ts +0 -62
- package/esm/bundler/sandbox/policy.d.ts.map +0 -1
- package/esm/bundler/types.d.ts +0 -702
- package/esm/bundler/types.d.ts.map +0 -1
- package/esm/components/alert.d.ts +0 -66
- package/esm/components/alert.d.ts.map +0 -1
- package/esm/components/alert.schema.d.ts +0 -98
- package/esm/components/alert.schema.d.ts.map +0 -1
- package/esm/components/avatar.d.ts +0 -77
- package/esm/components/avatar.d.ts.map +0 -1
- package/esm/components/avatar.schema.d.ts +0 -170
- package/esm/components/avatar.schema.d.ts.map +0 -1
- package/esm/components/badge.d.ts +0 -64
- package/esm/components/badge.d.ts.map +0 -1
- package/esm/components/badge.schema.d.ts +0 -91
- package/esm/components/badge.schema.d.ts.map +0 -1
- package/esm/components/button.d.ts +0 -100
- package/esm/components/button.d.ts.map +0 -1
- package/esm/components/button.schema.d.ts +0 -120
- package/esm/components/button.schema.d.ts.map +0 -1
- package/esm/components/card.d.ts +0 -53
- package/esm/components/card.d.ts.map +0 -1
- package/esm/components/card.schema.d.ts +0 -93
- package/esm/components/card.schema.d.ts.map +0 -1
- package/esm/components/form.d.ts +0 -212
- package/esm/components/form.d.ts.map +0 -1
- package/esm/components/form.schema.d.ts +0 -365
- package/esm/components/form.schema.d.ts.map +0 -1
- package/esm/components/index.d.ts +0 -29
- package/esm/components/index.d.ts.map +0 -1
- package/esm/components/list.d.ts +0 -121
- package/esm/components/list.d.ts.map +0 -1
- package/esm/components/list.schema.d.ts +0 -129
- package/esm/components/list.schema.d.ts.map +0 -1
- package/esm/components/modal.d.ts +0 -100
- package/esm/components/modal.d.ts.map +0 -1
- package/esm/components/modal.schema.d.ts +0 -151
- package/esm/components/modal.schema.d.ts.map +0 -1
- package/esm/components/table.d.ts +0 -91
- package/esm/components/table.d.ts.map +0 -1
- package/esm/components/table.schema.d.ts +0 -123
- package/esm/components/table.schema.d.ts.map +0 -1
- package/esm/index.d.ts +0 -40
- package/esm/index.d.ts.map +0 -1
- package/esm/layouts/base.d.ts +0 -86
- package/esm/layouts/base.d.ts.map +0 -1
- package/esm/layouts/index.d.ts +0 -8
- package/esm/layouts/index.d.ts.map +0 -1
- package/esm/layouts/presets.d.ts +0 -134
- package/esm/layouts/presets.d.ts.map +0 -1
- package/esm/pages/consent.d.ts +0 -117
- package/esm/pages/consent.d.ts.map +0 -1
- package/esm/pages/error.d.ts +0 -101
- package/esm/pages/error.d.ts.map +0 -1
- package/esm/pages/index.d.ts +0 -9
- package/esm/pages/index.d.ts.map +0 -1
- package/esm/pages/index.js +0 -1036
- package/esm/react/Alert.d.ts +0 -101
- package/esm/react/Alert.d.ts.map +0 -1
- package/esm/react/Badge.d.ts +0 -100
- package/esm/react/Badge.d.ts.map +0 -1
- package/esm/react/Button.d.ts +0 -108
- package/esm/react/Button.d.ts.map +0 -1
- package/esm/react/Card.d.ts +0 -103
- package/esm/react/Card.d.ts.map +0 -1
- package/esm/react/hooks/context.d.ts +0 -179
- package/esm/react/hooks/context.d.ts.map +0 -1
- package/esm/react/hooks/index.d.ts +0 -42
- package/esm/react/hooks/index.d.ts.map +0 -1
- package/esm/react/hooks/tools.d.ts +0 -284
- package/esm/react/hooks/tools.d.ts.map +0 -1
- package/esm/react/index.d.ts +0 -80
- package/esm/react/index.d.ts.map +0 -1
- package/esm/react/index.js +0 -3124
- package/esm/react/types.d.ts +0 -105
- package/esm/react/types.d.ts.map +0 -1
- package/esm/react/utils.d.ts +0 -43
- package/esm/react/utils.d.ts.map +0 -1
- package/esm/render/index.d.ts +0 -8
- package/esm/render/index.d.ts.map +0 -1
- package/esm/render/prerender.d.ts +0 -57
- package/esm/render/prerender.d.ts.map +0 -1
- package/esm/renderers/index.d.ts +0 -21
- package/esm/renderers/index.d.ts.map +0 -1
- package/esm/renderers/index.js +0 -381
- package/esm/renderers/react.adapter.d.ts +0 -70
- package/esm/renderers/react.adapter.d.ts.map +0 -1
- package/esm/renderers/react.renderer.d.ts +0 -96
- package/esm/renderers/react.renderer.d.ts.map +0 -1
- package/esm/universal/UniversalApp.d.ts +0 -108
- package/esm/universal/UniversalApp.d.ts.map +0 -1
- package/esm/universal/cached-runtime.d.ts +0 -115
- package/esm/universal/cached-runtime.d.ts.map +0 -1
- package/esm/universal/context.d.ts +0 -122
- package/esm/universal/context.d.ts.map +0 -1
- package/esm/universal/index.d.ts +0 -57
- package/esm/universal/index.d.ts.map +0 -1
- package/esm/universal/renderers/html.renderer.d.ts +0 -37
- package/esm/universal/renderers/html.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/index.d.ts +0 -112
- package/esm/universal/renderers/index.d.ts.map +0 -1
- package/esm/universal/renderers/markdown.renderer.d.ts +0 -33
- package/esm/universal/renderers/markdown.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/mdx.renderer.d.ts +0 -38
- package/esm/universal/renderers/mdx.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/react.renderer.d.ts +0 -46
- package/esm/universal/renderers/react.renderer.d.ts.map +0 -1
- package/esm/universal/runtime-builder.d.ts +0 -33
- package/esm/universal/runtime-builder.d.ts.map +0 -1
- package/esm/universal/store.d.ts +0 -135
- package/esm/universal/store.d.ts.map +0 -1
- package/esm/universal/types.d.ts +0 -199
- package/esm/universal/types.d.ts.map +0 -1
- package/esm/web-components/core/attribute-parser.d.ts +0 -82
- package/esm/web-components/core/attribute-parser.d.ts.map +0 -1
- package/esm/web-components/core/base-element.d.ts +0 -197
- package/esm/web-components/core/base-element.d.ts.map +0 -1
- package/esm/web-components/core/index.d.ts +0 -9
- package/esm/web-components/core/index.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-alert.d.ts +0 -46
- package/esm/web-components/elements/fmcp-alert.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-badge.d.ts +0 -47
- package/esm/web-components/elements/fmcp-badge.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-button.d.ts +0 -117
- package/esm/web-components/elements/fmcp-button.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-card.d.ts +0 -53
- package/esm/web-components/elements/fmcp-card.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-input.d.ts +0 -96
- package/esm/web-components/elements/fmcp-input.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-select.d.ts +0 -100
- package/esm/web-components/elements/fmcp-select.d.ts.map +0 -1
- package/esm/web-components/elements/index.d.ts +0 -13
- package/esm/web-components/elements/index.d.ts.map +0 -1
- package/esm/web-components/index.d.ts +0 -50
- package/esm/web-components/index.d.ts.map +0 -1
- package/esm/web-components/register.d.ts +0 -57
- package/esm/web-components/register.d.ts.map +0 -1
- package/esm/web-components/types.d.ts +0 -122
- package/esm/web-components/types.d.ts.map +0 -1
- package/esm/widgets/index.d.ts +0 -8
- package/esm/widgets/index.d.ts.map +0 -1
- package/esm/widgets/index.js +0 -883
- package/esm/widgets/progress.d.ts +0 -133
- package/esm/widgets/progress.d.ts.map +0 -1
- package/esm/widgets/resource.d.ts +0 -163
- package/esm/widgets/resource.d.ts.map +0 -1
- package/pages/consent.d.ts +0 -117
- package/pages/consent.d.ts.map +0 -1
- package/pages/error.d.ts +0 -101
- package/pages/error.d.ts.map +0 -1
- package/pages/index.d.ts +0 -9
- package/pages/index.d.ts.map +0 -1
- package/pages/index.js +0 -1065
- package/react/utils.d.ts +0 -43
- package/react/utils.d.ts.map +0 -1
- package/widgets/index.d.ts +0 -8
- package/widgets/index.d.ts.map +0 -1
- package/widgets/index.js +0 -910
- package/widgets/progress.d.ts +0 -133
- package/widgets/progress.d.ts.map +0 -1
- package/widgets/resource.d.ts +0 -163
- package/widgets/resource.d.ts.map +0 -1
- /package/esm/components/{index.js → index.mjs} +0 -0
- /package/esm/render/{index.js → index.mjs} +0 -0
- /package/esm/web-components/{index.js → index.mjs} +0 -0
package/react/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/react/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/react/types.ts"],"names":[],"mappings":"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"}
|
package/renderers/index.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React Renderer Module
|
|
3
3
|
*
|
|
4
|
-
* Provides the React renderer for template processing.
|
|
5
|
-
*
|
|
4
|
+
* Provides the React renderer and MDX server-side renderer for template processing.
|
|
5
|
+
* For React-free renderers (HTML, client-side MDX) use @frontmcp/uipack/renderers.
|
|
6
6
|
*
|
|
7
7
|
* @module @frontmcp/ui/renderers
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
-
* import { reactRenderer, ReactRenderer } from '@frontmcp/ui/renderers';
|
|
11
|
+
* import { reactRenderer, ReactRenderer, mdxRenderer, MdxRenderer } from '@frontmcp/ui/renderers';
|
|
12
12
|
* import { rendererRegistry } from '@frontmcp/uipack/renderers';
|
|
13
13
|
*
|
|
14
14
|
* // Register React renderer
|
|
15
15
|
* rendererRegistry.register(reactRenderer);
|
|
16
|
+
*
|
|
17
|
+
* // Use MDX server-side renderer
|
|
18
|
+
* const html = await mdxRenderer.render('# Hello {output.name}', context);
|
|
16
19
|
* ```
|
|
17
20
|
*/
|
|
18
21
|
export type { RendererType, UIRenderer, ToolUIProps, HydratedToolUIProps, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts, RenderResult, RendererRegistryOptions, DetectionResult, ReactComponentType, WrapperContext, ExtendedToolUIConfig, } from '@frontmcp/uipack/renderers';
|
|
19
|
-
export { ReactRenderer, reactRenderer
|
|
22
|
+
export { ReactRenderer, reactRenderer } from './react.renderer';
|
|
20
23
|
export { ReactRendererAdapter, createReactAdapter, loadReactAdapter } from './react.adapter';
|
|
24
|
+
export { MdxRenderer, mdxRenderer } from './mdx.renderer';
|
|
25
|
+
export { executeTranspiledCode, transpileAndExecute } from './transpiler';
|
|
21
26
|
//# sourceMappingURL=index.d.ts.map
|
package/renderers/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,YAAY,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAI7F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/renderers/index.js
CHANGED
|
@@ -30,17 +30,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// libs/ui/src/renderers/index.ts
|
|
31
31
|
var renderers_exports = {};
|
|
32
32
|
__export(renderers_exports, {
|
|
33
|
+
MdxRenderer: () => MdxRenderer,
|
|
33
34
|
ReactRenderer: () => ReactRenderer,
|
|
34
35
|
ReactRendererAdapter: () => ReactRendererAdapter,
|
|
35
|
-
buildHydrationScript: () => buildHydrationScript,
|
|
36
36
|
createReactAdapter: () => createReactAdapter,
|
|
37
|
+
executeTranspiledCode: () => executeTranspiledCode,
|
|
37
38
|
loadReactAdapter: () => loadReactAdapter,
|
|
38
|
-
|
|
39
|
+
mdxRenderer: () => mdxRenderer,
|
|
40
|
+
reactRenderer: () => reactRenderer,
|
|
41
|
+
transpileAndExecute: () => transpileAndExecute
|
|
39
42
|
});
|
|
40
43
|
module.exports = __toCommonJS(renderers_exports);
|
|
41
44
|
|
|
42
45
|
// libs/ui/src/renderers/react.renderer.ts
|
|
43
46
|
var import_renderers = require("@frontmcp/uipack/renderers");
|
|
47
|
+
var VALID_JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
48
|
+
function isValidComponentName(name) {
|
|
49
|
+
return VALID_JS_IDENTIFIER.test(name);
|
|
50
|
+
}
|
|
51
|
+
function sanitizeComponentName(name) {
|
|
52
|
+
if (isValidComponentName(name)) {
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
55
|
+
const sanitized = name.replace(/[^a-zA-Z0-9_$]/g, "_").replace(/^[0-9]/, "_$&");
|
|
56
|
+
return sanitized || "Component";
|
|
57
|
+
}
|
|
44
58
|
var REACT_CDN = {
|
|
45
59
|
react: "https://esm.sh/react@19",
|
|
46
60
|
reactDom: "https://esm.sh/react-dom@19/client"
|
|
@@ -54,13 +68,6 @@ var ReactRenderer = class {
|
|
|
54
68
|
type = "react";
|
|
55
69
|
priority = 20;
|
|
56
70
|
// Higher priority than HTML
|
|
57
|
-
/**
|
|
58
|
-
* Lazy-loaded React modules.
|
|
59
|
-
*/
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
React = null;
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
-
ReactDOMServer = null;
|
|
64
71
|
/**
|
|
65
72
|
* Check if this renderer can handle the given template.
|
|
66
73
|
*
|
|
@@ -101,46 +108,109 @@ var ReactRenderer = class {
|
|
|
101
108
|
throw new Error("Invalid template type for ReactRenderer");
|
|
102
109
|
}
|
|
103
110
|
/**
|
|
104
|
-
* Render the template to HTML
|
|
111
|
+
* Render the template to HTML for client-side rendering.
|
|
112
|
+
*
|
|
113
|
+
* Unlike SSR, this method generates HTML that will be rendered
|
|
114
|
+
* client-side by React in the browser. No server-side React required.
|
|
115
|
+
*
|
|
116
|
+
* The generated HTML includes:
|
|
117
|
+
* - A container div for the React root
|
|
118
|
+
* - The component code (transpiled if needed)
|
|
119
|
+
* - Props embedded as a data attribute
|
|
120
|
+
* - A render script that initializes the component
|
|
105
121
|
*/
|
|
106
|
-
async render(template, context,
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
async render(template, context, _options) {
|
|
123
|
+
const props = {
|
|
124
|
+
input: context.input,
|
|
125
|
+
output: context.output,
|
|
126
|
+
structuredContent: context.structuredContent,
|
|
127
|
+
helpers: context.helpers
|
|
128
|
+
};
|
|
129
|
+
const escapedProps = JSON.stringify(props).replace(/&/g, "&").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
130
|
+
const rootId = `frontmcp-react-${(0, import_renderers.hashString)(Date.now().toString()).slice(0, 8)}`;
|
|
131
|
+
let componentCode;
|
|
132
|
+
let componentName;
|
|
109
133
|
if (typeof template === "function") {
|
|
110
|
-
|
|
134
|
+
const rawName = template.name || "Component";
|
|
135
|
+
componentName = sanitizeComponentName(rawName);
|
|
136
|
+
componentCode = `
|
|
137
|
+
// Component should be registered via window.__frontmcp_components['${componentName}']
|
|
138
|
+
(function() {
|
|
139
|
+
if (!window.__frontmcp_components || !window.__frontmcp_components['${componentName}']) {
|
|
140
|
+
console.error('[FrontMCP] Component "${componentName}" not registered. Use buildHydrationScript() to register components.');
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
143
|
+
`;
|
|
111
144
|
} else if (typeof template === "string") {
|
|
112
145
|
const transpiled = await this.transpile(template);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Component = await (0, import_renderers.executeTranspiledCode)(transpiled.code, {
|
|
118
|
-
// Provide any additional MDX components if specified
|
|
119
|
-
...options?.mdxComponents
|
|
120
|
-
});
|
|
121
|
-
import_renderers.transpileCache.setByKey(`exec:${transpiled.hash}`, {
|
|
122
|
-
code: Component,
|
|
123
|
-
hash: transpiled.hash,
|
|
124
|
-
cached: false
|
|
125
|
-
});
|
|
126
|
-
}
|
|
146
|
+
const match = transpiled.code.match(/function\s+(\w+)/);
|
|
147
|
+
const rawName = match?.[1] || "Widget";
|
|
148
|
+
componentName = sanitizeComponentName(rawName);
|
|
149
|
+
componentCode = transpiled.code;
|
|
127
150
|
} else {
|
|
128
151
|
throw new Error("Invalid template type for ReactRenderer");
|
|
129
152
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
153
|
+
const html = `
|
|
154
|
+
<div id="${rootId}" data-frontmcp-react data-component="${componentName}" data-props='${escapedProps}'>
|
|
155
|
+
<div class="flex items-center justify-center p-4 text-gray-500">
|
|
156
|
+
<svg class="animate-spin h-5 w-5 mr-2" viewBox="0 0 24 24">
|
|
157
|
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"></circle>
|
|
158
|
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
159
|
+
</svg>
|
|
160
|
+
Loading...
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
<script type="module">
|
|
164
|
+
(function() {
|
|
165
|
+
${componentCode}
|
|
166
|
+
|
|
167
|
+
// Wait for React to be available
|
|
168
|
+
function waitForReact(callback, maxAttempts) {
|
|
169
|
+
var attempts = 0;
|
|
170
|
+
var check = function() {
|
|
171
|
+
if (typeof React !== 'undefined' && typeof ReactDOM !== 'undefined') {
|
|
172
|
+
callback();
|
|
173
|
+
} else if (attempts < maxAttempts) {
|
|
174
|
+
attempts++;
|
|
175
|
+
setTimeout(check, 50);
|
|
176
|
+
} else {
|
|
177
|
+
console.error('[FrontMCP] React not loaded after ' + maxAttempts + ' attempts');
|
|
178
|
+
}
|
|
135
179
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
180
|
+
check();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
waitForReact(function() {
|
|
184
|
+
try {
|
|
185
|
+
var root = document.getElementById('${rootId}');
|
|
186
|
+
if (!root) return;
|
|
187
|
+
|
|
188
|
+
var propsJson = root.getAttribute('data-props');
|
|
189
|
+
var props = propsJson ? JSON.parse(propsJson.replace(/&/g, '&').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>')) : {};
|
|
190
|
+
|
|
191
|
+
// Get the component
|
|
192
|
+
var Component = ${componentName};
|
|
193
|
+
|
|
194
|
+
// Check if it's registered globally
|
|
195
|
+
if (typeof Component === 'undefined' && window.__frontmcp_components) {
|
|
196
|
+
Component = window.__frontmcp_components['${componentName}'];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (typeof Component === 'function') {
|
|
200
|
+
var element = React.createElement(Component, props);
|
|
201
|
+
var reactRoot = ReactDOM.createRoot(root);
|
|
202
|
+
reactRoot.render(element);
|
|
203
|
+
} else {
|
|
204
|
+
console.error('[FrontMCP] Component "${componentName}" not found');
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
console.error('[FrontMCP] React render error:', err);
|
|
142
208
|
}
|
|
143
|
-
|
|
209
|
+
}, 100);
|
|
210
|
+
})();
|
|
211
|
+
</script>
|
|
212
|
+
`;
|
|
213
|
+
return html.trim();
|
|
144
214
|
}
|
|
145
215
|
/**
|
|
146
216
|
* Get runtime scripts for client-side functionality.
|
|
@@ -161,54 +231,8 @@ var ReactRenderer = class {
|
|
|
161
231
|
isInline: false
|
|
162
232
|
};
|
|
163
233
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Load React and ReactDOMServer modules.
|
|
166
|
-
*/
|
|
167
|
-
async loadReact() {
|
|
168
|
-
if (this.React && this.ReactDOMServer) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
this.React = await import("react");
|
|
173
|
-
this.ReactDOMServer = await import("react-dom/server");
|
|
174
|
-
} catch {
|
|
175
|
-
throw new Error("React is required for ReactRenderer. Install react and react-dom: npm install react react-dom");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
234
|
};
|
|
179
235
|
var reactRenderer = new ReactRenderer();
|
|
180
|
-
function buildHydrationScript() {
|
|
181
|
-
return `
|
|
182
|
-
<script>
|
|
183
|
-
(function() {
|
|
184
|
-
// Wait for React to be available
|
|
185
|
-
if (typeof React === 'undefined' || typeof ReactDOM === 'undefined') {
|
|
186
|
-
console.warn('[FrontMCP] React not available for hydration');
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Find all elements marked for hydration
|
|
191
|
-
document.querySelectorAll('[data-hydrate]').forEach(function(root) {
|
|
192
|
-
var componentName = root.getAttribute('data-hydrate');
|
|
193
|
-
var propsJson = root.getAttribute('data-props');
|
|
194
|
-
var props = propsJson ? JSON.parse(propsJson) : {};
|
|
195
|
-
|
|
196
|
-
// Look for the component in the global scope
|
|
197
|
-
if (window.__frontmcp_components && window.__frontmcp_components[componentName]) {
|
|
198
|
-
try {
|
|
199
|
-
ReactDOM.hydrateRoot(root, React.createElement(
|
|
200
|
-
window.__frontmcp_components[componentName],
|
|
201
|
-
props
|
|
202
|
-
));
|
|
203
|
-
} catch (e) {
|
|
204
|
-
console.error('[FrontMCP] Hydration failed for', componentName, e);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
})();
|
|
209
|
-
</script>
|
|
210
|
-
`;
|
|
211
|
-
}
|
|
212
236
|
|
|
213
237
|
// libs/ui/src/renderers/react.adapter.ts
|
|
214
238
|
var mountedRoots = /* @__PURE__ */ new WeakMap();
|
|
@@ -405,12 +429,228 @@ function createReactAdapter() {
|
|
|
405
429
|
async function loadReactAdapter() {
|
|
406
430
|
return createReactAdapter();
|
|
407
431
|
}
|
|
432
|
+
|
|
433
|
+
// libs/ui/src/renderers/mdx.renderer.ts
|
|
434
|
+
var import_renderers2 = require("@frontmcp/uipack/renderers");
|
|
435
|
+
function buildReactCdnUrls(version = "19") {
|
|
436
|
+
return {
|
|
437
|
+
react: `https://esm.sh/react@${version}`,
|
|
438
|
+
reactDom: `https://esm.sh/react-dom@${version}/client`
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var REACT_CDN2 = buildReactCdnUrls("19");
|
|
442
|
+
var INLINE_MDX_PLACEHOLDER = `
|
|
443
|
+
// MDX runtime not available inline yet.
|
|
444
|
+
// For blocked-network platforms, use pre-rendered HTML templates.
|
|
445
|
+
console.warn('[FrontMCP] MDX hydration not available on this platform.');
|
|
446
|
+
`;
|
|
447
|
+
var MdxRenderer = class {
|
|
448
|
+
type = "mdx";
|
|
449
|
+
priority = 10;
|
|
450
|
+
// Between HTML (0) and React (20)
|
|
451
|
+
/**
|
|
452
|
+
* Lazy-loaded modules.
|
|
453
|
+
*/
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
455
|
+
React = null;
|
|
456
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
457
|
+
ReactDOMServer = null;
|
|
458
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
459
|
+
jsxRuntime = null;
|
|
460
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
461
|
+
mdxEvaluate = null;
|
|
462
|
+
/**
|
|
463
|
+
* Check if this renderer can handle the given template.
|
|
464
|
+
*
|
|
465
|
+
* Accepts strings containing MDX syntax (Markdown + JSX).
|
|
466
|
+
*/
|
|
467
|
+
canHandle(template) {
|
|
468
|
+
if (typeof template !== "string") {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
return (0, import_renderers2.containsMdxSyntax)(template);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Prepare MDX template for rendering.
|
|
475
|
+
* Caches the template hash for deduplication. Actual MDX compilation
|
|
476
|
+
* happens during render() via @mdx-js/mdx evaluate().
|
|
477
|
+
*/
|
|
478
|
+
async transpile(template, _options) {
|
|
479
|
+
const hash = (0, import_renderers2.hashString)(template);
|
|
480
|
+
const cached = import_renderers2.transpileCache.getByKey(hash);
|
|
481
|
+
if (cached) {
|
|
482
|
+
return { ...cached, cached: true };
|
|
483
|
+
}
|
|
484
|
+
const transpileResult = {
|
|
485
|
+
code: template,
|
|
486
|
+
hash,
|
|
487
|
+
cached: false
|
|
488
|
+
};
|
|
489
|
+
import_renderers2.transpileCache.setByKey(hash, transpileResult);
|
|
490
|
+
return transpileResult;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Render MDX template to HTML string.
|
|
494
|
+
*
|
|
495
|
+
* Uses @mdx-js/mdx's evaluate() for clean compilation + execution,
|
|
496
|
+
* then renders the resulting React component to HTML via SSR.
|
|
497
|
+
*/
|
|
498
|
+
async render(template, context, options) {
|
|
499
|
+
await this.loadReact();
|
|
500
|
+
await this.loadMdx();
|
|
501
|
+
if (!this.mdxEvaluate) {
|
|
502
|
+
throw new Error("MDX compilation requires @mdx-js/mdx. Install it: npm install @mdx-js/mdx");
|
|
503
|
+
}
|
|
504
|
+
const templateHash = (0, import_renderers2.hashString)(template);
|
|
505
|
+
const cacheKey = `mdx-component:${templateHash}`;
|
|
506
|
+
let Content = import_renderers2.componentCache.get(cacheKey);
|
|
507
|
+
if (!Content) {
|
|
508
|
+
const result = await this.mdxEvaluate(template, {
|
|
509
|
+
...this.jsxRuntime,
|
|
510
|
+
Fragment: this.React.Fragment,
|
|
511
|
+
development: false
|
|
512
|
+
});
|
|
513
|
+
Content = result.default;
|
|
514
|
+
import_renderers2.componentCache.set(cacheKey, Content);
|
|
515
|
+
}
|
|
516
|
+
const mdxComponents = {
|
|
517
|
+
...options?.mdxComponents,
|
|
518
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
519
|
+
wrapper: ({ children }) => {
|
|
520
|
+
return this.React.createElement("div", { className: "mdx-content" }, children);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const props = {
|
|
524
|
+
input: context.input,
|
|
525
|
+
output: context.output,
|
|
526
|
+
structuredContent: context.structuredContent,
|
|
527
|
+
helpers: context.helpers
|
|
528
|
+
};
|
|
529
|
+
const reservedProps = /* @__PURE__ */ new Set(["input", "output", "structuredContent", "helpers", "components"]);
|
|
530
|
+
const outputProps = typeof context.output === "object" && context.output !== null ? Object.fromEntries(Object.entries(context.output).filter(([key]) => !reservedProps.has(key))) : {};
|
|
531
|
+
const spreadProps = {
|
|
532
|
+
...outputProps,
|
|
533
|
+
...props
|
|
534
|
+
};
|
|
535
|
+
const element = this.React.createElement(Content, {
|
|
536
|
+
components: mdxComponents,
|
|
537
|
+
...spreadProps
|
|
538
|
+
});
|
|
539
|
+
const html = this.ReactDOMServer.renderToString(element);
|
|
540
|
+
if (options?.hydrate) {
|
|
541
|
+
const escapedProps = JSON.stringify(props).replace(/&/g, "&").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
542
|
+
return `<div data-mdx-hydrate="true" data-props='${escapedProps}'>${html}</div>`;
|
|
543
|
+
}
|
|
544
|
+
return html;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get runtime scripts for client-side functionality.
|
|
548
|
+
*/
|
|
549
|
+
getRuntimeScripts(platform) {
|
|
550
|
+
if (platform.networkMode === "blocked") {
|
|
551
|
+
return {
|
|
552
|
+
headScripts: "",
|
|
553
|
+
inlineScripts: INLINE_MDX_PLACEHOLDER,
|
|
554
|
+
isInline: true
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
headScripts: `
|
|
559
|
+
<script crossorigin src="${REACT_CDN2.react}"></script>
|
|
560
|
+
<script crossorigin src="${REACT_CDN2.reactDom}"></script>
|
|
561
|
+
`,
|
|
562
|
+
isInline: false
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Load React and ReactDOMServer modules.
|
|
567
|
+
*/
|
|
568
|
+
async loadReact() {
|
|
569
|
+
if (this.React && this.ReactDOMServer && this.jsxRuntime) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
const [react, reactDomServer, jsxRuntime] = await Promise.all([
|
|
574
|
+
import("react"),
|
|
575
|
+
import("react-dom/server"),
|
|
576
|
+
import("react/jsx-runtime")
|
|
577
|
+
]);
|
|
578
|
+
this.React = react;
|
|
579
|
+
this.ReactDOMServer = reactDomServer;
|
|
580
|
+
this.jsxRuntime = jsxRuntime;
|
|
581
|
+
} catch {
|
|
582
|
+
throw new Error("React is required for MdxRenderer. Install react and react-dom: npm install react react-dom");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Load @mdx-js/mdx evaluate function.
|
|
587
|
+
*/
|
|
588
|
+
async loadMdx() {
|
|
589
|
+
if (this.mdxEvaluate) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
try {
|
|
593
|
+
const mdx = await import("@mdx-js/mdx");
|
|
594
|
+
this.mdxEvaluate = mdx.evaluate;
|
|
595
|
+
} catch {
|
|
596
|
+
console.warn(
|
|
597
|
+
"[@frontmcp/ui] @mdx-js/mdx not available. MDX rendering disabled. Install @mdx-js/mdx to enable: npm install @mdx-js/mdx"
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var mdxRenderer = new MdxRenderer();
|
|
603
|
+
|
|
604
|
+
// libs/ui/src/renderers/transpiler.ts
|
|
605
|
+
var import_renderers3 = require("@frontmcp/uipack/renderers");
|
|
606
|
+
async function executeTranspiledCode(code, context = {}) {
|
|
607
|
+
let React;
|
|
608
|
+
let jsxRuntime;
|
|
609
|
+
try {
|
|
610
|
+
React = await import("react");
|
|
611
|
+
jsxRuntime = await import("react/jsx-runtime");
|
|
612
|
+
} catch {
|
|
613
|
+
throw new Error("React is required for JSX templates. Install react: npm install react react-dom");
|
|
614
|
+
}
|
|
615
|
+
const exports2 = {};
|
|
616
|
+
const module2 = { exports: exports2 };
|
|
617
|
+
const require2 = (id) => {
|
|
618
|
+
switch (id) {
|
|
619
|
+
case "react":
|
|
620
|
+
return React;
|
|
621
|
+
case "react/jsx-runtime":
|
|
622
|
+
return jsxRuntime;
|
|
623
|
+
case "react/jsx-dev-runtime":
|
|
624
|
+
return jsxRuntime;
|
|
625
|
+
default:
|
|
626
|
+
if (context[id]) {
|
|
627
|
+
return context[id];
|
|
628
|
+
}
|
|
629
|
+
throw new Error(`Module '${id}' not available in JSX template context`);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
try {
|
|
633
|
+
const fn = new Function("exports", "require", "module", "__filename", "__dirname", "React", "context", code);
|
|
634
|
+
fn(exports2, require2, module2, "template.js", "/", React, context);
|
|
635
|
+
const exportKeys = Object.keys(module2.exports);
|
|
636
|
+
return module2.exports["default"] || (exportKeys.length > 0 ? module2.exports[exportKeys[0]] : null) || module2.exports;
|
|
637
|
+
} catch (error) {
|
|
638
|
+
throw new Error(`Failed to execute transpiled JSX: ${error instanceof Error ? error.message : String(error)}`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
async function transpileAndExecute(source, context = {}) {
|
|
642
|
+
const result = await (0, import_renderers3.transpileJsx)(source);
|
|
643
|
+
return executeTranspiledCode(result.code, context);
|
|
644
|
+
}
|
|
408
645
|
// Annotate the CommonJS export names for ESM import in node:
|
|
409
646
|
0 && (module.exports = {
|
|
647
|
+
MdxRenderer,
|
|
410
648
|
ReactRenderer,
|
|
411
649
|
ReactRendererAdapter,
|
|
412
|
-
buildHydrationScript,
|
|
413
650
|
createReactAdapter,
|
|
651
|
+
executeTranspiledCode,
|
|
414
652
|
loadReactAdapter,
|
|
415
|
-
|
|
653
|
+
mdxRenderer,
|
|
654
|
+
reactRenderer,
|
|
655
|
+
transpileAndExecute
|
|
416
656
|
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX Server Renderer
|
|
3
|
+
*
|
|
4
|
+
* Handles MDX templates - Markdown with embedded JSX components.
|
|
5
|
+
* Uses @mdx-js/mdx for compilation and react-dom/server for SSR.
|
|
6
|
+
*
|
|
7
|
+
* This renderer requires React as a peer dependency.
|
|
8
|
+
* For React-free client-side MDX rendering, use MdxClientRenderer from @frontmcp/uipack.
|
|
9
|
+
*
|
|
10
|
+
* MDX allows mixing Markdown with React components:
|
|
11
|
+
* - Markdown headings, lists, code blocks
|
|
12
|
+
* - JSX component tags: `<Card />`
|
|
13
|
+
* - JS expressions: `{output.items.map(...)}`
|
|
14
|
+
* - Frontmatter for metadata
|
|
15
|
+
*
|
|
16
|
+
* @module @frontmcp/ui/renderers
|
|
17
|
+
*/
|
|
18
|
+
import type { TemplateContext } from '@frontmcp/uipack/runtime';
|
|
19
|
+
import type { PlatformCapabilities } from '@frontmcp/uipack/theme';
|
|
20
|
+
import type { UIRenderer, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts } from '@frontmcp/uipack/renderers';
|
|
21
|
+
/**
|
|
22
|
+
* Types this renderer can handle - MDX strings.
|
|
23
|
+
*/
|
|
24
|
+
type MdxTemplate = string;
|
|
25
|
+
/**
|
|
26
|
+
* MDX Server Renderer Implementation.
|
|
27
|
+
*
|
|
28
|
+
* Compiles MDX (Markdown + JSX) to React components using @mdx-js/mdx,
|
|
29
|
+
* then renders to HTML using react-dom/server.
|
|
30
|
+
*
|
|
31
|
+
* @example Basic MDX template
|
|
32
|
+
* ```typescript
|
|
33
|
+
* @Tool({
|
|
34
|
+
* ui: {
|
|
35
|
+
* template: `
|
|
36
|
+
* # User Profile
|
|
37
|
+
*
|
|
38
|
+
* <UserCard name={output.name} email={output.email} />
|
|
39
|
+
*
|
|
40
|
+
* ## Recent Activity
|
|
41
|
+
* {output.items.map(item => <ActivityItem key={item.id} {...item} />)}
|
|
42
|
+
* `,
|
|
43
|
+
* mdxComponents: { UserCard, ActivityItem }
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class MdxRenderer implements UIRenderer<MdxTemplate> {
|
|
49
|
+
readonly type: "mdx";
|
|
50
|
+
readonly priority = 10;
|
|
51
|
+
/**
|
|
52
|
+
* Lazy-loaded modules.
|
|
53
|
+
*/
|
|
54
|
+
private React;
|
|
55
|
+
private ReactDOMServer;
|
|
56
|
+
private jsxRuntime;
|
|
57
|
+
private mdxEvaluate;
|
|
58
|
+
/**
|
|
59
|
+
* Check if this renderer can handle the given template.
|
|
60
|
+
*
|
|
61
|
+
* Accepts strings containing MDX syntax (Markdown + JSX).
|
|
62
|
+
*/
|
|
63
|
+
canHandle(template: unknown): template is MdxTemplate;
|
|
64
|
+
/**
|
|
65
|
+
* Prepare MDX template for rendering.
|
|
66
|
+
* Caches the template hash for deduplication. Actual MDX compilation
|
|
67
|
+
* happens during render() via @mdx-js/mdx evaluate().
|
|
68
|
+
*/
|
|
69
|
+
transpile(template: MdxTemplate, _options?: TranspileOptions): Promise<TranspileResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Render MDX template to HTML string.
|
|
72
|
+
*
|
|
73
|
+
* Uses @mdx-js/mdx's evaluate() for clean compilation + execution,
|
|
74
|
+
* then renders the resulting React component to HTML via SSR.
|
|
75
|
+
*/
|
|
76
|
+
render<In, Out>(template: MdxTemplate, context: TemplateContext<In, Out>, options?: RenderOptions): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Get runtime scripts for client-side functionality.
|
|
79
|
+
*/
|
|
80
|
+
getRuntimeScripts(platform: PlatformCapabilities): RuntimeScripts;
|
|
81
|
+
/**
|
|
82
|
+
* Load React and ReactDOMServer modules.
|
|
83
|
+
*/
|
|
84
|
+
private loadReact;
|
|
85
|
+
/**
|
|
86
|
+
* Load @mdx-js/mdx evaluate function.
|
|
87
|
+
*/
|
|
88
|
+
private loadMdx;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Singleton instance of the MDX renderer.
|
|
92
|
+
*/
|
|
93
|
+
export declare const mdxRenderer: MdxRenderer;
|
|
94
|
+
/**
|
|
95
|
+
* Build MDX hydration script for client-side interactivity.
|
|
96
|
+
*/
|
|
97
|
+
export declare function buildMdxHydrationScript(): string;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=mdx.renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx.renderer.d.ts","sourceRoot":"","sources":["../../src/renderers/mdx.renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EAEf,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC;AA6B1B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,WAAY,YAAW,UAAU,CAAC,WAAW,CAAC;IACzD,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,QAAQ,MAAM;IAEvB;;OAEG;IAEH,OAAO,CAAC,KAAK,CAAa;IAE1B,OAAO,CAAC,cAAc,CAAa;IAEnC,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,WAAW,CAAiF;IAEpG;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,WAAW;IAQrD;;;;OAIG;IACG,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAmB7F;;;;;OAKG;IACG,MAAM,CAAC,EAAE,EAAE,GAAG,EAClB,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,EACjC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC;IAqFlB;;OAEG;IACH,iBAAiB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,cAAc;IAkBjE;;OAEG;YACW,SAAS;IAoBvB;;OAEG;YACW,OAAO;CAgBtB;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC;AAE7C;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CA2BhD"}
|