@tarojs/components-react 4.1.4-beta.12 → 4.1.4-beta.13

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 (63) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/index.js +78 -11
  3. package/dist/index.js.map +1 -1
  4. package/dist/solid/index.css +1 -1
  5. package/dist/solid/index.js +78 -8
  6. package/dist/solid/index.js.map +1 -1
  7. package/package.json +6 -6
  8. package/dist/components/button/index.js +0 -87
  9. package/dist/components/button/index.js.map +0 -1
  10. package/dist/components/button/style/index.scss.js +0 -4
  11. package/dist/components/button/style/index.scss.js.map +0 -1
  12. package/dist/components/icon/index.js +0 -36
  13. package/dist/components/icon/index.js.map +0 -1
  14. package/dist/components/icon/style/index.scss.js +0 -4
  15. package/dist/components/icon/style/index.scss.js.map +0 -1
  16. package/dist/components/image/index.js +0 -86
  17. package/dist/components/image/index.js.map +0 -1
  18. package/dist/components/image/style/index.css.js +0 -4
  19. package/dist/components/image/style/index.css.js.map +0 -1
  20. package/dist/components/input/index.js +0 -233
  21. package/dist/components/input/index.js.map +0 -1
  22. package/dist/components/input/style/index.scss.js +0 -4
  23. package/dist/components/input/style/index.scss.js.map +0 -1
  24. package/dist/components/pull-down-refresh/index.js +0 -320
  25. package/dist/components/pull-down-refresh/index.js.map +0 -1
  26. package/dist/components/pull-down-refresh/style/index.css.js +0 -4
  27. package/dist/components/pull-down-refresh/style/index.css.js.map +0 -1
  28. package/dist/components/scroll-view/index.js +0 -184
  29. package/dist/components/scroll-view/index.js.map +0 -1
  30. package/dist/components/scroll-view/style/index.css.js +0 -4
  31. package/dist/components/scroll-view/style/index.css.js.map +0 -1
  32. package/dist/components/swiper/index.js +0 -461
  33. package/dist/components/swiper/index.js.map +0 -1
  34. package/dist/components/swiper/style/index.css.js +0 -4
  35. package/dist/components/swiper/style/index.css.js.map +0 -1
  36. package/dist/components/text/index.js +0 -28
  37. package/dist/components/text/index.js.map +0 -1
  38. package/dist/components/text/style/index.css.js +0 -4
  39. package/dist/components/text/style/index.css.js.map +0 -1
  40. package/dist/components/view/index.js +0 -80
  41. package/dist/components/view/index.js.map +0 -1
  42. package/dist/solid/components/button/index.js +0 -95
  43. package/dist/solid/components/button/index.js.map +0 -1
  44. package/dist/solid/components/button/style/index.scss.js +0 -4
  45. package/dist/solid/components/button/style/index.scss.js.map +0 -1
  46. package/dist/solid/components/icon/index.js +0 -39
  47. package/dist/solid/components/icon/index.js.map +0 -1
  48. package/dist/solid/components/icon/style/index.scss.js +0 -4
  49. package/dist/solid/components/icon/style/index.scss.js.map +0 -1
  50. package/dist/solid/components/image/index.js +0 -94
  51. package/dist/solid/components/image/index.js.map +0 -1
  52. package/dist/solid/components/image/style/index.css.js +0 -4
  53. package/dist/solid/components/image/style/index.css.js.map +0 -1
  54. package/dist/solid/components/scroll-view/index.js +0 -188
  55. package/dist/solid/components/scroll-view/index.js.map +0 -1
  56. package/dist/solid/components/scroll-view/style/index.css.js +0 -4
  57. package/dist/solid/components/scroll-view/style/index.css.js.map +0 -1
  58. package/dist/solid/components/text/index.js +0 -32
  59. package/dist/solid/components/text/index.js.map +0 -1
  60. package/dist/solid/components/text/style/index.css.js +0 -4
  61. package/dist/solid/components/text/style/index.css.js.map +0 -1
  62. package/dist/solid/components/view/index.js +0 -88
  63. package/dist/solid/components/view/index.js.map +0 -1
