@altertable/data-app 0.64.0 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/AGENTS.md +40 -0
  2. package/CONTRIBUTING.md +37 -3
  3. package/README.md +2 -2
  4. package/dist/chunks/{contract-mwe7gnmh.js → contract-13j5zb3c.js} +110 -216
  5. package/dist/chunks/contract-13j5zb3c.js.map +13 -0
  6. package/dist/chunks/contract-19ckn3n7.js +78 -0
  7. package/dist/chunks/contract-19ckn3n7.js.map +10 -0
  8. package/dist/chunks/contract-awa2d5b1.js +272 -0
  9. package/dist/chunks/contract-awa2d5b1.js.map +12 -0
  10. package/dist/chunks/{contract-xtxza1fy.js → contract-e11m4y7f.js} +35 -71
  11. package/dist/chunks/contract-e11m4y7f.js.map +12 -0
  12. package/dist/chunks/{contract-zr3jd7mr.js → contract-h8a6f559.js} +100 -75
  13. package/dist/chunks/contract-h8a6f559.js.map +12 -0
  14. package/dist/chunks/contract-havnjmdr.js +13011 -0
  15. package/dist/chunks/contract-havnjmdr.js.map +99 -0
  16. package/dist/chunks/{contract-txjy0en2.js → contract-m6n8ctfc.js} +64 -72
  17. package/dist/chunks/contract-m6n8ctfc.js.map +10 -0
  18. package/dist/chunks/contract-pk603qj7.js +146 -0
  19. package/dist/chunks/contract-pk603qj7.js.map +10 -0
  20. package/dist/chunks/{contract-yxbjea23.js → contract-rfbakka4.js} +179 -2
  21. package/dist/chunks/contract-rfbakka4.js.map +13 -0
  22. package/dist/client/index.js +11 -6
  23. package/dist/client/index.js.map +1 -1
  24. package/dist/core/appearance.js +1 -1
  25. package/dist/core/contract.js +13 -3
  26. package/dist/core/contract.js.map +1 -1
  27. package/dist/embed/index.js +25 -13
  28. package/dist/embed/index.js.map +3 -3
  29. package/dist/local.js +1 -1
  30. package/dist/local.js.map +2 -2
  31. package/dist/react/embed/index.js +5 -2
  32. package/dist/react/embed/index.js.map +3 -3
  33. package/dist/react/index.js +2532 -11273
  34. package/dist/react/index.js.map +16 -88
  35. package/dist/react/ui/index.js +1614 -0
  36. package/dist/react/ui/index.js.map +22 -0
  37. package/dist/server.js +1 -1
  38. package/dist/server.js.map +2 -2
  39. package/dist/types/client/annotations.d.ts +23 -0
  40. package/dist/types/client/iframe.d.ts +2 -0
  41. package/dist/types/client/index.d.ts +2 -0
  42. package/dist/types/client/logger.d.ts +6 -0
  43. package/dist/types/core/annotations.d.ts +92 -0
  44. package/dist/types/core/appearance.d.ts +2 -2
  45. package/dist/types/core/bridge-endpoint.d.ts +21 -0
  46. package/dist/types/core/bridge.d.ts +137 -16
  47. package/dist/types/core/contract.d.ts +2 -0
  48. package/dist/types/core/logger.d.ts +12 -0
  49. package/dist/types/core/presentation.d.ts +2 -0
  50. package/dist/types/core/variables.d.ts +2 -5
  51. package/dist/types/embed/host.d.ts +6 -2
  52. package/dist/types/embed/index.d.ts +1 -0
  53. package/dist/types/embed/source.d.ts +1 -1
  54. package/dist/types/react/annotations/AnnotationBar.d.ts +24 -0
  55. package/dist/types/react/annotations/AnnotationControls.d.ts +10 -0
  56. package/dist/types/react/annotations/AnnotationEditor.d.ts +15 -0
  57. package/dist/types/react/annotations/AnnotationMarkers.d.ts +19 -0
  58. package/dist/types/react/annotations/AnnotationSelectionLayer.d.ts +12 -0
  59. package/dist/types/react/annotations/AnnotationTarget.d.ts +9 -0
  60. package/dist/types/react/annotations/AnnotationTooltip.d.ts +9 -0
  61. package/dist/types/react/annotations/AnnotationTrigger.d.ts +10 -0
  62. package/dist/types/react/annotations/annotation-editor-state.d.ts +56 -0
  63. package/dist/types/react/annotations/annotation-screenshot.d.ts +4 -0
  64. package/dist/types/react/annotations/annotation-targets.d.ts +33 -0
  65. package/dist/types/react/annotations/getAnnotationProps.d.ts +15 -0
  66. package/dist/types/react/annotations/styles.d.ts +3 -0
  67. package/dist/types/react/annotations/useAnnotationGeometry.d.ts +22 -0
  68. package/dist/types/react/annotations/useDataAppAnnotations.d.ts +19 -0
  69. package/dist/types/react/bindings.d.ts +110 -0
  70. package/dist/types/react/content.d.ts +24 -11
  71. package/dist/types/react/embed/bridge.d.ts +1 -1
  72. package/dist/types/react/hooks.d.ts +29 -787
  73. package/dist/types/react/index.d.ts +30 -104
  74. package/dist/types/react/source-owner.d.ts +2 -0
  75. package/dist/types/react/style-contract.d.ts +60 -0
  76. package/dist/types/react/style-validation.d.ts +2 -0
  77. package/dist/types/react/ui/AboutData.d.ts +9 -1
  78. package/dist/types/react/ui/AppHeader.d.ts +1 -2
  79. package/dist/types/react/ui/AppLayout.d.ts +3 -9
  80. package/dist/types/react/ui/AppToolbar.d.ts +6 -7
  81. package/dist/types/react/ui/AreaChart.d.ts +7 -0
  82. package/dist/types/react/ui/BarChart.d.ts +6 -0
  83. package/dist/types/react/ui/{ComparisonVisual.d.ts → Comparison.d.ts} +3 -3
  84. package/dist/types/react/ui/ContentSkeleton.d.ts +2 -0
  85. package/dist/types/react/ui/DataApp.d.ts +17 -53
  86. package/dist/types/react/ui/DataAppFrame.d.ts +42 -0
  87. package/dist/types/react/ui/DataBoundary.d.ts +4 -5
  88. package/dist/types/react/ui/DataSection.d.ts +6 -18
  89. package/dist/types/react/ui/DataSectionBoundary.d.ts +30 -0
  90. package/dist/types/react/ui/DataValue.d.ts +9 -0
  91. package/dist/types/react/ui/DataWidget.d.ts +2 -1
  92. package/dist/types/react/ui/DateTimeTooltip.d.ts +1 -1
  93. package/dist/types/react/ui/ExportControl.d.ts +4 -0
  94. package/dist/types/react/ui/HelpPopover.d.ts +3 -4
  95. package/dist/types/react/ui/InspectionContext.d.ts +2 -0
  96. package/dist/types/react/ui/InspectionProvider.d.ts +29 -0
  97. package/dist/types/react/ui/LineChart.d.ts +7 -0
  98. package/dist/types/react/ui/MetricWidget.d.ts +4 -3
  99. package/dist/types/react/ui/PieChart.d.ts +8 -0
  100. package/dist/types/react/ui/PresentStory.d.ts +2 -5
  101. package/dist/types/react/ui/RefreshControl.d.ts +1 -2
  102. package/dist/types/react/ui/ScatterChart.d.ts +17 -0
  103. package/dist/types/react/ui/SearchField.d.ts +1 -2
  104. package/dist/types/react/ui/SearchInput.d.ts +3 -1
  105. package/dist/types/react/ui/Sheet.d.ts +2 -1
  106. package/dist/types/react/ui/Skeleton.d.ts +5 -2
  107. package/dist/types/react/ui/StaticDataApp.d.ts +4 -0
  108. package/dist/types/react/ui/TableWidget.d.ts +19 -16
  109. package/dist/types/react/ui/Tabs.d.ts +6 -2
  110. package/dist/types/react/ui/TextWidget.d.ts +2 -1
  111. package/dist/types/react/ui/Toast.d.ts +8 -0
  112. package/dist/types/react/ui/Tooltip.d.ts +4 -3
  113. package/dist/types/react/ui/TrendChart.d.ts +5 -0
  114. package/dist/types/react/ui/UpdatedAt.d.ts +1 -1
  115. package/dist/types/react/ui/VisualizationWidget.d.ts +12 -13
  116. package/dist/types/react/ui/WidgetViewTabs.d.ts +1 -1
  117. package/dist/types/react/ui/chart-data.d.ts +25 -0
  118. package/dist/types/react/ui/csv-export.d.ts +19 -0
  119. package/dist/types/react/ui/data-context.d.ts +18 -7
  120. package/dist/types/react/ui/icons.d.ts +2 -0
  121. package/dist/types/react/ui/index.d.ts +74 -0
  122. package/dist/types/react/ui/metric.d.ts +1 -1
  123. package/dist/types/react/ui/presentation.d.ts +5 -1
  124. package/dist/types/react/ui/shortcuts.d.ts +7 -1
  125. package/dist/types/react/view-runtime.d.ts +29 -0
  126. package/dist/types/react/view.d.ts +21 -4
  127. package/dist/types/react/widgets.d.ts +79 -0
  128. package/dist/worker.js +381 -79
  129. package/docs/app-authoring.md +64 -30
  130. package/docs/data-context.md +89 -0
  131. package/docs/embed.md +1 -1
  132. package/docs/formatting-and-appearance.md +52 -0
  133. package/docs/hosted-apps.md +2 -15
  134. package/docs/layout.md +33 -0
  135. package/docs/local-data-apps.md +1 -1
  136. package/docs/react-embed.md +2 -2
  137. package/docs/react.md +20 -254
  138. package/docs/stories-and-export.md +52 -0
  139. package/docs/styling.md +55 -0
  140. package/docs/ui-quality.md +20 -0
  141. package/docs/ui.md +41 -0
  142. package/docs/variables.md +98 -0
  143. package/docs/views.md +127 -0
  144. package/docs/widgets.md +142 -0
  145. package/examples/starter-data-app/index.tsx +89 -44
  146. package/package.json +13 -4
  147. package/dist/chunks/contract-cxr9t12b.js +0 -18
  148. package/dist/chunks/contract-cxr9t12b.js.map +0 -10
  149. package/dist/chunks/contract-mwe7gnmh.js.map +0 -13
  150. package/dist/chunks/contract-txjy0en2.js.map +0 -10
  151. package/dist/chunks/contract-xtxza1fy.js.map +0 -12
  152. package/dist/chunks/contract-yxbjea23.js.map +0 -12
  153. package/dist/chunks/contract-zr3jd7mr.js.map +0 -12
  154. package/dist/types/react/ui/RefreshRegion.d.ts +0 -9
  155. package/dist/types/react/ui/SelectableBarChart.d.ts +0 -15
  156. package/docs/releasing.md +0 -79
  157. /package/dist/types/react/ui/{comparison.d.ts → metric-comparison.d.ts} +0 -0
