@akohn/dashql-react 0.0.0-stage → 0.0.20-dev.661.gda3ac9a7e

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 (342) hide show
  1. package/LICENSE +373 -0
  2. package/NOTICE +66 -0
  3. package/README.md +46 -2
  4. package/dist/_virtual/_vite/preload-helper.js +100 -0
  5. package/dist/brand/brand.d.ts +13 -0
  6. package/dist/brand/brand.js +14 -0
  7. package/dist/brand/landing_backdrop.d.ts +56 -0
  8. package/dist/brand/landing_backdrop.js +1019 -0
  9. package/dist/brand/wobble_morph.d.ts +54 -0
  10. package/dist/brand/wobble_morph.js +439 -0
  11. package/dist/components/action_list.d.ts +31 -0
  12. package/dist/components/action_list.js +63 -0
  13. package/dist/components/action_list.module.js +11 -0
  14. package/dist/components/anchored_overlay.d.ts +28 -0
  15. package/dist/components/anchored_overlay.js +93 -0
  16. package/dist/components/button.d.ts +42 -0
  17. package/dist/components/button.js +97 -0
  18. package/dist/components/button.module.js +20 -0
  19. package/dist/components/button_group.d.ts +7 -0
  20. package/dist/components/button_group.js +18 -0
  21. package/dist/components/button_group.module.js +3 -0
  22. package/dist/components/card_placeholder.d.ts +9 -0
  23. package/dist/components/card_placeholder.js +39 -0
  24. package/dist/components/card_placeholder.module.js +6 -0
  25. package/dist/components/clipboard.d.ts +19 -0
  26. package/dist/components/clipboard.js +54 -0
  27. package/dist/components/data_table/computation_tables.d.ts +12 -0
  28. package/dist/components/data_table/computation_tables.js +42 -0
  29. package/dist/components/data_table/data_table.d.ts +38 -0
  30. package/dist/components/data_table/data_table.js +378 -0
  31. package/dist/components/data_table/data_table.module.js +41 -0
  32. package/dist/components/data_table/data_table_cell.d.ts +7 -0
  33. package/dist/components/data_table/data_table_cell.js +9 -0
  34. package/dist/components/data_table/data_table_cell_data.d.ts +21 -0
  35. package/dist/components/data_table/data_table_cell_data.js +99 -0
  36. package/dist/components/data_table/data_table_cell_header_name.d.ts +17 -0
  37. package/dist/components/data_table/data_table_cell_header_name.js +73 -0
  38. package/dist/components/data_table/data_table_cell_header_plots.d.ts +31 -0
  39. package/dist/components/data_table/data_table_cell_header_plots.js +122 -0
  40. package/dist/components/data_table/data_table_colors.d.ts +19 -0
  41. package/dist/components/data_table/data_table_colors.js +27 -0
  42. package/dist/components/data_table/data_table_column_resize.d.ts +21 -0
  43. package/dist/components/data_table/data_table_column_resize.js +121 -0
  44. package/dist/components/data_table/data_table_focus.d.ts +15 -0
  45. package/dist/components/data_table/data_table_focus.js +53 -0
  46. package/dist/components/data_table/data_table_layout.d.ts +18 -0
  47. package/dist/components/data_table/data_table_layout.js +103 -0
  48. package/dist/components/data_table/data_table_ordering.d.ts +9 -0
  49. package/dist/components/data_table/data_table_ordering.js +39 -0
  50. package/dist/components/data_table/data_table_portals.d.ts +9 -0
  51. package/dist/components/data_table/data_table_portals.js +29 -0
  52. package/dist/components/data_table/data_table_sticky_views.d.ts +34 -0
  53. package/dist/components/data_table/data_table_sticky_views.js +161 -0
  54. package/dist/components/data_table/data_table_window.d.ts +18 -0
  55. package/dist/components/data_table/data_table_window.js +118 -0
  56. package/dist/components/data_table/format_peek.d.ts +2 -0
  57. package/dist/components/data_table/format_peek.js +17 -0
  58. package/dist/components/data_table/histogram_bars.d.ts +36 -0
  59. package/dist/components/data_table/histogram_bars.js +100 -0
  60. package/dist/components/data_table/histogram_brush.d.ts +23 -0
  61. package/dist/components/data_table/histogram_brush.js +107 -0
  62. package/dist/components/data_table/histogram_cell.d.ts +19 -0
  63. package/dist/components/data_table/histogram_cell.js +325 -0
  64. package/dist/components/data_table/histogram_cell.module.js +9 -0
  65. package/dist/components/data_table/histogram_label.d.ts +1 -0
  66. package/dist/components/data_table/histogram_label.js +7 -0
  67. package/dist/components/data_table/memo_props.d.ts +1 -0
  68. package/dist/components/data_table/memo_props.js +17 -0
  69. package/dist/components/data_table/mostfrequent_cell.d.ts +17 -0
  70. package/dist/components/data_table/mostfrequent_cell.js +316 -0
  71. package/dist/components/data_table/mostfrequent_cell.module.js +10 -0
  72. package/dist/components/data_table/use_cross_filters.d.ts +14 -0
  73. package/dist/components/data_table/use_cross_filters.js +47 -0
  74. package/dist/components/deferred.d.ts +11 -0
  75. package/dist/components/deferred.js +41 -0
  76. package/dist/components/deferred.module.js +5 -0
  77. package/dist/components/error_boundary.d.ts +18 -0
  78. package/dist/components/error_boundary.js +15 -0
  79. package/dist/components/graph.module.js +15 -0
  80. package/dist/components/graph_port.d.ts +10 -0
  81. package/dist/components/graph_port.js +34 -0
  82. package/dist/components/inspector_overlay.d.ts +32 -0
  83. package/dist/components/inspector_overlay.js +72 -0
  84. package/dist/components/inspector_overlay.module.js +18 -0
  85. package/dist/components/json/json_arrow_symbol.d.ts +4 -0
  86. package/dist/components/json/json_arrow_symbol.js +25 -0
  87. package/dist/components/json/json_copy_button.d.ts +11 -0
  88. package/dist/components/json/json_copy_button.js +61 -0
  89. package/dist/components/json/json_ellipsis_symbol.d.ts +7 -0
  90. package/dist/components/json/json_ellipsis_symbol.js +11 -0
  91. package/dist/components/json/json_item_count.d.ts +5 -0
  92. package/dist/components/json/json_item_count.js +12 -0
  93. package/dist/components/json/json_key_name.d.ts +6 -0
  94. package/dist/components/json/json_key_name.js +40 -0
  95. package/dist/components/json/json_key_values.d.ts +12 -0
  96. package/dist/components/json/json_key_values.js +99 -0
  97. package/dist/components/json/json_literal.d.ts +8 -0
  98. package/dist/components/json/json_literal.js +140 -0
  99. package/dist/components/json/json_nested_close.d.ts +11 -0
  100. package/dist/components/json/json_nested_close.js +31 -0
  101. package/dist/components/json/json_nested_open.d.ts +18 -0
  102. package/dist/components/json/json_nested_open.js +150 -0
  103. package/dist/components/json/json_nested_state.d.ts +14 -0
  104. package/dist/components/json/json_nested_state.js +28 -0
  105. package/dist/components/json/json_tool_state.d.ts +18 -0
  106. package/dist/components/json/json_tool_state.js +46 -0
  107. package/dist/components/json/json_value.d.ts +10 -0
  108. package/dist/components/json/json_value.js +46 -0
  109. package/dist/components/json/json_view.d.ts +14 -0
  110. package/dist/components/json/json_view.js +37 -0
  111. package/dist/components/json/json_view.module.js +41 -0
  112. package/dist/components/json/json_view_state.d.ts +14 -0
  113. package/dist/components/json/json_view_state.js +32 -0
  114. package/dist/components/json/unique_key.d.ts +1 -0
  115. package/dist/components/json/unique_key.js +8 -0
  116. package/dist/components/keyvalue_list.d.ts +25 -0
  117. package/dist/components/keyvalue_list.js +106 -0
  118. package/dist/components/keyvalue_list.module.js +15 -0
  119. package/dist/components/name_input.d.ts +11 -0
  120. package/dist/components/name_input.js +51 -0
  121. package/dist/components/overlay.d.ts +53 -0
  122. package/dist/components/overlay.js +183 -0
  123. package/dist/components/overlay.module.js +32 -0
  124. package/dist/components/panel_resize_handle.d.ts +12 -0
  125. package/dist/components/panel_resize_handle.js +39 -0
  126. package/dist/components/portal.d.ts +8 -0
  127. package/dist/components/portal.js +53 -0
  128. package/dist/components/progress_bar.d.ts +7 -0
  129. package/dist/components/progress_bar.js +21 -0
  130. package/dist/components/progress_bar.module.js +3 -0
  131. package/dist/components/query_history_viewer.d.ts +33 -0
  132. package/dist/components/query_history_viewer.js +268 -0
  133. package/dist/components/query_history_viewer.module.js +7 -0
  134. package/dist/components/query_profile/engine_profile_view.d.ts +19 -0
  135. package/dist/components/query_profile/engine_profile_view.js +94 -0
  136. package/dist/components/query_profile/numeric_limits.d.ts +1 -0
  137. package/dist/components/query_profile/numeric_limits.js +2 -0
  138. package/dist/components/query_profile/profile_execution_controller.d.ts +14 -0
  139. package/dist/components/query_profile/profile_execution_controller.js +56 -0
  140. package/dist/components/query_profile/profile_fit.d.ts +24 -0
  141. package/dist/components/query_profile/profile_fit.js +22 -0
  142. package/dist/components/query_profile/profile_navigation.d.ts +3 -0
  143. package/dist/components/query_profile/profile_navigation.js +34 -0
  144. package/dist/components/query_profile/profile_scene.d.ts +64 -0
  145. package/dist/components/query_profile/profile_scene.js +422 -0
  146. package/dist/components/query_profile/query_profile_view.d.ts +44 -0
  147. package/dist/components/query_profile/query_profile_view.js +961 -0
  148. package/dist/components/query_profile/query_profile_view.module.js +23 -0
  149. package/dist/components/query_progress/query_profile_overlay.d.ts +7 -0
  150. package/dist/components/query_progress/query_profile_overlay.js +67 -0
  151. package/dist/components/query_progress/query_profile_overlay.module.js +6 -0
  152. package/dist/components/query_progress/query_progress_panel.d.ts +14 -0
  153. package/dist/components/query_progress/query_progress_panel.js +255 -0
  154. package/dist/components/query_progress/query_progress_panel.module.js +10 -0
  155. package/dist/components/query_result/cell_detail_overlay.d.ts +34 -0
  156. package/dist/components/query_result/cell_detail_overlay.js +277 -0
  157. package/dist/components/query_result/cell_detail_overlay.module.js +21 -0
  158. package/dist/components/query_result/query_result_action_menu.d.ts +12 -0
  159. package/dist/components/query_result/query_result_action_menu.js +62 -0
  160. package/dist/components/query_result/query_result_action_menu.module.js +2 -0
  161. package/dist/components/query_result/query_result_details.d.ts +17 -0
  162. package/dist/components/query_result/query_result_details.js +46 -0
  163. package/dist/components/query_result/query_result_details.module.js +5 -0
  164. package/dist/components/query_result/query_result_download_button.d.ts +8 -0
  165. package/dist/components/query_result/query_result_download_button.js +38 -0
  166. package/dist/components/query_result/query_result_header.d.ts +21 -0
  167. package/dist/components/query_result/query_result_header.js +71 -0
  168. package/dist/components/query_result/query_result_header.module.js +3 -0
  169. package/dist/components/query_result/query_result_search_controls.d.ts +12 -0
  170. package/dist/components/query_result/query_result_search_controls.js +141 -0
  171. package/dist/components/query_result/query_result_search_controls.module.js +7 -0
  172. package/dist/components/query_result/query_result_toolbar.d.ts +21 -0
  173. package/dist/components/query_result/query_result_toolbar.js +74 -0
  174. package/dist/components/query_result/result_table_overlay.d.ts +9 -0
  175. package/dist/components/query_result/result_table_overlay.js +73 -0
  176. package/dist/components/query_result/result_table_overlay.module.js +6 -0
  177. package/dist/components/query_result/use_query_result_search.d.ts +8 -0
  178. package/dist/components/query_result/use_query_result_search.js +28 -0
  179. package/dist/components/segmented_control.d.ts +58 -0
  180. package/dist/components/segmented_control.js +116 -0
  181. package/dist/components/segmented_control.module.js +17 -0
  182. package/dist/components/separator.d.ts +21 -0
  183. package/dist/components/separator.js +79 -0
  184. package/dist/components/separator.module.js +7 -0
  185. package/dist/components/size_observer.d.ts +7 -0
  186. package/dist/components/size_observer.js +57 -0
  187. package/dist/components/skeleton.d.ts +2 -0
  188. package/dist/components/skeleton.js +14 -0
  189. package/dist/components/skeleton.module.js +2 -0
  190. package/dist/components/spinners.d.ts +8 -0
  191. package/dist/components/spinners.js +33 -0
  192. package/dist/components/spinners.module.js +8 -0
  193. package/dist/components/status_indicator.d.ts +36 -0
  194. package/dist/components/status_indicator.js +182 -0
  195. package/dist/components/status_indicator.module.js +3 -0
  196. package/dist/components/symbol_icon.d.ts +65 -0
  197. package/dist/components/symbol_icon.js +213 -0
  198. package/dist/components/tab_header.d.ts +11 -0
  199. package/dist/components/tab_header.js +55 -0
  200. package/dist/components/tab_header.module.js +7 -0
  201. package/dist/components/tag.d.ts +10 -0
  202. package/dist/components/tag.js +17 -0
  203. package/dist/components/tag.module.js +4 -0
  204. package/dist/components/text_field.d.ts +44 -0
  205. package/dist/components/text_field.js +159 -0
  206. package/dist/components/text_field.module.js +15 -0
  207. package/dist/components/text_input.d.ts +25 -0
  208. package/dist/components/text_input.js +90 -0
  209. package/dist/components/text_input.module.js +13 -0
  210. package/dist/components/text_input_action.d.ts +19 -0
  211. package/dist/components/text_input_action.js +33 -0
  212. package/dist/components/text_input_action.module.js +2 -0
  213. package/dist/components/toggle_switch.d.ts +7 -0
  214. package/dist/components/toggle_switch.js +22 -0
  215. package/dist/components/toggle_switch.module.js +6 -0
  216. package/dist/components/tooltip.d.ts +22 -0
  217. package/dist/components/tooltip.js +139 -0
  218. package/dist/components/tooltip.module.js +2 -0
  219. package/dist/components/tree_entry.d.ts +17 -0
  220. package/dist/components/tree_entry.js +48 -0
  221. package/dist/components/tree_entry.module.js +9 -0
  222. package/dist/components/value_list.d.ts +17 -0
  223. package/dist/components/value_list.js +70 -0
  224. package/dist/components/value_list.module.js +8 -0
  225. package/dist/components/vegalite_chart.d.ts +18 -0
  226. package/dist/components/vegalite_chart.js +151 -0
  227. package/dist/components/vegalite_chart.module.js +3 -0
  228. package/dist/components/vegalite_view.d.ts +27 -0
  229. package/dist/components/vegalite_view.js +248 -0
  230. package/dist/components/vegalite_view.module.js +5 -0
  231. package/dist/components/vertical_scroll_shadows.d.ts +14 -0
  232. package/dist/components/vertical_scroll_shadows.js +55 -0
  233. package/dist/components/vertical_scroll_shadows.module.js +5 -0
  234. package/dist/components/vertical_split.d.ts +15 -0
  235. package/dist/components/vertical_split.js +112 -0
  236. package/dist/components/vertical_split.module.js +5 -0
  237. package/dist/components/vertical_tabs.d.ts +36 -0
  238. package/dist/components/vertical_tabs.js +169 -0
  239. package/dist/components/vertical_tabs.module.js +23 -0
  240. package/dist/components/visualization/capped_rows.d.ts +9 -0
  241. package/dist/components/visualization/capped_rows.js +23 -0
  242. package/dist/components/visualization/capped_rows.module.js +3 -0
  243. package/dist/components/visualization/chart_download_button.d.ts +12 -0
  244. package/dist/components/visualization/chart_download_button.js +41 -0
  245. package/dist/components/visualization/kpi_view.d.ts +10 -0
  246. package/dist/components/visualization/kpi_view.js +215 -0
  247. package/dist/components/visualization/kpi_view.module.js +17 -0
  248. package/dist/components/visualization/markdown_view.d.ts +17 -0
  249. package/dist/components/visualization/markdown_view.js +154 -0
  250. package/dist/components/visualization/markdown_view.module.js +4 -0
  251. package/dist/components/visualization/result_rows.d.ts +17 -0
  252. package/dist/components/visualization/result_rows.js +82 -0
  253. package/dist/components/visualization/vegalite_preview.d.ts +8 -0
  254. package/dist/components/visualization/vegalite_preview.js +17 -0
  255. package/dist/components/visualization/vegalite_preview.module.js +2 -0
  256. package/dist/components/visualization/visualization_dispatch.d.ts +14 -0
  257. package/dist/components/visualization/visualization_dispatch.js +41 -0
  258. package/dist/components/visualization/visualization_panel.d.ts +10 -0
  259. package/dist/components/visualization/visualization_panel.js +37 -0
  260. package/dist/components/visualization/visualization_panel.module.js +3 -0
  261. package/dist/dom/anchored_position.d.ts +42 -0
  262. package/dist/dom/anchored_position.js +255 -0
  263. package/dist/dom/app_host.d.ts +6 -0
  264. package/dist/dom/app_host.js +13 -0
  265. package/dist/dom/calm_frames.d.ts +24 -0
  266. package/dist/dom/calm_frames.js +96 -0
  267. package/dist/dom/classnames.d.ts +8 -0
  268. package/dist/dom/classnames.js +20 -0
  269. package/dist/dom/download_file.d.ts +1 -0
  270. package/dist/dom/download_file.js +12 -0
  271. package/dist/dom/focus.d.ts +29 -0
  272. package/dist/dom/focus.js +84 -0
  273. package/dist/dom/graph_edges.d.ts +53 -0
  274. package/dist/dom/graph_edges.js +450 -0
  275. package/dist/dom/key_events.d.ts +9 -0
  276. package/dist/dom/key_events.js +33 -0
  277. package/dist/dom/media_query.d.ts +2 -0
  278. package/dist/dom/media_query.js +15 -0
  279. package/dist/dom/outside_click.d.ts +8 -0
  280. package/dist/dom/outside_click.js +32 -0
  281. package/dist/dom/rerender_ref.d.ts +2 -0
  282. package/dist/dom/rerender_ref.js +11 -0
  283. package/dist/dom/row_context_menu.d.ts +7 -0
  284. package/dist/dom/row_context_menu.js +32 -0
  285. package/dist/dom/scrollbar.d.ts +3 -0
  286. package/dist/dom/scrollbar.js +23 -0
  287. package/dist/format/format.d.ts +11 -0
  288. package/dist/format/format.js +72 -0
  289. package/dist/format/query_progress_format.d.ts +17 -0
  290. package/dist/format/query_progress_format.js +69 -0
  291. package/dist/format/time_format.d.ts +5 -0
  292. package/dist/format/time_format.js +45 -0
  293. package/dist/hooks.d.ts +71 -0
  294. package/dist/hooks.js +302 -0
  295. package/dist/host.d.ts +10 -0
  296. package/dist/host.js +12 -0
  297. package/dist/logger.d.ts +4 -0
  298. package/dist/logger.js +6 -0
  299. package/dist/models/computation_model.d.ts +14 -0
  300. package/dist/models/computation_model.js +27 -0
  301. package/dist/models/query_model.d.ts +12 -0
  302. package/dist/models/query_model.js +27 -0
  303. package/dist/models/script_model.d.ts +17 -0
  304. package/dist/models/script_model.js +69 -0
  305. package/dist/style.css +4226 -0
  306. package/dist/svg_symbols.d.ts +2 -0
  307. package/dist/svg_symbols.js +2 -0
  308. package/dist/symbols.svg +1197 -0
  309. package/dist/theme/color_scheme.d.ts +4 -0
  310. package/dist/theme/color_scheme.js +28 -0
  311. package/dist/theme/xcode_palette.d.ts +22 -0
  312. package/dist/theme/xcode_palette.js +4 -0
  313. package/dist/theme/xcode_palettes.js +41 -0
  314. package/dist/utils/plan_engine.d.ts +2 -0
  315. package/dist/utils/plan_engine.js +13 -0
  316. package/dist/vegalite/vegalite_check.d.ts +1 -0
  317. package/dist/vegalite/vegalite_check.js +7 -0
  318. package/dist/vegalite/vegalite_crossfilter.d.ts +54 -0
  319. package/dist/vegalite/vegalite_crossfilter.js +187 -0
  320. package/dist/vegalite/vegalite_image.d.ts +16 -0
  321. package/dist/vegalite/vegalite_image.js +28 -0
  322. package/dist/vegalite/vegalite_loader.d.ts +7 -0
  323. package/dist/vegalite/vegalite_loader.js +15 -0
  324. package/dist/vegalite/vegalite_rows.d.ts +3 -0
  325. package/dist/vegalite/vegalite_rows.js +17 -0
  326. package/dist/vegalite/vegalite_theme.d.ts +11 -0
  327. package/dist/vegalite/vegalite_theme.js +125 -0
  328. package/fonts/InstrumentSans-Bold.ttf +0 -0
  329. package/fonts/InstrumentSans-Medium.ttf +0 -0
  330. package/fonts/InstrumentSans-OFL.txt +93 -0
  331. package/fonts/InstrumentSans-Regular.ttf +0 -0
  332. package/fonts/InstrumentSans-SemiBold.ttf +0 -0
  333. package/fonts/JetBrainsMono-Bold.ttf +0 -0
  334. package/fonts/JetBrainsMono-Medium.ttf +0 -0
  335. package/fonts/JetBrainsMono-OFL.txt +93 -0
  336. package/fonts/JetBrainsMono-Regular.ttf +0 -0
  337. package/fonts/JetBrainsMono-SemiBold.ttf +0 -0
  338. package/fonts/fonts.css +61 -0
  339. package/package.json +43 -4
  340. package/styles/colors.css +110 -0
  341. package/styles/flavors/dbcom.css +48 -0
  342. package/styles/tokens.css +192 -0
