@securancy/file-explorer 1.0.3 → 1.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.
@@ -2,7 +2,6 @@
2
2
  import FileExplorerDirectoryColumn from "./FileExplorerDirectoryColumn.svelte";
3
3
  import FileExplorerFileDetailColumn from "./FileExplorerFileDetailColumn.svelte";
4
4
  import FileExplorerDirectoryIndex from "./FileExplorerDirectoryIndex.svelte";
5
- import { joinPaths } from "../utilities";
6
5
  export let item;
7
6
  export let translations;
8
7
  export let routePrefix;
@@ -10,7 +9,14 @@ export let currentPath;
10
9
  export let canEdit;
11
10
  export let displayMode;
12
11
  export let getFilePreview;
13
- $: activeFileItem = item.children.find((fi) => currentPath.startsWith(joinPaths(fi.path, fi.name)));
12
+ $: currentPathParts = currentPath.split("/");
13
+ $: activeFileItem = item.children.find((fileItem) => {
14
+ const parts = [
15
+ ...fileItem.path.split("/").filter((part) => part !== ""),
16
+ fileItem.name
17
+ ];
18
+ return parts.every((part, index) => currentPathParts[index] === part);
19
+ });
14
20
  function canEditItem(item2, canEdit2) {
15
21
  return typeof canEdit2 === "function" ? canEdit2(item2) : canEdit2 === true;
16
22
  }
@@ -2,7 +2,7 @@
2
2
  import {} from "..";
3
3
  import { resize, ResizeDirections } from "@securancy/svelte-utilities";
4
4
  import { Icon, Popover, PopoverItem } from "@securancy/svelte-components";
5
- import { getExtension, openItem } from "../utilities/index.js";
5
+ import { getExtension, getItemHref } from "../utilities/index.js";
6
6
  import FileIcon from "./FileIcon.svelte";
7
7
  import { joinPaths } from "../utilities/index.js";
8
8
  const dispatch = createEventDispatcher();
@@ -89,12 +89,11 @@ function handleDragOver(event) {
89
89
  </div>
90
90
  {#if item.children.length > 0}
91
91
  {#each item.children as child}
92
- <button
92
+ <a
93
93
  class="file-explorer__list-item"
94
94
  class:file-explorer__list-item--active={activeFileItem === child}
95
+ href={getItemHref(child, routePrefix)}
95
96
  title={translations.itemTitle(child)}
96
- type="button"
97
- on:click={() => openItem(child, routePrefix)}
98
97
  >
99
98
  {#if child.type === 'directory'}
100
99
  <Icon class="fa-light fa-folder{activeFileItem === child ? '-open' : ''}" />
@@ -105,7 +104,7 @@ function handleDragOver(event) {
105
104
  {#if child.type === 'directory'}
106
105
  <Icon class="fa-light fa-sm fa-chevron-right" size="custom" />
107
106
  {/if}
108
- </button>
107
+ </a>
109
108
  {/each}
110
109
  {:else}
111
110
  <p class="file-explorer__message">
@@ -2,7 +2,7 @@
2
2
  import { createEventDispatcher } from "svelte";
3
3
  import { resize, ResizeDirections } from "@securancy/svelte-utilities";
4
4
  import { Icon, Popover, PopoverItem } from "@securancy/svelte-components";
5
- import { getExtension, joinPaths, openItem } from "../utilities/index.js";
5
+ import { getExtension, getItemHref, joinPaths } from "../utilities/index.js";
6
6
  const dispatch = createEventDispatcher();
7
7
  export let item;
8
8
  export let routePrefix;
@@ -48,12 +48,11 @@ function createDirectory() {
48
48
  {/if}
49
49
  </div>
50
50
  {#each item.children as child}
51
- <button
51
+ <a
52
52
  class="file-explorer__grid-item"
53
53
  class:file-explorer__grid-item--active={activeFileItem === child}
54
+ href={getItemHref(child, routePrefix)}
54
55
  title={translations.itemTitle(child)}
55
- type="button"
56
- on:click={() => openItem(child, routePrefix)}
57
56
  >
58
57
  {#if child.type === 'directory'}
59
58
  <Icon
@@ -64,7 +63,7 @@ function createDirectory() {
64
63
  <FileIcon extension={getExtension(child.name)} size="grid" />
65
64
  {/if}
66
65
  <span>{child.name}</span>
67
- </button>
66
+ </a>
68
67
  {:else}
69
68
  <p class="file-explorer__message">
70
69
  {translations.emptyDirectory}
@@ -1,5 +1,5 @@
1
1
  import type { FileSystemItem } from '../models/file-item.js';
2
- export declare function openItem(item: FileSystemItem, routePrefix: string): Promise<void>;
2
+ export declare function getItemHref(item: FileSystemItem, routePrefix: string): string;
3
3
  export declare function getExtension(path: string): string;
4
4
  export declare const imageExtensions: string[];
5
5
  export declare const videoExtensions: string[];
@@ -1,5 +1,4 @@
1
- import { goto } from '$app/navigation';
2
- export async function openItem(item, routePrefix) {
1
+ export function getItemHref(item, routePrefix) {
3
2
  const itemPath = [
4
3
  ...routePrefix.split('/'),
5
4
  ...item.path.split('/'),
@@ -8,7 +7,7 @@ export async function openItem(item, routePrefix) {
8
7
  .filter((node) => node !== '')
9
8
  .map(encodeURIComponent)
10
9
  .join('/');
11
- await goto(itemPath.startsWith('/') ? itemPath : `/${itemPath}`);
10
+ return itemPath.startsWith('/') ? itemPath : `/${itemPath}`;
12
11
  }
13
12
  export function getExtension(path) {
14
13
  // extract file name from full path (supports `\\` and `/` separators)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@securancy/file-explorer",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "svelte": "./dist/index.js",
@@ -52,8 +52,7 @@
52
52
  "@securancy/svelte-utilities": "2.0.1"
53
53
  },
54
54
  "peerDependencies": {
55
- "svelte": "^4.2.18",
56
- "@sveltejs/kit": "^2.5.18"
55
+ "svelte": "^4.2.18"
57
56
  },
58
57
  "scripts": {
59
58
  "dev": "vite dev",