nuance-ui 0.1.7 → 0.1.8
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -20
- package/dist/runtime/components/box.d.vue.ts +1 -1
- package/dist/runtime/components/box.vue +10 -2
- package/dist/runtime/components/box.vue.d.ts +1 -1
- package/dist/runtime/components/button/button.vue +3 -3
- package/dist/runtime/components/checkbox/checkbox-card.d.vue.ts +1 -1
- package/dist/runtime/components/checkbox/checkbox-card.vue.d.ts +1 -1
- package/dist/runtime/components/index.d.ts +2 -0
- package/dist/runtime/components/index.js +2 -0
- package/dist/runtime/components/link/lib.d.ts +2 -2
- package/dist/runtime/components/roving-focus/_lib/context.d.ts +51 -0
- package/dist/runtime/components/roving-focus/_lib/context.js +90 -0
- package/dist/runtime/components/roving-focus/index.d.ts +1 -0
- package/dist/runtime/components/roving-focus/index.js +1 -0
- package/dist/runtime/components/roving-focus/roving-focus-item.d.vue.ts +13 -0
- package/dist/runtime/components/roving-focus/roving-focus-item.vue +32 -0
- package/dist/runtime/components/roving-focus/roving-focus-item.vue.d.ts +13 -0
- package/dist/runtime/components/roving-focus/roving-focus.d.vue.ts +21 -0
- package/dist/runtime/components/roving-focus/roving-focus.vue +23 -0
- package/dist/runtime/components/roving-focus/roving-focus.vue.d.ts +21 -0
- package/dist/runtime/components/select/select.d.vue.ts +2 -2
- package/dist/runtime/components/select/select.vue.d.ts +2 -2
- package/dist/runtime/components/tabs/tabs-tab.d.vue.ts +1 -1
- package/dist/runtime/components/tabs/tabs-tab.vue.d.ts +1 -1
- package/dist/runtime/components/tree/_ui/tree-item.d.vue.ts +0 -0
- package/dist/runtime/components/tree/_ui/tree-item.vue +171 -0
- package/dist/runtime/components/tree/_ui/tree-item.vue.d.ts +0 -0
- package/dist/runtime/components/tree/_ui/tree-root.d.vue.ts +33 -0
- package/dist/runtime/components/tree/_ui/tree-root.vue +77 -0
- package/dist/runtime/components/tree/_ui/tree-root.vue.d.ts +33 -0
- package/dist/runtime/components/tree/index.d.ts +1 -0
- package/dist/runtime/components/tree/index.js +1 -0
- package/dist/runtime/components/tree/lib/context.d.ts +24 -0
- package/dist/runtime/components/tree/lib/context.js +102 -0
- package/dist/runtime/components/tree/lib/get-default.d.ts +7 -0
- package/dist/runtime/components/tree/lib/get-default.js +10 -0
- package/dist/runtime/components/tree/model.d.ts +33 -0
- package/dist/runtime/components/tree/model.js +0 -0
- package/dist/runtime/components/tree/tree.d.vue.ts +23 -0
- package/dist/runtime/components/tree/tree.vue +36 -0
- package/dist/runtime/components/tree/tree.vue.d.ts +23 -0
- package/dist/runtime/composals/index.d.ts +0 -1
- package/dist/runtime/composals/index.js +0 -1
- package/dist/runtime/utils/get-mod.d.ts +2 -0
- package/dist/runtime/{composals/use-mod.js → utils/get-mod.js} +2 -13
- package/dist/runtime/utils/index.d.ts +2 -0
- package/dist/runtime/utils/index.js +2 -0
- package/dist/runtime/utils/tree.d.ts +88 -0
- package/dist/runtime/utils/tree.js +85 -0
- package/package.json +1 -1
- package/dist/runtime/composals/use-mod.d.ts +0 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Represents a tree node with a value and optional children. */
|
|
2
|
+
export interface TreeNode<T extends string = string> {
|
|
3
|
+
/** The value stored in this tree node */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Optional array of child nodes */
|
|
6
|
+
children?: TreeNode<T>[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Searches for a tree item by its value using depth-first search.
|
|
10
|
+
* @template T - The type of node values
|
|
11
|
+
* @param {TreeNode<T>[]} items - The array of tree nodes to search in
|
|
12
|
+
* @param {T} value - The value to search for
|
|
13
|
+
* @returns {TreeNode<T> | null} The found node or null if not found
|
|
14
|
+
* @example
|
|
15
|
+
* const tree = [{ value: 'folder', children: [{ value: 'file' }] }]
|
|
16
|
+
* findTreeItem(tree, 'file') // { value: 'file' }
|
|
17
|
+
* findTreeItem(tree, 'missing') // null
|
|
18
|
+
*/
|
|
19
|
+
export declare function findTreeItem<T extends string = string>(items: TreeNode<T>[], value: T): TreeNode<T> | null;
|
|
20
|
+
/**
|
|
21
|
+
* Flattens a tree structure into a single-level array in depth-first order.
|
|
22
|
+
* @template T - The type of node values
|
|
23
|
+
* @param {TreeNode<T>[]} tree - The tree to flatten
|
|
24
|
+
* @returns {TreeNode<T>[]} Flattened array containing all nodes
|
|
25
|
+
* @example
|
|
26
|
+
* const tree = [
|
|
27
|
+
* { value: 'root', children: [
|
|
28
|
+
* { value: 'child1' },
|
|
29
|
+
* { value: 'child2' }
|
|
30
|
+
* ]}
|
|
31
|
+
* ]
|
|
32
|
+
* flatTree(tree) // [{ value: 'root', ... }, { value: 'child1' }, { value: 'child2' }]
|
|
33
|
+
*/
|
|
34
|
+
export declare function flatTree<T extends string = string>(tree: TreeNode<T>[]): TreeNode<T>[];
|
|
35
|
+
/**
|
|
36
|
+
* Gets all descendant values of a specific node in the tree.
|
|
37
|
+
*
|
|
38
|
+
* @template T - The type of node values
|
|
39
|
+
* @param {TreeNode<T>[]} tree - The tree to search in
|
|
40
|
+
* @param {T} value - The value of the parent node
|
|
41
|
+
* @returns {T[]} Array of all descendant values (empty if node not found or has no children)
|
|
42
|
+
* @example
|
|
43
|
+
* const tree = [
|
|
44
|
+
* { value: 'folder', children: [
|
|
45
|
+
* { value: 'file1' },
|
|
46
|
+
* { value: 'subfolder', children: [{ value: 'file2' }] }
|
|
47
|
+
* ]}
|
|
48
|
+
* ]
|
|
49
|
+
* getBranchChildren(tree, 'folder') // ['file1', 'subfolder', 'file2']
|
|
50
|
+
* getBranchChildren(tree, 'file1') // []
|
|
51
|
+
*/
|
|
52
|
+
export declare function getBranchChildren<T extends string = string>(tree: TreeNode<T>[], value: T): T[];
|
|
53
|
+
/**
|
|
54
|
+
* Gets all node values between two specified values (inclusive) in tree traversal order.
|
|
55
|
+
* If start comes after end in traversal order, the range is automatically reversed.
|
|
56
|
+
* Uses a single-pass algorithm that flattens and searches simultaneously.
|
|
57
|
+
* @template T - The type of node values
|
|
58
|
+
* @param {TreeNode<T>[]} tree - The tree to search in
|
|
59
|
+
* @param {T} start - The starting value
|
|
60
|
+
* @param {T} end - The ending value
|
|
61
|
+
* @returns {T[]} Array of values between start and end (inclusive), empty if either value not found
|
|
62
|
+
* @example
|
|
63
|
+
* const tree = [
|
|
64
|
+
* { value: 'a', children: [{ value: 'b' }, { value: 'c' }] },
|
|
65
|
+
* { value: 'd' }
|
|
66
|
+
* ]
|
|
67
|
+
* getItemsBetween(tree, 'b', 'd') // ['b', 'c', 'd']
|
|
68
|
+
* getItemsBetween(tree, 'd', 'b') // ['b', 'c', 'd'] (auto-reversed)
|
|
69
|
+
* getItemsBetween(tree, 'a', 'missing') // []
|
|
70
|
+
*/
|
|
71
|
+
export declare function getTreeItemsBetween<T extends string = string>(tree: TreeNode<T>[], start: T, end: T): T[];
|
|
72
|
+
/**
|
|
73
|
+
* Removes nodes with specified values from the tree, including their subtrees.
|
|
74
|
+
* Returns a new tree without modifying the original.
|
|
75
|
+
*
|
|
76
|
+
* @template T - The type of node values
|
|
77
|
+
* @param {TreeNode<T>[]} tree - The original tree (array of root nodes)
|
|
78
|
+
* @param {T[]} valuesToRemove - Array of values to remove
|
|
79
|
+
* @returns {TreeNode<T>[]} New tree with specified nodes and their subtrees removed
|
|
80
|
+
* @example
|
|
81
|
+
* const tree = [
|
|
82
|
+
* { value: 'a', children: [{ value: 'b' }, { value: 'c' }] },
|
|
83
|
+
* { value: 'd' }
|
|
84
|
+
* ]
|
|
85
|
+
* removeTreeNodes(tree, ['b', 'd']) // [{ value: 'a', children: [{ value: 'c' }] }]
|
|
86
|
+
* removeTreeNodes(tree, ['a']) // [{ value: 'd' }]
|
|
87
|
+
*/
|
|
88
|
+
export declare function removeTreeNodes<Node extends TreeNode = TreeNode, Value extends string = string>(tree: Node[], valuesToRemove: Value[]): Node[];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function traverse(nodes) {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (const node of nodes) {
|
|
4
|
+
result.push(node);
|
|
5
|
+
if (node.children?.length)
|
|
6
|
+
result.push(...traverse(node.children));
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
export function findTreeItem(items, value) {
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
if (item.value === value)
|
|
13
|
+
return item;
|
|
14
|
+
if (item.children?.length) {
|
|
15
|
+
const found = findTreeItem(item.children, value);
|
|
16
|
+
if (found)
|
|
17
|
+
return found;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
export function flatTree(tree) {
|
|
23
|
+
return traverse(tree);
|
|
24
|
+
}
|
|
25
|
+
export function getBranchChildren(tree, value) {
|
|
26
|
+
const children = [];
|
|
27
|
+
function findAndExtract(nodes) {
|
|
28
|
+
for (const node of nodes) {
|
|
29
|
+
if (node.value === value) {
|
|
30
|
+
if (node.children?.length) {
|
|
31
|
+
const extracted = traverse(node.children);
|
|
32
|
+
children.push(...extracted.map((i) => i.value));
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (node.children?.length && findAndExtract(node.children))
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
findAndExtract(tree);
|
|
42
|
+
return children;
|
|
43
|
+
}
|
|
44
|
+
export function getTreeItemsBetween(tree, start, end) {
|
|
45
|
+
const result = [];
|
|
46
|
+
let startIdx = -1;
|
|
47
|
+
let endIdx = -1;
|
|
48
|
+
let currentIdx = 0;
|
|
49
|
+
function traverseAndFind(nodes) {
|
|
50
|
+
for (const node of nodes) {
|
|
51
|
+
if (node.value === start)
|
|
52
|
+
startIdx = currentIdx;
|
|
53
|
+
if (node.value === end)
|
|
54
|
+
endIdx = currentIdx;
|
|
55
|
+
result.push(node.value);
|
|
56
|
+
currentIdx++;
|
|
57
|
+
if (node.children?.length)
|
|
58
|
+
traverseAndFind(node.children);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
traverseAndFind(tree);
|
|
62
|
+
if (startIdx === -1 || endIdx === -1)
|
|
63
|
+
return [];
|
|
64
|
+
const [from, to] = startIdx < endIdx ? [startIdx, endIdx] : [endIdx, startIdx];
|
|
65
|
+
return result.slice(from, to + 1);
|
|
66
|
+
}
|
|
67
|
+
export function removeTreeNodes(tree, valuesToRemove) {
|
|
68
|
+
const removeSet = new Set(valuesToRemove);
|
|
69
|
+
function recurse(nodes) {
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const node of nodes) {
|
|
72
|
+
if (removeSet.has(node.value))
|
|
73
|
+
continue;
|
|
74
|
+
const newNode = { ...node };
|
|
75
|
+
if (node.children?.length) {
|
|
76
|
+
const filteredChildren = recurse(node.children);
|
|
77
|
+
if (filteredChildren.length > 0)
|
|
78
|
+
newNode.children = filteredChildren;
|
|
79
|
+
}
|
|
80
|
+
result.push(newNode);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
return recurse(tree);
|
|
85
|
+
}
|
package/package.json
CHANGED