@rokkit/actions 1.0.0-next.78 → 1.0.0-next.80

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/actions",
3
- "version": "1.0.0-next.78",
3
+ "version": "1.0.0-next.80",
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",
@@ -22,8 +22,8 @@
22
22
  "typescript": "^5.3.3",
23
23
  "vite": "^5.0.12",
24
24
  "vitest": "~1.2.2",
25
- "validators": "1.0.0-next.78",
26
- "shared-config": "1.0.0-next.78"
25
+ "shared-config": "1.0.0-next.80",
26
+ "validators": "1.0.0-next.80"
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.78",
46
- "@rokkit/stores": "1.0.0-next.78"
45
+ "@rokkit/core": "1.0.0-next.80",
46
+ "@rokkit/stores": "1.0.0-next.80"
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
+ }
package/src/themeable.js CHANGED
@@ -11,7 +11,7 @@ export function themable(node) {
11
11
  theme.subscribe((data) => {
12
12
  switchClass(node, data.name, previous.name)
13
13
  switchClass(node, data.mode, previous.mode)
14
-
14
+ // switchPalette(node, data.palette, previous.palette)
15
15
  previous = data
16
16
  })
17
17
  }
@@ -30,3 +30,13 @@ function switchClass(node, current, previous) {
30
30
  node.classList.add(current)
31
31
  }
32
32
  }
33
+
34
+ // function switchPalette(node, current, previous) {
35
+ // Object.keys(current).map((key) => {
36
+ // if (!equals(current[key], previous[key])) {
37
+ // Object.keys(current[key]).map((shade) => {
38
+ // node.style.setProperty(`--${key}-${shade}`, current[key][shade])
39
+ // })
40
+ // }
41
+ // })
42
+ // }