@kjun-ui/native 0.12.0 → 0.12.1

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/index.cjs CHANGED
@@ -438,19 +438,25 @@ function useActiveLayerScope() {
438
438
  function currentFocus() {
439
439
  return typeof document === "undefined" ? null : document.activeElement;
440
440
  }
441
+ function domElement(target) {
442
+ const node = target;
443
+ return typeof (node == null ? void 0 : node.matches) === "function" && typeof node.closest === "function" && typeof node.querySelector === "function";
444
+ }
441
445
  function focusTrigger(target) {
442
- if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
446
+ if (domElement(target)) {
443
447
  return target.matches("button,input,[href],[tabindex]") ? target : target.querySelector("button,input,[href],[tabindex]") || target;
444
448
  }
445
449
  return target;
446
450
  }
451
+ function isRestorableFocus(item) {
452
+ return (item == null ? void 0 : item.isConnected) !== false && !(domElement(item) && item.closest("[inert]"));
453
+ }
447
454
  function restoreFocus(target, state, id, fallback2) {
448
- const usable = (item) => (item == null ? void 0 : item.isConnected) !== false && !(typeof HTMLElement !== "undefined" && item instanceof HTMLElement && item.closest("[inert]"));
449
455
  const restore = () => {
450
456
  var _a, _b, _c, _d, _e;
451
457
  if (state.entries.has(id)) return;
452
- if (usable(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
453
- else if (fallback2 && fallback2 !== target && usable(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
458
+ if (isRestorableFocus(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
459
+ else if (fallback2 && fallback2 !== target && isRestorableFocus(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
454
460
  else (_e = (_d = (_c = state.topWindow()) == null ? void 0 : _c.root) == null ? void 0 : _d.focus) == null ? void 0 : _e.call(_d, { preventScroll: true });
455
461
  };
456
462
  if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(restore);
package/dist/index.js CHANGED
@@ -320,19 +320,25 @@ function useActiveLayerScope() {
320
320
  function currentFocus() {
321
321
  return typeof document === "undefined" ? null : document.activeElement;
322
322
  }
323
+ function domElement(target) {
324
+ const node = target;
325
+ return typeof (node == null ? void 0 : node.matches) === "function" && typeof node.closest === "function" && typeof node.querySelector === "function";
326
+ }
323
327
  function focusTrigger(target) {
324
- if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
328
+ if (domElement(target)) {
325
329
  return target.matches("button,input,[href],[tabindex]") ? target : target.querySelector("button,input,[href],[tabindex]") || target;
326
330
  }
327
331
  return target;
328
332
  }
333
+ function isRestorableFocus(item) {
334
+ return (item == null ? void 0 : item.isConnected) !== false && !(domElement(item) && item.closest("[inert]"));
335
+ }
329
336
  function restoreFocus(target, state, id, fallback2) {
330
- const usable = (item) => (item == null ? void 0 : item.isConnected) !== false && !(typeof HTMLElement !== "undefined" && item instanceof HTMLElement && item.closest("[inert]"));
331
337
  const restore = () => {
332
338
  var _a, _b, _c, _d, _e;
333
339
  if (state.entries.has(id)) return;
334
- if (usable(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
335
- else if (fallback2 && fallback2 !== target && usable(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
340
+ if (isRestorableFocus(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
341
+ else if (fallback2 && fallback2 !== target && isRestorableFocus(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
336
342
  else (_e = (_d = (_c = state.topWindow()) == null ? void 0 : _c.root) == null ? void 0 : _d.focus) == null ? void 0 : _e.call(_d, { preventScroll: true });
337
343
  };
338
344
  if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(restore);
@@ -438,19 +438,25 @@ function useActiveLayerScope() {
438
438
  function currentFocus() {
439
439
  return typeof document === "undefined" ? null : document.activeElement;
440
440
  }
441
+ function domElement(target) {
442
+ const node = target;
443
+ return typeof (node == null ? void 0 : node.matches) === "function" && typeof node.closest === "function" && typeof node.querySelector === "function";
444
+ }
441
445
  function focusTrigger(target) {
442
- if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
446
+ if (domElement(target)) {
443
447
  return target.matches("button,input,[href],[tabindex]") ? target : target.querySelector("button,input,[href],[tabindex]") || target;
444
448
  }
445
449
  return target;
446
450
  }
451
+ function isRestorableFocus(item) {
452
+ return (item == null ? void 0 : item.isConnected) !== false && !(domElement(item) && item.closest("[inert]"));
453
+ }
447
454
  function restoreFocus(target, state, id, fallback2) {
448
- const usable = (item) => (item == null ? void 0 : item.isConnected) !== false && !(typeof HTMLElement !== "undefined" && item instanceof HTMLElement && item.closest("[inert]"));
449
455
  const restore = () => {
450
456
  var _a, _b, _c, _d, _e;
451
457
  if (state.entries.has(id)) return;
452
- if (usable(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
453
- else if (fallback2 && fallback2 !== target && usable(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
458
+ if (isRestorableFocus(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
459
+ else if (fallback2 && fallback2 !== target && isRestorableFocus(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
454
460
  else (_e = (_d = (_c = state.topWindow()) == null ? void 0 : _c.root) == null ? void 0 : _d.focus) == null ? void 0 : _e.call(_d, { preventScroll: true });
455
461
  };
456
462
  if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(restore);
package/dist/index.web.js CHANGED
@@ -320,19 +320,25 @@ function useActiveLayerScope() {
320
320
  function currentFocus() {
321
321
  return typeof document === "undefined" ? null : document.activeElement;
322
322
  }
323
+ function domElement(target) {
324
+ const node = target;
325
+ return typeof (node == null ? void 0 : node.matches) === "function" && typeof node.closest === "function" && typeof node.querySelector === "function";
326
+ }
323
327
  function focusTrigger(target) {
324
- if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
328
+ if (domElement(target)) {
325
329
  return target.matches("button,input,[href],[tabindex]") ? target : target.querySelector("button,input,[href],[tabindex]") || target;
326
330
  }
327
331
  return target;
328
332
  }
333
+ function isRestorableFocus(item) {
334
+ return (item == null ? void 0 : item.isConnected) !== false && !(domElement(item) && item.closest("[inert]"));
335
+ }
329
336
  function restoreFocus(target, state, id, fallback2) {
330
- const usable = (item) => (item == null ? void 0 : item.isConnected) !== false && !(typeof HTMLElement !== "undefined" && item instanceof HTMLElement && item.closest("[inert]"));
331
337
  const restore = () => {
332
338
  var _a, _b, _c, _d, _e;
333
339
  if (state.entries.has(id)) return;
334
- if (usable(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
335
- else if (fallback2 && fallback2 !== target && usable(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
340
+ if (isRestorableFocus(target)) (_a = target == null ? void 0 : target.focus) == null ? void 0 : _a.call(target, { preventScroll: true });
341
+ else if (fallback2 && fallback2 !== target && isRestorableFocus(fallback2)) (_b = fallback2.focus) == null ? void 0 : _b.call(fallback2, { preventScroll: true });
336
342
  else (_e = (_d = (_c = state.topWindow()) == null ? void 0 : _c.root) == null ? void 0 : _d.focus) == null ? void 0 : _e.call(_d, { preventScroll: true });
337
343
  };
338
344
  if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(restore);
@@ -35,6 +35,7 @@ export declare function usePopupFocusGuard(trigger: {
35
35
  };
36
36
  export declare function useActiveLayerScope(): boolean;
37
37
  export declare function focusTrigger(target: FocusTarget | null | undefined): FocusTarget | HTMLElement | null | undefined;
38
+ export declare function isRestorableFocus(item: FocusTarget | null | undefined): boolean;
38
39
  export declare function useLayer(open: boolean, present: boolean, kind: LayerKind, close: () => void, trigger?: {
39
40
  current: FocusTarget | null;
40
41
  }, returnFocus?: () => FocusTarget | null | false | undefined): {
@@ -35,6 +35,7 @@ export declare function usePopupFocusGuard(trigger: {
35
35
  };
36
36
  export declare function useActiveLayerScope(): boolean;
37
37
  export declare function focusTrigger(target: FocusTarget | null | undefined): FocusTarget | HTMLElement | null | undefined;
38
+ export declare function isRestorableFocus(item: FocusTarget | null | undefined): boolean;
38
39
  export declare function useLayer(open: boolean, present: boolean, kind: LayerKind, close: () => void, trigger?: {
39
40
  current: FocusTarget | null;
40
41
  }, returnFocus?: () => FocusTarget | null | false | undefined): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kjun-ui/native",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "license": "MIT",
5
5
  "homepage": "https://ui.kjun.dev",
6
6
  "repository": {
@@ -47,8 +47,8 @@
47
47
  "./package.json": "./package.json"
48
48
  },
49
49
  "dependencies": {
50
- "@kjun-ui/tokens": "0.12.0",
51
- "@kjun-ui/icons": "0.12.0"
50
+ "@kjun-ui/tokens": "0.12.1",
51
+ "@kjun-ui/icons": "0.12.1"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": "^19.2.3",