@mcpview/compose 0.13.1 → 0.14.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +53 -0
  3. package/esm/src/code-mode/chain.d.ts +24 -1
  4. package/esm/src/code-mode/chain.d.ts.map +1 -1
  5. package/esm/src/code-mode/chain.js +219 -86
  6. package/esm/src/code-mode/errors.d.ts +80 -0
  7. package/esm/src/code-mode/errors.d.ts.map +1 -0
  8. package/esm/src/code-mode/errors.js +140 -0
  9. package/esm/src/code-mode/guest-worker.d.ts +11 -0
  10. package/esm/src/code-mode/guest-worker.d.ts.map +1 -0
  11. package/esm/src/code-mode/guest-worker.js +80 -0
  12. package/esm/src/code-mode/mod.d.ts +3 -1
  13. package/esm/src/code-mode/mod.d.ts.map +1 -1
  14. package/esm/src/code-mode/mod.js +2 -0
  15. package/esm/src/code-mode/sandbox-core.d.ts +61 -0
  16. package/esm/src/code-mode/sandbox-core.d.ts.map +1 -0
  17. package/esm/src/code-mode/sandbox-core.js +424 -0
  18. package/esm/src/code-mode/sandbox.d.ts +68 -7
  19. package/esm/src/code-mode/sandbox.d.ts.map +1 -1
  20. package/esm/src/code-mode/sandbox.js +182 -120
  21. package/esm/src/code-mode/tool.d.ts.map +1 -1
  22. package/esm/src/code-mode/tool.js +2 -0
  23. package/esm/src/code-mode/worker-host.d.ts +82 -0
  24. package/esm/src/code-mode/worker-host.d.ts.map +1 -0
  25. package/esm/src/code-mode/worker-host.js +364 -0
  26. package/esm/src/code-mode/worker-protocol.d.ts +44 -0
  27. package/esm/src/code-mode/worker-protocol.d.ts.map +1 -0
  28. package/esm/src/code-mode/worker-protocol.js +7 -0
  29. package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -1
  30. package/esm/src/host/renderer/css/panel-controls.js +5 -1
  31. package/esm/src/host/renderer/js/card-height.d.ts +11 -1
  32. package/esm/src/host/renderer/js/card-height.d.ts.map +1 -1
  33. package/esm/src/host/renderer/js/card-height.js +57 -10
  34. package/esm/src/host/renderer/js/event-bus.d.ts +11 -0
  35. package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
  36. package/esm/src/host/renderer/js/event-bus.js +49 -8
  37. package/esm/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
  38. package/esm/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
  39. package/esm/src/host/renderer/js/intrinsic-layout.js +44 -0
  40. package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -1
  41. package/esm/src/host/renderer/panel-resizing.js +8 -0
  42. package/esm/src/version.d.ts +1 -1
  43. package/esm/src/version.js +1 -1
  44. package/package.json +1 -1
  45. package/script/src/code-mode/chain.d.ts +24 -1
  46. package/script/src/code-mode/chain.d.ts.map +1 -1
  47. package/script/src/code-mode/chain.js +218 -85
  48. package/script/src/code-mode/errors.d.ts +80 -0
  49. package/script/src/code-mode/errors.d.ts.map +1 -0
  50. package/script/src/code-mode/errors.js +148 -0
  51. package/script/src/code-mode/guest-worker.d.ts +11 -0
  52. package/script/src/code-mode/guest-worker.d.ts.map +1 -0
  53. package/script/src/code-mode/guest-worker.js +105 -0
  54. package/script/src/code-mode/mod.d.ts +3 -1
  55. package/script/src/code-mode/mod.d.ts.map +1 -1
  56. package/script/src/code-mode/mod.js +9 -1
  57. package/script/src/code-mode/sandbox-core.d.ts +61 -0
  58. package/script/src/code-mode/sandbox-core.d.ts.map +1 -0
  59. package/script/src/code-mode/sandbox-core.js +430 -0
  60. package/script/src/code-mode/sandbox.d.ts +68 -7
  61. package/script/src/code-mode/sandbox.d.ts.map +1 -1
  62. package/script/src/code-mode/sandbox.js +190 -122
  63. package/script/src/code-mode/tool.d.ts.map +1 -1
  64. package/script/src/code-mode/tool.js +2 -0
  65. package/script/src/code-mode/worker-host.d.ts +82 -0
  66. package/script/src/code-mode/worker-host.d.ts.map +1 -0
  67. package/script/src/code-mode/worker-host.js +399 -0
  68. package/script/src/code-mode/worker-protocol.d.ts +44 -0
  69. package/script/src/code-mode/worker-protocol.d.ts.map +1 -0
  70. package/script/src/code-mode/worker-protocol.js +8 -0
  71. package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -1
  72. package/script/src/host/renderer/css/panel-controls.js +5 -1
  73. package/script/src/host/renderer/js/card-height.d.ts +11 -1
  74. package/script/src/host/renderer/js/card-height.d.ts.map +1 -1
  75. package/script/src/host/renderer/js/card-height.js +57 -10
  76. package/script/src/host/renderer/js/event-bus.d.ts +11 -0
  77. package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
  78. package/script/src/host/renderer/js/event-bus.js +50 -8
  79. package/script/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
  80. package/script/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
  81. package/script/src/host/renderer/js/intrinsic-layout.js +48 -0
  82. package/script/src/host/renderer/panel-resizing.d.ts.map +1 -1
  83. package/script/src/host/renderer/panel-resizing.js +8 -0
  84. package/script/src/version.d.ts +1 -1
  85. package/script/src/version.js +1 -1
