@marimo-team/islands 0.15.2 → 0.15.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 (189) hide show
  1. package/dist/{ConnectedDataExplorerComponent-C39nQwtD.js → ConnectedDataExplorerComponent-DfvW3rBn.js} +323 -328
  2. package/dist/{ImageComparisonComponent-BhkiyswP.js → ImageComparisonComponent-XaJshw7d.js} +13 -13
  3. package/dist/{_baseUniq-DdHL34FO.js → _baseUniq-dN9WKF9m.js} +67 -67
  4. package/dist/any-language-editor-CpFniVi-.js +27 -0
  5. package/dist/{arc-BXrety1g.js → arc-BOhn-m2C.js} +1 -1
  6. package/dist/{architectureDiagram-KFL7JDKH-BMy6ywCF.js → architectureDiagram-W76B3OCA-Bpg85ZKv.js} +144 -144
  7. package/dist/assets/{worker-COGufAQn.js → worker-Y-Q4G-N2.js} +30 -26
  8. package/dist/asterisk-DS281yxp.js +271 -0
  9. package/dist/{blockDiagram-ZYB65J3Q-DYT2-nlI.js → blockDiagram-QIGZ2CNN-DS1kOHlW.js} +10 -10
  10. package/dist/{c4Diagram-AAMF2YG6-ZiQzioe6.js → c4Diagram-FPNF74CW-CyRVKssw.js} +8 -8
  11. package/dist/{channel-CeuXqUAU.js → channel-BilGXox7.js} +1 -1
  12. package/dist/{chunk-ANTBXLJU-BvYnIrdq.js → chunk-4BX2VUAB-CZR39zCO.js} +1 -1
  13. package/dist/{chunk-WVR4S24B-DXj8yaUk.js → chunk-55IACEB6-BIH-MYov.js} +1 -1
  14. package/dist/{chunk-GLLZNHP4-CyFsosAe.js → chunk-FMBD7UC4-4PZXFZE8.js} +1 -1
  15. package/dist/{chunk-JBRWN2VN-DA_EEhy2.js → chunk-K7UQS3LO-CEvWKznk.js} +117 -117
  16. package/dist/{chunk-NRVI72HA-BYx2jMlI.js → chunk-QN33PNHL-D5LO5Jq_.js} +1 -1
  17. package/dist/{chunk-FHKO5MBM-DfCztBk8.js → chunk-QZHKN3VN-6gwUonWI.js} +1 -1
  18. package/dist/{chunk-LXBSTHXV-Se7vdY6J.js → chunk-TVAH2DTR-3gm06QdU.js} +7 -7
  19. package/dist/{chunk-OMD6QJNC-CqgcPMgL.js → chunk-TZMSLE5B-Cm8Iy9bO.js} +1 -1
  20. package/dist/{classDiagram-v2-QTMF73CY-B19A3G1l.js → classDiagram-KNZD7YFC-DC529O_z.js} +2 -2
  21. package/dist/{classDiagram-3BZAVTQC-B19A3G1l.js → classDiagram-v2-RKCZMP56-DC529O_z.js} +2 -2
  22. package/dist/{clone-78au0tn1.js → clone-CLoRX3j6.js} +1 -1
  23. package/dist/cose-bilkent-S5V4N54A-qf5DlS6Y.js +2609 -0
  24. package/dist/{cytoscape.esm-BYnVVhJX.js → cytoscape.esm-DfdJODL8.js} +34 -34
  25. package/dist/{dagre-2BBEFEWP-BfEn3ZUV.js → dagre-5GWH7T2D-Ceocls0m.js} +6 -6
  26. package/dist/{data-grid-overlay-editor-CH_qLkV2.js → data-grid-overlay-editor-AqDS_UKe.js} +11 -11
  27. package/dist/{diagram-4IRLE6MV-CL8xidnG.js → diagram-N5W7TBWH-CP66oSiv.js} +59 -60
  28. package/dist/{diagram-RP2FKANI-B1BPcUew.js → diagram-QEK2KX5R-_YD4kxxi.js} +15 -15
  29. package/dist/{diagram-GUPCWM2R-CZ5cfqlq.js → diagram-S2PKOQOG-Cnj8T-OP.js} +10 -10
  30. package/dist/dockerfile-Cm8cRYCN.js +194 -0
  31. package/dist/ebnf-DUPDuY4r.js +78 -0
  32. package/dist/{erDiagram-HZWUO2LU-BEAIww50.js → erDiagram-AWTI2OKA-CGnvoHx6.js} +8 -8
  33. package/dist/fcl-CPC2WYrI.js +103 -0
  34. package/dist/{flowDiagram-THRYKUMA-Czs2UAI2.js → flowDiagram-PVAE7QVJ-DG-pr9R9.js} +9 -9
  35. package/dist/{ganttDiagram-WV7ZQ7D5-ByYIAVFO.js → ganttDiagram-OWAHRB6G-JmChtxvn.js} +34 -34
  36. package/dist/{gitGraphDiagram-OJR772UL-BcpDsiyB.js → gitGraphDiagram-NY62KEGX-D8wLfOPd.js} +4 -4
  37. package/dist/{glide-data-editor-CmN6FVyi.js → glide-data-editor-9nC3iCIZ.js} +33 -33
  38. package/dist/{graph-77W6heli.js → graph-CoRe7vAN.js} +3 -3
  39. package/dist/http-D9LttvKF.js +44 -0
  40. package/dist/{index-Bfk9dnyS.js → index-6qYeHHjQ.js} +33090 -32892
  41. package/dist/{index-BOojn38D.js → index-BpzLh4Qe.js} +7711 -7711
  42. package/dist/{index-CmozKMxx.js → index-BthgsgYX.js} +6 -6
  43. package/dist/{index-pBmAzQJl.js → index-MCx5v1x0.js} +2 -2
  44. package/dist/index-jkm77Jrz.js +98 -0
  45. package/dist/{infoDiagram-6WOFNB3A-CfzLHHVP.js → infoDiagram-STP46IZ2-BlXxvOrR.js} +2 -2
  46. package/dist/{journeyDiagram-FFXJYRFH-ndAcpkGn.js → journeyDiagram-BIP6EPQ6-CNRYs_Fc.js} +24 -26
  47. package/dist/{kanban-definition-KOZQBZVT-DcQYzNvc.js → kanban-definition-6OIFK2YF-B9HeMAuP.js} +14 -14
  48. package/dist/{layout-XySVHJgD.js → layout-m2vOUiW1.js} +81 -81
  49. package/dist/{linear-PbooOqg7.js → linear-DU6Q5CX3.js} +35 -35
  50. package/dist/{main-B5yML0bw.js → main-BD2KGFpU.js} +74594 -68034
  51. package/dist/main.js +1 -1
  52. package/dist/{mermaid-Cg5IX6Nv.js → mermaid-HVCtvbyx.js} +6160 -7493
  53. package/dist/min-DcGMA4e_.js +80 -0
  54. package/dist/mindmap-definition-Q6HEUPPD-BW8UmIDQ.js +785 -0
  55. package/dist/nginx-zDPm3Z74.js +89 -0
  56. package/dist/{number-overlay-editor-DUhfZqtP.js → number-overlay-editor-D8Hl0Syo.js} +19 -19
  57. package/dist/{pieDiagram-DBDJKBY4-DTOlNsja.js → pieDiagram-ADFJNKIX-Bg-3zg5U.js} +17 -17
  58. package/dist/{quadrantDiagram-YPSRARAO-BX2d8VS-.js → quadrantDiagram-LMRXKWRM-BO4IG6Yz.js} +6 -6
  59. package/dist/{react-plotly-Dcyw-3Sa.js → react-plotly-dkvHVuRb.js} +3577 -3577
  60. package/dist/{requirementDiagram-EGVEC5DT-D1T5u-wG.js → requirementDiagram-4UW4RH46-5sdTguSM.js} +7 -7
  61. package/dist/{sankeyDiagram-HRAUVNP4-G6xDfnp-.js → sankeyDiagram-GR3RE2ED-Buhlv9OI.js} +5 -5
  62. package/dist/sequenceDiagram-C3RYC4MD-C3qsM2UP.js +2519 -0
  63. package/dist/{slides-component-BJLlPJSr.js → slides-component-D209A0-s.js} +66 -66
  64. package/dist/solr-BNlsLglM.js +41 -0
  65. package/dist/spreadsheet-C-cy4P5N.js +49 -0
  66. package/dist/{stateDiagram-UUKSUZ4H-CYXbjaom.js → stateDiagram-KXAO66HF-CopJ7G6P.js} +5 -5
  67. package/dist/{stateDiagram-v2-EYPG3UTE-Br1HYKT6.js → stateDiagram-v2-UMBNRL4Z-CejL8AKf.js} +2 -2
  68. package/dist/style.css +1 -1
  69. package/dist/tiddlywiki-5wqsXtSk.js +155 -0
  70. package/dist/tiki-__Kn3CeS.js +181 -0
  71. package/dist/{time-B9SZnSen.js → time-BwSBitlN.js} +58 -58
  72. package/dist/{timeline-definition-3HZDQTIS-DeK_ZRD0.js → timeline-definition-XQNQX7LJ-DzMNTX-C.js} +10 -12
  73. package/dist/{timer-BYwnU4DF.js → timer-B0-z63CM.js} +16 -16
  74. package/dist/{treemap-75Q7IDZK-CKP4vV_0.js → treemap-75Q7IDZK-zeJG07dk.js} +14 -14
  75. package/dist/{vega-component-CpgdqX2d.js → vega-component-CUkiTayd.js} +30 -30
  76. package/dist/{xychartDiagram-FDP5SA34-AMEPsx_R.js → xychartDiagram-6GGTOJPD-DiENNXMS.js} +7 -7
  77. package/package.json +39 -39
  78. package/src/__mocks__/notebook.ts +3 -0
  79. package/src/__mocks__/requests.ts +3 -0
  80. package/src/__tests__/__snapshots__/CellStatus.test.tsx.snap +12 -12
  81. package/src/__tests__/chat-utils.test.ts +26 -211
  82. package/src/components/ai/ai-model-dropdown.tsx +25 -9
  83. package/src/components/app-config/ai-config.tsx +7 -0
  84. package/src/components/chat/chat-components.tsx +71 -0
  85. package/src/components/chat/chat-panel.tsx +481 -291
  86. package/src/components/chat/chat-utils.ts +50 -0
  87. package/src/components/chat/markdown-renderer.tsx +3 -7
  88. package/src/components/chat/tool-call-accordion.tsx +5 -5
  89. package/src/components/datasources/__tests__/utils.test.ts +6 -0
  90. package/src/components/datasources/column-preview.tsx +1 -3
  91. package/src/components/editor/actions/useNotebookActions.tsx +1 -1
  92. package/src/components/editor/ai/add-cell-with-ai.tsx +20 -15
  93. package/src/components/editor/ai/ai-completion-editor.tsx +22 -3
  94. package/src/components/editor/ai/completion-handlers.tsx +2 -4
  95. package/src/components/editor/ai/completion-utils.ts +85 -11
  96. package/src/components/editor/alerts/startup-logs-alert.tsx +72 -0
  97. package/src/components/editor/chrome/panels/datasources-panel.tsx +3 -1
  98. package/src/components/editor/chrome/panels/dependency-graph-panel.tsx +3 -1
  99. package/src/components/editor/chrome/panels/documentation-panel.tsx +3 -1
  100. package/src/components/editor/chrome/panels/error-panel.tsx +3 -1
  101. package/src/components/editor/chrome/panels/file-explorer-panel.tsx +3 -1
  102. package/src/components/editor/chrome/panels/logs-panel.tsx +3 -1
  103. package/src/components/editor/chrome/panels/outline-panel.tsx +3 -1
  104. package/src/components/editor/chrome/panels/packages-panel.tsx +4 -2
  105. package/src/components/editor/chrome/panels/scratchpad-panel.tsx +3 -1
  106. package/src/components/editor/chrome/panels/secrets-panel.tsx +3 -1
  107. package/src/components/editor/chrome/panels/snippets-panel.tsx +3 -1
  108. package/src/components/editor/chrome/panels/tracing-panel.tsx +3 -1
  109. package/src/components/editor/chrome/panels/variable-panel.tsx +3 -1
  110. package/src/components/editor/chrome/wrapper/app-chrome.tsx +38 -28
  111. package/src/components/editor/controls/command-palette-button.tsx +1 -1
  112. package/src/components/editor/controls/command-palette.tsx +5 -4
  113. package/src/components/editor/controls/state.ts +4 -0
  114. package/src/components/editor/package-alert.tsx +108 -58
  115. package/src/components/editor/renderers/CellArray.tsx +2 -0
  116. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +0 -1
  117. package/src/components/pages/edit-page.tsx +7 -3
  118. package/src/core/ai/chat-utils.ts +26 -43
  119. package/src/core/ai/config.ts +1 -1
  120. package/src/core/ai/context/__tests__/registry.test.ts +277 -3
  121. package/src/core/ai/context/context.ts +11 -1
  122. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +378 -0
  123. package/src/core/ai/context/providers/__tests__/error.test.ts +3 -2
  124. package/src/core/ai/context/providers/__tests__/file.test.ts +119 -0
  125. package/src/core/ai/context/providers/cell-output.ts +349 -0
  126. package/src/core/ai/context/providers/common.ts +5 -1
  127. package/src/core/ai/context/providers/file.ts +287 -0
  128. package/src/core/ai/context/registry.ts +79 -0
  129. package/src/core/ai/state.ts +22 -5
  130. package/src/core/alerts/state.ts +71 -3
  131. package/src/core/cells/cell.ts +2 -2
  132. package/src/core/cells/cells.ts +1 -1
  133. package/src/core/cells/logs.ts +1 -1
  134. package/src/core/cells/runs.ts +6 -5
  135. package/src/core/codemirror/ai/resources.ts +47 -5
  136. package/src/core/codemirror/ai/state.ts +12 -0
  137. package/src/core/codemirror/language/__tests__/sql.test.ts +45 -0
  138. package/src/core/codemirror/markdown/__tests__/commands.test.ts +1 -0
  139. package/src/core/codemirror/theme/dark.ts +1 -1
  140. package/src/core/config/capabilities.ts +1 -1
  141. package/src/core/datasets/__tests__/data-source.test.ts +24 -0
  142. package/src/core/errors/__tests__/errors.test.ts +2 -0
  143. package/src/core/islands/bridge.ts +1 -0
  144. package/src/core/islands/main.ts +1 -0
  145. package/src/core/kernel/messages.ts +12 -6
  146. package/src/core/layout/layout.ts +3 -3
  147. package/src/core/network/requests-network.ts +8 -0
  148. package/src/core/network/requests-static.ts +1 -0
  149. package/src/core/network/requests-toasting.ts +1 -0
  150. package/src/core/network/types.ts +4 -1
  151. package/src/core/wasm/bridge.ts +18 -2
  152. package/src/core/wasm/worker/bootstrap.ts +3 -1
  153. package/src/core/wasm/worker/getMarimoWheel.ts +3 -8
  154. package/src/core/wasm/worker/types.ts +3 -0
  155. package/src/core/websocket/useMarimoWebSocket.tsx +7 -1
  156. package/src/css/app/Cell.css +42 -21
  157. package/src/css/app/codemirror.css +5 -1
  158. package/src/css/globals.css +3 -0
  159. package/src/css/md.css +1 -1
  160. package/src/plugins/impl/MicrophonePlugin.tsx +2 -2
  161. package/src/plugins/impl/chat/ChatPlugin.tsx +2 -9
  162. package/src/plugins/impl/chat/chat-ui.tsx +129 -110
  163. package/src/plugins/impl/chat/types.ts +5 -8
  164. package/src/plugins/impl/code/__tests__/language.test.ts +15 -0
  165. package/src/plugins/impl/code/any-language-editor.tsx +11 -8
  166. package/src/plugins/layout/MimeRenderPlugin.tsx +3 -6
  167. package/src/stories/cell.stories.tsx +6 -0
  168. package/src/stories/layout/vertical/one-column.stories.tsx +215 -0
  169. package/src/theme/useTheme.ts +11 -6
  170. package/src/utils/__tests__/blob.test.ts +37 -0
  171. package/src/utils/arrays.ts +13 -0
  172. package/src/utils/fileToBase64.ts +21 -6
  173. package/src/utils/json/base64.ts +5 -2
  174. package/src/utils/numbers.ts +9 -7
  175. package/dist/any-language-editor-DC5170DQ.js +0 -45
  176. package/dist/asn1-jKiBa2Ya.js +0 -95
  177. package/dist/clojure-CCKyeQKf.js +0 -800
  178. package/dist/css-BkF-NPzE.js +0 -1553
  179. package/dist/index-5ZH_qS8j.js +0 -288
  180. package/dist/index-U4yn89qO.js +0 -341
  181. package/dist/javascript-C2yteZeJ.js +0 -691
  182. package/dist/min-DS5Jz-hg.js +0 -80
  183. package/dist/mindmap-definition-LNHGMQRG-0aOVaMR8.js +0 -3234
  184. package/dist/mllike-BSnXJBGA.js +0 -272
  185. package/dist/pug-CwAQJzGR.js +0 -248
  186. package/dist/python-BkR3uSy8.js +0 -313
  187. package/dist/rpm-IznJm2Xc.js +0 -57
  188. package/dist/sequenceDiagram-WFGC7UMF-DMhHzllb.js +0 -2284
  189. package/dist/ttcn-cfg-Bac_acMi.js +0 -88
