@doubao-apps/taro-runtime 0.0.26 → 0.0.27
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/api/device/accelerometer.d.ts +8 -0
- package/dist/api/device/accelerometer.js +31 -0
- package/dist/api/device/battery.d.ts +6 -0
- package/dist/api/device/battery.js +28 -0
- package/dist/api/device/gyroscope.d.ts +8 -0
- package/dist/api/device/gyroscope.js +31 -0
- package/dist/components/PickerView/index.jsx +65 -32
- package/dist/components/PickerView/map.d.ts +32 -17
- package/dist/components/PickerView/map.js +186 -14
- package/package.json +1 -1
|
@@ -3,7 +3,15 @@ type TaroStartAccelerometerOption = Parameters<typeof Taro.startAccelerometer>[0
|
|
|
3
3
|
type TaroStartAccelerometerResult = Awaited<ReturnType<typeof Taro.startAccelerometer>>;
|
|
4
4
|
type TaroStopAccelerometerOption = Parameters<typeof Taro.stopAccelerometer>[0];
|
|
5
5
|
type TaroStopAccelerometerResult = Awaited<ReturnType<typeof Taro.stopAccelerometer>>;
|
|
6
|
+
type TaroAccelerometerChangeCallback = Parameters<typeof Taro.onAccelerometerChange>[0];
|
|
7
|
+
type TaroAccelerometerChangeCallbackResult = Parameters<TaroAccelerometerChangeCallback>[0];
|
|
8
|
+
type AccelerometerChangeCallbackResult = TaroAccelerometerChangeCallbackResult & {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
};
|
|
11
|
+
type AccelerometerChangeCallback = (result: AccelerometerChangeCallbackResult) => void;
|
|
6
12
|
export declare function startAccelerometer(option?: TaroStartAccelerometerOption): Promise<TaroStartAccelerometerResult>;
|
|
7
13
|
export declare function stopAccelerometer(option?: TaroStopAccelerometerOption): Promise<TaroStopAccelerometerResult>;
|
|
14
|
+
export declare function onAccelerometerChange(callback: AccelerometerChangeCallback): void;
|
|
15
|
+
export declare function offAccelerometerChange(callback?: AccelerometerChangeCallback): void;
|
|
8
16
|
export {};
|
|
9
17
|
//# sourceMappingURL=accelerometer.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
|
|
2
2
|
import { runCallbackApi } from '../utils.js';
|
|
3
|
+
const accelerometerChangeCallbacks = new Map();
|
|
3
4
|
export async function startAccelerometer(option) {
|
|
4
5
|
return runCallbackApi('startAccelerometer', option, () => appFrameworkApi.startAccelerometer({
|
|
5
6
|
interval: option?.interval
|
|
@@ -8,4 +9,34 @@ export async function startAccelerometer(option) {
|
|
|
8
9
|
export async function stopAccelerometer(option) {
|
|
9
10
|
return runCallbackApi('stopAccelerometer', option, () => appFrameworkApi.stopAccelerometer({}));
|
|
10
11
|
}
|
|
12
|
+
export function onAccelerometerChange(callback) {
|
|
13
|
+
if (typeof callback !== 'function' || accelerometerChangeCallbacks.has(callback)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const unregister = appFrameworkApi.onAccelerometerChange((event) => {
|
|
17
|
+
callback({
|
|
18
|
+
x: event.x,
|
|
19
|
+
y: event.y,
|
|
20
|
+
z: event.z,
|
|
21
|
+
timestamp: event.timestamp
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
accelerometerChangeCallbacks.set(callback, unregister);
|
|
25
|
+
}
|
|
26
|
+
export function offAccelerometerChange(callback) {
|
|
27
|
+
if (typeof callback === 'function') {
|
|
28
|
+
const unregister = accelerometerChangeCallbacks.get(callback);
|
|
29
|
+
if (!unregister) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
unregister();
|
|
33
|
+
accelerometerChangeCallbacks.delete(callback);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (callback !== undefined) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
accelerometerChangeCallbacks.forEach((unregister) => unregister());
|
|
40
|
+
accelerometerChangeCallbacks.clear();
|
|
41
|
+
}
|
|
11
42
|
//# sourceMappingURL=accelerometer.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type Taro from '@tarojs/taro';
|
|
2
2
|
type TaroGetBatteryInfoOption = Parameters<typeof Taro.getBatteryInfo>[0];
|
|
3
3
|
type TaroGetBatteryInfoResult = Awaited<ReturnType<typeof Taro.getBatteryInfo>>;
|
|
4
|
+
type BatteryInfoChangeCallbackResult = {
|
|
5
|
+
isLowPowerModeEnabled: boolean;
|
|
6
|
+
};
|
|
7
|
+
type BatteryInfoChangeCallback = (result: BatteryInfoChangeCallbackResult) => void;
|
|
4
8
|
export declare function getBatteryInfo(option?: TaroGetBatteryInfoOption): Promise<TaroGetBatteryInfoResult>;
|
|
9
|
+
export declare function onBatteryInfoChange(callback: BatteryInfoChangeCallback): void;
|
|
10
|
+
export declare function offBatteryInfoChange(callback?: BatteryInfoChangeCallback): void;
|
|
5
11
|
export {};
|
|
6
12
|
//# sourceMappingURL=battery.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
|
|
2
2
|
import { buildOkCallbackResult, runTaroApi } from '../utils.js';
|
|
3
|
+
const batteryInfoChangeCallbacks = new Map();
|
|
3
4
|
function buildGetBatteryInfoResult(result) {
|
|
4
5
|
return {
|
|
5
6
|
isCharging: Boolean(result.isCharging),
|
|
@@ -10,4 +11,31 @@ function buildGetBatteryInfoResult(result) {
|
|
|
10
11
|
export async function getBatteryInfo(option) {
|
|
11
12
|
return runTaroApi('getBatteryInfo', option, async () => buildGetBatteryInfoResult(await appFrameworkApi.getBatteryInfo({})));
|
|
12
13
|
}
|
|
14
|
+
export function onBatteryInfoChange(callback) {
|
|
15
|
+
if (typeof callback !== 'function' || batteryInfoChangeCallbacks.has(callback)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const unregister = appFrameworkApi.onBatteryInfoChange((event) => {
|
|
19
|
+
callback({
|
|
20
|
+
isLowPowerModeEnabled: Boolean(event.isLowPowerModeEnabled)
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
batteryInfoChangeCallbacks.set(callback, unregister);
|
|
24
|
+
}
|
|
25
|
+
export function offBatteryInfoChange(callback) {
|
|
26
|
+
if (typeof callback === 'function') {
|
|
27
|
+
const unregister = batteryInfoChangeCallbacks.get(callback);
|
|
28
|
+
if (!unregister) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
unregister();
|
|
32
|
+
batteryInfoChangeCallbacks.delete(callback);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (callback !== undefined) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
batteryInfoChangeCallbacks.forEach((unregister) => unregister());
|
|
39
|
+
batteryInfoChangeCallbacks.clear();
|
|
40
|
+
}
|
|
13
41
|
//# sourceMappingURL=battery.js.map
|
|
@@ -3,7 +3,15 @@ type TaroStartGyroscopeOption = Parameters<typeof Taro.startGyroscope>[0];
|
|
|
3
3
|
type TaroStartGyroscopeResult = Awaited<ReturnType<typeof Taro.startGyroscope>>;
|
|
4
4
|
type TaroStopGyroscopeOption = Parameters<typeof Taro.stopGyroscope>[0];
|
|
5
5
|
type TaroStopGyroscopeResult = Awaited<ReturnType<typeof Taro.stopGyroscope>>;
|
|
6
|
+
type TaroGyroscopeChangeCallback = Parameters<typeof Taro.onGyroscopeChange>[0];
|
|
7
|
+
type TaroGyroscopeChangeCallbackResult = Parameters<TaroGyroscopeChangeCallback>[0];
|
|
8
|
+
type GyroscopeChangeCallbackResult = TaroGyroscopeChangeCallbackResult & {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
};
|
|
11
|
+
type GyroscopeChangeCallback = (result: GyroscopeChangeCallbackResult) => void;
|
|
6
12
|
export declare function startGyroscope(option: TaroStartGyroscopeOption): Promise<TaroStartGyroscopeResult>;
|
|
7
13
|
export declare function stopGyroscope(option?: TaroStopGyroscopeOption): Promise<TaroStopGyroscopeResult>;
|
|
14
|
+
export declare function onGyroscopeChange(callback: GyroscopeChangeCallback): void;
|
|
15
|
+
export declare function offGyroscopeChange(callback?: GyroscopeChangeCallback): void;
|
|
8
16
|
export {};
|
|
9
17
|
//# sourceMappingURL=gyroscope.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
|
|
2
2
|
import { runCallbackApi } from '../utils.js';
|
|
3
|
+
const gyroscopeChangeCallbacks = new Map();
|
|
3
4
|
export async function startGyroscope(option) {
|
|
4
5
|
return runCallbackApi('startGyroscope', option, () => appFrameworkApi.startGyroscope({
|
|
5
6
|
interval: option.interval
|
|
@@ -8,4 +9,34 @@ export async function startGyroscope(option) {
|
|
|
8
9
|
export async function stopGyroscope(option) {
|
|
9
10
|
return runCallbackApi('stopGyroscope', option, () => appFrameworkApi.stopGyroscope({}));
|
|
10
11
|
}
|
|
12
|
+
export function onGyroscopeChange(callback) {
|
|
13
|
+
if (typeof callback !== 'function' || gyroscopeChangeCallbacks.has(callback)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const unregister = appFrameworkApi.onGyroscopeChange((event) => {
|
|
17
|
+
callback({
|
|
18
|
+
x: event.x,
|
|
19
|
+
y: event.y,
|
|
20
|
+
z: event.z,
|
|
21
|
+
timestamp: event.timestamp
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
gyroscopeChangeCallbacks.set(callback, unregister);
|
|
25
|
+
}
|
|
26
|
+
export function offGyroscopeChange(callback) {
|
|
27
|
+
if (typeof callback === 'function') {
|
|
28
|
+
const unregister = gyroscopeChangeCallbacks.get(callback);
|
|
29
|
+
if (!unregister) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
unregister();
|
|
33
|
+
gyroscopeChangeCallbacks.delete(callback);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (callback !== undefined) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
gyroscopeChangeCallbacks.forEach((unregister) => unregister());
|
|
40
|
+
gyroscopeChangeCallbacks.clear();
|
|
41
|
+
}
|
|
11
42
|
//# sourceMappingURL=gyroscope.js.map
|
|
@@ -1,42 +1,50 @@
|
|
|
1
|
-
import { Children, cloneElement } from 'react';
|
|
2
1
|
import { PickerView as DoubaoPickerView, PickerColumn as DoubaoPickerColumn } from '@byted-doubao-apps/components';
|
|
3
|
-
import {
|
|
2
|
+
import { warnUnsupported } from '../base/warn-unsupported.js';
|
|
3
|
+
import { buildOptionsFromChildren, buildOptionsFromRange, mapPickerViewColumnProps, mapPickerViewProps, resolveExplicitItemHeight, resolveItemHeightFromChildren, resolveSelectedIndexValue, toPickerViewChangeEvent } from './map.js';
|
|
4
|
+
const PICKER_VIEW_COLUMN_TYPE = 'taro-picker-view-column';
|
|
4
5
|
export function PickerView(props) {
|
|
5
|
-
const { value, onChange, children, ...rest } = props;
|
|
6
|
-
const { mapped, unsupported } = mapPickerViewProps(rest);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const { value, defaultValue, onChange, children, itemHeight: propItemHeight, ...rest } = props;
|
|
7
|
+
const { mapped, unsupported, indicatorItemHeight } = mapPickerViewProps(rest);
|
|
8
|
+
const explicitItemHeight = resolveExplicitItemHeight(propItemHeight);
|
|
9
|
+
const pickerViewId = typeof mapped.id === 'string' ? mapped.id : '';
|
|
10
|
+
warnUnsupported('PickerView', propItemHeight !== undefined && explicitItemHeight === undefined
|
|
11
|
+
? [...unsupported, 'itemHeight must be a positive number']
|
|
12
|
+
: unsupported);
|
|
13
|
+
const columns = [];
|
|
14
|
+
toChildArray(children).forEach((child) => {
|
|
15
|
+
if (!isPickerViewColumnElement(child)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const columnProps = child.props;
|
|
19
|
+
const { className, style, unsupported: columnUnsupported } = mapPickerViewColumnProps(columnProps);
|
|
20
|
+
warnUnsupported('PickerViewColumn', columnUnsupported);
|
|
21
|
+
columns.push({
|
|
22
|
+
options: Array.isArray(columnProps.range)
|
|
23
|
+
? buildOptionsFromRange(columnProps.range)
|
|
24
|
+
: buildOptionsFromChildren(columnProps.children),
|
|
25
|
+
className,
|
|
26
|
+
style,
|
|
27
|
+
itemHeight: resolveItemHeightFromChildren(columnProps.children)
|
|
22
28
|
});
|
|
23
29
|
});
|
|
30
|
+
const resolvedItemHeight = explicitItemHeight ??
|
|
31
|
+
indicatorItemHeight ??
|
|
32
|
+
columns.find((column) => column.itemHeight !== undefined)?.itemHeight;
|
|
24
33
|
const handleChange = (values, selectedOptions) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
const indices = values.map((selectedValue, index) => {
|
|
35
|
+
if (typeof selectedValue === 'number') {
|
|
36
|
+
return selectedValue;
|
|
37
|
+
}
|
|
38
|
+
const optionValue = selectedOptions[index]?.value;
|
|
39
|
+
return typeof optionValue === 'number' ? optionValue : 0;
|
|
30
40
|
});
|
|
31
|
-
onChange?.(toPickerViewChangeEvent(indices));
|
|
41
|
+
onChange?.(toPickerViewChangeEvent(indices, pickerViewId));
|
|
32
42
|
};
|
|
33
|
-
return (<DoubaoPickerView {...mapped} onChange={onChange ? handleChange : undefined}>
|
|
34
|
-
{
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const columnStyle = child?.props?.style;
|
|
39
|
-
return (<DoubaoPickerColumn options={options ?? []} value={valueForColumn} className={columnClassName} style={columnStyle}/>);
|
|
43
|
+
return (<DoubaoPickerView {...mapped} itemHeight={resolvedItemHeight} onChange={onChange ? handleChange : undefined}>
|
|
44
|
+
{columns.map(({ options, className, style }, index) => {
|
|
45
|
+
const valueForColumn = resolveSelectedIndexValue(value, index, options);
|
|
46
|
+
const defaultValueForColumn = resolveSelectedIndexValue(defaultValue, index, options);
|
|
47
|
+
return (<DoubaoPickerColumn key={index} options={options} value={valueForColumn} defaultValue={defaultValueForColumn} className={className} style={style}/>);
|
|
40
48
|
})}
|
|
41
49
|
</DoubaoPickerView>);
|
|
42
50
|
}
|
|
@@ -44,4 +52,29 @@ export function PickerViewColumn(_props) {
|
|
|
44
52
|
// This is a placeholder wrapper. Real rendering is performed by PickerView above after mapping.
|
|
45
53
|
return null;
|
|
46
54
|
}
|
|
55
|
+
PickerViewColumn.__TARO_PICKER_VIEW_CHILD_TYPE = PICKER_VIEW_COLUMN_TYPE;
|
|
56
|
+
function isPickerViewColumnElement(child) {
|
|
57
|
+
if (!isReactElement(child)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const childType = child.type;
|
|
61
|
+
return (childType.__TARO_PICKER_VIEW_CHILD_TYPE === PICKER_VIEW_COLUMN_TYPE ||
|
|
62
|
+
childType.displayName === 'PickerViewColumn' ||
|
|
63
|
+
childType.name === 'PickerViewColumn' ||
|
|
64
|
+
child.type === 'picker-view-column' ||
|
|
65
|
+
child.type === 'taro-picker-view-column-core');
|
|
66
|
+
}
|
|
67
|
+
function isReactElement(node) {
|
|
68
|
+
return (typeof node === 'object' &&
|
|
69
|
+
node !== null &&
|
|
70
|
+
node.$$typeof === Symbol.for('react.element') &&
|
|
71
|
+
'type' in node &&
|
|
72
|
+
'props' in node);
|
|
73
|
+
}
|
|
74
|
+
function toChildArray(children) {
|
|
75
|
+
if (children === null || children === undefined || typeof children === 'boolean') {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return Array.isArray(children) ? children.flatMap(toChildArray) : [children];
|
|
79
|
+
}
|
|
47
80
|
//# sourceMappingURL=index.jsx.map
|
|
@@ -1,36 +1,51 @@
|
|
|
1
1
|
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { PickerViewProps as TaroPickerViewPropsBase } from '@tarojs/components';
|
|
2
4
|
import type { PickerViewProps as LynxPickerViewProps, PickerColumnOption } from '@byted-doubao-apps/framework/components';
|
|
3
|
-
export type TaroPickerViewProps = {
|
|
4
|
-
|
|
5
|
-
style?: CSSProperties;
|
|
6
|
-
value?: number[];
|
|
7
|
-
indicatorStyle?: CSSProperties;
|
|
8
|
-
maskStyle?: CSSProperties;
|
|
9
|
-
onChange?: (event: {
|
|
10
|
-
type: string;
|
|
11
|
-
timeStamp: number;
|
|
12
|
-
detail: {
|
|
13
|
-
value: number[];
|
|
14
|
-
};
|
|
15
|
-
}) => void;
|
|
16
|
-
children?: any;
|
|
5
|
+
export type TaroPickerViewProps = TaroPickerViewPropsBase & {
|
|
6
|
+
children?: ReactNode;
|
|
17
7
|
};
|
|
18
8
|
export type TaroPickerViewColumnProps = {
|
|
9
|
+
children?: ReactNode;
|
|
19
10
|
range?: Array<string | number>;
|
|
20
11
|
className?: string;
|
|
21
12
|
style?: CSSProperties;
|
|
22
13
|
};
|
|
23
|
-
export
|
|
14
|
+
export type PickerViewChangeEvent = {
|
|
24
15
|
type: string;
|
|
25
16
|
timeStamp: number;
|
|
17
|
+
target: {
|
|
18
|
+
id: string;
|
|
19
|
+
tagName: string;
|
|
20
|
+
dataset: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
currentTarget: {
|
|
23
|
+
id: string;
|
|
24
|
+
tagName: string;
|
|
25
|
+
dataset: Record<string, unknown>;
|
|
26
|
+
};
|
|
26
27
|
detail: {
|
|
27
28
|
value: number[];
|
|
28
29
|
};
|
|
30
|
+
preventDefault: () => void;
|
|
31
|
+
stopPropagation: () => void;
|
|
29
32
|
};
|
|
33
|
+
export declare function toPickerViewChangeEvent(indices: number[], pickerViewId?: string): PickerViewChangeEvent;
|
|
30
34
|
export declare function buildOptionsFromRange(range?: Array<string | number>): PickerColumnOption[];
|
|
31
|
-
export declare function
|
|
35
|
+
export declare function buildOptionsFromChildren(children?: ReactNode): PickerColumnOption[];
|
|
36
|
+
export declare function resolveSelectedIndexValue(indices: number[] | undefined, columnIndex: number, options: PickerColumnOption[]): number | undefined;
|
|
32
37
|
export declare function mapPickerViewProps(props: TaroPickerViewProps): {
|
|
33
|
-
mapped: Pick<LynxPickerViewProps, 'className' | 'style'>;
|
|
38
|
+
mapped: Pick<LynxPickerViewProps, 'className' | 'style'> & Record<string, unknown>;
|
|
39
|
+
unsupported: string[];
|
|
40
|
+
pickerViewId: string;
|
|
41
|
+
indicatorItemHeight: number | undefined;
|
|
42
|
+
};
|
|
43
|
+
export declare function mapPickerViewColumnProps(props: TaroPickerViewColumnProps): {
|
|
44
|
+
className?: string;
|
|
45
|
+
style?: CSSProperties;
|
|
34
46
|
unsupported: string[];
|
|
35
47
|
};
|
|
48
|
+
export declare function resolveItemHeightFromChildren(children?: ReactNode): number | undefined;
|
|
49
|
+
export declare function resolveExplicitItemHeight(itemHeight: unknown): number | undefined;
|
|
50
|
+
export declare function resolveItemHeightFromIndicatorStyle(indicatorStyle: unknown): number | undefined;
|
|
36
51
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1,29 +1,201 @@
|
|
|
1
|
-
|
|
1
|
+
import { BASE_PROP_MAP } from '../base/prop-map.js';
|
|
2
|
+
export function toPickerViewChangeEvent(indices, pickerViewId = '') {
|
|
2
3
|
return {
|
|
3
4
|
type: 'change',
|
|
4
5
|
timeStamp: Date.now(),
|
|
5
|
-
|
|
6
|
+
target: {
|
|
7
|
+
id: pickerViewId,
|
|
8
|
+
tagName: 'picker-view',
|
|
9
|
+
dataset: {}
|
|
10
|
+
},
|
|
11
|
+
currentTarget: {
|
|
12
|
+
id: pickerViewId,
|
|
13
|
+
tagName: 'picker-view',
|
|
14
|
+
dataset: {}
|
|
15
|
+
},
|
|
16
|
+
detail: { value: indices },
|
|
17
|
+
preventDefault: () => { },
|
|
18
|
+
stopPropagation: () => { }
|
|
6
19
|
};
|
|
7
20
|
}
|
|
8
21
|
export function buildOptionsFromRange(range) {
|
|
9
|
-
return (range ?? []).map((item) => ({ label: String(item), value:
|
|
22
|
+
return (range ?? []).map((item, index) => ({ label: String(item), value: index }));
|
|
10
23
|
}
|
|
11
|
-
export function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
export function buildOptionsFromChildren(children) {
|
|
25
|
+
return toChildArray(children).map((child, index) => ({
|
|
26
|
+
label: extractText(child) || String(index),
|
|
27
|
+
value: index
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
export function resolveSelectedIndexValue(indices, columnIndex, options) {
|
|
31
|
+
const selectedIndex = indices?.[columnIndex];
|
|
32
|
+
if (selectedIndex === undefined || options.length === 0) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
if (typeof selectedIndex !== 'number' || Number.isNaN(selectedIndex)) {
|
|
36
|
+
return undefined;
|
|
15
37
|
}
|
|
38
|
+
return Math.min(Math.max(Math.trunc(selectedIndex), 0), options.length - 1);
|
|
16
39
|
}
|
|
17
40
|
export function mapPickerViewProps(props) {
|
|
41
|
+
const { value: _value, defaultValue: _defaultValue, children: _children, onChange: _onChange, indicatorStyle, indicatorClass, maskStyle, maskClass, immediateChange, onPickStart, onPickEnd, title, ariaLabel, ...rest } = props;
|
|
18
42
|
const unsupported = [];
|
|
19
|
-
|
|
43
|
+
const indicatorItemHeight = resolveItemHeightFromIndicatorStyle(indicatorStyle);
|
|
44
|
+
unsupported.push(...getUnsupportedIndicatorStyleWarnings(indicatorStyle, indicatorItemHeight));
|
|
45
|
+
if (indicatorClass !== undefined)
|
|
46
|
+
unsupported.push('indicatorClass');
|
|
47
|
+
if (maskStyle !== undefined)
|
|
20
48
|
unsupported.push('maskStyle');
|
|
21
|
-
if (
|
|
22
|
-
unsupported.push('
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
if (maskClass !== undefined)
|
|
50
|
+
unsupported.push('maskClass');
|
|
51
|
+
if (immediateChange !== undefined)
|
|
52
|
+
unsupported.push('immediateChange');
|
|
53
|
+
if (onPickStart !== undefined)
|
|
54
|
+
unsupported.push('onPickStart');
|
|
55
|
+
if (onPickEnd !== undefined)
|
|
56
|
+
unsupported.push('onPickEnd');
|
|
57
|
+
if (title !== undefined)
|
|
58
|
+
unsupported.push('title');
|
|
59
|
+
if (ariaLabel !== undefined)
|
|
60
|
+
unsupported.push('ariaLabel');
|
|
61
|
+
const mapped = {};
|
|
62
|
+
Object.entries(rest).forEach(([key, value]) => {
|
|
63
|
+
const target = BASE_PROP_MAP[key];
|
|
64
|
+
if (target) {
|
|
65
|
+
mapped[target] = value;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
unsupported.push(key);
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
mapped,
|
|
72
|
+
unsupported: dedupe(unsupported),
|
|
73
|
+
pickerViewId: resolveId(mapped.id),
|
|
74
|
+
indicatorItemHeight
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function mapPickerViewColumnProps(props) {
|
|
78
|
+
const { children: _children, range: _range, className, style, ...rest } = props;
|
|
79
|
+
return {
|
|
80
|
+
className,
|
|
81
|
+
style,
|
|
82
|
+
unsupported: Object.keys(rest)
|
|
26
83
|
};
|
|
27
|
-
|
|
84
|
+
}
|
|
85
|
+
export function resolveItemHeightFromChildren(children) {
|
|
86
|
+
const firstHeight = toChildArray(children)
|
|
87
|
+
.map((child) => {
|
|
88
|
+
if (!isReactElement(child)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return parseStyleHeight(child.props.style);
|
|
92
|
+
})
|
|
93
|
+
.find((height) => height !== undefined);
|
|
94
|
+
return firstHeight;
|
|
95
|
+
}
|
|
96
|
+
export function resolveExplicitItemHeight(itemHeight) {
|
|
97
|
+
return typeof itemHeight === 'number' && Number.isFinite(itemHeight) && itemHeight > 0
|
|
98
|
+
? itemHeight
|
|
99
|
+
: undefined;
|
|
100
|
+
}
|
|
101
|
+
export function resolveItemHeightFromIndicatorStyle(indicatorStyle) {
|
|
102
|
+
if (typeof indicatorStyle === 'string') {
|
|
103
|
+
return parseStyleHeightString(indicatorStyle);
|
|
104
|
+
}
|
|
105
|
+
return parseStyleHeight(indicatorStyle);
|
|
106
|
+
}
|
|
107
|
+
function hasRpxIndicatorHeight(indicatorStyle) {
|
|
108
|
+
if (typeof indicatorStyle === 'string') {
|
|
109
|
+
return /(?:^|;)\s*height\s*:\s*\d+(?:\.\d+)?rpx\s*(?:;|$)/.test(indicatorStyle);
|
|
110
|
+
}
|
|
111
|
+
if (!indicatorStyle || typeof indicatorStyle !== 'object' || Array.isArray(indicatorStyle)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const height = indicatorStyle.height;
|
|
115
|
+
return typeof height === 'string' && /^\d+(?:\.\d+)?rpx$/.test(height.trim());
|
|
116
|
+
}
|
|
117
|
+
function getUnsupportedIndicatorStyleWarnings(indicatorStyle, indicatorItemHeight) {
|
|
118
|
+
if (indicatorStyle === undefined) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const unsupported = [];
|
|
122
|
+
if (hasUnsupportedIndicatorStyleFields(indicatorStyle)) {
|
|
123
|
+
unsupported.push('indicatorStyle only supports height');
|
|
124
|
+
}
|
|
125
|
+
if (hasRpxIndicatorHeight(indicatorStyle)) {
|
|
126
|
+
unsupported.push('indicatorStyle.height uses rpx, please use px or number');
|
|
127
|
+
}
|
|
128
|
+
else if (indicatorItemHeight === undefined) {
|
|
129
|
+
unsupported.push('indicatorStyle.height must be px or number');
|
|
130
|
+
}
|
|
131
|
+
return unsupported;
|
|
132
|
+
}
|
|
133
|
+
function hasUnsupportedIndicatorStyleFields(indicatorStyle) {
|
|
134
|
+
if (typeof indicatorStyle === 'string') {
|
|
135
|
+
return parseStyleDeclarationNames(indicatorStyle).some((name) => name !== 'height');
|
|
136
|
+
}
|
|
137
|
+
if (!indicatorStyle || typeof indicatorStyle !== 'object' || Array.isArray(indicatorStyle)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return Object.keys(indicatorStyle).some((name) => name !== 'height');
|
|
141
|
+
}
|
|
142
|
+
function parseStyleDeclarationNames(style) {
|
|
143
|
+
return style
|
|
144
|
+
.split(';')
|
|
145
|
+
.map((declaration) => declaration.trim())
|
|
146
|
+
.filter(Boolean)
|
|
147
|
+
.map((declaration) => declaration.split(':')[0]?.trim())
|
|
148
|
+
.filter((name) => Boolean(name));
|
|
149
|
+
}
|
|
150
|
+
function extractText(node) {
|
|
151
|
+
if (node === null || node === undefined || typeof node === 'boolean') {
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
if (typeof node === 'string' || typeof node === 'number') {
|
|
155
|
+
return String(node);
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(node)) {
|
|
158
|
+
return node.map(extractText).join('');
|
|
159
|
+
}
|
|
160
|
+
if (isReactElement(node)) {
|
|
161
|
+
return extractText(node.props.children);
|
|
162
|
+
}
|
|
163
|
+
return '';
|
|
164
|
+
}
|
|
165
|
+
function isReactElement(node) {
|
|
166
|
+
return (typeof node === 'object' &&
|
|
167
|
+
node !== null &&
|
|
168
|
+
node.$$typeof === Symbol.for('react.element') &&
|
|
169
|
+
'props' in node);
|
|
170
|
+
}
|
|
171
|
+
function toChildArray(children) {
|
|
172
|
+
if (children === null || children === undefined || typeof children === 'boolean') {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
return Array.isArray(children) ? children.flatMap(toChildArray) : [children];
|
|
176
|
+
}
|
|
177
|
+
function resolveId(id) {
|
|
178
|
+
return typeof id === 'string' ? id : '';
|
|
179
|
+
}
|
|
180
|
+
function dedupe(items) {
|
|
181
|
+
return Array.from(new Set(items));
|
|
182
|
+
}
|
|
183
|
+
function parseStyleHeight(style) {
|
|
184
|
+
if (!style || typeof style !== 'object' || Array.isArray(style)) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
const height = style.height;
|
|
188
|
+
if (typeof height === 'number' && Number.isFinite(height)) {
|
|
189
|
+
return height;
|
|
190
|
+
}
|
|
191
|
+
if (typeof height !== 'string') {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
const match = height.trim().match(/^(\d+(?:\.\d+)?)px$/);
|
|
195
|
+
return match ? Number(match[1]) : undefined;
|
|
196
|
+
}
|
|
197
|
+
function parseStyleHeightString(style) {
|
|
198
|
+
const match = style.match(/(?:^|;)\s*height\s*:\s*(\d+(?:\.\d+)?)px\s*(?:;|$)/);
|
|
199
|
+
return match ? Number(match[1]) : undefined;
|
|
28
200
|
}
|
|
29
201
|
//# sourceMappingURL=map.js.map
|
package/package.json
CHANGED