@douyinfe/semi-foundation 2.22.0-alpha.0 → 2.22.0-beta.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.
Files changed (79) hide show
  1. package/autoComplete/foundation.ts +3 -1
  2. package/base/foundation.ts +7 -0
  3. package/checkbox/checkboxFoundation.ts +10 -32
  4. package/form/utils.ts +1 -0
  5. package/image/previewImageFoundation.ts +34 -12
  6. package/image/previewInnerFoundation.ts +2 -2
  7. package/input/textareaFoundation.ts +6 -5
  8. package/inputNumber/foundation.ts +2 -2
  9. package/lib/cjs/autoComplete/foundation.d.ts +1 -0
  10. package/lib/cjs/autoComplete/foundation.js +3 -1
  11. package/lib/cjs/base/foundation.d.ts +3 -0
  12. package/lib/cjs/base/foundation.js +7 -1
  13. package/lib/cjs/checkbox/checkboxFoundation.d.ts +5 -14
  14. package/lib/cjs/checkbox/checkboxFoundation.js +3 -25
  15. package/lib/cjs/form/utils.js +1 -0
  16. package/lib/cjs/image/previewImageFoundation.d.ts +5 -4
  17. package/lib/cjs/image/previewImageFoundation.js +34 -11
  18. package/lib/cjs/image/previewInnerFoundation.js +2 -2
  19. package/lib/cjs/input/textareaFoundation.d.ts +1 -1
  20. package/lib/cjs/input/textareaFoundation.js +5 -3
  21. package/lib/cjs/inputNumber/foundation.js +4 -2
  22. package/lib/cjs/navigation/navigation.css +4 -0
  23. package/lib/cjs/navigation/navigation.scss +6 -0
  24. package/lib/cjs/rating/foundation.d.ts +2 -2
  25. package/lib/cjs/rating/foundation.js +6 -4
  26. package/lib/cjs/select/select.scss +1 -1
  27. package/lib/cjs/slider/foundation.d.ts +2 -6
  28. package/lib/cjs/slider/foundation.js +4 -4
  29. package/lib/cjs/table/foundation.d.ts +12 -0
  30. package/lib/cjs/table/foundation.js +56 -11
  31. package/lib/cjs/timePicker/timePicker.css +8 -0
  32. package/lib/cjs/timePicker/timePicker.scss +16 -0
  33. package/lib/cjs/timePicker/variables.scss +1 -0
  34. package/lib/cjs/tooltip/constants.d.ts +0 -1
  35. package/lib/cjs/tooltip/constants.js +2 -2
  36. package/lib/cjs/tooltip/foundation.d.ts +2 -11
  37. package/lib/cjs/tooltip/foundation.js +43 -218
  38. package/lib/cjs/upload/foundation.js +1 -0
  39. package/lib/es/autoComplete/foundation.d.ts +1 -0
  40. package/lib/es/autoComplete/foundation.js +3 -1
  41. package/lib/es/base/foundation.d.ts +3 -0
  42. package/lib/es/base/foundation.js +7 -1
  43. package/lib/es/checkbox/checkboxFoundation.d.ts +5 -14
  44. package/lib/es/checkbox/checkboxFoundation.js +3 -25
  45. package/lib/es/form/utils.js +1 -0
  46. package/lib/es/image/previewImageFoundation.d.ts +5 -4
  47. package/lib/es/image/previewImageFoundation.js +33 -11
  48. package/lib/es/image/previewInnerFoundation.js +2 -2
  49. package/lib/es/input/textareaFoundation.d.ts +1 -1
  50. package/lib/es/input/textareaFoundation.js +5 -3
  51. package/lib/es/inputNumber/foundation.js +4 -2
  52. package/lib/es/navigation/navigation.css +4 -0
  53. package/lib/es/navigation/navigation.scss +6 -0
  54. package/lib/es/rating/foundation.d.ts +2 -2
  55. package/lib/es/rating/foundation.js +6 -4
  56. package/lib/es/select/select.scss +1 -1
  57. package/lib/es/slider/foundation.d.ts +2 -6
  58. package/lib/es/slider/foundation.js +4 -4
  59. package/lib/es/table/foundation.d.ts +12 -0
  60. package/lib/es/table/foundation.js +55 -11
  61. package/lib/es/timePicker/timePicker.css +8 -0
  62. package/lib/es/timePicker/timePicker.scss +16 -0
  63. package/lib/es/timePicker/variables.scss +1 -0
  64. package/lib/es/tooltip/constants.d.ts +0 -1
  65. package/lib/es/tooltip/constants.js +2 -2
  66. package/lib/es/tooltip/foundation.d.ts +2 -11
  67. package/lib/es/tooltip/foundation.js +43 -218
  68. package/lib/es/upload/foundation.js +1 -0
  69. package/navigation/navigation.scss +6 -0
  70. package/package.json +2 -2
  71. package/rating/foundation.ts +4 -2
  72. package/select/select.scss +1 -1
  73. package/slider/foundation.ts +6 -6
  74. package/table/foundation.ts +43 -11
  75. package/timePicker/timePicker.scss +16 -0
  76. package/timePicker/variables.scss +1 -0
  77. package/tooltip/constants.ts +0 -1
  78. package/tooltip/foundation.ts +41 -213
  79. package/upload/foundation.ts +2 -0
