@epoch32/visage 1.3.2 → 1.3.3

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.
@@ -575,7 +575,7 @@ function useDismiss2(element, options) {
575
575
  }
576
576
  };
577
577
  if (typeof document !== "undefined") {
578
- const unbind = onClickOutside2(() => {
578
+ const unbindPointer = onClickOutside2(() => {
579
579
  const el = element();
580
580
  const rawIgnores = typeof options.outsideIgnore === "function" ? options.outsideIgnore() : options.outsideIgnore;
581
581
  const ignores = Array.isArray(rawIgnores) ? rawIgnores : rawIgnores ? [rawIgnores] : [];
@@ -592,7 +592,25 @@ function useDismiss2(element, options) {
592
592
  options.onDismiss();
593
593
  }
594
594
  });
595
- onCleanup2(unbind);
595
+ const onGlobalKeyDown = (e) => {
596
+ if (!isEnabled() || e.defaultPrevented)
597
+ return;
598
+ if (e.key === "Escape" && (options.escapeKey ?? true)) {
599
+ if (options.onEscapeKeyDown) {
600
+ options.onEscapeKeyDown(e);
601
+ }
602
+ if (!e.defaultPrevented) {
603
+ options.onDismiss();
604
+ e.stopPropagation();
605
+ }
606
+ }
607
+ };
608
+ const targetWindow = typeof window !== "undefined" ? window : document;
609
+ targetWindow.addEventListener("keydown", onGlobalKeyDown);
610
+ onCleanup2(() => {
611
+ unbindPointer();
612
+ targetWindow.removeEventListener("keydown", onGlobalKeyDown);
613
+ });
596
614
  }
597
615
  return {
598
616
  handleKeyDown,
package/dist/index.js CHANGED
@@ -153,7 +153,7 @@ import {
153
153
  ToastDescription2,
154
154
  ToastClose2,
155
155
  Toast2
156
- } from "./index-vbsc8z8h.js";
156
+ } from "./index-9700cg44.js";
157
157
  import {
158
158
  createVirtualizer2,
159
159
  VirtualList2,
package/dist/ui/index.js CHANGED
@@ -55,7 +55,7 @@ import {
55
55
  ToastDescription2,
56
56
  ToastClose2,
57
57
  Toast2
58
- } from "../index-vbsc8z8h.js";
58
+ } from "../index-9700cg44.js";
59
59
  import {
60
60
  createId2,
61
61
  createControllableSignal2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epoch32/visage",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Lightning-fast, zero-VDOM, fine-grained reactive UI library with full TypeScript support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/ui/overlay.ts CHANGED
@@ -97,9 +97,9 @@ export function useDismiss(
97
97
  }
98
98
  };
99
99
 
100
- // Setup outside pointer listener
100
+ // Setup outside pointer listener and global escape key listener
101
101
  if (typeof document !== "undefined") {
102
- const unbind = onClickOutside(
102
+ const unbindPointer = onClickOutside(
103
103
  () => {
104
104
  const el = element();
105
105
  const rawIgnores =
@@ -120,7 +120,27 @@ export function useDismiss(
120
120
  }
121
121
  }
122
122
  );
123
- onCleanup(unbind);
123
+
124
+ const onGlobalKeyDown = (e: KeyboardEvent) => {
125
+ if (!isEnabled() || e.defaultPrevented) return;
126
+ if (e.key === "Escape" && (options.escapeKey ?? true)) {
127
+ if (options.onEscapeKeyDown) {
128
+ options.onEscapeKeyDown(e);
129
+ }
130
+ if (!e.defaultPrevented) {
131
+ options.onDismiss();
132
+ e.stopPropagation();
133
+ }
134
+ }
135
+ };
136
+
137
+ const targetWindow = typeof window !== "undefined" ? window : document;
138
+ targetWindow.addEventListener("keydown", onGlobalKeyDown as any);
139
+
140
+ onCleanup(() => {
141
+ unbindPointer();
142
+ targetWindow.removeEventListener("keydown", onGlobalKeyDown as any);
143
+ });
124
144
  }
125
145
 
126
146
  return {