mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-27 02:27:18 +00:00
cleaning
This commit is contained in:
1 parent
8fd47d8b18
commit
5373d0f0d4
15 files changed
+339
-408
No files matched your search
@@ -28,24 +28,11 @@ export const dragging: { paths: string[]; target: string | undefined } = $state(
|
||||
target: undefined,
|
||||
});
|
||||
|
||||
/** `\` and `/` alike. */
|
||||
function isSeparator(char: string | undefined) {
|
||||
return char === '/' || char === '\\';
|
||||
}
|
||||
|
||||
/** The folder that holds `path`. */
|
||||
export function parentOf(path: string): string {
|
||||
const index = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
|
||||
return index > 0 ? path.slice(0, index) : path;
|
||||
}
|
||||
|
||||
/** Whether `path` is `folder` or something in it. */
|
||||
export function isWithin(path: string, folder: string): boolean {
|
||||
return path === folder || (path.startsWith(folder) && isSeparator(path[folder.length]));
|
||||
}
|
||||
|
||||
/** The name of a file without its extension, or the name of a folder. */
|
||||
export function editableName(name: string, isDir: boolean): string {
|
||||
const dot = name.lastIndexOf('.');
|
||||
return isDir || dot <= 0 ? name : name.slice(0, dot);
|
||||
/** The rows of the explorer that `element` is in, as they are shown: their path and kind. */
|
||||
export function treeRows(element: Element | null | undefined): { path: string; kind: string }[] {
|
||||
const tree = element?.closest('[data-explorer]');
|
||||
return [...(tree?.querySelectorAll<HTMLElement>('[data-explorer-path]') ?? [])].map((row) => ({
|
||||
path: row.dataset.explorerPath!,
|
||||
kind: row.dataset.kind!,
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user