@@ -12,10 +12,23 @@
12
12
  * @module renderer/js/event-bus
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MAX_VIEWER_HEIGHT = void 0;
15
16
  exports.generateEventBusScript = generateEventBusScript;
16
17
  const compose_events_js_1 = require("../../../sdk/compose-events.js");
17
18
  const version_js_1 = require("../../../version.js");
18
19
  const components_contract_js_1 = require("../../components-contract.js");
20
+ const intrinsic_layout_js_1 = require("./intrinsic-layout.js");
21
+ /**
22
+ * Tallest height, in CSS pixels, a viewer can claim with
23
+ * `ui/notifications/size-changed`. Taller content scrolls inside the viewer's
24
+ * iframe. Advertised to each viewer as `containerDimensions.maxHeight`.
25
+ *
26
+ * The cap also bounds a viewer whose content follows its own iframe
27
+ * (`min-height: 100vh` plus padding): it stops growing here. Compose does not
28
+ * guess such loops from equal increments, which a list gaining rows produces
29
+ * too.
30
+ */
31
+ exports.MAX_VIEWER_HEIGHT = 2_400;
19
32
  /**
20
33
  * Generate the event bus JavaScript for a composite UI.
21
34
  *
@@ -71,6 +84,31 @@ function generateEventBusScript(descriptor, slots = new Map()) {
71
84
  const lastHostContexts = new Map();
72
85
  const COMPONENT_CAPABILITY = '${components_contract_js_1.CASYS_COMPONENT_CATALOG_CAPABILITY_KEY}';
73
86
  const SURFACE_CONTEXT = '${components_contract_js_1.CASYS_SURFACE_CONTEXT_KEY}';
87
+ const MAX_VIEWER_HEIGHT = ${exports.MAX_VIEWER_HEIGHT};
88
+ // Viewers already warned about the cap.
89
+ const cappedViewers = new Set();
90
+ ${(0, intrinsic_layout_js_1.generateIntrinsicLayoutFunction)()}
91
+
92
+ // Viewer reports apply at once, as for any embed. Only an enclosing host
93
+ // that explicitly refused ui/initialize marks the board as refused: it
94
+ // fills its frame again and later reports no longer size it.
95
+ function handleViewerReport(slot, reported) {
96
+ const panel = iframes.get(slot)?.closest?.('.compose-viewer');
97
+ if (!panel) return;
98
+ const board = panel.parentElement;
99
+ if (board?.hasAttribute?.('data-compose-card-refused')) return;
100
+ const wanted = Math.ceil(reported);
101
+ if (wanted > MAX_VIEWER_HEIGHT && !cappedViewers.has(slot)) {
102
+ cappedViewers.add(slot);
103
+ console.warn('[mcp-compose] Viewer height capped', {
104
+ code: 'VIEWER_HEIGHT_CAPPED', slot, reported: wanted, max: MAX_VIEWER_HEIGHT
105
+ });
106
+ }
107
+ enterIntrinsicLayout(board);
108
+ panel.style.setProperty(
109
+ '--compose-native-height', Math.min(MAX_VIEWER_HEIGHT, wanted) + 'px'
110
+ );
111
+ }
74
112
 
75
113
  // Build slot -> iframe map + reverse lookup. The fallback lookup matters
76
114
  // when the iframe's WindowProxy becomes available after this script runs.
@@ -167,7 +205,7 @@ function generateEventBusScript(descriptor, slots = new Map()) {
167
205
  const panel = iframe.closest?.('.compose-viewer');
168
206
  // A fixed height in the handshake makes responsive Apps stretch to the
169
207
  // track before they can report the height of their own content.
170
- if (panel) return { width };
208
+ if (panel) return { width, maxHeight: MAX_VIEWER_HEIGHT };
171
209
  return { width, height };
172
210
  }
173
211
 
@@ -499,6 +537,10 @@ function generateEventBusScript(descriptor, slots = new Map()) {
499
537
  ];
500
538
  const catalog = validComponentCatalog(advertisedCatalog);
501
539
  if (catalog) componentCatalogs.set(sourceSlot, catalog);
540
+ // A reloaded viewer starts a new document: forget its height history,
541
+ // including the height the previous document reported. The captured
542
+ // template height stays as the fallback.
543
+ cappedViewers.delete(sourceSlot);
502
544
  const hostContext = hostContextForSlot(sourceSlot);
503
545
  lastHostContexts.set(sourceSlot, JSON.stringify(hostContext));
504
546
  respond(event.source, message.id, {
@@ -543,13 +585,13 @@ function generateEventBusScript(descriptor, slots = new Map()) {
543
585
  }
544
586
 
545
587
  if (message.method === 'ui/notifications/size-changed') {
546
- const height = message.params?.height;
547
- if (initializationResponded.has(sourceSlot) && Number.isFinite(height) && height > 0) {
548
- // Width belongs to the board. Only the child can measure its own document.
549
- const panel = iframes.get(sourceSlot)?.closest?.('.compose-viewer');
550
- panel?.style.setProperty('--compose-native-height', Math.ceil(height) + 'px');
551
- panel?.parentElement?.setAttribute('data-compose-intrinsic', '');
552
- }
588
+ const reported = message.params?.height;
589
+ // Width belongs to the board. Only the child can measure its own document.
590
+ const panel = iframes.get(sourceSlot)?.closest?.('.compose-viewer');
591
+ if (
592
+ panel && initializationResponded.has(sourceSlot) &&
593
+ Number.isFinite(reported) && reported > 0
594
+ ) handleViewerReport(sourceSlot, reported);
553
595
  ackIfRequested(event.source, message, targetOrigin);
554
596
  return;
555
597
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Browser helper shared by the event bus and the card-height bridge.
3
+ *
4
+ * In intrinsic mode a board sizes its rows from its viewers instead of filling
5
+ * the viewport. A viewer that reports its height through
6
+ * `ui/notifications/size-changed` gets it as `--compose-native-height`. A
7
+ * viewer that never reports keeps the height its template track gave it when
8
+ * the board switched (`--compose-template-height`), and never less than
9
+ * {@link VIEWER_FALLBACK_HEIGHT}.
10
+ *
11
+ * @module renderer/js/intrinsic-layout
12
+ */
13
+ /** Height, in CSS pixels, of a viewer that has not reported its own. */
14
+ export declare const VIEWER_FALLBACK_HEIGHT = 200;
15
+ /**
16
+ * Source of `enterIntrinsicLayout(board)`, to embed in a generated script.
17
+ * The function is idempotent: once the board is intrinsic, it does nothing.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const script = `${generateIntrinsicLayoutFunction()}
22
+ * enterIntrinsicLayout(document.querySelector('[data-compose-board]'));`;
23
+ * ```
24
+ */
25
+ export declare function generateIntrinsicLayoutFunction(): string;
26
+ //# sourceMappingURL=intrinsic-layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intrinsic-layout.d.ts","sourceRoot":"","sources":["../../../../../src/src/host/renderer/js/intrinsic-layout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,CAmBxD"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Browser helper shared by the event bus and the card-height bridge.
4
+ *
5
+ * In intrinsic mode a board sizes its rows from its viewers instead of filling
6
+ * the viewport. A viewer that reports its height through
7
+ * `ui/notifications/size-changed` gets it as `--compose-native-height`. A
8
+ * viewer that never reports keeps the height its template track gave it when
9
+ * the board switched (`--compose-template-height`), and never less than
10
+ * {@link VIEWER_FALLBACK_HEIGHT}.
11
+ *
12
+ * @module renderer/js/intrinsic-layout
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.VIEWER_FALLBACK_HEIGHT = void 0;
16
+ exports.generateIntrinsicLayoutFunction = generateIntrinsicLayoutFunction;
17
+ /** Height, in CSS pixels, of a viewer that has not reported its own. */
18
+ exports.VIEWER_FALLBACK_HEIGHT = 200;
19
+ /**
20
+ * Source of `enterIntrinsicLayout(board)`, to embed in a generated script.
21
+ * The function is idempotent: once the board is intrinsic, it does nothing.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const script = `${generateIntrinsicLayoutFunction()}
26
+ * enterIntrinsicLayout(document.querySelector('[data-compose-board]'));`;
27
+ * ```
28
+ */
29
+ function generateIntrinsicLayoutFunction() {
30
+ return `
31
+ function enterIntrinsicLayout(board) {
32
+ if (!board || board.hasAttribute('data-compose-intrinsic')) return;
33
+ // Measure before switching: afterwards the tracks follow their content.
34
+ for (const viewer of Array.from(board.children ?? [])) {
35
+ if (!viewer.classList?.contains('compose-viewer')) continue;
36
+ if (viewer.style.getPropertyValue('--compose-native-height')) continue;
37
+ const height = Math.ceil(viewer.getBoundingClientRect().height);
38
+ if (height > ${exports.VIEWER_FALLBACK_HEIGHT}) {
39
+ viewer.style.setProperty('--compose-template-height', height + 'px');
40
+ }
41
+ }
42
+ board.setAttribute('data-compose-intrinsic', '');
43
+ // Placements committed before the switch hold fixed row minimums.
44
+ if (typeof board.dispatchEvent === 'function') {
45
+ board.dispatchEvent(new Event('compose-layout-intrinsic'));
46
+ }
47
+ }`;
48
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"panel-resizing.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-resizing.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,gDAJW,WAAW,+FAoXrB;kCA1XiC,mBAAmB"}
1
+ {"version":3,"file":"panel-resizing.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-resizing.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,gDAJW,WAAW,+FA0XrB;kCAhYiC,mBAAmB"}
@@ -288,6 +288,14 @@ function installPanelResizing(container, signal, createReflow = panel_reflow_js_
288
288
  place();
289
289
  schedule();
290
290
  }, { signal });
291
+ // Entering intrinsic layout drops the row floors of committed placements.
292
+ container.addEventListener("compose-layout-intrinsic", () => {
293
+ if (projectDrag)
294
+ projectDrag();
295
+ else
296
+ place();
297
+ schedule();
298
+ }, { signal });
291
299
  container.addEventListener("compose-layout-change", () => {
292
300
  placements = placementsAfterSwap();
293
301
  manualPreview = undefined;
@@ -17,7 +17,7 @@
17
17
  * @module lib/version
18
18
  */
19
19
  /** @mcpview/compose package version. */
20
- export declare const COMPOSE_VERSION: "0.13.1";
20
+ export declare const COMPOSE_VERSION: "0.14.1";
21
21
  /**
22
22
  * MCP Apps protocol version targeted by compose.
23
23
  *
@@ -20,7 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.MCP_APPS_PROTOCOL_VERSION = exports.COMPOSE_VERSION = void 0;
22
22
  /** @mcpview/compose package version. */
23
- exports.COMPOSE_VERSION = "0.13.1";
23
+ exports.COMPOSE_VERSION = "0.14.1";
24
24
  /**
25
25
  * MCP Apps protocol version targeted by compose.
26
26
  *