@rainbow-oh/yee-c 0.15.1 → 0.15.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.
@@ -160,7 +160,7 @@ var Dialog = (baseprops) => {
160
160
  });
161
161
  (0, import_useLockFocus.default)(contentElement, delayOpen);
162
162
  (0, import_useEsc.default)({
163
- enabled: keyboard,
163
+ enabled: keyboard && open,
164
164
  onEsc: () => {
165
165
  onCancel == null ? void 0 : onCancel();
166
166
  }
@@ -157,7 +157,7 @@ var Drawer = (baseprops) => {
157
157
  const bodyId = `${drawerId}-body`;
158
158
  (0, import_useLockFocus.default)(contentRef.current, delayOpen);
159
159
  (0, import_useEsc.default)({
160
- enabled: keyboard,
160
+ enabled: keyboard && open,
161
161
  onEsc: () => {
162
162
  onClose == null ? void 0 : onClose();
163
163
  }
@@ -74,7 +74,7 @@ var Popup = (baseprops, ref) => {
74
74
  const internalRef = (0, import_react2.useRef)(null);
75
75
  const componentRef = ref || internalRef;
76
76
  (0, import_useEsc.default)({
77
- enabled: keyboard,
77
+ enabled: keyboard && open,
78
78
  onEsc: () => {
79
79
  onClose == null ? void 0 : onClose();
80
80
  }
@@ -205,7 +205,9 @@ export interface ColumnProps {
205
205
  /**
206
206
  * Custom filter function, e.g. custom search
207
207
  */
208
- render?: () => React.ReactNode;
208
+ render?: (ctx: {
209
+ close: () => void;
210
+ }) => React.ReactNode;
209
211
  /**
210
212
  * Filter callback function
211
213
  */
@@ -150,7 +150,7 @@ var HeaderFilter = import_react.default.memo((props) => {
150
150
  }
151
151
  ) : null;
152
152
  if (render) {
153
- popup = render();
153
+ popup = render({ close: () => setOpen(false) });
154
154
  } else if (items) {
155
155
  let dataSource = [];
156
156
  const inputValue = getStrLower(searchValue);
@@ -10,7 +10,7 @@ export interface UseEscProps {
10
10
  enabled?: boolean;
11
11
  }
12
12
  /**
13
- * React Hook for listening to ESC key press
13
+ * Hook for listening to ESC key press
14
14
  *
15
15
  * @example
16
16
  * ```tsx
@@ -34,25 +34,30 @@ __export(useEsc_exports, {
34
34
  module.exports = __toCommonJS(useEsc_exports);
35
35
  var import_react = require("react");
36
36
  var import_useEvent = __toESM(require("./useEvent"));
37
+ var escSeq = 0;
38
+ var escLayers = [];
37
39
  function useEsc({ onEsc, enabled = true } = {}) {
38
40
  const handleEsc = (0, import_useEvent.default)(onEsc || (() => {
39
41
  }));
40
- const handleKeyDown = (0, import_react.useCallback)(
41
- (event) => {
42
- if (event.key === "Escape") {
43
- event.preventDefault();
44
- handleEsc(event);
45
- }
46
- },
47
- [handleEsc]
48
- );
42
+ const [id] = (0, import_react.useState)(() => ++escSeq);
49
43
  (0, import_react.useEffect)(() => {
50
44
  if (!enabled) {
51
45
  return;
52
46
  }
47
+ escLayers.push(id);
48
+ const handleKeyDown = (event) => {
49
+ if (event.key === "Escape" && escLayers[escLayers.length - 1] === id) {
50
+ event.preventDefault();
51
+ handleEsc(event);
52
+ }
53
+ };
53
54
  document.addEventListener("keydown", handleKeyDown);
54
55
  return () => {
55
56
  document.removeEventListener("keydown", handleKeyDown);
57
+ const index = escLayers.lastIndexOf(id);
58
+ if (index !== -1) {
59
+ escLayers.splice(index, 1);
60
+ }
56
61
  };
57
- }, [enabled, handleKeyDown]);
62
+ }, [enabled, handleEsc, id]);
58
63
  }
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-10-16T07:04:02.333Z
4
+ * Generated on 2026-10-20T03:27:37.391Z
5
5
  */
6
6
 
7
7
  /* ========== color.blue.css ========== */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-10-16T07:04:02.333Z
4
+ * Generated on 2026-10-20T03:27:37.391Z
5
5
  */
6
6
 
7
7
  /* ========== color.css ========== */
@@ -3,4 +3,4 @@ declare global {
3
3
  __yee_c_version__: string;
4
4
  }
5
5
  }
6
- export declare const version = "0.15.1";
6
+ export declare const version = "0.15.3";
@@ -22,7 +22,7 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- var version = "0.15.1";
25
+ var version = "0.15.3";
26
26
  if (typeof window !== "undefined") {
27
27
  window.__yee_c_version__ = version;
28
28
  }
@@ -114,9 +114,10 @@ var Dialog = function Dialog(baseprops) {
114
114
  // lock focus in the dialog
115
115
  useLockFocus(contentElement, delayOpen);
116
116
 
117
- // enable esc to close dialog
117
+ // enable esc to close dialog; gated on open so a mounted-but-closed
118
+ // dialog does not occupy the esc layer stack and swallow the top layer
118
119
  useEsc({
119
- enabled: keyboard,
120
+ enabled: keyboard && open,
120
121
  onEsc: function onEsc() {
121
122
  onCancel === null || onCancel === void 0 || onCancel();
122
123
  }
@@ -136,8 +136,11 @@ var Drawer = function Drawer(baseprops) {
136
136
  var titleId = "".concat(drawerId, "-title");
137
137
  var bodyId = "".concat(drawerId, "-body");
138
138
  useLockFocus(contentRef.current, delayOpen);
139
+
140
+ // gated on open so a mounted-but-closed drawer does not occupy the esc
141
+ // layer stack and swallow the top layer
139
142
  useEsc({
140
- enabled: keyboard,
143
+ enabled: keyboard && open,
141
144
  onEsc: function onEsc() {
142
145
  onClose === null || onClose === void 0 || onClose();
143
146
  }
@@ -37,8 +37,11 @@ var Popup = function Popup(baseprops, ref) {
37
37
  onClose = props.onClose;
38
38
  var internalRef = useRef(null);
39
39
  var componentRef = ref || internalRef;
40
+
41
+ // gated on open so a mounted-but-closed viewer does not occupy the esc
42
+ // layer stack and swallow the top layer
40
43
  useEsc({
41
- enabled: keyboard,
44
+ enabled: keyboard && open,
42
45
  onEsc: function onEsc() {
43
46
  onClose === null || onClose === void 0 || onClose();
44
47
  }
@@ -205,7 +205,9 @@ export interface ColumnProps {
205
205
  /**
206
206
  * Custom filter function, e.g. custom search
207
207
  */
208
- render?: () => React.ReactNode;
208
+ render?: (ctx: {
209
+ close: () => void;
210
+ }) => React.ReactNode;
209
211
  /**
210
212
  * Filter callback function
211
213
  */
@@ -165,7 +165,11 @@ var HeaderFilter = /*#__PURE__*/React.memo(function (props) {
165
165
  ref: inputRef
166
166
  }) : null;
167
167
  if (render) {
168
- popup = render();
168
+ popup = render({
169
+ close: function close() {
170
+ return setOpen(false);
171
+ }
172
+ });
169
173
  } else if (items) {
170
174
  var dataSource = [];
171
175
  var inputValue = getStrLower(searchValue);
@@ -10,7 +10,7 @@ export interface UseEscProps {
10
10
  enabled?: boolean;
11
11
  }
12
12
  /**
13
- * React Hook for listening to ESC key press
13
+ * Hook for listening to ESC key press
14
14
  *
15
15
  * @example
16
16
  * ```tsx
@@ -1,7 +1,19 @@
1
- import { useCallback, useEffect } from 'react';
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useState } from 'react';
2
8
  import useEvent from "./useEvent";
9
+ // 层级栈:所有 useEsc 监听都挂在 document 上,同一 keydown 会触发全部 handler。
10
+ // 按启用顺序压栈,Esc 只响应最后启用(最上层)的那一个 —— 弹层内再开
11
+ // 筛选/下拉/抽屉时,第一次 Esc 只关最上层,再按才逐层关闭。
12
+ var escSeq = 0;
13
+ var escLayers = [];
14
+
3
15
  /**
4
- * React Hook for listening to ESC key press
16
+ * Hook for listening to ESC key press
5
17
  *
6
18
  * @example
7
19
  * ```tsx
@@ -19,19 +31,29 @@ export default function useEsc() {
19
31
  _ref$enabled = _ref.enabled,
20
32
  enabled = _ref$enabled === void 0 ? true : _ref$enabled;
21
33
  var handleEsc = useEvent(onEsc || function () {});
22
- var handleKeyDown = useCallback(function (event) {
23
- if (event.key === 'Escape') {
24
- event.preventDefault();
25
- handleEsc(event);
26
- }
27
- }, [handleEsc]);
34
+ var _useState = useState(function () {
35
+ return ++escSeq;
36
+ }),
37
+ _useState2 = _slicedToArray(_useState, 1),
38
+ id = _useState2[0];
28
39
  useEffect(function () {
29
40
  if (!enabled) {
30
41
  return;
31
42
  }
43
+ escLayers.push(id);
44
+ var handleKeyDown = function handleKeyDown(event) {
45
+ if (event.key === 'Escape' && escLayers[escLayers.length - 1] === id) {
46
+ event.preventDefault();
47
+ handleEsc(event);
48
+ }
49
+ };
32
50
  document.addEventListener('keydown', handleKeyDown);
33
51
  return function () {
34
52
  document.removeEventListener('keydown', handleKeyDown);
53
+ var index = escLayers.lastIndexOf(id);
54
+ if (index !== -1) {
55
+ escLayers.splice(index, 1);
56
+ }
35
57
  };
36
- }, [enabled, handleKeyDown]);
58
+ }, [enabled, handleEsc, id]);
37
59
  }
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-10-16T07:04:02.333Z
4
+ * Generated on 2026-10-20T03:27:37.391Z
5
5
  */
6
6
 
7
7
  /* ========== color.blue.css ========== */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-10-16T07:04:02.333Z
4
+ * Generated on 2026-10-20T03:27:37.391Z
5
5
  */
6
6
 
7
7
  /* ========== color.css ========== */
@@ -3,4 +3,4 @@ declare global {
3
3
  __yee_c_version__: string;
4
4
  }
5
5
  }
6
- export declare const version = "0.15.1";
6
+ export declare const version = "0.15.3";
@@ -1,4 +1,4 @@
1
- export var version = "0.15.1";
1
+ export var version = "0.15.3";
2
2
  if (typeof window !== 'undefined') {
3
3
  window.__yee_c_version__ = version;
4
4
  }