@rokkit/actions 1.3.15 → 1.4.0

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/dist/utils.d.ts CHANGED
@@ -1,11 +1,3 @@
1
- /**
2
- * Finds the closest ancestor of the given element that has the given attribute.
3
- *
4
- * @param {HTMLElement} element
5
- * @param {string} attribute
6
- * @returns {HTMLElement|null}
7
- */
8
- export function getClosestAncestorWithAttribute(element: HTMLElement, attribute: string): HTMLElement | null;
9
1
  export function handleAction(actions: any, event: any): void;
10
2
  /**
11
3
  * Finds and returns an index path based on data-path attribute
@@ -14,5 +6,7 @@ export function handleAction(actions: any, event: any): void;
14
6
  * @returns {number[]|null} null or index path array
15
7
  */
16
8
  export function getPathFromEvent(event: MouseEvent): number[] | null;
9
+ export { getClosestAncestorWithAttribute };
17
10
  export function getEventForKey(keyMapping: import("./types.js").KeyboardConfig, key: string): string | null;
18
11
  export function getClickAction(event: MouseEvent): string;
12
+ import { getClosestAncestorWithAttribute } from '@rokkit/core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/actions",
3
- "version": "1.3.15",
3
+ "version": "1.4.0",
4
4
  "description": "Contains generic actions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/navigator.js CHANGED
@@ -143,6 +143,8 @@ export class Navigator {
143
143
  #wrapper
144
144
  #keymap
145
145
  #containScroll
146
+ // Set by destroy() so a deferred focusout can tell it's been torn down.
147
+ #destroyed = false
146
148
 
147
149
  // Typeahead state
148
150
  #buffer = ''
@@ -169,6 +171,7 @@ export class Navigator {
169
171
  }
170
172
 
171
173
  destroy() {
174
+ this.#destroyed = true
172
175
  this.#root.removeEventListener('keydown', this.#onKeydown)
173
176
  this.#root.removeEventListener('click', this.#onClick)
174
177
  this.#root.removeEventListener('focusin', this.#onFocusin)
@@ -275,8 +278,18 @@ export class Navigator {
275
278
  // If it's null or outside this root, focus left the list
276
279
  const next = /** @type {Node|null} */ (event.relatedTarget)
277
280
  if (!next || !this.#root.contains(next)) {
278
- // Focus left the list — wrapper can react (e.g. close a dropdown)
279
- this.#wrapper.blur?.()
281
+ // Removing a focused element also fires focusout with a null
282
+ // relatedTarget, so teardown looks exactly like a real blur here. Calling
283
+ // wrapper.blur() synchronously in that case mutates state during Svelte's
284
+ // effect-cleanup phase, which throws `state_unsafe_mutation`. Deferring by
285
+ // a microtask lets destroy() land first, so a torn-down navigator stays
286
+ // quiet while a genuine blur still reaches the wrapper.
287
+ // JSDOM never fires focusout on removal, so this only shows up in a real
288
+ // browser — see packages/ui/browser/Select.browser.spec.ts.
289
+ queueMicrotask(() => {
290
+ if (this.#destroyed) return
291
+ this.#wrapper.blur?.()
292
+ })
280
293
  }
281
294
  }
282
295
 
package/src/utils.js CHANGED
@@ -1,17 +1,9 @@
1
1
  import { find, toPairs } from 'ramda'
2
+ import { getClosestAncestorWithAttribute } from '@rokkit/core'
2
3
 
3
- /**
4
- * Finds the closest ancestor of the given element that has the given attribute.
5
- *
6
- * @param {HTMLElement} element
7
- * @param {string} attribute
8
- * @returns {HTMLElement|null}
9
- */
10
- export function getClosestAncestorWithAttribute(element, attribute) {
11
- if (!element) return null
12
- if (element.getAttribute(attribute)) return element
13
- return getClosestAncestorWithAttribute(element.parentElement, attribute)
14
- }
4
+ // Re-exported so `@rokkit/actions` keeps its existing public surface; the single
5
+ // implementation lives in @rokkit/core.
6
+ export { getClosestAncestorWithAttribute }
15
7
 
16
8
  /**
17
9
  * Get the event name for a given key.
@@ -50,7 +42,6 @@ export function handleAction(actions, event) {
50
42
  export function getPathFromEvent(event) {
51
43
  const node = getClosestAncestorWithAttribute(event.target, 'data-path')
52
44
  return node?.getAttribute('data-path')
53
- // return node ? getPathFromKey(node.getAttribute('data-path')) : null
54
45
  }
55
46
 
56
47
  /**