@thoughtspot/visual-embed-sdk 1.52.0 → 1.52.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 (279) hide show
  1. package/cjs/package.json +9 -1
  2. package/cjs/src/contracts/contracts.spec.d.ts +2 -0
  3. package/cjs/src/contracts/contracts.spec.d.ts.map +1 -0
  4. package/cjs/src/contracts/contracts.spec.js +345 -0
  5. package/cjs/src/contracts/contracts.spec.js.map +1 -0
  6. package/cjs/src/contracts/embed-event-payloads.d.ts +73 -0
  7. package/cjs/src/contracts/embed-event-payloads.d.ts.map +1 -0
  8. package/cjs/src/contracts/embed-event-payloads.js +3 -0
  9. package/cjs/src/contracts/embed-event-payloads.js.map +1 -0
  10. package/cjs/src/contracts/host-event-contracts.d.ts +378 -0
  11. package/cjs/src/contracts/host-event-contracts.d.ts.map +1 -0
  12. package/cjs/src/contracts/host-event-contracts.js +3 -0
  13. package/cjs/src/contracts/host-event-contracts.js.map +1 -0
  14. package/cjs/src/contracts/index.d.ts +22 -0
  15. package/cjs/src/contracts/index.d.ts.map +1 -0
  16. package/cjs/src/contracts/index.js +33 -0
  17. package/cjs/src/contracts/index.js.map +1 -0
  18. package/cjs/src/contracts/ui-passthrough-contracts.d.ts +277 -0
  19. package/cjs/src/contracts/ui-passthrough-contracts.d.ts.map +1 -0
  20. package/cjs/src/{embed/hostEventClient/contracts.js → contracts/ui-passthrough-contracts.js} +6 -2
  21. package/cjs/src/contracts/ui-passthrough-contracts.js.map +1 -0
  22. package/cjs/src/embed/app.d.ts +17 -140
  23. package/cjs/src/embed/app.d.ts.map +1 -1
  24. package/cjs/src/embed/app.js +20 -120
  25. package/cjs/src/embed/app.js.map +1 -1
  26. package/cjs/src/embed/app.spec.js +70 -26
  27. package/cjs/src/embed/app.spec.js.map +1 -1
  28. package/cjs/src/embed/events.spec.js +12 -2
  29. package/cjs/src/embed/events.spec.js.map +1 -1
  30. package/cjs/src/embed/hostEventClient/host-event-client.d.ts +3 -2
  31. package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  32. package/cjs/src/embed/hostEventClient/host-event-client.js +23 -18
  33. package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
  34. package/cjs/src/embed/hostEventClient/host-event-client.spec.js +36 -36
  35. package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  36. package/cjs/src/embed/hostEventClient/utils.d.ts +1 -1
  37. package/cjs/src/embed/hostEventClient/utils.d.ts.map +1 -1
  38. package/cjs/src/embed/hostEventClient/utils.js +3 -3
  39. package/cjs/src/embed/hostEventClient/utils.js.map +1 -1
  40. package/cjs/src/embed/liveboard.d.ts +9 -161
  41. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  42. package/cjs/src/embed/liveboard.js +66 -134
  43. package/cjs/src/embed/liveboard.js.map +1 -1
  44. package/cjs/src/embed/liveboard.spec.js +211 -28
  45. package/cjs/src/embed/liveboard.spec.js.map +1 -1
  46. package/cjs/src/embed/search.d.ts +14 -0
  47. package/cjs/src/embed/search.d.ts.map +1 -1
  48. package/cjs/src/embed/search.js +4 -1
  49. package/cjs/src/embed/search.js.map +1 -1
  50. package/cjs/src/embed/search.spec.js +65 -0
  51. package/cjs/src/embed/search.spec.js.map +1 -1
  52. package/cjs/src/embed/ts-embed.d.ts +17 -22
  53. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  54. package/cjs/src/embed/ts-embed.js +82 -56
  55. package/cjs/src/embed/ts-embed.js.map +1 -1
  56. package/cjs/src/embed/ts-embed.spec.js +325 -17
  57. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  58. package/cjs/src/full-height.d.ts +137 -0
  59. package/cjs/src/full-height.d.ts.map +1 -0
  60. package/cjs/src/full-height.js +272 -0
  61. package/cjs/src/full-height.js.map +1 -0
  62. package/cjs/src/full-height.spec.d.ts +2 -0
  63. package/cjs/src/full-height.spec.d.ts.map +1 -0
  64. package/cjs/src/full-height.spec.js +835 -0
  65. package/cjs/src/full-height.spec.js.map +1 -0
  66. package/cjs/src/index.d.ts +4 -3
  67. package/cjs/src/index.d.ts.map +1 -1
  68. package/cjs/src/index.js +3 -3
  69. package/cjs/src/index.js.map +1 -1
  70. package/cjs/src/react/all-types-export.d.ts +1 -1
  71. package/cjs/src/react/all-types-export.d.ts.map +1 -1
  72. package/cjs/src/react/all-types-export.js.map +1 -1
  73. package/cjs/src/react/all-types-export.parity.spec.js +55 -3
  74. package/cjs/src/react/all-types-export.parity.spec.js.map +1 -1
  75. package/cjs/src/types.d.ts +540 -3
  76. package/cjs/src/types.d.ts.map +1 -1
  77. package/cjs/src/types.js +326 -1
  78. package/cjs/src/types.js.map +1 -1
  79. package/cjs/src/utils/processTrigger.d.ts +3 -1
  80. package/cjs/src/utils/processTrigger.d.ts.map +1 -1
  81. package/cjs/src/utils/processTrigger.js +19 -51
  82. package/cjs/src/utils/processTrigger.js.map +1 -1
  83. package/cjs/src/utils/transport/iframe-transport.d.ts +55 -0
  84. package/cjs/src/utils/transport/iframe-transport.d.ts.map +1 -0
  85. package/cjs/src/utils/transport/iframe-transport.js +108 -0
  86. package/cjs/src/utils/transport/iframe-transport.js.map +1 -0
  87. package/cjs/src/utils/transport/iframe-transport.spec.d.ts +2 -0
  88. package/cjs/src/utils/transport/iframe-transport.spec.d.ts.map +1 -0
  89. package/cjs/src/utils/transport/iframe-transport.spec.js +140 -0
  90. package/cjs/src/utils/transport/iframe-transport.spec.js.map +1 -0
  91. package/cjs/src/utils.d.ts +18 -0
  92. package/cjs/src/utils.d.ts.map +1 -1
  93. package/cjs/src/utils.js +39 -1
  94. package/cjs/src/utils.js.map +1 -1
  95. package/cjs/src/utils.spec.js +62 -0
  96. package/cjs/src/utils.spec.js.map +1 -1
  97. package/dist/{index-BMppCU63.js → index-C1pmYb5H.js} +1 -1
  98. package/dist/src/contracts/contracts.spec.d.ts +2 -0
  99. package/dist/src/contracts/contracts.spec.d.ts.map +1 -0
  100. package/dist/src/contracts/embed-event-payloads.d.ts +73 -0
  101. package/dist/src/contracts/embed-event-payloads.d.ts.map +1 -0
  102. package/dist/src/contracts/host-event-contracts.d.ts +378 -0
  103. package/dist/src/contracts/host-event-contracts.d.ts.map +1 -0
  104. package/dist/src/contracts/index.d.ts +22 -0
  105. package/dist/src/contracts/index.d.ts.map +1 -0
  106. package/dist/src/contracts/ui-passthrough-contracts.d.ts +277 -0
  107. package/dist/src/contracts/ui-passthrough-contracts.d.ts.map +1 -0
  108. package/dist/src/embed/app.d.ts +17 -140
  109. package/dist/src/embed/app.d.ts.map +1 -1
  110. package/dist/src/embed/hostEventClient/host-event-client.d.ts +3 -2
  111. package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  112. package/dist/src/embed/hostEventClient/utils.d.ts +1 -1
  113. package/dist/src/embed/hostEventClient/utils.d.ts.map +1 -1
  114. package/dist/src/embed/liveboard.d.ts +9 -161
  115. package/dist/src/embed/liveboard.d.ts.map +1 -1
  116. package/dist/src/embed/search.d.ts +14 -0
  117. package/dist/src/embed/search.d.ts.map +1 -1
  118. package/dist/src/embed/ts-embed.d.ts +17 -22
  119. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  120. package/dist/src/full-height.d.ts +137 -0
  121. package/dist/src/full-height.d.ts.map +1 -0
  122. package/dist/src/full-height.spec.d.ts +2 -0
  123. package/dist/src/full-height.spec.d.ts.map +1 -0
  124. package/dist/src/index.d.ts +4 -3
  125. package/dist/src/index.d.ts.map +1 -1
  126. package/dist/src/react/all-types-export.d.ts +1 -1
  127. package/dist/src/react/all-types-export.d.ts.map +1 -1
  128. package/dist/src/types.d.ts +540 -3
  129. package/dist/src/types.d.ts.map +1 -1
  130. package/dist/src/utils/processTrigger.d.ts +3 -1
  131. package/dist/src/utils/processTrigger.d.ts.map +1 -1
  132. package/dist/src/utils/transport/iframe-transport.d.ts +55 -0
  133. package/dist/src/utils/transport/iframe-transport.d.ts.map +1 -0
  134. package/dist/src/utils/transport/iframe-transport.spec.d.ts +2 -0
  135. package/dist/src/utils/transport/iframe-transport.spec.d.ts.map +1 -0
  136. package/dist/src/utils.d.ts +18 -0
  137. package/dist/src/utils.d.ts.map +1 -1
  138. package/dist/tsembed-react.es.js +925 -363
  139. package/dist/tsembed-react.js +924 -362
  140. package/dist/tsembed.es.js +925 -363
  141. package/dist/tsembed.js +924 -362
  142. package/dist/visual-embed-sdk-react-full.d.ts +1357 -656
  143. package/dist/visual-embed-sdk-react.d.ts +1257 -606
  144. package/dist/visual-embed-sdk.d.ts +1320 -642
  145. package/lib/package.json +9 -1
  146. package/lib/src/contracts/contracts.spec.d.ts +2 -0
  147. package/lib/src/contracts/contracts.spec.d.ts.map +1 -0
  148. package/lib/src/contracts/contracts.spec.js +342 -0
  149. package/lib/src/contracts/contracts.spec.js.map +1 -0
  150. package/lib/src/contracts/embed-event-payloads.d.ts +73 -0
  151. package/lib/src/contracts/embed-event-payloads.d.ts.map +1 -0
  152. package/lib/src/contracts/embed-event-payloads.js +2 -0
  153. package/lib/src/contracts/embed-event-payloads.js.map +1 -0
  154. package/lib/src/contracts/host-event-contracts.d.ts +378 -0
  155. package/lib/src/contracts/host-event-contracts.d.ts.map +1 -0
  156. package/lib/src/contracts/host-event-contracts.js +2 -0
  157. package/lib/src/contracts/host-event-contracts.js.map +1 -0
  158. package/lib/src/contracts/index.d.ts +22 -0
  159. package/lib/src/contracts/index.d.ts.map +1 -0
  160. package/lib/src/contracts/index.js +22 -0
  161. package/lib/src/contracts/index.js.map +1 -0
  162. package/lib/src/contracts/ui-passthrough-contracts.d.ts +277 -0
  163. package/lib/src/contracts/ui-passthrough-contracts.d.ts.map +1 -0
  164. package/lib/src/{embed/hostEventClient/contracts.js → contracts/ui-passthrough-contracts.js} +6 -2
  165. package/lib/src/contracts/ui-passthrough-contracts.js.map +1 -0
  166. package/lib/src/embed/app.d.ts +17 -140
  167. package/lib/src/embed/app.d.ts.map +1 -1
  168. package/lib/src/embed/app.js +22 -122
  169. package/lib/src/embed/app.js.map +1 -1
  170. package/lib/src/embed/app.spec.js +70 -26
  171. package/lib/src/embed/app.spec.js.map +1 -1
  172. package/lib/src/embed/events.spec.js +12 -2
  173. package/lib/src/embed/events.spec.js.map +1 -1
  174. package/lib/src/embed/hostEventClient/host-event-client.d.ts +3 -2
  175. package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  176. package/lib/src/embed/hostEventClient/host-event-client.js +6 -1
  177. package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
  178. package/lib/src/embed/hostEventClient/host-event-client.spec.js +1 -1
  179. package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  180. package/lib/src/embed/hostEventClient/utils.d.ts +1 -1
  181. package/lib/src/embed/hostEventClient/utils.d.ts.map +1 -1
  182. package/lib/src/embed/hostEventClient/utils.js +1 -1
  183. package/lib/src/embed/hostEventClient/utils.js.map +1 -1
  184. package/lib/src/embed/liveboard.d.ts +9 -161
  185. package/lib/src/embed/liveboard.d.ts.map +1 -1
  186. package/lib/src/embed/liveboard.js +67 -135
  187. package/lib/src/embed/liveboard.js.map +1 -1
  188. package/lib/src/embed/liveboard.spec.js +211 -28
  189. package/lib/src/embed/liveboard.spec.js.map +1 -1
  190. package/lib/src/embed/search.d.ts +14 -0
  191. package/lib/src/embed/search.d.ts.map +1 -1
  192. package/lib/src/embed/search.js +4 -1
  193. package/lib/src/embed/search.js.map +1 -1
  194. package/lib/src/embed/search.spec.js +65 -0
  195. package/lib/src/embed/search.spec.js.map +1 -1
  196. package/lib/src/embed/ts-embed.d.ts +17 -22
  197. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  198. package/lib/src/embed/ts-embed.js +82 -56
  199. package/lib/src/embed/ts-embed.js.map +1 -1
  200. package/lib/src/embed/ts-embed.spec.js +322 -14
  201. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  202. package/lib/src/full-height.d.ts +137 -0
  203. package/lib/src/full-height.d.ts.map +1 -0
  204. package/lib/src/full-height.js +268 -0
  205. package/lib/src/full-height.js.map +1 -0
  206. package/lib/src/full-height.spec.d.ts +2 -0
  207. package/lib/src/full-height.spec.d.ts.map +1 -0
  208. package/lib/src/full-height.spec.js +833 -0
  209. package/lib/src/full-height.spec.js.map +1 -0
  210. package/lib/src/index.d.ts +4 -3
  211. package/lib/src/index.d.ts.map +1 -1
  212. package/lib/src/index.js +1 -1
  213. package/lib/src/index.js.map +1 -1
  214. package/lib/src/react/all-types-export.d.ts +1 -1
  215. package/lib/src/react/all-types-export.d.ts.map +1 -1
  216. package/lib/src/react/all-types-export.js.map +1 -1
  217. package/lib/src/react/all-types-export.parity.spec.js +55 -3
  218. package/lib/src/react/all-types-export.parity.spec.js.map +1 -1
  219. package/lib/src/types.d.ts +540 -3
  220. package/lib/src/types.d.ts.map +1 -1
  221. package/lib/src/types.js +326 -1
  222. package/lib/src/types.js.map +1 -1
  223. package/lib/src/utils/processTrigger.d.ts +3 -1
  224. package/lib/src/utils/processTrigger.d.ts.map +1 -1
  225. package/lib/src/utils/processTrigger.js +19 -51
  226. package/lib/src/utils/processTrigger.js.map +1 -1
  227. package/lib/src/utils/transport/iframe-transport.d.ts +55 -0
  228. package/lib/src/utils/transport/iframe-transport.d.ts.map +1 -0
  229. package/lib/src/utils/transport/iframe-transport.js +101 -0
  230. package/lib/src/utils/transport/iframe-transport.js.map +1 -0
  231. package/lib/src/utils/transport/iframe-transport.spec.d.ts +2 -0
  232. package/lib/src/utils/transport/iframe-transport.spec.d.ts.map +1 -0
  233. package/lib/src/utils/transport/iframe-transport.spec.js +138 -0
  234. package/lib/src/utils/transport/iframe-transport.spec.js.map +1 -0
  235. package/lib/src/utils.d.ts +18 -0
  236. package/lib/src/utils.d.ts.map +1 -1
  237. package/lib/src/utils.js +37 -0
  238. package/lib/src/utils.js.map +1 -1
  239. package/lib/src/utils.spec.js +63 -1
  240. package/lib/src/utils.spec.js.map +1 -1
  241. package/lib/src/visual-embed-sdk.d.ts +1320 -642
  242. package/package.json +9 -1
  243. package/src/contracts/contracts.spec.ts +392 -0
  244. package/src/contracts/embed-event-payloads.ts +83 -0
  245. package/src/contracts/host-event-contracts.ts +456 -0
  246. package/src/contracts/index.ts +53 -0
  247. package/src/contracts/ui-passthrough-contracts.ts +301 -0
  248. package/src/embed/app.spec.ts +86 -34
  249. package/src/embed/app.ts +37 -264
  250. package/src/embed/events.spec.ts +14 -2
  251. package/src/embed/hostEventClient/host-event-client.spec.ts +2 -2
  252. package/src/embed/hostEventClient/host-event-client.ts +18 -5
  253. package/src/embed/hostEventClient/utils.ts +2 -1
  254. package/src/embed/liveboard.spec.ts +257 -38
  255. package/src/embed/liveboard.ts +75 -296
  256. package/src/embed/search.spec.ts +80 -0
  257. package/src/embed/search.ts +20 -0
  258. package/src/embed/ts-embed.spec.ts +448 -15
  259. package/src/embed/ts-embed.ts +109 -66
  260. package/src/full-height.spec.ts +1008 -0
  261. package/src/full-height.ts +361 -0
  262. package/src/index.ts +93 -5
  263. package/src/react/all-types-export.parity.spec.ts +63 -3
  264. package/src/react/all-types-export.ts +45 -0
  265. package/src/types.ts +540 -1
  266. package/src/utils/processTrigger.ts +28 -58
  267. package/src/utils/transport/iframe-transport.spec.ts +177 -0
  268. package/src/utils/transport/iframe-transport.ts +122 -0
  269. package/src/utils.spec.ts +71 -0
  270. package/src/utils.ts +38 -0
  271. package/cjs/src/embed/hostEventClient/contracts.d.ts +0 -231
  272. package/cjs/src/embed/hostEventClient/contracts.d.ts.map +0 -1
  273. package/cjs/src/embed/hostEventClient/contracts.js.map +0 -1
  274. package/dist/src/embed/hostEventClient/contracts.d.ts +0 -231
  275. package/dist/src/embed/hostEventClient/contracts.d.ts.map +0 -1
  276. package/lib/src/embed/hostEventClient/contracts.d.ts +0 -231
  277. package/lib/src/embed/hostEventClient/contracts.d.ts.map +0 -1
  278. package/lib/src/embed/hostEventClient/contracts.js.map +0 -1
  279. package/src/embed/hostEventClient/contracts.ts +0 -262
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Copyright (c) 2025
3
+ *
4
+ * Full-height support for the Liveboard and app embeds.
5
+ * @summary Full height
6
+ */
7
+
8
+ import {
9
+ BaseViewConfig,
10
+ EmbedEvent,
11
+ FullHeightViewConfig,
12
+ HostEvent,
13
+ MessageCallback,
14
+ MessagePayload,
15
+ Param,
16
+ QueryParams,
17
+ } from './types';
18
+ import {
19
+ calculateElementCenter,
20
+ calculateVisibleElementData,
21
+ getEffectiveClippingAncestors,
22
+ getScrollableAncestors,
23
+ isValidCssMargin,
24
+ } from './utils';
25
+ import { logger } from './utils/logger';
26
+ import { DEFAULT_LAZY_LOADING_MARGIN } from './config';
27
+
28
+ /**
29
+ * The height the embed falls back to when the host app has not configured
30
+ * `minimumHeight` or `defaultHeight`.
31
+ */
32
+ const DEFAULT_MINIMUM_HEIGHT = 500;
33
+
34
+ /**
35
+ * Routes that are part of the Liveboard experience itself. Navigating between
36
+ * these does not reset the frame height, because the ThoughtSpot app keeps
37
+ * reporting a height of its own for them.
38
+ */
39
+ const LIVEBOARD_RELATED_ROUTES = [
40
+ '/pinboard/',
41
+ '/insights/pinboard/',
42
+ '/schedules/',
43
+ '/embed/viz/',
44
+ '/embed/insights/viz/',
45
+ '/liveboard/',
46
+ '/insights/liveboard/',
47
+ '/tsl-editor/PINBOARD_ANSWER_BOOK/',
48
+ '/import-tsl/PINBOARD_ANSWER_BOOK/',
49
+ ];
50
+
51
+ /**
52
+ * The slice of an embed's view config the full-height controller reads.
53
+ */
54
+ export type FullHeightControllerViewConfig = FullHeightViewConfig &
55
+ Pick<BaseViewConfig, 'frameParams'>;
56
+
57
+ /**
58
+ * The subset of the embed the full-height controller drives. Keeping this
59
+ * narrow lets the controller stay independent of the embed class hierarchy.
60
+ */
61
+ export interface FullHeightEmbedHost {
62
+ /**
63
+ * Returns the embedded iframe. The iframe only exists once the embed has
64
+ * rendered, so this is a callback rather than a value.
65
+ */
66
+ getIframe: () => HTMLIFrameElement;
67
+ /**
68
+ * Sets the height of the embed container.
69
+ */
70
+ setFrameHeight: (height: number | string) => void;
71
+ /**
72
+ * Registers an SDK-owned handler for an embed event.
73
+ */
74
+ on: (eventType: EmbedEvent, callback: MessageCallback) => void;
75
+ /**
76
+ * Sends a host event to the embedded ThoughtSpot app.
77
+ */
78
+ trigger: (hostEvent: HostEvent, data: unknown) => void;
79
+ }
80
+
81
+ /**
82
+ * Owns every piece of full-height behavior for an embed: the height
83
+ * negotiation with the ThoughtSpot app, the query parameters that switch the
84
+ * feature on, and the viewport listeners that drive lazy loading.
85
+ *
86
+ * The controller is inert unless `fullHeight` is enabled, so embeds can create
87
+ * one unconditionally.
88
+ */
89
+ export class FullHeightController {
90
+ private scrollContainers: HTMLElement[] = [];
91
+
92
+ private resizeObserver: ResizeObserver | undefined;
93
+
94
+ private config: FullHeightControllerViewConfig;
95
+
96
+ constructor(
97
+ viewConfig: FullHeightControllerViewConfig,
98
+ private readonly host: FullHeightEmbedHost,
99
+ ) {
100
+ this.config = FullHeightController.withLazyLoadingDefaults(viewConfig);
101
+ this.registerEventHandlers();
102
+ }
103
+
104
+ /**
105
+ * The view config the controller runs on: the host app's own config with
106
+ * the lazy-loading defaults filled in. Read-only, so the only way to change
107
+ * it is through the setter, which re-resolves the defaults.
108
+ */
109
+ public get viewConfig(): Readonly<FullHeightControllerViewConfig> {
110
+ return this.config;
111
+ }
112
+
113
+ /**
114
+ * Replaces the view config the controller runs on and re-resolves the
115
+ * lazy-loading defaults against it. The config the caller passes is never
116
+ * written to; the controller keeps a copy of its own.
117
+ */
118
+ public set viewConfig(viewConfig: Readonly<FullHeightControllerViewConfig>) {
119
+ this.config = FullHeightController.withLazyLoadingDefaults(viewConfig);
120
+ }
121
+
122
+ /**
123
+ * The view config with the lazy-loading settings the embed falls back to
124
+ * when the host app has not chosen its own.
125
+ *
126
+ * Pure by design: it returns a new config rather than writing to the one it
127
+ * is given, so the host app's object is left untouched.
128
+ * @param viewConfig The embed's view config
129
+ * @returns A copy with the defaults filled in, host app choices preserved
130
+ */
131
+ private static withLazyLoadingDefaults(
132
+ viewConfig: Readonly<FullHeightControllerViewConfig>,
133
+ ): FullHeightControllerViewConfig {
134
+ return {
135
+ ...viewConfig,
136
+ lazyLoadingForFullHeight:
137
+ viewConfig.lazyLoadingForFullHeight === undefined
138
+ ? true
139
+ : viewConfig.lazyLoadingForFullHeight,
140
+ enableScrollableContainerLazyLoading:
141
+ viewConfig.enableScrollableContainerLazyLoading === undefined
142
+ ? true
143
+ : viewConfig.enableScrollableContainerLazyLoading,
144
+ lazyLoadingMargin:
145
+ viewConfig.lazyLoadingMargin === undefined
146
+ ? DEFAULT_LAZY_LOADING_MARGIN
147
+ : viewConfig.lazyLoadingMargin,
148
+ };
149
+ }
150
+
151
+ /**
152
+ * Whether the host app asked for a full-height embed.
153
+ */
154
+ private get isEnabled(): boolean {
155
+ return this.config.fullHeight === true;
156
+ }
157
+
158
+ /**
159
+ * Whether visualizations should load as they scroll into view, which
160
+ * requires the SDK to report the visible region of the embed.
161
+ */
162
+ private get isLazyLoadEnabled(): boolean {
163
+ return this.isEnabled && !!this.config.lazyLoadingForFullHeight;
164
+ }
165
+
166
+ /**
167
+ * The floor for the frame height. `defaultHeight` is the deprecated
168
+ * spelling of `minimumHeight` and is still honored for compatibility.
169
+ */
170
+ public get minimumHeight(): number {
171
+ const { minimumHeight, defaultHeight } = this.config;
172
+ return minimumHeight || defaultHeight || DEFAULT_MINIMUM_HEIGHT;
173
+ }
174
+
175
+ /**
176
+ * Registers the embed event handlers the feature depends on. Called from
177
+ * the constructor, so the handlers are in place before `render`.
178
+ */
179
+ private registerEventHandlers(): void {
180
+ if (!this.isEnabled) {
181
+ return;
182
+ }
183
+ this.host.on(EmbedEvent.RouteChange, this.handleRouteChange);
184
+ this.host.on(EmbedEvent.EmbedHeight, this.handleEmbedHeight);
185
+ this.host.on(EmbedEvent.EmbedIframeCenter, this.handleEmbedIframeCenter);
186
+ this.host.on(
187
+ EmbedEvent.RequestVisibleEmbedCoordinates,
188
+ this.handleRequestVisibleCoordinates,
189
+ );
190
+ }
191
+
192
+ /**
193
+ * Adds the full-height query parameters to the embed URL params.
194
+ * @param params The query parameters being built by the embed
195
+ */
196
+ public addQueryParams(params: QueryParams): void {
197
+ if (!this.isEnabled) {
198
+ return;
199
+ }
200
+ params[Param.fullHeight] = true;
201
+ if (!this.config.lazyLoadingForFullHeight) {
202
+ return;
203
+ }
204
+ params[Param.IsLazyLoadingForEmbedEnabled] = true;
205
+ if (isValidCssMargin(this.config.lazyLoadingMargin)) {
206
+ params[Param.RootMarginForLazyLoad] = this.config.lazyLoadingMargin;
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Attaches the viewport listeners that keep lazy loading in sync. Call this
212
+ * once the embed has rendered and the iframe exists.
213
+ */
214
+ public onRender(): void {
215
+ this.registerLazyLoadListeners();
216
+ }
217
+
218
+ /**
219
+ * Detaches every listener and observer owned by the controller.
220
+ */
221
+ public destroy(): void {
222
+ this.unregisterLazyLoadListeners();
223
+ }
224
+
225
+ /**
226
+ * Sets the frame height to the height reported by the ThoughtSpot app,
227
+ * never going below the configured minimum.
228
+ */
229
+ private handleEmbedHeight = (payload: MessagePayload): void => {
230
+ const height = Number(payload?.data);
231
+ if (!isNaN(height)) {
232
+ this.host.setFrameHeight(Math.max(height, this.minimumHeight));
233
+ }
234
+ this.sendVisibleCoordinates();
235
+ };
236
+
237
+ /**
238
+ * Answers the app's request for the center of the visible embed region.
239
+ */
240
+ private handleEmbedIframeCenter = (
241
+ payload: MessagePayload,
242
+ responder?: (data: any) => void,
243
+ ): void => {
244
+ const iframe = this.host.getIframe();
245
+ if (!iframe) {
246
+ return;
247
+ }
248
+ responder?.({
249
+ type: EmbedEvent.EmbedIframeCenter,
250
+ data: calculateElementCenter(iframe),
251
+ });
252
+ };
253
+
254
+ /**
255
+ * Answers the app's request for the currently visible embed coordinates.
256
+ */
257
+ private handleRequestVisibleCoordinates = (
258
+ payload: MessagePayload,
259
+ responder?: (data: any) => void,
260
+ ): void => {
261
+ logger.info('Sending RequestVisibleEmbedCoordinates', payload);
262
+ responder?.({
263
+ type: EmbedEvent.RequestVisibleEmbedCoordinates,
264
+ data: this.getVisibleCoordinates(),
265
+ });
266
+ };
267
+
268
+ /**
269
+ * Resets the frame height when the app navigates away from a Liveboard,
270
+ * since only Liveboard routes report a height of their own.
271
+ */
272
+ private handleRouteChange = (payload: MessagePayload): void => {
273
+ const currentPath: string = payload?.data?.currentPath;
274
+ if (!currentPath) {
275
+ return;
276
+ }
277
+ if (LIVEBOARD_RELATED_ROUTES.some((route) => currentPath.startsWith(route))) {
278
+ return;
279
+ }
280
+ this.host.setFrameHeight(this.config.frameParams?.height || this.minimumHeight);
281
+ };
282
+
283
+ /**
284
+ * Pushes the visible embed region to the app so it can decide which
285
+ * visualizations to load.
286
+ */
287
+ private sendVisibleCoordinates = (): void => {
288
+ if (!this.isLazyLoadEnabled) {
289
+ return;
290
+ }
291
+ const coordinates = this.getVisibleCoordinates();
292
+ if (coordinates) {
293
+ this.host.trigger(HostEvent.VisibleEmbedCoordinates, coordinates);
294
+ }
295
+ };
296
+
297
+ private getVisibleCoordinates() {
298
+ const iframe = this.host.getIframe();
299
+ if (!iframe) {
300
+ return null;
301
+ }
302
+ return calculateVisibleElementData(
303
+ iframe,
304
+ this.config.enableScrollableContainerLazyLoading,
305
+ );
306
+ }
307
+
308
+ private registerLazyLoadListeners(): void {
309
+ if (!this.isLazyLoadEnabled || !this.host.getIframe()) {
310
+ return;
311
+ }
312
+ // Re-registering is safe: drop whatever a previous render attached.
313
+ this.unregisterLazyLoadListeners();
314
+ // TODO: Use passive: true, install modernizr to check for passive
315
+ window.addEventListener('resize', this.sendVisibleCoordinates);
316
+ window.addEventListener('scroll', this.sendVisibleCoordinates, true);
317
+ if (!this.config.enableScrollableContainerLazyLoading) {
318
+ return;
319
+ }
320
+ this.observeScrollableContainers();
321
+ }
322
+
323
+ /**
324
+ * Tracks the ancestors that can scroll or clip the embed, so the visible
325
+ * region stays correct when the embed lives inside its own scroll
326
+ * container rather than the page.
327
+ */
328
+ private observeScrollableContainers(): void {
329
+ const iFrame = this.host.getIframe();
330
+ this.scrollContainers = getScrollableAncestors(iFrame);
331
+ this.scrollContainers.forEach((scrollContainer) => {
332
+ scrollContainer.addEventListener('scroll', this.sendVisibleCoordinates);
333
+ });
334
+ if (typeof ResizeObserver === 'undefined') {
335
+ return;
336
+ }
337
+ const resizeTargets = new Set(
338
+ [iFrame.parentElement, ...getEffectiveClippingAncestors(iFrame)].filter(
339
+ Boolean,
340
+ ) as HTMLElement[],
341
+ );
342
+ this.resizeObserver = new ResizeObserver(this.sendVisibleCoordinates);
343
+ resizeTargets.forEach((resizeTarget) => {
344
+ this.resizeObserver.observe(resizeTarget);
345
+ });
346
+ }
347
+
348
+ private unregisterLazyLoadListeners(): void {
349
+ if (!this.isLazyLoadEnabled) {
350
+ return;
351
+ }
352
+ window.removeEventListener('resize', this.sendVisibleCoordinates);
353
+ window.removeEventListener('scroll', this.sendVisibleCoordinates, true);
354
+ this.resizeObserver?.disconnect();
355
+ this.resizeObserver = undefined;
356
+ this.scrollContainers.forEach((scrollContainer) => {
357
+ scrollContainer.removeEventListener('scroll', this.sendVisibleCoordinates);
358
+ });
359
+ this.scrollContainers = [];
360
+ }
361
+ }
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ import {
64
64
  VizPoint,
65
65
  CustomActionPayload,
66
66
  ListPageColumns,
67
+ CustomAction,
67
68
  CustomActionsPosition,
68
69
  CustomActionTarget,
69
70
  InterceptedApiType,
@@ -95,10 +96,6 @@ import {
95
96
  UIPassthroughRequest,
96
97
  UIPassthroughResponse,
97
98
  UIPassthroughArrayResponse,
98
- HostEventRequest,
99
- HostEventResponse,
100
- TriggerPayload,
101
- TriggerResponse,
102
99
  LiveboardTab,
103
100
  LiveboardGroup,
104
101
  ApplicabilityLevel,
@@ -106,7 +103,54 @@ import {
106
103
  FilterUpdate,
107
104
  LiveboardFilter,
108
105
  LiveboardParameter,
109
- } from './embed/hostEventClient/contracts';
106
+ PinAnswerToLiveboardRequest,
107
+ PinAnswerToLiveboardResponse,
108
+ SaveAnswerRequest,
109
+ SaveAnswerResponse,
110
+ GetDiscoverabilityStatusResponse,
111
+ GetAvailableUIPassthroughsResponse,
112
+ GetAnswerConfigRequest,
113
+ GetUnsavedAnswerTMLRequest,
114
+ GetUnsavedAnswerTMLResponse,
115
+ GetAnswerSessionRequest,
116
+ GetAnswerSessionResponse,
117
+ GetFiltersRequest,
118
+ GetFiltersResponse,
119
+ GetIframeUrlResponse,
120
+ GetParametersResponse,
121
+ GetTMLRequest,
122
+ GetTabsResponse,
123
+ GetGroupsResponse,
124
+ GetExportRequestForCurrentPinboardResponse,
125
+ UpdateFiltersPassthroughRequest,
126
+ DrilldownRequest,
127
+ } from './contracts/ui-passthrough-contracts';
128
+ import {
129
+ HostEventRequest,
130
+ HostEventResponse,
131
+ TriggerPayload,
132
+ TriggerResponse,
133
+ TriggerData,
134
+ VizScopedRequest,
135
+ RequiredVizRequest,
136
+ ConversationScopedRequest,
137
+ OpenFilterRequest,
138
+ OpenFilterLiveboardRequest,
139
+ OpenFilterSpotterRequest,
140
+ OpenFilterSearchRequest,
141
+ DrillDownRequest,
142
+ OpenParameterRequest,
143
+ SearchRequest,
144
+ SpotterSearchRequest,
145
+ CrossFilterCondition,
146
+ UpdateCrossFilterRequest,
147
+ HostFilterUpdate,
148
+ UpdateFiltersRequest,
149
+ PersonalisedViewRequest,
150
+ ScheduleEmailRequest,
151
+ NavigateRequest,
152
+ SetActiveTabRequest,
153
+ } from './contracts/host-event-contracts';
110
154
 
111
155
  export {
112
156
  init,
@@ -191,6 +235,7 @@ export {
191
235
  HomePage,
192
236
  ListPage,
193
237
  VizPoint,
238
+ CustomAction,
194
239
  CustomActionPayload,
195
240
  UIPassthroughEvent,
196
241
  // Host event payload / response contracts. These describe what to send with
@@ -205,12 +250,55 @@ export {
205
250
  HostEventResponse,
206
251
  TriggerPayload,
207
252
  TriggerResponse,
253
+ // Host event contract shapes, map and trigger() data type — see /contracts.
254
+ TriggerData,
255
+ VizScopedRequest,
256
+ RequiredVizRequest,
257
+ ConversationScopedRequest,
258
+ OpenFilterRequest,
259
+ OpenFilterLiveboardRequest,
260
+ OpenFilterSpotterRequest,
261
+ OpenFilterSearchRequest,
262
+ DrillDownRequest,
263
+ OpenParameterRequest,
264
+ SearchRequest,
265
+ SpotterSearchRequest,
266
+ CrossFilterCondition,
267
+ UpdateCrossFilterRequest,
268
+ HostFilterUpdate,
269
+ UpdateFiltersRequest,
270
+ PersonalisedViewRequest,
271
+ ScheduleEmailRequest,
272
+ NavigateRequest,
273
+ SetActiveTabRequest,
208
274
  LiveboardTab,
209
275
  LiveboardGroup,
210
276
  ApplicabilityLevel,
211
277
  Applicability,
212
278
  FilterUpdate,
213
279
  LiveboardFilter,
280
+ // UI passthrough request/response shapes (see UIPassthroughContractBase).
281
+ PinAnswerToLiveboardRequest,
282
+ PinAnswerToLiveboardResponse,
283
+ SaveAnswerRequest,
284
+ SaveAnswerResponse,
285
+ GetDiscoverabilityStatusResponse,
286
+ GetAvailableUIPassthroughsResponse,
287
+ GetAnswerConfigRequest,
288
+ GetUnsavedAnswerTMLRequest,
289
+ GetUnsavedAnswerTMLResponse,
290
+ GetAnswerSessionRequest,
291
+ GetAnswerSessionResponse,
292
+ GetFiltersRequest,
293
+ GetFiltersResponse,
294
+ GetIframeUrlResponse,
295
+ GetParametersResponse,
296
+ GetTMLRequest,
297
+ GetTabsResponse,
298
+ GetGroupsResponse,
299
+ GetExportRequestForCurrentPinboardResponse,
300
+ UpdateFiltersPassthroughRequest,
301
+ DrilldownRequest,
214
302
  LiveboardParameter,
215
303
  ListPageColumns,
216
304
  DataPanelCustomColumnGroupsAccordionState,
@@ -16,6 +16,39 @@ import * as path from 'path';
16
16
 
17
17
  const INDEX_PATH = path.join(__dirname, '..', 'index.ts');
18
18
  const REACT_EXPORT_PATH = path.join(__dirname, 'all-types-export.ts');
19
+ const TYPES_PATH = path.join(__dirname, '..', 'types.ts');
20
+ const HOST_EVENT_CONTRACTS_PATH = path.join(
21
+ __dirname, '..', 'contracts', 'host-event-contracts.ts',
22
+ );
23
+
24
+ // Payload/request/response types named by `{@link X}` in a doc comment that a
25
+ // customer is meant to import. Enums and internal resolver/map mechanics are
26
+ // referenced by docs too but are not part of this exported-payload contract.
27
+ const NON_PAYLOAD_LINK_TARGETS = new Set([
28
+ 'HostEvent', 'EmbedEvent', 'ContextType', 'RuntimeFilterOp',
29
+ 'HostEventRequest', 'HostEventResponse', 'HostEventRequestMap',
30
+ 'HostEventContextRequestMap', 'DefaultHostEventRequest',
31
+ 'EmbedApiHostEventMapping', 'TriggerData', 'TriggerResponse',
32
+ 'TriggerPayload', 'DeepPartial', 'UIPassthroughRequest',
33
+ 'UIPassthroughResponse', 'HostEventName',
34
+ ]);
35
+
36
+ // Extract the payload types named by `{@link X}` (bare identifier, not a member
37
+ // access like `HostEvent.Foo`) inside the `*Request`/`*Response` docs and
38
+ // the HostEvent enum docs — the links a customer follows to a payload type.
39
+ const extractPayloadLinkTargets = (source: string): Set<string> => {
40
+ const targets = new Set<string>();
41
+ const linkRe = /\{@link\s+([A-Za-z_$][\w$]*)(?:\.[\w$]+)?\s*\}/g;
42
+ let m = linkRe.exec(source);
43
+ while (m !== null) {
44
+ const name = m[1];
45
+ // Member access (`HostEvent.OpenFilter`) captured `HostEvent` — that is
46
+ // an enum, filtered below. A payload type ends in Request/Response.
47
+ if (/(?:Request|Response)$/.test(name)) targets.add(name);
48
+ m = linkRe.exec(source);
49
+ }
50
+ return targets;
51
+ };
19
52
 
20
53
  /**
21
54
  * Symbols intentionally absent from the React surface.
@@ -45,8 +78,8 @@ const REACT_EXEMPT = new Set<string>([
45
78
  /**
46
79
  * PRE-EXISTING gaps, discovered when this spec was introduced. These are
47
80
  * symbols React consumers cannot import today — most look like oversights
48
- * rather than deliberate omissions (e.g. `ContextType`, `CustomActionPayload`,
49
- * `VizPoint`, the Spotter view configs).
81
+ * rather than deliberate omissions (e.g. `ContextType`, `VizPoint`,
82
+ * the Spotter view configs).
50
83
  *
51
84
  * This list may only ever SHRINK. Do not add to it — a new entry means a
52
85
  * symbol was added to `src/index.ts` without adding it to the React surface,
@@ -64,7 +97,6 @@ const KNOWN_REACT_GAPS = new Set<string>([
64
97
  'ContextMenuTriggerOptions',
65
98
  'ContextType',
66
99
  'ConversationViewConfig',
67
- 'CustomActionPayload',
68
100
  'DataLabelFilterOperator',
69
101
  'EmbedErrorCodes',
70
102
  'EmbedErrorDetailsEvent',
@@ -203,6 +235,34 @@ describe('react/all-types-export parity with index', () => {
203
235
  'HostEventResponse',
204
236
  'TriggerPayload',
205
237
  'TriggerResponse',
238
+ 'TriggerData',
239
+ 'UpdateFiltersRequest',
240
+ 'NavigateRequest',
206
241
  ].forEach((name) => expect(reactNames.has(name)).toBe(true));
207
242
  });
243
+
244
+ // Docs and types must not diverge: a `{@link SomethingRequest}` in a doc
245
+ // comment promises the reader can reach that type. If generation renames
246
+ // or drops a payload type, or an export is removed, the link dangles. This
247
+ // or drops a payload type, or an export is removed, the link dangles. It
248
+ it('every payload type linked from docs is exported from both entry points', () => {
249
+ const indexNames = extractExportedNames(fs.readFileSync(INDEX_PATH, 'utf8'));
250
+ const reactNames = extractExportedNames(fs.readFileSync(REACT_EXPORT_PATH, 'utf8'));
251
+ const linked = new Set<string>([
252
+ ...extractPayloadLinkTargets(fs.readFileSync(TYPES_PATH, 'utf8')),
253
+ ...extractPayloadLinkTargets(
254
+ fs.readFileSync(HOST_EVENT_CONTRACTS_PATH, 'utf8'),
255
+ ),
256
+ ]);
257
+
258
+ // Sanity: the doc scan found the payload links we added.
259
+ expect(linked.has('OpenFilterLiveboardRequest')).toBe(true);
260
+ expect(linked.has('DrillDownRequest')).toBe(true);
261
+ expect(linked.size).toBeGreaterThan(5);
262
+
263
+ const dangling = [...linked]
264
+ .filter((name) => !NON_PAYLOAD_LINK_TARGETS.has(name))
265
+ .filter((name) => !indexNames.has(name) || !reactNames.has(name));
266
+ expect(dangling).toEqual([]);
267
+ });
208
268
  });
@@ -66,16 +66,61 @@ export {
66
66
  HostEventResponse,
67
67
  TriggerPayload,
68
68
  TriggerResponse,
69
+ // Host event contract shapes, map and trigger() data type — see /contracts.
70
+ TriggerData,
71
+ VizScopedRequest,
72
+ RequiredVizRequest,
73
+ ConversationScopedRequest,
74
+ OpenFilterRequest,
75
+ OpenFilterLiveboardRequest,
76
+ OpenFilterSpotterRequest,
77
+ OpenFilterSearchRequest,
78
+ DrillDownRequest,
79
+ OpenParameterRequest,
80
+ SearchRequest,
81
+ SpotterSearchRequest,
82
+ CrossFilterCondition,
83
+ UpdateCrossFilterRequest,
84
+ HostFilterUpdate,
85
+ UpdateFiltersRequest,
86
+ PersonalisedViewRequest,
87
+ ScheduleEmailRequest,
88
+ NavigateRequest,
89
+ SetActiveTabRequest,
69
90
  LiveboardTab,
70
91
  LiveboardGroup,
71
92
  ApplicabilityLevel,
72
93
  Applicability,
73
94
  FilterUpdate,
74
95
  LiveboardFilter,
96
+ // UI passthrough request/response shapes (see UIPassthroughContractBase).
97
+ PinAnswerToLiveboardRequest,
98
+ PinAnswerToLiveboardResponse,
99
+ SaveAnswerRequest,
100
+ SaveAnswerResponse,
101
+ GetDiscoverabilityStatusResponse,
102
+ GetAvailableUIPassthroughsResponse,
103
+ GetAnswerConfigRequest,
104
+ GetUnsavedAnswerTMLRequest,
105
+ GetUnsavedAnswerTMLResponse,
106
+ GetAnswerSessionRequest,
107
+ GetAnswerSessionResponse,
108
+ GetFiltersRequest,
109
+ GetFiltersResponse,
110
+ GetIframeUrlResponse,
111
+ GetParametersResponse,
112
+ GetTMLRequest,
113
+ GetTabsResponse,
114
+ GetGroupsResponse,
115
+ GetExportRequestForCurrentPinboardResponse,
116
+ UpdateFiltersPassthroughRequest,
117
+ DrilldownRequest,
75
118
  LiveboardParameter,
76
119
  DataPanelCustomColumnGroupsAccordionState,
77
120
  InterceptedApiType,
78
121
  EmbedErrorSeverity,
122
+ CustomAction,
123
+ CustomActionPayload,
79
124
  CustomActionsPosition,
80
125
  CustomActionTarget,
81
126
  SpotterAnalystConfig,