@noya-app/noya-file-explorer 0.0.2 → 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/.turbo/turbo-build.log +13 -13
- package/CHANGELOG.md +21 -0
- package/dist/index.css +628 -568
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +25738 -13840
- package/dist/index.d.ts +25738 -13840
- package/dist/index.js +424 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +423 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/MediaCollection.tsx +128 -44
- package/src/__tests__/renameMediaItemAndDescendantPaths.test.ts +139 -0
- package/src/utils/files.ts +47 -2
- package/tsup.config.ts +1 -3
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.
|
|
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
|
-
|
|
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.
|
|
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 =
|
|
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 =
|
|
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.
|
|
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 =
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
687
|
-
return options.create(node2,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
845
|
+
exports2.insert = insert;
|
|
846
|
+
exports2.insertWithPathTracking = insertWithPathTracking;
|
|
716
847
|
var operation_1 = require_operation();
|
|
717
848
|
function insert(node, options) {
|
|
718
|
-
|
|
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
|
-
|
|
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 =
|
|
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.
|
|
879
|
+
if (options.paths.length === 0)
|
|
740
880
|
return node;
|
|
741
|
-
for (const indexPath of options.
|
|
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.
|
|
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 =
|
|
902
|
+
exports2.remove = remove;
|
|
903
|
+
exports2.removeWithPathTracking = removeWithPathTracking;
|
|
764
904
|
var operation_1 = require_operation();
|
|
765
905
|
function remove(node, options) {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
const operations = (0, operation_1.getRemovalOperations)(
|
|
774
|
-
|
|
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 =
|
|
928
|
+
exports2.replace = replace;
|
|
786
929
|
var operation_1 = require_operation();
|
|
787
930
|
function replace(node, options) {
|
|
788
|
-
if (options.
|
|
931
|
+
if (options.path.length === 0)
|
|
789
932
|
return options.node;
|
|
790
|
-
const operations = (0, operation_1.getReplaceOperations)(options.
|
|
933
|
+
const operations = (0, operation_1.getReplaceOperations)(options.path, options.node);
|
|
791
934
|
return (0, operation_1.applyOperations)(node, operations, options);
|
|
792
935
|
}
|
|
793
|
-
|
|
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 =
|
|
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.
|
|
829
|
-
this.
|
|
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.
|
|
884
|
-
|
|
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
|
}
|
|
@@ -930,6 +1124,7 @@ __export(src_exports, {
|
|
|
930
1124
|
moveMediaInsideFolder: () => moveMediaInsideFolder,
|
|
931
1125
|
movePathsIntoTarget: () => movePathsIntoTarget,
|
|
932
1126
|
moveUpAFolder: () => moveUpAFolder,
|
|
1127
|
+
renameMediaItemAndDescendantPaths: () => renameMediaItemAndDescendantPaths,
|
|
933
1128
|
rootMediaItem: () => rootMediaItem,
|
|
934
1129
|
rootMediaItemName: () => rootMediaItemName,
|
|
935
1130
|
rootMediaItemPath: () => rootMediaItemPath,
|
|
@@ -1124,7 +1319,7 @@ var moveUpAFolder = ({
|
|
|
1124
1319
|
media,
|
|
1125
1320
|
selectedIds
|
|
1126
1321
|
}) => {
|
|
1127
|
-
const indexPath = tree.
|
|
1322
|
+
const indexPath = tree.findPath(
|
|
1128
1323
|
rootMediaItem,
|
|
1129
1324
|
(item) => item.id === selectedIds[0]
|
|
1130
1325
|
);
|
|
@@ -1211,27 +1406,99 @@ var moveMediaInsideFolder = ({
|
|
|
1211
1406
|
};
|
|
1212
1407
|
var getParentDirectories = (mediaMap, folderId) => {
|
|
1213
1408
|
const tree = createMediaItemTree(mediaMap);
|
|
1214
|
-
const indexPath = tree.
|
|
1409
|
+
const indexPath = tree.findPath(
|
|
1215
1410
|
rootMediaItem,
|
|
1216
1411
|
(item) => item.id === folderId
|
|
1217
1412
|
);
|
|
1218
1413
|
if (!indexPath) return [rootMediaItem];
|
|
1219
1414
|
return tree.accessPath(rootMediaItem, indexPath);
|
|
1220
1415
|
};
|
|
1416
|
+
var renameMediaItemAndDescendantPaths = ({
|
|
1417
|
+
newName,
|
|
1418
|
+
selectedItemPath,
|
|
1419
|
+
media,
|
|
1420
|
+
tree
|
|
1421
|
+
}) => {
|
|
1422
|
+
const mediaClone = { ...media };
|
|
1423
|
+
const selectedItem = mediaClone[selectedItemPath];
|
|
1424
|
+
if (!selectedItem) return mediaClone;
|
|
1425
|
+
const parentPath = import_imfs2.path.dirname(selectedItemPath);
|
|
1426
|
+
const newItemPath = import_imfs2.path.join(parentPath, newName);
|
|
1427
|
+
const descendants = tree.flat(selectedItem).map((item) => tree.idToPathMap.get(item.id));
|
|
1428
|
+
for (const descendantPath of descendants) {
|
|
1429
|
+
if (!descendantPath) continue;
|
|
1430
|
+
const newDescendantPath = descendantPath.replace(
|
|
1431
|
+
selectedItemPath,
|
|
1432
|
+
newItemPath
|
|
1433
|
+
);
|
|
1434
|
+
mediaClone[newDescendantPath] = mediaClone[descendantPath];
|
|
1435
|
+
delete mediaClone[descendantPath];
|
|
1436
|
+
}
|
|
1437
|
+
return mediaClone;
|
|
1438
|
+
};
|
|
1221
1439
|
|
|
1222
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
|
+
}
|
|
1223
1469
|
var MediaThumbnailInternal = (0, import_react_utils.memoGeneric)(
|
|
1224
|
-
({
|
|
1470
|
+
({
|
|
1471
|
+
item,
|
|
1472
|
+
selected,
|
|
1473
|
+
size,
|
|
1474
|
+
path: pathProp
|
|
1475
|
+
}) => {
|
|
1225
1476
|
const asset = (0, import_noya_multiplayer_react.useAsset)(item.kind === "asset" ? item.assetId : void 0);
|
|
1226
1477
|
const isRoot = item.id === rootMediaItem.id;
|
|
1227
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;
|
|
1228
1493
|
return /* @__PURE__ */ import_react2.default.createElement(
|
|
1229
1494
|
import_noya_designsystem.MediaThumbnail,
|
|
1230
1495
|
{
|
|
1231
|
-
contentType
|
|
1496
|
+
contentType,
|
|
1232
1497
|
iconName: isRoot ? "HomeIcon" : isFolder ? "FolderIcon" : void 0,
|
|
1233
|
-
url
|
|
1234
|
-
selected
|
|
1498
|
+
url,
|
|
1499
|
+
selected,
|
|
1500
|
+
size,
|
|
1501
|
+
fileName
|
|
1235
1502
|
}
|
|
1236
1503
|
);
|
|
1237
1504
|
}
|
|
@@ -1241,7 +1508,8 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1241
1508
|
onSelectionChange,
|
|
1242
1509
|
selectedIds: selectedIdsProp,
|
|
1243
1510
|
media,
|
|
1244
|
-
setMedia,
|
|
1511
|
+
setMedia: setMediaProp,
|
|
1512
|
+
readOnly = false,
|
|
1245
1513
|
viewType = "list",
|
|
1246
1514
|
fileKindFilter = "all",
|
|
1247
1515
|
showRootItem = false,
|
|
@@ -1261,17 +1529,34 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1261
1529
|
sortable = false,
|
|
1262
1530
|
renderEmptyState
|
|
1263
1531
|
}, ref) {
|
|
1532
|
+
const setMedia = (0, import_react.useCallback)(
|
|
1533
|
+
(...args) => {
|
|
1534
|
+
setMediaProp?.(...args);
|
|
1535
|
+
},
|
|
1536
|
+
[setMediaProp]
|
|
1537
|
+
);
|
|
1264
1538
|
const tree = (0, import_react.useMemo)(() => createMediaItemTree(media), [media]);
|
|
1265
1539
|
const [tempItem, setTempItem] = (0, import_react.useState)(
|
|
1266
1540
|
void 0
|
|
1267
1541
|
);
|
|
1268
|
-
const
|
|
1269
|
-
() =>
|
|
1542
|
+
const mediaWithTempItem = (0, import_react.useMemo)(
|
|
1543
|
+
() => ({
|
|
1270
1544
|
...media,
|
|
1271
1545
|
...tempItem ? { [tempItem[0]]: tempItem[1] } : {}
|
|
1272
1546
|
}),
|
|
1273
1547
|
[media, tempItem]
|
|
1274
1548
|
);
|
|
1549
|
+
const treeWithTempItem = (0, import_react.useMemo)(
|
|
1550
|
+
() => createMediaItemTree(mediaWithTempItem),
|
|
1551
|
+
[mediaWithTempItem]
|
|
1552
|
+
);
|
|
1553
|
+
const temp = (0, import_react.useMemo)(
|
|
1554
|
+
() => ({
|
|
1555
|
+
media: mediaWithTempItem,
|
|
1556
|
+
tree: treeWithTempItem
|
|
1557
|
+
}),
|
|
1558
|
+
[mediaWithTempItem, treeWithTempItem]
|
|
1559
|
+
);
|
|
1275
1560
|
const [selectedIds, setSelectedIds] = (0, import_react_utils.useControlledOrUncontrolled)(
|
|
1276
1561
|
{
|
|
1277
1562
|
defaultValue: [],
|
|
@@ -1326,12 +1611,6 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1326
1611
|
if (!itemPath || !firstSelectedPath) return false;
|
|
1327
1612
|
return itemPath.startsWith(import_imfs3.path.dirname(firstSelectedPath));
|
|
1328
1613
|
});
|
|
1329
|
-
const gridSize = (0, import_react.useMemo)(() => {
|
|
1330
|
-
if (viewType === "grid") {
|
|
1331
|
-
return size;
|
|
1332
|
-
}
|
|
1333
|
-
return "medium";
|
|
1334
|
-
}, [viewType, size]);
|
|
1335
1614
|
(0, import_react.useEffect)(() => {
|
|
1336
1615
|
if (initialExpanded) {
|
|
1337
1616
|
setExpandedMap(initialExpanded);
|
|
@@ -1365,31 +1644,28 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1365
1644
|
selectedItem.id
|
|
1366
1645
|
);
|
|
1367
1646
|
if (!selectedItemPath) return;
|
|
1368
|
-
const mediaWithTempItem = {
|
|
1369
|
-
...media,
|
|
1370
|
-
...tempItem ? { [tempItem[0]]: tempItem[1] } : {}
|
|
1371
|
-
};
|
|
1372
1647
|
const renameIsValid = validateMediaItemRename({
|
|
1373
1648
|
basename: newName,
|
|
1374
1649
|
selectedItemPath,
|
|
1375
|
-
media:
|
|
1650
|
+
media: temp.media
|
|
1376
1651
|
});
|
|
1377
1652
|
if (!renameIsValid) {
|
|
1378
1653
|
setTempItem(void 0);
|
|
1379
1654
|
return;
|
|
1380
1655
|
}
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1656
|
+
const mediaWithRenamedDescendantPaths = renameMediaItemAndDescendantPaths({
|
|
1657
|
+
newName,
|
|
1658
|
+
selectedItemPath,
|
|
1659
|
+
media: temp.media,
|
|
1660
|
+
tree: temp.tree
|
|
1661
|
+
});
|
|
1383
1662
|
setMedia(
|
|
1384
1663
|
{ name: "Rename media item", timestamp: Date.now() },
|
|
1385
|
-
|
|
1386
|
-
...mediaClone,
|
|
1387
|
-
[import_imfs3.path.join(import_imfs3.path.dirname(selectedItemPath), newName)]: selectedItem
|
|
1388
|
-
}
|
|
1664
|
+
mediaWithRenamedDescendantPaths
|
|
1389
1665
|
);
|
|
1390
1666
|
setTempItem(void 0);
|
|
1391
1667
|
},
|
|
1392
|
-
[
|
|
1668
|
+
[renamable, setMedia, temp.media, temp.tree, treeWithTempItem.idToPathMap]
|
|
1393
1669
|
);
|
|
1394
1670
|
const handleAddFolder = (0, import_react.useCallback)(
|
|
1395
1671
|
(currentFolderId) => {
|
|
@@ -1669,8 +1945,10 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1669
1945
|
onSelect: (action) => handleMenuAction(action, selectedMediaItems),
|
|
1670
1946
|
selected,
|
|
1671
1947
|
onOpenChange,
|
|
1948
|
+
variant: viewType === "grid" ? "normal" : "bare",
|
|
1672
1949
|
style: {
|
|
1673
|
-
backgroundColor: selected ? import_noya_designsystem.cssVars.colors.
|
|
1950
|
+
backgroundColor: selected ? import_noya_designsystem.cssVars.colors.selectedListItemBackground : "transparent",
|
|
1951
|
+
color: selected ? import_noya_designsystem.cssVars.colors.selectedListItemText : void 0
|
|
1674
1952
|
}
|
|
1675
1953
|
}
|
|
1676
1954
|
);
|
|
@@ -1678,7 +1956,8 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1678
1956
|
assetContextMenuItems,
|
|
1679
1957
|
handleMenuAction,
|
|
1680
1958
|
renderActionProp,
|
|
1681
|
-
selectedMediaItems
|
|
1959
|
+
selectedMediaItems,
|
|
1960
|
+
viewType
|
|
1682
1961
|
]);
|
|
1683
1962
|
(0, import_react.useImperativeHandle)(ref, () => ({
|
|
1684
1963
|
upload: (selectedId) => handleUpload(selectedId),
|
|
@@ -1696,7 +1975,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1696
1975
|
import_noya_designsystem.FileExplorerLayout,
|
|
1697
1976
|
{
|
|
1698
1977
|
title: title ?? rootMediaItemName,
|
|
1699
|
-
right: /* @__PURE__ */ import_react2.default.createElement(
|
|
1978
|
+
right: !readOnly && /* @__PURE__ */ import_react2.default.createElement(
|
|
1700
1979
|
import_noya_designsystem.FileExplorerUploadButton,
|
|
1701
1980
|
{
|
|
1702
1981
|
showUploadButton,
|
|
@@ -1713,7 +1992,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1713
1992
|
scrollable,
|
|
1714
1993
|
items: visibleItems,
|
|
1715
1994
|
viewType,
|
|
1716
|
-
size
|
|
1995
|
+
size,
|
|
1717
1996
|
getId: (file) => file.id,
|
|
1718
1997
|
getName: (file) => {
|
|
1719
1998
|
if (file.id === tempItem?.[1].id) {
|
|
@@ -1746,13 +2025,19 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1746
2025
|
onRename,
|
|
1747
2026
|
renamable,
|
|
1748
2027
|
selectedIds,
|
|
1749
|
-
renderThumbnail: (props) => /* @__PURE__ */ import_react2.default.createElement(
|
|
2028
|
+
renderThumbnail: (props) => /* @__PURE__ */ import_react2.default.createElement(
|
|
2029
|
+
MediaThumbnailInternal,
|
|
2030
|
+
{
|
|
2031
|
+
...props,
|
|
2032
|
+
path: tree.idToPathMap.get(props.item.id)
|
|
2033
|
+
}
|
|
2034
|
+
),
|
|
1750
2035
|
renderAction,
|
|
1751
2036
|
renderDetail: (file, selected) => {
|
|
1752
2037
|
if (file.kind !== "asset") return null;
|
|
1753
2038
|
const asset = assets.find((a) => a.id === file.assetId);
|
|
1754
2039
|
if (!asset) return null;
|
|
1755
|
-
return /* @__PURE__ */ import_react2.default.createElement(import_noya_designsystem.FileExplorerDetail, { selected }, (asset.size / 1024).toFixed(1), "KB");
|
|
2040
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_noya_designsystem.FileExplorerDetail, { selected, size }, (asset.size / 1024).toFixed(1), "KB");
|
|
1756
2041
|
},
|
|
1757
2042
|
renderEmptyState: () => renderEmptyState?.() ?? /* @__PURE__ */ import_react2.default.createElement(import_noya_designsystem.FileExplorerEmptyState, null),
|
|
1758
2043
|
itemRoleDescription: "clickable file item",
|
|
@@ -1769,11 +2054,11 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1769
2054
|
if (position !== "inside" || targetItem.kind === "asset") {
|
|
1770
2055
|
return false;
|
|
1771
2056
|
}
|
|
1772
|
-
const sourcePath = tree.
|
|
2057
|
+
const sourcePath = tree.findPath(
|
|
1773
2058
|
rootMediaItem,
|
|
1774
2059
|
(item) => item.id === sourceItem.id
|
|
1775
2060
|
);
|
|
1776
|
-
const targetPath = tree.
|
|
2061
|
+
const targetPath = tree.findPath(
|
|
1777
2062
|
rootMediaItem,
|
|
1778
2063
|
(item) => item.id === targetItem.id
|
|
1779
2064
|
);
|
|
@@ -1845,6 +2130,7 @@ var MediaCollection = (0, import_react.memo)(
|
|
|
1845
2130
|
moveMediaInsideFolder,
|
|
1846
2131
|
movePathsIntoTarget,
|
|
1847
2132
|
moveUpAFolder,
|
|
2133
|
+
renameMediaItemAndDescendantPaths,
|
|
1848
2134
|
rootMediaItem,
|
|
1849
2135
|
rootMediaItemName,
|
|
1850
2136
|
rootMediaItemPath,
|