package/dist/hooks.js ADDED
@@ -0,0 +1,302 @@
1
+ import * as React from "react";
2
+ import { stringifyError } from "@akohn/dashql/platform/logger/logger";
3
+ var LOG_CTX = "runtime";
4
+ var RUNTIME_CTX = React.createContext(null);
5
+ var RuntimeContextProvider = RUNTIME_CTX.Provider;
6
+ function useRuntime() {
7
+ const runtime = React.useContext(RUNTIME_CTX);
8
+ if (runtime == null) throw new Error("the runtime needs a provider, e.g. RuntimeContextProvider");
9
+ return runtime;
10
+ }
11
+ function useOptionalRuntime() {
12
+ return React.useContext(RUNTIME_CTX);
13
+ }
14
+ function useOwnedRuntime(create) {
15
+ const owned = React.useRef(null);
16
+ if (owned.current == null) owned.current = {
17
+ runtime: create(),
18
+ release: null
19
+ };
20
+ React.useEffect(() => {
21
+ const held = owned.current;
22
+ if (held == null) return;
23
+ if (held.release != null) {
24
+ clearTimeout(held.release);
25
+ held.release = null;
26
+ }
27
+ return () => {
28
+ held.release = setTimeout(() => {
29
+ if (owned.current === held) owned.current = null;
30
+ held.runtime.destroy().catch((error) => {
31
+ held.runtime.logger.error("Failed to stop the runtime", { error: stringifyError(error) }, LOG_CTX);
32
+ });
33
+ }, 0);
34
+ };
35
+ }, []);
36
+ return owned.current.runtime;
37
+ }
38
+ var NO_SUBSCRIPTION = () => () => {};
39
+ function useViewSelector(kind, id, select) {
40
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
41
+ const subscribe = React.useMemo(() => store == null || id == null ? NO_SUBSCRIPTION : (listener) => store.subscribe(kind, id, listener), [
42
+ store,
43
+ kind,
44
+ id
45
+ ]);
46
+ const getSelection = () => select(store == null || id == null ? null : store.get(kind, id));
47
+ return React.useSyncExternalStore(subscribe, getSelection, getSelection);
48
+ }
49
+ function useView(kind, id) {
50
+ return useViewSelector(kind, id, selectView);
51
+ }
52
+ var selectView = (view) => view;
53
+ function useViewReader() {
54
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
55
+ return React.useCallback((kind, id) => store?.get(kind, id) ?? null, [store]);
56
+ }
57
+ function useAll(kind) {
58
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
59
+ const subscribe = React.useMemo(() => store == null ? NO_SUBSCRIPTION : (listener) => store.subscribeKind(kind, listener), [store, kind]);
60
+ const getSnapshot = React.useCallback(() => store?.all(kind) ?? NO_SLICES, [store, kind]);
61
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
62
+ }
63
+ var NO_SLICES = /* @__PURE__ */ new Map();
64
+ function useDispatch(target) {
65
+ const runtime = React.useContext(RUNTIME_CTX);
66
+ const key = target == null ? null : JSON.stringify(target);
67
+ return React.useCallback((action) => {
68
+ if (runtime == null) throw new Error("the runtime needs a provider, e.g. RuntimeContextProvider");
69
+ if (key == null) return {
70
+ ok: false,
71
+ changed: false,
72
+ error: "no target",
73
+ id: null,
74
+ settled: Promise.resolve()
75
+ };
76
+ return runtime.dispatch(JSON.parse(key), action);
77
+ }, [runtime, key]);
78
+ }
79
+ function useTable(handle) {
80
+ return React.useContext(RUNTIME_CTX)?.table(handle) ?? null;
81
+ }
82
+ var useWorkbook = (workbookId) => useView("workbook", workbookId);
83
+ function useWorkbookShown(workbookId) {
84
+ const runtime = React.useContext(RUNTIME_CTX);
85
+ React.useEffect(() => {
86
+ if (workbookId != null) runtime?.showWorkbook(workbookId);
87
+ }, [runtime, workbookId]);
88
+ }
89
+ var useScript = (scriptKey) => useView("script", scriptKey);
90
+ var useWorkbookDerived = (workbookId) => useView("workbookDerived", workbookId);
91
+ function useScriptReferences(workbookId, scriptKey) {
92
+ return useViewSelector("workbookDerived", workbookId, (derived) => scriptKey == null ? null : derived?.references.get(scriptKey) ?? null);
93
+ }
94
+ var selectInputs = (derived) => derived?.inputs ?? null;
95
+ var useWorkbookInputs = (workbookId) => useViewSelector("workbookDerived", workbookId, selectInputs);
96
+ var useWorkbookList = () => useView("workbookList", "root");
97
+ var useWorkbooks = () => useAll("workbook");
98
+ function useWorkbookScriptMap(workbookId) {
99
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
100
+ const cache = React.useRef({
101
+ keys: null,
102
+ scripts: [],
103
+ map: {}
104
+ });
105
+ const subscribe = React.useMemo(() => {
106
+ if (store == null || workbookId == null) return NO_SUBSCRIPTION;
107
+ return (listener) => {
108
+ const unsubscribeWorkbook = store.subscribe("workbook", workbookId, listener);
109
+ const unsubscribeScripts = store.subscribeKind("script", listener);
110
+ return () => {
111
+ unsubscribeWorkbook();
112
+ unsubscribeScripts();
113
+ };
114
+ };
115
+ }, [store, workbookId]);
116
+ const getSnapshot = React.useCallback(() => {
117
+ const keys = workbookId == null ? null : store?.get("workbook", workbookId)?.scriptKeys ?? null;
118
+ const scripts = (keys ?? []).map((key) => store?.get("script", key) ?? null);
119
+ const held = cache.current;
120
+ if (held.keys === keys && held.scripts.length === scripts.length && scripts.every((script, i) => script === held.scripts[i])) return held.map;
121
+ const map = {};
122
+ for (const script of scripts) if (script != null) map[script.scriptKey] = script;
123
+ cache.current = {
124
+ keys,
125
+ scripts,
126
+ map
127
+ };
128
+ return map;
129
+ }, [store, workbookId]);
130
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
131
+ }
132
+ var useConnection = (connectionId) => useView("connection", connectionId);
133
+ function useCatalog(connectionId) {
134
+ const runtime = React.useContext(RUNTIME_CTX);
135
+ const catalogId = useConnection(connectionId)?.catalogId ?? null;
136
+ return React.useMemo(() => runtime == null || connectionId == null || catalogId == null ? null : runtime.catalog(connectionId), [
137
+ runtime,
138
+ connectionId,
139
+ catalogId
140
+ ]);
141
+ }
142
+ var useConnectionList = () => useView("connectionList", "root");
143
+ var useConnections = () => useAll("connection");
144
+ function useConnectionViews(connectionIds) {
145
+ const connections = useConnections();
146
+ let resolved = null;
147
+ if (connectionIds != null && connectionIds.length > 0) {
148
+ const views = connectionIds.map((connectionId) => connections.get(connectionId));
149
+ if (views.every((view) => view != null)) resolved = views;
150
+ }
151
+ const latest = React.useRef(resolved);
152
+ if (!(latest.current === resolved || latest.current != null && resolved != null && latest.current.length === resolved.length && latest.current.every((connection, i) => connection === resolved[i]))) latest.current = resolved;
153
+ return latest.current;
154
+ }
155
+ var useQuery = (queryId) => useView("query", queryId);
156
+ var useAllQueries = () => useAll("query");
157
+ function useQueryResultTable(query) {
158
+ return useTable(query?.resultTable?.id ?? null);
159
+ }
160
+ function useQueryProfileDetail(queryId, enabled = true) {
161
+ const runtime = React.useContext(RUNTIME_CTX);
162
+ React.useEffect(() => {
163
+ if (!enabled || queryId == null || runtime == null) return;
164
+ return runtime.watchProfile(queryId);
165
+ }, [
166
+ runtime,
167
+ queryId,
168
+ enabled
169
+ ]);
170
+ }
171
+ var useComputation = (tableId) => useView("computation", tableId);
172
+ var useComputationDispatch = (tableId) => useDispatch(tableId == null ? null : { computation: tableId });
173
+ function useTableComputation(load, clientContext = null) {
174
+ const runtime = useRuntime();
175
+ const [state, setState] = React.useState({ status: "idle" });
176
+ const shown = React.useRef(null);
177
+ const release = React.useCallback((tableId) => {
178
+ runtime.dispatch({ computation: tableId }, { kind: "deleteComputation" });
179
+ }, [runtime]);
180
+ React.useEffect(() => () => {
181
+ if (shown.current != null) release(shown.current);
182
+ shown.current = null;
183
+ }, [release]);
184
+ React.useEffect(() => {
185
+ if (load == null) return;
186
+ let current = true;
187
+ setState((state) => state.status === "ready" ? state : { status: "loading" });
188
+ (async () => {
189
+ let tableId = null;
190
+ try {
191
+ const table = await load();
192
+ if (!current) return;
193
+ tableId = runtime.allocateId();
194
+ const ordering = shown.current == null ? [] : runtime.store.get("computation", shown.current)?.dataTableOrdering ?? [];
195
+ await runtime.analyzeTable(tableId, table, {
196
+ clientContext,
197
+ columnAggregates: false,
198
+ ordering
199
+ });
200
+ if (!current) {
201
+ release(tableId);
202
+ return;
203
+ }
204
+ const previous = shown.current;
205
+ shown.current = tableId;
206
+ setState({
207
+ status: "ready",
208
+ tableId,
209
+ table
210
+ });
211
+ if (previous != null) release(previous);
212
+ } catch (error) {
213
+ if (tableId != null) release(tableId);
214
+ runtime.logger.warn("Loading a table failed", { error: stringifyError(error) }, LOG_CTX);
215
+ if (current) setState((state) => state.status === "ready" ? state : {
216
+ status: "failed",
217
+ error: stringifyError(error)
218
+ });
219
+ }
220
+ })();
221
+ return () => {
222
+ current = false;
223
+ };
224
+ }, [
225
+ runtime,
226
+ release,
227
+ load,
228
+ clientContext
229
+ ]);
230
+ return state;
231
+ }
232
+ function useComputeReady() {
233
+ const database = React.useContext(RUNTIME_CTX)?.computeDatabase ?? null;
234
+ const subscribe = React.useMemo(() => database == null ? NO_SUBSCRIPTION : (listener) => database.subscribe(listener), [database]);
235
+ const getSnapshot = React.useCallback(() => database?.ready ?? false, [database]);
236
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
237
+ }
238
+ function useComputeDatabase() {
239
+ const runtime = React.useContext(RUNTIME_CTX);
240
+ const ready = useComputeReady();
241
+ const [database, setDatabase] = React.useState(null);
242
+ React.useEffect(() => {
243
+ if (runtime == null || !ready) return;
244
+ let current = true;
245
+ runtime.computeDatabase.get().then((resolved) => {
246
+ if (current) setDatabase(resolved);
247
+ }, () => {});
248
+ return () => {
249
+ current = false;
250
+ };
251
+ }, [runtime, ready]);
252
+ return ready ? database : null;
253
+ }
254
+ function useWorkbookExecution(workbookId) {
255
+ const runtime = React.useContext(RUNTIME_CTX);
256
+ const run = useView("run", workbookId);
257
+ const ready = useComputeReady();
258
+ const state = run?.state ?? null;
259
+ const held = run?.held != null;
260
+ return React.useMemo(() => {
261
+ const busy = state?.busy ?? false;
262
+ return {
263
+ state,
264
+ busy,
265
+ ready,
266
+ runActive: busy || held,
267
+ start: (options) => {
268
+ if (runtime == null) return;
269
+ const failed = (error) => runtime.logger.error("The run of the workbook failed", {
270
+ workbookId,
271
+ error: stringifyError(error)
272
+ }, "workbook_execution");
273
+ runtime.runWorkbook(workbookId, { inputs: options?.inputs == null ? void 0 : [...options.inputs] }).then((result) => {
274
+ const failure = result.outcome.failure;
275
+ if (failure != null && failure.kind === "error" && failure.queryId == null) failed(result.error);
276
+ }, failed);
277
+ },
278
+ stop: () => runtime?.stopRun(workbookId)
279
+ };
280
+ }, [
281
+ state,
282
+ held,
283
+ runtime,
284
+ workbookId,
285
+ ready
286
+ ]);
287
+ }
288
+ function useScriptRun() {
289
+ const runtime = React.useContext(RUNTIME_CTX);
290
+ return React.useMemo(() => runtime == null ? null : async (workbookId, scriptKey, options = {}) => {
291
+ try {
292
+ await runtime.runScript(workbookId, scriptKey, { refresh: options.refresh });
293
+ } catch (error) {
294
+ runtime.logger.warn("Workbook script run failed", {
295
+ workbookId,
296
+ scriptKey: scriptKey.toString(),
297
+ error: stringifyError(error)
298
+ }, "workbook_execution");
299
+ }
300
+ }, [runtime]);
301
+ }
302
+ export { RuntimeContextProvider, useAllQueries, useCatalog, useComputation, useComputationDispatch, useComputeDatabase, useComputeReady, useConnection, useConnectionList, useConnectionViews, useConnections, useDispatch, useOptionalRuntime, useOwnedRuntime, useQuery, useQueryProfileDetail, useQueryResultTable, useRuntime, useScript, useScriptReferences, useScriptRun, useTable, useTableComputation, useView, useViewReader, useViewSelector, useWorkbook, useWorkbookDerived, useWorkbookExecution, useWorkbookInputs, useWorkbookList, useWorkbookScriptMap, useWorkbookShown, useWorkbooks };
package/dist/host.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import type * as dashql from '@akohn/dashql';
3
+ export type CoreSetup = (context: string) => Promise<dashql.DashQL>;
4
+ export type DownloadFile = (data: Uint8Array | Blob, fileName: string) => Promise<void>;
5
+ export interface Host {
6
+ setupCore: CoreSetup | null;
7
+ downloadFile: DownloadFile;
8
+ }
9
+ export declare const HostProvider: React.Provider<Host>;
10
+ export declare function useHost(): Host;
package/dist/host.js ADDED
@@ -0,0 +1,12 @@
1
+ import { downloadFile } from "./dom/download_file.js";
2
+ import * as React from "react";
3
+ var DEFAULT_HOST = {
4
+ setupCore: null,
5
+ downloadFile
6
+ };
7
+ var HOST = React.createContext(DEFAULT_HOST);
8
+ var HostProvider = HOST.Provider;
9
+ function useHost() {
10
+ return React.useContext(HOST);
11
+ }
12
+ export { HostProvider, useHost };
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import type { Logger } from '@akohn/dashql/platform/logger/logger';
3
+ export declare const LoggerContext: React.Context<Logger | null>;
4
+ export declare function useLogger(): Logger;
package/dist/logger.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ var LoggerContext = React.createContext(null);
3
+ function useLogger() {
4
+ return React.useContext(LoggerContext);
5
+ }
6
+ export { LoggerContext, useLogger };
@@ -0,0 +1,14 @@
1
+ import * as arrow from 'apache-arrow';
2
+ import type * as core from '@akohn/dashql';
3
+ import type { ComputationView } from '@akohn/dashql';
4
+ import type { ResultRowWindow } from '@akohn/dashql/runtime';
5
+ import type { SummaryTables } from '@akohn/dashql/platform/compute/computation_types';
6
+ export interface ComputationModel {
7
+ readonly computation: ComputationView;
8
+ readonly tables: SummaryTables;
9
+ dispatch(action: core.ComputationAction): core.DispatchOutcome;
10
+ readRows(offset: number, limit: number): Promise<ResultRowWindow>;
11
+ previewRows(offset: number, limit: number, rowNumbers: boolean): Promise<arrow.Table>;
12
+ }
13
+ export type { ResultRowWindow };
14
+ export declare function useComputationModel(computation: ComputationView | null | undefined): ComputationModel | null;
@@ -0,0 +1,27 @@
1
+ import { useComputationDispatch, useOptionalRuntime } from "../hooks.js";
2
+ import * as React from "react";
3
+ import * as arrow from "apache-arrow";
4
+ var NO_TABLES = { table: () => void 0 };
5
+ var noRows = async () => {
6
+ throw new Error("there is no runtime to read the rows from");
7
+ };
8
+ function useComputationModel(computation) {
9
+ const runtime = useOptionalRuntime();
10
+ const dispatch = useComputationDispatch(computation?.tableId);
11
+ return React.useMemo(() => {
12
+ if (computation == null) return null;
13
+ const tableId = computation.tableId;
14
+ return {
15
+ computation,
16
+ tables: runtime ?? NO_TABLES,
17
+ dispatch,
18
+ readRows: runtime == null ? noRows : (offset, limit) => runtime.readResultRows(tableId, offset, limit),
19
+ previewRows: runtime == null ? noRows : async (offset, limit, rowNumbers) => arrow.tableFromIPC(await runtime.previewResult(tableId, offset, limit, rowNumbers))
20
+ };
21
+ }, [
22
+ runtime,
23
+ computation,
24
+ dispatch
25
+ ]);
26
+ }
27
+ export { useComputationModel };
@@ -0,0 +1,12 @@
1
+ import type * as arrow from 'apache-arrow';
2
+ import type { QueryExecutionProgress, QueryExecutionState } from '@akohn/dashql/platform/query/query_execution_state';
3
+ import { type ComputationModel } from './computation_model.js';
4
+ export interface QueryModel {
5
+ readonly queryId: number;
6
+ readonly query: QueryExecutionState;
7
+ readonly progress: QueryExecutionProgress | null;
8
+ readonly result: arrow.Table | null;
9
+ readonly computation: ComputationModel | null;
10
+ cancel(): Promise<void>;
11
+ }
12
+ export declare function useQueryModel(queryId: number | null | undefined): QueryModel | null;
@@ -0,0 +1,27 @@
1
+ import { useComputation, useOptionalRuntime, useQuery, useTable } from "../hooks.js";
2
+ import { useComputationModel } from "./computation_model.js";
3
+ import * as React from "react";
4
+ function useQueryModel(queryId) {
5
+ const runtime = useOptionalRuntime();
6
+ const query = useQuery(queryId);
7
+ const result = useTable(query?.resultTable?.id ?? null);
8
+ const computation = useComputationModel(useComputation(queryId));
9
+ return React.useMemo(() => {
10
+ if (query == null || queryId == null) return null;
11
+ return {
12
+ queryId,
13
+ query,
14
+ progress: query.progress ?? null,
15
+ result,
16
+ computation,
17
+ cancel: async () => await runtime?.cancel(queryId)
18
+ };
19
+ }, [
20
+ runtime,
21
+ queryId,
22
+ query,
23
+ result,
24
+ computation
25
+ ]);
26
+ }
27
+ export { useQueryModel };
@@ -0,0 +1,17 @@
1
+ import type { ScriptData } from '@akohn/dashql/platform/workbook/workbook_scripts';
2
+ import { type QueryModel } from './query_model.js';
3
+ export interface ScriptModel {
4
+ readonly workbookId: string;
5
+ readonly script: ScriptData;
6
+ readonly query: QueryModel | null;
7
+ readonly runActive: boolean;
8
+ run(options?: {
9
+ refresh?: boolean;
10
+ }): Promise<void>;
11
+ cancel(): Promise<void>;
12
+ setText(text: string): Promise<void>;
13
+ acceptDiff(): Promise<void>;
14
+ rejectDiff(): Promise<void>;
15
+ setVisSpec(spec: string): Promise<void>;
16
+ }
17
+ export declare function useScriptModel(workbookId: string, scriptKey: number | null | undefined): ScriptModel | null;
@@ -0,0 +1,69 @@
1
+ import { useDispatch, useOptionalRuntime, useScript, useViewSelector } from "../hooks.js";
2
+ import { useQueryModel } from "./query_model.js";
3
+ import * as React from "react";
4
+ import { stringifyError } from "@akohn/dashql/platform/logger/logger";
5
+ function useScriptModel(workbookId, scriptKey) {
6
+ const runtime = useOptionalRuntime();
7
+ const script = useScript(scriptKey);
8
+ const query = useQueryModel(script?.latestQueryId ?? null);
9
+ const runActive = useViewSelector("run", workbookId, (run) => run?.state?.busy === true || run?.held != null);
10
+ const dispatch = useDispatch({ workbook: workbookId });
11
+ const key = script?.scriptKey ?? null;
12
+ const operations = React.useMemo(() => key == null ? null : {
13
+ run: async (options) => {
14
+ if (runtime == null) return;
15
+ try {
16
+ await runtime.runScript(workbookId, key, { refresh: options?.refresh });
17
+ } catch (error) {
18
+ runtime.logger.warn("Workbook script run failed", {
19
+ workbookId,
20
+ scriptKey: key.toString(),
21
+ error: stringifyError(error)
22
+ }, "workbook_execution");
23
+ }
24
+ },
25
+ cancel: async () => await runtime?.cancelScript(workbookId, key),
26
+ setText: (text) => dispatch({
27
+ kind: "setScriptText",
28
+ value: {
29
+ scriptKey: key,
30
+ text,
31
+ withDiff: true
32
+ }
33
+ }).settled,
34
+ acceptDiff: () => dispatch({
35
+ kind: "acceptPendingDiff",
36
+ value: { scriptKey: key }
37
+ }).settled,
38
+ rejectDiff: () => dispatch({
39
+ kind: "rejectPendingDiff",
40
+ value: { scriptKey: key }
41
+ }).settled,
42
+ setVisSpec: (spec) => dispatch({
43
+ kind: "setScriptVisSpec",
44
+ value: {
45
+ scriptKey: key,
46
+ spec
47
+ }
48
+ }).settled
49
+ }, [
50
+ runtime,
51
+ workbookId,
52
+ key,
53
+ dispatch
54
+ ]);
55
+ return React.useMemo(() => script == null || operations == null ? null : {
56
+ workbookId,
57
+ script,
58
+ query,
59
+ runActive,
60
+ ...operations
61
+ }, [
62
+ workbookId,
63
+ script,
64
+ query,
65
+ runActive,
66
+ operations
67
+ ]);
68
+ }
69
+ export { useScriptModel };