@@ -39,6 +39,7 @@ export interface AutoCompleteAdapter<P = Record<string, any>, S = Record<string,
39
39
  notifyFocus: (event?: any) => void;
40
40
  notifyBlur: (event?: any) => void;
41
41
  rePositionDropdown: () => void;
42
+ persistEvent: (event: any) => void;
42
43
  }
43
44
 
44
45
  class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<AutoCompleteAdapter<P, S>, P, S> {
@@ -416,8 +417,9 @@ class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> e
416
417
  }
417
418
 
418
419
  handleBlur(e: any) {
420
+ // only need persist on react adapter
419
421
  // https://reactjs.org/docs/legacy-event-pooling.html
420
- e.persist();
422
+ this._persistEvent(e);
421
423
  // In order to handle the problem of losing onClick binding when clicking on the padding area, the onBlur event is triggered first to cause the react view to be updated
422
424
  // internal-issues:1231
423
425
  setTimeout(() => {
@@ -21,6 +21,7 @@ export interface DefaultAdapter<P = Record<string, any>, S = Record<string, any>
21
21
  getCaches(): any;
22
22
  setCache(key: any, value: any): void;
23
23
  stopPropagation(e: any): void;
24
+ persistEvent: (event: any) => void;
24
25
  }
25
26
 
26
27
  class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string, any>, S = Record<string, any>> {
@@ -61,6 +62,7 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
61
62
  setCache: noop,
62
63
  getCaches: noop,
63
64
  stopPropagation: noop,
65
+ persistEvent: noop,
64
66
  };
65
67
  }
66
68
 
@@ -141,5 +143,10 @@ class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string,
141
143
  log(text: string, ...rest: any) {
142
144
  log(text, ...rest);
143
145
  }
146
+
147
+ _persistEvent(e: any) {
148
+ // only work for react adapter for now
149
+ this._adapter.persistEvent(e);
150
+ }
144
151
  }
145
152
  export default BaseFoundation;
@@ -10,22 +10,24 @@ export interface BasicCheckboxEvent {
10
10
  target: BasicTargetObject;
11
11
  stopPropagation: () => void;
12
12
  preventDefault: () => void;
13
- nativeEvent: {
14
- stopImmediatePropagation: () => void;
15
- }
13
+ [x: string]: any;
14
+ // nativeEvent: {
15
+ // stopImmediatePropagation: () => void;
16
+ // }
16
17
  }
17
18
  export interface CheckboxAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
18
19
  getIsInGroup: () => boolean;
19
20
  getGroupValue: () => any[];
20
- notifyGroupChange: (event: BasicCheckboxEvent) => void;
21
+ notifyGroupChange: (e: any) => void;
21
22
  getGroupDisabled: () => boolean;
22
23
  setNativeControlChecked: (checked: boolean) => void;
23
24
  getState: noopFunction;
24
- notifyChange: (event: BasicCheckboxEvent) => void;
25
+ notifyChange: (e: any) => void;
25
26
  setAddonId: () => void;
26
27
  setExtraId: () => void;
27
28
  setFocusVisible: (focusVisible: boolean) => void;
28
29
  focusCheckboxEntity: () => void;
