@stonecrop/atable 0.2.10 → 0.2.13

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": "@stonecrop/atable",
3
- "version": "0.2.10",
3
+ "version": "0.2.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "uuid": "^9.0.0",
35
35
  "vue": "^3.4.23",
36
- "@stonecrop/themes": "0.2.10",
37
- "@stonecrop/utilities": "0.2.10"
36
+ "@stonecrop/themes": "0.2.13",
37
+ "@stonecrop/utilities": "0.2.13"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@histoire/plugin-vue": "^0.17.17",
@@ -55,10 +55,10 @@
55
55
  "vite": "^5.2.9",
56
56
  "vitest": "^1.5.0",
57
57
  "vue-router": "^4",
58
- "@stonecrop/aform": "0.2.10"
58
+ "@stonecrop/aform": "0.2.13"
59
59
  },
60
60
  "peerDependencies": {
61
- "@stonecrop/aform": "0.2.10"
61
+ "@stonecrop/aform": "0.2.13"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"
@@ -27,7 +27,7 @@
27
27
  <script setup lang="ts">
28
28
  import { computed, CSSProperties, inject, ref } from 'vue'
29
29
 
30
- import { defaultKeypressHandlers, useKeyboardNav } from '@stonecrop/utilities'
30
+ import { KeypressHandlers, defaultKeypressHandlers, useKeyboardNav } from '@stonecrop/utilities'
31
31
  import TableDataStore from '.'
32
32
 
33
33
  const props = withDefaults(
@@ -35,7 +35,7 @@ const props = withDefaults(
35
35
  colIndex: number
36
36
  rowIndex: number
37
37
  tableid: string
38
- addNavigation?: boolean | object
38
+ addNavigation?: boolean | KeypressHandlers
39
39
  tabIndex?: number
40
40
  clickHandler?: (event: MouseEvent) => void
41
41
  }>(),
@@ -16,7 +16,7 @@
16
16
  import { TableRow } from 'types'
17
17
  import { inject, ref } from 'vue'
18
18
 
19
- import { useKeyboardNav } from '@stonecrop/utilities'
19
+ import { type KeypressHandlers, useKeyboardNav } from '@stonecrop/utilities'
20
20
 
21
21
  import TableDataStore from '.'
22
22
 
@@ -26,9 +26,7 @@ const props = withDefaults(
26
26
  rowIndex: number
27
27
  tableid: string
28
28
  tabIndex?: number
29
- addNavigation?: {
30
- [key: string]: (ev: KeyboardEvent) => any
31
- }
29
+ addNavigation?: boolean | KeypressHandlers
32
30
  }>(),
33
31
  {
34
32
  tabIndex: -1,
@@ -43,18 +41,23 @@ const getRowExpandSymbol = () => {
43
41
  return tableData.display[props.rowIndex].expanded ? '▼' : '►'
44
42
  }
45
43
 
46
- if (props.addNavigation !== undefined) {
47
- const keyboardNav = Object.assign({}, props.addNavigation)
48
- keyboardNav['keydown.control.g'] = (event: KeyboardEvent) => {
49
- event.stopPropagation()
50
- event.preventDefault()
51
- tableData.toggleRowExpand(props.rowIndex)
44
+ if (props.addNavigation) {
45
+ const handlers: KeypressHandlers = {
46
+ 'keydown.control.g': (event: KeyboardEvent) => {
47
+ event.stopPropagation()
48
+ event.preventDefault()
49
+ tableData.toggleRowExpand(props.rowIndex)
50
+ },
51
+ }
52
+
53
+ if (typeof props.addNavigation === 'object') {
54
+ Object.assign(handlers, props.addNavigation)
52
55
  }
53
56
 
54
57
  useKeyboardNav([
55
58
  {
56
59
  selectors: rowEl,
57
- handlers: keyboardNav,
60
+ handlers: handlers,
58
61
  },
59
62
  ])
60
63
  }
@@ -21,7 +21,7 @@
21
21
  <script setup lang="ts">
22
22
  import { TableRow } from 'types'
23
23
  import { inject, ref } from 'vue'
24
- import { useKeyboardNav } from '@stonecrop/utilities'
24
+ import { type KeypressHandlers, useKeyboardNav, defaultKeypressHandlers } from '@stonecrop/utilities'
25
25
 
26
26
  import TableDataStore from '.'
27
27
 
@@ -31,10 +31,11 @@ const props = withDefaults(
31
31
  rowIndex: number
32
32
  tableid: string
33
33
  tabIndex?: number
34
- addNavigation?: object
34
+ addNavigation?: boolean | KeypressHandlers
35
35
  }>(),
36
36
  {
37
37
  tabIndex: -1,
38
+ addNavigation: false, // default to allowing cell navigation
38
39
  }
39
40
  )
40
41
 
@@ -79,10 +80,19 @@ const toggleRowExpand = (rowIndex: number) => {
79
80
  }
80
81
 
81
82
  if (props.addNavigation) {
83
+ let handlers = defaultKeypressHandlers
84
+
85
+ if (typeof props.addNavigation === 'object') {
86
+ handlers = {
87
+ ...handlers,
88
+ ...props.addNavigation,
89
+ }
90
+ }
91
+
82
92
  useKeyboardNav([
83
93
  {
84
94
  selectors: rowEl,
85
- handlers: props.addNavigation,
95
+ handlers: handlers,
86
96
  },
87
97
  ])
88
98
  }