@rokkit/actions 1.0.0-next.79 → 1.0.0-next.81
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 +10 -10
- package/src/index.js +1 -0
- package/src/switchable.js +41 -0
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.81",
|
|
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
|
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
|
16
16
|
"@testing-library/svelte": "^4.1.0",
|
|
17
17
|
"@types/ramda": "^0.29.10",
|
|
18
|
-
"@vitest/coverage-v8": "^1.
|
|
19
|
-
"@vitest/ui": "~1.
|
|
18
|
+
"@vitest/coverage-v8": "^1.3.1",
|
|
19
|
+
"@vitest/ui": "~1.3.1",
|
|
20
20
|
"jsdom": "^24.0.0",
|
|
21
|
-
"svelte": "^4.2.
|
|
21
|
+
"svelte": "^4.2.11",
|
|
22
22
|
"typescript": "^5.3.3",
|
|
23
|
-
"vite": "^5.
|
|
24
|
-
"vitest": "~1.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
23
|
+
"vite": "^5.1.4",
|
|
24
|
+
"vitest": "~1.3.1",
|
|
25
|
+
"validators": "1.0.0-next.81",
|
|
26
|
+
"shared-config": "1.0.0-next.81"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"src/**/*.js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"ramda": "^0.29.1",
|
|
45
|
-
"@rokkit/core": "1.0.0-next.
|
|
46
|
-
"@rokkit/stores": "1.0.0-next.
|
|
45
|
+
"@rokkit/core": "1.0.0-next.81",
|
|
46
|
+
"@rokkit/stores": "1.0.0-next.81"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"format": "prettier --write .",
|
package/src/index.js
CHANGED
|
@@ -8,5 +8,6 @@ export { navigator } from './navigator'
|
|
|
8
8
|
export { dismissable } from './dismissable'
|
|
9
9
|
export { themable } from './themeable'
|
|
10
10
|
export { swipeable } from './swipeable'
|
|
11
|
+
export { switchable } from './switchable'
|
|
11
12
|
export { delegateKeyboardEvents } from './delegate'
|
|
12
13
|
export { virtualListViewport } from './lib/viewport'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function switchable(node, data) {
|
|
2
|
+
let index = 0
|
|
3
|
+
let { value, options, disabled } = data
|
|
4
|
+
|
|
5
|
+
const update = (data) => {
|
|
6
|
+
value = data.value === null || data.value === undefined ? options[0] : data.value
|
|
7
|
+
options = data.options
|
|
8
|
+
disabled = data.disabled
|
|
9
|
+
index = options.indexOf(value)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const toggle = (increment = 1) => {
|
|
13
|
+
if (disabled) return
|
|
14
|
+
index = (index + increment) % options.length
|
|
15
|
+
value = options[index]
|
|
16
|
+
node.dispatchEvent(new CustomEvent('change', { detail: value }))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const keydown = (e) => {
|
|
20
|
+
if (disabled) return
|
|
21
|
+
if ([' ', 'Enter', 'ArrowRight', 'ArrowLeft'].includes(e.key)) {
|
|
22
|
+
e.preventDefault()
|
|
23
|
+
e.stopPropagation()
|
|
24
|
+
|
|
25
|
+
toggle(e.key === 'ArrowLeft' ? options.length - 1 : 1)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const click = () => toggle(1)
|
|
29
|
+
|
|
30
|
+
update(data)
|
|
31
|
+
node.addEventListener('click', click)
|
|
32
|
+
node.addEventListener('keydown', keydown)
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
update,
|
|
36
|
+
destroy() {
|
|
37
|
+
node.removeEventListener('click', click)
|
|
38
|
+
node.removeEventListener('keydown', keydown)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|