@tarojs/components-react 4.1.12-beta.4 → 4.1.12-beta.40

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/components/image/index.js +5 -3
  2. package/dist/components/image/index.js.map +1 -1
  3. package/dist/components/map/MapContext.js +628 -0
  4. package/dist/components/map/MapContext.js.map +1 -0
  5. package/dist/components/map/MapCustomCallout.js +91 -0
  6. package/dist/components/map/MapCustomCallout.js.map +1 -0
  7. package/dist/components/map/common.js +4 -0
  8. package/dist/components/map/common.js.map +1 -0
  9. package/dist/components/map/createMapContext.js +34 -0
  10. package/dist/components/map/createMapContext.js.map +1 -0
  11. package/dist/components/map/handler.js +50 -0
  12. package/dist/components/map/handler.js.map +1 -0
  13. package/dist/components/map/index.js +327 -0
  14. package/dist/components/map/index.js.map +1 -0
  15. package/dist/components/picker/picker-group.js +130 -70
  16. package/dist/components/picker/picker-group.js.map +1 -1
  17. package/dist/components/scroll-view/index.js +51 -23
  18. package/dist/components/scroll-view/index.js.map +1 -1
  19. package/dist/components/switch/index.js +125 -0
  20. package/dist/components/switch/index.js.map +1 -0
  21. package/dist/components/switch/style/index.scss.js +4 -0
  22. package/dist/components/switch/style/index.scss.js.map +1 -0
  23. package/dist/contexts/ScrollElementContext.js +6 -0
  24. package/dist/contexts/ScrollElementContext.js.map +1 -0
  25. package/dist/index.css +1 -1
  26. package/dist/index.js +5 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/original/components/image/index.js +5 -3
  29. package/dist/original/components/image/index.js.map +1 -1
  30. package/dist/original/components/image/style/index.scss +5 -1
  31. package/dist/original/components/map/MapContext.js +628 -0
  32. package/dist/original/components/map/MapContext.js.map +1 -0
  33. package/dist/original/components/map/MapCustomCallout.js +91 -0
  34. package/dist/original/components/map/MapCustomCallout.js.map +1 -0
  35. package/dist/original/components/map/common.js +4 -0
  36. package/dist/original/components/map/common.js.map +1 -0
  37. package/dist/original/components/map/createMapContext.js +34 -0
  38. package/dist/original/components/map/createMapContext.js.map +1 -0
  39. package/dist/original/components/map/handler.js +50 -0
  40. package/dist/original/components/map/handler.js.map +1 -0
  41. package/dist/original/components/map/index.js +327 -0
  42. package/dist/original/components/map/index.js.map +1 -0
  43. package/dist/original/components/picker/picker-group.js +130 -70
  44. package/dist/original/components/picker/picker-group.js.map +1 -1
  45. package/dist/original/components/scroll-view/index.js +51 -23
  46. package/dist/original/components/scroll-view/index.js.map +1 -1
  47. package/dist/original/components/switch/index.js +125 -0
  48. package/dist/original/components/switch/index.js.map +1 -0
  49. package/dist/original/components/switch/style/index.scss +35 -0
  50. package/dist/original/contexts/ScrollElementContext.js +6 -0
  51. package/dist/original/contexts/ScrollElementContext.js.map +1 -0
  52. package/dist/original/index.js +5 -1
  53. package/dist/original/index.js.map +1 -1
  54. package/dist/solid/components/image/index.js +5 -3
  55. package/dist/solid/components/image/index.js.map +1 -1
  56. package/dist/solid/components/picker/picker-group.js +130 -70
  57. package/dist/solid/components/picker/picker-group.js.map +1 -1
  58. package/dist/solid/components/scroll-view/index.js +55 -27
  59. package/dist/solid/components/scroll-view/index.js.map +1 -1
  60. package/dist/solid/contexts/ScrollElementContext.js +6 -0
  61. package/dist/solid/contexts/ScrollElementContext.js.map +1 -0
  62. package/dist/solid/index.css +1 -1
  63. package/package.json +8 -6
