@mcpview/compose 0.12.0 → 0.13.1
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/CHANGELOG.md +22 -0
- package/README.md +104 -1
- package/esm/_dnt.polyfills.d.ts +49 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +36 -0
- package/esm/src/code-mode/board.d.ts +21 -1
- package/esm/src/code-mode/board.d.ts.map +1 -1
- package/esm/src/code-mode/board.js +76 -2
- package/esm/src/code-mode/chain.d.ts +2 -0
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +34 -8
- package/esm/src/code-mode/connections.d.ts +1 -0
- package/esm/src/code-mode/connections.d.ts.map +1 -1
- package/esm/src/code-mode/connections.js +1 -0
- package/esm/src/code-mode/layout-publisher.d.ts +69 -0
- package/esm/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/esm/src/code-mode/layout-publisher.js +85 -0
- package/esm/src/code-mode/layout-runs.d.ts +35 -0
- package/esm/src/code-mode/layout-runs.d.ts.map +1 -0
- package/esm/src/code-mode/layout-runs.js +130 -0
- package/esm/src/code-mode/layout.d.ts +20 -0
- package/esm/src/code-mode/layout.d.ts.map +1 -0
- package/esm/src/code-mode/layout.js +54 -0
- package/esm/src/code-mode/mod.d.ts +1 -0
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +1 -0
- package/esm/src/code-mode/panel-contexts.d.ts +25 -0
- package/esm/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/esm/src/code-mode/panel-contexts.js +115 -0
- package/esm/src/code-mode/providers.d.ts +3 -0
- package/esm/src/code-mode/providers.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +2 -1
- package/esm/src/code-mode/sync.d.ts +11 -0
- package/esm/src/code-mode/sync.d.ts.map +1 -0
- package/esm/src/code-mode/sync.js +42 -0
- package/esm/src/code-mode/tool.d.ts +1 -1
- package/esm/src/code-mode/tool.d.ts.map +1 -1
- package/esm/src/code-mode/tool.js +12 -0
- package/esm/src/core/collector/collector.d.ts +2 -1
- package/esm/src/core/collector/collector.d.ts.map +1 -1
- package/esm/src/core/collector/collector.js +6 -0
- package/esm/src/core/types/resources.d.ts +4 -0
- package/esm/src/core/types/resources.d.ts.map +1 -1
- package/esm/src/core/types/resources.js +10 -1
- package/esm/src/host/renderer/css/base.d.ts.map +1 -1
- package/esm/src/host/renderer/css/base.js +3 -0
- package/esm/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/esm/src/host/renderer/css/layouts.js +17 -14
- package/esm/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/css/panel-controls.js +89 -0
- package/esm/src/host/renderer/html-generator.d.ts.map +1 -1
- package/esm/src/host/renderer/html-generator.js +38 -42
- package/esm/src/host/renderer/js/card-height.d.ts +3 -0
- package/esm/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/esm/src/host/renderer/js/card-height.js +58 -0
- package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/esm/src/host/renderer/js/event-bus.js +32 -12
- package/esm/src/host/renderer/panel-controls.d.ts +30 -0
- package/esm/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-controls.js +6 -0
- package/esm/src/host/renderer/panel-movement.d.ts +8 -0
- package/esm/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-movement.js +396 -0
- package/esm/src/host/renderer/panel-reflow.d.ts +17 -0
- package/esm/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-reflow.js +342 -0
- package/esm/src/host/renderer/panel-resizing.d.ts +11 -0
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-resizing.js +375 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-snapshot.js +65 -0
- package/esm/src/runtime/compose.d.ts.map +1 -1
- package/esm/src/runtime/compose.js +3 -0
- package/esm/src/runtime/manifest.d.ts.map +1 -1
- package/esm/src/runtime/manifest.js +4 -0
- package/esm/src/runtime/types.d.ts +2 -0
- package/esm/src/runtime/types.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.d.ts +2 -1
- package/esm/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.js +2 -2
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/_dnt.polyfills.d.ts +49 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +36 -0
- package/script/src/code-mode/board.d.ts +21 -1
- package/script/src/code-mode/board.d.ts.map +1 -1
- package/script/src/code-mode/board.js +87 -3
- package/script/src/code-mode/chain.d.ts +2 -0
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +34 -8
- package/script/src/code-mode/connections.d.ts +1 -0
- package/script/src/code-mode/connections.d.ts.map +1 -1
- package/script/src/code-mode/connections.js +1 -0
- package/script/src/code-mode/layout-publisher.d.ts +69 -0
- package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/script/src/code-mode/layout-publisher.js +88 -0
- package/script/src/code-mode/layout-runs.d.ts +35 -0
- package/script/src/code-mode/layout-runs.d.ts.map +1 -0
- package/script/src/code-mode/layout-runs.js +134 -0
- package/script/src/code-mode/layout.d.ts +20 -0
- package/script/src/code-mode/layout.d.ts.map +1 -0
- package/script/src/code-mode/layout.js +57 -0
- package/script/src/code-mode/mod.d.ts +1 -0
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +6 -1
- package/script/src/code-mode/panel-contexts.d.ts +25 -0
- package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/script/src/code-mode/panel-contexts.js +118 -0
- package/script/src/code-mode/providers.d.ts +3 -0
- package/script/src/code-mode/providers.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +2 -1
- package/script/src/code-mode/sync.d.ts +11 -0
- package/script/src/code-mode/sync.d.ts.map +1 -0
- package/script/src/code-mode/sync.js +51 -0
- package/script/src/code-mode/tool.d.ts +1 -1
- package/script/src/code-mode/tool.d.ts.map +1 -1
- package/script/src/code-mode/tool.js +12 -0
- package/script/src/core/collector/collector.d.ts +2 -1
- package/script/src/core/collector/collector.d.ts.map +1 -1
- package/script/src/core/collector/collector.js +6 -0
- package/script/src/core/types/resources.d.ts +4 -0
- package/script/src/core/types/resources.d.ts.map +1 -1
- package/script/src/core/types/resources.js +11 -0
- package/script/src/host/renderer/css/base.d.ts.map +1 -1
- package/script/src/host/renderer/css/base.js +3 -0
- package/script/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/script/src/host/renderer/css/layouts.js +17 -14
- package/script/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/css/panel-controls.js +92 -0
- package/script/src/host/renderer/html-generator.d.ts.map +1 -1
- package/script/src/host/renderer/html-generator.js +38 -42
- package/script/src/host/renderer/js/card-height.d.ts +3 -0
- package/script/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/script/src/host/renderer/js/card-height.js +61 -0
- package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/script/src/host/renderer/js/event-bus.js +32 -12
- package/script/src/host/renderer/panel-controls.d.ts +30 -0
- package/script/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/panel-controls.js +14 -0
- package/script/src/host/renderer/panel-movement.d.ts +8 -0
- package/script/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/script/src/host/renderer/panel-movement.js +399 -0
- package/script/src/host/renderer/panel-reflow.d.ts +17 -0
- package/script/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/script/src/host/renderer/panel-reflow.js +345 -0
- package/script/src/host/renderer/panel-resizing.d.ts +11 -0
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/script/src/host/renderer/panel-resizing.js +378 -0
- package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/script/src/host/renderer/panel-snapshot.js +69 -0
- package/script/src/runtime/compose.d.ts.map +1 -1
- package/script/src/runtime/compose.js +3 -0
- package/script/src/runtime/manifest.d.ts.map +1 -1
- package/script/src/runtime/manifest.js +4 -0
- package/script/src/runtime/types.d.ts +2 -0
- package/script/src/runtime/types.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.d.ts +2 -1
- package/script/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.js +2 -2
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { validateSyncRules } from "../core/sync/validator.js";
|
|
2
|
+
/** App-only metadata for explicit, receipt-scoped Compose rules. */
|
|
3
|
+
export const SNIPPET_SYNC_META_KEY = "io.mcpview/snippet-sync";
|
|
4
|
+
export function isPortName(value) {
|
|
5
|
+
return typeof value === "string" && value.length > 0 && value.length <= 120 &&
|
|
6
|
+
value.trim() === value && value !== "*";
|
|
7
|
+
}
|
|
8
|
+
export function snippetPorts(events, name) {
|
|
9
|
+
if (!events || !Object.hasOwn(events, name))
|
|
10
|
+
return;
|
|
11
|
+
return readSnippetEventPorts(events[name]);
|
|
12
|
+
}
|
|
13
|
+
export function readSnippetEventPorts(value) {
|
|
14
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
15
|
+
return;
|
|
16
|
+
const ports = value;
|
|
17
|
+
const names = (values) => Array.isArray(values) ? [...new Set(values.filter(isPortName))] : [];
|
|
18
|
+
const emits = names(ports.emits);
|
|
19
|
+
const accepts = names(ports.accepts);
|
|
20
|
+
if (emits.length || accepts.length)
|
|
21
|
+
return { emits, accepts };
|
|
22
|
+
}
|
|
23
|
+
export function parseSnippetSyncRule(value) {
|
|
24
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
25
|
+
return;
|
|
26
|
+
const fields = ["from", "event", "to", "action"];
|
|
27
|
+
if (Object.keys(value).length !== fields.length || !fields.every((key) => Object.hasOwn(value, key))) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const { from, event, to, action } = value;
|
|
31
|
+
if (!isPortName(from) || !isPortName(event) || !isPortName(to) || !isPortName(action))
|
|
32
|
+
return;
|
|
33
|
+
return { from, event, to, action };
|
|
34
|
+
}
|
|
35
|
+
export function supportsSnippetSync(rule, panels) {
|
|
36
|
+
return validateSyncRules([rule], [rule.from, rule.to].filter((id) => panels.has(id))).valid &&
|
|
37
|
+
panels.get(rule.from)?.emits?.includes(rule.event) === true &&
|
|
38
|
+
panels.get(rule.to)?.accepts?.includes(rule.action) === true;
|
|
39
|
+
}
|
|
40
|
+
export function snippetSyncKey({ from, event, to, action }) {
|
|
41
|
+
return JSON.stringify([from, event, to, action]);
|
|
42
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { SnippetProvider } from "./providers.js";
|
|
|
3
3
|
/** Configure the single model-facing tool and its MCP Apps board resource. */
|
|
4
4
|
export interface SnippetExecuteToolOptions {
|
|
5
5
|
readonly resourceUri: string;
|
|
6
|
-
readonly providers: ReadonlyMap<string, Pick<SnippetProvider, "names">>;
|
|
6
|
+
readonly providers: ReadonlyMap<string, Pick<SnippetProvider, "names" | "events">>;
|
|
7
7
|
/** Enable this when the chain uses a catalog and the host supplies a trusted scope. */
|
|
8
8
|
readonly savedChains?: boolean;
|
|
9
9
|
readonly annotations?: MCPTool["annotations"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,8EAA8E;AAC9E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;IACnF,uFAAuF;IACvF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkEpF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { snippetPorts } from "./sync.js";
|
|
1
2
|
import { maxCodeLength } from "./sandbox.js";
|
|
2
3
|
/** Build the tool declaration for registration with an MCPView server. */
|
|
3
4
|
export function createSnippetExecuteTool(options) {
|
|
@@ -6,6 +7,10 @@ export function createSnippetExecuteTool(options) {
|
|
|
6
7
|
throw new Error("Supply a ui:// resource URI for the board.");
|
|
7
8
|
}
|
|
8
9
|
const available = [...options.providers.keys()];
|
|
10
|
+
const eventPorts = [...options.providers].flatMap(([provider, config]) => config.names.flatMap((snippet) => {
|
|
11
|
+
const ports = snippetPorts(config.events, snippet);
|
|
12
|
+
return ports ? [{ provider, snippet, ...ports }] : [];
|
|
13
|
+
}));
|
|
9
14
|
return {
|
|
10
15
|
name: "execute",
|
|
11
16
|
description: [
|
|
@@ -14,6 +19,13 @@ export function createSnippetExecuteTool(options) {
|
|
|
14
19
|
"Configured provider aliases: " + JSON.stringify(available) + ".",
|
|
15
20
|
"await api.runSnippet(provider, name, input) returns a receipt {id, value}.",
|
|
16
21
|
"Pass values between calls. Use await api.panel(receipt.id, optionalTitle) for each result to display, in display order. Return a JSON summary.",
|
|
22
|
+
...(eventPorts.length
|
|
23
|
+
? [
|
|
24
|
+
"After selecting both panels, use await api.sync({from: source.id, event, to: target.id, action}) to route a UI event between them.",
|
|
25
|
+
"Use the source's declared emits and the target's declared accepts. Available panel event ports: " +
|
|
26
|
+
JSON.stringify(eventPorts) + ".",
|
|
27
|
+
]
|
|
28
|
+
: []),
|
|
17
29
|
...(options.savedChains
|
|
18
30
|
? [
|
|
19
31
|
"Use saveAs to save a successful chain, listSaved to list your saved chains, or replay with the saved name and new params.",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module collector/collector
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { type CollectedUiResource } from "../types/resources.js";
|
|
7
7
|
import type { ComponentSurface } from "../types/components.js";
|
|
8
8
|
/**
|
|
9
9
|
* Collector interface for accumulating UI resources from MCP tool results.
|
|
@@ -21,6 +21,7 @@ export interface UiCollector {
|
|
|
21
21
|
collect(toolName: string, result: unknown, context?: Record<string, unknown>, options?: {
|
|
22
22
|
readonly componentId?: string;
|
|
23
23
|
readonly surface?: ComponentSurface;
|
|
24
|
+
readonly supportedWidths?: readonly number[];
|
|
24
25
|
}): CollectedUiResource | null;
|
|
25
26
|
/** Get all collected resources in slot order. */
|
|
26
27
|
getResources(): CollectedUiResource[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../../../src/src/core/collector/collector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../../../src/src/core/collector/collector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,mBAAmB,EAAqB,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B,yFAAyF;IACzF,OAAO,CACL,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;QACpC,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KAC9C,GACA,mBAAmB,GAAG,IAAI,CAAC;IAE9B,iDAAiD;IACjD,YAAY,IAAI,mBAAmB,EAAE,CAAC;IAEtC,iCAAiC;IACjC,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,IAAI,WAAW,CAoC7C"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module collector/collector
|
|
5
5
|
*/
|
|
6
|
+
import { isSupportedWidths } from "../types/resources.js";
|
|
6
7
|
import { extractUiMeta } from "./extractor.js";
|
|
7
8
|
/**
|
|
8
9
|
* Create a new UI resource collector.
|
|
@@ -39,12 +40,17 @@ export function createCollector() {
|
|
|
39
40
|
if (!meta?.resourceUri) {
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
43
|
+
const widths = options?.supportedWidths;
|
|
44
|
+
if (widths !== undefined && !isSupportedWidths(widths)) {
|
|
45
|
+
throw new TypeError("supportedWidths must be an array of positive safe integers");
|
|
46
|
+
}
|
|
42
47
|
const resource = {
|
|
43
48
|
...(options?.componentId === undefined ? {} : { componentId: options.componentId }),
|
|
44
49
|
source: toolName,
|
|
45
50
|
resourceUri: meta.resourceUri,
|
|
46
51
|
context,
|
|
47
52
|
...(options?.surface === undefined ? {} : { surface: options.surface }),
|
|
53
|
+
...(widths === undefined ? {} : { supportedWidths: [...widths] }),
|
|
48
54
|
slot: resources.length,
|
|
49
55
|
};
|
|
50
56
|
resources.push(resource);
|
|
@@ -31,7 +31,11 @@ export interface CollectedUiResource {
|
|
|
31
31
|
context?: Record<string, unknown>;
|
|
32
32
|
/** Optional inner surface assembled from components advertised by this App. */
|
|
33
33
|
surface?: ComponentSurface;
|
|
34
|
+
/** Widths offered by this viewer in CSS pixels. An empty list disables resizing. */
|
|
35
|
+
supportedWidths?: readonly number[];
|
|
34
36
|
/** Slot index (0-based execution order). */
|
|
35
37
|
slot: number;
|
|
36
38
|
}
|
|
39
|
+
/** Whether a Compose width declaration contains only positive whole CSS pixel values. */
|
|
40
|
+
export declare function isSupportedWidths(value: unknown): value is readonly number[];
|
|
37
41
|
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../../src/src/core/types/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IAEf,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC,+EAA+E;IAC/E,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAE3B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../../src/src/core/types/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IAEf,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC,+EAA+E;IAC/E,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAE3B,oFAAoF;IACpF,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,MAAM,EAAE,CAM5E"}
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/** Whether a Compose width declaration contains only positive whole CSS pixel values. */
|
|
2
|
+
export function isSupportedWidths(value) {
|
|
3
|
+
if (!Array.isArray(value))
|
|
4
|
+
return false;
|
|
5
|
+
for (const width of value) {
|
|
6
|
+
if (!Number.isSafeInteger(width) || width <= 0)
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/css/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/css/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,IAAI,MAAM,CA6BnC"}
|
|
@@ -26,6 +26,7 @@ export function getBaseCss() {
|
|
|
26
26
|
--mcc-bg-secondary: #f5f5f5;
|
|
27
27
|
--mcc-bg-primary: #ffffff;
|
|
28
28
|
--mcc-bg-hover: #e8e8e8;
|
|
29
|
+
--mcc-text-secondary: #51565a;
|
|
29
30
|
--mcc-accent-color: #1a73e8;
|
|
30
31
|
}
|
|
31
32
|
body.dark {
|
|
@@ -33,6 +34,7 @@ export function getBaseCss() {
|
|
|
33
34
|
--mcc-bg-secondary: #2a2a2a;
|
|
34
35
|
--mcc-bg-primary: #1a1a1a;
|
|
35
36
|
--mcc-bg-hover: #3a3a3a;
|
|
37
|
+
--mcc-text-secondary: #c2c5c8;
|
|
36
38
|
--mcc-accent-color: #8ab4f8;
|
|
37
39
|
}
|
|
38
40
|
@media (prefers-color-scheme: dark) {
|
|
@@ -41,6 +43,7 @@ export function getBaseCss() {
|
|
|
41
43
|
--mcc-bg-secondary: #2a2a2a;
|
|
42
44
|
--mcc-bg-primary: #1a1a1a;
|
|
43
45
|
--mcc-bg-hover: #3a3a3a;
|
|
46
|
+
--mcc-text-secondary: #c2c5c8;
|
|
44
47
|
--mcc-accent-color: #8ab4f8;
|
|
45
48
|
}
|
|
46
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layouts.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/css/layouts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAA8B,MAAM,+BAA+B,CAAC;AAW1F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"layouts.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/css/layouts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAA8B,MAAM,+BAA+B,CAAC;AAW1F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAqDrD"}
|
|
@@ -42,13 +42,16 @@ export function getLayoutCss(layout) {
|
|
|
42
42
|
switch (preset) {
|
|
43
43
|
case "split":
|
|
44
44
|
return `
|
|
45
|
-
.layout-split {
|
|
46
|
-
|
|
45
|
+
.layout-split {
|
|
46
|
+
display: grid; height: 100vh; gap: 8px;
|
|
47
|
+
grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
|
|
48
|
+
}
|
|
47
49
|
`;
|
|
48
50
|
case "tabs":
|
|
49
51
|
return `
|
|
50
52
|
.layout-tabs { height: 100vh; display: flex; flex-direction: column; }
|
|
51
|
-
.tab-bar { display: flex; border-bottom: 1px solid var(--mcc-border-color); background: var(--mcc-bg-secondary); }
|
|
53
|
+
.tab-bar { display: flex; overflow-x: auto; border-bottom: 1px solid var(--mcc-border-color); background: var(--mcc-bg-secondary); }
|
|
54
|
+
.tab-bar > [data-compose-panel] { display: flex; align-items: center; }
|
|
52
55
|
.tab { padding: 12px 24px; cursor: pointer; border: none; background: transparent; font-size: 14px; color: inherit; }
|
|
53
56
|
.tab:hover { background: var(--mcc-bg-hover); }
|
|
54
57
|
.tab.active { background: var(--mcc-bg-primary); border-bottom: 2px solid var(--mcc-accent-color); }
|
|
@@ -60,20 +63,23 @@ export function getLayoutCss(layout) {
|
|
|
60
63
|
return `
|
|
61
64
|
.layout-grid {
|
|
62
65
|
display: grid;
|
|
63
|
-
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
|
|
66
|
+
grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
|
|
64
67
|
grid-auto-rows: 1fr;
|
|
65
68
|
gap: 8px;
|
|
66
69
|
height: 100vh;
|
|
67
70
|
padding: 8px;
|
|
68
71
|
box-sizing: border-box;
|
|
69
72
|
}
|
|
70
|
-
.layout-grid > iframe { border: 1px solid var(--mcc-border-color); border-radius: 4px; width: 100%; height: 100%; }
|
|
71
73
|
`;
|
|
72
74
|
case "stack":
|
|
73
75
|
return `
|
|
74
|
-
.layout-stack {
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
.layout-stack {
|
|
77
|
+
display: grid; height: 100vh; gap: 8px;
|
|
78
|
+
grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(auto, 1fr);
|
|
79
|
+
}
|
|
80
|
+
.layout-stack > .compose-viewer {
|
|
81
|
+
min-height: var(--compose-native-height, 200px);
|
|
82
|
+
}
|
|
77
83
|
`;
|
|
78
84
|
default: {
|
|
79
85
|
const _exhaustive = preset;
|
|
@@ -118,12 +124,9 @@ function getAreasCss(layout) {
|
|
|
118
124
|
padding: ${gap};
|
|
119
125
|
box-sizing: border-box;
|
|
120
126
|
}
|
|
121
|
-
.layout-areas
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
width: 100%;
|
|
125
|
-
height: 100%;
|
|
126
|
-
}
|
|
127
|
+
${layout.rows ? "" : ` .layout-areas[data-compose-intrinsic] {
|
|
128
|
+
grid-template-rows: repeat(${layout.areas.length}, auto);
|
|
129
|
+
}`}
|
|
127
130
|
${areaStyles}
|
|
128
131
|
`;
|
|
129
132
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-controls.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/css/panel-controls.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,wBAAgB,mBAAmB,IAAI,MAAM,CAuF5C"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Shared styles for the controls around mounted Compose viewers. */
|
|
2
|
+
export function getPanelControlsCss() {
|
|
3
|
+
return `
|
|
4
|
+
[data-compose-board] {
|
|
5
|
+
position: relative;
|
|
6
|
+
--compose-ink: var(--board-muted, var(--mcc-text-secondary, #5b6268));
|
|
7
|
+
--compose-active: var(--board-focus, var(--mcc-accent-color, #286cb7));
|
|
8
|
+
}
|
|
9
|
+
[data-compose-panel] { position: relative; min-width: 0; min-height: 0; }
|
|
10
|
+
.compose-viewer {
|
|
11
|
+
align-self: start;
|
|
12
|
+
height: var(--compose-native-height, 100%);
|
|
13
|
+
}
|
|
14
|
+
#container[data-compose-intrinsic] {
|
|
15
|
+
height: auto;
|
|
16
|
+
align-content: start;
|
|
17
|
+
grid-auto-rows: auto;
|
|
18
|
+
}
|
|
19
|
+
#container[data-compose-intrinsic] > .compose-viewer {
|
|
20
|
+
height: var(--compose-native-height, 200px);
|
|
21
|
+
}
|
|
22
|
+
.compose-viewer > iframe {
|
|
23
|
+
display: block; width: 100%; height: 100%; border: 0;
|
|
24
|
+
}
|
|
25
|
+
button[data-compose-grip] {
|
|
26
|
+
position: absolute; z-index: 4; top: 0; left: 2px;
|
|
27
|
+
display: block; width: 18px; height: 16px;
|
|
28
|
+
margin: 0; padding: 0; border: 0; border-radius: 3px;
|
|
29
|
+
background: transparent; color: var(--compose-ink);
|
|
30
|
+
cursor: grab; touch-action: none; user-select: none;
|
|
31
|
+
}
|
|
32
|
+
button[data-compose-grip][hidden] { display: none; }
|
|
33
|
+
button[data-compose-grip]::before {
|
|
34
|
+
content: ""; position: absolute; top: 4px; left: 8px;
|
|
35
|
+
width: 2px; height: 2px; border-radius: 50%; opacity: 0;
|
|
36
|
+
background: currentColor;
|
|
37
|
+
box-shadow: -4.25px 1.75px, -6px 6px;
|
|
38
|
+
}
|
|
39
|
+
[data-compose-grip]:focus-visible, [data-compose-corner]:focus-visible {
|
|
40
|
+
outline: 2px solid var(--compose-active); outline-offset: -2px;
|
|
41
|
+
}
|
|
42
|
+
[data-compose-moving] [data-compose-grip] { cursor: grabbing; }
|
|
43
|
+
[data-compose-dragging] iframe { pointer-events: none; }
|
|
44
|
+
button[data-compose-corner] {
|
|
45
|
+
position: absolute; z-index: 3; bottom: 0; right: 0; width: 18px; height: 18px;
|
|
46
|
+
padding: 0; margin: 0; min-width: 0; min-height: 0; border: 0; border-radius: 0;
|
|
47
|
+
color: var(--compose-ink); background: transparent; cursor: nwse-resize;
|
|
48
|
+
touch-action: none; user-select: none;
|
|
49
|
+
}
|
|
50
|
+
[data-compose-corner]::after {
|
|
51
|
+
content: ""; position: absolute; bottom: 3px; right: 3px; width: 9px; height: 9px;
|
|
52
|
+
background: linear-gradient(135deg, transparent 43%, currentColor 45% 52%, transparent 54% 68%, currentColor 70% 77%, transparent 79%);
|
|
53
|
+
opacity: 0; pointer-events: none;
|
|
54
|
+
}
|
|
55
|
+
:where([data-compose-panel]:hover) button[data-compose-grip]::before,
|
|
56
|
+
:where([data-compose-panel]:hover) [data-compose-corner]::after { opacity: .4; }
|
|
57
|
+
button[data-compose-grip]:is(:hover, :focus-visible, :active, [aria-pressed="true"])::before,
|
|
58
|
+
[data-compose-corner]:is(:hover, :focus-visible, :active)::after { opacity: 1; color: var(--compose-active); }
|
|
59
|
+
@media (pointer: coarse) {
|
|
60
|
+
button[data-compose-grip] { width: 24px; height: 24px; }
|
|
61
|
+
button[data-compose-corner] { width: 26px; height: 26px; }
|
|
62
|
+
button[data-compose-grip]::before,
|
|
63
|
+
[data-compose-corner]::after { opacity: .5; }
|
|
64
|
+
}
|
|
65
|
+
@media (forced-colors: active) {
|
|
66
|
+
button[data-compose-grip]::before { color: ButtonText; forced-color-adjust: none; }
|
|
67
|
+
[data-compose-corner]::after { color: ButtonText; forced-color-adjust: none; }
|
|
68
|
+
}
|
|
69
|
+
[data-compose-drop-preview] {
|
|
70
|
+
position: absolute; inset: 0; z-index: 5; pointer-events: none; box-sizing: border-box;
|
|
71
|
+
display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px;
|
|
72
|
+
border: 1.5px dashed var(--compose-active); border-radius: inherit;
|
|
73
|
+
background: color-mix(in srgb, var(--board-bg, var(--mcc-bg-primary, Canvas)) 90%, transparent);
|
|
74
|
+
color: color-mix(in srgb, var(--compose-active) 42%, transparent);
|
|
75
|
+
}
|
|
76
|
+
[data-compose-drop-preview]::before, [data-compose-drop-preview]::after {
|
|
77
|
+
content: ""; width: min(36%, 80px); height: 5px; border-radius: 3px; background: currentColor;
|
|
78
|
+
}
|
|
79
|
+
[data-compose-drop-preview]::after { width: min(24%, 54px); }
|
|
80
|
+
.tab-bar [data-compose-drop-preview]::before { width: min(50%, 32px); height: 3px; }
|
|
81
|
+
.tab-bar [data-compose-drop-preview]::after { display: none; }
|
|
82
|
+
@media (forced-colors: active) {
|
|
83
|
+
[data-compose-drop-preview] { border-color: Highlight; background: Canvas; color: GrayText; }
|
|
84
|
+
[data-compose-drop-preview]::before, [data-compose-drop-preview]::after {
|
|
85
|
+
background: GrayText; forced-color-adjust: none;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-generator.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/html-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"html-generator.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/html-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAS5E,OAAO,KAAK,EACV,sBAAsB,EAEtB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAWtB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,qBAAqB,EACjC,OAAO,GAAE,sBAA2B,GACnC,MAAM,CAuCR;AAkGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,qBAAqB,EACjC,OAAO,GAAE,sBAA2B,GACnC,WAAW,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAkClD"}
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module renderer/html-generator
|
|
5
5
|
*/
|
|
6
|
+
import { isSupportedWidths } from "../../core/types/resources.js";
|
|
6
7
|
import { isLayoutAreas } from "../../core/types/layout.js";
|
|
7
8
|
import { getBaseCss } from "./css/base.js";
|
|
8
9
|
import { getLayoutCss } from "./css/layouts.js";
|
|
10
|
+
import { getPanelControlsCss } from "./css/panel-controls.js";
|
|
11
|
+
import { generateCardHeightScript } from "./js/card-height.js";
|
|
9
12
|
import { generateEventBusScript } from "./js/event-bus.js";
|
|
13
|
+
import { createPanelReflow, installPanelMovement, installPanelResizing } from "./panel-controls.js";
|
|
10
14
|
/**
|
|
11
15
|
* Interactive App panels run scripts, but intentionally receive no forms,
|
|
12
16
|
* popups, downloads, or top-level navigation permissions. A local multi-App
|
|
@@ -43,6 +47,13 @@ export function renderComposite(descriptor, options = {}) {
|
|
|
43
47
|
const slots = resolveRendererSlots(descriptor, options);
|
|
44
48
|
const bodyContent = generateBodyContent(descriptor, slots);
|
|
45
49
|
const eventBusScript = generateEventBusScript(descriptor, slots);
|
|
50
|
+
const panelScript = descriptor.children.length === 0 ? "" : `
|
|
51
|
+
const board = document.querySelector('[data-compose-board]');
|
|
52
|
+
(${installPanelMovement})(board);
|
|
53
|
+
${descriptor.layout === "tabs"
|
|
54
|
+
? ""
|
|
55
|
+
: `(${installPanelResizing})(board, undefined, (${createPanelReflow}));`}
|
|
56
|
+
`;
|
|
46
57
|
return `<!DOCTYPE html>
|
|
47
58
|
<html>
|
|
48
59
|
<head>
|
|
@@ -54,51 +65,41 @@ export function renderComposite(descriptor, options = {}) {
|
|
|
54
65
|
body { font-family: system-ui, -apple-system, sans-serif; background: var(--mcc-bg-primary); color: inherit; }
|
|
55
66
|
${baseCss}
|
|
56
67
|
${layoutCss}
|
|
68
|
+
${getPanelControlsCss()}
|
|
57
69
|
</style>
|
|
58
70
|
</head>
|
|
59
71
|
<body>
|
|
60
72
|
${bodyContent}
|
|
61
73
|
<script>
|
|
62
74
|
${eventBusScript}
|
|
75
|
+
${panelScript}
|
|
76
|
+
${descriptor.layout === "tabs" ? "" : generateCardHeightScript()}
|
|
63
77
|
</script>
|
|
64
78
|
</body>
|
|
65
79
|
</html>`;
|
|
66
80
|
}
|
|
67
81
|
function generateBodyContent(descriptor, slots) {
|
|
68
|
-
if (isLayoutAreas(descriptor.layout)) {
|
|
69
|
-
return generateAreasLayout(descriptor, slots);
|
|
70
|
-
}
|
|
71
82
|
if (descriptor.layout === "tabs") {
|
|
72
83
|
return generateTabsLayout(descriptor, slots);
|
|
73
84
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
const layout = isLayoutAreas(descriptor.layout) ? "areas" : descriptor.layout;
|
|
86
|
+
const panels = descriptor.children.map((child) => {
|
|
87
|
+
const id = child.componentId ?? child.source;
|
|
88
|
+
const area = layout === "areas"
|
|
89
|
+
? ` data-area="${escapeAttr(descriptor.areaMap?.[id] ?? id)}"`
|
|
90
|
+
: "";
|
|
91
|
+
const widths = isSupportedWidths(child.supportedWidths) && child.supportedWidths.length
|
|
92
|
+
? ` data-compose-widths="${child.supportedWidths.join(" ")}"`
|
|
93
|
+
: "";
|
|
94
|
+
return `<section class="compose-viewer" data-compose-panel data-compose-panel-id="${escapeAttr(id)}" data-panel-label="${escapeAttr(id)}"${area}${widths}>
|
|
95
|
+
${descriptor.children.length > 1 ? grip(child) : ""}
|
|
96
|
+
${generateIframe(child, slots.get(child.slot))}
|
|
97
|
+
</section>`;
|
|
98
|
+
});
|
|
99
|
+
return `<div class="layout-${layout}" id="container" data-compose-board>${panels.join("\n")}</div>`;
|
|
80
100
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
const iframesHtml = descriptor.children
|
|
84
|
-
.map((child) => {
|
|
85
|
-
const componentId = child.componentId ?? child.source;
|
|
86
|
-
const area = areaMap[componentId] ?? componentId;
|
|
87
|
-
const slot = slots.get(child.slot);
|
|
88
|
-
return `<iframe
|
|
89
|
-
id="ui-${child.slot}"
|
|
90
|
-
src="${escapeAttr(slot?.iframeSrc ?? child.resourceUri)}"
|
|
91
|
-
data-slot="${child.slot}"
|
|
92
|
-
data-source="${escapeAttr(child.source)}"
|
|
93
|
-
data-component-id="${escapeAttr(componentId)}"
|
|
94
|
-
data-area="${escapeAttr(area)}"
|
|
95
|
-
${generateSandboxAttribute(slot)}
|
|
96
|
-
></iframe>`;
|
|
97
|
-
})
|
|
98
|
-
.join("\n ");
|
|
99
|
-
return `<div class="layout-areas" id="container">
|
|
100
|
-
${iframesHtml}
|
|
101
|
-
</div>`;
|
|
101
|
+
function grip(child) {
|
|
102
|
+
return `<button type="button" data-compose-grip aria-label="Move ${escapeAttr(child.componentId ?? child.source)}"></button>`;
|
|
102
103
|
}
|
|
103
104
|
function generateTabsLayout(descriptor, slots) {
|
|
104
105
|
if (descriptor.children.length === 0) {
|
|
@@ -110,21 +111,15 @@ function generateTabsLayout(descriptor, slots) {
|
|
|
110
111
|
</div>`;
|
|
111
112
|
}
|
|
112
113
|
const tabButtons = descriptor.children
|
|
113
|
-
.map((child, i) => `<
|
|
114
|
+
.map((child, i) => `<div data-compose-panel data-compose-panel-id="${escapeAttr(child.componentId ?? child.source)}" data-panel-label="${escapeAttr(child.componentId ?? child.source)}">
|
|
115
|
+
${descriptor.children.length > 1 ? grip(child) : ""}
|
|
116
|
+
<button type="button" class="tab${i === 0 ? " active" : ""}" data-slot="${child.slot}">${escapeHtml(child.source)}</button></div>`)
|
|
114
117
|
.join("\n ");
|
|
115
118
|
const iframesHtml = descriptor.children
|
|
116
|
-
.map((child, i) =>
|
|
117
|
-
id="ui-${child.slot}"
|
|
118
|
-
class="${i === 0 ? "active" : ""}"
|
|
119
|
-
src="${escapeAttr(slots.get(child.slot)?.iframeSrc ?? child.resourceUri)}"
|
|
120
|
-
data-slot="${child.slot}"
|
|
121
|
-
data-source="${escapeAttr(child.source)}"
|
|
122
|
-
data-component-id="${escapeAttr(child.componentId ?? child.source)}"
|
|
123
|
-
${generateSandboxAttribute(slots.get(child.slot))}
|
|
124
|
-
></iframe>`)
|
|
119
|
+
.map((child, i) => generateIframe(child, slots.get(child.slot), i === 0))
|
|
125
120
|
.join("\n ");
|
|
126
121
|
return `<div class="layout-tabs" id="container">
|
|
127
|
-
<div class="tab-bar">
|
|
122
|
+
<div class="tab-bar" data-compose-board>
|
|
128
123
|
${tabButtons}
|
|
129
124
|
</div>
|
|
130
125
|
<div class="tab-content">
|
|
@@ -132,9 +127,10 @@ ${generateSandboxAttribute(slots.get(child.slot))}
|
|
|
132
127
|
</div>
|
|
133
128
|
</div>`;
|
|
134
129
|
}
|
|
135
|
-
function generateIframe(child, slot) {
|
|
130
|
+
function generateIframe(child, slot, active = false) {
|
|
136
131
|
return `<iframe
|
|
137
132
|
id="ui-${child.slot}"
|
|
133
|
+
title="${escapeAttr(child.source)}"${active ? ' class="active"' : ""}
|
|
138
134
|
src="${escapeAttr(slot?.iframeSrc ?? child.resourceUri)}"
|
|
139
135
|
data-slot="${child.slot}"
|
|
140
136
|
data-source="${escapeAttr(child.source)}"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-height.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/js/card-height.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,wBAAgB,wBAAwB,IAAI,MAAM,CAuDjD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { COMPOSE_VERSION, MCP_APPS_PROTOCOL_VERSION } from "../../../version.js";
|
|
2
|
+
/** Connect the generated dashboard to its enclosing MCP Apps host as an App. */
|
|
3
|
+
export function generateCardHeightScript() {
|
|
4
|
+
return `
|
|
5
|
+
(() => {
|
|
6
|
+
const host = window.parent;
|
|
7
|
+
if (!host || host === window) return;
|
|
8
|
+
const board = document.querySelector('#container[data-compose-board]');
|
|
9
|
+
if (!board) return;
|
|
10
|
+
board.setAttribute('data-compose-intrinsic', '');
|
|
11
|
+
|
|
12
|
+
const initializeId = 'compose-card-initialize';
|
|
13
|
+
const protocolVersion = '${MCP_APPS_PROTOCOL_VERSION}';
|
|
14
|
+
let hostOrigin;
|
|
15
|
+
let lastHeight;
|
|
16
|
+
const send = (message) => host.postMessage(
|
|
17
|
+
{ jsonrpc: '2.0', ...message }, hostOrigin && hostOrigin !== 'null' ? hostOrigin : '*'
|
|
18
|
+
);
|
|
19
|
+
function reportHeight() {
|
|
20
|
+
// The viewport still has the previous height while a row disappears.
|
|
21
|
+
// The grid's border box includes the skeleton, row gaps and padding.
|
|
22
|
+
const height = Math.ceil(board.getBoundingClientRect().height);
|
|
23
|
+
if (!Number.isFinite(height) || height < 0 || height === lastHeight) return;
|
|
24
|
+
if (hostOrigin !== undefined) {
|
|
25
|
+
send({ method: 'ui/notifications/size-changed', params: { height } });
|
|
26
|
+
} else if (typeof window.openai?.notifyIntrinsicHeight === 'function') {
|
|
27
|
+
window.openai.notifyIntrinsicHeight(height);
|
|
28
|
+
} else {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
lastHeight = height;
|
|
32
|
+
}
|
|
33
|
+
const observer = new ResizeObserver(reportHeight);
|
|
34
|
+
function onHostMessage(event) {
|
|
35
|
+
const msg = event.data;
|
|
36
|
+
if (event.source !== host || msg?.jsonrpc !== '2.0') return;
|
|
37
|
+
if (hostOrigin === undefined) {
|
|
38
|
+
if (msg.id !== initializeId || msg.result?.protocolVersion !== protocolVersion) return;
|
|
39
|
+
hostOrigin = event.origin;
|
|
40
|
+
send({ method: 'ui/notifications/initialized' });
|
|
41
|
+
lastHeight = undefined;
|
|
42
|
+
reportHeight();
|
|
43
|
+
} else if (event.origin === hostOrigin && msg.method === 'ui/resource-teardown' && msg.id != null) {
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
window.removeEventListener('message', onHostMessage);
|
|
46
|
+
window.removeEventListener('openai:set_globals', reportHeight);
|
|
47
|
+
send({ id: msg.id, result: {} });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
window.addEventListener('message', onHostMessage);
|
|
51
|
+
window.addEventListener('openai:set_globals', reportHeight);
|
|
52
|
+
observer.observe(board, { box: 'border-box' });
|
|
53
|
+
send({ id: initializeId, method: 'ui/initialize', params: {
|
|
54
|
+
appInfo: { name: 'mcp-compose', version: '${COMPOSE_VERSION}' },
|
|
55
|
+
appCapabilities: {}, protocolVersion
|
|
56
|
+
} });
|
|
57
|
+
})();`;
|
|
58
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/js/event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG/E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAMjE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,qBAAqB,EACjC,KAAK,GAAE,WAAW,CAAC,MAAM,EAAE,2BAA2B,CAAa,GAClE,MAAM,
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/js/event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG/E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAMjE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,qBAAqB,EACjC,KAAK,GAAE,WAAW,CAAC,MAAM,EAAE,2BAA2B,CAAa,GAClE,MAAM,CAujBR"}
|