@douyinfe/semi-foundation 2.68.0-beta.0 → 2.68.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.
@@ -3,7 +3,8 @@ import { keyToCode, Keys } from './constants';
3
3
 
4
4
  export interface HotKeysAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
5
5
  notifyHotKey: (e: KeyboardEvent) => void;
6
- getListenerTarget: () => HTMLElement
6
+ registerEvent: () => void;
7
+ unregisterEvent: () => void
7
8
  }
8
9
 
9
10
  export default class HotKeysFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<HotKeysAdapter<P, S>, P, S> {
@@ -13,8 +14,7 @@ export default class HotKeysFoundation<P = Record<string, any>, S = Record<strin
13
14
 
14
15
  init(): void {
15
16
  // init Listener
16
- const target = this._adapter.getListenerTarget();
17
- target?.addEventListener('keydown', this.handleKeyDown);
17
+ this._adapter.registerEvent();
18
18
  const hotKeys = this.getProps().hotKeys;
19
19
  if (!this.isValidHotKeys(hotKeys)) {
20
20
  throw new Error('HotKeys must have one common key and 0/some modifier key');
@@ -75,7 +75,6 @@ export default class HotKeysFoundation<P = Record<string, any>, S = Record<strin
75
75
 
76
76
  destroy(): void {
77
77
  // remove Listener
78
- const target = this._adapter.getListenerTarget();
79
- target?.removeEventListener('keydown', this.handleKeyDown);
78
+ this._adapter.unregisterEvent();
80
79
  }
81
80
  }
@@ -1,7 +1,8 @@
1
1
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
2
2
  export interface HotKeysAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
3
3
  notifyHotKey: (e: KeyboardEvent) => void;
4
- getListenerTarget: () => HTMLElement;
4
+ registerEvent: () => void;
5
+ unregisterEvent: () => void;
5
6
  }
6
7
  export default class HotKeysFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<HotKeysAdapter<P, S>, P, S> {
7
8
  constructor(adapter: HotKeysAdapter<P, S>);
@@ -63,8 +63,7 @@ class HotKeysFoundation extends _foundation.default {
63
63
  }
64
64
  init() {
65
65
  // init Listener
66
- const target = this._adapter.getListenerTarget();
67
- target === null || target === void 0 ? void 0 : target.addEventListener('keydown', this.handleKeyDown);
66
+ this._adapter.registerEvent();
68
67
  const hotKeys = this.getProps().hotKeys;
69
68
  if (!this.isValidHotKeys(hotKeys)) {
70
69
  throw new Error('HotKeys must have one common key and 0/some modifier key');
@@ -72,8 +71,7 @@ class HotKeysFoundation extends _foundation.default {
72
71
  }
73
72
  destroy() {
74
73
  // remove Listener
75
- const target = this._adapter.getListenerTarget();
76
- target === null || target === void 0 ? void 0 : target.removeEventListener('keydown', this.handleKeyDown);
74
+ this._adapter.unregisterEvent();
77
75
  }
78
76
  }
79
77
  exports.default = HotKeysFoundation;
@@ -1,7 +1,8 @@
1
1
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
2
2
  export interface HotKeysAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
3
3
  notifyHotKey: (e: KeyboardEvent) => void;
4
- getListenerTarget: () => HTMLElement;
4
+ registerEvent: () => void;
5
+ unregisterEvent: () => void;
5
6
  }
6
7
  export default class HotKeysFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<HotKeysAdapter<P, S>, P, S> {
7
8
  constructor(adapter: HotKeysAdapter<P, S>);
@@ -56,8 +56,7 @@ export default class HotKeysFoundation extends BaseFoundation {
56
56
  }
57
57
  init() {
58
58
  // init Listener
59
- const target = this._adapter.getListenerTarget();
60
- target === null || target === void 0 ? void 0 : target.addEventListener('keydown', this.handleKeyDown);
59
+ this._adapter.registerEvent();
61
60
  const hotKeys = this.getProps().hotKeys;
62
61
  if (!this.isValidHotKeys(hotKeys)) {
63
62
  throw new Error('HotKeys must have one common key and 0/some modifier key');
@@ -65,7 +64,6 @@ export default class HotKeysFoundation extends BaseFoundation {
65
64
  }
66
65
  destroy() {
67
66
  // remove Listener
68
- const target = this._adapter.getListenerTarget();
69
- target === null || target === void 0 ? void 0 : target.removeEventListener('keydown', this.handleKeyDown);
67
+ this._adapter.unregisterEvent();
70
68
  }
71
69
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.68.0-beta.0",
3
+ "version": "2.68.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
7
7
  "prepublishOnly": "npm run build:lib"
8
8
  },
9
9
  "dependencies": {
10
- "@douyinfe/semi-animation": "2.68.0-beta.0",
10
+ "@douyinfe/semi-animation": "2.68.0",
11
11
  "@mdx-js/mdx": "^3.0.1",
12
12
  "async-validator": "^3.5.0",
13
13
  "classnames": "^2.2.6",
@@ -28,7 +28,7 @@
28
28
  "*.scss",
29
29
  "*.css"
30
30
  ],
31
- "gitHead": "14e3f82adfde5d9ac0de952b74b3e2cee2e5fd33",
31
+ "gitHead": "f28e4e271565377b85d7f039fdb0e8177fa120ae",
32
32
  "devDependencies": {
33
33
  "@babel/plugin-transform-runtime": "^7.15.8",
34
34
  "@babel/preset-env": "^7.15.8",