@noya-app/noya-file-explorer 0.0.3 → 0.0.4

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/index.js CHANGED
@@ -35,7 +35,46 @@ var require_access = __commonJS({
35
35
  "../../node_modules/tree-visit/lib/access.js"(exports2) {
36
36
  "use strict";
37
37
  Object.defineProperty(exports2, "__esModule", { value: true });
38
- exports2.accessPath = exports2.access = void 0;
38
+ exports2.get = get;
39
+ exports2.ancestors = ancestors;
40
+ exports2.access = access;
41
+ exports2.accessPath = accessPath;
42
+ function get(node, indexPath, options) {
43
+ if (options.includeTraversalContext) {
44
+ const accessed = _getPath(node, indexPath, options);
45
+ return accessed[accessed.length - 1];
46
+ }
47
+ let path4 = indexPath.slice();
48
+ while (path4.length > 0) {
49
+ let index = path4.shift();
50
+ const children = options.getChildren(node, path4);
51
+ const child = children[index];
52
+ if (!child) {
53
+ return void 0;
54
+ }
55
+ node = child;
56
+ }
57
+ return node;
58
+ }
59
+ function ancestors(node, indexPath, options) {
60
+ return _getPath(node, indexPath, options).slice(0, -1);
61
+ }
62
+ function _getPath(node, indexPath, options) {
63
+ let path4 = indexPath.slice();
64
+ let result = [node];
65
+ while (path4.length > 0) {
66
+ let index = path4.shift();
67
+ const context = options.includeTraversalContext ? makeTraversalContext(result) : void 0;
68
+ const children = options.getChildren(node, path4, context);
69
+ const child = children[index];
70
+ if (!child) {
71
+ return result;
72
+ }
73
+ node = child;
74
+ result.push(node);
75
+ }
76
+ return result;
77
+ }
39
78
  function access(node, indexPath, options) {
40
79
  if (options.includeTraversalContext) {
41
80
  const accessed = accessPath(node, indexPath, options);
@@ -48,23 +87,24 @@ var require_access = __commonJS({
48
87
  }
49
88
  return node;
50
89
  }
51
- exports2.access = access;
52
90
  function accessPath(node, indexPath, options) {
53
91
  let path4 = indexPath.slice();
54
92
  let result = [node];
55
93
  while (path4.length > 0) {
56
94
  let index = path4.shift();
57
- const context = options.includeTraversalContext ? {
58
- getRoot: () => result[0],
59
- getParent: () => result[result.length - 2],
60
- getAncestors: () => result.slice(0, -1)
61
- } : void 0;
95
+ const context = options.includeTraversalContext ? makeTraversalContext(result) : void 0;
62
96
  node = options.getChildren(node, path4, context)[index];
63
97
  result.push(node);
64
98
  }
65
99
  return result;
66
100
  }
67
- exports2.accessPath = accessPath;
101
+ function makeTraversalContext(array) {
102
+ return {
103
+ getRoot: () => array[0],
104
+ getParent: () => array[array.length - 2],
105
+ getAncestors: () => array.slice(0, -1)
106
+ };
107
+ }
68
108
  }
69
109
  });
70
110
 
@@ -73,7 +113,8 @@ var require_sort = __commonJS({
73
113
  "../../node_modules/tree-visit/lib/sort.js"(exports2) {
74
114
  "use strict";
75
115
  Object.defineProperty(exports2, "__esModule", { value: true });
76
- exports2.sortPaths = exports2.comparePathsByComponent = void 0;
116
+ exports2.comparePathsByComponent = comparePathsByComponent;
117
+ exports2.sortPaths = sortPaths;
77
118
  function comparePathsByComponent(a, b) {
78
119
  for (let i = 0; i < Math.min(a.length, b.length); i++) {
79
120
  if (a[i] < b[i])
@@ -83,11 +124,9 @@ var require_sort = __commonJS({
83
124
  }
84
125
  return a.length - b.length;
85
126
  }
86
- exports2.comparePathsByComponent = comparePathsByComponent;
87
127
  function sortPaths(indexPaths) {
88
128
  return [...indexPaths].sort(comparePathsByComponent);
89
129
  }
90
- exports2.sortPaths = sortPaths;
91
130
  }
92
131
  });
93
132
 
@@ -96,7 +135,7 @@ var require_ancestors = __commonJS({
96
135
  "../../node_modules/tree-visit/lib/ancestors.js"(exports2) {
97
136
  "use strict";
98
137
  Object.defineProperty(exports2, "__esModule", { value: true });
99
- exports2.ancestorPaths = void 0;
138
+ exports2.ancestorPaths = ancestorPaths2;
100
139
  var sort_1 = require_sort();
101
140
  function ancestorPaths2(paths, options) {
102
141
  var _a;
@@ -114,7 +153,6 @@ var require_ancestors = __commonJS({
114
153
  }
115
154
  return Array.from(result.values());
116
155
  }
117
- exports2.ancestorPaths = ancestorPaths2;
118
156
  }
119
157
  });
120
158
 
@@ -123,7 +161,7 @@ var require_boxDiagram = __commonJS({
123
161
  "../../node_modules/tree-visit/lib/diagram/boxDiagram.js"(exports2) {
124
162
  "use strict";
125
163
  Object.defineProperty(exports2, "__esModule", { value: true });
126
- exports2.boxDiagram = void 0;
164
+ exports2.boxDiagram = boxDiagram;
127
165
  var BoxDrawing;
128
166
  (function(BoxDrawing2) {
129
167
  BoxDrawing2["TopLeft"] = "\u250C";
@@ -238,7 +276,6 @@ var require_boxDiagram = __commonJS({
238
276
  function boxDiagram(node, options) {
239
277
  return nodeDiagram(node, [], options).contents.join("\n");
240
278
  }
241
- exports2.boxDiagram = boxDiagram;
242
279
  function centerIndex(width) {
243
280
  return Math.floor(width / 2);
244
281
  }
@@ -267,7 +304,9 @@ var require_directoryDiagram = __commonJS({
267
304
  "../../node_modules/tree-visit/lib/diagram/directoryDiagram.js"(exports2) {
268
305
  "use strict";
269
306
  Object.defineProperty(exports2, "__esModule", { value: true });
270
- exports2.prefixBlock = exports2.isMultiline = exports2.directoryDiagram = void 0;
307
+ exports2.directoryDiagram = directoryDiagram;
308
+ exports2.isMultiline = isMultiline;
309
+ exports2.prefixBlock = prefixBlock;
271
310
  var LinePrefix;
272
311
  (function(LinePrefix2) {
273
312
  LinePrefix2["Child"] = "\u251C\u2500\u2500 ";
@@ -314,17 +353,14 @@ var require_directoryDiagram = __commonJS({
314
353
  const strings = lines.map((line) => prefixBlock(line.label, line.prefix, line.multilinePrefix));
315
354
  return strings.join("\n");
316
355
  }
317
- exports2.directoryDiagram = directoryDiagram;
318
356
  function isMultiline(line) {
319
357
  return line.includes("\n");
320
358
  }
321
- exports2.isMultiline = isMultiline;
322
359
  function prefixBlock(block, prefix, multilinePrefix) {
323
360
  if (!isMultiline(block))
324
361
  return prefix + block;
325
362
  return block.split("\n").map((line, index) => (index === 0 ? prefix : multilinePrefix) + line).join("\n");
326
363
  }
327
- exports2.prefixBlock = prefixBlock;
328
364
  }
329
365
  });
330
366
 
@@ -333,7 +369,7 @@ var require_diagram = __commonJS({
333
369
  "../../node_modules/tree-visit/lib/diagram.js"(exports2) {
334
370
  "use strict";
335
371
  Object.defineProperty(exports2, "__esModule", { value: true });
336
- exports2.diagram = void 0;
372
+ exports2.diagram = diagram;
337
373
  var boxDiagram_1 = require_boxDiagram();
338
374
  var directoryDiagram_1 = require_directoryDiagram();
339
375
  function diagram(node, options) {
@@ -342,7 +378,6 @@ var require_diagram = __commonJS({
342
378
  }
343
379
  return (0, directoryDiagram_1.directoryDiagram)(node, options);
344
380
  }
345
- exports2.diagram = diagram;
346
381
  }
347
382
  });
348
383
 
@@ -351,11 +386,16 @@ var require_visit = __commonJS({
351
386
  "../../node_modules/tree-visit/lib/visit.js"(exports2) {
352
387
  "use strict";
353
388
  Object.defineProperty(exports2, "__esModule", { value: true });
354
- exports2.visit = exports2.STOP = exports2.SKIP = void 0;
389
+ exports2.STOP = exports2.SKIP = void 0;
390
+ exports2.visit = visit;
355
391
  exports2.SKIP = "skip";
356
392
  exports2.STOP = "stop";
357
393
  function visit(node, options) {
358
- const { onEnter, onLeave, getChildren, onDetectCycle, getIdentifier } = options;
394
+ const { onEnter, onLeave, getChildren: originalGetChildren, onDetectCycle, getIdentifier, direction = "forward" } = options;
395
+ const getChildren = (node2, indexPath2, context2) => {
396
+ const children = originalGetChildren(node2, indexPath2, context2);
397
+ return direction === "forward" ? children : children.slice().reverse();
398
+ };
359
399
  let indexPath = [];
360
400
  let stack = [{ node }];
361
401
  const visited = onDetectCycle ? /* @__PURE__ */ new Set() : void 0;
@@ -400,7 +440,7 @@ var require_visit = __commonJS({
400
440
  if (wrapper.state !== -1) {
401
441
  if (wrapper.state < children.length) {
402
442
  let currentIndex = wrapper.state;
403
- indexPath.push(currentIndex);
443
+ indexPath.push(direction === "forward" ? currentIndex : children.length - currentIndex - 1);
404
444
  stack.push({ node: children[currentIndex] });
405
445
  wrapper.state = currentIndex + 1;
406
446
  continue;
@@ -417,7 +457,23 @@ var require_visit = __commonJS({
417
457
  stack.pop();
418
458
  }
419
459
  }
420
- exports2.visit = visit;
460
+ }
461
+ });
462
+
463
+ // ../../node_modules/tree-visit/lib/entries.js
464
+ var require_entries = __commonJS({
465
+ "../../node_modules/tree-visit/lib/entries.js"(exports2) {
466
+ "use strict";
467
+ Object.defineProperty(exports2, "__esModule", { value: true });
468
+ exports2.entries = entries;
469
+ var visit_1 = require_visit();
470
+ function entries(node, options) {
471
+ let result = [];
472
+ (0, visit_1.visit)(node, Object.assign(Object.assign({}, options), { onEnter: (item, indexPath) => {
473
+ result.push([indexPath, item]);
474
+ } }));
475
+ return result;
476
+ }
421
477
  }
422
478
  });
423
479
 
@@ -426,7 +482,10 @@ var require_find = __commonJS({
426
482
  "../../node_modules/tree-visit/lib/find.js"(exports2) {
427
483
  "use strict";
428
484
  Object.defineProperty(exports2, "__esModule", { value: true });
429
- exports2.findAllIndexPaths = exports2.findIndexPath = exports2.findAll = exports2.find = void 0;
485
+ exports2.find = find;
486
+ exports2.findAll = findAll;
487
+ exports2.findPath = findPath;
488
+ exports2.findAllPaths = findAllPaths;
430
489
  var visit_1 = require_visit();
431
490
  function find(node, options) {
432
491
  let found;
@@ -438,7 +497,6 @@ var require_find = __commonJS({
438
497
  } }));
439
498
  return found;
440
499
  }
441
- exports2.find = find;
442
500
  function findAll(node, options) {
443
501
  let found = [];
444
502
  (0, visit_1.visit)(node, {
@@ -451,8 +509,7 @@ var require_find = __commonJS({
451
509
  });
452
510
  return found;
453
511
  }
454
- exports2.findAll = findAll;
455
- function findIndexPath(node, options) {
512
+ function findPath(node, options) {
456
513
  let found;
457
514
  (0, visit_1.visit)(node, {
458
515
  onEnter: (child, indexPath) => {
@@ -465,8 +522,7 @@ var require_find = __commonJS({
465
522
  });
466
523
  return found;
467
524
  }
468
- exports2.findIndexPath = findIndexPath;
469
- function findAllIndexPaths(node, options) {
525
+ function findAllPaths(node, options) {
470
526
  let found = [];
471
527
  (0, visit_1.visit)(node, {
472
528
  onEnter: (child, indexPath) => {
@@ -478,7 +534,6 @@ var require_find = __commonJS({
478
534
  });
479
535
  return found;
480
536
  }
481
- exports2.findAllIndexPaths = findAllIndexPaths;
482
537
  }
483
538
  });
484
539
 
@@ -487,7 +542,7 @@ var require_reduce = __commonJS({
487
542
  "../../node_modules/tree-visit/lib/reduce.js"(exports2) {
488
543
  "use strict";
489
544
  Object.defineProperty(exports2, "__esModule", { value: true });
490
- exports2.reduce = void 0;
545
+ exports2.reduce = reduce;
491
546
  var visit_1 = require_visit();
492
547
  function reduce(node, options) {
493
548
  let result = options.initialResult;
@@ -496,7 +551,6 @@ var require_reduce = __commonJS({
496
551
  } }));
497
552
  return result;
498
553
  }
499
- exports2.reduce = reduce;
500
554
  }
501
555
  });
502
556
 
@@ -505,7 +559,7 @@ var require_flat = __commonJS({
505
559
  "../../node_modules/tree-visit/lib/flat.js"(exports2) {
506
560
  "use strict";
507
561
  Object.defineProperty(exports2, "__esModule", { value: true });
508
- exports2.flat = void 0;
562
+ exports2.flat = flat;
509
563
  var reduce_1 = require_reduce();
510
564
  function flat(node, options) {
511
565
  return (0, reduce_1.reduce)(node, Object.assign(Object.assign({}, options), { initialResult: [], nextResult: (result, child) => {
@@ -513,24 +567,6 @@ var require_flat = __commonJS({
513
567
  return result;
514
568
  } }));
515
569
  }
516
- exports2.flat = flat;
517
- }
518
- });
519
-
520
- // ../../node_modules/tree-visit/lib/flatMap.js
521
- var require_flatMap = __commonJS({
522
- "../../node_modules/tree-visit/lib/flatMap.js"(exports2) {
523
- "use strict";
524
- Object.defineProperty(exports2, "__esModule", { value: true });
525
- exports2.flatMap = void 0;
526
- var reduce_1 = require_reduce();
527
- function flatMap(node, options) {
528
- return (0, reduce_1.reduce)(node, Object.assign(Object.assign({}, options), { initialResult: [], nextResult: (result, child, indexPath) => {
529
- result.push(...options.transform(child, indexPath));
530
- return result;
531
- } }));
532
- }
533
- exports2.flatMap = flatMap;
534
570
  }
535
571
  });
536
572
 
@@ -539,9 +575,15 @@ var require_map = __commonJS({
539
575
  "../../node_modules/tree-visit/lib/map.js"(exports2) {
540
576
  "use strict";
541
577
  Object.defineProperty(exports2, "__esModule", { value: true });
542
- exports2.map = void 0;
578
+ exports2.map = map;
579
+ exports2.flatMap = flatMap;
543
580
  var visit_1 = require_visit();
544
581
  function map(node, options) {
582
+ return flatMap(node, Object.assign(Object.assign({}, options), { transform: (node2, transformedChildren, indexPath) => [
583
+ options.transform(node2, transformedChildren, indexPath)
584
+ ] }));
585
+ }
586
+ function flatMap(node, options) {
545
587
  const childrenMap = {};
546
588
  (0, visit_1.visit)(node, Object.assign(Object.assign({}, options), { onLeave: (child, indexPath) => {
547
589
  var _a, _b;
@@ -550,12 +592,56 @@ var require_map = __commonJS({
550
592
  const transformed = options.transform(child, (_a = childrenMap[key]) !== null && _a !== void 0 ? _a : [], indexPath);
551
593
  const parentKey = keyIndexPath.slice(0, -1).join();
552
594
  const parentChildren = (_b = childrenMap[parentKey]) !== null && _b !== void 0 ? _b : [];
553
- parentChildren.push(transformed);
595
+ parentChildren.push(...transformed);
554
596
  childrenMap[parentKey] = parentChildren;
555
597
  } }));
556
598
  return childrenMap[""][0];
557
599
  }
558
- exports2.map = map;
600
+ }
601
+ });
602
+
603
+ // ../../node_modules/tree-visit/lib/transformPath.js
604
+ var require_transformPath = __commonJS({
605
+ "../../node_modules/tree-visit/lib/transformPath.js"(exports2) {
606
+ "use strict";
607
+ Object.defineProperty(exports2, "__esModule", { value: true });
608
+ exports2.transformPath = transformPath;
609
+ var sort_1 = require_sort();
610
+ function commonAncestor(path4, otherPath) {
611
+ const length = Math.min(path4.length, otherPath.length);
612
+ for (let i = 0; i < length; i++) {
613
+ if (path4[i] !== otherPath[i]) {
614
+ return path4.slice(0, i);
615
+ }
616
+ }
617
+ return path4.slice(0, length);
618
+ }
619
+ function transformPath(path4, operation, otherPath, count = 1) {
620
+ if (otherPath.length > path4.length || (0, sort_1.comparePathsByComponent)(otherPath, path4) > 0) {
621
+ return path4;
622
+ }
623
+ if (otherPath.length === 0 && operation === "remove") {
624
+ return void 0;
625
+ }
626
+ const common = commonAncestor(path4, otherPath);
627
+ const adjustmentIndex = common.length === path4.length || common.length === otherPath.length ? common.length - 1 : common.length;
628
+ const pathValue = path4[adjustmentIndex];
629
+ const otherPathValue = otherPath[adjustmentIndex];
630
+ if (operation === "insert" && otherPathValue <= pathValue) {
631
+ const newPath = [...path4];
632
+ newPath[adjustmentIndex] += count;
633
+ return newPath;
634
+ } else if (operation === "remove") {
635
+ if (otherPathValue === pathValue) {
636
+ return void 0;
637
+ } else if (otherPathValue < pathValue) {
638
+ const newPath = [...path4];
639
+ newPath[adjustmentIndex] -= count;
640
+ return newPath;
641
+ }
642
+ }
643
+ return path4;
644
+ }
559
645
  }
560
646
  });
561
647
 
@@ -564,9 +650,18 @@ var require_operation = __commonJS({
564
650
  "../../node_modules/tree-visit/lib/operation.js"(exports2) {
565
651
  "use strict";
566
652
  Object.defineProperty(exports2, "__esModule", { value: true });
567
- exports2.splice = exports2.applyOperations = exports2.getReplaceOperations = exports2.getRemovalOperations = exports2.getInsertionOperations = exports2.replaceOperation = exports2.removeOperation = exports2.insertOperation = void 0;
653
+ exports2.insertOperation = insertOperation;
654
+ exports2.removeOperation = removeOperation;
655
+ exports2.replaceOperation = replaceOperation;
656
+ exports2.getInsertionOperations = getInsertionOperations;
657
+ exports2.getRemovalOperations = getRemovalOperations;
658
+ exports2.getReplaceOperations = getReplaceOperations;
659
+ exports2.applyOperations = applyOperations;
660
+ exports2.arraySplice = arraySplice;
661
+ exports2.transformPathsByOperations = transformPathsByOperations;
568
662
  var ancestors_1 = require_ancestors();
569
663
  var map_1 = require_map();
664
+ var transformPath_1 = require_transformPath();
570
665
  function insertOperation(index, nodes) {
571
666
  return {
572
667
  type: "insert",
@@ -574,20 +669,17 @@ var require_operation = __commonJS({
574
669
  nodes
575
670
  };
576
671
  }
577
- exports2.insertOperation = insertOperation;
578
672
  function removeOperation(indexes) {
579
673
  return {
580
674
  type: "remove",
581
675
  indexes
582
676
  };
583
677
  }
584
- exports2.removeOperation = removeOperation;
585
678
  function replaceOperation() {
586
679
  return {
587
680
  type: "replace"
588
681
  };
589
682
  }
590
- exports2.replaceOperation = replaceOperation;
591
683
  function splitIndexPath(indexPath) {
592
684
  return [indexPath.slice(0, -1), indexPath[indexPath.length - 1]];
593
685
  }
@@ -617,7 +709,6 @@ var require_operation = __commonJS({
617
709
  }
618
710
  return operations;
619
711
  }
620
- exports2.getInsertionOperations = getInsertionOperations;
621
712
  function getRemovalOperations(indexPaths) {
622
713
  var _a, _b;
623
714
  const _ancestorIndexPaths = (0, ancestors_1.ancestorPaths)(indexPaths);
@@ -641,7 +732,6 @@ var require_operation = __commonJS({
641
732
  }
642
733
  return operations;
643
734
  }
644
- exports2.getRemovalOperations = getRemovalOperations;
645
735
  function getReplaceOperations(indexPath, node) {
646
736
  const operations = /* @__PURE__ */ new Map();
647
737
  const [parentIndexPath, index] = splitIndexPath(indexPath);
@@ -657,7 +747,9 @@ var require_operation = __commonJS({
657
747
  });
658
748
  return operations;
659
749
  }
660
- exports2.getReplaceOperations = getReplaceOperations;
750
+ function adjustInsertIndex(index, removeIndexes) {
751
+ return removeIndexes.reduce((index2, removedIndex) => removedIndex < index2 ? index2 - 1 : index2, index);
752
+ }
661
753
  function applyOperations(node, operations, options) {
662
754
  return (0, map_1.map)(node, Object.assign(Object.assign({}, options), {
663
755
  // Avoid calling `getChildren` for every node in the tree.
@@ -683,10 +775,10 @@ var require_operation = __commonJS({
683
775
  return options.create(node2, children.filter((_, index) => !operation.indexes.includes(index)), indexPath);
684
776
  case "removeThenInsert":
685
777
  const updatedChildren = children.filter((_, index) => !operation.removeIndexes.includes(index));
686
- const adjustedIndex = operation.removeIndexes.reduce((index, removedIndex) => removedIndex < index ? index - 1 : index, operation.insertIndex);
687
- return options.create(node2, splice(updatedChildren, adjustedIndex, 0, ...operation.insertNodes), indexPath);
778
+ const adjustedIndex = adjustInsertIndex(operation.insertIndex, operation.removeIndexes);
779
+ return options.create(node2, arraySplice(updatedChildren, adjustedIndex, 0, ...operation.insertNodes), indexPath);
688
780
  case "insert":
689
- return options.create(node2, splice(children, operation.index, 0, ...operation.nodes), indexPath);
781
+ return options.create(node2, arraySplice(children, operation.index, 0, ...operation.nodes), indexPath);
690
782
  case "replace":
691
783
  return options.create(node2, children, indexPath);
692
784
  default:
@@ -695,15 +787,53 @@ var require_operation = __commonJS({
695
787
  }
696
788
  }));
697
789
  }
698
- exports2.applyOperations = applyOperations;
699
- function splice(array, start, deleteCount, ...items) {
790
+ function arraySplice(array, start, deleteCount, ...items) {
700
791
  return [
701
792
  ...array.slice(0, start),
702
793
  ...items,
703
794
  ...array.slice(start + deleteCount)
704
795
  ];
705
796
  }
706
- exports2.splice = splice;
797
+ function transformPathsByOperations(paths, operations) {
798
+ let transformedPaths = paths;
799
+ for (const [parentKey, operation] of operations.entries()) {
800
+ const parentPath = parentKey ? parentKey.split(",").map(Number) : [];
801
+ transformedPaths = transformByOperation(transformedPaths, parentPath, operation);
802
+ }
803
+ return transformedPaths;
804
+ }
805
+ function transformByOperation(transformedPaths, parentPath, operation) {
806
+ switch (operation.type) {
807
+ case "insert": {
808
+ const otherPath = parentPath.concat(operation.index);
809
+ return transformedPaths.map((path4) => path4 ? (0, transformPath_1.transformPath)(path4, "insert", otherPath, operation.nodes.length) : void 0);
810
+ }
811
+ case "remove": {
812
+ const otherPaths = [...operation.indexes].reverse().map((index) => parentPath.concat(index));
813
+ return transformedPaths.map((path4) => {
814
+ for (const otherPath of otherPaths) {
815
+ path4 = path4 ? (0, transformPath_1.transformPath)(path4, "remove", otherPath) : void 0;
816
+ }
817
+ return path4;
818
+ });
819
+ }
820
+ case "removeThenInsert": {
821
+ const result = transformByOperation(transformedPaths, parentPath, {
822
+ type: "remove",
823
+ indexes: operation.removeIndexes
824
+ });
825
+ const insertIndex = adjustInsertIndex(operation.insertIndex, operation.removeIndexes);
826
+ return transformByOperation(result, parentPath, {
827
+ type: "insert",
828
+ index: insertIndex,
829
+ nodes: operation.insertNodes
830
+ });
831
+ }
832
+ case "replace": {
833
+ return transformedPaths;
834
+ }
835
+ }
836
+ }
707
837
  }
708
838
  });
709
839
 
@@ -712,17 +842,27 @@ var require_insert = __commonJS({
712
842
  "../../node_modules/tree-visit/lib/insert.js"(exports2) {
713
843
  "use strict";
714
844
  Object.defineProperty(exports2, "__esModule", { value: true });
715
- exports2.insert = void 0;
845
+ exports2.insert = insert;
846
+ exports2.insertWithPathTracking = insertWithPathTracking;
716
847
  var operation_1 = require_operation();
717
848
  function insert(node, options) {
718
- const { nodes, at } = options;
849
+ return _insertWithPathTracking(node, options).node;
850
+ }
851
+ function insertWithPathTracking(node, options) {
852
+ return _insertWithPathTracking(node, options);
853
+ }
854
+ function _insertWithPathTracking(node, options) {
855
+ const { nodes, path: at, track } = options;
719
856
  if (at.length === 0) {
720
857
  throw new Error(`Can't insert nodes at the root`);
721
858
  }
722
859
  const state = (0, operation_1.getInsertionOperations)(at, nodes);
723
- return (0, operation_1.applyOperations)(node, state, options);
860
+ const transformedPaths = track ? (0, operation_1.transformPathsByOperations)(track, state) : [];
861
+ return {
862
+ node: (0, operation_1.applyOperations)(node, state, options),
863
+ paths: transformedPaths
864
+ };
724
865
  }
725
- exports2.insert = insert;
726
866
  }
727
867
  });
728
868
 
@@ -731,14 +871,14 @@ var require_move = __commonJS({
731
871
  "../../node_modules/tree-visit/lib/move.js"(exports2) {
732
872
  "use strict";
733
873
  Object.defineProperty(exports2, "__esModule", { value: true });
734
- exports2.move = void 0;
874
+ exports2.move = move;
735
875
  var access_1 = require_access();
736
876
  var ancestors_1 = require_ancestors();
737
877
  var operation_1 = require_operation();
738
878
  function move(node, options) {
739
- if (options.indexPaths.length === 0)
879
+ if (options.paths.length === 0)
740
880
  return node;
741
- for (const indexPath of options.indexPaths) {
881
+ for (const indexPath of options.paths) {
742
882
  if (indexPath.length === 0) {
743
883
  throw new Error(`Can't move the root node`);
744
884
  }
@@ -746,12 +886,11 @@ var require_move = __commonJS({
746
886
  if (options.to.length === 0) {
747
887
  throw new Error(`Can't move nodes to the root`);
748
888
  }
749
- const _ancestorIndexPaths = (0, ancestors_1.ancestorPaths)(options.indexPaths);
889
+ const _ancestorIndexPaths = (0, ancestors_1.ancestorPaths)(options.paths);
750
890
  const nodesToInsert = _ancestorIndexPaths.map((indexPath) => (0, access_1.access)(node, indexPath, options));
751
891
  const operations = (0, operation_1.getInsertionOperations)(options.to, nodesToInsert, (0, operation_1.getRemovalOperations)(_ancestorIndexPaths));
752
892
  return (0, operation_1.applyOperations)(node, operations, options);
753
893
  }
754
- exports2.move = move;
755
894
  }
756
895
  });
757
896
 
@@ -760,20 +899,24 @@ var require_remove = __commonJS({
760
899
  "../../node_modules/tree-visit/lib/remove.js"(exports2) {
761
900
  "use strict";
762
901
  Object.defineProperty(exports2, "__esModule", { value: true });
763
- exports2.remove = void 0;
902
+ exports2.remove = remove;
903
+ exports2.removeWithPathTracking = removeWithPathTracking;
764
904
  var operation_1 = require_operation();
765
905
  function remove(node, options) {
766
- if (options.indexPaths.length === 0)
767
- return node;
768
- for (const indexPath of options.indexPaths) {
769
- if (indexPath.length === 0) {
770
- throw new Error(`Can't remove the root node`);
771
- }
772
- }
773
- const operations = (0, operation_1.getRemovalOperations)(options.indexPaths);
774
- return (0, operation_1.applyOperations)(node, operations, options);
906
+ return _removeWithPathTracking(node, options).node;
907
+ }
908
+ function removeWithPathTracking(node, options) {
909
+ return _removeWithPathTracking(node, options);
910
+ }
911
+ function _removeWithPathTracking(node, options) {
912
+ const { paths, track } = options;
913
+ const operations = (0, operation_1.getRemovalOperations)(paths);
914
+ const transformedPaths = track ? (0, operation_1.transformPathsByOperations)(track, operations) : [];
915
+ return {
916
+ node: (0, operation_1.applyOperations)(node, operations, options),
917
+ paths: transformedPaths
918
+ };
775
919
  }
776
- exports2.remove = remove;
777
920
  }
778
921
  });
779
922
 
@@ -782,15 +925,53 @@ var require_replace = __commonJS({
782
925
  "../../node_modules/tree-visit/lib/replace.js"(exports2) {
783
926
  "use strict";
784
927
  Object.defineProperty(exports2, "__esModule", { value: true });
785
- exports2.replace = void 0;
928
+ exports2.replace = replace;
786
929
  var operation_1 = require_operation();
787
930
  function replace(node, options) {
788
- if (options.at.length === 0)
931
+ if (options.path.length === 0)
789
932
  return options.node;
790
- const operations = (0, operation_1.getReplaceOperations)(options.at, options.node);
933
+ const operations = (0, operation_1.getReplaceOperations)(options.path, options.node);
791
934
  return (0, operation_1.applyOperations)(node, operations, options);
792
935
  }
793
- exports2.replace = replace;
936
+ }
937
+ });
938
+
939
+ // ../../node_modules/tree-visit/lib/splice.js
940
+ var require_splice = __commonJS({
941
+ "../../node_modules/tree-visit/lib/splice.js"(exports2) {
942
+ "use strict";
943
+ Object.defineProperty(exports2, "__esModule", { value: true });
944
+ exports2.splice = splice;
945
+ exports2.spliceWithPathTracking = spliceWithPathTracking;
946
+ var operation_1 = require_operation();
947
+ function splice(node, options) {
948
+ return _spliceWithPathTracking(node, options).node;
949
+ }
950
+ function spliceWithPathTracking(node, options) {
951
+ return _spliceWithPathTracking(node, options);
952
+ }
953
+ function _spliceWithPathTracking(node, options) {
954
+ const { path: path4, deleteCount = 0, nodes, track } = options;
955
+ if (path4.length === 0) {
956
+ throw new Error(`Can't splice at the root`);
957
+ }
958
+ const pathsToRemove = getPathsToRemove(path4, deleteCount);
959
+ const operations = (0, operation_1.getInsertionOperations)(path4, nodes, (0, operation_1.getRemovalOperations)(pathsToRemove));
960
+ const transformedPaths = track ? (0, operation_1.transformPathsByOperations)(track, operations) : [];
961
+ return {
962
+ node: (0, operation_1.applyOperations)(node, operations, options),
963
+ paths: transformedPaths
964
+ };
965
+ }
966
+ function getPathsToRemove(path4, deleteCount) {
967
+ let pathsToRemove = [];
968
+ let parentPath = path4.slice(0, -1);
969
+ let index = path4[path4.length - 1];
970
+ for (let i = 0; i < deleteCount; i++) {
971
+ pathsToRemove.push(parentPath.concat(index + i));
972
+ }
973
+ return pathsToRemove;
974
+ }
794
975
  }
795
976
  });
796
977
 
@@ -799,18 +980,19 @@ var require_defineTree = __commonJS({
799
980
  "../../node_modules/tree-visit/lib/defineTree.js"(exports2) {
800
981
  "use strict";
801
982
  Object.defineProperty(exports2, "__esModule", { value: true });
802
- exports2.defineTree = void 0;
983
+ exports2.defineTree = defineTree2;
803
984
  var access_1 = require_access();
804
985
  var diagram_1 = require_diagram();
986
+ var entries_1 = require_entries();
805
987
  var find_1 = require_find();
806
988
  var flat_1 = require_flat();
807
- var flatMap_1 = require_flatMap();
808
989
  var insert_1 = require_insert();
809
990
  var map_1 = require_map();
810
991
  var move_1 = require_move();
811
992
  var reduce_1 = require_reduce();
812
993
  var remove_1 = require_remove();
813
994
  var replace_1 = require_replace();
995
+ var splice_1 = require_splice();
814
996
  var visit_1 = require_visit();
815
997
  var Tree = class _Tree {
816
998
  constructor(getChildrenOrBaseOptions, appliedOptions) {
@@ -822,19 +1004,26 @@ var require_defineTree = __commonJS({
822
1004
  this.withOptions = (newOptions) => new _Tree(this.baseOptions, Object.assign(Object.assign({}, this.appliedOptions), newOptions));
823
1005
  this.access = (node, indexPath) => (0, access_1.access)(node, indexPath, this.mergeOptions({}));
824
1006
  this.accessPath = (node, indexPath) => (0, access_1.accessPath)(node, indexPath, this.mergeOptions({}));
1007
+ this.get = (node, indexPath) => (0, access_1.get)(node, indexPath, this.mergeOptions({}));
1008
+ this.ancestors = (node, indexPath) => (0, access_1.ancestors)(node, indexPath, this.mergeOptions({}));
825
1009
  this.diagram = (node, options) => typeof options === "function" ? (0, diagram_1.diagram)(node, this.mergeOptions({ getLabel: options })) : (0, diagram_1.diagram)(node, this.mergeOptions(options));
826
1010
  this.find = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.find)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.find)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
827
1011
  this.findAll = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.findAll)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.findAll)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
828
- this.findIndexPath = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.findIndexPath)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.findIndexPath)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
829
- this.findAllIndexPaths = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.findAllIndexPaths)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.findAllIndexPaths)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
1012
+ this.findPath = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.findPath)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.findPath)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
1013
+ this.findAllPaths = (node, predicateOrOptions) => typeof predicateOrOptions === "function" ? (0, find_1.findAllPaths)(node, this.mergeOptions({ predicate: predicateOrOptions })) : (0, find_1.findAllPaths)(node, this.mergeOptions(Object.assign({}, predicateOrOptions)));
1014
+ this.entries = (node) => (0, entries_1.entries)(node, this.mergeOptions({}));
830
1015
  this.flat = (node) => (0, flat_1.flat)(node, this.mergeOptions({}));
831
- this.flatMap = (node, transform) => (0, flatMap_1.flatMap)(node, this.mergeOptions({ transform }));
832
1016
  this.reduce = (node, nextResult, initialResult) => (0, reduce_1.reduce)(node, this.mergeOptions({ nextResult, initialResult }));
833
1017
  this.map = (node, transform) => (0, map_1.map)(node, this.mergeOptions({ transform }));
1018
+ this.flatMap = (node, transform) => (0, map_1.flatMap)(node, this.mergeOptions({ transform }));
834
1019
  this.visit = (node, onEnterOrOptions) => typeof onEnterOrOptions === "function" ? (0, visit_1.visit)(node, this.mergeOptions({ onEnter: onEnterOrOptions })) : (0, visit_1.visit)(node, this.mergeOptions(Object.assign({}, onEnterOrOptions)));
835
1020
  this.insert = (node, options) => (0, insert_1.insert)(node, this.mergeOptions(options));
1021
+ this.insertWithPathTracking = (node, options) => (0, insert_1.insertWithPathTracking)(node, this.mergeOptions(options));
836
1022
  this.remove = (node, options) => (0, remove_1.remove)(node, this.mergeOptions(options));
1023
+ this.removeWithPathTracking = (node, options) => (0, remove_1.removeWithPathTracking)(node, this.mergeOptions(options));
837
1024
  this.move = (node, options) => (0, move_1.move)(node, this.mergeOptions(options));
1025
+ this.splice = (node, options) => (0, splice_1.splice)(node, this.mergeOptions(options));
1026
+ this.spliceWithPathTracking = (node, options) => (0, splice_1.spliceWithPathTracking)(node, this.mergeOptions(options));
838
1027
  this.replace = (node, options) => (0, replace_1.replace)(node, this.mergeOptions(options));
839
1028
  this.baseOptions = typeof getChildrenOrBaseOptions === "function" ? { getChildren: getChildrenOrBaseOptions } : getChildrenOrBaseOptions;
840
1029
  this._getChildren = this.baseOptions.getChildren;
@@ -843,7 +1032,6 @@ var require_defineTree = __commonJS({
843
1032
  function defineTree2(getChildren) {
844
1033
  return new Tree(getChildren, {});
845
1034
  }
846
- exports2.defineTree = defineTree2;
847
1035
  }
848
1036
  });
849
1037
 
@@ -880,9 +1068,13 @@ var require_lib = __commonJS({
880
1068
  "use strict";
881
1069
  var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
882
1070
  if (k2 === void 0) k2 = k;
883
- Object.defineProperty(o, k2, { enumerable: true, get: function() {
884
- return m[k];
885
- } });
1071
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1072
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1073
+ desc = { enumerable: true, get: function() {
1074
+ return m[k];
1075
+ } };
1076
+ }
1077
+ Object.defineProperty(o, k2, desc);
886
1078
  } : function(o, m, k, k2) {
887
1079
  if (k2 === void 0) k2 = k;
888
1080
  o[k2] = m[k];
@@ -895,9 +1087,9 @@ var require_lib = __commonJS({
895
1087
  __exportStar(require_ancestors(), exports2);
896
1088
  __exportStar(require_defineTree(), exports2);
897
1089
  __exportStar(require_diagram(), exports2);
1090
+ __exportStar(require_entries(), exports2);
898
1091
  __exportStar(require_find(), exports2);
899
1092
  __exportStar(require_flat(), exports2);
900
- __exportStar(require_flatMap(), exports2);
901
1093
  __exportStar(require_indexPath(), exports2);
902
1094
  __exportStar(require_insert(), exports2);
903
1095
  __exportStar(require_map(), exports2);
@@ -907,6 +1099,8 @@ var require_lib = __commonJS({
907
1099
  __exportStar(require_remove(), exports2);
908
1100
  __exportStar(require_replace(), exports2);
909
1101
  __exportStar(require_sort(), exports2);
1102
+ __exportStar(require_splice(), exports2);
1103
+ __exportStar(require_transformPath(), exports2);
910
1104
  __exportStar(require_visit(), exports2);
911
1105
  __exportStar(require_withOptions(), exports2);
912
1106
  }
@@ -1125,7 +1319,7 @@ var moveUpAFolder = ({
1125
1319
  media,
1126
1320
  selectedIds
1127
1321
  }) => {
1128
- const indexPath = tree.findIndexPath(
1322
+ const indexPath = tree.findPath(
1129
1323
  rootMediaItem,
1130
1324
  (item) => item.id === selectedIds[0]
1131
1325
  );
@@ -1212,7 +1406,7 @@ var moveMediaInsideFolder = ({
1212
1406
  };
1213
1407
  var getParentDirectories = (mediaMap, folderId) => {
1214
1408
  const tree = createMediaItemTree(mediaMap);
1215
- const indexPath = tree.findIndexPath(
1409
+ const indexPath = tree.findPath(
1216
1410
  rootMediaItem,
1217
1411
  (item) => item.id === folderId
1218
1412
  );
@@ -1244,19 +1438,67 @@ var renameMediaItemAndDescendantPaths = ({
1244
1438
  };
1245
1439
 
1246
1440
  // src/MediaCollection.tsx
1441
+ var extensionToContentType = {
1442
+ svg: "image/svg+xml",
1443
+ png: "image/png",
1444
+ jpeg: "image/jpeg"
1445
+ };
1446
+ function encodeFileContentForThumbnail(pathProp, item) {
1447
+ const extension = import_imfs3.path.extname(pathProp).slice(1);
1448
+ const contentType = extensionToContentType[extension];
1449
+ if (contentType) {
1450
+ if (item.encoding === "base64") {
1451
+ return {
1452
+ contentType,
1453
+ url: `data:${contentType};base64,${item.content}`
1454
+ };
1455
+ } else {
1456
+ try {
1457
+ return {
1458
+ contentType,
1459
+ url: `data:${contentType},${encodeURIComponent(item.content)}`
1460
+ };
1461
+ } catch (error) {
1462
+ console.warn("Failed to encode content:", error);
1463
+ return { contentType };
1464
+ }
1465
+ }
1466
+ }
1467
+ return void 0;
1468
+ }
1247
1469
  var MediaThumbnailInternal = (0, import_react_utils.memoGeneric)(
1248
- ({ item, selected, size }) => {
1470
+ ({
1471
+ item,
1472
+ selected,
1473
+ size,
1474
+ path: pathProp
1475
+ }) => {
1249
1476
  const asset = (0, import_noya_multiplayer_react.useAsset)(item.kind === "asset" ? item.assetId : void 0);
1250
1477
  const isRoot = item.id === rootMediaItem.id;
1251
1478
  const isFolder = item.kind === "folder";
1479
+ const isFile = item.kind === "file";
1480
+ let contentType;
1481
+ let url;
1482
+ if (asset) {
1483
+ contentType = asset.contentType;
1484
+ url = asset.url;
1485
+ } else if (isFile && pathProp) {
1486
+ const encoded = encodeFileContentForThumbnail(pathProp, item);
1487
+ if (encoded) {
1488
+ contentType = encoded.contentType;
1489
+ url = encoded.url;
1490
+ }
1491
+ }
1492
+ const fileName = pathProp ? import_imfs3.path.basename(pathProp) : void 0;
1252
1493
  return /* @__PURE__ */ import_react2.default.createElement(
1253
1494
  import_noya_designsystem.MediaThumbnail,
1254
1495
  {
1255
- contentType: asset?.contentType,
1496
+ contentType,
1256
1497
  iconName: isRoot ? "HomeIcon" : isFolder ? "FolderIcon" : void 0,
1257
- url: asset?.url,
1498
+ url,
1258
1499
  selected,
1259
- size
1500
+ size,
1501
+ fileName
1260
1502
  }
1261
1503
  );
1262
1504
  }
@@ -1266,7 +1508,8 @@ var MediaCollection = (0, import_react.memo)(
1266
1508
  onSelectionChange,
1267
1509
  selectedIds: selectedIdsProp,
1268
1510
  media,
1269
- setMedia,
1511
+ setMedia: setMediaProp,
1512
+ readOnly = false,
1270
1513
  viewType = "list",
1271
1514
  fileKindFilter = "all",
1272
1515
  showRootItem = false,
@@ -1286,6 +1529,12 @@ var MediaCollection = (0, import_react.memo)(
1286
1529
  sortable = false,
1287
1530
  renderEmptyState
1288
1531
  }, ref) {
1532
+ const setMedia = (0, import_react.useCallback)(
1533
+ (...args) => {
1534
+ setMediaProp?.(...args);
1535
+ },
1536
+ [setMediaProp]
1537
+ );
1289
1538
  const tree = (0, import_react.useMemo)(() => createMediaItemTree(media), [media]);
1290
1539
  const [tempItem, setTempItem] = (0, import_react.useState)(
1291
1540
  void 0
@@ -1698,7 +1947,8 @@ var MediaCollection = (0, import_react.memo)(
1698
1947
  onOpenChange,
1699
1948
  variant: viewType === "grid" ? "normal" : "bare",
1700
1949
  style: {
1701
- backgroundColor: selected ? import_noya_designsystem.cssVars.colors.primaryPastel : "transparent"
1950
+ backgroundColor: selected ? import_noya_designsystem.cssVars.colors.selectedListItemBackground : "transparent",
1951
+ color: selected ? import_noya_designsystem.cssVars.colors.selectedListItemText : void 0
1702
1952
  }
1703
1953
  }
1704
1954
  );
@@ -1725,7 +1975,7 @@ var MediaCollection = (0, import_react.memo)(
1725
1975
  import_noya_designsystem.FileExplorerLayout,
1726
1976
  {
1727
1977
  title: title ?? rootMediaItemName,
1728
- right: /* @__PURE__ */ import_react2.default.createElement(
1978
+ right: !readOnly && /* @__PURE__ */ import_react2.default.createElement(
1729
1979
  import_noya_designsystem.FileExplorerUploadButton,
1730
1980
  {
1731
1981
  showUploadButton,
@@ -1775,7 +2025,13 @@ var MediaCollection = (0, import_react.memo)(
1775
2025
  onRename,
1776
2026
  renamable,
1777
2027
  selectedIds,
1778
- renderThumbnail: (props) => /* @__PURE__ */ import_react2.default.createElement(MediaThumbnailInternal, { ...props }),
2028
+ renderThumbnail: (props) => /* @__PURE__ */ import_react2.default.createElement(
2029
+ MediaThumbnailInternal,
2030
+ {
2031
+ ...props,
2032
+ path: tree.idToPathMap.get(props.item.id)
2033
+ }
2034
+ ),
1779
2035
  renderAction,
1780
2036
  renderDetail: (file, selected) => {
1781
2037
  if (file.kind !== "asset") return null;
@@ -1798,11 +2054,11 @@ var MediaCollection = (0, import_react.memo)(
1798
2054
  if (position !== "inside" || targetItem.kind === "asset") {
1799
2055
  return false;
1800
2056
  }
1801
- const sourcePath = tree.findIndexPath(
2057
+ const sourcePath = tree.findPath(
1802
2058
  rootMediaItem,
1803
2059
  (item) => item.id === sourceItem.id
1804
2060
  );
1805
- const targetPath = tree.findIndexPath(
2061
+ const targetPath = tree.findPath(
1806
2062
  rootMediaItem,
1807
2063
  (item) => item.id === targetItem.id
1808
2064
  );