@marimo-team/islands 0.16.1 → 0.16.3

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 (238) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DyqLQGPc.js → ConnectedDataExplorerComponent-CareOso9.js} +2 -2
  2. package/dist/{ImageComparisonComponent-CQDGJfUA.js → ImageComparisonComponent-I_Z738Uj.js} +1 -1
  3. package/dist/{_baseUniq-B2Nna6Kt.js → _baseUniq-D-Kb4EU4.js} +1 -1
  4. package/dist/{any-language-editor-D-wq0tOG.js → any-language-editor-BRWmYor8.js} +1 -1
  5. package/dist/{architectureDiagram-W76B3OCA-C6tdnMBf.js → architectureDiagram-W76B3OCA-bZJcJYGH.js} +4 -4
  6. package/dist/assets/{worker-B0C57BK8.js → worker-DMlIUTIq.js} +18 -17
  7. package/dist/{blockDiagram-QIGZ2CNN-IagL8LCN.js → blockDiagram-QIGZ2CNN-DyXjO8fR.js} +5 -5
  8. package/dist/{c4Diagram-FPNF74CW-D3_lIWUP.js → c4Diagram-FPNF74CW-Bfs9ui2r.js} +2 -2
  9. package/dist/{channel-DCJI_DKk.js → channel-CMup9X3Z.js} +1 -1
  10. package/dist/{chunk-4BX2VUAB-B2DrODwN.js → chunk-4BX2VUAB-CW-ni6M_.js} +1 -1
  11. package/dist/{chunk-55IACEB6-BUWDsQ-t.js → chunk-55IACEB6-Bj-Indya.js} +1 -1
  12. package/dist/{chunk-FMBD7UC4-BExPNFv1.js → chunk-FMBD7UC4-9IC8qSSk.js} +1 -1
  13. package/dist/{chunk-K7UQS3LO-Cixi-Yko.js → chunk-K7UQS3LO-aapkEuWN.js} +4 -4
  14. package/dist/{chunk-QN33PNHL-B83MtvER.js → chunk-QN33PNHL-Bo5dJ5T5.js} +1 -1
  15. package/dist/{chunk-QZHKN3VN-CXvbu85X.js → chunk-QZHKN3VN-BkMzjJYY.js} +1 -1
  16. package/dist/{chunk-TVAH2DTR-CpiumCHg.js → chunk-TVAH2DTR-Wqy_C_Rn.js} +3 -3
  17. package/dist/{chunk-TZMSLE5B-DIzaZjcI.js → chunk-TZMSLE5B-DjBmEAUz.js} +1 -1
  18. package/dist/{classDiagram-v2-RKCZMP56-DyN5HPdk.js → classDiagram-KNZD7YFC-DUsaN1O4.js} +2 -2
  19. package/dist/{classDiagram-KNZD7YFC-DyN5HPdk.js → classDiagram-v2-RKCZMP56-DUsaN1O4.js} +2 -2
  20. package/dist/{clone-DrJYap2i.js → clone-Dkt_7KOK.js} +1 -1
  21. package/dist/{cose-bilkent-S5V4N54A-D39b4WrQ.js → cose-bilkent-S5V4N54A-ClBuGZWI.js} +2 -2
  22. package/dist/{dagre-5GWH7T2D-BLjRxDpS.js → dagre-5GWH7T2D-BzmDIGaM.js} +6 -6
  23. package/dist/{data-grid-overlay-editor-DTALqerV.js → data-grid-overlay-editor-NiU9Ea77.js} +2 -2
  24. package/dist/{diagram-N5W7TBWH-MM8AIKGR.js → diagram-N5W7TBWH-BlO1yw_g.js} +5 -5
  25. package/dist/{diagram-QEK2KX5R-BZGarWuJ.js → diagram-QEK2KX5R-BvK83LUx.js} +3 -3
  26. package/dist/{diagram-S2PKOQOG-CnPinN9Q.js → diagram-S2PKOQOG-DvBzRYd7.js} +3 -3
  27. package/dist/{dockerfile-U8DnCJ4X.js → dockerfile-CPQG2tLO.js} +1 -1
  28. package/dist/{erDiagram-AWTI2OKA-CvDVbxOO.js → erDiagram-AWTI2OKA-Doy9FRTX.js} +4 -4
  29. package/dist/{flowDiagram-PVAE7QVJ-C2uuBTZS.js → flowDiagram-PVAE7QVJ-D_tX_HU1.js} +5 -5
  30. package/dist/{ganttDiagram-OWAHRB6G-BEff10RF.js → ganttDiagram-OWAHRB6G-CV03BHVY.js} +4 -4
  31. package/dist/{gitGraphDiagram-NY62KEGX-wggu0kb2.js → gitGraphDiagram-NY62KEGX-w3szEguZ.js} +4 -4
  32. package/dist/{glide-data-editor-Bqh5_dzJ.js → glide-data-editor-akznFrmp.js} +3 -3
  33. package/dist/{graph-DKpp_wzf.js → graph-CjrrDHdT.js} +3 -3
  34. package/dist/index-CIJJs0Tu.js +40382 -0
  35. package/dist/{index-DzJ_YPCG.js → index-DMo6cbcV.js} +3 -3
  36. package/dist/{index-4XruEJkp.js → index-DlV2CtJb.js} +1 -1
  37. package/dist/{index-DdfF_cLK.js → index-Y-Vbae6Z.js} +1 -1
  38. package/dist/{infoDiagram-STP46IZ2-DF7KW-Op.js → infoDiagram-STP46IZ2-BcBV2j75.js} +2 -2
  39. package/dist/{journeyDiagram-BIP6EPQ6-B_jmhmqd.js → journeyDiagram-BIP6EPQ6-BTGMSgvB.js} +3 -3
  40. package/dist/{kanban-definition-6OIFK2YF-B-M9FTyw.js → kanban-definition-6OIFK2YF-aopNqZ1Y.js} +2 -2
  41. package/dist/{layout-C4oVYZZD.js → layout-Dvo9pb_w.js} +4 -4
  42. package/dist/{linear-C-HCGr0T.js → linear-CHnELER9.js} +1 -1
  43. package/dist/{main-B9x2-9f2.js → main-kLZGkzVQ.js} +41787 -40423
  44. package/dist/main.js +1 -1
  45. package/dist/{mermaid-BE4cM3Qs.js → mermaid-DgM4_4bD.js} +30 -30
  46. package/dist/{min-DTpHJ698.js → min-cX4DuL_n.js} +2 -2
  47. package/dist/{mindmap-definition-Q6HEUPPD-Cpd-hO1E.js → mindmap-definition-Q6HEUPPD-DZjbYryy.js} +3 -3
  48. package/dist/{number-overlay-editor-CvURA2Ud.js → number-overlay-editor-8MpIObf7.js} +2 -2
  49. package/dist/{pieDiagram-ADFJNKIX-D9f_f6fn.js → pieDiagram-ADFJNKIX-D6L1IYAc.js} +3 -3
  50. package/dist/{quadrantDiagram-LMRXKWRM-DgllE7xw.js → quadrantDiagram-LMRXKWRM-nOyuc3Bf.js} +2 -2
  51. package/dist/{react-plotly-BU-JRJSi.js → react-plotly-ChkfYiVe.js} +1 -1
  52. package/dist/{requirementDiagram-4UW4RH46-Dk_G8eUb.js → requirementDiagram-4UW4RH46-OVV8wsju.js} +3 -3
  53. package/dist/{sankeyDiagram-GR3RE2ED-BhLIhDc1.js → sankeyDiagram-GR3RE2ED-qZHMdnE_.js} +1 -1
  54. package/dist/{sequenceDiagram-C3RYC4MD-DHoZdMFJ.js → sequenceDiagram-C3RYC4MD-D0bOqf-t.js} +3 -3
  55. package/dist/{slides-component-DXAgdf7K.js → slides-component-CNzLDdA3.js} +1 -1
  56. package/dist/{stateDiagram-KXAO66HF-C1Ie-7Xf.js → stateDiagram-KXAO66HF-CFNCnNJS.js} +4 -4
  57. package/dist/{stateDiagram-v2-UMBNRL4Z--CRuIHtM.js → stateDiagram-v2-UMBNRL4Z-CnIh27m8.js} +2 -2
  58. package/dist/style.css +1 -1
  59. package/dist/{time-yQjlGPwa.js → time-Z7CJSfOW.js} +2 -2
  60. package/dist/{timeline-definition-XQNQX7LJ-D_PjxB1B.js → timeline-definition-XQNQX7LJ-BYLMfrvK.js} +1 -1
  61. package/dist/{treemap-75Q7IDZK--NYqQjUZ.js → treemap-75Q7IDZK-BEh1HacP.js} +5 -5
  62. package/dist/{vega-component-CCUOMM5K.js → vega-component-iMjXd3tD.js} +2 -2
  63. package/dist/{xychartDiagram-6GGTOJPD-WLKsEnzs.js → xychartDiagram-6GGTOJPD-Bmi13ZSG.js} +2 -2
  64. package/package.json +8 -8
  65. package/src/__mocks__/common.ts +5 -3
  66. package/src/__mocks__/notebook.ts +2 -2
  67. package/src/__mocks__/requests.ts +1 -0
  68. package/src/__tests__/main.test.tsx +2 -2
  69. package/src/components/ai/ai-provider-icon.tsx +2 -0
  70. package/src/components/app-config/ai-config.tsx +32 -1
  71. package/src/components/app-config/common.tsx +2 -2
  72. package/src/components/app-config/user-config-form.tsx +26 -0
  73. package/src/components/audio/audio-recorder.tsx +0 -1
  74. package/src/components/chat/acp/blocks.tsx +2 -2
  75. package/src/components/chat/acp/thread.tsx +3 -5
  76. package/src/components/chat/acp/utils.ts +5 -5
  77. package/src/components/chat/chat-panel.tsx +1 -1
  78. package/src/components/data-table/__tests__/columns.test.tsx +38 -0
  79. package/src/components/data-table/__tests__/data-table.test.tsx +2 -2
  80. package/src/components/data-table/cell-hover-template/feature.ts +1 -1
  81. package/src/components/data-table/cell-hover-template/types.ts +1 -1
  82. package/src/components/data-table/charts/__tests__/altair-generator.test.ts +1 -1
  83. package/src/components/data-table/charts/chart-spec/tooltips.ts +3 -3
  84. package/src/components/data-table/charts/components/chart-items.tsx +1 -1
  85. package/src/components/data-table/charts/components/form-fields.tsx +2 -2
  86. package/src/components/data-table/charts/constants.ts +1 -1
  87. package/src/components/data-table/column-explorer-panel/column-explorer.tsx +1 -1
  88. package/src/components/data-table/column-summary/chart-spec-model.tsx +2 -2
  89. package/src/components/data-table/columns.tsx +22 -3
  90. package/src/components/data-table/data-table.tsx +35 -3
  91. package/src/components/data-table/date-popover.tsx +1 -1
  92. package/src/components/data-table/download-actions.tsx +1 -1
  93. package/src/components/data-table/range-focus/__tests__/utils.test.ts +5 -5
  94. package/src/components/data-table/renderers.tsx +22 -13
  95. package/src/components/data-table/row-viewer-panel/row-viewer.tsx +1 -1
  96. package/src/components/data-table/schemas.ts +16 -0
  97. package/src/components/data-table/types.ts +4 -3
  98. package/src/components/datasources/column-preview.tsx +9 -6
  99. package/src/components/debugger/debugger-code.tsx +1 -1
  100. package/src/components/dependency-graph/custom-node.tsx +15 -6
  101. package/src/components/dependency-graph/dependency-graph-minimap.tsx +2 -2
  102. package/src/components/dependency-graph/dependency-graph-tree.tsx +2 -2
  103. package/src/components/dependency-graph/dependency-graph.tsx +1 -1
  104. package/src/components/dependency-graph/elements.ts +7 -7
  105. package/src/components/dependency-graph/utils/changes.ts +4 -4
  106. package/src/components/editor/Cell.tsx +7 -1
  107. package/src/components/editor/ai/transport/chat-transport.tsx +1 -1
  108. package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +1 -1
  109. package/src/components/editor/chrome/panels/packages-panel.tsx +1 -1
  110. package/src/components/editor/columns/storage.ts +1 -1
  111. package/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap +36 -0
  112. package/src/components/editor/database/__tests__/as-code.test.ts +30 -7
  113. package/src/components/editor/database/add-database-form.tsx +11 -0
  114. package/src/components/editor/database/as-code.ts +104 -5
  115. package/src/components/editor/database/schemas.ts +36 -18
  116. package/src/components/editor/errors/auto-fix.tsx +12 -2
  117. package/src/components/editor/errors/sql-validation-errors.tsx +40 -0
  118. package/src/components/editor/navigation/clipboard.ts +2 -2
  119. package/src/components/editor/output/ConsoleOutput.tsx +14 -2
  120. package/src/components/editor/output/JsonOutput.tsx +1 -1
  121. package/src/components/editor/output/MarimoErrorOutput.tsx +60 -1
  122. package/src/components/editor/output/MarimoTracebackOutput.tsx +17 -2
  123. package/src/components/editor/renderers/grid-layout/types.ts +2 -2
  124. package/src/components/editor/renderers/plugins.ts +1 -1
  125. package/src/components/editor/renderers/types.ts +1 -1
  126. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +7 -7
  127. package/src/components/forms/form.tsx +5 -5
  128. package/src/components/ui/links.tsx +1 -0
  129. package/src/core/ai/__tests__/model-registry.test.ts +0 -10
  130. package/src/core/ai/context/providers/cell-output.ts +1 -18
  131. package/src/core/ai/context/providers/error.ts +2 -2
  132. package/src/core/ai/ids/ids.ts +1 -0
  133. package/src/core/ai/model-registry.ts +2 -1
  134. package/src/core/cells/cells.ts +5 -5
  135. package/src/core/cells/logs.ts +1 -1
  136. package/src/core/cells/types.ts +1 -1
  137. package/src/core/codemirror/__tests__/format.test.ts +6 -0
  138. package/src/core/codemirror/cells/traceback-decorations.ts +1 -1
  139. package/src/core/codemirror/editing/commands.ts +2 -2
  140. package/src/core/codemirror/find-replace/navigate.ts +1 -1
  141. package/src/core/codemirror/language/__tests__/extension.test.ts +24 -0
  142. package/src/core/codemirror/language/__tests__/sql-validation.test.ts +133 -0
  143. package/src/core/codemirror/language/__tests__/sql.test.ts +764 -79
  144. package/src/core/codemirror/language/languages/markdown.ts +4 -1
  145. package/src/core/codemirror/language/languages/sql/banner-validation-errors.ts +85 -0
  146. package/src/core/codemirror/language/languages/sql/completion-builder.ts +160 -0
  147. package/src/core/codemirror/language/languages/sql/completion-sources.tsx +9 -3
  148. package/src/core/codemirror/language/languages/sql/completion-store.ts +46 -50
  149. package/src/core/codemirror/language/languages/sql/renderers.tsx +485 -0
  150. package/src/core/codemirror/language/languages/sql/sql-mode.ts +20 -0
  151. package/src/core/codemirror/language/languages/sql/sql.ts +218 -4
  152. package/src/core/codemirror/language/languages/sql/utils.ts +4 -1
  153. package/src/core/codemirror/language/panel/panel.tsx +8 -2
  154. package/src/core/codemirror/language/panel/sql.tsx +86 -4
  155. package/src/core/codemirror/language/utils/ast.ts +3 -3
  156. package/src/core/codemirror/lsp/federated-lsp.ts +4 -4
  157. package/src/core/codemirror/lsp/lens.ts +4 -4
  158. package/src/core/codemirror/lsp/notebook-lsp.ts +1 -1
  159. package/src/core/codemirror/lsp/types.ts +1 -1
  160. package/src/core/codemirror/markdown/completions.ts +1 -1
  161. package/src/core/codemirror/reactive-references/analyzer.ts +2 -2
  162. package/src/core/codemirror/rtc/loro/awareness.ts +1 -1
  163. package/src/core/config/config-schema.ts +1 -0
  164. package/src/core/config/feature-flag.tsx +6 -2
  165. package/src/core/datasets/request-registry.ts +24 -1
  166. package/src/core/dom/events.ts +1 -1
  167. package/src/core/dom/outline.ts +2 -2
  168. package/src/core/dom/uiregistry.ts +2 -8
  169. package/src/core/errors/__tests__/errors.test.ts +22 -4
  170. package/src/core/errors/errors.ts +29 -1
  171. package/src/core/errors/state.ts +1 -1
  172. package/src/core/islands/bridge.ts +1 -0
  173. package/src/core/islands/main.ts +3 -2
  174. package/src/core/islands/parse.ts +1 -3
  175. package/src/core/kernel/messages.ts +2 -1
  176. package/src/core/network/CachingRequestRegistry.ts +74 -0
  177. package/src/core/network/DeferredRequestRegistry.ts +3 -1
  178. package/src/core/network/__tests__/CachingRequestRegistry.test.ts +73 -0
  179. package/src/core/network/requests-network.ts +7 -0
  180. package/src/core/network/requests-static.ts +1 -0
  181. package/src/core/network/requests-toasting.ts +1 -0
  182. package/src/core/network/types.ts +3 -1
  183. package/src/core/variables/state.ts +2 -2
  184. package/src/core/wasm/__tests__/state.test.ts +1 -1
  185. package/src/core/wasm/bridge.ts +5 -0
  186. package/src/core/websocket/useMarimoWebSocket.tsx +9 -2
  187. package/src/custom.d.ts +1 -1
  188. package/src/hooks/useCellRenderCount.ts +1 -0
  189. package/src/hooks/useResizeHandle.ts +4 -1
  190. package/src/plugins/core/RenderHTML.tsx +1 -2
  191. package/src/plugins/core/registerReactComponent.tsx +23 -19
  192. package/src/plugins/impl/DataTablePlugin.tsx +18 -6
  193. package/src/plugins/impl/FileUploadPlugin.tsx +1 -1
  194. package/src/plugins/impl/RefreshPlugin.tsx +1 -1
  195. package/src/plugins/impl/SliderPlugin.tsx +4 -0
  196. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +27 -9
  197. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +58 -2
  198. package/src/plugins/impl/anywidget/__tests__/model.test.ts +3 -4
  199. package/src/plugins/impl/anywidget/model.ts +2 -3
  200. package/src/plugins/impl/data-editor/types.ts +1 -1
  201. package/src/plugins/impl/data-explorer/components/query-form.tsx +1 -1
  202. package/src/plugins/impl/data-frames/DataFramePlugin.tsx +17 -5
  203. package/src/plugins/impl/data-frames/types.ts +1 -1
  204. package/src/plugins/impl/panel/PanelPlugin.tsx +2 -2
  205. package/src/plugins/impl/plotly/PlotlyPlugin.tsx +3 -3
  206. package/src/plugins/impl/vega/__tests__/loader.test.ts +2 -2
  207. package/src/plugins/impl/vega/loader.ts +1 -1
  208. package/src/plugins/impl/vega/vega-component.tsx +1 -1
  209. package/src/plugins/impl/vega/vega-loader.ts +2 -2
  210. package/src/plugins/layout/NavigationMenuPlugin.tsx +1 -1
  211. package/src/plugins/layout/RoutesPlugin.tsx +1 -2
  212. package/src/plugins/plugins.ts +2 -2
  213. package/src/stories/dataframe.stories.tsx +2 -0
  214. package/src/utils/Logger.ts +1 -1
  215. package/src/utils/__tests__/data-views.test.ts +30 -68
  216. package/src/utils/__tests__/dom.test.ts +167 -0
  217. package/src/utils/__tests__/id-tree.test.ts +49 -1
  218. package/src/utils/__tests__/storage.test.ts +1 -1
  219. package/src/utils/__tests__/traceback.test.ts +13 -2
  220. package/src/utils/arrays.ts +1 -1
  221. package/src/utils/createReducer.ts +1 -5
  222. package/src/utils/data-views.ts +6 -19
  223. package/src/utils/dom.ts +55 -0
  224. package/src/utils/edit-distance.ts +1 -1
  225. package/src/utils/fileToBase64.ts +1 -1
  226. package/src/utils/id-tree.tsx +20 -18
  227. package/src/utils/json/base64.ts +13 -0
  228. package/src/utils/json/json-parser.ts +2 -2
  229. package/src/utils/lru.ts +4 -0
  230. package/src/utils/mergeRefs.ts +1 -1
  231. package/src/utils/objects.ts +3 -3
  232. package/src/utils/pluralize.ts +1 -1
  233. package/src/utils/routes.ts +2 -2
  234. package/src/utils/sets.ts +1 -1
  235. package/src/utils/traceback.ts +45 -15
  236. package/src/utils/tracer.ts +11 -9
  237. package/dist/index-DW0BCGJE.js +0 -40315
  238. package/src/__tests__/lru.test.ts +0 -74