@@ -0,0 +1,125 @@
1
+ import { __rest } from 'tslib';
2
+ import './style/index.scss';
3
+ import { View } from '@tarojs/components';
4
+ import classNames from 'classnames';
5
+ import { omit, createForwardRefComponent } from '../../utils/index.js';
6
+ import { useState, useCallback } from '../../utils/hooks.react.js';
7
+ import { jsx } from 'react/jsx-runtime';
8
+
9
+ function Switch(props) {
10
+ const {
11
+ type = 'switch',
12
+ checked: controlledChecked,
13
+ defaultChecked = false,
14
+ disabled = false,
15
+ color = '#04BE02',
16
+ width,
17
+ height,
18
+ beforeChange,
19
+ nativeProps = {},
20
+ onChange,
21
+ forwardedRef,
22
+ className,
23
+ style
24
+ } = props,
25
+ rest = __rest(props, ["type", "checked", "defaultChecked", "disabled", "color", "width", "height", "beforeChange", "nativeProps", "onChange", "forwardedRef", "className", "style"]);
26
+ const [innerChecked, setInnerChecked] = useState(defaultChecked);
27
+ const [loading, setLoading] = useState(false);
28
+ const isChecked = controlledChecked !== undefined ? controlledChecked : innerChecked;
29
+ const applyChange = useCallback(value => {
30
+ if (controlledChecked === undefined) {
31
+ setInnerChecked(value);
32
+ }
33
+ const e = {
34
+ detail: {
35
+ value
36
+ }
37
+ };
38
+ onChange && onChange(e);
39
+ }, [controlledChecked, onChange]);
40
+ const handleToggle = useCallback(newValue => {
41
+ if (disabled || loading) return;
42
+ if (beforeChange) {
43
+ const result = beforeChange(newValue);
44
+ if (result === false) return;
45
+ if (result instanceof Promise) {
46
+ setLoading(true);
47
+ result.then(asyncResult => {
48
+ setLoading(false);
49
+ if (asyncResult === false) return;
50
+ applyChange(newValue);
51
+ }, () => {
52
+ setLoading(false);
53
+ });
54
+ return;
55
+ }
56
+ }
57
+ applyChange(newValue);
58
+ }, [disabled, loading, beforeChange, applyChange]);
59
+ const isSwitch = type === 'switch';
60
+ const sw = width !== null && width !== void 0 ? width : isSwitch ? 52 : 20;
61
+ const sh = height !== null && height !== void 0 ? height : isSwitch ? 32 : 20;
62
+ const dynamicStyle = isSwitch ? {
63
+ width: `${sw}px`,
64
+ height: `${sh}px`,
65
+ borderRadius: `${sh / 2}px`,
66
+ backgroundColor: isChecked ? color : '#DFDFDF',
67
+ borderColor: isChecked ? color : '#DFDFDF'
68
+ } : {
69
+ width: `${sh}px`,
70
+ height: `${sh}px`,
71
+ borderRadius: '4px',
72
+ backgroundColor: isChecked ? color : 'transparent',
73
+ borderColor: isChecked ? color : '#c9c9c9'
74
+ };
75
+ const cls = classNames('taro-switch', `taro-switch--type-${type}`, {
76
+ 'taro-switch--checked': isChecked,
77
+ 'taro-switch--disabled': disabled
78
+ }, className);
79
+ const rootStyle = Object.assign(Object.assign({}, dynamicStyle), style);
80
+ const onClick = e => {
81
+ e.stopPropagation();
82
+ handleToggle(!isChecked);
83
+ };
84
+ if (isSwitch) {
85
+ const thumbStyle = {
86
+ width: `${sh - 4}px`,
87
+ height: `${sh - 4}px`,
88
+ transform: isChecked ? `translateX(${sw - sh}px)` : undefined
89
+ };
90
+ return /*#__PURE__*/jsx(View, {
91
+ className: cls,
92
+ style: rootStyle,
93
+ ref: forwardedRef,
94
+ onClick: onClick,
95
+ ...omit(rest, ['forwardedRef']),
96
+ ...nativeProps,
97
+ children: /*#__PURE__*/jsx(View, {
98
+ className: "taro-switch__thumb",
99
+ style: thumbStyle
100
+ })
101
+ });
102
+ }
103
+ return /*#__PURE__*/jsx(View, {
104
+ className: cls,
105
+ style: rootStyle,
106
+ ref: forwardedRef,
107
+ onClick: onClick,
108
+ ...omit(rest, ['forwardedRef']),
109
+ ...nativeProps,
110
+ children: /*#__PURE__*/jsx(View, {
111
+ className: "taro-switch__checkmark",
112
+ style: {
113
+ width: `${Math.round(sh * 0.3)}px`,
114
+ height: `${Math.round(sh * 0.5)}px`,
115
+ borderRight: `${Math.round(sh * 0.1)}px solid #fff`,
116
+ borderBottom: `${Math.round(sh * 0.1)}px solid #fff`,
117
+ transform: isChecked ? `translate(-50%, -65%) rotate(45deg) scale(1)` : `translate(-50%, -65%) rotate(45deg) scale(0)`
118
+ }
119
+ })
120
+ });
121
+ }
122
+ var index = createForwardRefComponent(Switch);
123
+
124
+ export { index as default };
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/switch/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport { View } from '@tarojs/components'\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent, omit } from '../../utils'\nimport { useCallback, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\nexport type BeforeChange = (value: boolean) => boolean | Promise<boolean>\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n type?: 'switch' | 'checkbox'\n checked?: boolean\n defaultChecked?: boolean\n disabled?: boolean\n color?: string\n width?: number\n height?: number\n beforeChange?: BeforeChange\n nativeProps?: Record<string, any>\n onChange?: (e: any) => void\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\nfunction Switch (props: IProps) {\n const {\n type = 'switch',\n checked: controlledChecked,\n defaultChecked = false,\n disabled = false,\n color = '#04BE02',\n width,\n height,\n beforeChange,\n nativeProps = {},\n onChange,\n forwardedRef,\n className,\n style,\n ...rest\n } = props\n\n const [innerChecked, setInnerChecked] = useState(defaultChecked)\n const [loading, setLoading] = useState(false)\n\n const isChecked = controlledChecked !== undefined\n ? controlledChecked\n : innerChecked\n\n const applyChange = useCallback((value: boolean) => {\n if (controlledChecked === undefined) {\n setInnerChecked(value)\n }\n\n const e = { detail: { value } }\n onChange && onChange(e)\n }, [controlledChecked, onChange])\n\n const handleToggle = useCallback((newValue: boolean) => {\n if (disabled || loading) return\n\n if (beforeChange) {\n const result = beforeChange(newValue)\n\n if (result === false) return\n\n if (result instanceof Promise) {\n setLoading(true)\n result\n .then((asyncResult) => {\n setLoading(false)\n if (asyncResult === false) return\n applyChange(newValue)\n }, () => {\n setLoading(false)\n })\n return\n }\n }\n\n applyChange(newValue)\n }, [disabled, loading, beforeChange, applyChange])\n\n const isSwitch = type === 'switch'\n const sw = width ?? (isSwitch ? 52 : 20)\n const sh = height ?? (isSwitch ? 32 : 20)\n\n const dynamicStyle: React.CSSProperties = isSwitch ? {\n width: `${sw}px`,\n height: `${sh}px`,\n borderRadius: `${sh / 2}px`,\n backgroundColor: isChecked ? color : '#DFDFDF',\n borderColor: isChecked ? color : '#DFDFDF'\n } : {\n width: `${sh}px`,\n height: `${sh}px`,\n borderRadius: '4px',\n backgroundColor: isChecked ? color : 'transparent',\n borderColor: isChecked ? color : '#c9c9c9'\n }\n\n const cls = classNames(\n 'taro-switch',\n `taro-switch--type-${type}`,\n {\n 'taro-switch--checked': isChecked,\n 'taro-switch--disabled': disabled\n },\n className\n )\n\n const rootStyle = {\n ...dynamicStyle,\n ...style\n } as unknown as React.CSSProperties\n\n const onClick = (e: React.MouseEvent) => {\n e.stopPropagation()\n handleToggle(!isChecked)\n }\n\n if (isSwitch) {\n const thumbStyle: React.CSSProperties = {\n width: `${sh - 4}px`,\n height: `${sh - 4}px`,\n transform: isChecked ? `translateX(${sw - sh}px)` : undefined\n }\n return (\n <View\n className={cls}\n style={rootStyle}\n ref={forwardedRef}\n onClick={onClick}\n {...omit(rest, ['forwardedRef'])}\n {...nativeProps}\n >\n <View className='taro-switch__thumb' style={thumbStyle} />\n </View>\n )\n }\n\n return (\n <View\n className={cls}\n style={rootStyle}\n ref={forwardedRef}\n onClick={onClick}\n {...omit(rest, ['forwardedRef'])}\n {...nativeProps}\n >\n <View\n className='taro-switch__checkmark'\n style={{\n width: `${Math.round(sh * 0.3)}px`,\n height: `${Math.round(sh * 0.5)}px`,\n borderRight: `${Math.round(sh * 0.1)}px solid #fff`,\n borderBottom: `${Math.round(sh * 0.1)}px solid #fff`,\n transform: isChecked\n ? `translate(-50%, -65%) rotate(45deg) scale(1)`\n : `translate(-50%, -65%) rotate(45deg) scale(0)`\n }}\n />\n </View>\n )\n}\n\nexport default createForwardRefComponent(Switch)\n"],"names":["Switch","props","type","checked","controlledChecked","defaultChecked","disabled","color","width","height","beforeChange","nativeProps","onChange","forwardedRef","className","style","rest","innerChecked","setInnerChecked","useState","loading","setLoading","isChecked","undefined","applyChange","useCallback","value","e","detail","handleToggle","newValue","result","Promise","then","asyncResult","isSwitch","sw","sh","dynamicStyle","borderRadius","backgroundColor","borderColor","cls","classNames","rootStyle","Object","assign","onClick","stopPropagation","thumbStyle","transform","_jsx","View","ref","omit","children","Math","round","borderRight","borderBottom","createForwardRefComponent"],"mappings":";;;;;;;;AA0BA,SAASA,MAAMA,CAAEC,KAAa,EAAA;EAC5B,MAAM;AACJC,MAAAA,IAAI,GAAG,QAAQ;AACfC,MAAAA,OAAO,EAAEC,iBAAiB;AAC1BC,MAA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AAS,EAAC,oBAAoB;AAACC,QAAAA,KAAK,EAAEkC;OAC9C;AAAA,KAAM,CAAC;AAEX;EAEA,oBACEE,GAAA,CAACC,IAAI,EAAA;AACHtC,IAAAA,SAAS,EAAE4B,GAAI;AACf3B,IAAAA,KAAK,EAAE6B,SAAU;AACjBS,IAAAA,GAAG,EAAExC,YAAa;AAClBkC,IAAAA,OAAO,EAAEA,OAAQ;AAAA,IAAA,GACbO,IAAI,CAACtC,IAAI,EAAE,CAAC,cAAc,CAAC,CAAC;AAAA,IAAA,GAC5BL,WAAW;IAAA4C,QAAA,eAEfJ,GAAA,CAACC,IAAI,EAAA;AACHtC,MAAAA,SAAS,EAAC,wBAAwB;AAClCC,MAAAA,KAAK,EAAE;QACLP,KAAK,EAAE,CAAGgD,EAAAA,IAAI,CAACC,KAAK,CAACpB,EAAE,GAAG,GAAG,CAAC,CAAI,EAAA,CAAA;QAClC5B,MAAM,EAAE,CAAG+C,EAAAA,IAAI,CAACC,KAAK,CAACpB,EAAE,GAAG,GAAG,CAAC,CAAI,EAAA,CAAA;QACnCqB,WAAW,EAAE,CAAGF,EAAAA,IAAI,CAACC,KAAK,CAACpB,EAAE,GAAG,GAAG,CAAC,CAAe,aAAA,CAAA;QACnDsB,YAAY,EAAE,CAAGH,EAAAA,IAAI,CAACC,KAAK,CAACpB,EAAE,GAAG,GAAG,CAAC,CAAe,aAAA,CAAA;AACpDa,QAAAA,SAAS,EAAE5B,SAAS,GAChB,CAAA,4CAAA,CAA8C,GAC9C,CAAA,4CAAA;AACL;KAEL;AAAA,GAAM,CAAC;AAEX;AAEA,YAAesC,yBAAyB,CAAC5D,MAAM,CAAC;;;;"}
@@ -0,0 +1,35 @@
1
+ .taro-switch {
2
+ position: relative;
3
+ display: inline-block;
4
+ cursor: pointer;
5
+
6
+ &--disabled {
7
+ opacity: 0.5;
8
+ cursor: not-allowed;
9
+ }
10
+
11
+ &--type-switch {
12
+ border: 1px solid #DFDFDF;
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ &--type-switch &__thumb {
17
+ position: absolute;
18
+ top: 1px;
19
+ left: 1px;
20
+ border-radius: 50%;
21
+ background-color: #fff;
22
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
23
+ }
24
+
25
+ &--type-checkbox {
26
+ border: 1px solid #c9c9c9;
27
+ box-sizing: border-box;
28
+ }
29
+
30
+ &--type-checkbox &__checkmark {
31
+ position: absolute;
32
+ top: 50%;
33
+ left: 50%;
34
+ }
35
+ }
@@ -0,0 +1,6 @@
1
+ import React__default from 'react';
2
+
3
+ const ScrollElementContext = /*#__PURE__*/React__default.createContext(null);
4
+
5
+ export { ScrollElementContext };
6
+ //# sourceMappingURL=ScrollElementContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScrollElementContext.js","sources":["../../../src/contexts/ScrollElementContext.tsx"],"sourcesContent":["import React from 'react'\n\n/**\n * ScrollElementContext:嵌套滚动场景下,父容器(ScrollView/List)向子组件提供滚动容器信息。\n * 子组件(WaterFlow/List)可从 Context 获取 scrollRef、containerHeight、startOffset,\n * 实现随父容器一起滚动,无需业务方手动传 scrollElement。\n */\nexport interface ScrollElementContextValue {\n /** 外层滚动容器 ref */\n scrollRef: React.MutableRefObject<HTMLElement | null>\n /** 可视区高度 */\n containerHeight: number\n /** 内容在滚动容器中的起始偏移(上方有其他内容时使用) */\n startOffset: number\n /** 内层 WaterFlow 报告 scrollHeight 时调用(List 动高联动等) */\n reportNestedHeightChange?: (scrollHeight: number) => void\n}\n\nexport const ScrollElementContext = React.createContext<ScrollElementContextValue | null>(null)\n"],"names":["ScrollElementContext","React","createContext"],"mappings":";;AAkBO,MAAMA,oBAAoB,gBAAGC,cAAK,CAACC,aAAa,CAAmC,IAAI;;;;"}
@@ -1,15 +1,19 @@
1
- export { Ad, AdCustom, AnimationVideo, AnimationView, ArCamera, Audio, AwemeData, Block, Camera, Canvas, ChannelLive, ChannelVideo, Checkbox, CheckboxGroup, CommentDetail, CommentList, ContactButton, CoverImage, CoverView, CustomWrapper, DraggableSheet, Editor, FollowSwan, Form, FunctionalPageNavigator, GridBuilder, GridView, InlinePaymentPanel, KeyboardAccessory, Label, Lifestyle, Like, ListBuilder, ListView, LivePlayer, LivePusher, Login, Lottie, Map, MatchMedia, MovableArea, MovableView, NativeSlot, NavigationBar, Navigator, NestedScrollBody, NestedScrollHeader, OfficialAccount, OpenContainer, OpenData, PageContainer, PageMeta, PickerView, PickerViewColumn, Progress, Radio, RadioGroup, RichText, RootPortal, RtcRoom, RtcRoomItem, Script, ShareElement, Slider, Slot, Snapshot, Span, Switch, Tabs, Textarea, Video, VoipRoom, WebView } from '@tarojs/components/lib/react';
1
+ export { Ad, AdCustom, AnimationVideo, AnimationView, ArCamera, Audio, AwemeData, Block, Camera, Canvas, ChannelLive, ChannelVideo, Checkbox, CheckboxGroup, CommentDetail, CommentList, ContactButton, CoverImage, CoverView, CustomWrapper, DraggableSheet, Editor, FollowSwan, Form, FunctionalPageNavigator, GridBuilder, GridView, InlinePaymentPanel, KeyboardAccessory, Label, Lifestyle, Like, ListBuilder, ListView, LivePlayer, LivePusher, Login, Lottie, MatchMedia, MovableArea, MovableView, NativeSlot, NavigationBar, Navigator, NestedScrollBody, NestedScrollHeader, OfficialAccount, OpenContainer, OpenData, PageContainer, PageMeta, PickerView, PickerViewColumn, Progress, Radio, RadioGroup, RichText, RootPortal, RtcRoom, RtcRoomItem, Script, ShareElement, Slider, Slot, Snapshot, Span, Tabs, Textarea, Video, VoipRoom, WebView } from '@tarojs/components/lib/react';
2
2
  export { default as Button } from './components/button/index.js';
3
3
  export { default as Icon } from './components/icon/index.js';
4
4
  export { default as Image } from './components/image/index.js';
5
5
  export { default as Input } from './components/input/index.js';
6
+ export { default as Map } from './components/map/index.js';
6
7
  export { default as Picker } from './components/picker/index.js';
7
8
  export { default as PullDownRefresh } from './components/pull-down-refresh/index.js';
8
9
  export { Refresher } from './components/refresher/index.js';
10
+ export { ScrollElementContext } from './contexts/ScrollElementContext.js';
9
11
  export { default as ScrollView } from './components/scroll-view/index.js';
10
12
  export { Swiper, SwiperItem } from './components/swiper/index.js';
13
+ export { default as Switch } from './components/switch/index.js';
11
14
  export { default as Text } from './components/text/index.js';
12
15
  export { default as View } from './components/view/index.js';
16
+ export { createMapContext } from './components/map/createMapContext.js';
13
17
 
14
18
  /* eslint-disable simple-import-sort/exports */
15
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.react.ts"],"sourcesContent":["/* eslint-disable simple-import-sort/exports */\nexport { Ad } from '@tarojs/components/lib/react'\nexport { AdCustom } from '@tarojs/components/lib/react'\nexport { AnimationVideo } from '@tarojs/components/lib/react'\nexport { AnimationView } from '@tarojs/components/lib/react'\nexport { ArCamera } from '@tarojs/components/lib/react'\nexport { Audio } from '@tarojs/components/lib/react'\nexport { AwemeData } from '@tarojs/components/lib/react'\nexport { Block } from '@tarojs/components/lib/react'\nexport { default as Button } from './components/button'\nexport { Camera } from '@tarojs/components/lib/react'\nexport { Canvas } from '@tarojs/components/lib/react'\nexport { ChannelLive } from '@tarojs/components/lib/react'\nexport { ChannelVideo } from '@tarojs/components/lib/react'\nexport { Checkbox, CheckboxGroup } from '@tarojs/components/lib/react'\nexport { CommentDetail, CommentList } from '@tarojs/components/lib/react'\nexport { ContactButton } from '@tarojs/components/lib/react'\nexport { CoverImage } from '@tarojs/components/lib/react'\nexport { CoverView } from '@tarojs/components/lib/react'\nexport { CustomWrapper } from '@tarojs/components/lib/react'\nexport { DraggableSheet } from '@tarojs/components/lib/react'\nexport { Editor } from '@tarojs/components/lib/react'\nexport { FollowSwan } from '@tarojs/components/lib/react'\nexport { Form } from '@tarojs/components/lib/react'\nexport { FunctionalPageNavigator } from '@tarojs/components/lib/react'\nexport { GridView } from '@tarojs/components/lib/react'\nexport { GridBuilder } from '@tarojs/components/lib/react'\nexport { default as Icon } from './components/icon'\nexport { default as Image } from './components/image'\nexport { InlinePaymentPanel } from '@tarojs/components/lib/react'\nexport { default as Input } from './components/input'\nexport { KeyboardAccessory } from '@tarojs/components/lib/react'\nexport { Label } from '@tarojs/components/lib/react'\nexport { Lifestyle } from '@tarojs/components/lib/react'\nexport { Like } from '@tarojs/components/lib/react'\nexport { LivePlayer } from '@tarojs/components/lib/react'\nexport { LivePusher } from '@tarojs/components/lib/react'\nexport { ListBuilder } from '@tarojs/components/lib/react'\nexport { ListView } from '@tarojs/components/lib/react'\nexport { Login } from '@tarojs/components/lib/react'\nexport { Lottie } from '@tarojs/components/lib/react'\nexport { Map } from '@tarojs/components/lib/react'\nexport { MatchMedia } from '@tarojs/components/lib/react'\nexport { MovableArea, MovableView } from '@tarojs/components/lib/react'\nexport { NavigationBar } from '@tarojs/components/lib/react'\nexport { Navigator } from '@tarojs/components/lib/react'\nexport { NestedScrollBody } from '@tarojs/components/lib/react'\nexport { NestedScrollHeader } from '@tarojs/components/lib/react'\nexport { OfficialAccount } from '@tarojs/components/lib/react'\nexport { OpenData } from '@tarojs/components/lib/react'\nexport { OpenContainer } from '@tarojs/components/lib/react'\nexport { PageContainer } from '@tarojs/components/lib/react'\nexport { PageMeta } from '@tarojs/components/lib/react'\nexport { default as Picker } from './components/picker'\nexport { PickerView, PickerViewColumn } from '@tarojs/components/lib/react'\nexport { Progress } from '@tarojs/components/lib/react'\nexport { default as PullDownRefresh } from './components/pull-down-refresh'\n// export { PullToRefresh } from '@tarojs/components/lib/react'\nexport { default as Refresher, type RefresherProps } from './components/refresher'\nexport { Radio, RadioGroup } from '@tarojs/components/lib/react'\nexport { RichText } from '@tarojs/components/lib/react'\nexport { RootPortal } from '@tarojs/components/lib/react'\nexport { RtcRoom, RtcRoomItem } from '@tarojs/components/lib/react'\nexport { Script } from '@tarojs/components/lib/react'\nexport { default as ScrollView } from './components/scroll-view'\nexport { ShareElement } from '@tarojs/components/lib/react'\nexport { Slider } from '@tarojs/components/lib/react'\nexport { Snapshot } from '@tarojs/components/lib/react'\nexport { Span } from '@tarojs/components/lib/react'\nexport { NativeSlot, Slot } from '@tarojs/components/lib/react'\nexport { Swiper, SwiperItem } from './components/swiper'\nexport { Switch } from '@tarojs/components/lib/react'\nexport { Tabs } from '@tarojs/components/lib/react'\nexport { default as Text } from './components/text'\nexport { Textarea } from '@tarojs/components/lib/react'\nexport { Video } from '@tarojs/components/lib/react'\nexport { default as View } from './components/view'\nexport { VoipRoom } from '@tarojs/components/lib/react'\nexport { WebView } from '@tarojs/components/lib/react'\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.react.ts"],"sourcesContent":["/* eslint-disable simple-import-sort/exports */\nexport { Ad } from '@tarojs/components/lib/react'\nexport { AdCustom } from '@tarojs/components/lib/react'\nexport { AnimationVideo } from '@tarojs/components/lib/react'\nexport { AnimationView } from '@tarojs/components/lib/react'\nexport { ArCamera } from '@tarojs/components/lib/react'\nexport { Audio } from '@tarojs/components/lib/react'\nexport { AwemeData } from '@tarojs/components/lib/react'\nexport { Block } from '@tarojs/components/lib/react'\nexport { default as Button } from './components/button'\nexport { Camera } from '@tarojs/components/lib/react'\nexport { Canvas } from '@tarojs/components/lib/react'\nexport { ChannelLive } from '@tarojs/components/lib/react'\nexport { ChannelVideo } from '@tarojs/components/lib/react'\nexport { Checkbox, CheckboxGroup } from '@tarojs/components/lib/react'\nexport { CommentDetail, CommentList } from '@tarojs/components/lib/react'\nexport { ContactButton } from '@tarojs/components/lib/react'\nexport { CoverImage } from '@tarojs/components/lib/react'\nexport { CoverView } from '@tarojs/components/lib/react'\nexport { CustomWrapper } from '@tarojs/components/lib/react'\nexport { DraggableSheet } from '@tarojs/components/lib/react'\nexport { Editor } from '@tarojs/components/lib/react'\nexport { FollowSwan } from '@tarojs/components/lib/react'\nexport { Form } from '@tarojs/components/lib/react'\nexport { FunctionalPageNavigator } from '@tarojs/components/lib/react'\nexport { GridView } from '@tarojs/components/lib/react'\nexport { GridBuilder } from '@tarojs/components/lib/react'\nexport { default as Icon } from './components/icon'\nexport { default as Image } from './components/image'\nexport { InlinePaymentPanel } from '@tarojs/components/lib/react'\nexport { default as Input } from './components/input'\nexport { KeyboardAccessory } from '@tarojs/components/lib/react'\nexport { Label } from '@tarojs/components/lib/react'\nexport { Lifestyle } from '@tarojs/components/lib/react'\nexport { Like } from '@tarojs/components/lib/react'\nexport { LivePlayer } from '@tarojs/components/lib/react'\nexport { LivePusher } from '@tarojs/components/lib/react'\nexport { ListBuilder } from '@tarojs/components/lib/react'\nexport { ListView } from '@tarojs/components/lib/react'\nexport { Login } from '@tarojs/components/lib/react'\nexport { Lottie } from '@tarojs/components/lib/react'\nexport { default as Map, type MapProps } from './components/map'\nexport { createMapContext } from './components/map'\nexport { MatchMedia } from '@tarojs/components/lib/react'\nexport { MovableArea, MovableView } from '@tarojs/components/lib/react'\nexport { NavigationBar } from '@tarojs/components/lib/react'\nexport { Navigator } from '@tarojs/components/lib/react'\nexport { NestedScrollBody } from '@tarojs/components/lib/react'\nexport { NestedScrollHeader } from '@tarojs/components/lib/react'\nexport { OfficialAccount } from '@tarojs/components/lib/react'\nexport { OpenData } from '@tarojs/components/lib/react'\nexport { OpenContainer } from '@tarojs/components/lib/react'\nexport { PageContainer } from '@tarojs/components/lib/react'\nexport { PageMeta } from '@tarojs/components/lib/react'\nexport { default as Picker } from './components/picker'\nexport { PickerView, PickerViewColumn } from '@tarojs/components/lib/react'\nexport { Progress } from '@tarojs/components/lib/react'\nexport { default as PullDownRefresh } from './components/pull-down-refresh'\n// export { PullToRefresh } from '@tarojs/components/lib/react'\nexport { default as Refresher, type RefresherProps } from './components/refresher'\nexport { Radio, RadioGroup } from '@tarojs/components/lib/react'\nexport { RichText } from '@tarojs/components/lib/react'\nexport { RootPortal } from '@tarojs/components/lib/react'\nexport { RtcRoom, RtcRoomItem } from '@tarojs/components/lib/react'\nexport { Script } from '@tarojs/components/lib/react'\nexport { ScrollElementContext, type ScrollElementContextValue } from './contexts/ScrollElementContext'\nexport { default as ScrollView } from './components/scroll-view'\nexport { ShareElement } from '@tarojs/components/lib/react'\nexport { Slider } from '@tarojs/components/lib/react'\nexport { Snapshot } from '@tarojs/components/lib/react'\nexport { Span } from '@tarojs/components/lib/react'\nexport { NativeSlot, Slot } from '@tarojs/components/lib/react'\nexport { Swiper, SwiperItem } from './components/swiper'\nexport { default as Switch } from './components/switch'\nexport { Tabs } from '@tarojs/components/lib/react'\nexport { default as Text } from './components/text'\nexport { Textarea } from '@tarojs/components/lib/react'\nexport { Video } from '@tarojs/components/lib/react'\nexport { default as View } from './components/view'\nexport { VoipRoom } from '@tarojs/components/lib/react'\nexport { WebView } from '@tarojs/components/lib/react'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA"}
@@ -13,16 +13,18 @@ function Image(props) {
13
13
  const [, setIsLoaded] = useState(false);
14
14
  const {
15
15
  className,
16
- style: style$1 = {},
16
+ style: style$1,
17
17
  src,
18
18
  mode,
19
19
  onError,
20
20
  lazyLoad,
21
21
  imgProps,
22
- forwardedRef
22
+ forwardedRef,
23
+ disableDefaultSize = false
23
24
  } = props,
24
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
25
+ reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef", "disableDefaultSize"]);
25
26
  const cls = classNames('taro-img', {
27
+ 'taro-img--with-default-host-size': !disableDefaultSize,
26
28
  'taro-img__widthfix': mode === 'widthFix'
27
29
  }, className);
28
30
  const imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\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\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","_el$","_tmpl$","_$use","_$spread","_$insert","_el$2","_tmpl$2","_$addEventListener","img","_$setAttribute","_el$3","_$effect","_$p","_$style","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;aACTC,OAAK,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;AAET,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,IAAAA,MAAM,CAACC,cAAc,CAACH,CAAC,EAAE,QAAQ,EAAE;AACjCI,MAAAA,UAAU,EAAE,IAAI;AAChBC,MAAAA,QAAQ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A,CAAA,CAAA;AAAA,IAAA,OAAAZ,IAAA;AAAA,GAAA,GAAA;AAsBrC;AAEA,YAAec,yBAAyB,CAAC5D,KAAK,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\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 /** 为 true 时不挂载默认占位尺寸(320×240),由业务 style/class 决定容器大小 */\n disableDefaultSize?: boolean\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 disableDefaultSize = false,\n ...reset\n } = props\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img--with-default-host-size': !disableDefaultSize,\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","disableDefaultSize","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","_el$","_tmpl$","_$use","_$spread","_$insert","_el$2","_tmpl$2","_$addEventListener","img","_$setAttribute","_el$3","_$effect","_$p","_$style","createForwardRefComponent"],"mappings":";;;;;;;;;AAqBA,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;aACTC,OAAK;MACLC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;MACRC,YAAY;AACZC,MAAAA,kBAAkB,GAAG;AAEnB,KAAA,GAAAd,KAAK;IADJe,KAAK,GACNC,MAAA,CAAAhB,KAAK,EAXH,CAAA,WAAA,EAAA,OAAA,EAAA,KAAA,EAAA,MAAA,EAAA,SAAA,EAAA,UAAA,EAAA,UAAA,EAAA,cAAA,E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