@keenmate/svelte-treeview 4.0.0 → 4.0.1
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/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A high-performance, feature-rich hierarchical tree view component for Svelte 5 with drag & drop support, search functionality, and flexible data structures using LTree.
|
|
4
4
|
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> **Looking for a framework-agnostic solution?** There's also a web component version that can be used standalone or in other frameworks at https://github.com/KeenMate/web-treeview/
|
|
7
|
+
|
|
5
8
|
## 🚀 Features
|
|
6
9
|
|
|
7
10
|
- **Svelte 5 Native**: Built specifically for Svelte 5 with full support for runes and modern Svelte patterns
|
|
@@ -709,4 +712,4 @@ MIT License - see LICENSE file for details.
|
|
|
709
712
|
|
|
710
713
|
---
|
|
711
714
|
|
|
712
|
-
Built with ❤️ by [KeenMate](https://github.com/keenmate)
|
|
715
|
+
Built with ❤️ by [KeenMate](https://github.com/keenmate)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function getParentPath(path: string): string | null;
|
|
2
|
-
export declare function getRelativePath(path: string, parentPath: string): string;
|
|
3
|
-
export declare function getPathSegments(path: string, start?: number, count?: number): string;
|
|
1
|
+
export declare function getParentPath(path: string, pathSeparator?: string): string | null;
|
|
2
|
+
export declare function getRelativePath(path: string, parentPath: string, pathSeparator?: string): string;
|
|
3
|
+
export declare function getPathSegments(path: string, start?: number, count?: number, pathSeparator?: string): string;
|
|
4
4
|
export declare function getLevel(path: string, pathSeparator: string): number;
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { isEmptyString } from './string-helpers.js';
|
|
2
|
-
export function getParentPath(path) {
|
|
2
|
+
export function getParentPath(path, pathSeparator = '.') {
|
|
3
3
|
if (!path || typeof path !== 'string')
|
|
4
4
|
return null;
|
|
5
|
-
const lastDotIndex = path.lastIndexOf(
|
|
5
|
+
const lastDotIndex = path.lastIndexOf(pathSeparator);
|
|
6
6
|
return lastDotIndex === -1 ? '' : path.substring(0, lastDotIndex);
|
|
7
7
|
}
|
|
8
|
-
export function getRelativePath(path, parentPath) {
|
|
8
|
+
export function getRelativePath(path, parentPath, pathSeparator = '.') {
|
|
9
9
|
if (isEmptyString(parentPath))
|
|
10
10
|
return path;
|
|
11
|
-
return path.startsWith(parentPath +
|
|
11
|
+
return path.startsWith(parentPath + pathSeparator) ? path.substring(parentPath.length + pathSeparator.length) : path;
|
|
12
12
|
}
|
|
13
|
-
export function getPathSegments(path, start = 0, count = 1) {
|
|
14
|
-
const segments = path.split(
|
|
13
|
+
export function getPathSegments(path, start = 0, count = 1, pathSeparator = '.') {
|
|
14
|
+
const segments = path.split(pathSeparator);
|
|
15
15
|
const taken = segments.slice(start, start + count);
|
|
16
|
-
return taken.join(
|
|
16
|
+
return taken.join(pathSeparator);
|
|
17
17
|
}
|
|
18
18
|
export function getLevel(path, pathSeparator) {
|
|
19
|
-
|
|
20
|
-
for (let i = 0; i < path.length; i++) {
|
|
21
|
-
if (path[i] === pathSeparator)
|
|
22
|
-
count++;
|
|
23
|
-
}
|
|
24
|
-
return count;
|
|
19
|
+
return path.split(pathSeparator).length;
|
|
25
20
|
}
|
|
@@ -95,11 +95,11 @@ export function createLTree(_idMember, _pathMember, _parentPathMember, _levelMem
|
|
|
95
95
|
node.id = _idMember ? row[_idMember] : undefined;
|
|
96
96
|
node.path = _pathMember ? row[_pathMember] : undefined;
|
|
97
97
|
if (shouldCalculateParentPath) {
|
|
98
|
-
node.parentPath = getParentPath(node.path);
|
|
98
|
+
node.parentPath = getParentPath(node.path, this.treePathSeparator);
|
|
99
99
|
}
|
|
100
100
|
else
|
|
101
101
|
node.parentPath = row[_parentPathMember];
|
|
102
|
-
node.pathSegment = getPathSegments(getRelativePath(node.path, node.parentPath));
|
|
102
|
+
node.pathSegment = getPathSegments(getRelativePath(node.path, node.parentPath, this.treePathSeparator), 0, 1, this.treePathSeparator);
|
|
103
103
|
if (!shouldCalculateLevel)
|
|
104
104
|
node.level = row[_levelMember];
|
|
105
105
|
else
|
|
@@ -199,7 +199,7 @@ export function createLTree(_idMember, _pathMember, _parentPathMember, _levelMem
|
|
|
199
199
|
if (shouldCalculateLevel) {
|
|
200
200
|
newNode.level = (parentNode.level || 0) + 1;
|
|
201
201
|
}
|
|
202
|
-
const newSegment = segmentPrefix + getPathSegments(getRelativePath(newNode?.path, parentPath));
|
|
202
|
+
const newSegment = segmentPrefix + getPathSegments(getRelativePath(newNode?.path, parentPath, this.treePathSeparator), 0, 1, this.treePathSeparator);
|
|
203
203
|
if (!parentNode.children.hasOwnProperty(newSegment)) {
|
|
204
204
|
parentNode.children[newSegment] = newNode;
|
|
205
205
|
if (shouldCalculateHasChildren && !parentNode.hasChildren) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keenmate/svelte-treeview",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev --port 17777",
|
|
6
6
|
"build": "vite build && npm run prepack",
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"prepack": "svelte-kit sync && svelte-package && sass src/lib/styles.scss dist/styles.css && publint",
|
|
11
11
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
12
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"test:run": "vitest run",
|
|
13
15
|
"format": "prettier --write .",
|
|
14
16
|
"lint": "prettier --check . && eslint ."
|
|
15
17
|
},
|
|
@@ -59,7 +61,8 @@
|
|
|
59
61
|
"svelte-preprocess": "^6.0.3",
|
|
60
62
|
"typescript": "^5.0.0",
|
|
61
63
|
"typescript-eslint": "^8.20.0",
|
|
62
|
-
"vite": "^7.0.4"
|
|
64
|
+
"vite": "^7.0.4",
|
|
65
|
+
"vitest": "^3.2.4"
|
|
63
66
|
},
|
|
64
67
|
"optionalDependencies": {
|
|
65
68
|
"flexsearch": "^0.8.212"
|