@marimo-team/islands 0.19.8-dev37 → 0.19.8-dev38

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
@@ -12022,8 +12022,7 @@ ${d.join("\n")}`;
12022
12022
  let c = [
12023
12023
  ...this.nodes
12024
12024
  ], d = c[r];
12025
- if (!d.isCollapsed) throw Error(`Node ${e2} is already expanded`);
12026
- return c[r] = new TreeNode(d.value, false, []), c = arrayInsertMany(c, r + 1, d.children), this.withNodes(c);
12025
+ return d.isCollapsed ? (c[r] = new TreeNode(d.value, false, []), c = arrayInsertMany(c, r + 1, d.children), this.withNodes(c)) : this;
12027
12026
  }
12028
12027
  expandAll() {
12029
12028
  let e2 = [
@@ -12071,12 +12070,8 @@ ${d.join("\n")}`;
12071
12070
  return this.insert(e2, 0);
12072
12071
  }
12073
12072
  deleteAtIndex(e2) {
12074
- let r = this.atOrThrow(e2), c = this.withNodes(this.nodes);
12075
- try {
12076
- c = c.expand(r);
12077
- } catch {
12078
- }
12079
- return this.withNodes(arrayDelete(c.nodes, e2));
12073
+ let r = this.atOrThrow(e2), c = this.expand(r);
12074
+ return c.withNodes(arrayDelete(c.nodes, e2));
12080
12075
  }
12081
12076
  delete(e2) {
12082
12077
  let r = this.indexOfOrThrow(e2);
@@ -12088,13 +12083,7 @@ ${d.join("\n")}`;
12088
12083
  }
12089
12084
  findAndExpandDeep(e2) {
12090
12085
  let r = this.find(e2);
12091
- if (r.length === 0) return this;
12092
- let c = this.withNodes(this.nodes);
12093
- for (let e3 of r) try {
12094
- c = c.expand(e3);
12095
- } catch {
12096
- }
12097
- return c;
12086
+ return r.length === 0 ? this : r.reduce((e3, r2) => e3.expand(r2), this);
12098
12087
  }
12099
12088
  find(e2) {
12100
12089
  function r(c, d) {
@@ -73203,7 +73192,7 @@ Image URL: ${r.imageUrl}`)), contextToXml({
73203
73192
  return Logger.warn("Failed to get version from mount config"), null;
73204
73193
  }
73205
73194
  }
73206
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.8-dev37"), showCodeInRunModeAtom = atom(true);
73195
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.8-dev38"), showCodeInRunModeAtom = atom(true);
73207
73196
  atom(null);
73208
73197
  var import_compiler_runtime$88 = require_compiler_runtime();
73209
73198
  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-dev37",
3
+ "version": "0.19.8-dev38",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -214,16 +214,19 @@ describe("CollapsibleTree", () => {
214
214
  `);
215
215
  });
216
216
 
217
- it("fails to expand", () => {
217
+ it("fails to expand when node not found", () => {
218
218
  expect(() => tree.expand("five")).toThrowErrorMatchingInlineSnapshot(
219
219
  "[Error: Node five not found in tree. Valid ids: one,two,three,four]",
220
220
  );
221
- expect(() => {
222
- tree.expand("one");
223
- tree.expand("one");
224
- }).toThrowErrorMatchingInlineSnapshot(
225
- "[Error: Node one is already expanded]",
226
- );
221
+ });
222
+
223
+ it("expand on already expanded node is a no-op", () => {
224
+ // Expanding an already expanded node should return the same tree (no-op)
225
+ const result = tree.expand("one");
226
+ expect(result).toBe(tree);
227
+ // Can call multiple times without error
228
+ const result2 = tree.expand("one");
229
+ expect(result2).toBe(tree);
227
230
  });
228
231
 
229
232
  it("moves nodes correctly", () => {
@@ -378,6 +381,18 @@ describe("CollapsibleTree", () => {
378
381
  `);
379
382
  });
380
383
 
384
+ it("can delete non-collapsed nodes without throwing", () => {
385
+ // Deleting a non-collapsed node should not throw
386
+ // (previously this would throw "Node is already expanded" internally)
387
+ const result = tree.deleteAtIndex(1);
388
+ expect(result.toString()).toMatchInlineSnapshot(`
389
+ "one
390
+ three
391
+ four
392
+ "
393
+ `);
394
+ });
395
+
381
396
  it("fails to delete nodes", () => {
382
397
  expect(() => tree.deleteAtIndex(5)).toThrowErrorMatchingInlineSnapshot(
383
398
  "[Error: Node at index 5 not found in tree]",
@@ -360,7 +360,8 @@ export class CollapsibleTree<T> {
360
360
  }
361
361
 
362
362
  /**
363
- * Expand a node and all of its children
363
+ * Expand a node and all of its children.
364
+ * If the node is already expanded, returns the same tree (no-op).
364
365
  */
365
366
  expand(id: T): CollapsibleTree<T> {
366
367
  const nodeIndex = this.nodes.findIndex((n) => n.value === id);
@@ -373,7 +374,8 @@ export class CollapsibleTree<T> {
373
374
  let nodes = [...this.nodes];
374
375
  const node = nodes[nodeIndex];
375
376
  if (!node.isCollapsed) {
376
- throw new Error(`Node ${id} is already expanded`);
377
+ // Already expanded, no-op
378
+ return this;
377
379
  }
378
380
 
379
381
  nodes[nodeIndex] = new TreeNode(node.value, false, []);
@@ -495,13 +497,9 @@ export class CollapsibleTree<T> {
495
497
  */
496
498
  deleteAtIndex(idx: number): CollapsibleTree<T> {
497
499
  const id = this.atOrThrow(idx);
498
- let tree = this.withNodes(this.nodes);
499
- try {
500
- tree = tree.expand(id);
501
- } catch {
502
- // Don't care if its not expanded
503
- }
504
- return this.withNodes(arrayDelete(tree.nodes, idx));
500
+ // Expand the node first (if collapsed) to bring children back to top level
501
+ const tree = this.expand(id);
502
+ return tree.withNodes(arrayDelete(tree.nodes, idx));
505
503
  }
506
504
 
507
505
  delete(id: T): CollapsibleTree<T> {
@@ -524,16 +522,10 @@ export class CollapsibleTree<T> {
524
522
  if (found.length === 0) {
525
523
  return this;
526
524
  }
527
- let result = this.withNodes(this.nodes);
528
- for (const node of found) {
529
- try {
530
- result = result.expand(node);
531
- } catch {
532
- // Don't care if its the last node and its not expanded
533
- }
534
- }
535
-
536
- return result;
525
+ return found.reduce<CollapsibleTree<T>>(
526
+ (acc, node) => acc.expand(node),
527
+ this,
528
+ );
537
529
  }
538
530
 
539
531
  /**