@doubao-apps/taro-runtime 0.0.20 → 0.0.23
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/map/index.js
CHANGED
|
@@ -27,8 +27,12 @@ export function createMapContext(mapId, _component) {
|
|
|
27
27
|
if (!Array.isArray(resolvedOption.points)) {
|
|
28
28
|
return rejectMethod('includePoints', resolvedOption, 'points is required');
|
|
29
29
|
}
|
|
30
|
+
const padding = normalizeFitPointsPadding(resolvedOption.padding);
|
|
31
|
+
if (resolvedOption.padding !== undefined && padding === undefined) {
|
|
32
|
+
return rejectMethod('includePoints', resolvedOption, 'padding does not support non-number values');
|
|
33
|
+
}
|
|
30
34
|
return runWithController(mapId, 'includePoints', resolvedOption, (controller) => {
|
|
31
|
-
controller[MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD.includePoints](resolvedOption.points,
|
|
35
|
+
controller[MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD.includePoints](resolvedOption.points, padding);
|
|
32
36
|
return undefined;
|
|
33
37
|
});
|
|
34
38
|
},
|
|
@@ -105,4 +109,16 @@ function rejectMethod(method, option, message) {
|
|
|
105
109
|
emitFailure(option, payload);
|
|
106
110
|
return Promise.reject(payload);
|
|
107
111
|
}
|
|
112
|
+
function normalizeFitPointsPadding(padding) {
|
|
113
|
+
if (padding === undefined || (Array.isArray(padding) && padding.length === 0)) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (!Array.isArray(padding) || padding.some((value) => typeof value !== 'number')) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const [top, right = top, bottom = top, left = right] = padding;
|
|
120
|
+
// Taro includePoints padding follows top/right/bottom/left, but component
|
|
121
|
+
// fitPoints expects left/right/top/bottom.
|
|
122
|
+
return [left, right, top, bottom];
|
|
123
|
+
}
|
|
108
124
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
import type { MapMarkerProps } from '@byted-doubao-apps/components';
|
|
1
|
+
import type { MapMarkerProps, MapProps as ComponentMapProps } from '@byted-doubao-apps/components';
|
|
2
2
|
import type { MapProps } from '@tarojs/components';
|
|
3
|
-
export interface NativeRegionChangeDetail {
|
|
4
|
-
type: 'begin' | 'end';
|
|
5
|
-
rotate: number;
|
|
6
|
-
scale: number;
|
|
7
|
-
center: MapProps.point;
|
|
8
|
-
region: {
|
|
9
|
-
northeast: MapProps.point;
|
|
10
|
-
southwest: MapProps.point;
|
|
11
|
-
};
|
|
12
|
-
causedBy: 'drag' | 'scale' | 'rotate';
|
|
13
|
-
}
|
|
14
|
-
export interface NativeRegionChangeLike {
|
|
15
|
-
type: 'begin' | 'end';
|
|
16
|
-
rotate?: number;
|
|
17
|
-
scale?: number;
|
|
18
|
-
center?: MapProps.point;
|
|
19
|
-
region?: {
|
|
20
|
-
northeast: MapProps.point;
|
|
21
|
-
southwest: MapProps.point;
|
|
22
|
-
};
|
|
23
|
-
causedBy?: 'drag' | 'scale' | 'rotate';
|
|
24
|
-
}
|
|
25
3
|
export interface NativeMarkerBridgeProps {
|
|
26
4
|
markerId: string | number;
|
|
27
5
|
position: MapProps.point;
|
|
@@ -83,8 +61,8 @@ export declare function resolveNativePolygons(polygons: MapProps.polygon[]): {
|
|
|
83
61
|
}[];
|
|
84
62
|
export declare function resolvePadding(padding: NonNullable<MapProps['includePadding']>): number[] | undefined;
|
|
85
63
|
export declare function resolveCustomMapStyle(customMapStyle: MapProps['customMapStyle']): "normal-light" | "simple-light" | undefined;
|
|
86
|
-
export declare function mapRegionChangeDetail(detail:
|
|
87
|
-
export declare function mapPolylineTapDetail(
|
|
64
|
+
export declare function mapRegionChangeDetail(detail: Parameters<NonNullable<ComponentMapProps['onRegionChange']>>[0]): MapProps.onRegionEventDetail<'begin'> | MapProps.onRegionEventDetail<'end'>;
|
|
65
|
+
export declare function mapPolylineTapDetail(detail: Parameters<NonNullable<ComponentMapProps['onPolylineClick']>>[0]): MapProps.onPolylineTapEventDetail;
|
|
88
66
|
export declare function mapMarkerToNativeProps(marker: MapProps.marker, index: number): NativeMarkerBridgeProps;
|
|
89
67
|
export declare function getMarkerId(marker: MapProps.marker, index: number): number;
|
|
90
68
|
export declare function createMarkerElementProps(options: MarkerElementPropsOptions): MapMarkerProps;
|
|
@@ -97,8 +75,7 @@ export declare function composeMarkers(propMarkers: MapProps.marker[], addedMark
|
|
|
97
75
|
export declare function mergeMarkersById(base: MapProps.marker[], incoming: MapProps.marker[]): MapProps.marker[];
|
|
98
76
|
export declare function removeMarkersByIds(markers: MapProps.marker[], markerIds: number[]): MapProps.marker[];
|
|
99
77
|
export declare function getNumericMarkerId(marker: MapProps.marker): number | undefined;
|
|
100
|
-
export declare function mapRegionCausedByEnd(causedBy: 'drag' | 'scale' | '
|
|
101
|
-
export declare function toNativeRegionChangeDetail(detail: NativeRegionChangeLike): NativeRegionChangeDetail;
|
|
78
|
+
export declare function mapRegionCausedByEnd(causedBy: 'drag' | 'scale', by?: 'user' | 'api'): "scale" | "drag" | "update";
|
|
102
79
|
export declare function dispatchMarkerTapEvent<T>(handlers: {
|
|
103
80
|
onMarkerTap?: (event: T) => void;
|
|
104
81
|
onLabelTap?: (event: T) => void;
|
|
@@ -77,12 +77,29 @@ export function resolveNativePolygons(polygons) {
|
|
|
77
77
|
}));
|
|
78
78
|
}
|
|
79
79
|
export function resolvePadding(padding) {
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
// Taro includePadding is expressed as top/right/bottom/left,
|
|
81
|
+
// while Doubao MapRef.fitPoints expects left/right/top/bottom.
|
|
82
|
+
const values = [padding.left, padding.right, padding.top, padding.bottom]
|
|
83
|
+
.map((value) => toPaddingNumber(value))
|
|
84
|
+
.filter((value) => value !== undefined);
|
|
85
|
+
if (values.length !== 4) {
|
|
86
|
+
console.error('[doubao-apps/taro-runtime] Map includePadding does not support non-number values.');
|
|
82
87
|
return undefined;
|
|
83
88
|
}
|
|
84
89
|
return values;
|
|
85
90
|
}
|
|
91
|
+
function toPaddingNumber(value) {
|
|
92
|
+
if (typeof value === 'number') {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'string') {
|
|
96
|
+
const parsed = Number(value.trim());
|
|
97
|
+
if (Number.isFinite(parsed)) {
|
|
98
|
+
return parsed;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
86
103
|
export function resolveCustomMapStyle(customMapStyle) {
|
|
87
104
|
if (customMapStyle === 'default') {
|
|
88
105
|
return 'normal-light';
|
|
@@ -93,45 +110,56 @@ export function resolveCustomMapStyle(customMapStyle) {
|
|
|
93
110
|
return undefined;
|
|
94
111
|
}
|
|
95
112
|
export function mapRegionChangeDetail(detail) {
|
|
113
|
+
const center = detail.center ?? { latitude: 0, longitude: 0 };
|
|
114
|
+
const regionSource = detail.region ?? {
|
|
115
|
+
northeast: center,
|
|
116
|
+
southwest: center
|
|
117
|
+
};
|
|
118
|
+
const causedBy = detail.causedBy ?? 'drag';
|
|
119
|
+
const rotate = detail.rotate ?? 0;
|
|
120
|
+
const scale = detail.scale ?? 0;
|
|
121
|
+
const beginCausedBy = mapRegionCausedByBegin(causedBy, detail.by);
|
|
96
122
|
const region = {
|
|
97
|
-
northeast:
|
|
123
|
+
northeast: regionSource.northeast,
|
|
98
124
|
southeast: {
|
|
99
|
-
longitude:
|
|
100
|
-
latitude:
|
|
125
|
+
longitude: regionSource.northeast.longitude,
|
|
126
|
+
latitude: regionSource.southwest.latitude
|
|
101
127
|
}
|
|
102
128
|
};
|
|
103
129
|
if (detail.type === 'begin') {
|
|
104
130
|
return {
|
|
105
131
|
type: 'begin',
|
|
106
|
-
causedBy:
|
|
132
|
+
causedBy: beginCausedBy,
|
|
107
133
|
detail: {
|
|
108
|
-
rotate
|
|
134
|
+
rotate,
|
|
109
135
|
skew: 0,
|
|
110
|
-
causedBy:
|
|
136
|
+
causedBy: beginCausedBy,
|
|
111
137
|
type: 'begin',
|
|
112
|
-
scale
|
|
113
|
-
centerLocation:
|
|
138
|
+
scale,
|
|
139
|
+
centerLocation: center,
|
|
114
140
|
region
|
|
115
141
|
}
|
|
116
142
|
};
|
|
117
143
|
}
|
|
118
144
|
return {
|
|
119
145
|
type: 'end',
|
|
120
|
-
causedBy: mapRegionCausedByEnd(detail.
|
|
146
|
+
causedBy: mapRegionCausedByEnd(causedBy, detail.by),
|
|
121
147
|
detail: {
|
|
122
|
-
rotate
|
|
148
|
+
rotate,
|
|
123
149
|
skew: 0,
|
|
124
|
-
causedBy: mapRegionCausedByEnd(detail.
|
|
150
|
+
causedBy: mapRegionCausedByEnd(causedBy, detail.by),
|
|
125
151
|
type: 'end',
|
|
126
|
-
scale
|
|
127
|
-
centerLocation:
|
|
152
|
+
scale,
|
|
153
|
+
centerLocation: center,
|
|
128
154
|
region
|
|
129
155
|
}
|
|
130
156
|
};
|
|
131
157
|
}
|
|
132
|
-
export function mapPolylineTapDetail(
|
|
158
|
+
export function mapPolylineTapDetail(detail) {
|
|
133
159
|
return {
|
|
134
|
-
polylineId: coerceEventId(id)
|
|
160
|
+
polylineId: coerceEventId(detail.id),
|
|
161
|
+
longitude: 0,
|
|
162
|
+
latitude: 0
|
|
135
163
|
};
|
|
136
164
|
}
|
|
137
165
|
export function mapMarkerToNativeProps(marker, index) {
|
|
@@ -252,26 +280,17 @@ export function removeMarkersByIds(markers, markerIds) {
|
|
|
252
280
|
export function getNumericMarkerId(marker) {
|
|
253
281
|
return typeof marker.id === 'number' ? marker.id : undefined;
|
|
254
282
|
}
|
|
255
|
-
export function mapRegionCausedByEnd(causedBy) {
|
|
256
|
-
if (
|
|
257
|
-
return
|
|
283
|
+
export function mapRegionCausedByEnd(causedBy, by) {
|
|
284
|
+
if (by === 'api') {
|
|
285
|
+
return 'update';
|
|
258
286
|
}
|
|
259
|
-
return
|
|
287
|
+
return causedBy;
|
|
260
288
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
};
|
|
267
|
-
return {
|
|
268
|
-
type: detail.type,
|
|
269
|
-
rotate: detail.rotate ?? 0,
|
|
270
|
-
scale: detail.scale ?? 0,
|
|
271
|
-
center,
|
|
272
|
-
region,
|
|
273
|
-
causedBy: detail.causedBy ?? 'rotate'
|
|
274
|
-
};
|
|
289
|
+
function mapRegionCausedByBegin(causedBy, by) {
|
|
290
|
+
if (by === 'api') {
|
|
291
|
+
return 'update';
|
|
292
|
+
}
|
|
293
|
+
return 'gesture';
|
|
275
294
|
}
|
|
276
295
|
export function dispatchMarkerTapEvent(handlers, event) {
|
|
277
296
|
handlers.onMarkerTap?.(event);
|
|
@@ -89,13 +89,21 @@ function DoubaoAppsMap(props) {
|
|
|
89
89
|
resolvedPolygons
|
|
90
90
|
});
|
|
91
91
|
warnUnsupported('Map', unsupported);
|
|
92
|
+
const { top: includePaddingTop, right: includePaddingRight, bottom: includePaddingBottom, left: includePaddingLeft } = includePadding ?? {};
|
|
92
93
|
useEffect(() => {
|
|
93
94
|
if (!mapControllerRef.current || !includePoints?.length) {
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
97
|
const padding = includePadding ? resolvePadding(includePadding) : undefined;
|
|
97
98
|
void mapControllerRef.current.fitPoints(includePoints, padding);
|
|
98
|
-
}, [
|
|
99
|
+
}, [
|
|
100
|
+
includePoints,
|
|
101
|
+
includePaddingTop,
|
|
102
|
+
includePaddingRight,
|
|
103
|
+
includePaddingBottom,
|
|
104
|
+
includePaddingLeft,
|
|
105
|
+
mapControllerRef
|
|
106
|
+
]);
|
|
99
107
|
useEffect(() => {
|
|
100
108
|
if (!mapId || !mapControllerRef.current) {
|
|
101
109
|
return;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { MapRef } from '@byted-doubao-apps/framework/components';
|
|
2
|
+
import type { MapProps as ComponentMapProps } from '@byted-doubao-apps/components';
|
|
2
3
|
import type { CSSProperties } from '@lynx-js/types';
|
|
3
4
|
import type { MapProps } from '@tarojs/components';
|
|
4
|
-
import { resolveCustomMapStyle
|
|
5
|
+
import { resolveCustomMapStyle } from './bridge.js';
|
|
5
6
|
type CommonEvent<T = unknown> = {
|
|
6
7
|
type: string;
|
|
7
8
|
timeStamp: number;
|
|
@@ -19,12 +20,9 @@ type CommonEvent<T = unknown> = {
|
|
|
19
20
|
preventDefault: () => void;
|
|
20
21
|
stopPropagation: () => void;
|
|
21
22
|
};
|
|
22
|
-
type NativeMapClickDetail =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type NativeMapPolylineClickDetail = {
|
|
26
|
-
id: string;
|
|
27
|
-
};
|
|
23
|
+
type NativeMapClickDetail = Parameters<NonNullable<ComponentMapProps['onClick']>>[0];
|
|
24
|
+
type NativeMapPolylineClickDetail = Parameters<NonNullable<ComponentMapProps['onPolylineClick']>>[0];
|
|
25
|
+
type NativeMapRegionChangeDetail = Parameters<NonNullable<ComponentMapProps['onRegionChange']>>[0];
|
|
28
26
|
type ResolvedMapValues = {
|
|
29
27
|
resolvedSetting: Record<string, unknown>;
|
|
30
28
|
resolvedScale: number;
|
|
@@ -166,7 +164,7 @@ export declare function createMapElementProps(options: CreateMapElementPropsOpti
|
|
|
166
164
|
}[];
|
|
167
165
|
onClick: (detail: NativeMapClickDetail) => void;
|
|
168
166
|
onMapLoaded: () => void;
|
|
169
|
-
onRegionChange: (detail:
|
|
167
|
+
onRegionChange: (detail: NativeMapRegionChangeDetail) => void;
|
|
170
168
|
onPolylineClick: (detail: NativeMapPolylineClickDetail) => void;
|
|
171
169
|
};
|
|
172
170
|
export declare function toCommonEvent<T>(detail: T, type: string, mapId: string): CommonEvent<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBooleanSetting, getNumberSetting, mapPolylineTapDetail, mapRegionChangeDetail, normalizeSetting, resolveCircles, resolveCustomMapStyle, resolveNativePolygons, resolvePadding, resolvePolylines
|
|
1
|
+
import { getBooleanSetting, getNumberSetting, mapPolylineTapDetail, mapRegionChangeDetail, normalizeSetting, resolveCircles, resolveCustomMapStyle, resolveNativePolygons, resolvePadding, resolvePolylines } from './bridge.js';
|
|
2
2
|
const SUPPORTED_SETTING_KEYS = new Set([
|
|
3
3
|
'scale',
|
|
4
4
|
'minScale',
|
|
@@ -118,10 +118,10 @@ export function createMapElementProps(options) {
|
|
|
118
118
|
options.onInitComplete?.(event);
|
|
119
119
|
},
|
|
120
120
|
onRegionChange: (detail) => {
|
|
121
|
-
options.onRegionChange?.(toCommonEvent(mapRegionChangeDetail(
|
|
121
|
+
options.onRegionChange?.(toCommonEvent(mapRegionChangeDetail(detail), 'regionchange', options.mapId));
|
|
122
122
|
},
|
|
123
123
|
onPolylineClick: (detail) => {
|
|
124
|
-
options.onPolylineTap?.(toCommonEvent(mapPolylineTapDetail(detail
|
|
124
|
+
options.onPolylineTap?.(toCommonEvent(mapPolylineTapDetail(detail), 'polylinetap', options.mapId));
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
}
|
package/package.json
CHANGED