@tarojs/components-react 4.0.0-beta.7 → 4.0.0-beta.9
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.
- package/dist/components/button/index.js +84 -0
- package/dist/components/button/index.js.map +1 -0
- package/dist/components/button/style/index.scss.js +4 -0
- package/dist/components/button/style/index.scss.js.map +1 -0
- package/dist/components/icon/index.js +28 -0
- package/dist/components/icon/index.js.map +1 -0
- package/dist/components/icon/style/index.scss.js +4 -0
- package/dist/components/icon/style/index.scss.js.map +1 -0
- package/dist/components/image/index.js +74 -96
- package/dist/components/image/index.js.map +1 -1
- package/dist/components/image/style/index.css.js +2 -6
- package/dist/components/image/style/index.css.js.map +1 -1
- package/dist/components/input/index.js +228 -0
- package/dist/components/input/index.js.map +1 -0
- package/dist/components/input/style/index.scss.js +4 -0
- package/dist/components/input/style/index.scss.js.map +1 -0
- package/dist/components/pull-down-refresh/index.js +182 -209
- package/dist/components/pull-down-refresh/index.js.map +1 -1
- package/dist/components/pull-down-refresh/style/index.css.js +2 -6
- package/dist/components/pull-down-refresh/style/index.css.js.map +1 -1
- package/dist/components/scroll-view/index.js +127 -155
- package/dist/components/scroll-view/index.js.map +1 -1
- package/dist/components/scroll-view/style/index.css.js +2 -6
- package/dist/components/scroll-view/style/index.css.js.map +1 -1
- package/dist/components/swiper/index.js +230 -268
- package/dist/components/swiper/index.js.map +1 -1
- package/dist/components/swiper/style/index.css.js +2 -6
- package/dist/components/swiper/style/index.css.js.map +1 -1
- package/dist/components/text/index.js +15 -28
- package/dist/components/text/index.js.map +1 -1
- package/dist/components/text/style/index.css.js +2 -6
- package/dist/components/text/style/index.css.js.map +1 -1
- package/dist/components/view/index.js +72 -93
- package/dist/components/view/index.js.map +1 -1
- package/dist/components/view/style/index.css.js +2 -6
- package/dist/components/view/style/index.css.js.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.js +20 -12
- package/dist/utils/index.js.map +1 -1
- package/package.json +6 -4
- package/dist/node_modules/.pnpm/registry.npmjs.org_style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js +0 -27
- package/dist/node_modules/.pnpm/registry.npmjs.org_style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import './style/index.scss.js';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { omit } from '../../utils/index.js';
|
|
5
|
+
|
|
6
|
+
class Button extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.state = {
|
|
10
|
+
hover: false,
|
|
11
|
+
touch: false
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
componentWillUnmount() {
|
|
15
|
+
this.startTimer && clearTimeout(this.startTimer);
|
|
16
|
+
this.endTimer && clearTimeout(this.endTimer);
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
const {
|
|
20
|
+
plain = false,
|
|
21
|
+
children,
|
|
22
|
+
disabled = false,
|
|
23
|
+
className,
|
|
24
|
+
style,
|
|
25
|
+
onClick,
|
|
26
|
+
onTouchStart,
|
|
27
|
+
onTouchEnd,
|
|
28
|
+
hoverClass = 'button-hover',
|
|
29
|
+
hoverStartTime = 20,
|
|
30
|
+
hoverStayTime = 70,
|
|
31
|
+
loading = false,
|
|
32
|
+
type
|
|
33
|
+
} = this.props;
|
|
34
|
+
const cls = classNames(className, 'taro-button-core', {
|
|
35
|
+
[`${hoverClass}`]: this.state.hover && !disabled
|
|
36
|
+
});
|
|
37
|
+
const _onTouchStart = e => {
|
|
38
|
+
this.setState(() => ({
|
|
39
|
+
touch: true
|
|
40
|
+
}));
|
|
41
|
+
if (hoverClass && hoverClass !== 'none' && !disabled) {
|
|
42
|
+
this.startTimer = setTimeout(() => {
|
|
43
|
+
if (this.state.touch) {
|
|
44
|
+
this.setState(() => ({
|
|
45
|
+
hover: true
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}, hoverStartTime);
|
|
49
|
+
}
|
|
50
|
+
onTouchStart && onTouchStart(e);
|
|
51
|
+
};
|
|
52
|
+
const _onTouchEnd = e => {
|
|
53
|
+
this.setState(() => ({
|
|
54
|
+
touch: false
|
|
55
|
+
}));
|
|
56
|
+
if (hoverClass && hoverClass !== 'none' && !disabled) {
|
|
57
|
+
this.endTimer = setTimeout(() => {
|
|
58
|
+
if (!this.state.touch) {
|
|
59
|
+
this.setState(() => ({
|
|
60
|
+
hover: false
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
}, hoverStayTime);
|
|
64
|
+
}
|
|
65
|
+
onTouchEnd && onTouchEnd(e);
|
|
66
|
+
};
|
|
67
|
+
return React.createElement("button", Object.assign({}, omit(this.props, ['hoverClass', 'onTouchStart', 'onTouchEnd', 'type', 'loading']), {
|
|
68
|
+
type: type,
|
|
69
|
+
className: cls,
|
|
70
|
+
style: style,
|
|
71
|
+
onClick: onClick,
|
|
72
|
+
disabled: disabled,
|
|
73
|
+
onTouchStart: _onTouchStart,
|
|
74
|
+
onTouchEnd: _onTouchEnd,
|
|
75
|
+
loading: loading.toString(),
|
|
76
|
+
plain: plain.toString()
|
|
77
|
+
}), !!loading && React.createElement("i", {
|
|
78
|
+
className: 'weui-loading'
|
|
79
|
+
}), children);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { Button as default };
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/button/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\nimport React from 'react'\n\nimport { omit } from '../../utils'\n\ninterface IProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> {\n size?: string\n plain?: boolean\n hoverClass?: string\n hoverStartTime?: number\n hoverStayTime?: number\n disabled?: boolean\n loading?: boolean\n type?: string\n className?: string\n}\n\ninterface IState {\n hover:boolean\n touch: boolean\n}\n\nclass Button extends React.Component<IProps, IState> {\n constructor (props) {\n super(props)\n this.state = {\n hover: false,\n touch: false\n }\n }\n\n startTimer: ReturnType<typeof setTimeout>\n endTimer: ReturnType<typeof setTimeout>\n\n componentWillUnmount () {\n this.startTimer && clearTimeout(this.startTimer)\n this.endTimer && clearTimeout(this.endTimer)\n }\n\n render () {\n const {\n plain = false,\n children,\n disabled = false,\n className,\n style,\n onClick,\n onTouchStart,\n onTouchEnd,\n hoverClass = 'button-hover',\n hoverStartTime = 20,\n hoverStayTime = 70,\n loading = false,\n type,\n } = this.props\n const cls = classNames(\n className,\n 'taro-button-core',\n {\n [`${hoverClass}`]: this.state.hover && !disabled\n }\n )\n\n const _onTouchStart = e => {\n this.setState(() => ({\n touch: true\n }))\n if (hoverClass && hoverClass !== 'none' && !disabled) {\n this.startTimer = setTimeout(() => {\n if (this.state.touch) {\n this.setState(() => ({\n hover: true\n }))\n }\n }, hoverStartTime)\n }\n onTouchStart && onTouchStart(e)\n }\n const _onTouchEnd = e => {\n this.setState(() => ({\n touch: false\n }))\n if (hoverClass && hoverClass !== 'none' && !disabled) {\n this.endTimer = setTimeout(() => {\n if (!this.state.touch) {\n this.setState(() => ({\n hover: false\n }))\n }\n }, hoverStayTime)\n }\n onTouchEnd && onTouchEnd(e)\n }\n\n return (\n <button\n {...omit(this.props, ['hoverClass', 'onTouchStart', 'onTouchEnd', 'type', 'loading'])}\n type={type}\n className={cls}\n style={style}\n onClick={onClick}\n disabled={disabled}\n onTouchStart={_onTouchStart}\n onTouchEnd={_onTouchEnd}\n loading={loading.toString()}\n plain={plain.toString()}\n >\n {!!loading && <i className='weui-loading' />}\n {children}\n </button>\n )\n }\n}\n\nexport default Button\n"],"names":["Button","React","Component","constructor","props","state","hover","touch","componentWillUnmount","startTimer","clearTimeout","endTimer","render","plain","children","disabled","className","style","onClick","onTouchStart","onTouchEnd","hoverClass","hoverStartTime","hoverStayTime","loading","type","cls","classNames","_onTouchStart","e","setState","setTimeout","_onTouchEnd","createElement","Object","assign","omit","toString"],"mappings":";;;;;AAwBA,MAAMA,MAAO,SAAQC,KAAK,CAACC,SAAyB,CAAA;EAClDC,WAAAA,CAAaC,KAAK,EAAA;IAChB,KAAK,CAACA,KAAK,CAAC,CAAA;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,KAAK,EAAE,KAAK;AACZC,MAAAA,KAAK,EAAE,KAAA;KACR,CAAA;AACH,GAAA;AAKAC,EAAAA,oBAAoBA,GAAA;IAClB,IAAI,CAACC,UAAU,IAAIC,YAAY,CAAC,IAAI,CAACD,UAAU,CAAC,CAAA;IAChD,IAAI,CAACE,QAAQ,IAAID,YAAY,CAAC,IAAI,CAACC,QAAQ,CAAC,CAAA;AAC9C,GAAA;AAEAC,EAAAA,MAAMA,GAAA;IACJ,MAAM;AACJC,MAAAA,KAAK,GAAG,KAAK;MACbC,QAAQ;AACRC,MAAAA,QAAQ,GAAG,KAAK;MAChBC,SAAS;MACTC,KAAK;MACLC,OAAO;MACPC,YAAY;MACZC,UAAU;AACVC,MAAAA,UAAU,GAAG,cAAc;AAC3BC,MAAAA,cAAc,GAAG,EAAE;AACnBC,MAAAA,aAAa,GAAG,EAAE;AAClBC,MAAAA,OAAO,GAAG,KAAK;AACfC,MAAAA,IAAAA;KACD,GAAG,IAAI,CAACrB,KAAK,CAAA;AACd,IAAA,MAAMsB,GAAG,GAAGC,UAAU,CACpBX,SAAS,EACT,kBAAkB,EAClB;MACE,CAAI,CAAA,EAAAK,UAAY,CAAA,CAAA,GAAG,IAAI,CAAChB,KAAK,CAACC,KAAK,IAAI,CAACS,QAAAA;AACzC,KAAA,CACF,CAAA;IAED,MAAMa,aAAa,GAAGC,CAAC,IAAG;MACxB,IAAI,CAACC,QAAQ,CAAC,OAAO;AACnBvB,QAAAA,KAAK,EAAE,IAAA;AACR,OAAA,CAAC,CAAC,CAAA;MACH,IA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AACdT,MAAAA,KAAK,EAAEA,KAAK;AACZC,MAAAA,OAAO,EAAEA,OAAO;AAChBH,MAAAA,QAAQ,EAAEA,QAAQ;AAClBI,MAAAA,YAAY,EAAES,aAAa;AAC3BR,MAAAA,UAAU,EAAEY,WAAW;AACvBR,MAAAA,OAAO,EAAEA,OAAO,CAACa,QAAQ,EAAE;AAC3BxB,MAAAA,KAAK,EAAEA,KAAK,CAACwB,QAAQ,EAAE;KAAA,CAAA,EAEtB,CAAC,CAACb,OAAO,IAAIvB;AAAGe,MAAAA,SAAS,EAAC,cAAA;KAAiB,CAAA,EAC3CF,QAAQ,CACF,CAAA;AAEb,GAAA;AACD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './style/index.scss.js';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { omit } from '../../utils/index.js';
|
|
5
|
+
|
|
6
|
+
const Icon = props => {
|
|
7
|
+
let {
|
|
8
|
+
type,
|
|
9
|
+
className = '',
|
|
10
|
+
size = '23',
|
|
11
|
+
color
|
|
12
|
+
} = props;
|
|
13
|
+
if (type) type = type.replace(/_/g, '-');
|
|
14
|
+
const cls = classNames({
|
|
15
|
+
[`weui-icon-${type}`]: true
|
|
16
|
+
}, className);
|
|
17
|
+
const style = {
|
|
18
|
+
'font-size': size + 'px',
|
|
19
|
+
color: color
|
|
20
|
+
};
|
|
21
|
+
return React.createElement("i", Object.assign({}, omit(props, ['type', 'className']), {
|
|
22
|
+
className: cls,
|
|
23
|
+
style: style
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { Icon as default };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/icon/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\nimport React from 'react'\n\nimport { omit } from '../../utils'\n\n\ninterface IProps {\n type: string\n color: string\n size?: number | string\n className?: string\n}\n\nconst Icon = (props: IProps) => {\n let { type, className = '', size = '23', color } = props\n if (type) type = type.replace(/_/g, '-')\n const cls = classNames(\n {\n [`weui-icon-${type}`]: true\n },\n className\n )\n const style = { 'font-size': size + 'px', color: color }\n\n return (\n <i {...omit(props, ['type', 'className'])} className={cls} style={style} />\n )\n}\nexport default Icon\n"],"names":["Icon","props","type","className","size","color","replace","cls","classNames","style","React","omit"],"mappings":";;;;;AAeMA,MAAAA,IAAI,GAAIC,KAAa,IAAI;EAC7B,IAAI;IAAEC,IAAI;AAAEC,IAAAA,SAAS,GAAG,EAAE;AAAEC,IAAAA,IAAI,GAAG,IAAI;AAAEC,IAAAA,KAAAA;AAAO,GAAA,GAAGJ,KAAK,CAAA;EACxD,IAAIC,IAAI,EAAEA,IAAI,GAAGA,IAAI,CAACI,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;EACxC,MAAMC,GAAG,GAAGC,UAAU,CACpB;IACE,CAAc,CAAA,UAAA,EAAAN,IAAM,CAAA,CAAA,GAAG,IAAA;GACxB,EACDC,SAAS,CACV,CAAA;AACD,EAAA,MAAMM,KAAK,GAAG;IAAE,WAAW,EAAEL,IAAI,GAAG,IAAI;AAAEC,IAAAA,KAAK,EAAEA,KAAAA;GAAO,CAAA;EAExD,OACEK,2CAAOC,IAAI,CAACV,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE;AAAAE,IAAAA,SAAS,EAAEI,GAAG;AAAEE,IAAAA,KAAK,EAAEA,KAAAA;AAAS,GAAA,CAAA,CAAA,CAAA;AAE/E;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,111 +1,89 @@
|
|
|
1
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
-
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
4
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
5
|
-
import _createSuper from '@babel/runtime/helpers/createSuper';
|
|
6
1
|
import { __rest } from 'tslib';
|
|
7
2
|
import './style/index.css.js';
|
|
8
3
|
import classNames from 'classnames';
|
|
9
4
|
import React from 'react';
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_this = _super.call(this, props);
|
|
18
|
-
_this.observer = {};
|
|
19
|
-
_this.imgRef = null;
|
|
20
|
-
_this.state = {
|
|
6
|
+
class Image extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.observer = {};
|
|
10
|
+
this.imgRef = null;
|
|
11
|
+
this.state = {
|
|
21
12
|
isLoaded: false
|
|
22
13
|
};
|
|
23
|
-
|
|
14
|
+
this.imageOnLoad = this.imageOnLoad.bind(this);
|
|
24
15
|
// this.observer = {}
|
|
25
|
-
return _this;
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_this2.imgRef.src = _this2.props.src;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
rootMargin: '300px 0px'
|
|
44
|
-
});
|
|
45
|
-
this.observer.observe(this.imgRef);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
key: "componentWillUnmount",
|
|
50
|
-
value: function componentWillUnmount() {
|
|
51
|
-
this.observer.disconnect && this.observer.disconnect();
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "imageOnLoad",
|
|
55
|
-
value: function imageOnLoad(e) {
|
|
56
|
-
var onLoad = this.props.onLoad;
|
|
57
|
-
Object.defineProperty(e, 'detail', {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: {
|
|
61
|
-
width: e.target.width,
|
|
62
|
-
height: e.target.height
|
|
17
|
+
|
|
18
|
+
componentDidMount() {
|
|
19
|
+
if (this.props.lazyLoad) {
|
|
20
|
+
this.observer = new IntersectionObserver(entries => {
|
|
21
|
+
// 异步 api 关系
|
|
22
|
+
if (entries[entries.length - 1].isIntersecting) {
|
|
23
|
+
this.setState({
|
|
24
|
+
isLoaded: true
|
|
25
|
+
}, () => {
|
|
26
|
+
// findDOMNode(this).children[0].src = this.props.src
|
|
27
|
+
this.imgRef.src = this.props.src;
|
|
28
|
+
});
|
|
63
29
|
}
|
|
30
|
+
}, {
|
|
31
|
+
rootMargin: '300px 0px'
|
|
64
32
|
});
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "render",
|
|
69
|
-
value: function render() {
|
|
70
|
-
var _this3 = this;
|
|
71
|
-
var _a = this.props,
|
|
72
|
-
className = _a.className,
|
|
73
|
-
_a$style = _a.style,
|
|
74
|
-
style = _a$style === void 0 ? {} : _a$style,
|
|
75
|
-
src = _a.src,
|
|
76
|
-
mode = _a.mode,
|
|
77
|
-
onError = _a.onError,
|
|
78
|
-
lazyLoad = _a.lazyLoad,
|
|
79
|
-
imgProps = _a.imgProps,
|
|
80
|
-
reset = __rest(_a, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps"]);
|
|
81
|
-
var cls = classNames('taro-img', {
|
|
82
|
-
'taro-img__widthfix': mode === 'widthFix'
|
|
83
|
-
}, className);
|
|
84
|
-
var imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
|
|
85
|
-
return React.createElement("div", Object.assign({
|
|
86
|
-
className: cls,
|
|
87
|
-
style: style
|
|
88
|
-
}, reset), lazyLoad ? React.createElement("img", Object.assign({
|
|
89
|
-
ref: function ref(img) {
|
|
90
|
-
return _this3.imgRef = img;
|
|
91
|
-
},
|
|
92
|
-
className: imgCls,
|
|
93
|
-
"data-src": src,
|
|
94
|
-
onLoad: this.imageOnLoad,
|
|
95
|
-
onError: onError
|
|
96
|
-
}, imgProps)) : React.createElement("img", Object.assign({
|
|
97
|
-
ref: function ref(img) {
|
|
98
|
-
return _this3.imgRef = img;
|
|
99
|
-
},
|
|
100
|
-
className: imgCls,
|
|
101
|
-
src: src,
|
|
102
|
-
onLoad: this.imageOnLoad,
|
|
103
|
-
onError: onError
|
|
104
|
-
}, imgProps)));
|
|
33
|
+
this.observer.observe(this.imgRef);
|
|
105
34
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
35
|
+
}
|
|
36
|
+
componentWillUnmount() {
|
|
37
|
+
this.observer.disconnect && this.observer.disconnect();
|
|
38
|
+
}
|
|
39
|
+
imageOnLoad(e) {
|
|
40
|
+
const {
|
|
41
|
+
onLoad
|
|
42
|
+
} = this.props;
|
|
43
|
+
Object.defineProperty(e, 'detail', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: {
|
|
47
|
+
width: e.target.width,
|
|
48
|
+
height: e.target.height
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
onLoad && onLoad(e);
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
const _a = this.props,
|
|
55
|
+
{
|
|
56
|
+
className,
|
|
57
|
+
style = {},
|
|
58
|
+
src,
|
|
59
|
+
mode,
|
|
60
|
+
onError,
|
|
61
|
+
lazyLoad,
|
|
62
|
+
imgProps
|
|
63
|
+
} = _a,
|
|
64
|
+
reset = __rest(_a, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps"]);
|
|
65
|
+
const cls = classNames('taro-img', {
|
|
66
|
+
'taro-img__widthfix': mode === 'widthFix'
|
|
67
|
+
}, className);
|
|
68
|
+
const imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
|
|
69
|
+
return React.createElement("div", Object.assign({
|
|
70
|
+
className: cls,
|
|
71
|
+
style: style
|
|
72
|
+
}, reset), lazyLoad ? React.createElement("img", Object.assign({
|
|
73
|
+
ref: img => this.imgRef = img,
|
|
74
|
+
className: imgCls,
|
|
75
|
+
"data-src": src,
|
|
76
|
+
onLoad: this.imageOnLoad,
|
|
77
|
+
onError: onError
|
|
78
|
+
}, imgProps)) : React.createElement("img", Object.assign({
|
|
79
|
+
ref: img => this.imgRef = img,
|
|
80
|
+
className: imgCls,
|
|
81
|
+
src: src,
|
|
82
|
+
onLoad: this.imageOnLoad,
|
|
83
|
+
onError: onError
|
|
84
|
+
}, imgProps)));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
109
87
|
|
|
110
88
|
export { Image as default };
|
|
111
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.css'\n\nimport classNames from 'classnames'\nimport 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}\n\nclass Image extends React.Component<IProps> {\n constructor (props) {\n super(props)\n this.state = {\n isLoaded: false\n }\n this.imageOnLoad = this.imageOnLoad.bind(this)\n // this.observer = {}\n }\n\n observer: any = {}\n imgRef: any = null\n\n componentDidMount () {\n if (this.props.lazyLoad) {\n this.observer = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n this.setState({ isLoaded: true }, () => {\n // findDOMNode(this).children[0].src = this.props.src\n this.imgRef.src = this.props.src\n })\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n this.observer.observe(this.imgRef)\n }\n }\n\n componentWillUnmount () {\n this.observer.disconnect && this.observer.disconnect()\n }\n\n imageOnLoad (e) {\n const { onLoad } = this.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 }\n\n render () {\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n ...reset\n } = this.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 return (\n <div className={cls} style={style} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (this.imgRef = img)}\n className={imgCls}\n data-src={src}\n onLoad={this.imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (this.imgRef = img)}\n className={imgCls}\n src={src}\n onLoad={this.imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n }\n}\n\nexport default Image\n"],"names":["Image","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.css'\n\nimport classNames from 'classnames'\nimport 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}\n\nclass Image extends React.Component<IProps> {\n constructor (props) {\n super(props)\n this.state = {\n isLoaded: false\n }\n this.imageOnLoad = this.imageOnLoad.bind(this)\n // this.observer = {}\n }\n\n observer: any = {}\n imgRef: any = null\n\n componentDidMount () {\n if (this.props.lazyLoad) {\n this.observer = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n this.setState({ isLoaded: true }, () => {\n // findDOMNode(this).children[0].src = this.props.src\n this.imgRef.src = this.props.src\n })\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n this.observer.observe(this.imgRef)\n }\n }\n\n componentWillUnmount () {\n this.observer.disconnect && this.observer.disconnect()\n }\n\n imageOnLoad (e) {\n const { onLoad } = this.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 }\n\n render () {\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n ...reset\n } = this.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 return (\n <div className={cls} style={style} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (this.imgRef = img)}\n className={imgCls}\n data-src={src}\n onLoad={this.imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (this.imgRef = img)}\n className={imgCls}\n src={src}\n onLoad={this.imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n }\n}\n\nexport default Image\n"],"names":["Image","React","Component","constructor","props","observer","imgRef","state","isLoaded","imageOnLoad","bind","componentDidMount","lazyLoad","IntersectionObserver","entries","length","isIntersecting","setState","src","rootMargin","observe","componentWillUnmount","disconnect","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","render","_a","className","style","mode","onError","imgProps","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","createElement","assign","ref","img"],"mappings":";;;;;AAcA,MAAMA,KAAM,SAAQC,KAAK,CAACC,SAAiB,CAAA;EACzCC,WAAAA,CAAaC,KAAK,EAAA;IAChB,KAAK,CAACA,KAAK,CAAC,CAAA;AAQd,IAAA,IAAQ,CAAAC,QAAA,GAAQ,EAAE,CAAA;IAClB,IAAM,CAAAC,MAAA,GAAQ,IAAI,CAAA;IARhB,IAAI,CAAC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AAC,QAAQ,EACZ,GAEFtC;AACEgD,MAAAA,GAAG,EAAEC,GAAG,IAAK,IAAI,CAAC5C,MAAM,GAAG4C,GAAI;AAC/Bf,MAAAA,SAAS,EAAES,MAAM;AACjB1B,MAAAA,GAAG,EAAEA,GAAG;MACRM,MAAM,EAAE,IAAI,CAACf,WAAW;AACxB6B,MAAAA,OAAO,EAAEA,OAAAA;AAAO,KAAA,EACZC,QAAQ,CACZ,CACH,CACG,CAAA;AAEV,GAAA;AACD;;;;"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var undefined$1 = undefined;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var stylesheet="img[src=\"\"]{opacity:0}.taro-img{display:inline-block;font-size:0;height:240px;overflow:hidden;position:relative;width:320px}.taro-img.taro-img__widthfix{height:100%}.taro-img__mode-aspectfit,.taro-img__mode-scaletofill{height:100%;object-fit:contain;width:100%}.taro-img__mode-aspectfill{height:100%;object-fit:cover;width:100%}.taro-img__mode-top,.taro-img__mode-widthfix{width:100%}.taro-img__mode-bottom{bottom:0;position:absolute;width:100%}.taro-img__mode-left{height:100%}.taro-img__mode-right{height:100%}.taro-img__mode-right,.taro-img__mode-topright{position:absolute;right:0}.taro-img__mode-bottomleft{bottom:0;position:absolute}.taro-img__mode-bottomright{bottom:0;position:absolute;right:0}";
|
|
5
|
-
styleInject(css_248z,{"insertAt":"top"});
|
|
6
|
-
|
|
7
|
-
export { css_248z as default, stylesheet };
|
|
3
|
+
export { undefined$1 as default };
|
|
8
4
|
//# sourceMappingURL=index.css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import './style/index.scss.js';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { omit } from '../../utils/index.js';
|
|
5
|
+
|
|
6
|
+
function getTrueType(type, confirmType, password) {
|
|
7
|
+
if (confirmType === 'search') type = 'search';
|
|
8
|
+
if (password) type = 'password';
|
|
9
|
+
if (typeof type === 'undefined') {
|
|
10
|
+
return 'text';
|
|
11
|
+
}
|
|
12
|
+
if (!type) {
|
|
13
|
+
throw new Error('unexpected type');
|
|
14
|
+
}
|
|
15
|
+
if (type === 'digit') type = 'number';
|
|
16
|
+
return type;
|
|
17
|
+
}
|
|
18
|
+
function fixControlledValue(value) {
|
|
19
|
+
return value !== null && value !== void 0 ? value : '';
|
|
20
|
+
}
|
|
21
|
+
class Input extends React.Component {
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props);
|
|
24
|
+
this.handleBeforeInput = e => {
|
|
25
|
+
if (!e.data) return;
|
|
26
|
+
const isNumber = e.data && /[0-9]/.test(e.data);
|
|
27
|
+
if (this.props.type === 'number' && !isNumber) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
}
|
|
30
|
+
if (this.props.type === 'digit' && !isNumber) {
|
|
31
|
+
if (e.data !== '.' || e.data === '.' && e.target.value.indexOf('.') > -1) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.handleInput = this.handleInput.bind(this);
|
|
37
|
+
this.handlePaste = this.handlePaste.bind(this);
|
|
38
|
+
this.handleFocus = this.handleFocus.bind(this);
|
|
39
|
+
this.handleBlur = this.handleBlur.bind(this);
|
|
40
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
41
|
+
this.handleComposition = this.handleComposition.bind(this);
|
|
42
|
+
this.handleBeforeInput = this.handleBeforeInput.bind(this);
|
|
43
|
+
this.isOnComposition = false;
|
|
44
|
+
this.onInputExcuted = false;
|
|
45
|
+
}
|
|
46
|
+
componentDidMount() {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
// 修复无法选择文件
|
|
49
|
+
if (this.props.type === 'file') {
|
|
50
|
+
(_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.addEventListener('change', this.handleInput);
|
|
51
|
+
} else {
|
|
52
|
+
(_b = this.inputRef) === null || _b === void 0 ? void 0 : _b.addEventListener('textInput', this.handleBeforeInput);
|
|
53
|
+
}
|
|
54
|
+
// 处理初始化是否 focus
|
|
55
|
+
if (this.props.focus && this.inputRef) this.inputRef.focus();
|
|
56
|
+
}
|
|
57
|
+
componentWillUnmount() {
|
|
58
|
+
var _a;
|
|
59
|
+
// 修复无法选择文件
|
|
60
|
+
if (this.props.type === 'file') {
|
|
61
|
+
this.inputRef.removeEventListener('change', this.handleInput);
|
|
62
|
+
} else {
|
|
63
|
+
(_a = this.inputRef) === null || _a === void 0 ? void 0 : _a.removeEventListener('textInput', this.handleBeforeInput);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
67
|
+
if (!this.props.focus && nextProps.focus && this.inputRef) this.inputRef.focus();
|
|
68
|
+
}
|
|
69
|
+
handleInput(e) {
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
const {
|
|
72
|
+
type,
|
|
73
|
+
maxlength = 140,
|
|
74
|
+
confirmType = 'done',
|
|
75
|
+
password = false,
|
|
76
|
+
onInput
|
|
77
|
+
} = this.props;
|
|
78
|
+
if (!this.isOnComposition && !this.onInputExcuted) {
|
|
79
|
+
let {
|
|
80
|
+
value
|
|
81
|
+
} = e.target;
|
|
82
|
+
const inputType = getTrueType(type, confirmType, password);
|
|
83
|
+
this.onInputExcuted = true;
|
|
84
|
+
/* 修复 number 类型 maxLength 无效 */
|
|
85
|
+
if (inputType === 'number' && value && maxlength <= value.length) {
|
|
86
|
+
value = value.substring(0, maxlength);
|
|
87
|
+
e.target.value = value;
|
|
88
|
+
}
|
|
89
|
+
Object.defineProperty(e, 'detail', {
|
|
90
|
+
value: {
|
|
91
|
+
value,
|
|
92
|
+
cursor: value.length
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// // 修复 IOS 光标跳转问题
|
|
96
|
+
// if (!(['number', 'file'].indexOf(inputType) >= 0)) {
|
|
97
|
+
// const pos = e.target.selectionEnd
|
|
98
|
+
// setTimeout(
|
|
99
|
+
// () => {
|
|
100
|
+
// e.target.selectionStart = pos
|
|
101
|
+
// e.target.selectionEnd = pos
|
|
102
|
+
// }
|
|
103
|
+
// )
|
|
104
|
+
// }
|
|
105
|
+
typeof onInput === 'function' && onInput(e);
|
|
106
|
+
this.onInputExcuted = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
handlePaste(e) {
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
const {
|
|
112
|
+
onPaste
|
|
113
|
+
} = this.props;
|
|
114
|
+
this.onInputExcuted = false;
|
|
115
|
+
Object.defineProperty(e, 'detail', {
|
|
116
|
+
value: {
|
|
117
|
+
value: e.target.value
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
typeof onPaste === 'function' && onPaste(e);
|
|
121
|
+
}
|
|
122
|
+
handleFocus(e) {
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
const {
|
|
125
|
+
onFocus
|
|
126
|
+
} = this.props;
|
|
127
|
+
this.onInputExcuted = false;
|
|
128
|
+
Object.defineProperty(e, 'detail', {
|
|
129
|
+
value: {
|
|
130
|
+
value: e.target.value
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
onFocus && onFocus(e);
|
|
134
|
+
}
|
|
135
|
+
handleBlur(e) {
|
|
136
|
+
e.stopPropagation();
|
|
137
|
+
const {
|
|
138
|
+
onBlur
|
|
139
|
+
} = this.props;
|
|
140
|
+
Object.defineProperty(e, 'detail', {
|
|
141
|
+
value: {
|
|
142
|
+
value: e.target.value
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
onBlur && onBlur(e);
|
|
146
|
+
}
|
|
147
|
+
handleKeyDown(e) {
|
|
148
|
+
e.stopPropagation();
|
|
149
|
+
const {
|
|
150
|
+
onConfirm,
|
|
151
|
+
onKeyDown
|
|
152
|
+
} = this.props;
|
|
153
|
+
const {
|
|
154
|
+
value
|
|
155
|
+
} = e.target;
|
|
156
|
+
const keyCode = e.keyCode || e.code;
|
|
157
|
+
this.onInputExcuted = false;
|
|
158
|
+
if (typeof onKeyDown === 'function') {
|
|
159
|
+
Object.defineProperty(e, 'detail', {
|
|
160
|
+
value: {
|
|
161
|
+
value,
|
|
162
|
+
cursor: value.length,
|
|
163
|
+
keyCode
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
onKeyDown(e);
|
|
167
|
+
}
|
|
168
|
+
if (e.keyCode === 13 && typeof onConfirm === 'function') {
|
|
169
|
+
Object.defineProperty(e, 'detail', {
|
|
170
|
+
value: {
|
|
171
|
+
value
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
onConfirm(e);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
handleComposition(e) {
|
|
178
|
+
e.stopPropagation();
|
|
179
|
+
if (!(e.target instanceof HTMLInputElement)) return;
|
|
180
|
+
if (e.type === 'compositionend') {
|
|
181
|
+
this.isOnComposition = false;
|
|
182
|
+
this.handleInput(e);
|
|
183
|
+
} else {
|
|
184
|
+
this.isOnComposition = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
render() {
|
|
188
|
+
const {
|
|
189
|
+
className = '',
|
|
190
|
+
placeholder,
|
|
191
|
+
type,
|
|
192
|
+
password = false,
|
|
193
|
+
disabled = false,
|
|
194
|
+
maxlength = 140,
|
|
195
|
+
confirmType = 'done',
|
|
196
|
+
name,
|
|
197
|
+
value
|
|
198
|
+
} = this.props;
|
|
199
|
+
const cls = classNames('taro-input-core', 'weui-input', className);
|
|
200
|
+
const otherProps = omit(this.props, ['className', 'placeholder', 'disabled', 'password', 'type', 'maxlength', 'confirmType', 'focus', 'name']);
|
|
201
|
+
if ('value' in this.props) {
|
|
202
|
+
otherProps.value = fixControlledValue(value);
|
|
203
|
+
}
|
|
204
|
+
return React.createElement("input", Object.assign({
|
|
205
|
+
ref: input => {
|
|
206
|
+
this.inputRef = input;
|
|
207
|
+
}
|
|
208
|
+
}, otherProps, {
|
|
209
|
+
className: cls,
|
|
210
|
+
type: getTrueType(type, confirmType, password),
|
|
211
|
+
placeholder: placeholder,
|
|
212
|
+
disabled: disabled,
|
|
213
|
+
maxLength: maxlength,
|
|
214
|
+
name: name,
|
|
215
|
+
onInput: this.handleInput,
|
|
216
|
+
onPaste: this.handlePaste,
|
|
217
|
+
onFocus: this.handleFocus,
|
|
218
|
+
onBlur: this.handleBlur,
|
|
219
|
+
onKeyDown: this.handleKeyDown,
|
|
220
|
+
onCompositionStart: this.handleComposition,
|
|
221
|
+
onCompositionEnd: this.handleComposition,
|
|
222
|
+
onBeforeInput: this.handleBeforeInput
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { Input as default };
|
|
228
|
+
//# sourceMappingURL=index.js.map
|