@doubao-dev/taro-runtime 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -0
- package/assets/refresh-loading.png +0 -0
- package/dist/api/base/can-i-use.d.ts +3 -0
- package/dist/api/base/can-i-use.js +12 -0
- package/dist/api/base/event-center.d.ts +12 -0
- package/dist/api/base/event-center.js +52 -0
- package/dist/api/base/index.d.ts +1 -1
- package/dist/api/base/index.js +1 -1
- package/dist/api/base/next-tick.d.ts +3 -0
- package/dist/api/base/next-tick.js +11 -0
- package/dist/api/canvas/index.d.ts +17 -0
- package/dist/api/canvas/index.js +29 -0
- package/dist/api/create-animation.d.ts +47 -0
- package/dist/api/create-animation.js +98 -0
- package/dist/api/create-intersection-observer/index.d.ts +7 -0
- package/dist/api/create-intersection-observer/index.js +126 -0
- package/dist/api/create-selector-query/index.js +284 -109
- package/dist/api/device/accelerometer.js +1 -1
- package/dist/api/device/accessibility.js +1 -1
- package/dist/api/device/battery.js +1 -1
- package/dist/api/device/beacon.js +1 -1
- package/dist/api/device/bluetooth.js +1 -1
- package/dist/api/device/clipboard.js +1 -1
- package/dist/api/device/compass.js +1 -1
- package/dist/api/device/crypto.js +1 -1
- package/dist/api/device/device-motion.js +1 -1
- package/dist/api/device/gyroscope.js +1 -1
- package/dist/api/device/keyboard.js +1 -1
- package/dist/api/device/scan.js +1 -1
- package/dist/api/device/screen.js +1 -1
- package/dist/api/device/sms.js +1 -1
- package/dist/api/device/vibration.js +1 -1
- package/dist/api/device/wifi.js +1 -1
- package/dist/api/index.d.ts +8 -1
- package/dist/api/index.js +8 -1
- package/dist/api/interaction/index.js +1 -1
- package/dist/api/location/index.d.ts +2 -2
- package/dist/api/location/index.js +1 -1
- package/dist/api/media/image.d.ts +9 -0
- package/dist/api/media/image.js +21 -1
- package/dist/api/media/index.d.ts +2 -0
- package/dist/api/media/index.js +2 -0
- package/dist/api/media/inner-audio.d.ts +5 -0
- package/dist/api/media/inner-audio.js +7 -0
- package/dist/api/media/media.d.ts +6 -0
- package/dist/api/media/media.js +9 -0
- package/dist/api/px-transform.d.ts +11 -0
- package/dist/api/px-transform.js +31 -0
- package/dist/api/request/index.js +1 -1
- package/dist/api/request/websocket.js +1 -1
- package/dist/api/router/current-instance.d.ts +17 -0
- package/dist/api/router/current-instance.js +28 -0
- package/dist/api/router/exit-mini-program.js +1 -1
- package/dist/api/router/get-current-pages.d.ts +13 -1
- package/dist/api/router/get-current-pages.js +5 -3
- package/dist/api/router/index.d.ts +1 -0
- package/dist/api/router/index.js +1 -0
- package/dist/api/router/navigate-back.js +1 -1
- package/dist/api/router/navigate-to.js +1 -1
- package/dist/api/router/re-launch.js +1 -1
- package/dist/api/router/redirect-to.js +1 -1
- package/dist/api/runtime/download.d.ts +11 -0
- package/dist/api/runtime/download.js +18 -0
- package/dist/api/runtime/resize.d.ts +7 -0
- package/dist/api/runtime/resize.js +26 -0
- package/dist/api/runtime/system.d.ts +8 -0
- package/dist/api/runtime/system.js +10 -0
- package/dist/api/show-toast/index.js +1 -1
- package/dist/api/storage/index.d.ts +1 -1
- package/dist/api/storage/index.js +1 -1
- package/dist/api/system/index.js +1 -1
- package/dist/components/Block/index.d.ts +3 -0
- package/dist/components/Block/index.jsx +4 -0
- package/dist/components/Button/index.d.ts +7 -0
- package/dist/components/Button/index.jsx +28 -0
- package/dist/components/Canvas/index.d.ts +4 -0
- package/dist/components/Canvas/index.jsx +25 -0
- package/dist/components/Checkbox/index.d.ts +3 -0
- package/dist/components/Checkbox/index.jsx +17 -0
- package/dist/components/CheckboxGroup/index.d.ts +3 -0
- package/dist/components/CheckboxGroup/index.jsx +13 -0
- package/dist/components/CoverView/index.d.ts +6 -1
- package/dist/components/CoverView/index.js +5 -1
- package/dist/components/Form/index.d.ts +4 -0
- package/dist/components/Form/index.jsx +39 -0
- package/dist/components/Form/use-form-field.d.ts +5 -0
- package/dist/components/Form/use-form-field.js +40 -0
- package/dist/components/Icon/index.d.ts +3 -0
- package/dist/components/Icon/index.jsx +40 -0
- package/dist/components/Image/index.d.ts +3 -1
- package/dist/components/Image/index.jsx +15 -4
- package/dist/components/Input/index.d.ts +1 -1
- package/dist/components/Input/index.jsx +9 -5
- package/dist/components/Input/map.d.ts +1 -1
- package/dist/components/Label/control.d.ts +6 -0
- package/dist/components/Label/control.js +29 -0
- package/dist/components/Label/index.d.ts +3 -0
- package/dist/components/Label/index.jsx +15 -0
- package/dist/components/LivePlayer/index.d.ts +3 -0
- package/dist/components/LivePlayer/index.jsx +8 -0
- package/dist/components/Map/bridge.d.ts +1 -1
- package/dist/components/Map/index.jsx +10 -6
- package/dist/components/Movable/index.d.ts +4 -0
- package/dist/components/Movable/index.jsx +26 -0
- package/dist/components/NavigationBar/index.d.ts +3 -0
- package/dist/components/NavigationBar/index.jsx +16 -0
- package/dist/components/Navigator/index.d.ts +3 -0
- package/dist/components/Navigator/index.jsx +32 -0
- package/dist/components/OpenData/index.d.ts +3 -0
- package/dist/components/OpenData/index.js +4 -0
- package/dist/components/Picker/index.d.ts +6 -0
- package/dist/components/Picker/index.jsx +155 -0
- package/dist/components/Picker/popup.d.ts +18 -0
- package/dist/components/Picker/popup.jsx +105 -0
- package/dist/components/PickerView/index.d.ts +1 -1
- package/dist/components/PickerView/index.jsx +1 -1
- package/dist/components/PickerView/map.d.ts +1 -1
- package/dist/components/Progress/index.d.ts +3 -0
- package/dist/components/Progress/index.jsx +14 -0
- package/dist/components/Radio/index.jsx +9 -5
- package/dist/components/Radio/shared.d.ts +1 -1
- package/dist/components/RadioGroup/context.js +1 -1
- package/dist/components/RadioGroup/index.jsx +8 -4
- package/dist/components/RadioGroup/map.d.ts +1 -1
- package/dist/components/RichText/index.d.ts +3 -0
- package/dist/components/RichText/index.jsx +7 -0
- package/dist/components/ScrollView/index.d.ts +4 -1
- package/dist/components/ScrollView/index.jsx +44 -14
- package/dist/components/ScrollView/map.d.ts +4 -2
- package/dist/components/ScrollView/map.js +19 -1
- package/dist/components/ScrollView/refresh-types.d.ts +25 -0
- package/dist/components/ScrollView/refresh-types.js +2 -0
- package/dist/components/ScrollView/refresh.d.ts +10 -0
- package/dist/components/ScrollView/refresh.jsx +29 -0
- package/dist/components/ScrollView/use-refresher.d.ts +19 -0
- package/dist/components/ScrollView/use-refresher.js +214 -0
- package/dist/components/Slider/index.d.ts +3 -0
- package/dist/components/Slider/index.jsx +13 -0
- package/dist/components/Swiper/index.d.ts +3 -0
- package/dist/components/Swiper/index.jsx +79 -0
- package/dist/components/SwiperItem/index.d.ts +3 -0
- package/dist/components/SwiperItem/index.jsx +18 -0
- package/dist/components/Switch/index.d.ts +3 -0
- package/dist/components/Switch/index.jsx +32 -0
- package/dist/components/Text/format.d.ts +5 -0
- package/dist/components/Text/format.js +51 -0
- package/dist/components/Text/index.d.ts +4 -3
- package/dist/components/Text/index.jsx +3 -2
- package/dist/components/Text/map.js +9 -4
- package/dist/components/Textarea/index.d.ts +3 -0
- package/dist/components/Textarea/index.jsx +30 -0
- package/dist/components/Video/index.d.ts +3 -0
- package/dist/components/Video/index.jsx +22 -0
- package/dist/components/View/index.d.ts +5 -5
- package/dist/components/View/index.jsx +11 -13
- package/dist/components/View/map.js +5 -0
- package/dist/components/base/change-event.d.ts +18 -0
- package/dist/components/base/change-event.js +13 -0
- package/dist/components/base/wrap-text-node.d.ts +3 -0
- package/dist/components/base/wrap-text-node.jsx +34 -0
- package/dist/components/index.d.ts +24 -1
- package/dist/components/index.js +24 -1
- package/dist/exports/app.d.ts +2 -1
- package/dist/exports/app.js +3 -1
- package/dist/exports/common.d.ts +1 -0
- package/dist/exports/common.js +1 -0
- package/dist/exports/view-core.d.ts +2 -1
- package/dist/exports/view-core.js +2 -1
- package/dist/exports/view.d.ts +2 -1
- package/dist/exports/view.js +3 -1
- package/dist/hooks/lifecycle/app.js +1 -1
- package/dist/hooks/use-animation.d.ts +9 -0
- package/dist/hooks/use-animation.js +151 -0
- package/dist/internal/class-components.d.ts +11 -0
- package/dist/internal/class-components.js +42 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/map-context/index.d.ts +1 -1
- package/dist/internal/query-node.d.ts +9 -0
- package/dist/internal/query-node.js +35 -0
- package/dist/internal/selector-id.d.ts +6 -0
- package/dist/internal/selector-id.js +18 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.js +4 -0
- package/package.json +23 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RefreshProps } from '@doubao-dev/framework/components';
|
|
2
|
+
import type { ScrollViewRefreshProps } from './refresh-types.js';
|
|
3
|
+
type Props = Pick<RefreshProps, 'style' | 'className' | 'children'> & {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
refresh: ScrollViewRefreshProps;
|
|
6
|
+
scrollProps: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export declare function ScrollViewRefresh({ children, style, className, enabled, refresh, scrollProps }: Props): any;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LoadingIndicator } from '@doubao-dev/framework/components';
|
|
2
|
+
import loadingIcon from '../../../assets/refresh-loading.png';
|
|
3
|
+
import { useRefresher } from './use-refresher.js';
|
|
4
|
+
const headerStyle = {
|
|
5
|
+
position: 'absolute',
|
|
6
|
+
width: '100%',
|
|
7
|
+
height: '60px',
|
|
8
|
+
display: 'flex',
|
|
9
|
+
justifyContent: 'center',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
backgroundColor: 'var(--static-white, #fff)'
|
|
12
|
+
};
|
|
13
|
+
const loadingStyle = { width: '20px', height: '20px', transform: 'translateX(4px)' };
|
|
14
|
+
export function ScrollViewRefresh({ children, style, className, enabled, refresh, scrollProps }) {
|
|
15
|
+
const controller = useRefresher(refresh, enabled);
|
|
16
|
+
const data = {};
|
|
17
|
+
for (const [key, value] of Object.entries(scrollProps)) {
|
|
18
|
+
if (key.startsWith('data-')) {
|
|
19
|
+
data[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return (<refresh {...data} ref={controller.refreshRef} className={className} style={style} enableRefresh={enabled} onStartRefresh={controller.onStartRefresh} onHeaderOffset={controller.onHeaderOffset} onRefreshStateChange={controller.onStateChange}>
|
|
23
|
+
<refresh-header style={headerStyle}>
|
|
24
|
+
<LoadingIndicator src={loadingIcon} style={loadingStyle}/>
|
|
25
|
+
</refresh-header>
|
|
26
|
+
{children}
|
|
27
|
+
</refresh>);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=refresh.jsx.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NodesRef, RefreshHeaderOffsetEvent, RefreshStartRefreshEvent, RefreshStateChangeEvent } from '@lynx-js/types';
|
|
2
|
+
import type { ScrollViewRefreshProps } from './refresh-types.js';
|
|
3
|
+
export declare const supportsNativeRefresh: boolean;
|
|
4
|
+
export declare const useRefresher: typeof useInitialRefresher | typeof useBackgroundRefresher;
|
|
5
|
+
declare function useInitialRefresher(): {
|
|
6
|
+
refreshRef: import("react").MutableRefObject<NodesRef | null>;
|
|
7
|
+
onStartRefresh: undefined;
|
|
8
|
+
onHeaderOffset: undefined;
|
|
9
|
+
onStateChange: undefined;
|
|
10
|
+
};
|
|
11
|
+
declare function useBackgroundRefresher(props: ScrollViewRefreshProps, enabled: boolean): {
|
|
12
|
+
refreshRef: import("react").MutableRefObject<NodesRef | null>;
|
|
13
|
+
} & {
|
|
14
|
+
onStartRefresh: (event: RefreshStartRefreshEvent) => void;
|
|
15
|
+
onHeaderOffset: (event: RefreshHeaderOffsetEvent) => void;
|
|
16
|
+
onStateChange: (event: RefreshStateChangeEvent) => void;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=use-refresher.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from '@doubao-dev/framework';
|
|
2
|
+
export const supportsNativeRefresh = typeof __DOUBAO_APPS_WEB__ === 'undefined' || !__DOUBAO_APPS_WEB__;
|
|
3
|
+
// The main thread renders only the initial header. Native events and effects
|
|
4
|
+
// run on the background thread, which owns the complete refresh controller.
|
|
5
|
+
// This compile-time selection keeps hook order fixed within each runtime.
|
|
6
|
+
export const useRefresher = !supportsNativeRefresh || (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__)
|
|
7
|
+
? useInitialRefresher
|
|
8
|
+
: useBackgroundRefresher;
|
|
9
|
+
function useInitialRefresher() {
|
|
10
|
+
return {
|
|
11
|
+
refreshRef: useRef(null),
|
|
12
|
+
onStartRefresh: undefined,
|
|
13
|
+
onHeaderOffset: undefined,
|
|
14
|
+
onStateChange: undefined
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function useBackgroundRefresher(props, enabled) {
|
|
18
|
+
const refreshRef = useRef(null);
|
|
19
|
+
const options = useRef({ props, enabled });
|
|
20
|
+
options.current = { props, enabled };
|
|
21
|
+
const controller = useMemo(() => createRefresher(refreshRef, () => options.current), []);
|
|
22
|
+
useEffect(() => controller.mount(), [controller]);
|
|
23
|
+
useEffect(() => controller.update(), [controller, enabled, props.refresherTriggered]);
|
|
24
|
+
return Object.assign({ refreshRef }, controller.handlers);
|
|
25
|
+
}
|
|
26
|
+
function createRefresher(refreshRef, getOptions) {
|
|
27
|
+
'background only';
|
|
28
|
+
let mounted = false;
|
|
29
|
+
let phase = 'idle';
|
|
30
|
+
let pulled = false;
|
|
31
|
+
let notified = false;
|
|
32
|
+
let stopRequested = false;
|
|
33
|
+
let restartRequested = false;
|
|
34
|
+
let command = 0;
|
|
35
|
+
let retryTimer;
|
|
36
|
+
const emit = (name, event, detail) => {
|
|
37
|
+
const { props } = getOptions();
|
|
38
|
+
const target = {
|
|
39
|
+
id: props.id ?? '',
|
|
40
|
+
dataset: event.currentTarget.dataset ?? {}
|
|
41
|
+
};
|
|
42
|
+
const normalized = Object.assign({}, event, {
|
|
43
|
+
type: `refresher${name.toLowerCase()}`,
|
|
44
|
+
target,
|
|
45
|
+
currentTarget: target,
|
|
46
|
+
detail
|
|
47
|
+
});
|
|
48
|
+
props[`onRefresher${name}`]?.(normalized);
|
|
49
|
+
};
|
|
50
|
+
const invoke = (method) => {
|
|
51
|
+
const request = ++command;
|
|
52
|
+
if (retryTimer !== undefined) {
|
|
53
|
+
clearTimeout(retryTimer);
|
|
54
|
+
}
|
|
55
|
+
const attempt = (remaining) => {
|
|
56
|
+
if (!mounted || command !== request) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const fail = (code) => {
|
|
60
|
+
if (!mounted || command !== request) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (code === 2 && remaining > 0) {
|
|
64
|
+
retryTimer = setTimeout(() => attempt(remaining - 1), 16);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
phase = notified ? 'refreshing' : 'idle';
|
|
68
|
+
console.warn(`[taro scroll-view] ${method} failed: ${code}`);
|
|
69
|
+
};
|
|
70
|
+
if (!refreshRef.current) {
|
|
71
|
+
fail(2);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
refreshRef.current.invoke({ method, fail: ({ code }) => fail(code) }).exec();
|
|
75
|
+
};
|
|
76
|
+
attempt(2);
|
|
77
|
+
};
|
|
78
|
+
const finish = () => {
|
|
79
|
+
if (phase === 'idle' && !pulled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
stopRequested = true;
|
|
83
|
+
if (phase === 'finishing') {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// A start command may still be queued on the UI thread. End it as soon as
|
|
87
|
+
// startrefresh arrives, instead of finishing before it has actually started.
|
|
88
|
+
if (phase === 'starting' && !notified) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
phase = 'finishing';
|
|
92
|
+
invoke('finishRefresh');
|
|
93
|
+
};
|
|
94
|
+
const start = () => {
|
|
95
|
+
const { enabled } = getOptions();
|
|
96
|
+
if (!enabled) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// A disabled native refresh may have ignored an already queued start. A new
|
|
100
|
+
// true intent must be allowed to issue a fresh command in that case.
|
|
101
|
+
if (phase === 'starting' && stopRequested && !notified) {
|
|
102
|
+
phase = 'idle';
|
|
103
|
+
}
|
|
104
|
+
stopRequested = false;
|
|
105
|
+
if (phase === 'finishing') {
|
|
106
|
+
restartRequested = true;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (phase !== 'idle') {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
phase = 'starting';
|
|
113
|
+
invoke('autoStartRefresh');
|
|
114
|
+
};
|
|
115
|
+
const settle = (event) => {
|
|
116
|
+
const { props, enabled } = getOptions();
|
|
117
|
+
if (!mounted) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
++command;
|
|
121
|
+
if (retryTimer !== undefined) {
|
|
122
|
+
clearTimeout(retryTimer);
|
|
123
|
+
}
|
|
124
|
+
const refreshed = notified;
|
|
125
|
+
const aborted = pulled && !refreshed;
|
|
126
|
+
const restart = restartRequested && enabled && props.refresherTriggered === true;
|
|
127
|
+
phase = 'idle';
|
|
128
|
+
pulled = false;
|
|
129
|
+
notified = false;
|
|
130
|
+
stopRequested = false;
|
|
131
|
+
restartRequested = false;
|
|
132
|
+
if (refreshed) {
|
|
133
|
+
emit('Restore', event, {});
|
|
134
|
+
}
|
|
135
|
+
else if (aborted) {
|
|
136
|
+
emit('Abort', event, {});
|
|
137
|
+
}
|
|
138
|
+
if (restart) {
|
|
139
|
+
start();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const onStartRefresh = (event) => {
|
|
143
|
+
const { enabled } = getOptions();
|
|
144
|
+
if (!mounted || notified) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
++command;
|
|
148
|
+
if (retryTimer !== undefined) {
|
|
149
|
+
clearTimeout(retryTimer);
|
|
150
|
+
}
|
|
151
|
+
// Some iOS hosts report the first gesture as programmatic. A recorded pull
|
|
152
|
+
// without a pending start command still identifies a manual refresh.
|
|
153
|
+
const isManual = Boolean(event.detail.isManual) || (phase === 'idle' && pulled);
|
|
154
|
+
// A new gesture after re-enabling starts its own cycle, even if an earlier
|
|
155
|
+
// disabled programmatic start never produced a native start event.
|
|
156
|
+
if (enabled && isManual) {
|
|
157
|
+
stopRequested = false;
|
|
158
|
+
restartRequested = false;
|
|
159
|
+
}
|
|
160
|
+
phase = 'refreshing';
|
|
161
|
+
notified = true;
|
|
162
|
+
if (enabled) {
|
|
163
|
+
emit('Refresh', event, { isManual });
|
|
164
|
+
}
|
|
165
|
+
if (!enabled || stopRequested) {
|
|
166
|
+
finish();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const onHeaderOffset = (event) => {
|
|
170
|
+
const { enabled } = getOptions();
|
|
171
|
+
if (!mounted) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const { isDragging, offsetPercent } = event.detail;
|
|
175
|
+
if (enabled && isDragging && offsetPercent > 0 && phase === 'idle') {
|
|
176
|
+
pulled = true;
|
|
177
|
+
emit('Pulling', event, { isDragging: Boolean(isDragging), offsetPercent });
|
|
178
|
+
}
|
|
179
|
+
if (!isDragging && offsetPercent <= 0 && ((phase === 'idle' && pulled) || phase === 'finishing')) {
|
|
180
|
+
settle(event);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const onStateChange = (event) => {
|
|
184
|
+
// Lynx RefreshState.IDLE = 0. REFRESHING may precede startrefresh, so only
|
|
185
|
+
// startrefresh starts the business cycle and emits its notification.
|
|
186
|
+
if (event.detail.state === 0 && (pulled || notified)) {
|
|
187
|
+
settle(event);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
handlers: { onStartRefresh, onHeaderOffset, onStateChange },
|
|
192
|
+
mount() {
|
|
193
|
+
mounted = true;
|
|
194
|
+
return () => {
|
|
195
|
+
mounted = false;
|
|
196
|
+
++command;
|
|
197
|
+
if (retryTimer !== undefined) {
|
|
198
|
+
clearTimeout(retryTimer);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
update() {
|
|
203
|
+
const { props, enabled } = getOptions();
|
|
204
|
+
if (enabled && props.refresherTriggered === true) {
|
|
205
|
+
start();
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
restartRequested = false;
|
|
209
|
+
finish();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=use-refresher.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Slider as SDKSlider } from '@doubao-dev/framework/components';
|
|
2
|
+
import { changeEvent } from '../base/change-event.js';
|
|
3
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
4
|
+
import { useFormField } from '../Form/use-form-field.js';
|
|
5
|
+
export function Slider({ id, name, onChange, onChanging, value = 0, style, ...props }) {
|
|
6
|
+
const updateForm = useFormField(name, value);
|
|
7
|
+
warnUnsupported('Slider', onChanging ? ['onChanging'] : []);
|
|
8
|
+
return (<SDKSlider {...props} style={style} value={value} onChange={(value) => {
|
|
9
|
+
updateForm?.(value);
|
|
10
|
+
onChange?.(changeEvent('slider', id, { value }));
|
|
11
|
+
}}/>);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SwiperProps } from '@tarojs/components';
|
|
2
|
+
export declare function Swiper({ children, current, currentItemId, autoplay, circular, interval, duration, scrollWithAnimation, onChange, id, className, style, hidden, onClick, onTouchStart, onTouchMove, onTouchEnd, onTouchCancel, onLongPress, ...unsupportedProps }: SwiperProps): any;
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Swiper as SDKSwiper, SwiperItem as SDKSwiperItem } from '@doubao-dev/framework/components';
|
|
2
|
+
import { isValidElement, useEffect, useRef, useState } from '@doubao-dev/framework';
|
|
3
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
4
|
+
export function Swiper({ children, current, currentItemId, autoplay = false, circular = false, interval = 5000, duration = 500, scrollWithAnimation = true, onChange, id = '', className, style, hidden, onClick, onTouchStart, onTouchMove, onTouchEnd, onTouchCancel, onLongPress, ...unsupportedProps }) {
|
|
5
|
+
const items = (Array.isArray(children) ? children.flat(Infinity) : [children]).filter((child) => isValidElement(child));
|
|
6
|
+
const itemIndex = items.findIndex((item) => currentItemId != null && item.props.itemId === currentItemId);
|
|
7
|
+
const selected = Math.min(Math.max(0, current ?? itemIndex), Math.max(0, items.length - 1));
|
|
8
|
+
const [size, setSize] = useState({ width: 0, height: 0 });
|
|
9
|
+
const { width, height } = size;
|
|
10
|
+
const swiper = useRef(null);
|
|
11
|
+
const reportedIndex = useRef(selected);
|
|
12
|
+
const requestedIndex = useRef(selected);
|
|
13
|
+
const source = useRef('');
|
|
14
|
+
const unsupported = Object.entries(unsupportedProps)
|
|
15
|
+
.filter(([key, value]) => {
|
|
16
|
+
if (key === 'displayMultipleItems') {
|
|
17
|
+
return value != null && value !== 1;
|
|
18
|
+
}
|
|
19
|
+
if (key === 'previousMargin' || key === 'nextMargin') {
|
|
20
|
+
return value != null && !/^0(?:px|rpx)?$/.test(String(value));
|
|
21
|
+
}
|
|
22
|
+
if (key === 'easingFunction' || key === 'indicatorType') {
|
|
23
|
+
return value != null && value !== (key === 'indicatorType' ? 'normal' : 'default');
|
|
24
|
+
}
|
|
25
|
+
return value != null && value !== false;
|
|
26
|
+
})
|
|
27
|
+
.map(([key]) => key);
|
|
28
|
+
const warning = unsupported.join(',');
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (warning) {
|
|
31
|
+
warnUnsupported('Swiper', warning.split(','));
|
|
32
|
+
}
|
|
33
|
+
}, [warning]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (width <= 0 || requestedIndex.current === selected) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
requestedIndex.current = selected;
|
|
39
|
+
if (reportedIndex.current !== selected) {
|
|
40
|
+
source.current = '';
|
|
41
|
+
swiper.current?.swipeTo(selected, { animate: scrollWithAnimation });
|
|
42
|
+
}
|
|
43
|
+
}, [selected, scrollWithAnimation, width]);
|
|
44
|
+
function handleChange(index) {
|
|
45
|
+
reportedIndex.current = index;
|
|
46
|
+
const currentItemId = items[index]?.props.itemId;
|
|
47
|
+
const target = { id, dataset: {}, tagName: 'swiper' };
|
|
48
|
+
onChange?.({
|
|
49
|
+
type: 'change',
|
|
50
|
+
timeStamp: Date.now(),
|
|
51
|
+
target,
|
|
52
|
+
currentTarget: target,
|
|
53
|
+
detail: {
|
|
54
|
+
current: index,
|
|
55
|
+
source: source.current || (autoplay && index !== requestedIndex.current ? 'autoplay' : ''),
|
|
56
|
+
currentItemId
|
|
57
|
+
},
|
|
58
|
+
preventDefault() { },
|
|
59
|
+
stopPropagation() { }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return (<view id={id} className={className} style={(typeof style === 'string'
|
|
63
|
+
? `height:150px;${style}${hidden ? ';display:none' : ''}`
|
|
64
|
+
: { height: 150, ...style, ...(hidden ? { display: 'none' } : {}) })} bindtap={onClick} bindtouchstart={onTouchStart} bindtouchmove={onTouchMove} bindtouchend={onTouchEnd} {...{ bindtouchcancel: onTouchCancel }} bindlongpress={onLongPress} bindlayoutchange={(event) => {
|
|
65
|
+
const { width, height } = event.detail;
|
|
66
|
+
setSize((previous) => previous.width === width && previous.height === height ? previous : { width, height });
|
|
67
|
+
}}>
|
|
68
|
+
{width > 0 && items.length > 0 && (<SDKSwiper ref={swiper} data={items} itemWidth={width} containerWidth={width} itemHeight={height} style={{ width: '100%', height: '100%' }} initialIndex={selected} autoPlay={autoplay} autoPlayInterval={interval} loop={circular && items.length > 1} duration={duration} onSwipeStart={() => {
|
|
69
|
+
source.current = 'touch';
|
|
70
|
+
}} onSwipeStop={() => {
|
|
71
|
+
source.current = '';
|
|
72
|
+
}} onChange={handleChange}>
|
|
73
|
+
{({ item, index, realIndex }) => (<SDKSwiperItem index={index} realIndex={realIndex} key={item.key ?? index}>
|
|
74
|
+
{item}
|
|
75
|
+
</SDKSwiperItem>)}
|
|
76
|
+
</SDKSwiper>)}
|
|
77
|
+
</view>);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect } from '@doubao-dev/framework';
|
|
2
|
+
import { View } from '../View/index.jsx';
|
|
3
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
4
|
+
export function SwiperItem({ children, itemId, skipHiddenItemLayout, deep, animation, ...props }) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
warnUnsupported('SwiperItem', [
|
|
7
|
+
...(skipHiddenItemLayout ? ['skipHiddenItemLayout'] : []),
|
|
8
|
+
...(deep ? ['deep'] : []),
|
|
9
|
+
...(animation ? ['animation'] : [])
|
|
10
|
+
]);
|
|
11
|
+
}, [skipHiddenItemLayout, deep, animation]);
|
|
12
|
+
return (<View {...props} style={typeof props.style === 'string'
|
|
13
|
+
? `width:100%;height:100%;${props.style}`
|
|
14
|
+
: { width: '100%', height: '100%', ...props.style }}>
|
|
15
|
+
{children}
|
|
16
|
+
</View>);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Switch as SDKSwitch } from '@doubao-dev/framework/components';
|
|
2
|
+
import { useState } from '@doubao-dev/framework';
|
|
3
|
+
import { useLabelControl } from '../Label/control.js';
|
|
4
|
+
import { useFormField } from '../Form/use-form-field.js';
|
|
5
|
+
import { Checkbox } from '../Checkbox/index.jsx';
|
|
6
|
+
import { changeEvent } from '../base/change-event.js';
|
|
7
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
8
|
+
export function Switch({ id, name, className, style, checked, disabled, type, color, onChange }) {
|
|
9
|
+
const [localChecked, setChecked] = useState(false);
|
|
10
|
+
const selected = checked ?? localChecked;
|
|
11
|
+
const updateForm = useFormField(name, selected);
|
|
12
|
+
function handleChange(value) {
|
|
13
|
+
if (disabled)
|
|
14
|
+
return;
|
|
15
|
+
if (checked === undefined)
|
|
16
|
+
setChecked(value);
|
|
17
|
+
updateForm?.(value);
|
|
18
|
+
onChange?.(changeEvent('switch', id, { value }));
|
|
19
|
+
}
|
|
20
|
+
const insideLabel = useLabelControl(type === 'checkbox' ? undefined : id, () => {
|
|
21
|
+
if (type !== 'checkbox')
|
|
22
|
+
handleChange(!selected);
|
|
23
|
+
}, type !== 'checkbox');
|
|
24
|
+
if (type === 'checkbox') {
|
|
25
|
+
return (<Checkbox value="checked" id={id} className={className} style={style} checked={selected} disabled={disabled} color={color} onChange={(event) => handleChange(event.detail.value.length > 0)}/>);
|
|
26
|
+
}
|
|
27
|
+
warnUnsupported('Switch', color ? ['color'] : []);
|
|
28
|
+
return (<view id={id} catchtap={insideLabel ? () => { } : undefined}>
|
|
29
|
+
<SDKSwitch className={className} style={style} checked={selected} disabled={disabled} onChange={handleChange}/>
|
|
30
|
+
</view>);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
import type { TextProps } from '@tarojs/components';
|
|
3
|
+
export type TextFormatOptions = Pick<TextProps, 'space' | 'decode'>;
|
|
4
|
+
export declare function formatTextChildren(children: ReactNode, options: TextFormatOptions): ReactNode;
|
|
5
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Children, Fragment, cloneElement, isValidElement } from '@doubao-dev/framework';
|
|
2
|
+
const SPACES = {
|
|
3
|
+
ensp: '\u2002',
|
|
4
|
+
emsp: '\u2003',
|
|
5
|
+
nbsp: '\u00a0'
|
|
6
|
+
};
|
|
7
|
+
const ENTITIES = {
|
|
8
|
+
amp: '&',
|
|
9
|
+
lt: '<',
|
|
10
|
+
gt: '>',
|
|
11
|
+
quot: '"',
|
|
12
|
+
apos: "'",
|
|
13
|
+
...SPACES
|
|
14
|
+
};
|
|
15
|
+
function decodeEntities(text) {
|
|
16
|
+
// Decode once so escaped entities such as &lt; remain literal <.
|
|
17
|
+
return text.replace(/&(?:(amp|lt|gt|quot|apos|nbsp|ensp|emsp)|#(\d{1,7})|#[xX]([\da-fA-F]{1,6}));/g, (match, named, decimal, hex) => {
|
|
18
|
+
if (named) {
|
|
19
|
+
return ENTITIES[named];
|
|
20
|
+
}
|
|
21
|
+
const codePoint = decimal ? Number(decimal) : Number.parseInt(hex, 16);
|
|
22
|
+
if (codePoint === 0 || codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) {
|
|
23
|
+
return match;
|
|
24
|
+
}
|
|
25
|
+
return String.fromCodePoint(codePoint);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function formatTextChildren(children, options) {
|
|
29
|
+
const { space, decode } = options;
|
|
30
|
+
const replacement = space === 'ensp' || space === 'emsp' || space === 'nbsp' ? SPACES[space] : undefined;
|
|
31
|
+
if (!decode && replacement === undefined) {
|
|
32
|
+
return children;
|
|
33
|
+
}
|
|
34
|
+
if (typeof children === 'string') {
|
|
35
|
+
const text = decode ? decodeEntities(children) : children;
|
|
36
|
+
return replacement === undefined ? text : text.replace(/ /g, replacement);
|
|
37
|
+
}
|
|
38
|
+
return Children.map(children, (child) => {
|
|
39
|
+
if (typeof child === 'string') {
|
|
40
|
+
return formatTextChildren(child, options);
|
|
41
|
+
}
|
|
42
|
+
if (isValidElement(child) && child.type === Fragment) {
|
|
43
|
+
return cloneElement(child, {
|
|
44
|
+
children: formatTextChildren(child.props.children, options)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Nested Text components format their own children with their own props.
|
|
48
|
+
return child;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ReactNode } from '@
|
|
1
|
+
import type { ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
import { type TextFormatOptions } from './format.js';
|
|
2
3
|
type TextProps = {
|
|
3
4
|
children?: ReactNode;
|
|
4
|
-
} & Record<string, unknown>;
|
|
5
|
-
export declare function Text({ children, ...rest }: TextProps): any;
|
|
5
|
+
} & TextFormatOptions & Record<string, unknown>;
|
|
6
|
+
export declare function Text({ children, space, decode, ...rest }: TextProps): any;
|
|
6
7
|
export {};
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
2
|
+
import { formatTextChildren } from './format.js';
|
|
2
3
|
import { mapTextProps } from './map.js';
|
|
3
|
-
export function Text({ children, ...rest }) {
|
|
4
|
+
export function Text({ children, space, decode, ...rest }) {
|
|
4
5
|
const { mapped, unsupported } = mapTextProps(rest);
|
|
5
6
|
warnUnsupported('Text', unsupported);
|
|
6
|
-
return <text {...mapped}>{children}</text>;
|
|
7
|
+
return <text {...mapped}>{formatTextChildren(children, { space, decode })}</text>;
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=index.jsx.map
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { BASE_PROP_MAP } from '../base/prop-map.js';
|
|
2
2
|
const TEXT_PROP_MAP = {
|
|
3
3
|
selectable: 'text-selection',
|
|
4
|
+
userSelect: 'text-selection',
|
|
4
5
|
numberOfLines: 'text-maxline',
|
|
5
6
|
maxLines: 'text-maxline',
|
|
6
|
-
userSelect: null,
|
|
7
|
-
space: null,
|
|
8
|
-
decode: null,
|
|
9
7
|
overflow: null
|
|
10
8
|
};
|
|
11
9
|
export function mapTextProps(props) {
|
|
12
10
|
const mapped = {};
|
|
13
11
|
const unsupported = [];
|
|
14
12
|
Object.entries(props).forEach(([key, value]) => {
|
|
15
|
-
if (key === 'children') {
|
|
13
|
+
if (key === 'children' || key === 'space' || key === 'decode') {
|
|
16
14
|
return;
|
|
17
15
|
}
|
|
18
16
|
const target = TEXT_PROP_MAP[key] ?? BASE_PROP_MAP[key];
|
|
@@ -30,6 +28,13 @@ export function mapTextProps(props) {
|
|
|
30
28
|
}
|
|
31
29
|
unsupported.push(key);
|
|
32
30
|
});
|
|
31
|
+
const selection = props.userSelect ?? props.selectable;
|
|
32
|
+
if (selection !== undefined) {
|
|
33
|
+
mapped['text-selection'] = selection;
|
|
34
|
+
if (selection === true) {
|
|
35
|
+
mapped.flatten = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
33
38
|
return { mapped, unsupported };
|
|
34
39
|
}
|
|
35
40
|
export { TEXT_PROP_MAP };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TextareaProps } from '@tarojs/components';
|
|
2
|
+
export declare function Textarea({ id, name, className, style, value, placeholder, maxlength, disabled, confirmType, autoHeight, focus, onInput, onFocus, onBlur, onConfirm }: TextareaProps): any;
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TextArea as SDKTextArea } from '@doubao-dev/framework/components';
|
|
2
|
+
import { useEffect, useRef } from '@doubao-dev/framework';
|
|
3
|
+
import { useFormField } from '../Form/use-form-field.js';
|
|
4
|
+
import { changeEvent } from '../base/change-event.js';
|
|
5
|
+
export function Textarea({ id, name, className, style, value, placeholder, maxlength, disabled, confirmType, autoHeight, focus, onInput, onFocus, onBlur, onConfirm }) {
|
|
6
|
+
const updateForm = useFormField(name, value ?? '');
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const nativeValue = useRef();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (value !== undefined && value !== nativeValue.current) {
|
|
11
|
+
// Lynx has no controlled textarea protocol. Only synchronize changed Taro props;
|
|
12
|
+
// echoing onInput back through setValue would add an asynchronous native write.
|
|
13
|
+
nativeValue.current = value;
|
|
14
|
+
ref.current?.invoke({ method: 'setValue', params: { value } }).exec();
|
|
15
|
+
}
|
|
16
|
+
}, [value]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (focus !== undefined) {
|
|
19
|
+
ref.current?.invoke({ method: focus ? 'focus' : 'blur' }).exec();
|
|
20
|
+
}
|
|
21
|
+
}, [focus]);
|
|
22
|
+
return (<SDKTextArea ref={ref} id={id} className={className} style={(autoHeight && typeof style === 'object'
|
|
23
|
+
? { ...style, height: undefined }
|
|
24
|
+
: style)} {...{ 'harmony-auto-height': autoHeight }} placeholder={placeholder} maxlength={maxlength} disabled={disabled} confirmType={confirmType} onInput={(event) => {
|
|
25
|
+
nativeValue.current = event.detail.value;
|
|
26
|
+
updateForm?.(event.detail.value);
|
|
27
|
+
onInput?.(changeEvent('textarea', id, event.detail, 'input'));
|
|
28
|
+
}} onFocus={onFocus && ((event) => onFocus(changeEvent('textarea', id, event.detail, 'focus')))} onBlur={onBlur && ((event) => onBlur(changeEvent('textarea', id, event.detail, 'blur')))} onConfirm={onConfirm && ((event) => onConfirm(changeEvent('textarea', id, event.detail, 'confirm')))}/>);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Video as SDKVideo } from '@doubao-dev/framework/components';
|
|
2
|
+
import { View } from '../View/index.jsx';
|
|
3
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
4
|
+
const objectFit = { contain: 'aspectFit', cover: 'aspectFill', fill: 'scaleToFill' };
|
|
5
|
+
export function Video(props) {
|
|
6
|
+
const { id, className, style, src, poster, autoplay, muted, loop, initialTime, onPlay, onPause, onEnded, onTimeUpdate, onError } = props;
|
|
7
|
+
if (props.controls !== false) {
|
|
8
|
+
warnUnsupported('Video', ['controls']);
|
|
9
|
+
}
|
|
10
|
+
function event(type, detail = {}) {
|
|
11
|
+
const target = { id: id ?? '', dataset: {} };
|
|
12
|
+
return { type, detail, target, currentTarget: target, timeStamp: Date.now() };
|
|
13
|
+
}
|
|
14
|
+
return (<View id={id} className={className}>
|
|
15
|
+
<SDKVideo style={style} playUrl={src} poster={poster} autoPlay={autoplay} mute={muted} loop={loop} initTime={initialTime} objectfit={props.objectFit ? objectFit[props.objectFit] : undefined} onPlay={onPlay && (() => onPlay(event('play')))} onPause={onPause && (() => onPause(event('pause')))} onEnded={onEnded && (() => onEnded(event('ended')))} onError={onError && ((detail) => onError(event('error', { ...detail, errMsg: detail.errorMsg })))} onTimeUpdate={onTimeUpdate &&
|
|
16
|
+
(({ detail }) => onTimeUpdate(event('timeupdate', {
|
|
17
|
+
currentTime: detail.current,
|
|
18
|
+
duration: detail.total
|
|
19
|
+
})))}/>
|
|
20
|
+
</View>);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
type
|
|
1
|
+
import { type ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
import type { AnimationData } from '../../api/create-animation.js';
|
|
3
|
+
export declare const View: (props: {
|
|
3
4
|
children?: ReactNode;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {};
|
|
5
|
+
animation?: AnimationData;
|
|
6
|
+
} & Record<string, unknown> & import("react").RefAttributes<import("@lynx-js/types").NodesRef>) => React.ReactElement | null;
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|