@@ -0,0 +1,215 @@
1
+ /* Copyright 2024 Marimo. All rights reserved. */
2
+
3
+ import type { Meta } from "@storybook/react-vite";
4
+ import { createStore, Provider } from "jotai";
5
+ import { createRef } from "react";
6
+ import { type NotebookState, notebookAtom } from "@/core/cells/cells";
7
+ import { createCellRuntimeState } from "@/core/cells/types";
8
+ import { defaultUserConfig, parseAppConfig } from "@/core/config/config-schema";
9
+ import { showCodeInRunModeAtom } from "@/core/meta/state";
10
+ import { connectionAtom } from "@/core/network/connection";
11
+ import { requestClientAtom } from "@/core/network/requests";
12
+ import { resolveRequestClient } from "@/core/network/resolve.ts";
13
+ import { WebSocketState } from "@/core/websocket/types";
14
+ import { MultiColumn } from "@/utils/id-tree";
15
+ import type { Milliseconds, Seconds } from "@/utils/time";
16
+ import { CellArray } from "../../../components/editor/renderers/CellArray";
17
+ import { CellsRenderer } from "../../../components/editor/renderers/cells-renderer";
18
+ import { TooltipProvider } from "../../../components/ui/tooltip";
19
+ import type { CellId } from "../../../core/cells/ids";
20
+
21
+ const createLongReprNotebook = (
22
+ cellId: CellId,
23
+ hideCode = false,
24
+ ): NotebookState => ({
25
+ cellData: {
26
+ [cellId]: {
27
+ id: cellId,
28
+ name: "_",
29
+ code: `class LongReprA:
30
+ def __repr__(self):
31
+ return "<dlt.Relation(dataset='" + ("jaffle_ingest_dataset_" * 80) + \\
32
+ "', destination='<dlt.destinations.duckdb(destination_type=\\'duckdb\\'," + \\
33
+ " credentials=\\'local_jaffle.duckdb\\')>')>"
34
+
35
+ print('hello')
36
+ LongReprA()`,
37
+ edited: false,
38
+ serializedEditorState: null,
39
+ config: {
40
+ hide_code: hideCode,
41
+ disabled: false,
42
+ column: null,
43
+ },
44
+ lastCodeRun: `class LongReprA:
45
+ def __repr__(self):
46
+ return "<dlt.Relation(dataset='" + ("jaffle_ingest_dataset_" * 80) + \\
47
+ "', destination='<dlt.destinations.duckdb(destination_type=\\'duckdb\\'," + \\
48
+ " credentials=\\'local_jaffle.duckdb\\')>')>"
49
+
50
+ print('hello')
51
+ LongReprA()`,
52
+ lastExecutionTime: null,
53
+ },
54
+ },
55
+ cellIds: MultiColumn.from([[cellId]]),
56
+ cellRuntime: {
57
+ [cellId]: createCellRuntimeState({
58
+ output: {
59
+ channel: "output",
60
+ data: "<dlt.Relation(dataset='jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_jaffle_ingest_dataset_', destination='<dlt.destinations.duckdb(destination_type='duckdb', credentials='local_jaffle.duckdb')>')>",
61
+ mimetype: "text/plain",
62
+ timestamp: 1_686_863_710,
63
+ },
64
+ runElapsedTimeMs: 8 as Milliseconds,
65
+ status: "idle",
66
+ consoleOutputs: [
67
+ {
68
+ channel: "stdout",
69
+ mimetype: "text/plain",
70
+ data: "hello",
71
+ timestamp: 1_686_863_705,
72
+ },
73
+ ],
74
+ interrupted: false,
75
+ errored: false,
76
+ stopped: false,
77
+ staleInputs: false,
78
+ runStartTimestamp: 0 as Seconds,
79
+ lastRunStartTimestamp: 0 as Seconds,
80
+ debuggerActive: false,
81
+ outline: null,
82
+ }),
83
+ },
84
+ cellHandles: {
85
+ [cellId]: createRef(),
86
+ },
87
+ cellLogs: [],
88
+ history: [],
89
+ scrollKey: null,
90
+ untouchedNewCells: new Set(),
91
+ });
92
+
93
+ export default {
94
+ title: "Layout/Vertical/One Column",
95
+ component: CellsRenderer,
96
+ args: {},
97
+ } satisfies Meta<typeof CellsRenderer>;
98
+
99
+ type W = Window & { __MARIMO_STATIC__?: { files: Record<string, unknown> } };
100
+
101
+ const EditModeCodeShown = () => {
102
+ const cellId = "Hbol" as CellId;
103
+ const notebook = createLongReprNotebook(cellId);
104
+
105
+ const store = createStore();
106
+ store.set(notebookAtom, notebook);
107
+ store.set(connectionAtom, { state: WebSocketState.OPEN });
108
+ store.set(requestClientAtom, resolveRequestClient());
109
+ store.set(showCodeInRunModeAtom, true);
110
+
111
+ return (
112
+ <Provider store={store}>
113
+ <TooltipProvider>
114
+ <CellsRenderer appConfig={parseAppConfig({})} mode="edit">
115
+ <CellArray
116
+ mode="edit"
117
+ userConfig={defaultUserConfig()}
118
+ appConfig={parseAppConfig({})}
119
+ />
120
+ </CellsRenderer>
121
+ </TooltipProvider>
122
+ </Provider>
123
+ );
124
+ };
125
+
126
+ const EditModeCodeHidden = () => {
127
+ const cellId = "Hbol" as CellId;
128
+ const notebook = createLongReprNotebook(cellId, true);
129
+
130
+ const store = createStore();
131
+ store.set(notebookAtom, notebook);
132
+ store.set(connectionAtom, { state: WebSocketState.OPEN });
133
+ store.set(requestClientAtom, resolveRequestClient());
134
+ store.set(showCodeInRunModeAtom, true);
135
+
136
+ return (
137
+ <Provider store={store}>
138
+ <TooltipProvider>
139
+ <CellsRenderer appConfig={parseAppConfig({})} mode="edit">
140
+ <CellArray
141
+ mode="edit"
142
+ userConfig={defaultUserConfig()}
143
+ appConfig={parseAppConfig({})}
144
+ />
145
+ </CellsRenderer>
146
+ </TooltipProvider>
147
+ </Provider>
148
+ );
149
+ };
150
+
151
+ const ReadModeCodeShown = () => {
152
+ const cellId = "Hbol" as CellId;
153
+ const notebook = createLongReprNotebook(cellId);
154
+
155
+ const store = createStore();
156
+ store.set(notebookAtom, notebook);
157
+ store.set(connectionAtom, { state: WebSocketState.OPEN });
158
+ store.set(requestClientAtom, resolveRequestClient());
159
+ store.set(showCodeInRunModeAtom, true);
160
+
161
+ return (
162
+ <Provider store={store}>
163
+ <TooltipProvider>
164
+ <CellsRenderer appConfig={parseAppConfig({})} mode="read" />
165
+ </TooltipProvider>
166
+ </Provider>
167
+ );
168
+ };
169
+
170
+ const ReadModeCodeHidden = () => {
171
+ const cellId = "Hbol" as CellId;
172
+ const notebook = createLongReprNotebook(cellId);
173
+
174
+ const store = createStore();
175
+ store.set(notebookAtom, notebook);
176
+ store.set(connectionAtom, { state: WebSocketState.OPEN });
177
+ store.set(requestClientAtom, resolveRequestClient());
178
+ store.set(showCodeInRunModeAtom, true);
179
+
180
+ return (
181
+ <Provider store={store}>
182
+ <TooltipProvider>
183
+ <CellsRenderer appConfig={parseAppConfig({})} mode="read" />
184
+ </TooltipProvider>
185
+ </Provider>
186
+ );
187
+ };
188
+
189
+ export const EditModeCodeShownStory = {
190
+ render: () => <EditModeCodeShown />,
191
+ name: "Edit Mode - Code Shown",
192
+ };
193
+ export const EditModeCodeHiddenStory = {
194
+ render: () => <EditModeCodeHidden />,
195
+ name: "Edit Mode - Code Hidden",
196
+ };
197
+ export const ReadModeCodeShownStory = {
198
+ render: () => {
199
+ if (typeof window !== "undefined") {
200
+ (window as W).__MARIMO_STATIC__ = { files: {} };
201
+ }
202
+
203
+ return <ReadModeCodeShown />;
204
+ },
205
+ name: "Read Mode - Code Shown",
206
+ };
207
+ export const ReadModeCodeHiddenStory = {
208
+ render: () => {
209
+ if (typeof window !== "undefined") {
210
+ delete (window as W).__MARIMO_STATIC__;
211
+ }
212
+ return <ReadModeCodeHidden />;
213
+ },
214
+ name: "Read Mode - Code Hidden",
215
+ };
@@ -74,12 +74,17 @@ setupThemeListener();
74
74
 