@@ -25,9 +25,9 @@ export type CellIndex = number & { __brand?: "CellIndex" };
25
25
  export class TreeNode<T> {
26
26
  public value: T;
27
27
  public isCollapsed: boolean;
28
- public children: Array<TreeNode<T>>;
28
+ public children: TreeNode<T>[];
29
29
 
30
- constructor(value: T, isCollapsed: boolean, children: Array<TreeNode<T>>) {
30
+ constructor(value: T, isCollapsed: boolean, children: TreeNode<T>[]) {
31
31
  this.value = value;
32
32
  this.isCollapsed = isCollapsed;
33
33
  this.children = children;
@@ -77,15 +77,17 @@ export class TreeNode<T> {
77
77
  @Memoize()
78
78
  get inOrderIds(): T[] {
79
79
  const result: T[] = [];
80
- const queue = [...this.children];
81
80
 
82
- while (queue.length > 0) {
83
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84
- const node = queue.shift()!;
81
+ // Use depth-first traversal to preserve logical document order
82
+ const traverse = (node: TreeNode<T>) => {
85
83
  result.push(node.value);
84
+ for (const child of node.children) {
85
+ traverse(child);
86
+ }
87
+ };
86
88
 
87
- // Add children to queue to maintain breadth-first traversal
88
- queue.push(...node.children);
89
+ for (const child of this.children) {
90
+ traverse(child);
89
91
  }
90
92
 
91
93
  return result;
@@ -106,10 +108,10 @@ export class TreeNode<T> {
106
108
  let uniqueId = 0;
107
109
 
108
110
  export class CollapsibleTree<T> {
109
- public readonly nodes: Array<TreeNode<T>>;
111
+ public readonly nodes: TreeNode<T>[];
110
112
  public readonly id: CellColumnId;
111
113
 
112
- private constructor(nodes: Array<TreeNode<T>>, id: CellColumnId) {
114
+ private constructor(nodes: TreeNode<T>[], id: CellColumnId) {
113
115
  this.nodes = nodes;
114
116
  this.id = id;
115
117
  }
@@ -160,7 +162,7 @@ export class CollapsibleTree<T> {
160
162
  return newTree;
161
163
  }
162
164
 
163
- withNodes(nodes: Array<TreeNode<T>>): CollapsibleTree<T> {
165
+ withNodes(nodes: TreeNode<T>[]): CollapsibleTree<T> {
164
166
  return new CollapsibleTree(nodes, this.id);
165
167
  }
166
168
 
@@ -305,7 +307,7 @@ export class CollapsibleTree<T> {
305
307
  * Does not collapse the children of already collapsed nodes
306
308
  */
307
309
  collapseAll(
308
- collapseRanges: Array<{ id: T; until: T | undefined } | null>,
310
+ collapseRanges: ({ id: T; until: T | undefined } | null)[],
309
311
  ): CollapsibleTree<T> {
310
312
  const nodes = [...this.nodes];
311
313
  if (collapseRanges.length === 0) {
@@ -539,7 +541,7 @@ export class CollapsibleTree<T> {
539
541
  */
540
542
  find(id: T): T[] {
541
543
  // We need to recursively find the node
542
- function findNode(nodes: Array<TreeNode<T>>, path: T[]): T[] {
544
+ function findNode(nodes: TreeNode<T>[], path: T[]): T[] {
543
545
  for (const node of nodes) {
544
546
  if (node.value === id) {
545
547
  return [...path, id];
@@ -585,7 +587,7 @@ export class CollapsibleTree<T> {
585
587
  toString(): string {
586
588
  let depth = 0;
587
589
  let result = "";
588
- const asString = (nodes: Array<TreeNode<T>>) => {
590
+ const asString = (nodes: TreeNode<T>[]) => {
589
591
  for (const node of nodes) {
590
592
  result += `${" ".repeat(depth * 2)}${node.toString()}\n`;
591
593
  depth += 1;
@@ -599,9 +601,9 @@ export class CollapsibleTree<T> {
599
601
  }
600
602
 
601
603
  export class MultiColumn<T> {
602
- private readonly columns: ReadonlyArray<CollapsibleTree<T>>;
604
+ private readonly columns: readonly CollapsibleTree<T>[];
603
605
 
604
- constructor(columns: ReadonlyArray<CollapsibleTree<T>>) {
606
+ constructor(columns: readonly CollapsibleTree<T>[]) {
605
607
  this.columns = columns;
606
608
 
607
609
  // Ensure there is always at least one column
@@ -662,7 +664,7 @@ export class MultiColumn<T> {
662
664
  }
663
665
 
664
666
  static fromIdsAndColumns<T>(
665
- idAndColumns: Array<[T, number | undefined | null]>,
667
+ idAndColumns: [T, number | undefined | null][],
666
668
  ): MultiColumn<T> {
667
669
  // If column is undefined, use the previous column
668
670
  // Ensure there is always at least one column
@@ -744,7 +746,7 @@ export class MultiColumn<T> {
744
746
  return this.columns.length === 1;
745
747
  }
746
748
 
747
- getColumns(): ReadonlyArray<CollapsibleTree<T>> {
749
+ getColumns(): readonly CollapsibleTree<T>[] {
748
750
  return this.columns;
749
751
  }
750
752
 
@@ -1,4 +1,6 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
+
3
+ import type { OperationMessageData } from "@/core/kernel/messages";
2
4
  import type { TypedString } from "../typed";
3
5
 
4
6
  export type JsonString<T = unknown> = TypedString<"Json"> & {
@@ -52,3 +54,14 @@ export function extractBase64FromDataURL(str: DataURLString): Base64String {
52
54
  export function byteStringToBinary(bytes: ByteString): Uint8Array {
53
55
  return Uint8Array.from(bytes, (c) => c.charCodeAt(0));
54
56
  }
57
+
58
+ export function safeExtractSetUIElementMessageBuffers(
59
+ op: OperationMessageData<"send-ui-element-message">,
60
+ ): readonly DataView[] {
61
+ // @ts-expect-error - TypeScript doesn't know that these strings are actually base64 strings
62
+ const strs: Base64String[] = op.buffers ?? [];
63
+ return strs.map((str) => {
64
+ const bytes = byteStringToBinary(typedAtob(str));
65
+ return new DataView(bytes.buffer);
66
+ });
67
+ }
@@ -34,7 +34,7 @@ export function jsonParseWithSpecialChar<T = unknown>(
34
34
  /(?<=\s|^|\[|,|:)(NaN|-Infinity|Infinity)(?=(?:[^"'\\]*(\\.|'([^'\\]*\\.)*[^'\\]*'|"([^"\\]*\\.)*[^"\\]*"))*[^"']*$)/g,
35
35
  `"${CHAR}$1${CHAR}"`,
36
36
  );
37
- return JSON.parse(value, (key, v) => {
37
+ return JSON.parse(value, (_key, v) => {
38
38
  if (typeof v !== "string") {
39
39
  return v;
40
40
  }
@@ -54,7 +54,7 @@ export function jsonParseWithSpecialChar<T = unknown>(
54
54
  }
55
55
  }
56
56
 
57
- export function jsonToTSV(json: Array<Record<string, unknown>>) {
57
+ export function jsonToTSV(json: Record<string, unknown>[]) {
58
58
  if (json.length === 0) {
59
59
  return "";
60
60
  }
package/src/utils/lru.ts CHANGED
@@ -65,4 +65,8 @@ export class LRUCache<K, V> {
65
65
  public entries() {
66
66
  return this.cache.entries();
67
67
  }
68
+
69
+ public delete(key: K) {
70
+ this.cache.delete(key);
71
+ }
68
72
  }
@@ -1,6 +1,6 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
2
  export function mergeRefs<T>(
3
- ...refs: Array<React.Ref<T>>
3
+ ...refs: React.Ref<T>[]
4
4
  ): (value: T | null) => void {
5
5
  return (value) => {
6
6
  refs.forEach((ref) => {
@@ -17,14 +17,14 @@ export const Objects = {
17
17
  /**
18
18
  * Type-safe Object.fromEntries
19
19
  */
20
- fromEntries<K extends string | number, V>(obj: Array<[K, V]>): Record<K, V> {
20
+ fromEntries<K extends string | number, V>(obj: [K, V][]): Record<K, V> {
21
21
  return Object.fromEntries(obj) as Record<K, V>;
22
22
  },
23
23
  /**
24
24
  * Type-safe Object.entries
25
25
  */
26
- entries<K extends string | number, V>(obj: Record<K, V>): Array<[K, V]> {
27
- return Object.entries(obj) as Array<[K, V]>;
26
+ entries<K extends string | number, V>(obj: Record<K, V>): [K, V][] {
27
+ return Object.entries(obj) as [K, V][];
28
28
  },
29
29
  /**
30
30
  * Type-safe Object.keys
@@ -25,7 +25,7 @@ export class PluralWords {
25
25
  this.words = words;
26
26
  }
27
27
 
28
- static of(...words: Array<PluralWord | string>) {
28
+ static of(...words: (PluralWord | string)[]) {
29
29
  return new PluralWords(
30
30
  words.map((word) => {
31
31
  if (typeof word === "string") {
@@ -8,10 +8,10 @@ import {
8
8
  } from "path-to-regexp";
9
9
 
10
10
  export class TinyRouter {
11
- private routes: Array<{
11
+ private routes: {
12
12
  template: string;
13
13
  pathFunction: MatchFunction<ParamData>;
14
- }>;
14
+ }[];
15
15
 
16
16
  constructor(templates: string[]) {
17
17
  this.routes = templates.map((template) => {
package/src/utils/sets.ts CHANGED
@@ -3,7 +3,7 @@ export const Sets = {
3
3
  /**
4
4
  * Merge multiple iterables into a single set.
5
5
  */
6
- merge<T>(...sets: Array<Iterable<T>>): Set<T> {
6
+ merge<T>(...sets: Iterable<T>[]): Set<T> {
7
7
  const result = new Set<T>();
8
8
  for (const set of sets) {
9
9
  for (const item of set) {
@@ -28,13 +28,38 @@ export const elementContainsMarimoCellFile = (domNode: Element) => {
28
28
  );
29
29
  };
30
30
 
31
- export interface TracebackInfo {
32
- cellId: CellId;
33
- lineNumber: number;
34
- }
31
+ export type TracebackInfo =
32
+ | {
33
+ kind: "file";
34
+ filePath: string;
35
+ lineNumber: number;
36
+ }
37
+ | {
38
+ kind: "cell";
39
+ cellId: CellId;
40
+ lineNumber: number;
41
+ };
35
42
 
36
43
  /**
37
44
  * Extract the cell id and line number from a traceback DOM node.
45
+ *
46
+ * Example transformation:
47
+ *
48
+ * File <span class="nb">"/tmp/marimo_<number>/__marimo__cell_<CellId>.py"</span>
49
+ * , line <span class="n">1</span>...
50
+ *
51
+ * becomes
52
+ *
53
+ * { kind: "cell", cellId: <CellID>, lineNumber: 1 }
54
+ *
55
+ * or for files:
56
+ *
57
+ * File <span class="nb">"/path/to/file.py"</span>
58
+ * , line <span class="n">42</span>...
59
+ *
60
+ * becomes
61
+ *
62
+ * { kind: "file", filePath: "/path/to/file.py", lineNumber: 42 }
38
63
  */
39
64
  export function getTracebackInfo(domNode: DOMNode): TracebackInfo | null {
40
65
  // The traceback can be manipulated either in output render or in the pygments
@@ -57,7 +82,7 @@ export function getTracebackInfo(domNode: DOMNode): TracebackInfo | null {
57
82
  if (
58
83
  domNode instanceof Element &&
59
84
  domNode.firstChild instanceof Text &&
60
- elementContainsMarimoCellFile(domNode)
85
+ matchesSelector(domNode, "span.nb")
61
86
  ) {
62
87
  const nextSibling = domNode.next;
63
88
  if (nextSibling && nextSibling instanceof Text) {
@@ -68,14 +93,22 @@ export function getTracebackInfo(domNode: DOMNode): TracebackInfo | null {
68
93
  lineSibling.firstChild instanceof Text &&
69
94
  matchesSelector(lineSibling, "span.m")
70
95
  ) {
71
- const cellId = /__marimo__cell_(\w+)_/.exec(
72
- domNode.firstChild.nodeValue,
73
- )?.[1];
74
96
  const lineNumber = Number.parseInt(
75
97
  lineSibling.firstChild.nodeValue || "0",
98
+ 10,
76
99
  );
77
- if (cellId && lineNumber) {
78
- return { cellId: cellId as CellId, lineNumber };
100
+ if (domNode.firstChild.nodeValue?.includes("__marimo__")) {
101
+ const cellId = /__marimo__cell_(\w+)_/.exec(
102
+ domNode.firstChild.nodeValue,
103
+ )?.[1] as CellId;
104
+ if (cellId && lineNumber) {
105
+ return { kind: "cell", cellId, lineNumber };
106
+ }
107
+ } else {
108
+ const filePath = /"(.+?)"/.exec(domNode.firstChild.nodeValue)?.[1];
109
+ if (filePath && lineNumber) {
110
+ return { kind: "file", filePath, lineNumber };
111
+ }
79
112
  }
80
113
  }
81
114
  }
@@ -92,11 +125,8 @@ export function extractAllTracebackInfo(traceback: string): TracebackInfo[] {
92
125
  replace: (domNode) => {
93
126
  const info = getTracebackInfo(domNode);
94
127
  if (info) {
95
- infos.push({
96
- cellId: info.cellId,
97
- lineNumber: info.lineNumber,
98
- });
99
- return `${info.cellId}:${info.lineNumber}`;
128
+ infos.push(info);
129
+ return "dummy";
100
130
  }
101
131
  },
102
132
  });
@@ -1,7 +1,9 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
2
 
3
- /* eslint-disable no-console */
4
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ /** biome-ignore-all lint/suspicious/noConsole: for debugging */
5
+
6
+ import { Logger } from "./Logger";
5
7
 
6
8
  type SpanStatus = "ok" | "error";
7
9
 
@@ -88,19 +90,19 @@ export class Tracer {
88
90
  s.startTime < span.endTime,
89
91
  );
90
92
  if (childSpans.length > 0) {
91
- console.log("Child Spans:");
93
+ Logger.log("Child Spans:");
92
94
  childSpans.forEach((childSpan) => {
93
- console.log(` - ${childSpan.name}`);
95
+ Logger.log(` - ${childSpan.name}`);
94
96
  });
95
97
  }
96
- console.log(`Start Time: ${new Date(span.startTime).toISOString()}`);
98
+ Logger.log(`Start Time: ${new Date(span.startTime).toISOString()}`);
97
99
  if (span.endTime) {
98
- console.log(`End Time: ${new Date(span.endTime).toISOString()}`);
99
- console.log(`Duration: ${span.endTime - span.startTime}ms`);
100
+ Logger.log(`End Time: ${new Date(span.endTime).toISOString()}`);
101
+ Logger.log(`Duration: ${span.endTime - span.startTime}ms`);
100
102
  }
101
- console.log(`Status: ${span.status}`);
102
- console.log(`Attributes: ${JSON.stringify(span.attributes)}`);
103
- console.log("---");
103
+ Logger.log(`Status: ${span.status}`);
104
+ Logger.log(`Attributes: ${JSON.stringify(span.attributes)}`);
105
+ Logger.log("---");
104
106
  });
105
107
  }
106
108
  }