@marimo-team/islands 0.19.8-dev24 → 0.19.8-dev25

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.
package/dist/main.js CHANGED
@@ -39750,6 +39750,17 @@ ${c.sqlString}
39750
39750
  }
39751
39751
  return e;
39752
39752
  },
39753
+ markUntouched: (e, r) => {
39754
+ let { cellId: c } = r;
39755
+ if (!e.untouchedNewCells.has(c)) {
39756
+ let r2 = new Set(e.untouchedNewCells);
39757
+ return r2.add(c), {
39758
+ ...e,
39759
+ untouchedNewCells: r2
39760
+ };
39761
+ }
39762
+ return e;
39763
+ },
39753
39764
  scrollToTarget: (e) => {
39754
39765
  let r = e.scrollKey;
39755
39766
  if (r === null) return e;
@@ -73192,7 +73203,7 @@ Image URL: ${r.imageUrl}`)), contextToXml({
73192
73203
  return Logger.warn("Failed to get version from mount config"), null;
73193
73204
  }
73194
73205
  }
73195
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.8-dev24"), showCodeInRunModeAtom = atom(true);
73206
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.8-dev25"), showCodeInRunModeAtom = atom(true);
73196
73207
  atom(null);
73197
73208
  var import_compiler_runtime$88 = require_compiler_runtime();
73198
73209
  function useKeydownOnElement(e, r) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.19.8-dev24",
3
+ "version": "0.19.8-dev25",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -43,6 +43,7 @@ import type { CellData } from "@/core/cells/types";
43
43
  import { formatEditorViews } from "@/core/codemirror/format";
44
44
  import { toggleToLanguage } from "@/core/codemirror/language/commands";
45
45
  import { switchLanguage } from "@/core/codemirror/language/extension";
46
+ import { MARKDOWN_INITIAL_HIDE_CODE } from "@/core/codemirror/language/languages/markdown";
46
47
  import {
47
48
  aiEnabledAtom,
48
49
  appWidthAtom,
@@ -85,6 +86,7 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
85
86
  sendToBottom,
86
87
  addColumnBreakpoint,
87
88
  clearCellOutput,
89
+ markUntouched,
88
90
  } = useCellActions();
89
91
  const splitCell = useSplitCellCallback();
90
92
  const runCell = useRunCell(cell?.cellId);
@@ -209,7 +211,7 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
209
211
  icon: <MarkdownIcon />,
210
212
  label: "Convert to Markdown",
211
213
  hotkey: "cell.viewAsMarkdown",
212
- handle: () => {
214
+ handle: async () => {
213
215
  const editorView = getEditorView();
214
216
  if (!editorView) {
215
217
  return;
@@ -219,6 +221,17 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
219
221
  language: "markdown",
220
222
  keepCodeAsIs: false,
221
223
  });
224
+ // Code stays visible until the user blurs the cell
225
+ if (!config.hide_code && MARKDOWN_INITIAL_HIDE_CODE) {
226
+ await saveCellConfig({
227
+ configs: { [cellId]: { hide_code: MARKDOWN_INITIAL_HIDE_CODE } },
228
+ });
229
+ updateCellConfig({
230
+ cellId,
231
+ config: { hide_code: MARKDOWN_INITIAL_HIDE_CODE },
232
+ });
233
+ markUntouched({ cellId });
234
+ }
222
235
  },
223
236
  hidden: isSetupCell,
224
237
  },
@@ -12,6 +12,7 @@ import {
12
12
  import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
13
13
  import { useCellActions } from "@/core/cells/cells";
14
14
  import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters";
15
+ import { MARKDOWN_INITIAL_HIDE_CODE } from "@/core/codemirror/language/languages/markdown";
15
16
  import {
16
17
  getConnectionTooltip,
17
18
  isAppInteractionDisabled,
@@ -63,7 +64,7 @@ export const CreateCellButton = ({
63
64
  maybeAddMarimoImport({ autoInstantiate: true, createNewCell });
64
65
  onClick?.({
65
66
  code: LanguageAdapters.markdown.defaultCode,
66
- hideCode: true,
67
+ hideCode: MARKDOWN_INITIAL_HIDE_CODE,
67
68
  });
68
69
  };
69
70
 
@@ -19,6 +19,7 @@ import {
19
19
  reconfigureLanguageEffect,
20
20
  switchLanguage,
21
21
  } from "@/core/codemirror/language/extension";
22
+ import { MARKDOWN_INITIAL_HIDE_CODE } from "@/core/codemirror/language/languages/markdown";
22
23
  import type { LanguageAdapterType } from "@/core/codemirror/language/types";
23
24
  import {
24
25
  connectedDocAtom,
@@ -149,6 +150,17 @@ const CellEditorInternal = ({
149
150
  autoInstantiate,
150
151
  createNewCell: cellActions.createNewCell,
151
152
  });
153
+ // Code stays visible until the user blurs the cell
154
+ if (!cellConfig.hide_code && MARKDOWN_INITIAL_HIDE_CODE) {
155
+ void saveCellConfig({
156
+ configs: { [cellId]: { hide_code: MARKDOWN_INITIAL_HIDE_CODE } },
157
+ });
158
+ cellActions.updateCellConfig({
159
+ cellId,
160
+ config: { hide_code: MARKDOWN_INITIAL_HIDE_CODE },
161
+ });
162
+ cellActions.markUntouched({ cellId });
163
+ }
152
164
  });
153
165
 
154
166
  const aiEnabled = isAiEnabled(userConfig);
@@ -23,6 +23,7 @@ import { Tooltip } from "@/components/ui/tooltip";
23
23
  import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
24
24
  import { SETUP_CELL_ID } from "@/core/cells/ids";
25
25
  import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters";
26
+ import { MARKDOWN_INITIAL_HIDE_CODE } from "@/core/codemirror/language/languages/markdown";
26
27
  import { aiEnabledAtom } from "@/core/config/config";
27
28
  import { canInteractWithAppAtom } from "@/core/network/connection";
28
29
  import { useBoolean } from "@/hooks/useBoolean";
@@ -295,7 +296,7 @@ const AddCellButtons: React.FC<{
295
296
  cellId: { type: "__end__", columnId },
296
297
  before: false,
297
298
  code: LanguageAdapters.markdown.defaultCode,
298
- hideCode: true,
299
+ hideCode: MARKDOWN_INITIAL_HIDE_CODE,
299
300
  });
300
301
  }}
301
302
  >
@@ -2561,6 +2561,126 @@ describe("cell reducer", () => {
2561
2561
  expect(state.untouchedNewCells.has(newCellId)).toBe(false);
2562
2562
  expect(exportedForTesting.isCellCodeHidden(state, newCellId)).toBe(true);
2563
2563
  });
2564
+
2565
+ it("can mark an existing cell as untouched", () => {
2566
+ // Create a cell without hideCode (not in untouchedNewCells)
2567
+ actions.createNewCell({
2568
+ cellId: "__end__",
2569
+ before: false,
2570
+ hideCode: false,
2571
+ });
2572
+
2573
+ const newCellId =
2574
+ state.cellIds.inOrderIds[state.cellIds.inOrderIds.length - 1];
2575
+ expect(state.untouchedNewCells.has(newCellId)).toBe(false);
2576
+
2577
+ // Mark it as untouched
2578
+ actions.markUntouched({ cellId: newCellId });
2579
+
2580
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2581
+ });
2582
+
2583
+ it("markUntouched is idempotent", () => {
2584
+ // Create a cell without hideCode
2585
+ actions.createNewCell({
2586
+ cellId: "__end__",
2587
+ before: false,
2588
+ hideCode: false,
2589
+ });
2590
+
2591
+ const newCellId =
2592
+ state.cellIds.inOrderIds[state.cellIds.inOrderIds.length - 1];
2593
+ expect(state.untouchedNewCells.has(newCellId)).toBe(false);
2594
+
2595
+ // Mark as untouched multiple times
2596
+ actions.markUntouched({ cellId: newCellId });
2597
+ actions.markUntouched({ cellId: newCellId });
2598
+ actions.markUntouched({ cellId: newCellId });
2599
+
2600
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2601
+ });
2602
+
2603
+ it("markUntouched does not affect already untouched cells", () => {
2604
+ // Create a cell with hideCode (already in untouchedNewCells)
2605
+ actions.createNewCell({
2606
+ cellId: "__end__",
2607
+ before: false,
2608
+ hideCode: true,
2609
+ });
2610
+
2611
+ const newCellId =
2612
+ state.cellIds.inOrderIds[state.cellIds.inOrderIds.length - 1];
2613
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2614
+
2615
+ // Calling markUntouched should not change anything
2616
+ actions.markUntouched({ cellId: newCellId });
2617
+
2618
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2619
+ });
2620
+
2621
+ it("markTouched and markUntouched can toggle cell state", () => {
2622
+ // Create a cell without hideCode
2623
+ actions.createNewCell({
2624
+ cellId: "__end__",
2625
+ before: false,
2626
+ hideCode: false,
2627
+ });
2628
+
2629
+ const newCellId =
2630
+ state.cellIds.inOrderIds[state.cellIds.inOrderIds.length - 1];
2631
+
2632
+ // Initially not untouched
2633
+ expect(state.untouchedNewCells.has(newCellId)).toBe(false);
2634
+
2635
+ // Mark as untouched
2636
+ actions.markUntouched({ cellId: newCellId });
2637
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2638
+
2639
+ // Mark as touched
2640
+ actions.markTouched({ cellId: newCellId });
2641
+ expect(state.untouchedNewCells.has(newCellId)).toBe(false);
2642
+
2643
+ // Mark as untouched again
2644
+ actions.markUntouched({ cellId: newCellId });
2645
+ expect(state.untouchedNewCells.has(newCellId)).toBe(true);
2646
+ });
2647
+
2648
+ it("markUntouched works for markdown cell conversion scenario", () => {
2649
+ // Simulates converting a Python cell to Markdown
2650
+ // 1. Create a regular cell (no hideCode)
2651
+ actions.createNewCell({
2652
+ cellId: "__end__",
2653
+ before: false,
2654
+ hideCode: false,
2655
+ });
2656
+
2657
+ const cellId =
2658
+ state.cellIds.inOrderIds[state.cellIds.inOrderIds.length - 1];
2659
+
2660
+ // Cell starts without hide_code and not in untouchedNewCells
2661
+ expect(state.cellData[cellId].config.hide_code).toBe(false);
2662
+ expect(state.untouchedNewCells.has(cellId)).toBe(false);
2663
+ expect(exportedForTesting.isCellCodeHidden(state, cellId)).toBe(false);
2664
+
2665
+ // 2. Convert to markdown: set hide_code and mark as untouched
2666
+ actions.updateCellConfig({
2667
+ cellId,
2668
+ config: { hide_code: true },
2669
+ });
2670
+ actions.markUntouched({ cellId });
2671
+
2672
+ // Code should NOT be hidden because cell is untouched (user can edit)
2673
+ expect(state.cellData[cellId].config.hide_code).toBe(true);
2674
+ expect(state.untouchedNewCells.has(cellId)).toBe(true);
2675
+ expect(exportedForTesting.isCellCodeHidden(state, cellId)).toBe(false);
2676
+
2677
+ // 3. User blurs the cell (markTouched)
2678
+ actions.markTouched({ cellId });
2679
+
2680
+ // Now code should be hidden
2681
+ expect(state.untouchedNewCells.has(cellId)).toBe(false);
2682
+ expect(exportedForTesting.isCellCodeHidden(state, cellId)).toBe(true);
2683
+ });
2564
2684
  });
2565
2685
 
2566
2686
  describe("releaseCellAtoms", () => {
@@ -1033,6 +1033,20 @@ const {
1033
1033
 
1034
1034
  return state;
1035
1035
  },
1036
+ markUntouched: (state, action: { cellId: CellId }) => {
1037
+ const { cellId } = action;
1038
+
1039
+ if (!state.untouchedNewCells.has(cellId)) {
1040
+ const nextUntouchedNewCells = new Set(state.untouchedNewCells);
1041
+ nextUntouchedNewCells.add(cellId);
1042
+ return {
1043
+ ...state,
1044
+ untouchedNewCells: nextUntouchedNewCells,
1045
+ };
1046
+ }
1047
+
1048
+ return state;
1049
+ },
1036
1050
  scrollToTarget: (state) => {
1037
1051
  // Scroll to the specified cell and clear the scroll key.
1038
1052
  const scrollKey = state.scrollKey;
@@ -28,6 +28,13 @@ import type { LanguageAdapter } from "../types";
28
28
 
29
29
  export type MarkdownLanguageAdapterMetadata = MarkdownMetadata;
30
30
 
31
+ /**
32
+ * Default hide_code setting for markdown cells.
33
+ * When true, the markdown code is hidden after the cell is blurred,
34
+ * showing only the rendered output.
35
+ */
36
+ export const MARKDOWN_INITIAL_HIDE_CODE = true;
37
+
31
38
  /**
32
39
  * Language adapter for Markdown.
33
40
  */