@rokkit/actions 1.0.0-next.35 → 1.0.0-next.36
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/package.json +8 -7
- package/src/hierarchy.js +1 -1
- package/src/navigator.js +37 -9
- package/src/themeable.js +9 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/actions",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.36",
|
|
4
4
|
"description": "Contains generic actions that can be used in various components.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@sveltejs/vite-plugin-svelte": "^2.4.2",
|
|
17
17
|
"@testing-library/svelte": "^4.0.3",
|
|
18
|
-
"@vitest/coverage-v8": "^0.
|
|
19
|
-
"@vitest/ui": "~0.
|
|
18
|
+
"@vitest/coverage-v8": "^0.33.0",
|
|
19
|
+
"@vitest/ui": "~0.33.0",
|
|
20
20
|
"jsdom": "^22.1.0",
|
|
21
|
-
"svelte": "^4.0.
|
|
21
|
+
"svelte": "^4.0.5",
|
|
22
22
|
"typescript": "^5.1.6",
|
|
23
23
|
"validators": "latest",
|
|
24
|
-
"vite": "^4.
|
|
25
|
-
"vitest": "~0.
|
|
26
|
-
"shared-config": "1.0.0-next.
|
|
24
|
+
"vite": "^4.4.4",
|
|
25
|
+
"vitest": "~0.33.0",
|
|
26
|
+
"shared-config": "1.0.0-next.36"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"src/**/*.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@rokkit/core": "latest",
|
|
43
44
|
"@rokkit/stores": "latest"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
package/src/hierarchy.js
CHANGED
|
@@ -60,7 +60,7 @@ export function isNested(items, fields) {
|
|
|
60
60
|
*/
|
|
61
61
|
export function navigateToLastVisibleChild(path) {
|
|
62
62
|
let current = path[path.length - 1]
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
while (isExpanded(current.items[current.index], current.fields)) {
|
|
65
65
|
const items = current.items[current.index][current.fields.children]
|
|
66
66
|
const level = {
|
package/src/navigator.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getId } from '@rokkit/core'
|
|
1
2
|
import {
|
|
2
3
|
moveNext,
|
|
3
4
|
movePrevious,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
indicesFromPath,
|
|
8
9
|
getCurrentNode
|
|
9
10
|
} from './hierarchy'
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* @typedef NavigatorOptions
|
|
12
14
|
* @property {Array<*>} items - An array containing the data set to navigate
|
|
@@ -40,7 +42,8 @@ export function navigator(node, options) {
|
|
|
40
42
|
path = moveNext(path, items, fields)
|
|
41
43
|
currentNode = getCurrentNode(path)
|
|
42
44
|
|
|
43
|
-
if (previousNode !== currentNode)
|
|
45
|
+
if (previousNode !== currentNode)
|
|
46
|
+
moveTo(node, path, currentNode, idPrefix, fields)
|
|
44
47
|
}
|
|
45
48
|
const previous = () => {
|
|
46
49
|
const previousNode = currentNode
|
|
@@ -48,14 +51,18 @@ export function navigator(node, options) {
|
|
|
48
51
|
if (path.length > 0) {
|
|
49
52
|
currentNode = getCurrentNode(path)
|
|
50
53
|
if (previousNode !== currentNode)
|
|
51
|
-
moveTo(node, path, currentNode, idPrefix)
|
|
54
|
+
moveTo(node, path, currentNode, idPrefix, fields)
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
const select = () => {
|
|
55
58
|
if (currentNode)
|
|
56
59
|
node.dispatchEvent(
|
|
57
60
|
new CustomEvent('select', {
|
|
58
|
-
detail: {
|
|
61
|
+
detail: {
|
|
62
|
+
path: indicesFromPath(path),
|
|
63
|
+
node: currentNode,
|
|
64
|
+
id: getId(currentNode, fields)
|
|
65
|
+
}
|
|
59
66
|
})
|
|
60
67
|
)
|
|
61
68
|
}
|
|
@@ -68,7 +75,11 @@ export function navigator(node, options) {
|
|
|
68
75
|
currentNode[path[path.length - 1].fields.isOpen] = false
|
|
69
76
|
node.dispatchEvent(
|
|
70
77
|
new CustomEvent('collapse', {
|
|
71
|
-
detail: {
|
|
78
|
+
detail: {
|
|
79
|
+
path: indicesFromPath(path),
|
|
80
|
+
node: currentNode,
|
|
81
|
+
id: getId(currentNode, fields)
|
|
82
|
+
}
|
|
72
83
|
})
|
|
73
84
|
)
|
|
74
85
|
} else if (path.length > 0) {
|
|
@@ -83,7 +94,11 @@ export function navigator(node, options) {
|
|
|
83
94
|
currentNode[path[path.length - 1].fields.isOpen] = true
|
|
84
95
|
node.dispatchEvent(
|
|
85
96
|
new CustomEvent('expand', {
|
|
86
|
-
detail: {
|
|
97
|
+
detail: {
|
|
98
|
+
path: indicesFromPath(path),
|
|
99
|
+
node: currentNode,
|
|
100
|
+
id: getId(currentNode, fields)
|
|
101
|
+
}
|
|
87
102
|
})
|
|
88
103
|
)
|
|
89
104
|
}
|
|
@@ -130,13 +145,21 @@ export function navigator(node, options) {
|
|
|
130
145
|
: 'collapse'
|
|
131
146
|
node.dispatchEvent(
|
|
132
147
|
new CustomEvent(event, {
|
|
133
|
-
detail: {
|
|
148
|
+
detail: {
|
|
149
|
+
path: indices,
|
|
150
|
+
node: currentNode,
|
|
151
|
+
id: getId(currentNode, fields)
|
|
152
|
+
}
|
|
134
153
|
})
|
|
135
154
|
)
|
|
136
155
|
}
|
|
137
156
|
node.dispatchEvent(
|
|
138
157
|
new CustomEvent('select', {
|
|
139
|
-
detail: {
|
|
158
|
+
detail: {
|
|
159
|
+
path: indices,
|
|
160
|
+
node: currentNode,
|
|
161
|
+
id: getId(currentNode, fields)
|
|
162
|
+
}
|
|
140
163
|
})
|
|
141
164
|
)
|
|
142
165
|
}
|
|
@@ -154,15 +177,20 @@ export function navigator(node, options) {
|
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
179
|
|
|
157
|
-
export function moveTo(node, path, currentNode, idPrefix) {
|
|
180
|
+
export function moveTo(node, path, currentNode, idPrefix, fields) {
|
|
158
181
|
const indices = indicesFromPath(path)
|
|
159
182
|
|
|
160
183
|
let current = node.querySelector('#' + idPrefix + indices.join('-'))
|
|
161
184
|
if (current) current.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
|
|
162
185
|
|
|
186
|
+
const id = getId(currentNode, fields)
|
|
163
187
|
node.dispatchEvent(
|
|
164
188
|
new CustomEvent('move', {
|
|
165
|
-
detail: {
|
|
189
|
+
detail: {
|
|
190
|
+
path: indices,
|
|
191
|
+
node: currentNode,
|
|
192
|
+
id
|
|
193
|
+
}
|
|
166
194
|
})
|
|
167
195
|
)
|
|
168
196
|
}
|
package/src/themeable.js
CHANGED
|
@@ -9,15 +9,16 @@ export function themable(node) {
|
|
|
9
9
|
let previous = {}
|
|
10
10
|
|
|
11
11
|
theme.subscribe((data) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
node.classList.add(data.name)
|
|
15
|
-
}
|
|
16
|
-
if (data.mode && data.mode !== previous.mode) {
|
|
17
|
-
node.classList.remove(previous.mode)
|
|
18
|
-
node.classList.add(data.mode)
|
|
19
|
-
}
|
|
12
|
+
switchClass(node, data.name, previous.name)
|
|
13
|
+
switchClass(node, data.mode, previous.mode)
|
|
20
14
|
|
|
21
15
|
previous = data
|
|
22
16
|
})
|
|
23
17
|
}
|
|
18
|
+
|
|
19
|
+
function switchClass(node, current, previous) {
|
|
20
|
+
if (current && current !== previous) {
|
|
21
|
+
node.classList.remove(previous)
|
|
22
|
+
node.classList.add(current)
|
|
23
|
+
}
|
|
24
|
+
}
|