horizon-design 0.0.1 → 0.0.2
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.
|
@@ -5,14 +5,8 @@
|
|
|
5
5
|
import MingcuteRightLine from '~icons/mingcute/right-line';
|
|
6
6
|
import MingcuteFileLine from '~icons/mingcute/file-line';
|
|
7
7
|
import { SvelteSet } from 'svelte/reactivity';
|
|
8
|
+
import type { AnyNode } from '.';
|
|
8
9
|
|
|
9
|
-
type AnyNode = {
|
|
10
|
-
id?: string;
|
|
11
|
-
name?: string;
|
|
12
|
-
label?: string;
|
|
13
|
-
children?: AnyNode[];
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
};
|
|
16
10
|
type DropTarget = { value: string; position: 'before' | 'inside' | 'after' } | null;
|
|
17
11
|
|
|
18
12
|
let {
|
|
@@ -61,6 +55,24 @@
|
|
|
61
55
|
let justMovedValue = $state<string | null>(null);
|
|
62
56
|
let justMovedTimer: ReturnType<typeof setTimeout> | null = null;
|
|
63
57
|
|
|
58
|
+
// Tracks the last children reference we sent via onDataChange so we can
|
|
59
|
+
// distinguish an external data update from the parent echoing our own change back.
|
|
60
|
+
let _sentDataRef: AnyNode[] = untrack(() => data);
|
|
61
|
+
|
|
62
|
+
function emitDataChange() {
|
|
63
|
+
_sentDataRef = treeData.children ?? [];
|
|
64
|
+
onDataChange?.(_sentDataRef);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
$effect(() => {
|
|
68
|
+
const snapshot = data;
|
|
69
|
+
untrack(() => {
|
|
70
|
+
if (isDragging || renamingValue !== null) return;
|
|
71
|
+
if (snapshot === _sentDataRef) return;
|
|
72
|
+
treeData = { children: structuredClone(snapshot) };
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
64
76
|
function portal(node: HTMLElement) {
|
|
65
77
|
document.body.appendChild(node);
|
|
66
78
|
return {
|
|
@@ -229,7 +241,7 @@
|
|
|
229
241
|
siblings[info.index - 1]
|
|
230
242
|
];
|
|
231
243
|
treeData = replaceChildren(treeData, getValue(info.parent), siblings);
|
|
232
|
-
|
|
244
|
+
emitDataChange();
|
|
233
245
|
flashMoved(targetValue);
|
|
234
246
|
}
|
|
235
247
|
|
|
@@ -242,7 +254,7 @@
|
|
|
242
254
|
siblings[info.index]
|
|
243
255
|
];
|
|
244
256
|
treeData = replaceChildren(treeData, getValue(info.parent), siblings);
|
|
245
|
-
|
|
257
|
+
emitDataChange();
|
|
246
258
|
flashMoved(targetValue);
|
|
247
259
|
}
|
|
248
260
|
|
|
@@ -267,7 +279,7 @@
|
|
|
267
279
|
onExpandedChange?.({ expandedValue });
|
|
268
280
|
}
|
|
269
281
|
|
|
270
|
-
|
|
282
|
+
emitDataChange();
|
|
271
283
|
flashMoved(targetValue);
|
|
272
284
|
}
|
|
273
285
|
|
|
@@ -293,7 +305,7 @@
|
|
|
293
305
|
|
|
294
306
|
treeData = replaceChildren(treeData, getValue(grandInfo.parent), newGrandChildren);
|
|
295
307
|
|
|
296
|
-
|
|
308
|
+
emitDataChange();
|
|
297
309
|
flashMoved(targetValue);
|
|
298
310
|
}
|
|
299
311
|
|
|
@@ -397,7 +409,7 @@
|
|
|
397
409
|
selectedValue = selectedValue.filter((v) => !deleted.has(v));
|
|
398
410
|
pivot = pivot && !deleted.has(pivot) ? pivot : null;
|
|
399
411
|
onSelectionChange?.({ selectedValue });
|
|
400
|
-
|
|
412
|
+
emitDataChange();
|
|
401
413
|
} else if (e.key === 'Escape') {
|
|
402
414
|
selectedValue = [];
|
|
403
415
|
pivot = null;
|
|
@@ -485,7 +497,7 @@
|
|
|
485
497
|
const nodesToInsert = findNodes(treeData, vals);
|
|
486
498
|
const newTree = removeNodes(treeData, vals);
|
|
487
499
|
treeData = { ...newTree, children: [...(newTree.children ?? []), ...nodesToInsert] };
|
|
488
|
-
|
|
500
|
+
emitDataChange();
|
|
489
501
|
}
|
|
490
502
|
isDragging = false;
|
|
491
503
|
dragValues = [];
|
|
@@ -507,7 +519,7 @@
|
|
|
507
519
|
let newTree = removeNodes(treeData, vals);
|
|
508
520
|
newTree = insertAt(newTree, target.value, nodesToInsert, target.position);
|
|
509
521
|
treeData = newTree;
|
|
510
|
-
|
|
522
|
+
emitDataChange();
|
|
511
523
|
if (target.position === 'inside' && !expandedValue.includes(target.value)) {
|
|
512
524
|
expandedValue = [...expandedValue, target.value];
|
|
513
525
|
onExpandedChange?.({ expandedValue });
|
|
@@ -570,7 +582,7 @@
|
|
|
570
582
|
if (!renamingValue) return;
|
|
571
583
|
if (renameText.trim()) {
|
|
572
584
|
treeData = renameNodeInTree(treeData, renamingValue, renameText.trim());
|
|
573
|
-
|
|
585
|
+
emitDataChange();
|
|
574
586
|
}
|
|
575
587
|
renamingValue = null;
|
|
576
588
|
renameText = '';
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
type AnyNode
|
|
3
|
-
id?: string;
|
|
4
|
-
name?: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
children?: AnyNode[];
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
};
|
|
2
|
+
import type { AnyNode } from '.';
|
|
9
3
|
type $$ComponentProps = {
|
|
10
4
|
class?: string;
|
|
11
5
|
data: AnyNode[];
|
package/package.json
CHANGED
|
@@ -1,76 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
2
|
+
"name": "horizon-design",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/horizon-engine/horizon-design"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite dev",
|
|
10
|
+
"build": "vite build && npm run prepack",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"prepare": "svelte-kit sync || echo ''",
|
|
13
|
+
"prepack": "svelte-kit sync && svelte-package && publint",
|
|
14
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
15
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
16
|
+
"lint": "prettier --check . && eslint .",
|
|
17
|
+
"format": "prettier --write ."
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"**/*.css"
|
|
26
|
+
],
|
|
27
|
+
"svelte": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"svelte": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./horizon-design.css": "./dist/horizon-design.css",
|
|
36
|
+
"./theme.svelte": {
|
|
37
|
+
"types": "./dist/theme.svelte.d.ts",
|
|
38
|
+
"svelte": "./dist/theme.svelte.js",
|
|
39
|
+
"default": "./dist/theme.svelte.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"svelte": "^5.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@eslint/compat": "^2.1.0",
|
|
47
|
+
"@eslint/js": "^10.0.1",
|
|
48
|
+
"@iconify-json/mingcute": "^1.2.7",
|
|
49
|
+
"@sveltejs/adapter-auto": "^7.0.1",
|
|
50
|
+
"@sveltejs/kit": "^2.65.0",
|
|
51
|
+
"@sveltejs/package": "^2.5.8",
|
|
52
|
+
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
53
|
+
"@tailwindcss/vite": "^4.3.1",
|
|
54
|
+
"@types/node": "^22.19.21",
|
|
55
|
+
"eslint": "^10.5.0",
|
|
56
|
+
"eslint-config-prettier": "^10.1.8",
|
|
57
|
+
"eslint-plugin-svelte": "^3.19.0",
|
|
58
|
+
"globals": "^17.6.0",
|
|
59
|
+
"prettier": "^3.8.4",
|
|
60
|
+
"prettier-plugin-svelte": "^3.5.2",
|
|
61
|
+
"prettier-plugin-tailwindcss": "^0.7.4",
|
|
62
|
+
"publint": "^0.3.21",
|
|
63
|
+
"svelte": "^5.56.3",
|
|
64
|
+
"svelte-check": "^4.6.0",
|
|
65
|
+
"tailwindcss": "^4.3.1",
|
|
66
|
+
"typescript": "^6.0.3",
|
|
67
|
+
"typescript-eslint": "^8.61.0",
|
|
68
|
+
"unplugin-icons": "^23.0.1",
|
|
69
|
+
"vite": "^8.0.16"
|
|
70
|
+
},
|
|
71
|
+
"keywords": [
|
|
72
|
+
"svelte"
|
|
73
|
+
],
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@ark-ui/svelte": "^5.22.1",
|
|
76
|
+
"clsx": "^2.1.1",
|
|
77
|
+
"esm-env": "^1.2.2",
|
|
78
|
+
"horizon-layout": "^1.0.0",
|
|
79
|
+
"tailwind-merge": "^3.6.0"
|
|
80
|
+
},
|
|
81
|
+
"license": "MIT"
|
|
82
|
+
}
|