@douyinfe/semi-foundation 2.65.2-alpha.1 → 2.66.0-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.
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _get2 = _interopRequireDefault(require("lodash/get"));
8
- var _fastCopy = _interopRequireDefault(require("fast-copy"));
9
8
  var _foundation = _interopRequireDefault(require("../base/foundation"));
10
9
  var _constants = require("./constants");
10
+ var _fastCopy = _interopRequireDefault(require("fast-copy"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  const Boundary = _constants.strings.BOUNDARY_MAP;
13
13
  const OverflowDirection = _constants.strings.OVERFLOW_DIR;
@@ -39,7 +39,8 @@ class OverflowListFoundation extends _foundation.default {
39
39
  if (!this.isScrollMode()) {
40
40
  return overflow;
41
41
  }
42
- const visibleStateArr = items.map(_ref => {
42
+ const cloneItems = (0, _fastCopy.default)(items);
43
+ const visibleStateArr = cloneItems.map(_ref => {
43
44
  let {
44
45
  key
45
46
  } = _ref;
@@ -48,8 +49,8 @@ class OverflowListFoundation extends _foundation.default {
48
49
  const visibleStart = visibleStateArr.indexOf(true);
49
50
  const visibleEnd = visibleStateArr.lastIndexOf(true);
50
51
  const overflowList = [];
51
- overflowList[0] = visibleStart >= 0 ? items.slice(0, visibleStart) : [];
52
- overflowList[1] = visibleEnd >= 0 ? items.slice(visibleEnd + 1, items.length) : items.slice();
52
+ overflowList[0] = visibleStart >= 0 ? cloneItems.slice(0, visibleStart) : [];
53
+ overflowList[1] = visibleEnd >= 0 ? cloneItems.slice(visibleEnd + 1, cloneItems.length) : cloneItems;
53
54
  return overflowList;
54
55
  }
55
56
  handleIntersect(entries) {
@@ -49,6 +49,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
49
49
  getTriggerNode(): any;
50
50
  setId(): void;
51
51
  getTriggerDOM(): HTMLElement | null;
52
+ getAnimatingState(): boolean;
52
53
  }
53
54
  export type Position = ArrayElement<typeof strings.POSITION_SET>;
54
55
  export interface PopupContainerDOMRect extends DOMRectLikeType {
@@ -60,6 +60,9 @@ class Tooltip extends _foundation.default {
60
60
  }
61
61
  };
62
62
  this.show = () => {
63
+ if (this._adapter.getAnimatingState()) {
64
+ return;
65
+ }
63
66
  const content = this.getProp('content');
64
67
  const trigger = this.getProp('trigger');
65
68
  const clickTriggerToHide = this.getProp('clickTriggerToHide');
@@ -1,7 +1,7 @@
1
1
  import _get from "lodash/get";
2
- import copy from 'fast-copy';
3
2
  import BaseFoundation from '../base/foundation';
4
3
  import { strings } from './constants';
4
+ import copy from 'fast-copy';
5
5
  const Boundary = strings.BOUNDARY_MAP;
6
6
  const OverflowDirection = strings.OVERFLOW_DIR;
7
7
  class OverflowListFoundation extends BaseFoundation {
@@ -32,7 +32,8 @@ class OverflowListFoundation extends BaseFoundation {
32
32
  if (!this.isScrollMode()) {
33
33
  return overflow;
34
34
  }
35
- const visibleStateArr = items.map(_ref => {
35
+ const cloneItems = copy(items);
36
+ const visibleStateArr = cloneItems.map(_ref => {
36
37
  let {
37
38
  key
38
39
  } = _ref;
@@ -41,8 +42,8 @@ class OverflowListFoundation extends BaseFoundation {
41
42
  const visibleStart = visibleStateArr.indexOf(true);
42
43
  const visibleEnd = visibleStateArr.lastIndexOf(true);
43
44
  const overflowList = [];
44
- overflowList[0] = visibleStart >= 0 ? items.slice(0, visibleStart) : [];
45
- overflowList[1] = visibleEnd >= 0 ? items.slice(visibleEnd + 1, items.length) : items.slice();
45
+ overflowList[0] = visibleStart >= 0 ? cloneItems.slice(0, visibleStart) : [];
46
+ overflowList[1] = visibleEnd >= 0 ? cloneItems.slice(visibleEnd + 1, cloneItems.length) : cloneItems;
46
47
  return overflowList;
47
48
  }
48
49
  handleIntersect(entries) {
@@ -49,6 +49,7 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
49
49
  getTriggerNode(): any;
50
50
  setId(): void;
51
51
  getTriggerDOM(): HTMLElement | null;
52
+ getAnimatingState(): boolean;
52
53
  }
53
54
  export type Position = ArrayElement<typeof strings.POSITION_SET>;
54
55
  export interface PopupContainerDOMRect extends DOMRectLikeType {
@@ -53,6 +53,9 @@ export default class Tooltip extends BaseFoundation {
53
53
  }
54
54
  };
55
55
  this.show = () => {
56
+ if (this._adapter.getAnimatingState()) {
57
+ return;
58
+ }
56
59
  const content = this.getProp('content');
57
60
  const trigger = this.getProp('trigger');
58
61
  const clickTriggerToHide = this.getProp('clickTriggerToHide');
@@ -1,7 +1,7 @@
1
- import copy from 'fast-copy';
2
1
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
3
2
  import { strings } from './constants';
4
3
  import { get, cloneDeep } from 'lodash';
4
+ import copy from 'fast-copy';
5
5
 
6
6
  const Boundary = strings.BOUNDARY_MAP;
7
7
  const OverflowDirection = strings.OVERFLOW_DIR;
@@ -33,13 +33,15 @@ class OverflowListFoundation extends BaseFoundation<OverflowListAdapter> {
33
33
  return overflow;
34
34
  }
35
35
 
36
- const visibleStateArr = items.map(({ key }: { key: string }) => Boolean(visibleState.get(key)));
36
+ const cloneItems = copy(items);
37
+
38
+ const visibleStateArr = cloneItems.map(({ key }: { key: string }) => Boolean(visibleState.get(key)));
37
39
  const visibleStart = visibleStateArr.indexOf(true);
38
40
  const visibleEnd = visibleStateArr.lastIndexOf(true);
39
41
 
40
42
  const overflowList = [];
41
- overflowList[0] = visibleStart >= 0 ? items.slice(0, visibleStart) : [];
42
- overflowList[1] = visibleEnd >= 0 ? items.slice(visibleEnd + 1, items.length) : items.slice();
43
+ overflowList[0] = visibleStart >= 0 ? cloneItems.slice(0, visibleStart) : [];
44
+ overflowList[1] = visibleEnd >= 0 ? cloneItems.slice(visibleEnd + 1, cloneItems.length) : cloneItems;
43
45
  return overflowList;
44
46
  }
45
47
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.65.2-alpha.1",
3
+ "version": "2.66.0-alpha.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.65.2-alpha.1",
10
+ "@douyinfe/semi-animation": "2.66.0-alpha.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": "083b1f5da4743d7beb9565811c56eca5edabdbb4",
31
+ "gitHead": "0e7074a7bfa97bcab89ffe43127c4315c02b4c6b",
32
32
  "devDependencies": {
33
33
  "@babel/plugin-transform-runtime": "^7.15.8",
34
34
  "@babel/preset-env": "^7.15.8",
@@ -67,7 +67,8 @@ export interface TooltipAdapter<P = Record<string, any>, S = Record<string, any>
67
67
  notifyEscKeydown(event: any): void;
68
68
  getTriggerNode(): any;
69
69
  setId(): void;
70
- getTriggerDOM(): HTMLElement|null
70
+ getTriggerDOM(): HTMLElement|null;
71
+ getAnimatingState(): boolean
71
72
  }
72
73
 
73
74
  export type Position = ArrayElement<typeof strings.POSITION_SET>;
@@ -180,7 +181,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
180
181
  _reducePos(position = '') {
181
182
  // if cur position consists of two directions, remove the last position
182
183
  const found = ['Top', 'Bottom', 'Left', 'Right'].find(pos => position.endsWith(pos));
183
- return found ? position.replace(found, ''): position;
184
+ return found ? position.replace(found, '') : position;
184
185
  }
185
186
 
186
187
  clearDelayTimer() {
@@ -311,6 +312,9 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
311
312
  };
312
313
 
313
314
  show = () => {
315
+ if (this._adapter.getAnimatingState()) {
316
+ return;
317
+ }
314
318
  const content = this.getProp('content');
315
319
  const trigger = this.getProp('trigger');
316
320
 
@@ -334,7 +338,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
334
338
  this.calcPosition();
335
339
  });
336
340
 
337
- if (trigger==="hover") {
341
+ if (trigger === "hover") {
338
342
  const checkTriggerIsHover = () => {
339
343
  const triggerDOM = this._adapter.getTriggerDOM();
340
344
  if (trigger && !triggerDOM?.matches?.(":hover")) {
@@ -474,13 +478,13 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
474
478
  const isWrapperWidthOverflow = wrapperRect.width > innerWidth;
475
479
  const scaled = Math.abs(wrapperRect?.width - this._adapter.getContainer()?.clientWidth) > 1;
476
480
  if (scaled) {
477
- SPACING = SPACING * wrapperRect.width/this._adapter.getContainer().clientWidth;
481
+ SPACING = SPACING * wrapperRect.width / this._adapter.getContainer().clientWidth;
478
482
  }
479
483
  switch (position) {
480
484
  case 'top':
481
485
  // left = middleX;
482
486
  // top = triggerRect.top - SPACING;
483
- left = isWidthOverFlow ? (isTriggerNearLeft ? containerRect.left + wrapperRect.width / 2 : containerRect.right - wrapperRect.width / 2 + offsetWidth): middleX + ANO_SPACING;
487
+ left = isWidthOverFlow ? (isTriggerNearLeft ? containerRect.left + wrapperRect.width / 2 : containerRect.right - wrapperRect.width / 2 + offsetWidth) : middleX + ANO_SPACING;
484
488
  top = isHeightOverFlow ? containerRect.bottom + offsetHeight : triggerRect.top - SPACING;
485
489
  translateX = -0.5;
486
490
  translateY = -1;
@@ -505,7 +509,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
505
509
  // top = middleY;
506
510
  // left = isWidthOverFlow? containerRect.right - SPACING : triggerRect.left - SPACING;
507
511
  left = isWidthOverFlow ? containerRect.right + offsetWidth - SPACING + offsetXWithArrow : triggerRect.left - SPACING;
508
- top = isHeightOverFlow ? (isTriggerNearTop ? containerRect.top + wrapperRect.height / 2 : containerRect.bottom - wrapperRect.height / 2 + offsetHeight): middleY + ANO_SPACING;
512
+ top = isHeightOverFlow ? (isTriggerNearTop ? containerRect.top + wrapperRect.height / 2 : containerRect.bottom - wrapperRect.height / 2 + offsetHeight) : middleY + ANO_SPACING;
509
513
  translateX = -1;
510
514
  translateY = -0.5;
511
515
  break;
@@ -519,22 +523,22 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
519
523
  case 'leftBottom':
520
524
  // left = triggerRect.left - SPACING;
521
525
  // top = pointAtCenter ? middleY + offsetYWithArrow : triggerRect.bottom;
522
- left = isWidthOverFlow ? containerRect.right + offsetWidth - SPACING + offsetXWithArrow: triggerRect.left - SPACING;
523
- top = isHeightOverFlow ? containerRect.bottom + offsetHeight: (pointAtCenter ? middleY + offsetYWithArrow + ANO_SPACING : triggerRect.bottom + ANO_SPACING);
526
+ left = isWidthOverFlow ? containerRect.right + offsetWidth - SPACING + offsetXWithArrow : triggerRect.left - SPACING;
527
+ top = isHeightOverFlow ? containerRect.bottom + offsetHeight : (pointAtCenter ? middleY + offsetYWithArrow + ANO_SPACING : triggerRect.bottom + ANO_SPACING);
524
528
  translateX = -1;
525
529
  translateY = -1;
526
530
  break;
527
531
  case 'bottom':
528
532
  // left = middleX;
529
533
  // top = triggerRect.top + triggerRect.height + SPACING;
530
- left = isWidthOverFlow ? (isTriggerNearLeft ? containerRect.left + wrapperRect.width / 2 : containerRect.right - wrapperRect.width / 2 + offsetWidth): middleX + ANO_SPACING;
531
- top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING: triggerRect.top + triggerRect.height + SPACING;
534
+ left = isWidthOverFlow ? (isTriggerNearLeft ? containerRect.left + wrapperRect.width / 2 : containerRect.right - wrapperRect.width / 2 + offsetWidth) : middleX + ANO_SPACING;
535
+ top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING : triggerRect.top + triggerRect.height + SPACING;
532
536
  translateX = -0.5;
533
537
  break;
534
538
  case 'bottomLeft':
535
539
  // left = pointAtCenter ? middleX - offsetXWithArrow : triggerRect.left;
536
540
  // top = triggerRect.bottom + SPACING;
537
- left = isWidthOverFlow ? (isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width ) : (pointAtCenter ? middleX - offsetXWithArrow + ANO_SPACING: triggerRect.left + ANO_SPACING);
541
+ left = isWidthOverFlow ? (isWrapperWidthOverflow ? containerRect.left : containerRect.right - wrapperRect.width ) : (pointAtCenter ? middleX - offsetXWithArrow + ANO_SPACING : triggerRect.left + ANO_SPACING);
538
542
  top = isHeightOverFlow ? containerRect.top + offsetYWithArrow - SPACING : triggerRect.top + triggerRect.height + SPACING;
539
543
  break;
540
544
  case 'bottomRight':
@@ -596,11 +600,11 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
596
600
  top = top - containerRect.top;
597
601
 
598
602
  if (scaled) {
599
- left /= wrapperRect.width/this._adapter.getContainer().clientWidth;
603
+ left /= wrapperRect.width / this._adapter.getContainer().clientWidth;
600
604
  }
601
605
 
602
606
  if (scaled) {
603
- top /= wrapperRect.height/this._adapter.getContainer().clientHeight;
607
+ top /= wrapperRect.height / this._adapter.getContainer().clientHeight;
604
608
  }
605
609
 
606
610
  /**
@@ -820,7 +824,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
820
824
  const shouldViewReverseLeft = clientLeft - marginLeft < wrapperRect.width + spacing && restClientRight - marginRight > wrapperRect.width + spacing;
821
825
  const shouldViewReverseBottom = restClientBottom - marginBottom < wrapperRect.height + spacing && clientTop - marginTop > wrapperRect.height + spacing;
822
826
  const shouldViewReverseRight = restClientRight - marginRight < wrapperRect.width + spacing && clientLeft - marginLeft > wrapperRect.width + spacing;
823
- const shouldViewReverseTopOver = restClientTop - marginBottom< wrapperRect.height + spacing && clientBottom - marginTop> wrapperRect.height + spacing;
827
+ const shouldViewReverseTopOver = restClientTop - marginBottom < wrapperRect.height + spacing && clientBottom - marginTop > wrapperRect.height + spacing;
824
828
  const shouldViewReverseBottomOver = clientBottom - marginTop < wrapperRect.height + spacing && restClientTop - marginBottom > wrapperRect.height + spacing;
825
829
 
826
830
  const shouldViewReverseTopSide = restClientTop < wrapperRect.height + ano_spacing && clientBottom > wrapperRect.height + ano_spacing;