@@ -1,86 +0,0 @@
1
- import { __rest } from 'tslib';
2
- import './style/index.css.js';
3
- import classNames from 'classnames';
4
- import { createForwardRefComponent } from '../../utils/index.js';
5
- import { useRef, useState, useCallback, useEffect } from '../../utils/hooks.react.js';
6
- import { jsx } from 'react/jsx-runtime';
7
-
8
- function Image(props) {
9
- const imgRef = useRef(null);
10
- const observer = useRef({});
11
- const [, setIsLoaded] = useState(false);
12
- const {
13
- className,
14
- style = {},
15
- src,
16
- mode,
17
- onError,
18
- lazyLoad,
19
- imgProps,
20
- forwardedRef
21
- } = props,
22
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
23
- const cls = classNames('taro-img', {
24
- 'taro-img__widthfix': mode === 'widthFix'
25
- }, className);
26
- const imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
27
- const imageOnLoad = useCallback(e => {
28
- const {
29
- onLoad
30
- } = props;
31
- Object.defineProperty(e, 'detail', {
32
- enumerable: true,
33
- writable: true,
34
- value: {
35
- width: e.target.width,
36
- height: e.target.height
37
- }
38
- });
39
- onLoad && onLoad(e);
40
- }, [props]);
41
- useEffect(() => {
42
- var _a, _b;
43
- if (lazyLoad) {
44
- observer.current = new IntersectionObserver(entries => {
45
- // 异步 api 关系
46
- if (entries[entries.length - 1].isIntersecting) {
47
- setIsLoaded(true);
48
- // findDOMNode(this).children[0].src = src
49
- imgRef.current.src = src;
50
- }
51
- }, {
52
- rootMargin: '300px 0px'
53
- });
54
- (_b = (_a = observer.current).observe) === null || _b === void 0 ? void 0 : _b.call(_a, imgRef.current);
55
- }
56
- return () => {
57
- var _a, _b;
58
- (_b = (_a = observer.current) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
59
- };
60
- }, [lazyLoad, src]);
61
- return /*#__PURE__*/jsx("div", {
62
- className: cls,
63
- style: style,
64
- ref: forwardedRef,
65
- ...reset,
66
- children: lazyLoad ? /*#__PURE__*/jsx("img", {
67
- ref: img => imgRef.current = img,
68
- className: imgCls,
69
- "data-src": src,
70
- onLoad: imageOnLoad,
71
- onError: onError,
72
- ...imgProps
73
- }) : /*#__PURE__*/jsx("img", {
74
- ref: img => imgRef.current = img,
75
- className: imgCls,
76
- src: src,
77
- onLoad: imageOnLoad,
78
- onError: onError,
79
- ...imgProps
80
- })
81
- });
82
- }
83
- var index = createForwardRefComponent(Image);
84
-
85
- export { index as default };
86
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.css'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n ...reset\n } = props\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAmBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,CAAC;AACpD,EAAA,MAAMC,QAAQ,GAAGD,MAAM,CAAgC,EAAE,CAAC;AAC1D,EAAA,MAAM,GAAGE,WAAW,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM;MACJC,SAAS;MACTC,KAAK,GAAG,EAAE;MACVC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;AACRC,MAAAA;AAAY,KAAA,GAEVb,KAAK;IADJc,KAAK,GAAAC,MAAA,CACNf,KAAK,EAVH,CAUL,WAAA,EAAA,OAAA,EAAA,KAAA,EAAA,MAAA,EAAA,SAAA,EAAA,UAAA,EAAA,UAAA,EAAA,cAAA,CAAA,CAAQ;AACT,EAAA,MAAMgB,GAAG,GAAGC,UAAU,CACpB,UAAU,EACV;IACE,oBAAoB,EAAER,IAAI,KAAK;GAChC,EACDH,SAAS,CACV;EACD,MAAMY,MAAM,GAAGD,UAAU,CACvB,iBAAiB,GACf,CAACR,IAAI,IAAI,aAAa,EAAEU,WAAW,EAAE,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAC3D;AAED,EAAA,MAAMC,WAAW,GAAGC,WAAW,CAAEC,CAAC,IAAI;IACpC,MAAM;AAAEC,MAAAA;AAAQ,KAAA,GAAGxB,KAAK;AACxByB,IAA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C;AAEnB,EAAA,oBACEqC,GAAA,CAAA,KAAA,EAAA;AAAKvC,IAAAA,SAAS,EAAEU,GAAI;AAACT,IAAAA,KAAK,EAAEA,KAAM;AAACuC,IAAAA,GAAG,EAAEjC,YAAa;AAAA,IAAA,GAAKC,KAAK;IAAAiC,QAAA,EAC5DpC,QAAQ,gBACPkC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAK/C,MAAM,CAACiC,OAAO,GAAGc,GAAK;AACnC1C,MAAAA,SAAS,EAAEY,MAAO;AAClB,MAAA,UAAA,EAAUV,GAAI;AACdgB,MAAAA,MAAM,EAAEH,WAAY;AACpBX,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KAAS,CACb,gBAEFiC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAK/C,MAAM,CAACiC,OAAO,GAAGc,GAAK;AACnC1C,MAAAA,SAAS,EAAEY,MAAO;AAClBV,MAAAA,GAAG,EAAEA,GAAI;AACTgB,MAAAA,MAAM,EAAEH,WAAY;AACpBX,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAeqC,yBAAyB,CAAClD,KAAK,CAAC;;;;"}
@@ -1,4 +0,0 @@
1
- var undefined$1 = undefined;
2
-
3
- export { undefined$1 as default };
4
- //# sourceMappingURL=index.css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,233 +0,0 @@
1
- import './style/index.scss.js';
2
- import classNames from 'classnames';
3
- import React__default from 'react';
4
- import { omit, createForwardRefComponent } from '../../utils/index.js';
5
- import { jsx } from 'react/jsx-runtime';
6
-
7
- function getTrueType(type, confirmType, password) {
8
- if (confirmType === 'search') type = 'search';
9
- if (password) type = 'password';
10
- if (typeof type === 'undefined') {
11
- return 'text';
12
- }
13
- if (!type) {
14
- throw new Error('unexpected type');
15
- }
16
- if (type === 'digit') type = 'number';
17
- return type;
18
- }
19
- function fixControlledValue(value) {
20
- return value !== null && value !== void 0 ? value : '';
21
- }
22
- class Input extends React__default.Component {
23
- constructor(props) {
24
- super(props);
25
- this.handleBeforeInput = e => {
26
- if (!e.data) return;
27
- const isNumber = e.data && /[0-9]/.test(e.data);
28
- if (this.props.type === 'number' && !isNumber) {
29
- e.preventDefault();
30
- }
31
- if (this.props.type === 'digit' && !isNumber) {
32
- if (e.data !== '.' || e.data === '.' && e.target.value.indexOf('.') > -1) {
33
- e.preventDefault();
34
- }
35
- }
36
- };
37
- this.handleInput = this.handleInput.bind(this);
38
- this.handlePaste = this.handlePaste.bind(this);
39
- this.handleFocus = this.handleFocus.bind(this);
40
- this.handleBlur = this.handleBlur.bind(this);
41
- this.handleKeyDown = this.handleKeyDown.bind(this);
42
- this.handleComposition = this.handleComposition.bind(this);
43
- this.handleBeforeInput = this.handleBeforeInput.bind(this);
44
- this.isOnComposition = false;
45
- this.onInputExcuted = false;
46
- }
47
- componentDidMount() {
48
- var _a, _b;
49
- // 修复无法选择文件
50
- if (this.props.type === 'file') {
51
- (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.addEventListener('change', this.handleInput);
52
- } else {
53
- (_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.addEventListener('textInput', this.handleBeforeInput);
54
- }
55
- // 处理初始化是否 focus
56
- if (this.props.focus && this.inputRef) this.inputRef.focus();
57
- }
58
- componentWillUnmount() {
59
- var _a;
60
- // 修复无法选择文件
61
- if (this.props.type === 'file') {
62
- this.inputRef.removeEventListener('change', this.handleInput);
63
- } else {
64
- (_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.removeEventListener('textInput', this.handleBeforeInput);
65
- }
66
- }
67
- UNSAFE_componentWillReceiveProps(nextProps) {
68
- if (!this.props.focus && nextProps.focus && this.inputRef) this.inputRef.focus();
69
- }
70
- handleInput(e) {
71
- e.stopPropagation();
72
- const {
73
- type,
74
- maxlength = 140,
75
- confirmType = 'done',
76
- password = false,
77
- onInput
78
- } = this.props;
79
- if (!this.isOnComposition && !this.onInputExcuted) {
80
- let {
81
- value
82
- } = e.target;
83
- const inputType = getTrueType(type, confirmType, password);
84
- this.onInputExcuted = true;
85
- /* 修复 number 类型 maxLength 无效 */
86
- if (inputType === 'number' && value && maxlength <= value.length) {
87
- value = value.substring(0, maxlength);
88
- e.target.value = value;
89
- }
90
- Object.defineProperty(e, 'detail', {
91
- value: {
92
- value,
93
- cursor: value.length
94
- }
95
- });
96
- // // 修复 IOS 光标跳转问题
97
- // if (!(['number', 'file'].indexOf(inputType) >= 0)) {
98
- // const pos = e.target.selectionEnd
99
- // setTimeout(
100
- // () => {
101
- // e.target.selectionStart = pos
102
- // e.target.selectionEnd = pos
103
- // }
104
- // )
105
- // }
106
- typeof onInput === 'function' && onInput(e);
107
- this.onInputExcuted = false;
108
- }
109
- }
110
- handlePaste(e) {
111
- e.stopPropagation();
112
- const {
113
- onPaste
114
- } = this.props;
115
- this.onInputExcuted = false;
116
- Object.defineProperty(e, 'detail', {
117
- value: {
118
- value: e.target.value
119
- }
120
- });
121
- typeof onPaste === 'function' && onPaste(e);
122
- }
123
- handleFocus(e) {
124
- e.stopPropagation();
125
- const {
126
- onFocus
127
- } = this.props;
128
- this.onInputExcuted = false;
129
- Object.defineProperty(e, 'detail', {
130
- value: {
131
- value: e.target.value
132
- }
133
- });
134
- onFocus && onFocus(e);
135
- }
136
- handleBlur(e) {
137
- e.stopPropagation();
138
- const {
139
- onBlur
140
- } = this.props;
141
- Object.defineProperty(e, 'detail', {
142
- value: {
143
- value: e.target.value
144
- }
145
- });
146
- onBlur && onBlur(e);
147
- }
148
- handleKeyDown(e) {
149
- e.stopPropagation();
150
- const {
151
- onConfirm,
152
- onKeyDown
153
- } = this.props;
154
- const {
155
- value
156
- } = e.target;
157
- const keyCode = e.keyCode || e.code;
158
- this.onInputExcuted = false;
159
- if (typeof onKeyDown === 'function') {
160
- Object.defineProperty(e, 'detail', {
161
- value: {
162
- value,
163
- cursor: value.length,
164
- keyCode
165
- }
166
- });
167
- onKeyDown(e);
168
- }
169
- if (e.keyCode === 13 && typeof onConfirm === 'function') {
170
- Object.defineProperty(e, 'detail', {
171
- value: {
172
- value
173
- }
174
- });
175
- onConfirm(e);
176
- }
177
- }
178
- handleComposition(e) {
179
- e.stopPropagation();
180
- if (!(e.target instanceof HTMLInputElement)) return;
181
- if (e.type === 'compositionend') {
182
- this.isOnComposition = false;
183
- this.handleInput(e);
184
- } else {
185
- this.isOnComposition = true;
186
- }
187
- }
188
- render() {
189
- const {
190
- className = '',
191
- placeholder,
192
- type,
193
- password = false,
194
- disabled = false,
195
- maxlength = 140,
196
- confirmType = 'done',
197
- name,
198
- value
199
- } = this.props;
200
- const cls = classNames('taro-input-core', 'weui-input', className);
201
- const otherProps = omit(this.props, ['forwardedRef', 'className', 'placeholder', 'disabled', 'password', 'type', 'maxlength', 'confirmType', 'focus', 'name']);
202
- if ('value' in this.props) {
203
- otherProps.value = fixControlledValue(value);
204
- }
205
- return /*#__PURE__*/jsx("input", {
206
- ref: input => {
207
- if (this.props.forwardedRef) {
208
- this.props.forwardedRef.current = input;
209
- }
210
- this.inputRef = input;
211
- },
212
- ...otherProps,
213
- className: cls,
214
- type: getTrueType(type, confirmType, password),
215
- placeholder: placeholder,
216
- disabled: disabled,
217
- maxLength: maxlength,
218
- name: name,
219
- onInput: this.handleInput,
220
- onPaste: this.handlePaste,
221
- onFocus: this.handleFocus,
222
- onBlur: this.handleBlur,
223
- onKeyDown: this.handleKeyDown,
224
- onCompositionStart: this.handleComposition,
225
- onCompositionEnd: this.handleComposition,
226
- onBeforeInput: this.handleBeforeInput
227
- });
228
- }
229
- }
230
- var index = createForwardRefComponent(Input);
231
-
232
- export { index as default };
233
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/input/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\nimport React from 'react'\n\nimport { createForwardRefComponent, omit } from '../../utils'\n\nfunction getTrueType (type: string | undefined, confirmType: string, password: boolean) {\n if (confirmType === 'search') type = 'search'\n if (password) type = 'password'\n if (typeof type === 'undefined') {\n return 'text'\n }\n if (!type) {\n throw new Error('unexpected type')\n }\n if (type === 'digit') type = 'number'\n\n return type\n}\n\nfunction fixControlledValue (value) {\n return value ?? ''\n}\n\ninterface IProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> {\n password?: boolean\n disabled?: boolean\n maxlength?: number\n placeholder?: string\n value?: string\n focus?: boolean\n confirmType?: string\n name?: string\n type?: string\n onConfirm?: (e) => void\n forwardedRef?: React.MutableRefObject<HTMLInputElement>\n}\n\nclass Input extends React.Component<IProps, null> {\n constructor (props) {\n super(props)\n this.handleInput = this.handleInput.bind(this)\n this.handlePaste = this.handlePaste.bind(this)\n this.handleFocus = this.handleFocus.bind(this)\n this.handleBlur = this.handleBlur.bind(this)\n this.handleKeyDown = this.handleKeyDown.bind(this)\n this.handleComposition = this.handleComposition.bind(this)\n this.handleBeforeInput = this.handleBeforeInput.bind(this)\n this.isOnComposition = false\n this.onInputExcuted = false\n }\n\n inputRef: HTMLInputElement\n isOnComposition: boolean\n onInputExcuted: boolean\n\n componentDidMount () {\n // 修复无法选择文件\n if (this.props.type === 'file') {\n this.inputRef?.addEventListener('change', this.handleInput)\n } else {\n this.inputRef?.addEventListener('textInput', this.handleBeforeInput)\n }\n\n // 处理初始化是否 focus\n if (this.props.focus && this.inputRef) this.inputRef.focus()\n }\n\n componentWillUnmount () {\n // 修复无法选择文件\n if (this.props.type === 'file') {\n this.inputRef.removeEventListener('change', this.handleInput)\n } else {\n this.inputRef?.removeEventListener('textInput', this.handleBeforeInput)\n }\n }\n\n UNSAFE_componentWillReceiveProps (nextProps: Readonly<IProps>) {\n if (!this.props.focus && nextProps.focus && this.inputRef) this.inputRef.focus()\n }\n\n handleInput (e) {\n e.stopPropagation()\n const {\n type,\n maxlength = 140,\n confirmType = 'done',\n password = false,\n onInput\n } = this.props\n\n if (!this.isOnComposition && !this.onInputExcuted) {\n let { value } = e.target\n const inputType = getTrueType(type, confirmType, password)\n this.onInputExcuted = true\n /* 修复 number 类型 maxLength 无效 */\n if (inputType === 'number' && value && maxlength <= value.length) {\n value = value.substring(0, maxlength)\n e.target.value = value\n }\n\n Object.defineProperty(e, 'detail', {\n value: { value, cursor: value.length }\n })\n // // 修复 IOS 光标跳转问题\n // if (!(['number', 'file'].indexOf(inputType) >= 0)) {\n // const pos = e.target.selectionEnd\n // setTimeout(\n // () => {\n // e.target.selectionStart = pos\n // e.target.selectionEnd = pos\n // }\n // )\n // }\n\n typeof onInput === 'function' && onInput(e)\n this.onInputExcuted = false\n }\n }\n\n handlePaste (e) {\n e.stopPropagation()\n const { onPaste } = this.props\n this.onInputExcuted = false\n Object.defineProperty(e, 'detail', {\n value: {\n value: e.target.value\n }\n })\n typeof onPaste === 'function' && onPaste(e)\n }\n\n handleFocus (e) {\n e.stopPropagation()\n const { onFocus } = this.props\n this.onInputExcuted = false\n Object.defineProperty(e, 'detail', {\n value: {\n value: e.target.value\n }\n })\n onFocus && onFocus(e)\n }\n\n handleBlur (e) {\n e.stopPropagation()\n const { onBlur } = this.props\n Object.defineProperty(e, 'detail', {\n value: {\n value: e.target.value\n }\n })\n onBlur && onBlur(e)\n }\n\n handleKeyDown (e) {\n e.stopPropagation()\n const { onConfirm, onKeyDown } = this.props\n const { value } = e.target\n const keyCode = e.keyCode || e.code\n this.onInputExcuted = false\n\n if (typeof onKeyDown === 'function') {\n Object.defineProperty(e, 'detail', {\n value: {\n value,\n cursor: value.length,\n keyCode\n }\n })\n onKeyDown(e)\n }\n\n if (e.keyCode === 13 && typeof onConfirm === 'function') {\n Object.defineProperty(e, 'detail', {\n value: {\n value\n }\n })\n onConfirm(e)\n }\n }\n\n handleComposition (e) {\n e.stopPropagation()\n if (!(e.target instanceof HTMLInputElement)) return\n\n if (e.type === 'compositionend') {\n this.isOnComposition = false\n this.handleInput(e)\n } else {\n this.isOnComposition = true\n }\n }\n\n handleBeforeInput = (e) => {\n if (!e.data) return\n const isNumber = e.data && /[0-9]/.test(e.data)\n if (this.props.type === 'number' && !isNumber) {\n e.preventDefault()\n }\n if (this.props.type === 'digit' && !isNumber) {\n if (e.data !== '.' || (e.data === '.' && e.target.value.indexOf('.') > -1)) {\n e.preventDefault()\n }\n }\n }\n\n render () {\n const {\n className = '',\n placeholder,\n type,\n password = false,\n disabled = false,\n maxlength = 140,\n confirmType = 'done',\n name,\n value\n } = this.props\n const cls = classNames('taro-input-core', 'weui-input', className)\n\n const otherProps = omit(this.props, [\n 'forwardedRef',\n 'className',\n 'placeholder',\n 'disabled',\n 'password',\n 'type',\n 'maxlength',\n 'confirmType',\n 'focus',\n 'name'\n ])\n\n if ('value' in this.props) {\n otherProps.value = fixControlledValue(value)\n }\n\n return (\n <input\n ref={(input: HTMLInputElement) => {\n if (this.props.forwardedRef) {\n this.props.forwardedRef.current = input\n }\n this.inputRef = input\n }}\n {...otherProps}\n className={cls}\n type={getTrueType(type, confirmType, password)}\n placeholder={placeholder}\n disabled={disabled}\n maxLength={maxlength}\n name={name}\n onInput={this.handleInput}\n onPaste={this.handlePaste}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n onKeyDown={this.handleKeyDown}\n onCompositionStart={this.handleComposition}\n onCompositionEnd={this.handleComposition}\n onBeforeInput={this.handleBeforeInput}\n />\n )\n }\n}\n\nexport default createForwardRefComponent(Input)\n"],"names":["getTrueType","type","confirmType","password","Error","fixControlledValue","value","Input","React","Component","constructor","props","handleBeforeInput","e","data","isNumber","test","preventDefault","target","indexOf","handleInput","bind","handlePaste","handleFocus","handleBlur","handleKeyDown","handleComposition","isOnComposition","onInputExcuted","componentDidMount","_a","inputRef","addEventListener","_b","focus","componentWillUnmount","removeEventListener","UNSAFE_componentWillReceiveProps","nextProps","stopPropagation","maxlength","onInput","inputType","length","substring","Object","defineProperty","cursor","onPaste","onFocus","onBlur","onConfirm","onKeyDown","keyCode","code","HTMLInputElement","render","className","placeholder","disabled","name","cls","classNames","otherProps","omit","_jsx","ref","input","forwardedRef","current","maxLength","onCompositionStart","onCompositionEnd","onBeforeInput","createForwardRefComponent"],"mappings":";;;;;;AAOA,SAASA,WAAWA,CAAEC,IAAwB,EAAEC,WAAmB,EAAEC,QAAiB,EAAA;AACpF,EAAA,IAAID,WAAW,KAAK,QAAQ,EAAED,IAAI,GAAG,QAAQ;AAC7C,EAAA,IAAIE,QAAQ,EAAEF,IAAI,GAAG,UAAU;AAC/B,EAAA,IAAI,OAAOA,IAAI,KAAK,WAAW,EAAE;AAC/B,IAAA,OAAO,MAAM;AACf;EACA,IAAI,CAACA,IAAI,EAAE;AACT,IAAA,MAAM,IAAIG,KAAK,CAAC,iBAAiB,CAAC;AACpC;AACA,EAAA,IAAIH,IAAI,KAAK,OAAO,EAAEA,IAAI,GAAG,QAAQ;AAErC,EAAA,OAAOA,IAAI;AACb;AAEA,SAASI,kBAAkBA,CAAEC,KAAK,EAAA;EAChC,OAAOA,KAAK,KAAL,IAAA,IAAAA,KAAK,cAALA,KAAK,GAAI,EAAE;AACpB;AAgBA,MAAMC,KAAM,SAAQC,cAAK,CAACC,SAAuB,CAAA;EAC/CC,WAAAA,CAAaC,KAAK,EAAA;IAChB,KAAK,CAACA,KAAK,CAAC;AA2Jd,IAAA,IAAA,CAAAC,iBAAiB,GAAIC,CAAC,IAAI;AACxB,MAAA,IAAI,CAACA,CAAC,CAACC,IAAI,EAAE;AACb,MAAA,MAAMC,QAAQ,GAAGF,CAAC,CAACC,IAAI,IAAI,OAAO,CAACE,IAAI,CAACH,CAAC,CAACC,IAAI,CAAC;MAC/C,IAAI,IAAI,CAACH,KAAK,CAACV,IAAI,KAAK,QAAQ,IAAI,CAACc,QAAQ,EAAE;QAC7CF,CAAC,CAACI,cAAc,EAAE;AACpB;MACA,IAAI,IAAI,CAACN,KAAK,CAACV,IAAI,KAAK,OAAO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kB,CAACC,KAAK,CAAC;AAC9C;AAEA,IAAA,oBACE2D,GAAA,CAAA,OAAA,EAAA;MACEC,GAAG,EAAGC,KAAuB,IAAI;AAC/B,QAAA,IAAI,IAAI,CAACxD,KAAK,CAACyD,YAAY,EAAE;AAC3B,UAAA,IAAI,CAACzD,KAAK,CAACyD,YAAY,CAACC,OAAO,GAAGF,KAAK;AACzC;QACA,IAAI,CAACpC,QAAQ,GAAGoC,KAAK;OACrB;AAAA,MAAA,GACEJ,UAAU;AACdN,MAAAA,SAAS,EAAEI,GAAI;MACf5D,IAAI,EAAED,WAAW,CAACC,IAAI,EAAEC,WAAW,EAAEC,QAAQ,CAAE;AAC/CuD,MAAAA,WAAW,EAAEA,WAAY;AACzBC,MAAAA,QAAQ,EAAEA,QAAS;AACnBW,MAAAA,SAAS,EAAE9B,SAAU;AACrBoB,MAAAA,IAAI,EAAEA,IAAK;MACXnB,OAAO,EAAE,IAAI,CAACrB,WAAY;MAC1B4B,OAAO,EAAE,IAAI,CAAC1B,WAAY;MAC1B2B,OAAO,EAAE,IAAI,CAAC1B,WAAY;MAC1B2B,MAAM,EAAE,IAAI,CAAC1B,UAAW;MACxB4B,SAAS,EAAE,IAAI,CAAC3B,aAAc;MAC9B8C,kBAAkB,EAAE,IAAI,CAAC7C,iBAAkB;MAC3C8C,gBAAgB,EAAE,IAAI,CAAC9C,iBAAkB;MACzC+C,aAAa,EAAE,IAAI,CAAC7D;AAAkB,KACtC,CAAA;AAEN;AACD;AAED,YAAe8D,yBAAyB,CAACnE,KAAK,CAAC;;;;"}
@@ -1,4 +0,0 @@
1
- var undefined$1 = undefined;
2
-
3
- export { undefined$1 as default };
4
- //# sourceMappingURL=index.scss.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}