30
+ generateEvent: (checked: boolean, e: any) => any; // 1.modify checked value 2.add nativeEvent on react adapter
29
31
  }
30
32
 
31
33
  class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<CheckboxAdapter<P, S>, P, S> {
@@ -46,32 +48,8 @@ class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> exten
46
48
  }
47
49
  }
48
50
 
49
- getEvent(checked: boolean, e: any) {
50
- const props = this.getProps();
51
- const cbValue = {
52
- target: {
53
- ...props,
54
- checked,
55
- },
56
- stopPropagation: () => {
57
- e.stopPropagation();
58
- },
59
- preventDefault: () => {
60
- e.preventDefault();
61
- },
62
- nativeEvent: {
63
- stopImmediatePropagation: () => {
64
- if (e.nativeEvent && typeof e.nativeEvent.stopImmediatePropagation === 'function') {
65
- e.nativeEvent.stopImmediatePropagation();
66
- }
67
- }
68
- },
69
- };
70
- return cbValue;
71
- }
72
-
73
51
  notifyChange(checked: boolean, e: any) {
74
- const cbValue = this.getEvent(checked, e);
52
+ const cbValue = this._adapter.generateEvent(checked, e);
75
53
  this._adapter.notifyChange(cbValue);
76
54
  }
77
55
 
@@ -114,7 +92,7 @@ class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> exten
114
92
  const groupValue = this._adapter.getGroupValue();
115
93
  const checked = groupValue.includes(value);
116
94
  const newChecked = !checked;
117
- const event = this.getEvent(newChecked, e);
95
+ const event = this._adapter.generateEvent(newChecked, e);
118
96
  this._adapter.notifyChange(event);
119
97
  this._adapter.notifyGroupChange(event);
120
98
  }
@@ -160,7 +138,7 @@ export interface BaseCheckboxProps {
160
138
  defaultChecked?: boolean;
161
139
  disabled?: boolean;
162
140
  indeterminate?: boolean;
163
- onChange?: (e: BasicCheckboxEvent) => any;
141
+ onChange?: (e: any) => any;
164
142
  value?: any;
165
143
  style?: Record<string, any>;
166
144
  className?: string;
package/form/utils.ts CHANGED
@@ -47,6 +47,7 @@ export function isValid(errors: any): boolean {
47
47
  errors.$$typeof.toString() === 'Symbol(react.element)'
48
48
  ) {
49
49
  // when error message is reactNode
50
+ // only work with React Adapter
50
51
  valid = false;
51
52
  }
52
53
  return valid;
@@ -5,13 +5,14 @@ import { throttle, isUndefined } from "lodash";
5
5
  export interface PreviewImageAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
6
6
  getOriginImageSize: () => { originImageWidth: number; originImageHeight: number; };
7
7
  setOriginImageSize: (size: { originImageWidth: number; originImageHeight: number; }) => void;
8
- getContainerRef: () => any;
9
- getImageRef: () => any;
8
+ getContainer: () => HTMLDivElement;
9
+ getImage: () => HTMLImageElement;
10
10
  getMouseMove: () => boolean;
11
11
  setStartMouseMove: (move: boolean) => void;
12
12
  getMouseOffset: () => { x: number; y: number };
13
13
  setStartMouseOffset: (offset: { x: number; y: number }) => void;
14
14
  setLoading: (loading: boolean) => void;
15
+ setImageCursor: (canDrag: boolean) => void;
15
16
  }
16
17
 
