@douyinfe/semi-foundation 2.32.3 → 2.32.5-alpha.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.
@@ -45,8 +45,9 @@ class SubNavFoundation extends _foundation.default {
45
45
  this._timer = null;
46
46
  }
47
47
 
48
- destroy() {} // eslint-disable-line
49
-
48
+ destroy() {
49
+ this.clearDelayTimer();
50
+ }
50
51
 
51
52
  clearDelayTimer() {
52
53
  if (this._timer) {
@@ -56,7 +57,6 @@ class SubNavFoundation extends _foundation.default {
56
57
  }
57
58
 
58
59
  isValidKey(itemKey) {
59
- // eslint-disable-next-line eqeqeq
60
60
  return itemKey != null && (typeof itemKey === 'number' || typeof itemKey === 'string');
61
61
  }
62
62
 
@@ -10,7 +10,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
10
10
  notifyVisibleChange(isVisible: any): void;
11
11
  getPopupContainerRect(): PopupContainerDOMRect;
12
12
  containerIsBody(): boolean;
13
- off(arg0: string): void;
13
+ off(arg0: string, arg1?: () => void): void;
14
14
  canMotion(): boolean;
15
15
  registerScrollHandler(arg: () => Record<string, any>): void;
16
16
  unregisterScrollHandler(): void;
@@ -47,6 +47,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
47
47
  notifyEscKeydown(event: any): void;
48
48
  getTriggerNode(): any;
49
49
  setId(): void;
50
+ getTriggerDOM(): HTMLElement | null;
50
51
  }
51
52
  export declare type Position = ArrayElement<typeof strings.POSITION_SET>;
52
53
  export interface PopupContainerDOMRect extends DOMRectLikeType {
@@ -93,6 +93,20 @@ class Tooltip extends _foundation.default {
93
93
  this.calcPosition();
94
94
  });
95
95
 
96
+ if (trigger === "hover") {
97
+ const checkTriggerIsHover = () => {
98
+ const triggerDOM = this._adapter.getTriggerDOM();
99
+
100
+ if (trigger && !triggerDOM.matches(":hover")) {
101
+ this.hide();
102
+ }
103
+
104
+ this._adapter.off("portalInserted", checkTriggerIsHover);
105
+ };
106
+
107
+ this._adapter.on('portalInserted', checkTriggerIsHover);
108
+ }
109
+
96
110
  this._adapter.on('positionUpdated', () => {
97
111
  this._togglePortalVisible(true);
98
112
  });
@@ -292,6 +306,7 @@ class Tooltip extends _foundation.default {
292
306
 
293
307
  this.unBindResizeEvent();
294
308
  this.unBindScrollEvent();
309
+ clearTimeout(this._timer);
295
310
  }
296
311
 
297
312
  _bindTriggerEvent(triggerEventSet) {
@@ -75,6 +75,6 @@ export declare function getValueOrKey(data: any): any;
75
75
  export declare function normalizeValue(value: any, withObject: boolean): any;
76
76
  export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
77
77
  export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;
78
- export declare function calcDropRelativePosition(event: any, treeNode: any): 0 | 1 | -1;
78
+ export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
79
79
  export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
80
80
  export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
@@ -18,7 +18,7 @@ declare const strings: {
18
18
  DRAG_AREA_ILLEGAL: string;
19
19
  TRIGGER_AUTO: "auto";
20
20
  TRIGGER_CUSTOM: "custom";
21
- UPLOAD_TRIGGER: ("custom" | "auto")[];
21
+ UPLOAD_TRIGGER: ("auto" | "custom")[];
22
22
  VALIDATE_STATUS: readonly ["default", "error", "warning", "success"];
23
23
  PROMPT_POSITION: readonly ["left", "right", "bottom"];
24
24
  };
@@ -67,8 +67,9 @@ class Event {
67
67
  return false;
68
68
  }
69
69
 
70
- this._eventMap.get(event).forEach(callback => callback(...args));
70
+ const callbacks = [...this._eventMap.get(event)]; // clone to avoid someone writing the logic of deleting callback in callbacks into his or her callback code, for example the once func above
71
71
 
72
+ callbacks.forEach(callback => callback(...args));
72
73
  return true;
73
74
  }
74
75
 
@@ -35,8 +35,9 @@ export default class SubNavFoundation extends BaseFoundation {
35
35
  this._timer = null;
36
36
  }
37
37
 
38
- destroy() {} // eslint-disable-line
39
-
38
+ destroy() {
39
+ this.clearDelayTimer();
40
+ }
40
41
 
41
42
  clearDelayTimer() {
42
43
  if (this._timer) {
@@ -46,7 +47,6 @@ export default class SubNavFoundation extends BaseFoundation {
46
47
  }
47
48
 
48
49
  isValidKey(itemKey) {
49
- // eslint-disable-next-line eqeqeq
50
50
  return itemKey != null && (typeof itemKey === 'number' || typeof itemKey === 'string');
51
51
  }
52
52
 
@@ -10,7 +10,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
10
10
  notifyVisibleChange(isVisible: any): void;
11
11
  getPopupContainerRect(): PopupContainerDOMRect;
12
12
  containerIsBody(): boolean;
13
- off(arg0: string): void;
13
+ off(arg0: string, arg1?: () => void): void;
14
14
  canMotion(): boolean;
15
15
  registerScrollHandler(arg: () => Record<string, any>): void;
16
16
  unregisterScrollHandler(): void;
@@ -47,6 +47,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
47
47
  notifyEscKeydown(event: any): void;
48
48
  getTriggerNode(): any;
49
49
  setId(): void;
50
+ getTriggerDOM(): HTMLElement | null;
50
51
  }
51
52
  export declare type Position = ArrayElement<typeof strings.POSITION_SET>;
52
53
  export interface PopupContainerDOMRect extends DOMRectLikeType {
@@ -79,6 +79,20 @@ export default class Tooltip extends BaseFoundation {
79
79
  this.calcPosition();
80
80
  });
81
81
 
82
+ if (trigger === "hover") {
83
+ const checkTriggerIsHover = () => {
84
+ const triggerDOM = this._adapter.getTriggerDOM();
85
+
86
+ if (trigger && !triggerDOM.matches(":hover")) {
87
+ this.hide();
88
+ }
89
+
90
+ this._adapter.off("portalInserted", checkTriggerIsHover);
91
+ };
92
+
93
+ this._adapter.on('portalInserted', checkTriggerIsHover);
94
+ }
95
+
82
96
  this._adapter.on('positionUpdated', () => {
83
97
  this._togglePortalVisible(true);
84
98
  });
@@ -278,6 +292,7 @@ export default class Tooltip extends BaseFoundation {
278
292
 
279
293
  this.unBindResizeEvent();
280
294
  this.unBindScrollEvent();
295
+ clearTimeout(this._timer);
281
296
  }
282
297
 
283
298
  _bindTriggerEvent(triggerEventSet) {
@@ -75,6 +75,6 @@ export declare function getValueOrKey(data: any): any;
75
75
  export declare function normalizeValue(value: any, withObject: boolean): any;
76
76
  export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
77
77
  export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;
78
- export declare function calcDropRelativePosition(event: any, treeNode: any): 0 | 1 | -1;
78
+ export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
79
79
  export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
80
80
  export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
@@ -18,7 +18,7 @@ declare const strings: {
18
18
  DRAG_AREA_ILLEGAL: string;
19
19
  TRIGGER_AUTO: "auto";
20
20
  TRIGGER_CUSTOM: "custom";
21
- UPLOAD_TRIGGER: ("custom" | "auto")[];
21
+ UPLOAD_TRIGGER: ("auto" | "custom")[];
22
22
  VALIDATE_STATUS: readonly ["default", "error", "warning", "success"];
23
23
  PROMPT_POSITION: readonly ["left", "right", "bottom"];
24
24
  };
@@ -57,8 +57,9 @@ export default class Event {
57
57
  return false;
58
58
  }
59
59
 
60
- this._eventMap.get(event).forEach(callback => callback(...args));
60
+ const callbacks = [...this._eventMap.get(event)]; // clone to avoid someone writing the logic of deleting callback in callbacks into his or her callback code, for example the once func above
61
61
 
62
+ callbacks.forEach(callback => callback(...args));
62
63
  return true;
63
64
  }
64
65
 
@@ -52,7 +52,9 @@ export default class SubNavFoundation<P = Record<string, any>, S = Record<string
52
52
  this._timer = null;
53
53
  }
54
54
 
55
- destroy() {} // eslint-disable-line
55
+ destroy() {
56
+ this.clearDelayTimer();
57
+ }
56
58
 
57
59
  clearDelayTimer() {
58
60
  if (this._timer) {
@@ -62,7 +64,6 @@ export default class SubNavFoundation<P = Record<string, any>, S = Record<string
62
64
  }
63
65
 
64
66
  isValidKey(itemKey: string | number) {
65
- // eslint-disable-next-line eqeqeq
66
67
  return itemKey != null && (typeof itemKey === 'number' || typeof itemKey === 'string');
67
68
  }
68
69
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.32.3",
3
+ "version": "2.32.5-alpha.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
@@ -23,7 +23,7 @@
23
23
  "*.scss",
24
24
  "*.css"
25
25
  ],
26
- "gitHead": "f0218cd43e7b3a8e9bc013b649ff308d8db2c876",
26
+ "gitHead": "6af4807f2242164d654659116f21e692d811ed08",
27
27
  "devDependencies": {
28
28
  "@babel/plugin-transform-runtime": "^7.15.8",
29
29
  "@babel/preset-env": "^7.15.8",
@@ -32,7 +32,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
32
32
  notifyVisibleChange(isVisible: any): void;
33
33
  getPopupContainerRect(): PopupContainerDOMRect;
34
34
  containerIsBody(): boolean;
35
- off(arg0: string): void;
35
+ off(arg0: string, arg1?: () => void): void;
36
36
  canMotion(): boolean;
37
37
  registerScrollHandler(arg: () => Record<string, any>): void;
38
38
  unregisterScrollHandler(): void;
@@ -68,7 +68,8 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
68
68
  setInitialFocus(): void;
69
69
  notifyEscKeydown(event: any): void;
70
70
  getTriggerNode(): any;
71
- setId(): void
71
+ setId(): void;
72
+ getTriggerDOM(): HTMLElement|null
72
73
  }
73
74
 
74
75
  export type Position = ArrayElement<typeof strings.POSITION_SET>;
@@ -115,6 +116,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
115
116
  this._adapter.unregisterClickOutsideHandler();
116
117
  this.unBindResizeEvent();
117
118
  this.unBindScrollEvent();
119
+ clearTimeout(this._timer);
118
120
  }