@@ -1,11 +1,10 @@
1
1
  import {
2
- BRIDGE,
3
2
  PARENT_PARAM,
4
3
  MAX_PENDING,
5
4
  REQUEST_TIMEOUT_MS,
6
- isBridgeMessage,
7
- validId
8
- } from "./contract-cxr9t12b.js";
5
+ validId,
6
+ createBridgeEndpoint
7
+ } from "./contract-awa2d5b1.js";
9
8
  import {
10
9
  MessageRoutingError2
11
10
  } from "./contract-tf8c3qpv.js";
@@ -16,6 +15,7 @@ function attachDataAppConnection({
16
15
  connection,
17
16
  javascript,
18
17
  presentation,
18
+ logger,
19
19
  onStatusChange,
20
20
  onDiagnostic,
21
21
  onMessage,
@@ -29,6 +29,7 @@ function attachDataAppConnection({
29
29
  let token = connection.type === "opaque" ? connection.token : undefined;
30
30
  const targetOrigin = connection.type === "opaque" ? "*" : frameOrigin;
31
31
  let currentPresentation;
32
+ let presentationIdentity;
32
33
  let disposed = false;
33
34
  let documentId;
34
35
  let sessionId;
@@ -37,48 +38,106 @@ function attachDataAppConnection({
37
38
  return {
38
39
  search: host.location.search,
39
40
  hash: host.location.hash,
40
- ...currentPresentation ? { presentation: currentPresentation } : {}
41
+ ...currentPresentation ? { presentation: currentPresentation } : {},
42
+ logging: logger !== undefined
41
43
  };
42
44
  }
45
+ function setLogger(value) {
46
+ if (disposed || value === logger)
47
+ return;
48
+ const wasEnabled = logger !== undefined;
49
+ logger = value;
50
+ if (wasEnabled !== (logger !== undefined))
51
+ publishState();
52
+ }
43
53
  function setPresentation(value) {
44
54
  if (disposed)
45
55
  return;
46
- if (value?.surface === currentPresentation?.surface && value?.theme === currentPresentation?.theme)
56
+ const identity = JSON.stringify(value);
57
+ if (identity === presentationIdentity)
47
58
  return;
48
- currentPresentation = value && { ...value };
49
- if (sessionId)
50
- publishState();
59
+ presentationIdentity = identity;
60
+ currentPresentation = identity === undefined ? undefined : JSON.parse(identity);
61
+ publishState();
51
62
  }
52
63
  function cancelAll() {
53
64
  for (const controller of pending.values())
54
65
  controller.abort();
55
66
  pending.clear();
56
67
  }
57
- function send(message) {
58
- onDiagnostic?.({ direction: "send", type: message.type ?? "unknown" });
59
- iframe.contentWindow?.postMessage({
60
- channel: BRIDGE,
61
- version: 1,
62
- documentId,
63
- sessionId,
64
- ...connection.type === "opaque" ? { token } : {},
65
- ...message
66
- }, targetOrigin);
67
- }
68
+ const endpoint = createBridgeEndpoint({
69
+ role: "host",
70
+ origin: frameOrigin,
71
+ source: () => iframe.contentWindow,
72
+ opaque: connection.type === "opaque",
73
+ context: () => ({ documentId, sessionId, token }),
74
+ post: (message) => iframe.contentWindow?.postMessage(message, targetOrigin),
75
+ diagnostic: (direction, type) => onDiagnostic?.({ direction, type }),
76
+ invalidRequest: (id) => {
77
+ if (pending.has(id))
78
+ return;
79
+ if (pending.size >= MAX_PENDING)
80
+ error(id, "bridge_busy", "Too many pending data requests.");
81
+ else
82
+ error(id, "invalid_message", "Invalid message route.");
83
+ },
84
+ handlers: {
85
+ ready(message) {
86
+ if (message.documentId !== documentId) {
87
+ cancelAll();
88
+ documentId = message.documentId;
89
+ sessionId = crypto.randomUUID();
90
+ }
91
+ onStatusChange?.("connected");
92
+ if (disposed)
93
+ return;
94
+ send("initialize", { state: hostState() });
95
+ if (disposed)
96
+ return;
97
+ if (javascript !== undefined)
98
+ send("scriptLoad", { javascript });
99
+ },
100
+ runtimeLog({ payload }) {
101
+ try {
102
+ logger?.[payload.method](...payload.args);
103
+ } catch {}
104
+ },
105
+ runtimeReady() {
106
+ onStatusChange?.("ready");
107
+ },
108
+ runtimeError() {
109
+ onStatusChange?.("failed");
110
+ },
111
+ request(message) {
112
+ request(message);
113
+ },
114
+ cancel(message) {
115
+ pending.get(message.id)?.abort();
116
+ pending.delete(message.id);
117
+ },
118
+ disconnect() {
119
+ cancelAll();
120
+ documentId = undefined;
121
+ sessionId = undefined;
122
+ onStatusChange?.("disconnected");
123
+ }
124
+ }
125
+ });
126
+ const send = endpoint.send;
127
+ const receive = endpoint.receive;
68
128
  function error(id, code, message, requestId) {
69
- send({ type: "bridge:error", id, code, message, requestId });
129
+ send("error", { id, code, message, requestId });
70
130
  }
71
131
  async function request(message) {
72
132
  const id = message.id;
73
- if (!validId(id) || pending.has(id))
133
+ if (pending.has(id))
74
134
  return;
75
135
  if (pending.size >= MAX_PENDING)
76
136
  return error(id, "bridge_busy", "Too many pending data requests.");
77
- if (typeof message.route !== "string" || !message.route || message.route.length > 256)
78
- return error(id, "invalid_message", "Invalid message route.");
79
137
  try {
80
138
  const body = JSON.stringify(message.payload);
81
- if (message.payload !== undefined && (typeof body !== "string" || body.length > 16384))
139
+ const limit = message.route === "annotation:draft" ? 384000 : 16384;
140
+ if (message.payload !== undefined && (typeof body !== "string" || body.length > limit))
82
141
  throw new Error("Invalid payload");
83
142
  } catch {
84
143
  return error(id, "invalid_payload", "The message payload is invalid or too large.");
@@ -98,7 +157,7 @@ function attachDataAppConnection({
98
157
  try {
99
158
  const response = await onMessage({ route: message.route, payload: message.payload }, { signal: controller.signal });
100
159
  if (pending.get(id) === controller)
101
- send({ type: "bridge:result", id, response });
160
+ send("result", { id, response });
102
161
  } catch (failure) {
103
162
  if (pending.get(id) === controller) {
104
163
  if (failure instanceof MessageRoutingError2)
@@ -112,51 +171,10 @@ function attachDataAppConnection({
112
171
  pending.delete(id);
113
172
  }
114
173
  }
115
- function receive(event) {
116
- if (event.origin !== frameOrigin || event.source !== iframe.contentWindow || !isBridgeMessage(event.data))
117
- return;
118
- const message = event.data;
119
- if (connection.type === "opaque" && message.token !== token)
120
- return;
121
- onDiagnostic?.({ direction: "receive", type: message.type });
122
- if (message.type === "bridge:ready") {
123
- if (message.documentId !== documentId) {
124
- cancelAll();
125
- documentId = message.documentId;
126
- sessionId = crypto.randomUUID();
127
- }
128
- onStatusChange?.("connected");
129
- send({
130
- type: "bridge:initialize",
131
- state: hostState()
132
- });
133
- if (javascript !== undefined)
134
- send({ type: "script:load", javascript });
135
- return;
136
- }
137
- if (!sessionId || message.sessionId !== sessionId || message.documentId !== documentId)
138
- return;
139
- if (message.type === "runtime:ready")
140
- onStatusChange?.("ready");
141
- else if (message.type === "runtime:error")
142
- onStatusChange?.("failed");
143
- else if (message.type === "bridge:request")
144
- request(message);
145
- else if (message.type === "bridge:cancel" && validId(message.id)) {
146
- pending.get(message.id)?.abort();
147
- pending.delete(message.id);
148
- } else if (message.type === "bridge:disconnect") {
149
- cancelAll();
150
- documentId = undefined;
151
- sessionId = undefined;
152
- onStatusChange?.("disconnected");
153
- }
154
- }
155
174
  function publishState() {
156
- send({
157
- type: "state:update",
158
- state: hostState()
159
- });
175
+ if (disposed || !sessionId)
176
+ return;
177
+ send("stateUpdate", { state: hostState() });
160
178
  }
161
179
  function load() {
162
180
  if (connection.type === "opaque")
@@ -165,10 +183,11 @@ function attachDataAppConnection({
165
183
  documentId = undefined;
166
184
  sessionId = undefined;
167
185
  onStatusChange?.("connecting");
168
- send({ type: "bridge:connect", documentId: "host" });
186
+ send("connect", {});
169
187
  }
170
188
  function dispose() {
171
189
  disposed = true;
190
+ endpoint.dispose();
172
191
  cancelAll();
173
192
  iframe.removeEventListener("load", load);
174
193
  host.removeEventListener("message", receive);
@@ -181,8 +200,8 @@ function attachDataAppConnection({
181
200
  host.addEventListener("popstate", publishState);
182
201
  host.addEventListener("pagehide", cancelAll);
183
202
  onStatusChange?.("connecting");
184
- send({ type: "bridge:connect", documentId: "host" });
185
- return { dispose, setPresentation };
203
+ send("connect", {});
204
+ return { dispose, setPresentation, setLogger };
186
205
  }
187
206
 
188
207
  // src/embed/source.ts
@@ -190,6 +209,7 @@ function attachDataAppSource({
190
209
  iframe,
191
210
  source,
192
211
  presentation,
212
+ logger,
193
213
  onMessage,
194
214
  onStatusChange,
195
215
  onDiagnostic,
@@ -233,6 +253,7 @@ function attachDataAppSource({
233
253
  connection: opaque ? { type: "opaque", token: crypto.randomUUID() } : { type: "origin", origin: url.origin },
234
254
  javascript: opaque ? source.javascript : undefined,
235
255
  presentation,
256
+ logger,
236
257
  onMessage,
237
258
  onStatusChange: status,
238
259
  onDiagnostic,
@@ -248,7 +269,11 @@ function attachDataAppSource({
248
269
  iframe.removeEventListener("error", error);
249
270
  bridge.dispose();
250
271
  }
251
- return { dispose, setPresentation: bridge.setPresentation };
272
+ return {
273
+ dispose,
274
+ setPresentation: bridge.setPresentation,
275
+ setLogger: bridge.setLogger
276
+ };
252
277
  }
253
278
 
254
279
  // src/embed/bridge.ts
@@ -258,4 +283,4 @@ function attachDataAppBridge2(options) {
258
283
 
259
284
  export { attachDataAppBridge2 };
260
285
 
261
- //# debugId=F23BB728E5A0F78664756E2164756E21
286
+ //# debugId=E598DB4534AD980C64756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/embed/host.ts", "../src/embed/source.ts", "../src/embed/bridge.ts"],
4
+ "sourcesContent": [
5
+ "import { createBridgeEndpoint } from '@/src/core/bridge-endpoint';\nimport type { DataAppPresentation } from '@/src/core/presentation';\nimport type { DataAppLogger } from '@/src/core/logger';\nimport {\n MAX_PENDING,\n REQUEST_TIMEOUT_MS,\n validId,\n type BridgeEventMessage,\n type BridgeMessage,\n} from '@/src/core/bridge';\n\nimport {\n MessageRoutingError,\n type MessageDispatcher,\n} from '@/src/core/messages';\n\nexport type DataAppConnection =\n | { type: 'origin'; origin: string }\n | { type: 'opaque'; token: string };\nexport type DataAppStatus =\n | 'connecting'\n | 'connected'\n | 'ready'\n | 'failed'\n | 'disconnected';\nexport type DataAppDiagnostic = {\n direction: 'send' | 'receive';\n type: BridgeMessage['type'];\n};\n\nexport type DataAppHost = {\n dispose: () => void;\n setPresentation: (presentation?: DataAppPresentation) => void;\n setLogger: (logger?: DataAppLogger) => void;\n};\n\nexport type DataAppHostOptions = {\n iframe: HTMLIFrameElement;\n presentation?: DataAppPresentation;\n logger?: DataAppLogger;\n onStatusChange?: (status: DataAppStatus) => void;\n onDiagnostic?: (event: DataAppDiagnostic) => void;\n onMessage: MessageDispatcher;\n};\n\nexport type DataAppConnectionOptions = DataAppHostOptions & {\n connection: DataAppConnection;\n javascript?: string;\n window?: Window;\n};\n\n/** The bridge owns delivery and cancellation; the routed handler owns validation, authorization and execution. */\nexport function attachDataAppConnection({\n iframe,\n connection,\n javascript,\n presentation,\n logger,\n onStatusChange,\n onDiagnostic,\n onMessage,\n window: host = window,\n}: DataAppConnectionOptions): DataAppHost {\n const frameOrigin = connection.type === 'origin' ? connection.origin : 'null';\n if (\n connection.type === 'origin' &&\n new URL(frameOrigin).origin !== frameOrigin\n )\n throw new Error('Expected an exact frame origin.');\n if (connection.type === 'opaque' && !validId(connection.token))\n throw new Error('Invalid sandbox token.');\n let token = connection.type === 'opaque' ? connection.token : undefined;\n const targetOrigin = connection.type === 'opaque' ? '*' : frameOrigin;\n let currentPresentation: DataAppPresentation | undefined;\n let presentationIdentity: string | undefined;\n let disposed = false;\n let documentId: string | undefined;\n let sessionId: string | undefined;\n const pending = new Map<string, AbortController>();\n\n function hostState() {\n return {\n search: host.location.search,\n hash: host.location.hash,\n ...(currentPresentation ? { presentation: currentPresentation } : {}),\n logging: logger !== undefined,\n };\n }\n\n function setLogger(value: DataAppLogger | undefined) {\n if (disposed || value === logger) return;\n const wasEnabled = logger !== undefined;\n logger = value;\n if (wasEnabled !== (logger !== undefined)) publishState();\n }\n\n function setPresentation(value: DataAppPresentation | undefined) {\n if (disposed) return;\n const identity = JSON.stringify(value);\n if (identity === presentationIdentity) return;\n presentationIdentity = identity;\n currentPresentation =\n identity === undefined\n ? undefined\n : (JSON.parse(identity) as DataAppPresentation);\n publishState();\n }\n\n function cancelAll() {\n for (const controller of pending.values()) controller.abort();\n pending.clear();\n }\n\n const endpoint = createBridgeEndpoint({\n role: 'host',\n origin: frameOrigin,\n source: () => iframe.contentWindow,\n opaque: connection.type === 'opaque',\n context: () => ({ documentId, sessionId, token }),\n post: message => iframe.contentWindow?.postMessage(message, targetOrigin),\n diagnostic: (direction, type) => onDiagnostic?.({ direction, type }),\n invalidRequest: id => {\n if (pending.has(id)) return;\n if (pending.size >= MAX_PENDING)\n error(id, 'bridge_busy', 'Too many pending data requests.');\n else error(id, 'invalid_message', 'Invalid message route.');\n },\n handlers: {\n ready(message) {\n if (message.documentId !== documentId) {\n cancelAll();\n documentId = message.documentId;\n sessionId = crypto.randomUUID();\n }\n onStatusChange?.('connected');\n if (disposed) return;\n send('initialize', { state: hostState() });\n if (disposed) return;\n if (javascript !== undefined) send('scriptLoad', { javascript });\n },\n runtimeLog({ payload }) {\n try {\n logger?.[payload.method](...payload.args);\n } catch {\n // A host logger failure must not break bridge delivery.\n }\n },\n runtimeReady() {\n onStatusChange?.('ready');\n },\n runtimeError() {\n onStatusChange?.('failed');\n },\n request(message) {\n void request(message);\n },\n cancel(message) {\n pending.get(message.id)?.abort();\n pending.delete(message.id);\n },\n disconnect() {\n cancelAll();\n documentId = undefined;\n sessionId = undefined;\n onStatusChange?.('disconnected');\n },\n },\n });\n const send = endpoint.send;\n const receive = endpoint.receive;\n\n function error(\n id: string,\n code: string,\n message: string,\n requestId?: string\n ) {\n send('error', { id, code, message, requestId });\n }\n\n async function request(message: BridgeEventMessage<'request'>) {\n const id = message.id;\n if (pending.has(id)) return;\n if (pending.size >= MAX_PENDING)\n return error(id, 'bridge_busy', 'Too many pending data requests.');\n try {\n const body = JSON.stringify(message.payload);\n // PNG annotation captures have a separate validated 256 KiB image budget.\n const limit = message.route === 'annotation:draft' ? 384_000 : 16_384;\n if (\n message.payload !== undefined &&\n (typeof body !== 'string' || body.length > limit)\n )\n throw new Error('Invalid payload');\n } catch {\n return error(\n id,\n 'invalid_payload',\n 'The message payload is invalid or too large.'\n );\n }\n const controller = new AbortController();\n pending.set(id, controller);\n const timer = setTimeout(() => {\n if (pending.get(id) !== controller) return;\n pending.delete(id);\n controller.abort();\n error(id, 'timeout', 'The data request timed out.');\n }, REQUEST_TIMEOUT_MS);\n controller.signal.addEventListener('abort', () => clearTimeout(timer), {\n once: true,\n });\n try {\n const response = await onMessage(\n { route: message.route, payload: message.payload },\n { signal: controller.signal }\n );\n if (pending.get(id) === controller) send('result', { id, response });\n } catch (failure) {\n if (pending.get(id) === controller) {\n if (failure instanceof MessageRoutingError)\n error(id, failure.code, failure.message, failure.requestId);\n else\n error(\n id,\n 'request_failed',\n 'The message request failed. Retry the request.'\n );\n }\n } finally {\n clearTimeout(timer);\n if (pending.get(id) === controller) pending.delete(id);\n }\n }\n\n function publishState() {\n if (disposed || !sessionId) return;\n send('stateUpdate', { state: hostState() });\n }\n\n function load() {\n if (connection.type === 'opaque') token = crypto.randomUUID();\n cancelAll();\n documentId = undefined;\n sessionId = undefined;\n onStatusChange?.('connecting');\n send('connect', {});\n }\n\n function dispose() {\n disposed = true;\n endpoint.dispose();\n cancelAll();\n iframe.removeEventListener('load', load);\n host.removeEventListener('message', receive);\n host.removeEventListener('popstate', publishState);\n host.removeEventListener('pagehide', cancelAll);\n }\n\n setPresentation(presentation);\n iframe.addEventListener('load', load);\n host.addEventListener('message', receive);\n host.addEventListener('popstate', publishState);\n host.addEventListener('pagehide', cancelAll);\n // Reconnect an already-loaded iframe when its host bridge mounts again.\n onStatusChange?.('connecting');\n send('connect', {});\n\n return { dispose, setPresentation, setLogger };\n}\n",
6
+ "import { PARENT_PARAM } from '@/src/core/bridge';\nimport {\n attachDataAppConnection,\n type DataAppStatus,\n type DataAppHost,\n type DataAppHostOptions,\n} from '@/src/embed/host';\n\nexport type DataAppSource =\n | { type: 'url'; url: string }\n | {\n type: 'bundle';\n bootstrapUrl: string;\n javascript: string;\n };\nexport type DataAppSourceOptions = DataAppHostOptions & {\n source: DataAppSource;\n startupTimeoutMs?: number;\n};\n\n/** Owns loading and sandbox policy. Dispose before replacing the source or retrying. */\nexport function attachDataAppSource({\n iframe,\n source,\n presentation,\n logger,\n onMessage,\n onStatusChange,\n onDiagnostic,\n startupTimeoutMs = 30_000,\n}: DataAppSourceOptions): DataAppHost {\n const host = iframe.ownerDocument.defaultView;\n if (!host) throw new Error('The iframe requires a host window.');\n const url = new URL(\n source.type === 'url' ? source.url : source.bootstrapUrl,\n host.location.href\n );\n if (!/^https?:$/.test(url.protocol))\n throw new Error('Data apps require an HTTP(S) URL.');\n const opaque = source.type === 'bundle';\n if (!opaque && url.origin === host.location.origin)\n throw new Error('URL data apps require a separate origin from the host.');\n iframe.setAttribute(\n 'sandbox',\n opaque\n ? 'allow-scripts'\n : 'allow-scripts allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox'\n );\n iframe.referrerPolicy = 'no-referrer';\n if (!opaque) url.searchParams.set(PARENT_PARAM, host.location.origin);\n let timer: ReturnType<typeof setTimeout> | undefined;\n let failed = false;\n\n function status(value: DataAppStatus) {\n if (value === 'connecting') failed = false;\n if (failed && value !== 'connecting') return;\n clearTimeout(timer);\n if (value === 'connecting' || value === 'connected')\n timer = setTimeout(() => {\n failed = true;\n bridge.dispose();\n onStatusChange?.('failed');\n }, startupTimeoutMs);\n if (value === 'failed') {\n failed = true;\n bridge.dispose();\n }\n onStatusChange?.(value);\n }\n\n const bridge = attachDataAppConnection({\n iframe,\n connection: opaque\n ? { type: 'opaque', token: crypto.randomUUID() }\n : { type: 'origin', origin: url.origin },\n javascript: opaque ? source.javascript : undefined,\n presentation,\n logger,\n onMessage,\n onStatusChange: status,\n onDiagnostic,\n window: host,\n });\n\n function error() {\n return status('failed');\n }\n\n iframe.addEventListener('error', error);\n iframe.src = url.href;\n\n function dispose() {\n clearTimeout(timer);\n iframe.removeEventListener('error', error);\n bridge.dispose();\n }\n\n return {\n dispose,\n setPresentation: bridge.setPresentation,\n setLogger: bridge.setLogger,\n };\n}\n",
7
+ "import {\n attachDataAppConnection,\n type DataAppConnectionOptions,\n} from '@/src/embed/host';\nimport {\n attachDataAppSource,\n type DataAppSourceOptions,\n} from '@/src/embed/source';\n\nexport type DataAppBridgeOptions =\n | (DataAppSourceOptions & {\n connection?: never;\n window?: never;\n javascript?: never;\n })\n | (DataAppConnectionOptions & { source?: never; startupTimeoutMs?: never });\n\n/** Source mode configures and loads the iframe; connection mode attaches to a host-owned document. */\nexport function attachDataAppBridge(options: DataAppBridgeOptions) {\n return options.source\n ? attachDataAppSource(options)\n : attachDataAppConnection(options);\n}\n"
8
+ ],
9
+ "mappings": ";;;;;;;;;;;;AAoDO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,OAAO;AAAA,GACyB;AAAA,EACxC,MAAM,cAAc,WAAW,SAAS,WAAW,WAAW,SAAS;AAAA,EACvE,IACE,WAAW,SAAS,YACpB,IAAI,IAAI,WAAW,EAAE,WAAW;AAAA,IAEhC,MAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD,IAAI,WAAW,SAAS,YAAY,CAAC,QAAQ,WAAW,KAAK;AAAA,IAC3D,MAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C,IAAI,QAAQ,WAAW,SAAS,WAAW,WAAW,QAAQ;AAAA,EAC9D,MAAM,eAAe,WAAW,SAAS,WAAW,MAAM;AAAA,EAC1D,IAAI;AAAA,EAC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