17
18
  export interface DragDirection {
@@ -29,6 +30,17 @@ export interface ImageOffset {
29
30
  y: number;
30
31
  }
31
32
 
33
+ const DefaultDOMRect = {
34
+ bottom: 0,
35
+ height: 0,
36
+ left: 0,
37
+ right: 0,
38
+ top: 0,
39
+ width: 0,
40
+ x: 0,
41
+ y: 0,
42
+ toJSON: () => ({})
43
+ };
32
44
  export default class PreviewImageFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewImageAdapter<P, S>, P, S> {
33
45
  constructor(adapter: PreviewImageAdapter<P, S>) {
34
46
  super({ ...adapter });
@@ -37,13 +49,19 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
37
49
  _isImageVertical = (): boolean => this.getProp("rotation") % 180 !== 0;
38
50
 
39
51
  _getImageBounds = (): DOMRect => {
40
- const imageRef = this._adapter.getImageRef();
41
- return imageRef?.getBoundingClientRect();
52
+ const imageDOM = this._adapter.getImage();
53
+ if (imageDOM) {
54
+ return imageDOM.getBoundingClientRect();
55
+ }
56
+ return DefaultDOMRect;
42
57
  };
43
58
 
44
59
  _getContainerBounds = (): DOMRect => {
45
- const containerRef = this._adapter.getContainerRef();
46
- return containerRef?.current?.getBoundingClientRect();
60
+ const containerDOM = this._adapter.getContainer();
61
+ if (containerDOM) {
62
+ return containerDOM.getBoundingClientRect();
63
+ }
64
+ return DefaultDOMRect;
47
65
  }
48
66
 
49
67
  _getOffset = (e: any): ImageOffset => {
@@ -98,8 +116,8 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
98
116
  const imgWidth = horizontal ? originImageWidth : originImageHeight;
99
117
  const imgHeight = horizontal ? originImageHeight : originImageWidth;
100
118
  const { onZoom } = this.getProps();
101
- const containerRef = this._adapter.getContainerRef();
102
- if (containerRef && containerRef.current) {
119
+ const containerDOM = this._adapter.getContainer();
120
+ if (containerDOM) {
103
121
  const { width: containerWidth, height: containerHeight } = this._getContainerBounds();
104
122
  const reservedWidth = containerWidth - 80;
105
123
  const reservedHeight = containerHeight - 80;
@@ -121,12 +139,14 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
121
139
  }
122
140
  };
123
141
 
124
- handleWheel = (e: React.WheelEvent<HTMLImageElement>) => {
142
+ // e: WheelEvent<HTMLImageElement>
143
+ handleWheel = (e: any) => {
125
144
  this.onWheel(e);
126
145
  handlePrevent(e);
127
146
  }
128
147
 
129
- onWheel = throttle((e: React.WheelEvent<HTMLImageElement>): void => {
148
+ // e: WheelEvent<HTMLImageElement>
149
+ onWheel = throttle((e: any): void => {
130
150
  const { onZoom, zoomStep, maxZoom, minZoom } = this.getProps();
131
151
  const { currZoom } = this.getStates();
132
152
  let _zoom:number;
@@ -163,7 +183,7 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
163
183
  };
164
184
 
165
185
  handleZoomChange = (newZoom: number, e: any): void => {
166
- const imageRef = this._adapter.getImageRef();
186
+ const imageDOM = this._adapter.getImage();
167
187
  const { originImageWidth, originImageHeight } = this._adapter.getOriginImageSize();
168
188
  const { canDragVertical, canDragHorizontal } = this.calcCanDragDirection();
169
189
  const canDrag = canDragVertical || canDragHorizontal;
@@ -201,7 +221,9 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
201
221
  top: newTop,
202
222
  currZoom: newZoom,
203
223
  } as any);
204
- imageRef && (imageRef.style.cursor = canDrag ? "grab" : "default");
224
+ if (imageDOM) {
225
+ this._adapter.setImageCursor(canDrag);
226
+ }
205
227
  };
206
228
 
207
229
  calcExtremeBounds = (): ExtremeBounds => {
@@ -57,7 +57,7 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
57
57
  }
58
58
 
59
59
  handleMouseMoveEvent = (e: any, event: string) => {
60
- const isTarget = isTargetEmit(e.nativeEvent, STOP_CLOSE_TARGET);
60
+ const isTarget = isTargetEmit(e, STOP_CLOSE_TARGET);
61
61
  if (isTarget && event === "over") {
62
62
  this._adapter.setStopTiming(true);
63
63
  } else if (isTarget && event === "out") {
@@ -74,7 +74,7 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
74
74
 
75
75
  handleMouseUp = (e: any) => {
76
76
  const { maskClosable } = this.getProps();
77
- let couldClose = !isTargetEmit(e.nativeEvent, NOT_CLOSE_TARGETS);
77
+ let couldClose = !isTargetEmit(e, NOT_CLOSE_TARGETS);
78
78
  const { clientX, clientY } = e;
79
79
  const { x, y } = this._adapter.getStartMouseDown();
80
80
  // 对鼠标移动做容错处理,当 x 和 y 方向在 mouseUp 的时候移动距离都小于等于 5px 时候就可以关闭预览
@@ -7,7 +7,6 @@ import {
7
7
  } from 'lodash';
8
8
  import calculateNodeHeight from './util/calculateNodeHeight';
9
9
  import getSizingData from './util/getSizingData';
10
- import isEnterPress from '../utils/isEnterPress';
11
10
 
12
11
  export interface TextAreaDefaultAdapter {
13
12
  notifyChange: noopFunction;
@@ -24,7 +23,7 @@ export interface TextAreaDefaultAdapter {
24
23
  export interface TextAreaAdapter extends Partial<DefaultAdapter>, Partial<TextAreaDefaultAdapter> {
25
24
  setMinLength(length: number): void;
26
25
  notifyPressEnter(e: any): void;
27
- getRef(): any;
26
+ getRef(): HTMLInputElement;
28
27
  notifyHeightUpdate(e: any): void;
29
28
  }
30
29
 
@@ -175,7 +174,7 @@ export default class TextAreaFoundation extends BaseFoundation<TextAreaAdapter>
175
174
  resizeTextarea = (cb?: any) => {
176
175
  const { height } = this.getStates();
177
176
  const { rows } = this.getProps();
178
- const node = this._adapter.getRef().current;
177
+ const node = this._adapter.getRef();
179
178
  const nodeSizingData = getSizingData(node);
180
179
 
181
180
  if (!nodeSizingData) {
@@ -199,11 +198,13 @@ export default class TextAreaFoundation extends BaseFoundation<TextAreaAdapter>
199
198
  cb && cb();
200
199
  };
201
200
 
202
- handleMouseEnter(e) {
201
+ // e: MouseEvent
202
+ handleMouseEnter(e: any) {
203
203
  this._adapter.toggleHovering(true);
204
204
  }
205
205
 
206
- handleMouseLeave(e) {
206
+ // e: MouseEvent
207
+ handleMouseLeave(e: any) {
207
208
  this._adapter.toggleHovering(false);
208
209
  }
209
210
 
@@ -300,7 +300,7 @@ class InputNumberFoundation extends BaseFoundation<InputNumberAdapter> {
300
300
  }
301
301
  this._adapter.setClickUpOrDown(true);
302
302
  if (event) {
303
- event.persist();
303
+ this._persistEvent(event);
304
304
  event.stopPropagation();
305
305
  // Prevent native blurring events
306
306
  this._preventDefault(event);
@@ -321,7 +321,7 @@ class InputNumberFoundation extends BaseFoundation<InputNumberAdapter> {
321
321
  }
322
322
  this._adapter.setClickUpOrDown(true);
323
323
  if (event) {
324
- event.persist();
324
+ this._persistEvent(event);
325
325
  event.stopPropagation();
326
326
  this._preventDefault(event);
327
327
  }
@@ -30,6 +30,7 @@ export interface AutoCompleteAdapter<P = Record<string, any>, S = Record<string,
30
30
  notifyFocus: (event?: any) => void;
31
31
  notifyBlur: (event?: any) => void;
32
32
  rePositionDropdown: () => void;
33
+ persistEvent: (event: any) => void;
33
34
  }
34
35
  declare class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<AutoCompleteAdapter<P, S>, P, S> {
35
36
  private _keydownHandler;
@@ -499,10 +499,12 @@ class AutoCompleteFoundation extends _foundation.default {
499
499
  }
500
500
 
501
501
  handleBlur(e) {
502
+ // only need persist on react adapter
502
503
  // https://reactjs.org/docs/legacy-event-pooling.html
503
- e.persist(); // In order to handle the problem of losing onClick binding when clicking on the padding area, the onBlur event is triggered first to cause the react view to be updated
504
+ this._persistEvent(e); // In order to handle the problem of losing onClick binding when clicking on the padding area, the onBlur event is triggered first to cause the react view to be updated
504
505
  // internal-issues:1231
505
506
 
507
+
506
508
  setTimeout(() => {
507
509
  this._adapter.notifyBlur(e);
508
510
 
@@ -16,6 +16,7 @@ export interface DefaultAdapter<P = Record<string, any>, S = Record<string, any>
16
16
  getCaches(): any;
17
17
  setCache(key: any, value: any): void;
18
18
  stopPropagation(e: any): void;
19
+ persistEvent: (event: any) => void;
19
20
  }
20
21
  declare class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record<string, any>, S = Record<string, any>> {
21
22
  /** @return enum{css className} */
@@ -36,6 +37,7 @@ declare class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record
36
37
  setCache: (...args: any[]) => void;
37
38
  getCaches: (...args: any[]) => void;
38
39
  stopPropagation: (...args: any[]) => void;
40
+ persistEvent: (...args: any[]) => void;
39
41
  };
40
42
  _adapter: T;
41
43
  constructor(adapter: T);
@@ -55,5 +57,6 @@ declare class BaseFoundation<T extends Partial<DefaultAdapter<P, S>>, P = Record
55
57
  init(lifecycle?: any): void;
56
58
  destroy(): void;
57
59
  log(text: string, ...rest: any): void;
60
+ _persistEvent(e: any): void;
58
61
  }
59
62
  export default BaseFoundation;
@@ -63,7 +63,8 @@ class BaseFoundation {
63
63
  getCache: _noop2.default,
64
64
  setCache: _noop2.default,
65
65
  getCaches: _noop2.default,
66
- stopPropagation: _noop2.default
66
+ stopPropagation: _noop2.default,
67
+ persistEvent: _noop2.default
67
68
  };
68
69
  }
69
70
 
@@ -145,6 +146,11 @@ class BaseFoundation {
145
146
  (0, _log.default)(text, ...rest);
146
147
  }
147
148
 
149
+ _persistEvent(e) {
150
+ // only work for react adapter for now
151
+ this._adapter.persistEvent(e);
152
+ }
153
+
148
154
  }
149
155
 
150
156
  var _default = BaseFoundation;
@@ -7,35 +7,26 @@ export interface BasicCheckboxEvent {
7
7
  target: BasicTargetObject;
8
8
  stopPropagation: () => void;
9
9
  preventDefault: () => void;
10
- nativeEvent: {
11
- stopImmediatePropagation: () => void;
12
- };
10
+ [x: string]: any;
13
11
  }
14
12
  export interface CheckboxAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
15
13
  getIsInGroup: () => boolean;
16
14
  getGroupValue: () => any[];
17
- notifyGroupChange: (event: BasicCheckboxEvent) => void;
15
+ notifyGroupChange: (e: any) => void;
18
16
  getGroupDisabled: () => boolean;
19
17
  setNativeControlChecked: (checked: boolean) => void;
20
18
  getState: noopFunction;
21
- notifyChange: (event: BasicCheckboxEvent) => void;
19
+ notifyChange: (e: any) => void;
22
20
  setAddonId: () => void;
23
21
  setExtraId: () => void;
24
22
  setFocusVisible: (focusVisible: boolean) => void;
25
23
  focusCheckboxEntity: () => void;
24
+ generateEvent: (checked: boolean, e: any) => any;
26
25
  }
27
26
  declare class CheckboxFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<CheckboxAdapter<P, S>, P, S> {
28
27
  constructor(adapter: CheckboxAdapter<P, S>);
29
28
  clickState: boolean;
30
29
  init(): void;
31
- getEvent(checked: boolean, e: any): {
32
- target: any;
33
- stopPropagation: () => void;
34
- preventDefault: () => void;
35
- nativeEvent: {
36
- stopImmediatePropagation: () => void;
37
- };
38
- };
39
30
  notifyChange(checked: boolean, e: any): void;
40
31
  handleChange(e: any): void;
41
32
  handleChangeInGroup(e: any): void;
@@ -52,7 +43,7 @@ export interface BaseCheckboxProps {
52
43
  defaultChecked?: boolean;
53
44
  disabled?: boolean;
54
45
  indeterminate?: boolean;
55
- onChange?: (e: BasicCheckboxEvent) => any;
46
+ onChange?: (e: any) => any;
56
47
  value?: any;
57
48
  style?: Record<string, any>;
58
49
  className?: string;
@@ -61,31 +61,8 @@ class CheckboxFoundation extends _foundation.default {
61
61
  }
62
62
  }
63
63
 
64
- getEvent(checked, e) {
65
- const props = this.getProps();
66
- const cbValue = {
67
- target: Object.assign(Object.assign({}, props), {
68
- checked
69
- }),
70
- stopPropagation: () => {
71
- e.stopPropagation();
72
- },
73
- preventDefault: () => {
74
- e.preventDefault();
75
- },
76
- nativeEvent: {
77
- stopImmediatePropagation: () => {
78
- if (e.nativeEvent && typeof e.nativeEvent.stopImmediatePropagation === 'function') {
79
- e.nativeEvent.stopImmediatePropagation();
80
- }
81
- }
82
- }
83
- };
84
- return cbValue;
85
- }
86
-
87
64
  notifyChange(checked, e) {
88
- const cbValue = this.getEvent(checked, e);
65
+ const cbValue = this._adapter.generateEvent(checked, e);
89
66
 
90
67
  this._adapter.notifyChange(cbValue);
91
68
  }
@@ -135,7 +112,8 @@ class CheckboxFoundation extends _foundation.default {
135
112
 
136
113
  const checked = groupValue.includes(value);
137
114
  const newChecked = !checked;
138
- const event = this.getEvent(newChecked, e);
115
+
116
+ const event = this._adapter.generateEvent(newChecked, e);
139
117
 
140
118
  this._adapter.notifyChange(event);
141
119
 
@@ -76,6 +76,7 @@ function isValid(errors) {
76
76
  valid = errors;
77
77
  } else if (errors && typeof errors.$$typeof === 'symbol' && errors.$$typeof.toString() === 'Symbol(react.element)') {
78
78
  // when error message is reactNode
79
+ // only work with React Adapter
79
80
  valid = false;
80
81
  }
81
82
 
@@ -9,8 +9,8 @@ export interface PreviewImageAdapter<P = Record<string, any>, S = Record<string,
9
9
  originImageWidth: number;
10
10
  originImageHeight: number;
11
11
  }) => void;
12
- getContainerRef: () => any;
13
- getImageRef: () => any;
12
+ getContainer: () => HTMLDivElement;
13
+ getImage: () => HTMLImageElement;
14
14
  getMouseMove: () => boolean;
15
15
  setStartMouseMove: (move: boolean) => void;
16
16
  getMouseOffset: () => {
@@ -22,6 +22,7 @@ export interface PreviewImageAdapter<P = Record<string, any>, S = Record<string,
22
22
  y: number;
23
23
  }) => void;
24
24
  setLoading: (loading: boolean) => void;
25
+ setImageCursor: (canDrag: boolean) => void;
25
26
  }
26
27
  export interface DragDirection {
27
28
  canDragVertical: boolean;
@@ -47,8 +48,8 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
47
48
  handleError: (e: any) => void;
48
49
  handleResizeImage: () => void;
49
50
  handleRightClickImage: (e: any) => boolean;
50
- handleWheel: (e: React.WheelEvent<HTMLImageElement>) => void;
51
- onWheel: import("lodash").DebouncedFunc<(e: React.WheelEvent<HTMLImageElement>) => void>;
51
+ handleWheel: (e: any) => void;
52
+ onWheel: import("lodash").DebouncedFunc<(e: any) => void>;
52
53
  calcCanDragDirection: () => DragDirection;
53
54
  handleZoomChange: (newZoom: number, e: any) => void;
54
55
  calcExtremeBounds: () => ExtremeBounds;
@@ -15,6 +15,18 @@ var _a11y = require("../utils/a11y");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
+ const DefaultDOMRect = {
19
+ bottom: 0,
20
+ height: 0,
21
+ left: 0,
22
+ right: 0,
23
+ top: 0,
24
+ width: 0,
25
+ x: 0,
26
+ y: 0,
27
+ toJSON: () => ({})
28
+ };
29
+
18
30
  class PreviewImageFoundation extends _foundation.default {
19
31
  constructor(adapter) {
20
32
  super(Object.assign({}, adapter));
@@ -22,17 +34,23 @@ class PreviewImageFoundation extends _foundation.default {
22
34
  this._isImageVertical = () => this.getProp("rotation") % 180 !== 0;
23
35
 
24
36
  this._getImageBounds = () => {
25
- const imageRef = this._adapter.getImageRef();
37
+ const imageDOM = this._adapter.getImage();
38
+
39
+ if (imageDOM) {
40
+ return imageDOM.getBoundingClientRect();
41
+ }
26
42
 
27
- return imageRef === null || imageRef === void 0 ? void 0 : imageRef.getBoundingClientRect();
43
+ return DefaultDOMRect;
28
44
  };
29
45
 
30
46
  this._getContainerBounds = () => {
31
- var _a;
47
+ const containerDOM = this._adapter.getContainer();
32
48
 
33
- const containerRef = this._adapter.getContainerRef();
49
+ if (containerDOM) {
50
+ return containerDOM.getBoundingClientRect();
51
+ }
34
52
 
35
- return (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
53
+ return DefaultDOMRect;
36
54
  };
37
55
 
38
56
  this._getOffset = e => {
@@ -123,9 +141,9 @@ class PreviewImageFoundation extends _foundation.default {
123
141
  onZoom
124
142
  } = this.getProps();
125
143
 
126
- const containerRef = this._adapter.getContainerRef();
144
+ const containerDOM = this._adapter.getContainer();
127
145
 
128
- if (containerRef && containerRef.current) {
146
+ if (containerDOM) {
129
147
  const {
130
148
  width: containerWidth,
131
149
  height: containerHeight
@@ -152,12 +170,14 @@ class PreviewImageFoundation extends _foundation.default {
152
170
  } else {
153
171
  return true;
154
172
  }
155
- };
173
+ }; // e: WheelEvent<HTMLImageElement>
174
+
156
175
 
157
176
  this.handleWheel = e => {
158
177
  this.onWheel(e);
159
178
  (0, _a11y.handlePrevent)(e);
160
- };
179
+ }; // e: WheelEvent<HTMLImageElement>
180
+
161
181
 
162
182
  this.onWheel = (0, _throttle2.default)(e => {
163
183
  const {
@@ -218,7 +238,7 @@ class PreviewImageFoundation extends _foundation.default {
218
238
  };
219
239
 
220
240
  this.handleZoomChange = (newZoom, e) => {
221
- const imageRef = this._adapter.getImageRef();
241
+ const imageDOM = this._adapter.getImage();
222
242
 
223
243
  const {
224
244
  originImageWidth,
@@ -269,7 +289,10 @@ class PreviewImageFoundation extends _foundation.default {
269
289
  top: newTop,
270
290
  currZoom: newZoom
271
291
  });
272
- imageRef && (imageRef.style.cursor = canDrag ? "grab" : "default");
292
+
293
+ if (imageDOM) {
294
+ this._adapter.setImageCursor(canDrag);
295
+ }
273
296
  };
274
297
 
275
298
  this.calcExtremeBounds = () => {
@@ -42,7 +42,7 @@ class PreviewInnerFoundation extends _foundation.default {
42
42
  };
43
43
 
44
44
  this.handleMouseMoveEvent = (e, event) => {
45
- const isTarget = (0, _utils.isTargetEmit)(e.nativeEvent, STOP_CLOSE_TARGET);
45
+ const isTarget = (0, _utils.isTargetEmit)(e, STOP_CLOSE_TARGET);
46
46
 
47
47
  if (isTarget && event === "over") {
48
48
  this._adapter.setStopTiming(true);
@@ -63,7 +63,7 @@ class PreviewInnerFoundation extends _foundation.default {
63
63
  const {
64
64
  maskClosable
65
65
  } = this.getProps();
66
- let couldClose = !(0, _utils.isTargetEmit)(e.nativeEvent, NOT_CLOSE_TARGETS);
66
+ let couldClose = !(0, _utils.isTargetEmit)(e, NOT_CLOSE_TARGETS);
67
67
  const {
68
68
  clientX,
69
69
  clientY
@@ -13,7 +13,7 @@ export interface TextAreaDefaultAdapter {
13
13
  export interface TextAreaAdapter extends Partial<DefaultAdapter>, Partial<TextAreaDefaultAdapter> {
14
14
  setMinLength(length: number): void;
15
15
  notifyPressEnter(e: any): void;
16
- getRef(): any;
16
+ getRef(): HTMLInputElement;
17
17
  notifyHeightUpdate(e: any): void;
18
18
  }
19
19
  export default class TextAreaFoundation extends BaseFoundation<TextAreaAdapter> {