119
121
 
120
122
  _bindTriggerEvent(triggerEventSet: Record<string, any>) {
@@ -318,6 +320,17 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
318
320
  this.calcPosition();
319
321
  });
320
322
 
323
+ if (trigger==="hover") {
324
+ const checkTriggerIsHover = () => {
325
+ const triggerDOM = this._adapter.getTriggerDOM();
326
+ if (trigger && !triggerDOM.matches(":hover")) {
327
+ this.hide();
328
+ }
329
+ this._adapter.off("portalInserted", checkTriggerIsHover);
330
+ };
331
+ this._adapter.on('portalInserted', checkTriggerIsHover);
332
+ }
333
+
321
334
  this._adapter.on('positionUpdated', () => {
322
335
  this._togglePortalVisible(true);
323
336
  });
package/utils/Event.ts CHANGED
@@ -45,7 +45,9 @@ export default class Event {
45
45
  if (!this._eventMap.has(event)) {
46
46
  return false;
47
47
  }
48
- this._eventMap.get(event).forEach(callback => callback(...args));
48
+ const callbacks = [...this._eventMap.get(event)];
49
+ // clone to avoid someone writing the logic of deleting callback in callbacks into his or her callback code, for example the once func above
50
+ callbacks.forEach(callback => callback(...args));
49
51
  return true;
50
52
  }
51
53
  }