@rokkit/actions 1.0.0-next.125 → 1.0.0-next.128

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/src/utils.js CHANGED
@@ -26,8 +26,8 @@ export function getClosestAncestorWithAttribute(element, attribute) {
26
26
  * @returns {string|null} - The event name or null if no match is found.
27
27
  */
28
28
  export const getEventForKey = (keyMapping, key) => {
29
- // eslint-disable-next-line no-unused-vars
30
- const matchEvent = ([eventName, keys]) =>
29
+
30
+ const matchEvent = ([_eventName, keys]) =>
31
31
  (Array.isArray(keys) && keys.includes(key)) || (keys instanceof RegExp && keys.test(key))
32
32
 
33
33
  const event = find(matchEvent, toPairs(keyMapping))
@@ -92,7 +92,7 @@ export function getPathFromEvent(event) {
92
92
  /**
93
93
  * Identifies if an element is a collapsible icon
94
94
  * @param {HTMLElement} target
95
- * @returns
95
+ * @returns {boolean}
96
96
  */
97
97
  function isNodeToggle(target) {
98
98
  return (
@@ -101,6 +101,29 @@ function isNodeToggle(target) {
101
101
  ['closed', 'opened'].includes(target.getAttribute('data-state'))
102
102
  )
103
103
  }
104
+
105
+ /**
106
+ * Finds the closest ancestor (or self) that has the given attribute
107
+ * @param {HTMLElement} element
108
+ * @param {string} attribute
109
+ * @returns {HTMLElement|null}
110
+ */
111
+ function findClosestWithAttribute(element, attribute) {
112
+ if (!element) return null
113
+ if (element.hasAttribute && element.hasAttribute(attribute)) return element
114
+ return findClosestWithAttribute(element.parentElement, attribute)
115
+ }
116
+
117
+ /**
118
+ * Identifies if an element or its ancestors is an accordion/tree trigger
119
+ * @param {HTMLElement} target
120
+ * @returns {boolean}
121
+ */
122
+ function isAccordionTrigger(target) {
123
+ if (!target) return false
124
+ const trigger = findClosestWithAttribute(target, 'data-accordion-trigger')
125
+ return trigger !== null
126
+ }
104
127
  // getKeyboardAction moved to kbd.js
105
128
 
106
129
  /**
@@ -110,9 +133,14 @@ function isNodeToggle(target) {
110
133
  * @returns {string} The determined action
111
134
  */
112
135
  export const getClickAction = (event) => {
113
- const { ctrlKey, metaKey, target } = event
136
+ const { ctrlKey, metaKey, shiftKey, target } = event
114
137
 
115
- // Check for modifier keys first (highest priority)
138
+ // Check for shift key first (range selection)
139
+ if (shiftKey && !ctrlKey && !metaKey) {
140
+ return 'range'
141
+ }
142
+
143
+ // Check for modifier keys (toggle selection)
116
144
  if (ctrlKey || metaKey) {
117
145
  return 'extend'
118
146
  }
@@ -122,6 +150,11 @@ export const getClickAction = (event) => {
122
150
  return 'toggle'
123
151
  }
124
152
 
153
+ // Check if clicked on accordion trigger (header area)
154
+ if (isAccordionTrigger(target)) {
155
+ return 'toggle'
156
+ }
157
+
125
158
  // Default action
126
159
  return 'select'
127
160
  }