Skip to content

Commit 5b5f869

Browse files
committed
optimize sorting
1 parent 3294a10 commit 5b5f869

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/svelte-file-tree/src/lib/components/Tree.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
generics="TFile extends FileNode = FileNode, TFolder extends FolderNode<TFile, TFolder> = FolderNode<TFile>, TTree extends FileTree<TFile, TFolder> = FileTree<TFile, TFolder>"
44
>
55
import { DEV } from "esm-env";
6-
import { tick } from "svelte";
76
import { SvelteSet } from "svelte/reactivity";
87
import { isControlOrMeta, noop, truePredicate } from "$lib/helpers.js";
98
import {
@@ -321,6 +320,7 @@
321320
destinationChildren.push(copy);
322321
}
323322
onChildrenChange({
323+
operation: "insert",
324324
target: destination,
325325
children: destinationChildren,
326326
});
@@ -394,6 +394,7 @@
394394
for (const owner of sourceOwners) {
395395
owner.children = owner.children.filter((child) => !sourceIds.has(child.id));
396396
onChildrenChange({
397+
operation: "remove",
397398
target: owner,
398399
children: owner.children,
399400
});
@@ -404,6 +405,7 @@
404405
destinationChildren.push(source.node);
405406
}
406407
onChildrenChange({
408+
operation: "insert",
407409
target: destination,
408410
children: destinationChildren,
409411
});
@@ -529,6 +531,7 @@
529531
for (const owner of removedOwners) {
530532
owner.children = owner.children.filter((child) => !selectedIds.has(child.id));
531533
onChildrenChange({
534+
operation: "remove",
532535
target: owner,
533536
children: owner.children,
534537
});

packages/svelte-file-tree/src/lib/components/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type OnChildrenChangeArgs<
2727
TFolder extends FolderNode<TFile, TFolder> = FolderNode<TFile>,
2828
TTree extends FileTree<TFile, TFolder> = FileTree<TFile, TFolder>,
2929
> = {
30+
operation: "insert" | "remove";
3031
target: TFolder | TTree;
3132
children: Array<TFile | TFolder>;
3233
};

sites/preview/src/lib/components/Tree.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
{tree}
1616
{expandedIds}
1717
onChildrenChange={(args) => {
18-
args.children.sort((a, b) => a.name.localeCompare(b.name));
18+
if (args.operation === "insert") {
19+
args.children.sort((a, b) => a.name.localeCompare(b.name));
20+
}
1921
}}
2022
onDropDestinationChange={(args) => {
2123
dropDestination = args.dropDestination;

0 commit comments

Comments
 (0)