75
75
  function getVsCodeTheme(): "light" | "dark" | undefined {
76
76
  const kind = document.body.dataset.vscodeThemeKind;
77
- if (kind === "vscode-dark") {
78
- return "dark";
79
- } else if (kind === "vscode-high-contrast") {
80
- return "dark";
81
- } else if (kind === "vscode-light") {
82
- return "light";
77
+ switch (kind) {
78
+ case "vscode-dark":
79
+ return "dark";
80
+
81
+ case "vscode-high-contrast":
82
+ return "dark";
83
+
84
+ case "vscode-light":
85
+ return "light";
86
+
87
+ // No default
83
88
  }
84
89
  return undefined;
85
90
  }
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
2
  import { beforeEach, describe, expect, test } from "vitest";
3
3
  import { deserializeBlob, serializeBlob } from "../blob";
4
+ import { blobToString } from "../fileToBase64";
4
5
 
5
6
  describe("Blob serialization and deserialization", () => {
6
7
  const testString = "Hello, world!";
@@ -50,3 +51,39 @@ describe("Blob serialization and deserialization", () => {
50
51
  expect(deserialized.type).toBe(imageBlob.type);
51
52
  });
52
53
  });
54
+
55
+ describe("blobToString", () => {
56
+ const testString = "Hello, world!";
57
+ const mimeType = "text/plain";
58
+
59
+ test("should convert a Blob to a base64 string", async () => {
60
+ const blob = new Blob([testString], { type: mimeType });
61
+ const base64 = await blobToString(blob, "base64");
62
+ expect(base64).toBe(btoa(testString));
63
+ });
64
+
65
+ test("should convert a File to a base64 string", async () => {
66
+ const file = new File([testString], "test.txt", { type: mimeType });
67
+ const base64 = await blobToString(file, "base64");
68
+ expect(base64).toBe(btoa(testString));
69
+ });
70
+
71
+ test("should convert a Blob to a data URL", async () => {
72
+ const blob = new Blob([testString], { type: mimeType });
73
+ const dataUrl = await blobToString(blob, "dataUrl");
74
+ expect(dataUrl).toBe(`data:${mimeType};base64,${btoa(testString)}`);
75
+ });
76
+
77
+ test("should handle empty Blob", async () => {
78
+ const blob = new Blob([], { type: mimeType });
79
+ const base64 = await blobToString(blob, "base64");
80
+ expect(base64).toBe("");
81
+ });
82
+
83
+ test("should handle binary data", async () => {
84
+ const binaryData = new Uint8Array([0, 1, 2, 3, 4, 5]);
85
+ const blob = new Blob([binaryData], { type: "application/octet-stream" });
86
+ const base64 = await blobToString(blob, "base64");
87
+ expect(base64).toBe(btoa(String.fromCharCode(...binaryData)));
88
+ });
89
+ });
@@ -73,3 +73,16 @@ export function arrayToggle<T>(arr: T[], item: T): T[] {
73
73
  result.splice(index, 1);
74
74
  return result;
75
75
  }
76
+
77
+ export function uniqueBy<T>(arr: T[], key: (item: T) => string): T[] {
78
+ const result = [];
79
+ const seen = new Set();
80
+ for (const item of arr) {
81
+ const k = key(item);
82
+ if (!seen.has(k)) {
83
+ seen.add(k);
84
+ result.push(item);
85
+ }
86
+ }
87
+ return result;
88
+ }
@@ -1,14 +1,29 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
- export function blobToBase64(blob: Blob): Promise<string> {
2
+
3
+ /**
4
+ * Converts a Blob or File to either a base64-encoded string or a data URL.
5
+ *
6
+ * @param input - The Blob or File to convert.
7
+ * @param format - The output format: "base64" for the base64-encoded string, "dataUrl" for the full data URL.
8
+ * @returns A promise that resolves to the requested string representation.
9
+ */
10
+ export function blobToString(
11
+ input: Blob | File,
12
+ format: "base64" | "dataUrl",
13
+ ): Promise<string> {
3
14
  return new Promise((resolve) => {
4
15
  const reader = new FileReader();
5
- reader.readAsDataURL(blob);
16
+ reader.readAsDataURL(input);
6
17
  reader.onload = (e) => {
7
18
  if (e.target?.result) {
8
19
  const dataURL = e.target.result as string;
9
- // Get contents from a string of the form: data:*/*;base64,contents
10
- const b64EncodedContents = dataURL.slice(dataURL.indexOf(",") + 1);
11
- resolve(b64EncodedContents);
20
+ if (format === "base64") {
21
+ // Extract base64 content from data URL. data:*/*;base64,contents
22
+ const base64Content = dataURL.slice(dataURL.indexOf(",") + 1);
23
+ resolve(base64Content);
24
+ } else {
25
+ resolve(dataURL);
26
+ }
12
27
  }
13
28
  };
14
29
  });
@@ -22,7 +37,7 @@ export function blobToBase64(blob: Blob): Promise<string> {
22
37
  export function filesToBase64(files: File[]): Promise<Array<[string, string]>> {
23
38
  return Promise.all(
24
39
  files.map((file) =>
25
- blobToBase64(file).then(
40
+ blobToString(file, "base64").then(
26
41
  (contents) => [file.name, contents] as [string, string],
27
42
  ),
28
43
  ),
@@ -26,8 +26,11 @@ export function deserializeJson<T>(jsonString: JsonString<T>): T {
26
26
  return JSON.parse(jsonString) as T;
27
27
  }
28
28
 
29
- export function base64ToDataURL<T>(base64: Base64String<T>, mimeType: string) {
30
- return `data:${mimeType};base64,${base64}`;
29
+ export function base64ToDataURL<T>(
30
+ base64: Base64String<T>,
31
+ mimeType: string,
32
+ ): DataURLString {
33
+ return `data:${mimeType};base64,${base64}` as DataURLString;
31
34
  }
32
35
 
33
36
  export function typedAtob<T>(base64: Base64String<T>): ByteString<T> {
@@ -1,8 +1,6 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
2
 
3
- export function prettyNumber(
4
- value: number | string | undefined | null | boolean | unknown[],
5
- ): string {
3
+ export function prettyNumber(value: unknown): string {
6
4
  if (value === undefined || value === null) {
7
5
  return "";
8
6
  }
@@ -19,10 +17,14 @@ export function prettyNumber(
19
17
  return String(value);
20
18
  }
21
19
 
22
- return value.toLocaleString(undefined, {
23
- minimumFractionDigits: 0,
24
- maximumFractionDigits: 2,
25
- });
20
+ if (typeof value === "number" || typeof value === "bigint") {
21
+ return value.toLocaleString(undefined, {
22
+ minimumFractionDigits: 0,
23
+ maximumFractionDigits: 2,
24
+ });
25
+ }
26
+
27
+ return String(value);
26
28
  }
27
29
 
28
30
  function scientificSpecialCase(value: number): string | null {
@@ -1,45 +0,0 @@
1
- import { c as b, L, l as h, j as g, E, a as v, C as y, R as N } from "./main-B5yML0bw.js";
2
- const $ = (x) => {
3
- const e = b.c(26);
4
- let t, o, l, s;
5
- e[0] !== x ? ({
6
- language: t,
7
- showCopyButton: l,
8
- extensions: s,
9
- ...o
10
- } = x, e[0] = x, e[1] = t, e[2] = o, e[3] = l, e[4] = s) : (t = e[1], o = e[2], l = e[3], s = e[4]);
11
- let u;
12
- e[5] !== s ? (u = s === void 0 ? [] : s, e[5] = s, e[6] = u) : u = e[6];
13
- const c = u, a = t && !(t in v);
14
- a && L.warn(`Language ${t} not found in CodeMirror.`);
15
- let m;
16
- e: {
17
- if (!t) {
18
- m = c;
19
- break e;
20
- }
21
- const C = t;
22
- let p;
23
- e[7] !== C ? (p = h(C), e[7] = C, e[8] = p) : p = e[8];
24
- let f;
25
- e[9] !== c || e[10] !== p ? (f = [p, ...c].filter(Boolean), e[9] = c, e[10] = p, e[11] = f) : f = e[11], m = f;
26
- }
27
- const j = m;
28
- let r;
29
- e[12] !== a || e[13] !== t ? (r = a && /* @__PURE__ */ g.jsx(E, { className: "mb-1 rounded-sm", error: `Language ${t} not supported.
30
-
31
- Supported languages are: ${Object.keys(v).join(", ")}` }), e[12] = a, e[13] = t, e[14] = r) : r = e[14];
32
- let n;
33
- e[15] !== a || e[16] !== o || e[17] !== l ? (n = l && !a && /* @__PURE__ */ g.jsx(y, { tooltip: false, className: "absolute top-2 right-2 p-1 hover-action z-10 text-muted-foreground", value: o.value || "", toastTitle: "Copied to clipboard" }), e[15] = a, e[16] = o, e[17] = l, e[18] = n) : n = e[18];
34
- let i;
35
- e[19] !== j || e[20] !== o ? (i = /* @__PURE__ */ g.jsx(N, { ...o, extensions: j }), e[19] = j, e[20] = o, e[21] = i) : i = e[21];
36
- let d;
37
- return e[22] !== r || e[23] !== n || e[24] !== i ? (d = /* @__PURE__ */ g.jsxs("div", { className: "relative w-full group hover-actions-parent", children: [
38
- r,
39
- n,
40
- i
41
- ] }), e[22] = r, e[23] = n, e[24] = i, e[25] = d) : d = e[25], d;
42
- };
43
- export {
44
- $ as default
45
- };
@@ -1,95 +0,0 @@
1
- function u(i) {
2
- for (var s = {}, c = i.split(" "), T = 0; T < c.length; ++T) s[c[T]] = true;
3
- return s;
4
- }
5
- const o = {
6
- keywords: u("DEFINITIONS OBJECTS IF DERIVED INFORMATION ACTION REPLY ANY NAMED CHARACTERIZED BEHAVIOUR REGISTERED WITH AS IDENTIFIED CONSTRAINED BY PRESENT BEGIN IMPORTS FROM UNITS SYNTAX MIN-ACCESS MAX-ACCESS MINACCESS MAXACCESS REVISION STATUS DESCRIPTION SEQUENCE SET COMPONENTS OF CHOICE DistinguishedName ENUMERATED SIZE MODULE END INDEX AUGMENTS EXTENSIBILITY IMPLIED EXPORTS"),
7
- cmipVerbs: u("ACTIONS ADD GET NOTIFICATIONS REPLACE REMOVE"),
8
- compareTypes: u("OPTIONAL DEFAULT MANAGED MODULE-TYPE MODULE_IDENTITY MODULE-COMPLIANCE OBJECT-TYPE OBJECT-IDENTITY OBJECT-COMPLIANCE MODE CONFIRMED CONDITIONAL SUBORDINATE SUPERIOR CLASS TRUE FALSE NULL TEXTUAL-CONVENTION"),
9
- status: u("current deprecated mandatory obsolete"),
10
- tags: u("APPLICATION AUTOMATIC EXPLICIT IMPLICIT PRIVATE TAGS UNIVERSAL"),
11
- storage: u("BOOLEAN INTEGER OBJECT IDENTIFIER BIT OCTET STRING UTCTime InterfaceIndex IANAifType CMIP-Attribute REAL PACKAGE PACKAGES IpAddress PhysAddress NetworkAddress BITS BMPString TimeStamp TimeTicks TruthValue RowStatus DisplayString GeneralString GraphicString IA5String NumericString PrintableString SnmpAdminString TeletexString UTF8String VideotexString VisibleString StringStore ISO646String T61String UniversalString Unsigned32 Integer32 Gauge Gauge32 Counter Counter32 Counter64"),
12
- modifier: u("ATTRIBUTE ATTRIBUTES MANDATORY-GROUP MANDATORY-GROUPS GROUP GROUPS ELEMENTS EQUALITY ORDERING SUBSTRINGS DEFINED"),
13
- accessTypes: u("not-accessible accessible-for-notify read-only read-create read-write"),
14
- multiLineStrings: true
15
- };
16
- function g(i) {
17
- var s = i.keywords || o.keywords, c = i.cmipVerbs || o.cmipVerbs, T = i.compareTypes || o.compareTypes, N = i.status || o.status, d = i.tags || o.tags, f = i.storage || o.storage, m = i.modifier || o.modifier, C = i.accessTypes || o.accessTypes;
18
- i.multiLineStrings || o.multiLineStrings;
19
- var R = i.indentStatements !== false, A = /[\|\^]/, E;
20
- function y(e, n) {
21
- var t = e.next();
22
- if (t == '"' || t == "'")
23
- return n.tokenize = D(t), n.tokenize(e, n);
24
- if (/[\[\]\(\){}:=,;]/.test(t))
25
- return E = t, "punctuation";
26
- if (t == "-" && e.eat("-"))
27
- return e.skipToEnd(), "comment";
28
- if (/\d/.test(t))
29
- return e.eatWhile(/[\w\.]/), "number";
30
- if (A.test(t))
31
- return e.eatWhile(A), "operator";
32
- e.eatWhile(/[\w\-]/);
33
- var r = e.current();
34
- return s.propertyIsEnumerable(r) ? "keyword" : c.propertyIsEnumerable(r) ? "variableName" : T.propertyIsEnumerable(r) ? "atom" : N.propertyIsEnumerable(r) ? "comment" : d.propertyIsEnumerable(r) ? "typeName" : f.propertyIsEnumerable(r) || m.propertyIsEnumerable(r) || C.propertyIsEnumerable(r) ? "modifier" : "variableName";
35
- }
36
- function D(e) {
37
- return function(n, t) {
38
- for (var r = false, S, O = false; (S = n.next()) != null; ) {
39
- if (S == e && !r) {
40
- var I = n.peek();
41
- I && (I = I.toLowerCase(), (I == "b" || I == "h" || I == "o") && n.next()), O = true;
42
- break;
43
- }
44
- r = !r && S == "\\";
45
- }
46
- return O && (t.tokenize = null), "string";
47
- };
48
- }
49
- function p(e, n, t, r, S) {
50
- this.indented = e, this.column = n, this.type = t, this.align = r, this.prev = S;
51
- }
52
- function a(e, n, t) {
53
- var r = e.indented;
54
- return e.context && e.context.type == "statement" && (r = e.context.indented), e.context = new p(r, n, t, null, e.context);
55
- }
56
- function l(e) {
57
- var n = e.context.type;
58
- return (n == ")" || n == "]" || n == "}") && (e.indented = e.context.indented), e.context = e.context.prev;
59
- }
60
- return {
61
- name: "asn1",
62
- startState: function() {
63
- return {
64
- tokenize: null,
65
- context: new p(-2, 0, "top", false),
66
- indented: 0,
67
- startOfLine: true
68
- };
69
- },
70
- token: function(e, n) {
71
- var t = n.context;
72
- if (e.sol() && (t.align == null && (t.align = false), n.indented = e.indentation(), n.startOfLine = true), e.eatSpace()) return null;
73
- E = null;
74
- var r = (n.tokenize || y)(e, n);
75
- if (r == "comment") return r;
76
- if (t.align == null && (t.align = true), (E == ";" || E == ":" || E == ",") && t.type == "statement")
77
- l(n);
78
- else if (E == "{") a(n, e.column(), "}");
79
- else if (E == "[") a(n, e.column(), "]");
80
- else if (E == "(") a(n, e.column(), ")");
81
- else if (E == "}") {
82
- for (; t.type == "statement"; ) t = l(n);
83
- for (t.type == "}" && (t = l(n)); t.type == "statement"; ) t = l(n);
84
- } else E == t.type ? l(n) : R && ((t.type == "}" || t.type == "top") && E != ";" || t.type == "statement" && E == "newstatement") && a(n, e.column(), "statement");
85
- return n.startOfLine = false, r;
86
- },
87
- languageData: {
88
- indentOnInput: /^\s*[{}]$/,
89
- commentTokens: { line: "--" }
90
- }
91
- };
92
- }
93
- export {
94
- g as asn1
95
- };